diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2012-07-20 18:18:37 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2012-07-20 18:18:37 +0200 |
commit | bd7332455d7e896fcddae7fc9fd9c6aed49b7fbe (patch) | |
tree | 157f7feae2169c8262d82a3466cd9c7dd590165f /src/plugins/relay | |
parent | eab011073224b13ada61f80f3731e8dd459b7bfa (diff) | |
download | weechat-bd7332455d7e896fcddae7fc9fd9c6aed49b7fbe.zip |
relay: add object type "arr" (array) in WeeChat protocol
Diffstat (limited to 'src/plugins/relay')
-rw-r--r-- | src/plugins/relay/weechat/relay-weechat-msg.c | 190 | ||||
-rw-r--r-- | src/plugins/relay/weechat/relay-weechat-msg.h | 1 | ||||
-rw-r--r-- | src/plugins/relay/weechat/relay-weechat-protocol.c | 36 |
3 files changed, 158 insertions, 69 deletions
diff --git a/src/plugins/relay/weechat/relay-weechat-msg.c b/src/plugins/relay/weechat/relay-weechat-msg.c index 43bb50e62..2a5f785ea 100644 --- a/src/plugins/relay/weechat/relay-weechat-msg.c +++ b/src/plugins/relay/weechat/relay-weechat-msg.c @@ -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) + { + 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) { - 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, + 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; + } } } } diff --git a/src/plugins/relay/weechat/relay-weechat-msg.h b/src/plugins/relay/weechat/relay-weechat-msg.h index 4a8282d9d..5ffc9f61b 100644 --- a/src/plugins/relay/weechat/relay-weechat-msg.h +++ b/src/plugins/relay/weechat/relay-weechat-msg.h @@ -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 { diff --git a/src/plugins/relay/weechat/relay-weechat-protocol.c b/src/plugins/relay/weechat/relay-weechat-protocol.c index e499a85bb..c21754d45 100644 --- a/src/plugins/relay/weechat/relay-weechat-protocol.c +++ b/src/plugins/relay/weechat/relay-weechat-protocol.c @@ -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); } |