Implemented proxy capabilities.
This commit is contained in:
parent
70959e3d6e
commit
ab1cef34fc
@ -41,6 +41,7 @@ char *twc_profile_option_names[TWC_PROFILE_NUM_OPTIONS] =
|
|||||||
"proxy_address",
|
"proxy_address",
|
||||||
"proxy_port",
|
"proxy_port",
|
||||||
"proxy_enabled",
|
"proxy_enabled",
|
||||||
|
"udp_disabled",
|
||||||
};
|
};
|
||||||
|
|
||||||
char *twc_profile_option_defaults[TWC_PROFILE_NUM_OPTIONS] =
|
char *twc_profile_option_defaults[TWC_PROFILE_NUM_OPTIONS] =
|
||||||
@ -49,7 +50,8 @@ char *twc_profile_option_defaults[TWC_PROFILE_NUM_OPTIONS] =
|
|||||||
"off",
|
"off",
|
||||||
"100",
|
"100",
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
"0",
|
||||||
|
"off",
|
||||||
"off",
|
"off",
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -171,7 +173,7 @@ twc_config_profile_check_value_callback(void *data,
|
|||||||
switch (option_index)
|
switch (option_index)
|
||||||
{
|
{
|
||||||
case TWC_PROFILE_OPTION_PROXY_ADDRESS:
|
case TWC_PROFILE_OPTION_PROXY_ADDRESS:
|
||||||
return strlen(value) < 256;
|
return !value || strlen(value) < 256;
|
||||||
default:
|
default:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -219,9 +221,7 @@ twc_config_init_option(int option_index, const char *option_name)
|
|||||||
"automatically load a profile and connect to the Tox network "
|
"automatically load a profile and connect to the Tox network "
|
||||||
"when WeeChat starts",
|
"when WeeChat starts",
|
||||||
NULL, 0, 0,
|
NULL, 0, 0,
|
||||||
twc_profile_option_defaults[option_index],
|
twc_profile_option_defaults[option_index], NULL, 1,
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index,
|
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index,
|
||||||
twc_config_profile_change_callback, (void *)(intptr_t)option_index,
|
twc_config_profile_change_callback, (void *)(intptr_t)option_index,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
@ -232,9 +232,7 @@ twc_config_init_option(int option_index, const char *option_name)
|
|||||||
"maximum amount of friend requests to retain before dropping "
|
"maximum amount of friend requests to retain before dropping "
|
||||||
"new ones",
|
"new ones",
|
||||||
NULL, 0, INT_MAX,
|
NULL, 0, INT_MAX,
|
||||||
twc_profile_option_defaults[option_index],
|
twc_profile_option_defaults[option_index], NULL, 1,
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index,
|
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index,
|
||||||
twc_config_profile_change_callback, (void *)(intptr_t)option_index,
|
twc_config_profile_change_callback, (void *)(intptr_t)option_index,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
@ -244,9 +242,7 @@ twc_config_init_option(int option_index, const char *option_name)
|
|||||||
option_name, "string",
|
option_name, "string",
|
||||||
"proxy address ",
|
"proxy address ",
|
||||||
NULL, 0, 0,
|
NULL, 0, 0,
|
||||||
twc_profile_option_defaults[option_index],
|
twc_profile_option_defaults[option_index], NULL, 1,
|
||||||
NULL,
|
|
||||||
1,
|
|
||||||
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index,
|
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index,
|
||||||
twc_config_profile_change_callback, (void *)(intptr_t)option_index,
|
twc_config_profile_change_callback, (void *)(intptr_t)option_index,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
@ -257,9 +253,7 @@ twc_config_init_option(int option_index, const char *option_name)
|
|||||||
"whether or not to proxy this profile; requires reload to "
|
"whether or not to proxy this profile; requires reload to "
|
||||||
"effect",
|
"effect",
|
||||||
NULL, 0, 0,
|
NULL, 0, 0,
|
||||||
twc_profile_option_defaults[option_index],
|
twc_profile_option_defaults[option_index], NULL, 1,
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index,
|
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index,
|
||||||
twc_config_profile_change_callback, (void *)(intptr_t)option_index,
|
twc_config_profile_change_callback, (void *)(intptr_t)option_index,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
@ -268,10 +262,8 @@ twc_config_init_option(int option_index, const char *option_name)
|
|||||||
twc_config_file, twc_config_section_profile,
|
twc_config_file, twc_config_section_profile,
|
||||||
option_name, "integer",
|
option_name, "integer",
|
||||||
"proxy address",
|
"proxy address",
|
||||||
NULL, 0, UINT16_MAX ,
|
NULL, 1, UINT16_MAX ,
|
||||||
twc_profile_option_defaults[option_index],
|
twc_profile_option_defaults[option_index], NULL, 1,
|
||||||
NULL,
|
|
||||||
1,
|
|
||||||
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index,
|
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index,
|
||||||
twc_config_profile_change_callback, (void *)(intptr_t)option_index,
|
twc_config_profile_change_callback, (void *)(intptr_t)option_index,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
@ -283,9 +275,17 @@ twc_config_init_option(int option_index, const char *option_name)
|
|||||||
"home, \"%p\" by the profile name); will be created if it does "
|
"home, \"%p\" by the profile name); will be created if it does "
|
||||||
"not exist.",
|
"not exist.",
|
||||||
NULL, 0, 0,
|
NULL, 0, 0,
|
||||||
twc_profile_option_defaults[option_index],
|
twc_profile_option_defaults[option_index], NULL, 1,
|
||||||
NULL,
|
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index,
|
||||||
0,
|
twc_config_profile_change_callback, (void *)(intptr_t)option_index,
|
||||||
|
NULL, NULL);
|
||||||
|
case TWC_PROFILE_OPTION_UDP_DISABLED:
|
||||||
|
return weechat_config_new_option(
|
||||||
|
twc_config_file, twc_config_section_profile,
|
||||||
|
option_name, "boolean",
|
||||||
|
"disable UDP; may be necessary for certain proxies",
|
||||||
|
NULL, 0, 0,
|
||||||
|
twc_profile_option_defaults[option_index], NULL, 1,
|
||||||
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index,
|
twc_config_profile_check_value_callback, (void *)(intptr_t)option_index,
|
||||||
twc_config_profile_change_callback, (void *)(intptr_t)option_index,
|
twc_config_profile_change_callback, (void *)(intptr_t)option_index,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
@ -314,6 +314,7 @@ twc_config_init_profile(struct t_twc_profile *profile)
|
|||||||
twc_profile_option_names[i]);
|
twc_profile_option_names[i]);
|
||||||
|
|
||||||
profile->options[i] = twc_config_init_option(i, option_name);
|
profile->options[i] = twc_config_init_option(i, option_name);
|
||||||
|
weechat_log_printf("Initialized option %s %p", option_name, profile->options[i]);
|
||||||
free(option_name);
|
free(option_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ char *
|
|||||||
twc_profile_expanded_data_path(struct t_twc_profile *profile)
|
twc_profile_expanded_data_path(struct t_twc_profile *profile)
|
||||||
{
|
{
|
||||||
const char *weechat_dir = weechat_info_get ("weechat_dir", NULL);
|
const char *weechat_dir = weechat_info_get ("weechat_dir", NULL);
|
||||||
const char *base_path = weechat_config_string(profile->options[TWC_PROFILE_OPTION_SAVEFILE]);
|
const char *base_path = TWC_PROFILE_OPTION_STRING(profile, TWC_PROFILE_OPTION_SAVEFILE);
|
||||||
char *home_expanded = weechat_string_replace(base_path, "%h", weechat_dir);
|
char *home_expanded = weechat_string_replace(base_path, "%h", weechat_dir);
|
||||||
char *full_path = weechat_string_replace(home_expanded, "%p", profile->name);
|
char *full_path = weechat_string_replace(home_expanded, "%p", profile->name);
|
||||||
free(home_expanded);
|
free(home_expanded);
|
||||||
@ -218,20 +218,44 @@ twc_profile_load(struct t_twc_profile *profile)
|
|||||||
// create Tox options object
|
// create Tox options object
|
||||||
Tox_Options *options = malloc(sizeof(Tox_Options));
|
Tox_Options *options = malloc(sizeof(Tox_Options));
|
||||||
options->proxy_enabled =
|
options->proxy_enabled =
|
||||||
weechat_config_boolean(profile->options[TWC_PROFILE_OPTION_PROXY_ENABLED]);
|
TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_PROXY_ENABLED);
|
||||||
|
|
||||||
const char *proxy_address =
|
const char *proxy_address =
|
||||||
weechat_config_string(profile->options[TWC_PROFILE_OPTION_PROXY_ADDRESS]);
|
TWC_PROFILE_OPTION_STRING(profile, TWC_PROFILE_OPTION_PROXY_ADDRESS);
|
||||||
|
if (proxy_address)
|
||||||
memcpy(options->proxy_address, proxy_address, strlen(proxy_address) + 1);
|
memcpy(options->proxy_address, proxy_address, strlen(proxy_address) + 1);
|
||||||
|
|
||||||
options->proxy_port =
|
options->proxy_port =
|
||||||
weechat_config_integer(profile->options[TWC_PROFILE_OPTION_PROXY_PORT]);
|
TWC_PROFILE_OPTION_INTEGER(profile, TWC_PROFILE_OPTION_PROXY_PORT);
|
||||||
|
options->udp_disabled =
|
||||||
|
TWC_PROFILE_OPTION_BOOLEAN(profile, TWC_PROFILE_OPTION_UDP_DISABLED);
|
||||||
|
|
||||||
|
if (options->proxy_enabled)
|
||||||
|
{
|
||||||
|
if (!options->proxy_address || !options->proxy_port)
|
||||||
|
{
|
||||||
|
weechat_printf(profile->buffer,
|
||||||
|
"%sproxy is enabled, but address or port is "
|
||||||
|
"missing; aborting",
|
||||||
|
weechat_prefix("error"),
|
||||||
|
options->proxy_address, options->proxy_port);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
weechat_printf(profile->buffer,
|
||||||
|
"%sUsing proxy %s:%d",
|
||||||
|
weechat_prefix("network"),
|
||||||
|
options->proxy_address, options->proxy_port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// create Tox
|
// create Tox
|
||||||
profile->tox = tox_new(options);
|
profile->tox = tox_new(options);
|
||||||
if (!(profile->tox))
|
if (!(profile->tox))
|
||||||
{
|
{
|
||||||
weechat_printf(profile->buffer,
|
weechat_printf(profile->buffer,
|
||||||
"Could not create Tox instance!",
|
"%sCould not create Tox instance!",
|
||||||
weechat_prefix("error"), weechat_plugin->name);
|
weechat_prefix("error"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,7 +355,7 @@ twc_profile_autoload()
|
|||||||
struct t_twc_list_item *item;
|
struct t_twc_list_item *item;
|
||||||
twc_list_foreach(twc_profiles, index, item)
|
twc_list_foreach(twc_profiles, index, item)
|
||||||
{
|
{
|
||||||
if (weechat_config_boolean(item->profile->options[TWC_PROFILE_OPTION_AUTOLOAD]))
|
if (TWC_PROFILE_OPTION_BOOLEAN(item->profile, TWC_PROFILE_OPTION_AUTOLOAD))
|
||||||
twc_profile_load(item->profile);
|
twc_profile_load(item->profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ enum t_twc_profile_option
|
|||||||
TWC_PROFILE_OPTION_PROXY_ADDRESS,
|
TWC_PROFILE_OPTION_PROXY_ADDRESS,
|
||||||
TWC_PROFILE_OPTION_PROXY_PORT,
|
TWC_PROFILE_OPTION_PROXY_PORT,
|
||||||
TWC_PROFILE_OPTION_PROXY_ENABLED,
|
TWC_PROFILE_OPTION_PROXY_ENABLED,
|
||||||
|
TWC_PROFILE_OPTION_UDP_DISABLED,
|
||||||
|
|
||||||
TWC_PROFILE_NUM_OPTIONS,
|
TWC_PROFILE_NUM_OPTIONS,
|
||||||
};
|
};
|
||||||
@ -56,6 +57,21 @@ struct t_twc_profile
|
|||||||
|
|
||||||
extern struct t_twc_list *twc_profiles;
|
extern struct t_twc_list *twc_profiles;
|
||||||
|
|
||||||
|
#define TWC_PROFILE_OPTION_BOOLEAN(profile, index) \
|
||||||
|
((!weechat_config_option_is_null(profile->options[index])) ? \
|
||||||
|
weechat_config_boolean(profile->options[index]) : \
|
||||||
|
weechat_config_boolean_default(profile->options[index])) \
|
||||||
|
|
||||||
|
#define TWC_PROFILE_OPTION_INTEGER(profile, index) \
|
||||||
|
((!weechat_config_option_is_null(profile->options[index])) ? \
|
||||||
|
weechat_config_integer(profile->options[index]) : \
|
||||||
|
weechat_config_integer_default(profile->options[index])) \
|
||||||
|
|
||||||
|
#define TWC_PROFILE_OPTION_STRING(profile, index) \
|
||||||
|
((!weechat_config_option_is_null(profile->options[index])) ? \
|
||||||
|
weechat_config_string(profile->options[index]) : \
|
||||||
|
weechat_config_string_default(profile->options[index])) \
|
||||||
|
|
||||||
void
|
void
|
||||||
twc_profile_init();
|
twc_profile_init();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user