diff options
Diffstat (limited to 'src/plugins/relay')
-rw-r--r-- | src/plugins/relay/api/relay-api-msg.c | 52 | ||||
-rw-r--r-- | src/plugins/relay/api/relay-api-msg.h | 1 | ||||
-rw-r--r-- | src/plugins/relay/api/relay-api-protocol.c | 31 | ||||
-rw-r--r-- | src/plugins/relay/relay.c | 2 | ||||
-rw-r--r-- | src/plugins/relay/relay.h | 1 |
5 files changed, 87 insertions, 0 deletions
diff --git a/src/plugins/relay/api/relay-api-msg.c b/src/plugins/relay/api/relay-api-msg.c index 6dde683a5..1fdf3afe6 100644 --- a/src/plugins/relay/api/relay-api-msg.c +++ b/src/plugins/relay/api/relay-api-msg.c @@ -614,3 +614,55 @@ relay_api_msg_nick_group_to_json (struct t_gui_nick_group *nick_group) return json; } + +/* + * Creates a JSON object with a hotlist entry. + */ + +cJSON * +relay_api_msg_hotlist_to_json (struct t_gui_hotlist *hotlist) +{ + struct t_hdata *hdata; + struct t_gui_hotlist *pointer; + struct t_gui_buffer *buffer; + cJSON *json, *json_count; + time_t time_value; + struct timeval tv; + struct tm gm_time; + char str_time[256], str_key[32]; + int i, array_size; + long long buffer_id; + + hdata = relay_hdata_hotlist; + pointer = hotlist; + + json = cJSON_CreateObject (); + if (!json) + return NULL; + + if (!hotlist) + return json; + + MSG_ADD_HDATA_VAR(Number, "priority", integer, "priority"); + MSG_ADD_HDATA_TIME_USEC("date", "time", "time_usec"); + buffer = weechat_hdata_pointer (hdata, hotlist, "buffer"); + buffer_id = (buffer) ? + weechat_hdata_longlong (relay_hdata_buffer, buffer, "id") : -1; + cJSON_AddItemToObject (json, "buffer_id", cJSON_CreateNumber (buffer_id)); + + json_count = cJSON_CreateArray (); + if (json_count) + { + array_size = weechat_hdata_get_var_array_size (hdata, hotlist, "count"); + for (i = 0; i < array_size; i++) + { + snprintf (str_key, sizeof (str_key), "%d|count", i); + cJSON_AddItemToArray ( + json_count, + cJSON_CreateNumber (weechat_hdata_integer (hdata, hotlist, str_key))); + } + } + cJSON_AddItemToObject (json, "count", json_count); + + return json; +} diff --git a/src/plugins/relay/api/relay-api-msg.h b/src/plugins/relay/api/relay-api-msg.h index 33f0dd690..41b5d307a 100644 --- a/src/plugins/relay/api/relay-api-msg.h +++ b/src/plugins/relay/api/relay-api-msg.h @@ -47,5 +47,6 @@ extern cJSON *relay_api_msg_line_data_to_json (struct t_gui_line_data *line_data enum t_relay_api_colors colors); extern cJSON *relay_api_msg_nick_to_json (struct t_gui_nick *nick); extern cJSON *relay_api_msg_nick_group_to_json (struct t_gui_nick_group *nick_group); +extern cJSON *relay_api_msg_hotlist_to_json (struct t_gui_hotlist *hotlist); #endif /* WEECHAT_PLUGIN_RELAY_API_MSG_H */ diff --git a/src/plugins/relay/api/relay-api-protocol.c b/src/plugins/relay/api/relay-api-protocol.c index cdfa25516..64c6d8adf 100644 --- a/src/plugins/relay/api/relay-api-protocol.c +++ b/src/plugins/relay/api/relay-api-protocol.c @@ -460,6 +460,36 @@ error: } /* + * Callback for resource "hotlist". + * + * Routes: + * GET /api/hotlist + */ + +RELAY_API_PROTOCOL_CALLBACK(hotlist) +{ + cJSON *json; + struct t_gui_hotlist *ptr_hotlist; + + json = cJSON_CreateArray (); + if (!json) + return WEECHAT_RC_ERROR; + + ptr_hotlist = weechat_hdata_get_list (relay_hdata_hotlist, "gui_hotlist"); + while (ptr_hotlist) + { + cJSON_AddItemToArray ( + json, + relay_api_msg_hotlist_to_json (ptr_hotlist)); + ptr_hotlist = weechat_hdata_move (relay_hdata_hotlist, ptr_hotlist, 1); + } + + relay_api_msg_send_json (client, RELAY_HTTP_200_OK, json); + cJSON_Delete (json); + return WEECHAT_RC_OK; +} + +/* * Callback for resource "input". * * Routes: @@ -770,6 +800,7 @@ relay_api_protocol_recv_http (struct t_relay_client *client) { "POST", "handshake", 0, 0, 0, &relay_api_protocol_cb_handshake }, { "GET", "version", 1, 0, 0, &relay_api_protocol_cb_version }, { "GET", "buffers", 1, 0, 3, &relay_api_protocol_cb_buffers }, + { "GET", "hotlist", 1, 0, 3, &relay_api_protocol_cb_hotlist }, { "POST", "input", 1, 0, 0, &relay_api_protocol_cb_input }, { "POST", "ping", 1, 0, 0, &relay_api_protocol_cb_ping }, { "POST", "sync", 1, 0, 0, &relay_api_protocol_cb_sync }, diff --git a/src/plugins/relay/relay.c b/src/plugins/relay/relay.c index ca22dad69..debce9167 100644 --- a/src/plugins/relay/relay.c +++ b/src/plugins/relay/relay.c @@ -57,6 +57,7 @@ struct t_hdata *relay_hdata_nick_group = NULL; struct t_hdata *relay_hdata_nick = NULL; struct t_hdata *relay_hdata_completion = NULL; struct t_hdata *relay_hdata_completion_word = NULL; +struct t_hdata *relay_hdata_hotlist = NULL; int relay_signal_upgrade_received = 0; /* signal "upgrade" received ? */ @@ -220,6 +221,7 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) relay_hdata_nick = weechat_hdata_get ("nick"); relay_hdata_completion = weechat_hdata_get ("completion"); relay_hdata_completion_word = weechat_hdata_get ("completion_word"); + relay_hdata_hotlist = weechat_hdata_get ("hotlist"); relay_signal_upgrade_received = 0; diff --git a/src/plugins/relay/relay.h b/src/plugins/relay/relay.h index 70c743c6e..b2797f2ab 100644 --- a/src/plugins/relay/relay.h +++ b/src/plugins/relay/relay.h @@ -34,6 +34,7 @@ extern struct t_hdata *relay_hdata_nick_group; extern struct t_hdata *relay_hdata_nick; extern struct t_hdata *relay_hdata_completion; extern struct t_hdata *relay_hdata_completion_word; +extern struct t_hdata *relay_hdata_hotlist; extern int relay_signal_upgrade_received; |