summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2012-07-17 09:56:03 +0200
committerSebastien Helleu <flashcode@flashtux.org>2012-07-17 09:56:03 +0200
commit99c1065bcf6b4f051785caa96053aa17fc31f315 (patch)
tree68b8689b1cebcc52d783330f7c193da26000dff6 /src/plugins
parent380ce5d45d5025806965cf7acdec3dfeabe730a4 (diff)
downloadweechat-99c1065bcf6b4f051785caa96053aa17fc31f315.zip
relay: move creation of client from relay-upgrade.c to relay-client.c
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/relay/relay-client.c69
-rw-r--r--src/plugins/relay/relay-client.h1
-rw-r--r--src/plugins/relay/relay-upgrade.c59
3 files changed, 71 insertions, 58 deletions
diff --git a/src/plugins/relay/relay-client.c b/src/plugins/relay/relay-client.c
index d9f0e8cb8..dbb0ac587 100644
--- a/src/plugins/relay/relay-client.c
+++ b/src/plugins/relay/relay-client.c
@@ -492,6 +492,75 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server)
}
/*
+ * relay_client_new_with_infolist: create a new client using an infolist
+ */
+
+struct t_relay_client *
+relay_client_new_with_infolist (struct t_infolist *infolist)
+{
+ struct t_relay_client *new_client;
+ const char *str;
+
+ new_client = malloc (sizeof (*new_client));
+ if (new_client)
+ {
+ new_client->id = weechat_infolist_integer (infolist, "id");
+ new_client->sock = weechat_infolist_integer (infolist, "sock");
+ 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");
+ str = weechat_infolist_string (infolist, "protocol_args");
+ new_client->protocol_args = (str) ? strdup (str) : NULL;
+ 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");
+ if (new_client->sock >= 0)
+ {
+ new_client->hook_fd = weechat_hook_fd (new_client->sock,
+ 1, 0, 0,
+ &relay_client_recv_cb,
+ new_client);
+ }
+ else
+ new_client->hook_fd = NULL;
+ new_client->last_activity = weechat_infolist_time (infolist, "last_activity");
+ sscanf (weechat_infolist_string (infolist, "bytes_recv"),
+ "%lu", &(new_client->bytes_recv));
+ sscanf (weechat_infolist_string (infolist, "bytes_sent"),
+ "%lu", &(new_client->bytes_sent));
+
+ switch (new_client->protocol)
+ {
+ case RELAY_PROTOCOL_WEECHAT:
+ relay_weechat_alloc_with_infolist (new_client,
+ infolist);
+ break;
+ case RELAY_PROTOCOL_IRC:
+ relay_irc_alloc_with_infolist (new_client,
+ infolist);
+ break;
+ case RELAY_NUM_PROTOCOLS:
+ break;
+ }
+
+ new_client->outqueue = NULL;
+ new_client->last_outqueue = NULL;
+
+ new_client->prev_client = NULL;
+ new_client->next_client = relay_clients;
+ if (relay_clients)
+ relay_clients->prev_client = new_client;
+ else
+ last_relay_client = new_client;
+ relay_clients = new_client;
+
+ relay_client_count++;
+ }
+
+ return new_client;
+}
+
+/*
* relay_client_set_status: set status for a client
*/
diff --git a/src/plugins/relay/relay-client.h b/src/plugins/relay/relay-client.h
index 47155dfda..b53002299 100644
--- a/src/plugins/relay/relay-client.h
+++ b/src/plugins/relay/relay-client.h
@@ -90,6 +90,7 @@ extern int relay_client_send (struct t_relay_client *client, const char *data,
extern int relay_client_timer_cb (void *data, int remaining_calls);
extern struct t_relay_client *relay_client_new (int sock, const char *address,
struct t_relay_server *server);
+extern struct t_relay_client *relay_client_new_with_infolist (struct t_infolist *infolist);
extern void relay_client_set_status (struct t_relay_client *client,
enum t_relay_status status);
extern void relay_client_free (struct t_relay_client *client);
diff --git a/src/plugins/relay/relay-upgrade.c b/src/plugins/relay/relay-upgrade.c
index d39bd3b43..141ad6768 100644
--- a/src/plugins/relay/relay-upgrade.c
+++ b/src/plugins/relay/relay-upgrade.c
@@ -159,9 +159,6 @@ relay_upgrade_read_cb (void *data,
int object_id,
struct t_infolist *infolist)
{
- struct t_relay_client *new_client;
- const char *str;
-
/* make C compiler happy */
(void) data;
(void) upgrade_file;
@@ -172,61 +169,7 @@ relay_upgrade_read_cb (void *data,
switch (object_id)
{
case RELAY_UPGRADE_TYPE_CLIENT:
- new_client = malloc (sizeof (*new_client));
- if (new_client)
- {
- new_client->id = weechat_infolist_integer (infolist, "id");
- new_client->sock = weechat_infolist_integer (infolist, "sock");
- 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");
- str = weechat_infolist_string (infolist, "protocol_args");
- new_client->protocol_args = (str) ? strdup (str) : NULL;
- 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");
- if (new_client->sock >= 0)
- {
- new_client->hook_fd = weechat_hook_fd (new_client->sock,
- 1, 0, 0,
- &relay_client_recv_cb,
- new_client);
- }
- else
- new_client->hook_fd = NULL;
- new_client->last_activity = weechat_infolist_time (infolist, "last_activity");
- sscanf (weechat_infolist_string (infolist, "bytes_recv"),
- "%lu", &(new_client->bytes_recv));
- sscanf (weechat_infolist_string (infolist, "bytes_sent"),
- "%lu", &(new_client->bytes_sent));
-
- switch (new_client->protocol)
- {
- case RELAY_PROTOCOL_WEECHAT:
- relay_weechat_alloc_with_infolist (new_client,
- infolist);
- break;
- case RELAY_PROTOCOL_IRC:
- relay_irc_alloc_with_infolist (new_client,
- infolist);
- break;
- case RELAY_NUM_PROTOCOLS:
- break;
- }
-
- new_client->outqueue = NULL;
- new_client->last_outqueue = NULL;
-
- new_client->prev_client = NULL;
- new_client->next_client = relay_clients;
- if (relay_clients)
- relay_clients->prev_client = new_client;
- else
- last_relay_client = new_client;
- relay_clients = new_client;
-
- relay_client_count++;
- }
+ relay_client_new_with_infolist (infolist);
break;
case RELAY_UPGRADE_TYPE_RAW_MESSAGE:
relay_raw_message_add_to_list (weechat_infolist_time (infolist, "date"),