mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 20:23:01 +01:00
add HTTP proxy support
This commit is contained in:
parent
9240f62829
commit
e55e5f3f7e
@ -378,7 +378,7 @@ void *dns3_lookup_thread(void *data)
|
|||||||
/* creates new thread for dns3 lookup. Only allows one lookup at a time. */
|
/* creates new thread for dns3 lookup. Only allows one lookup at a time. */
|
||||||
void dns3_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr, const char *msg)
|
void dns3_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr, const char *msg)
|
||||||
{
|
{
|
||||||
if (arg_opts.use_proxy && arg_opts.force_tcp) {
|
if (arg_opts.proxy_type != TOX_PROXY_NONE && arg_opts.force_tcp) {
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "DNS lookups are disabled.");
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "DNS lookups are disabled.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
42
src/toxic.c
42
src/toxic.c
@ -258,21 +258,21 @@ static Tox *init_tox(void)
|
|||||||
Tox_Options tox_opts;
|
Tox_Options tox_opts;
|
||||||
tox_opts.ipv6enabled = !arg_opts.use_ipv4;
|
tox_opts.ipv6enabled = !arg_opts.use_ipv4;
|
||||||
tox_opts.udp_disabled = arg_opts.force_tcp;
|
tox_opts.udp_disabled = arg_opts.force_tcp;
|
||||||
tox_opts.proxy_enabled = arg_opts.use_proxy;
|
tox_opts.proxy_type = arg_opts.proxy_type;
|
||||||
|
|
||||||
if (tox_opts.proxy_enabled) {
|
if (tox_opts.proxy_type != TOX_PROXY_NONE) {
|
||||||
tox_opts.proxy_port = arg_opts.proxy_port;
|
tox_opts.proxy_port = arg_opts.proxy_port;
|
||||||
snprintf(tox_opts.proxy_address, sizeof(tox_opts.proxy_address), "%s", arg_opts.proxy_address);
|
snprintf(tox_opts.proxy_address, sizeof(tox_opts.proxy_address), "%s", arg_opts.proxy_address);
|
||||||
|
const char *ps = tox_opts.proxy_type == TOX_PROXY_SOCKS5 ? "SOCKS5" : "HTTP";
|
||||||
|
|
||||||
char tmp[48];
|
char tmp[48];
|
||||||
snprintf(tmp, sizeof(tmp), "Using proxy %s : %d",
|
snprintf(tmp, sizeof(tmp), "Using %s proxy %s : %d", ps, arg_opts.proxy_address, arg_opts.proxy_port);
|
||||||
arg_opts.proxy_address, arg_opts.proxy_port);
|
|
||||||
queue_init_message("%s", tmp);
|
queue_init_message("%s", tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tox_opts.udp_disabled) {
|
if (tox_opts.udp_disabled) {
|
||||||
queue_init_message("UDP disabled");
|
queue_init_message("UDP disabled");
|
||||||
} else if (tox_opts.proxy_enabled) {
|
} else if (tox_opts.proxy_type != TOX_PROXY_NONE) {
|
||||||
const char *msg = "WARNING: Using a proxy without disabling UDP may leak your real IP address.";
|
const char *msg = "WARNING: Using a proxy without disabling UDP may leak your real IP address.";
|
||||||
queue_init_message("%s", msg);
|
queue_init_message("%s", msg);
|
||||||
msg = "Use the -t option to disable UDP.";
|
msg = "Use the -t option to disable UDP.";
|
||||||
@ -291,7 +291,7 @@ static Tox *init_tox(void)
|
|||||||
if (!tox_opts.ipv6enabled)
|
if (!tox_opts.ipv6enabled)
|
||||||
queue_init_message("Forcing IPv4 connection");
|
queue_init_message("Forcing IPv4 connection");
|
||||||
|
|
||||||
if (tox_opts.proxy_enabled && m == NULL)
|
if (tox_opts.proxy_type != TOX_PROXY_NONE && m == NULL)
|
||||||
exit_toxic_err("Proxy error", FATALERR_PROXY);
|
exit_toxic_err("Proxy error", FATALERR_PROXY);
|
||||||
|
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
@ -791,7 +791,8 @@ static void print_usage(void)
|
|||||||
fprintf(stderr, " -h, --help Show this message and exit\n");
|
fprintf(stderr, " -h, --help Show this message and exit\n");
|
||||||
fprintf(stderr, " -n, --nodes Use specified DHTnodes file\n");
|
fprintf(stderr, " -n, --nodes Use specified DHTnodes file\n");
|
||||||
fprintf(stderr, " -o, --noconnect Do not connect to the DHT network\n");
|
fprintf(stderr, " -o, --noconnect Do not connect to the DHT network\n");
|
||||||
fprintf(stderr, " -p, --proxy Use proxy: Requires [IP] [port]\n");
|
fprintf(stderr, " -p, --SOCKS5-proxy Use SOCKS5 proxy: Requires [IP] [port]\n");
|
||||||
|
fprintf(stderr, " -P, --HTTP-proxy Use HTTP proxy: Requires [IP] [port]\n");
|
||||||
fprintf(stderr, " -r, --dnslist Use specified DNSservers file\n");
|
fprintf(stderr, " -r, --dnslist Use specified DNSservers file\n");
|
||||||
fprintf(stderr, " -t, --force-tcp Force TCP connection (use this with proxies)\n");
|
fprintf(stderr, " -t, --force-tcp Force TCP connection (use this with proxies)\n");
|
||||||
fprintf(stderr, " -u, --unencrypt-data Unencrypt an encrypted data file\n");
|
fprintf(stderr, " -u, --unencrypt-data Unencrypt an encrypted data file\n");
|
||||||
@ -803,6 +804,7 @@ static void set_default_opts(void)
|
|||||||
memset(&arg_opts, 0, sizeof(struct arg_opts));
|
memset(&arg_opts, 0, sizeof(struct arg_opts));
|
||||||
|
|
||||||
/* set any non-zero defaults here*/
|
/* set any non-zero defaults here*/
|
||||||
|
arg_opts.proxy_type = TOX_PROXY_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_args(int argc, char *argv[])
|
static void parse_args(int argc, char *argv[])
|
||||||
@ -822,12 +824,13 @@ static void parse_args(int argc, char *argv[])
|
|||||||
{"noconnect", no_argument, 0, 'o'},
|
{"noconnect", no_argument, 0, 'o'},
|
||||||
{"dnslist", required_argument, 0, 'r'},
|
{"dnslist", required_argument, 0, 'r'},
|
||||||
{"force-tcp", no_argument, 0, 't'},
|
{"force-tcp", no_argument, 0, 't'},
|
||||||
{"proxy", required_argument, 0, 'p'},
|
{"SOCKS5-proxy", required_argument, 0, 'p'},
|
||||||
|
{"HTTP-proxy", required_argument, 0, 'P'},
|
||||||
{"unencrypt-data", no_argument, 0, 'u'},
|
{"unencrypt-data", no_argument, 0, 'u'},
|
||||||
{NULL, no_argument, NULL, 0},
|
{NULL, no_argument, NULL, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *opts_str = "4bdehotuxc:f:n:r:p:";
|
const char *opts_str = "4bdehotuxc:f:n:r:p:P:";
|
||||||
int opt, indexptr;
|
int opt, indexptr;
|
||||||
|
|
||||||
while ((opt = getopt_long(argc, argv, opts_str, long_opts, &indexptr)) != -1) {
|
while ((opt = getopt_long(argc, argv, opts_str, long_opts, &indexptr)) != -1) {
|
||||||
@ -887,7 +890,17 @@ static void parse_args(int argc, char *argv[])
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
arg_opts.use_proxy = 1;
|
arg_opts.proxy_type = TOX_PROXY_SOCKS5;
|
||||||
|
snprintf(arg_opts.proxy_address, sizeof(arg_opts.proxy_address), "%s", optarg);
|
||||||
|
|
||||||
|
if (++optind > argc || argv[optind-1][0] == '-')
|
||||||
|
exit_toxic_err("Proxy error", FATALERR_PROXY);
|
||||||
|
|
||||||
|
arg_opts.proxy_port = (uint16_t) atoi(argv[optind-1]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'P':
|
||||||
|
arg_opts.proxy_type = TOX_PROXY_HTTP;
|
||||||
snprintf(arg_opts.proxy_address, sizeof(arg_opts.proxy_address), "%s", optarg);
|
snprintf(arg_opts.proxy_address, sizeof(arg_opts.proxy_address), "%s", optarg);
|
||||||
|
|
||||||
if (++optind > argc || argv[optind-1][0] == '-')
|
if (++optind > argc || argv[optind-1][0] == '-')
|
||||||
@ -981,10 +994,12 @@ static useconds_t optimal_msleepval(uint64_t *looptimer, uint64_t *loopcount, ui
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
void cb(const char* asdv, DropType dt)
|
void DnD_callback(const char* asdv, DropType dt)
|
||||||
{
|
{
|
||||||
if (dt != DT_plain)
|
if (dt != DT_plain)
|
||||||
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, asdv);
|
return;
|
||||||
|
|
||||||
|
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, asdv);
|
||||||
}
|
}
|
||||||
#endif /* X11 */
|
#endif /* X11 */
|
||||||
|
|
||||||
@ -1025,7 +1040,8 @@ int main(int argc, char *argv[])
|
|||||||
int settings_err = settings_load(user_settings, p);
|
int settings_err = settings_load(user_settings, p);
|
||||||
|
|
||||||
#ifdef X11
|
#ifdef X11
|
||||||
init_xtra(cb);
|
if (init_xtra(DnD_callback) == -1)
|
||||||
|
queue_init_message("X failed to initialize");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Tox *m = init_tox();
|
Tox *m = init_tox();
|
||||||
|
@ -94,7 +94,7 @@ struct arg_opts {
|
|||||||
char config_path[MAX_STR_SIZE];
|
char config_path[MAX_STR_SIZE];
|
||||||
char nodes_path[MAX_STR_SIZE];
|
char nodes_path[MAX_STR_SIZE];
|
||||||
|
|
||||||
int use_proxy;
|
uint8_t proxy_type;
|
||||||
char proxy_address[256];
|
char proxy_address[256];
|
||||||
uint16_t proxy_port;
|
uint16_t proxy_port;
|
||||||
};
|
};
|
||||||
|
@ -202,7 +202,7 @@ static void handle_xdnd_selection(XSelectionEvent* e)
|
|||||||
if (Xtra.on_drop && p.read_num)
|
if (Xtra.on_drop && p.read_num)
|
||||||
{
|
{
|
||||||
char *sptr;
|
char *sptr;
|
||||||
char *str = strtok_r((char*)p.data, "\n\r", &sptr);
|
char *str = strtok_r((char *) p.data, "\n\r", &sptr);
|
||||||
|
|
||||||
if (str) Xtra.on_drop(str, dt);
|
if (str) Xtra.on_drop(str, dt);
|
||||||
while ((str = strtok_r(NULL, "\n\r", &sptr)))
|
while ((str = strtok_r(NULL, "\n\r", &sptr)))
|
||||||
|
Loading…
Reference in New Issue
Block a user