diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2012-01-23 12:21:29 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2012-01-23 12:21:29 +0100 |
commit | 0f7150db19866315f03ae8f59049bd4e55e28281 (patch) | |
tree | 911df4dd6c9571f55be3eb5739ec2eb067cbed77 /src/plugins/relay | |
parent | 498f2131a747acc1c0e48cfc5b4bd33c6fef4e31 (diff) | |
download | weechat-0f7150db19866315f03ae8f59049bd4e55e28281.zip |
relay: use protocol arguments for protocol "irc" only (arguments forbidden for protocol "weechat")
Diffstat (limited to 'src/plugins/relay')
-rw-r--r-- | src/plugins/relay/relay-client.c | 17 | ||||
-rw-r--r-- | src/plugins/relay/relay-command.c | 5 | ||||
-rw-r--r-- | src/plugins/relay/relay-completion.c | 5 | ||||
-rw-r--r-- | src/plugins/relay/relay-config.c | 47 | ||||
-rw-r--r-- | src/plugins/relay/relay-raw.c | 5 | ||||
-rw-r--r-- | src/plugins/relay/relay-server.c | 37 | ||||
-rw-r--r-- | src/plugins/relay/relay-upgrade.c | 5 |
7 files changed, 80 insertions, 41 deletions
diff --git a/src/plugins/relay/relay-client.c b/src/plugins/relay/relay-client.c index cc22ab10e..fe9c68037 100644 --- a/src/plugins/relay/relay-client.c +++ b/src/plugins/relay/relay-client.c @@ -158,7 +158,7 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server) new_client->address = strdup ((address) ? address : "?"); new_client->status = RELAY_STATUS_CONNECTED; new_client->protocol = server->protocol; - new_client->protocol_args = strdup (server->protocol_args); + new_client->protocol_args = (server->protocol_args) ? strdup (server->protocol_args) : NULL; new_client->listen_start_time = server->start_time; new_client->start_time = time (NULL); new_client->end_time = 0; @@ -189,7 +189,7 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server) relay_clients = new_client; weechat_printf (NULL, - _("%s: new client from %s%s%s on port %d (id: %d, relaying: %s.%s)"), + _("%s: new client from %s%s%s on port %d (id: %d, relaying: %s%s%s)"), RELAY_PLUGIN_NAME, RELAY_COLOR_CHAT_HOST, new_client->address, @@ -197,7 +197,8 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server) server->port, new_client->id, relay_protocol_string[new_client->protocol], - new_client->protocol_args); + (new_client->protocol_args) ? "." : "", + (new_client->protocol_args) ? new_client->protocol_args : ""); new_client->hook_fd = weechat_hook_fd (new_client->sock, 1, 0, 0, @@ -258,24 +259,26 @@ relay_client_set_status (struct t_relay_client *client, { case RELAY_STATUS_AUTH_FAILED: weechat_printf (NULL, - _("%s%s: authentication failed with client %s%s%s (%s.%s)"), + _("%s%s: authentication failed with client %s%s%s (%s%s%s)"), weechat_prefix ("error"), RELAY_PLUGIN_NAME, RELAY_COLOR_CHAT_HOST, client->address, RELAY_COLOR_CHAT, relay_protocol_string[client->protocol], - client->protocol_args); + (client->protocol_args) ? "." : "", + (client->protocol_args) ? client->protocol_args : ""); break; case RELAY_STATUS_DISCONNECTED: weechat_printf (NULL, - _("%s: disconnected from client %s%s%s (%s.%s)"), + _("%s: disconnected from client %s%s%s (%s%s%s)"), RELAY_PLUGIN_NAME, RELAY_COLOR_CHAT_HOST, client->address, RELAY_COLOR_CHAT, relay_protocol_string[client->protocol], - client->protocol_args); + (client->protocol_args) ? "." : "", + (client->protocol_args) ? client->protocol_args : ""); break; default: break; diff --git a/src/plugins/relay/relay-command.c b/src/plugins/relay/relay-command.c index acb88feb4..16b4361ff 100644 --- a/src/plugins/relay/relay-command.c +++ b/src/plugins/relay/relay-command.c @@ -138,13 +138,14 @@ relay_command_server_list () } weechat_printf (NULL, - _(" port %s%d%s, relay: %s%s.%s%s, started on: %s"), + _(" port %s%d%s, relay: %s%s%s%s%s, started on: %s"), RELAY_COLOR_CHAT_BUFFER, ptr_server->port, RELAY_COLOR_CHAT, RELAY_COLOR_CHAT_BUFFER, relay_protocol_string[ptr_server->protocol], - ptr_server->protocol_args, + (ptr_server->protocol_args) ? "." : "", + (ptr_server->protocol_args) ? ptr_server->protocol_args : "", RELAY_COLOR_CHAT, date_start); i++; diff --git a/src/plugins/relay/relay-completion.c b/src/plugins/relay/relay-completion.c index 3a13f185b..dc14c9ca6 100644 --- a/src/plugins/relay/relay-completion.c +++ b/src/plugins/relay/relay-completion.c @@ -88,9 +88,10 @@ relay_completion_relays_cb (void *data, const char *completion_item, for (ptr_server = relay_servers; ptr_server; ptr_server = ptr_server->next_server) { - snprintf (protocol_name, sizeof (protocol_name), "%s.%s", + snprintf (protocol_name, sizeof (protocol_name), "%s%s%s", relay_protocol_string[ptr_server->protocol], - ptr_server->protocol_args); + (ptr_server->protocol_args) ? "." : "", + (ptr_server->protocol_args) ? ptr_server->protocol_args : ""); weechat_hook_completion_list_add (completion, protocol_name, 0, WEECHAT_LIST_POS_SORT); } diff --git a/src/plugins/relay/relay-config.c b/src/plugins/relay/relay-config.c index c71a6d77f..0080f0cff 100644 --- a/src/plugins/relay/relay-config.c +++ b/src/plugins/relay/relay-config.c @@ -235,7 +235,7 @@ relay_config_create_option_port (void *data, protocol_number = -1; port = -1; - if (protocol && protocol_args) + if (protocol) protocol_number = relay_protocol_search (protocol); if (protocol_number < 0) @@ -246,13 +246,33 @@ relay_config_create_option_port (void *data, rc = WEECHAT_CONFIG_OPTION_SET_ERROR; } - if (weechat_config_search_option (config_file, section, option_name)) + if ((protocol_number == RELAY_PROTOCOL_WEECHAT) && protocol_args) { - weechat_printf (NULL, _("%s%s: error: relay for \"%s\" already exists"), + weechat_printf (NULL, _("%s%s: error: name is not allowed for protocol " + "\"%s\""), weechat_prefix ("error"), - RELAY_PLUGIN_NAME, option_name); + RELAY_PLUGIN_NAME, protocol); rc = WEECHAT_CONFIG_OPTION_SET_ERROR; } + else if ((protocol_number == RELAY_PROTOCOL_IRC) && !protocol_args) + { + weechat_printf (NULL, _("%s%s: error: name is not required for protocol " + "\"%s\""), + weechat_prefix ("error"), + RELAY_PLUGIN_NAME, protocol); + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; + } + + if (rc != WEECHAT_CONFIG_OPTION_SET_ERROR) + { + if (weechat_config_search_option (config_file, section, option_name)) + { + weechat_printf (NULL, _("%s%s: error: relay for \"%s\" already exists"), + weechat_prefix ("error"), + RELAY_PLUGIN_NAME, option_name); + rc = WEECHAT_CONFIG_OPTION_SET_ERROR; + } + } if (rc != WEECHAT_CONFIG_OPTION_SET_ERROR) { @@ -270,17 +290,18 @@ relay_config_create_option_port (void *data, if (rc != WEECHAT_CONFIG_OPTION_SET_ERROR) { - /* create config option */ - weechat_config_new_option ( - config_file, section, - option_name, "integer", NULL, - NULL, 0, 65535, "", value, 0, - &relay_config_check_port_cb, NULL, - &relay_config_change_port_cb, NULL, - &relay_config_delete_port_cb, NULL); - if (relay_server_new (protocol_number, protocol_args, port)) + { + /* create config option */ + weechat_config_new_option ( + config_file, section, + option_name, "integer", NULL, + NULL, 0, 65535, "", value, 0, + &relay_config_check_port_cb, NULL, + &relay_config_change_port_cb, NULL, + &relay_config_delete_port_cb, NULL); rc = WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE; + } else rc = WEECHAT_CONFIG_OPTION_SET_ERROR; } diff --git a/src/plugins/relay/relay-raw.c b/src/plugins/relay/relay-raw.c index f8c33fdaf..2b186c616 100644 --- a/src/plugins/relay/relay-raw.c +++ b/src/plugins/relay/relay-raw.c @@ -276,14 +276,15 @@ relay_raw_message_add (struct t_relay_client *client, int flags, if (client) { - snprintf (prefix, sizeof (prefix), "%s[%s%d%s] %s%s.%s %s%s", + snprintf (prefix, sizeof (prefix), "%s[%s%d%s] %s%s%s%s %s%s", weechat_color ("chat_delimiters"), weechat_color ("chat"), client->id, weechat_color ("chat_delimiters"), weechat_color ("chat_server"), relay_protocol_string[client->protocol], - client->protocol_args, + (client->protocol_args) ? "." : "", + (client->protocol_args) ? client->protocol_args : "", (flags & RELAY_RAW_FLAG_SEND) ? weechat_color ("chat_prefix_quit") : weechat_color ("chat_prefix_join"), diff --git a/src/plugins/relay/relay-server.c b/src/plugins/relay/relay-server.c index b0600a4bc..7a22df8ba 100644 --- a/src/plugins/relay/relay-server.c +++ b/src/plugins/relay/relay-server.c @@ -66,7 +66,7 @@ relay_server_get_protocol_args (const char *protocol_and_args, else { *protocol = strdup (protocol_and_args); - *protocol_args = strdup ("*"); + *protocol_args = NULL; } } @@ -85,15 +85,20 @@ relay_server_search (const char *protocol_and_args) ptr_server = NULL; - if (protocol && protocol_args) + if (protocol) { for (ptr_server = relay_servers; ptr_server; ptr_server = ptr_server->next_server) { - if ((strcmp (protocol, relay_protocol_string[ptr_server->protocol]) == 0) - && (strcmp (protocol_args, ptr_server->protocol_args) == 0)) + if (strcmp (protocol, relay_protocol_string[ptr_server->protocol]) == 0) { - break; + if (!protocol_args && !ptr_server->protocol_args) + break; + if (protocol_args && ptr_server->protocol_args + && (strcmp (protocol_args, ptr_server->protocol_args) == 0)) + { + break; + } } } } @@ -146,10 +151,11 @@ relay_server_close_socket (struct t_relay_server *server) if (!relay_signal_upgrade_received) { weechat_printf (NULL, - _("%s: socket closed for %s.%s (port %d)"), + _("%s: socket closed for %s%s%s (port %d)"), RELAY_PLUGIN_NAME, relay_protocol_string[server->protocol], - server->protocol_args, + (server->protocol_args) ? "." : "", + (server->protocol_args) ? server->protocol_args : "", server->port); } } @@ -181,12 +187,13 @@ relay_server_sock_cb (void *data, int fd) if (client_fd < 0) { weechat_printf (NULL, - _("%s%s: cannot accept client on port %d (%s.%s)"), + _("%s%s: cannot accept client on port %d (%s%s%s)"), weechat_prefix ("error"), RELAY_PLUGIN_NAME, server->port, relay_protocol_string[server->protocol], - server->protocol_args); + (server->protocol_args) ? "." : "", + (server->protocol_args) ? server->protocol_args : ""); return WEECHAT_RC_OK; } @@ -282,11 +289,12 @@ relay_server_create_socket (struct t_relay_server *server) sizeof (server_addr)) < 0) { weechat_printf (NULL, - _("%s%s: error with \"bind\" on port %d (%s.%s)"), + _("%s%s: error with \"bind\" on port %d (%s%s%s)"), weechat_prefix ("error"), RELAY_PLUGIN_NAME, server->port, relay_protocol_string[server->protocol], - server->protocol_args); + (server->protocol_args) ? "." : "", + (server->protocol_args) ? server->protocol_args : ""); close (server->sock); server->sock = -1; return 0; @@ -297,11 +305,12 @@ relay_server_create_socket (struct t_relay_server *server) listen (server->sock, max_clients); weechat_printf (NULL, - _("%s: listening on port %d (relay: %s.%s, max %d clients)"), + _("%s: listening on port %d (relay: %s%s%s, max %d clients)"), RELAY_PLUGIN_NAME, server->port, relay_protocol_string[server->protocol], - server->protocol_args, + (server->protocol_args) ? "." : "", + (server->protocol_args) ? server->protocol_args : "", max_clients); server->hook_fd = weechat_hook_fd (server->sock, @@ -338,7 +347,7 @@ relay_server_new (enum t_relay_protocol protocol, { new_server->protocol = protocol; new_server->protocol_args = - (protocol_args) ? strdup (protocol_args) : strdup ("*"); + (protocol_args) ? strdup (protocol_args) : NULL; new_server->port = port; new_server->sock = -1; new_server->hook_fd = NULL; diff --git a/src/plugins/relay/relay-upgrade.c b/src/plugins/relay/relay-upgrade.c index 1746524ac..c0bf01a0c 100644 --- a/src/plugins/relay/relay-upgrade.c +++ b/src/plugins/relay/relay-upgrade.c @@ -160,6 +160,7 @@ relay_upgrade_read_cb (void *data, struct t_infolist *infolist) { struct t_relay_client *new_client; + const char *str; /* make C compiler happy */ (void) data; @@ -179,7 +180,9 @@ relay_upgrade_read_cb (void *data, new_client->address = strdup (weechat_infolist_string (infolist, "address")); new_client->status = weechat_infolist_integer (infolist, "status"); new_client->protocol = weechat_infolist_integer (infolist, "protocol"); - new_client->protocol_args = strdup (weechat_infolist_string (infolist, "protocol_args")); + str = weechat_infolist_string (infolist, "protocol_args"); + if (str) + new_client->protocol_args = strdup (str); new_client->listen_start_time = weechat_infolist_time (infolist, "listen_start_time"); new_client->start_time = weechat_infolist_time (infolist, "start_time"); new_client->end_time = weechat_infolist_time (infolist, "end_time"); |