mirror of
https://github.com/weechat/weechat.git
synced 2026-07-09 03:03:12 +02:00
relay: add type "hashtable" in relay protocol and hdata, add signals "buffer_localvar_xxx" in protocol
This commit is contained in:
@@ -251,6 +251,77 @@ relay_weechat_msg_add_time (struct t_relay_weechat_msg *msg, time_t time)
|
||||
relay_weechat_msg_add_bytes (msg, str_time, length);
|
||||
}
|
||||
|
||||
/*
|
||||
* relay_weechat_msg_hashtable_map_cb: callback used to add hashtable items in
|
||||
* message
|
||||
*/
|
||||
|
||||
void
|
||||
relay_weechat_msg_hashtable_map_cb (void *data, struct t_hashtable *hashtable,
|
||||
const void *key, const void *value)
|
||||
{
|
||||
struct t_relay_weechat_msg *msg;
|
||||
char *types[2] = { "type_keys", "type_values" };
|
||||
const void *pointers[2];
|
||||
const char *type;
|
||||
int i;
|
||||
|
||||
msg = (struct t_relay_weechat_msg *)data;
|
||||
pointers[0] = key;
|
||||
pointers[1] = value;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
type = weechat_hashtable_get_string (hashtable, types[i]);
|
||||
if (strcmp (type, WEECHAT_HASHTABLE_INTEGER) == 0)
|
||||
relay_weechat_msg_add_int (msg, *((int *)pointers[i]));
|
||||
else if (strcmp (type, WEECHAT_HASHTABLE_STRING) == 0)
|
||||
relay_weechat_msg_add_string (msg, (const char *)pointers[i]);
|
||||
else if (strcmp (type, WEECHAT_HASHTABLE_POINTER) == 0)
|
||||
relay_weechat_msg_add_pointer (msg, (void *)pointers[i]);
|
||||
else if (strcmp (type, WEECHAT_HASHTABLE_BUFFER) == 0)
|
||||
relay_weechat_msg_add_pointer (msg, (void *)pointers[i]);
|
||||
else if (strcmp (type, WEECHAT_HASHTABLE_TIME) == 0)
|
||||
relay_weechat_msg_add_time (msg, *((time_t *)pointers[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* relay_weechat_msg_add_hashtable: add a hashtable to a message
|
||||
*/
|
||||
|
||||
void
|
||||
relay_weechat_msg_add_hashtable (struct t_relay_weechat_msg *msg,
|
||||
struct t_hashtable *hashtable)
|
||||
{
|
||||
char *types[2] = { "type_keys", "type_values" };
|
||||
const char *type;
|
||||
int i, count;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
type = weechat_hashtable_get_string (hashtable, types[i]);
|
||||
if (strcmp (type, WEECHAT_HASHTABLE_INTEGER) == 0)
|
||||
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_INT);
|
||||
else if (strcmp (type, WEECHAT_HASHTABLE_STRING) == 0)
|
||||
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_STRING);
|
||||
else if (strcmp (type, WEECHAT_HASHTABLE_POINTER) == 0)
|
||||
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_POINTER);
|
||||
else if (strcmp (type, WEECHAT_HASHTABLE_BUFFER) == 0)
|
||||
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_POINTER);
|
||||
else if (strcmp (type, WEECHAT_HASHTABLE_TIME) == 0)
|
||||
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_TIME);
|
||||
}
|
||||
|
||||
/* number of items */
|
||||
count = weechat_hashtable_get_integer (hashtable, "items_count");
|
||||
relay_weechat_msg_add_int (msg, count);
|
||||
|
||||
/* add all items */
|
||||
weechat_hashtable_map (hashtable,
|
||||
&relay_weechat_msg_hashtable_map_cb, msg);
|
||||
}
|
||||
|
||||
/*
|
||||
* relay_weechat_msg_add_hdata_path: recursively add hdata for a path
|
||||
* return number of hdata objects added in
|
||||
@@ -385,6 +456,12 @@ relay_weechat_msg_add_hdata_path (struct t_relay_weechat_msg *msg,
|
||||
pointer,
|
||||
list_keys[i]));
|
||||
break;
|
||||
case WEECHAT_HDATA_HASHTABLE:
|
||||
relay_weechat_msg_add_hashtable (msg,
|
||||
weechat_hdata_hashtable (hdata,
|
||||
pointer,
|
||||
list_keys[i]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -548,6 +625,9 @@ relay_weechat_msg_add_hdata (struct t_relay_weechat_msg *msg,
|
||||
case WEECHAT_HDATA_TIME:
|
||||
strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_TIME);
|
||||
break;
|
||||
case WEECHAT_HDATA_HASHTABLE:
|
||||
strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_HASHTABLE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,16 +23,17 @@
|
||||
#define RELAY_WEECHAT_MSG_INITIAL_ALLOC 4096
|
||||
|
||||
/* object ids in binary messages */
|
||||
#define RELAY_WEECHAT_MSG_OBJ_CHAR "chr"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_INT "int"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_LONG "lon"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_STRING "str"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_BUFFER "buf"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_POINTER "ptr"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_TIME "tim"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_HDATA "hda"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_INFO "inf"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_INFOLIST "lis"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_CHAR "chr"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_INT "int"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_LONG "lon"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_STRING "str"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_BUFFER "buf"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_POINTER "ptr"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_TIME "tim"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_HASHTABLE "htb"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_HDATA "hda"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_INFO "inf"
|
||||
#define RELAY_WEECHAT_MSG_OBJ_INFOLIST "inl"
|
||||
|
||||
struct t_relay_weechat_msg
|
||||
{
|
||||
|
||||
@@ -275,7 +275,7 @@ relay_weechat_protocol_signal_buffer_cb (void *data, const char *signal,
|
||||
struct t_gui_line_data *ptr_line_data;
|
||||
struct t_gui_buffer *ptr_buffer;
|
||||
struct t_relay_weechat_msg *msg;
|
||||
char cmd_hdata[64];
|
||||
char cmd_hdata[64], str_signal[128];
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) signal;
|
||||
@@ -285,20 +285,22 @@ relay_weechat_protocol_signal_buffer_cb (void *data, const char *signal,
|
||||
if (!ptr_client || !relay_client_valid (ptr_client))
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
snprintf (str_signal, sizeof (str_signal), "_%s", signal);
|
||||
|
||||
if (strcmp (signal, "buffer_opened") == 0)
|
||||
{
|
||||
ptr_buffer = (struct t_gui_buffer *)signal_data;
|
||||
if (!ptr_buffer)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
msg = relay_weechat_msg_new ("_buffer_opened");
|
||||
msg = relay_weechat_msg_new (str_signal);
|
||||
if (msg)
|
||||
{
|
||||
snprintf (cmd_hdata, sizeof (cmd_hdata),
|
||||
"buffer:0x%lx", (long unsigned int)ptr_buffer);
|
||||
relay_weechat_msg_add_hdata (msg, cmd_hdata,
|
||||
"number,full_name,short_name,"
|
||||
"nicklist,title,"
|
||||
"nicklist,title,local_variables,"
|
||||
"prev_buffer,next_buffer");
|
||||
relay_weechat_msg_send (ptr_client, msg, 0);
|
||||
relay_weechat_msg_free (msg);
|
||||
@@ -310,7 +312,7 @@ relay_weechat_protocol_signal_buffer_cb (void *data, const char *signal,
|
||||
if (!ptr_buffer)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
msg = relay_weechat_msg_new ("_buffer_moved");
|
||||
msg = relay_weechat_msg_new (str_signal);
|
||||
if (msg)
|
||||
{
|
||||
snprintf (cmd_hdata, sizeof (cmd_hdata),
|
||||
@@ -328,7 +330,7 @@ relay_weechat_protocol_signal_buffer_cb (void *data, const char *signal,
|
||||
if (!ptr_buffer)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
msg = relay_weechat_msg_new ("_buffer_merged");
|
||||
msg = relay_weechat_msg_new (str_signal);
|
||||
if (msg)
|
||||
{
|
||||
snprintf (cmd_hdata, sizeof (cmd_hdata),
|
||||
@@ -346,13 +348,14 @@ relay_weechat_protocol_signal_buffer_cb (void *data, const char *signal,
|
||||
if (!ptr_buffer)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
msg = relay_weechat_msg_new ("_buffer_renamed");
|
||||
msg = relay_weechat_msg_new (str_signal);
|
||||
if (msg)
|
||||
{
|
||||
snprintf (cmd_hdata, sizeof (cmd_hdata),
|
||||
"buffer:0x%lx", (long unsigned int)ptr_buffer);
|
||||
relay_weechat_msg_add_hdata (msg, cmd_hdata,
|
||||
"number,full_name,short_name");
|
||||
"number,full_name,short_name,"
|
||||
"local_variables");
|
||||
relay_weechat_msg_send (ptr_client, msg, 0);
|
||||
relay_weechat_msg_free (msg);
|
||||
}
|
||||
@@ -363,7 +366,7 @@ relay_weechat_protocol_signal_buffer_cb (void *data, const char *signal,
|
||||
if (!ptr_buffer)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
msg = relay_weechat_msg_new ("_buffer_title_changed");
|
||||
msg = relay_weechat_msg_new (str_signal);
|
||||
if (msg)
|
||||
{
|
||||
snprintf (cmd_hdata, sizeof (cmd_hdata),
|
||||
@@ -374,6 +377,23 @@ relay_weechat_protocol_signal_buffer_cb (void *data, const char *signal,
|
||||
relay_weechat_msg_free (msg);
|
||||
}
|
||||
}
|
||||
else if (strncmp (signal, "buffer_localvar_", 16) == 0)
|
||||
{
|
||||
ptr_buffer = (struct t_gui_buffer *)signal_data;
|
||||
if (!ptr_buffer)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
msg = relay_weechat_msg_new (str_signal);
|
||||
if (msg)
|
||||
{
|
||||
snprintf (cmd_hdata, sizeof (cmd_hdata),
|
||||
"buffer:0x%lx", (long unsigned int)ptr_buffer);
|
||||
relay_weechat_msg_add_hdata (msg, cmd_hdata,
|
||||
"number,full_name,local_variables");
|
||||
relay_weechat_msg_send (ptr_client, msg, 0);
|
||||
relay_weechat_msg_free (msg);
|
||||
}
|
||||
}
|
||||
else if (strcmp (signal, "buffer_line_added") == 0)
|
||||
{
|
||||
ptr_line = (struct t_gui_line *)signal_data;
|
||||
@@ -404,7 +424,7 @@ relay_weechat_protocol_signal_buffer_cb (void *data, const char *signal,
|
||||
weechat_buffer_get_string (ptr_buffer,
|
||||
"full_name")))
|
||||
{
|
||||
msg = relay_weechat_msg_new ("_buffer_line_added");
|
||||
msg = relay_weechat_msg_new (str_signal);
|
||||
if (msg)
|
||||
{
|
||||
snprintf (cmd_hdata, sizeof (cmd_hdata),
|
||||
@@ -423,7 +443,7 @@ relay_weechat_protocol_signal_buffer_cb (void *data, const char *signal,
|
||||
if (!ptr_buffer)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
msg = relay_weechat_msg_new ("_buffer_closing");
|
||||
msg = relay_weechat_msg_new (str_signal);
|
||||
if (msg)
|
||||
{
|
||||
snprintf (cmd_hdata, sizeof (cmd_hdata),
|
||||
|
||||
Reference in New Issue
Block a user