1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-26 04:46:37 +02:00

relay: add object type "arr" (array) in WeeChat protocol

This commit is contained in:
Sebastien Helleu
2012-07-20 18:18:37 +02:00
parent eab0110732
commit bd7332455d
5 changed files with 196 additions and 69 deletions
+1
View File
@@ -50,6 +50,7 @@ Version 0.3.9 (under dev!)
* python: fix detection of python (first try "python2.x" and then "python")
(bug #36835)
* python: fix crash when unloading a script without pointer to interpreter
* relay: add object type "arr" (array) in WeeChat protocol
* relay: fix freeze when writing on relay socket (use non-blocking sockets in
relay for irc and weechat protocols) (bug #36655)
* ruby: detect ruby version 1.9.3 in cmake and autotools
+37
View File
@@ -519,6 +519,7 @@ available:
| hda | Hdata content | Variable
| inf | Info: name + content | Variable
| inl | Infolist content | Variable
| arr | Array of values | 3 bytes (type) + number of items + data
|=====================================================
[[object_char]]
@@ -831,6 +832,42 @@ infolist buffer
name count item 1 item 2
.......................................
[[object_array]]
Array
^^^^^
An array is a type (3 bytes) + number of items (integer on 4 bytes) + data.
Example of array with 2 strings:
.......................................
┌─────╥────┬────┬────┬────╥────┬────┬────┬────╥────┬────┬────╥────┬────┬────┬────╥────┬────┐
│ str ║ 00 │ 00 │ 00 │ 02 ║ 00 │ 00 │ 00 │ 03 ║ 61 │ 62 │ 63 ║ 00 │ 00 │ 00 │ 02 ║ 64 │ 65 │ ────► { "abc", "de" }
└─────╨────┴────┴────┴────╨────┴────┴────┴────╨────┴────┴────╨────┴────┴────┴────╨────┴────┘
└───┘ └─────────────────┘ └─────────────────┘ └────────────┘ └─────────────────┘ └───────┘
type number of strings length 'a' 'b' 'c' length 'd' 'e'
.......................................
Example of array with 3 integers:
.......................................
┌─────╥────┬────┬────┬────╥────┬────┬────┬────╥────┬────┬────┬────╥────┬────┬────┬────┐
│ int ║ 00 │ 00 │ 00 │ 03 ║ 00 │ 00 │ 00 │ 7B ║ 00 │ 00 │ 01 │ C8 ║ 00 │ 00 │ 03 │ 15 │ ────► { 123, 456, 789 }
└─────╨────┴────┴────┴────╨────┴────┴────┴────╨────┴────┴────┴────╨────┴────┴────┴────┘
└───┘ └─────────────────┘ └─────────────────┘ └─────────────────┘ └─────────────────┘
type number of integers 123 (0x7B) 456 (0x1C8) 789 (0x315)
.......................................
A 'NULL' array:
.......................................
┌─────╥────┬────┬────┬────┐
│ str ║ 00 │ 00 │ 00 │ 00 │ ────► NULL
└─────╨────┴────┴────┴────┘
└───┘ └─────────────────┘
type number of strings
.......................................
[[typical_session]]
Typical session
---------------
+121 -69
View File
@@ -336,8 +336,9 @@ relay_weechat_msg_add_hdata_path (struct t_relay_weechat_msg *msg,
void *pointer,
char **list_keys)
{
int num_added, i, count, count_all, type;
char *pos, *pos2, *str_count, *error;
int num_added, i, j, count, count_all, var_type, array_size, max_array_size;
int length;
char *pos, *pos2, *str_count, *error, *name;
void *sub_pointer;
struct t_hdata *sub_hdata;
const char *sub_hdata_name;
@@ -414,53 +415,96 @@ relay_weechat_msg_add_hdata_path (struct t_relay_weechat_msg *msg,
}
for (i = 0; list_keys[i]; i++)
{
type = weechat_hdata_get_var_type (hdata, list_keys[i]);
if ((type >= 0) && (type != WEECHAT_HDATA_OTHER))
var_type = weechat_hdata_get_var_type (hdata, list_keys[i]);
if ((var_type >= 0) && (var_type != WEECHAT_HDATA_OTHER))
{
switch (type)
max_array_size = 1;
array_size = weechat_hdata_get_var_array_size (hdata,
pointer,
list_keys[i]);
if (array_size >= 0)
{
case WEECHAT_HDATA_CHAR:
relay_weechat_msg_add_char (msg,
weechat_hdata_char (hdata,
pointer,
list_keys[i]));
break;
case WEECHAT_HDATA_INTEGER:
relay_weechat_msg_add_int (msg,
weechat_hdata_integer (hdata,
pointer,
list_keys[i]));
break;
case WEECHAT_HDATA_LONG:
relay_weechat_msg_add_long (msg,
weechat_hdata_long (hdata,
pointer,
list_keys[i]));
break;
case WEECHAT_HDATA_STRING:
relay_weechat_msg_add_string (msg,
weechat_hdata_string (hdata,
pointer,
list_keys[i]));
break;
case WEECHAT_HDATA_POINTER:
relay_weechat_msg_add_pointer (msg,
weechat_hdata_pointer (hdata,
pointer,
list_keys[i]));
break;
case WEECHAT_HDATA_TIME:
relay_weechat_msg_add_time (msg,
weechat_hdata_time (hdata,
pointer,
list_keys[i]));
break;
case WEECHAT_HDATA_HASHTABLE:
relay_weechat_msg_add_hashtable (msg,
weechat_hdata_hashtable (hdata,
switch (var_type)
{
case WEECHAT_HDATA_CHAR:
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_CHAR);
break;
case WEECHAT_HDATA_INTEGER:
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_INT);
break;
case WEECHAT_HDATA_LONG:
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_LONG);
break;
case WEECHAT_HDATA_STRING:
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_STRING);
break;
case WEECHAT_HDATA_POINTER:
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_POINTER);
break;
case WEECHAT_HDATA_TIME:
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_TIME);
break;
case WEECHAT_HDATA_HASHTABLE:
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_HASHTABLE);
break;
}
relay_weechat_msg_add_int (msg, array_size);
max_array_size = array_size;
}
length = 16 + strlen (list_keys[i]) + 1;
name = malloc (length);
if (name)
{
for (j = 0; j < max_array_size; j++)
{
snprintf (name, length, "%d|%s", j, list_keys[i]);
switch (var_type)
{
case WEECHAT_HDATA_CHAR:
relay_weechat_msg_add_char (msg,
weechat_hdata_char (hdata,
pointer,
name));
break;
case WEECHAT_HDATA_INTEGER:
relay_weechat_msg_add_int (msg,
weechat_hdata_integer (hdata,
pointer,
list_keys[i]));
break;
name));
break;
case WEECHAT_HDATA_LONG:
relay_weechat_msg_add_long (msg,
weechat_hdata_long (hdata,
pointer,
name));
break;
case WEECHAT_HDATA_STRING:
relay_weechat_msg_add_string (msg,
weechat_hdata_string (hdata,
pointer,
name));
break;
case WEECHAT_HDATA_POINTER:
relay_weechat_msg_add_pointer (msg,
weechat_hdata_pointer (hdata,
pointer,
name));
break;
case WEECHAT_HDATA_TIME:
relay_weechat_msg_add_time (msg,
weechat_hdata_time (hdata,
pointer,
name));
break;
case WEECHAT_HDATA_HASHTABLE:
relay_weechat_msg_add_hashtable (msg,
weechat_hdata_hashtable (hdata,
pointer,
name));
break;
}
}
free (name);
}
}
}
@@ -507,7 +551,7 @@ relay_weechat_msg_add_hdata (struct t_relay_weechat_msg *msg,
struct t_hdata *ptr_hdata_head, *ptr_hdata;
char *hdata_head, *pos, **list_keys, *keys_types, **list_path;
char *path_returned;
const char *hdata_name;
const char *hdata_name, *array_size;
void *pointer, **path_pointers;
long unsigned int value;
int num_keys, num_path, i, type, pos_count, count, rc;
@@ -604,29 +648,37 @@ relay_weechat_msg_add_hdata (struct t_relay_weechat_msg *msg,
strcat (keys_types, ",");
strcat (keys_types, list_keys[i]);
strcat (keys_types, ":");
switch (type)
array_size = weechat_hdata_get_var_array_size_string (ptr_hdata,
NULL,
list_keys[i]);
if (array_size)
strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_ARRAY);
else
{
case WEECHAT_HDATA_CHAR:
strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_CHAR);
break;
case WEECHAT_HDATA_INTEGER:
strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_INT);
break;
case WEECHAT_HDATA_LONG:
strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_LONG);
break;
case WEECHAT_HDATA_STRING:
strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_STRING);
break;
case WEECHAT_HDATA_POINTER:
strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_POINTER);
break;
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;
switch (type)
{
case WEECHAT_HDATA_CHAR:
strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_CHAR);
break;
case WEECHAT_HDATA_INTEGER:
strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_INT);
break;
case WEECHAT_HDATA_LONG:
strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_LONG);
break;
case WEECHAT_HDATA_STRING:
strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_STRING);
break;
case WEECHAT_HDATA_POINTER:
strcat (keys_types, RELAY_WEECHAT_MSG_OBJ_POINTER);
break;
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;
}
}
}
}
@@ -34,6 +34,7 @@
#define RELAY_WEECHAT_MSG_OBJ_HDATA "hda"
#define RELAY_WEECHAT_MSG_OBJ_INFO "inf"
#define RELAY_WEECHAT_MSG_OBJ_INFOLIST "inl"
#define RELAY_WEECHAT_MSG_OBJ_ARRAY "arr"
struct t_relay_weechat_msg
{
@@ -808,26 +808,62 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(test)
msg = relay_weechat_msg_new (id);
if (msg)
{
/* char */
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_CHAR);
relay_weechat_msg_add_char (msg, 'A');
/* integer */
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_INT);
relay_weechat_msg_add_int (msg, 123456);
/* long */
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_LONG);
relay_weechat_msg_add_long (msg, 1234567890L);
/* string */
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_STRING);
relay_weechat_msg_add_string (msg, "a string");
/* empty string */
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_STRING);
relay_weechat_msg_add_string (msg, "");
/* NULL string */
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_STRING);
relay_weechat_msg_add_string (msg, NULL);
/* buffer */
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_BUFFER);
relay_weechat_msg_add_buffer (msg, "buffer", 6);
/* NULL buffer */
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_BUFFER);
relay_weechat_msg_add_buffer (msg, NULL, 0);
/* pointer */
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_POINTER);
relay_weechat_msg_add_pointer (msg, &msg);
/* time */
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_TIME);
relay_weechat_msg_add_time (msg, 1321993456);
/* array of strings: { "abc", "de" } */
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_ARRAY);
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_STRING);
relay_weechat_msg_add_int (msg, 2);
relay_weechat_msg_add_string (msg, "abc");
relay_weechat_msg_add_string (msg, "de");
/* array of integers: { 123, 456, 789 } */
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_ARRAY);
relay_weechat_msg_add_type (msg, RELAY_WEECHAT_MSG_OBJ_INT);
relay_weechat_msg_add_int (msg, 3);
relay_weechat_msg_add_int (msg, 123);
relay_weechat_msg_add_int (msg, 456);
relay_weechat_msg_add_int (msg, 789);
/* send message */
relay_weechat_msg_send (client, msg);
relay_weechat_msg_free (msg);
}