summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/relay/relay-client.c21
-rw-r--r--src/plugins/relay/relay-client.h1
-rw-r--r--src/plugins/relay/relay-info.c48
3 files changed, 70 insertions, 0 deletions
diff --git a/src/plugins/relay/relay-client.c b/src/plugins/relay/relay-client.c
index c60870c94..6153ddfb3 100644
--- a/src/plugins/relay/relay-client.c
+++ b/src/plugins/relay/relay-client.c
@@ -138,6 +138,27 @@ relay_client_search_by_id (int id)
}
/*
+ * Searches for a client status.
+ *
+ * Returns index of status in enum t_relay_status, -1 if status is not found.
+ */
+
+int
+relay_client_status_search (const char *name)
+{
+ int i;
+
+ for (i = 0; i < RELAY_NUM_STATUS; i++)
+ {
+ if (strcmp (relay_client_status_name[i], name) == 0)
+ return i;
+ }
+
+ /* status not found */
+ return -1;
+}
+
+/*
* Sends a signal with the status of client ("relay_client_xxx").
*/
diff --git a/src/plugins/relay/relay-client.h b/src/plugins/relay/relay-client.h
index 5ee8dd9b7..148e6aeec 100644
--- a/src/plugins/relay/relay-client.h
+++ b/src/plugins/relay/relay-client.h
@@ -113,6 +113,7 @@ extern int relay_client_count;
extern int relay_client_valid (struct t_relay_client *client);
extern struct t_relay_client *relay_client_search_by_number (int number);
extern struct t_relay_client *relay_client_search_by_id (int id);
+extern int relay_client_status_search (const char *name);
extern void relay_client_set_desc (struct t_relay_client *client);
extern int relay_client_recv_cb (void *arg_client, int fd);
extern int relay_client_send (struct t_relay_client *client, const char *data,
diff --git a/src/plugins/relay/relay-info.c b/src/plugins/relay/relay-info.c
index a5208d796..1d9cbb729 100644
--- a/src/plugins/relay/relay-info.c
+++ b/src/plugins/relay/relay-info.c
@@ -28,6 +28,45 @@
/*
+ * Returns relay info.
+ */
+
+const char *
+relay_info_get_info_cb (void *data, const char *info_name,
+ const char *arguments)
+{
+ static char str_count[32];
+ int count, status;
+ struct t_relay_client *ptr_client;
+
+ /* make C compiler happy */
+ (void) data;
+
+ if (weechat_strcasecmp (info_name, "relay_client_count") == 0)
+ {
+ str_count[0] = '\0';
+ count = relay_client_count;
+ if (arguments && arguments[0])
+ {
+ status = relay_client_status_search (arguments);
+ if (status < 0)
+ return NULL;
+ count = 0;
+ for (ptr_client = relay_clients; ptr_client;
+ ptr_client = ptr_client->next_client)
+ {
+ if ((int)ptr_client->status == status)
+ count++;
+ }
+ }
+ snprintf (str_count, sizeof (str_count), "%d", count);
+ return str_count;
+ }
+
+ return NULL;
+}
+
+/*
* Returns infolist with relay info.
*/
@@ -90,6 +129,15 @@ relay_info_get_infolist_cb (void *data, const char *infolist_name,
void
relay_info_init ()
{
+ /* info hooks */
+ weechat_hook_info ("relay_client_count",
+ N_("number of clients for relay"),
+ /* TRANSLATORS: please do not translate the status names, they must be used in English */
+ N_("status name (optional): connecting, waiting_auth, "
+ "connected, auth_failed, disconnected"),
+ &relay_info_get_info_cb, NULL);
+
+ /* infolist hooks */
weechat_hook_infolist ("relay", N_("list of relay clients"),
N_("relay pointer (optional)"),
NULL,