diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-03-31 16:26:17 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-04-07 13:18:13 +0200 |
commit | 9d7e887d8e9122114ca43fa0fa7440fd1cd221ab (patch) | |
tree | ac56def513a6d313be5709256b7f8c13d89a4728 /src/plugins/relay/api | |
parent | 643adecff5b2d16679e106dce771cb111f338a42 (diff) | |
download | weechat-9d7e887d8e9122114ca43fa0fa7440fd1cd221ab.zip |
relay/api: add "body_type" in response when a body is set and connected via websocket (issue #2066)
Diffstat (limited to 'src/plugins/relay/api')
-rw-r--r-- | src/plugins/relay/api/relay-api-msg.c | 21 | ||||
-rw-r--r-- | src/plugins/relay/api/relay-api-msg.h | 3 | ||||
-rw-r--r-- | src/plugins/relay/api/relay-api-protocol.c | 36 |
3 files changed, 32 insertions, 28 deletions
diff --git a/src/plugins/relay/api/relay-api-msg.c b/src/plugins/relay/api/relay-api-msg.c index cb87d7045..6f5cc30c6 100644 --- a/src/plugins/relay/api/relay-api-msg.c +++ b/src/plugins/relay/api/relay-api-msg.c @@ -115,9 +115,9 @@ relay_api_msg_send_json_internal (struct t_relay_client *client, int return_code, const char *message, const char *event_name, - const char *event_type, struct t_gui_buffer *event_buffer, const char *headers, + const char *body_type, cJSON *json_body) { cJSON *json, *json_event; @@ -150,9 +150,6 @@ relay_api_msg_send_json_internal (struct t_relay_client *client, cJSON_AddItemToObject ( json_event, "name", cJSON_CreateString ((event_name) ? event_name : "")); - cJSON_AddItemToObject ( - json_event, "type", - cJSON_CreateString ((event_type) ? event_type : "")); id = -1; if (event_buffer) { @@ -168,7 +165,12 @@ relay_api_msg_send_json_internal (struct t_relay_client *client, cJSON_AddItemToObject (json, "event", json_event); } } - cJSON_AddItemToObject (json, "body", json_body); + if (json_body) + { + cJSON_AddItemToObject (json, "body_type", + cJSON_CreateString ((body_type) ? body_type : "")); + cJSON_AddItemToObject (json, "body", json_body); + } string = cJSON_PrintUnformatted (json); num_bytes = relay_client_send ( client, @@ -204,15 +206,16 @@ int relay_api_msg_send_json (struct t_relay_client *client, int return_code, const char *message, + const char *body_type, cJSON *json_body) { return relay_api_msg_send_json_internal (client, return_code, message, NULL, /* event_name */ - NULL, /* event_type */ NULL, /* event_buffer */ NULL, /* headers */ + body_type, json_body); } @@ -257,9 +260,9 @@ relay_api_msg_send_error_json (struct t_relay_client *client, return_code, message, NULL, /* event_name */ - NULL, /* event_type */ NULL, /* event_buffer */ headers, + NULL, /* body_type */ json); cJSON_Delete (json); } @@ -295,16 +298,16 @@ relay_api_msg_send_error_json (struct t_relay_client *client, int relay_api_msg_send_event (struct t_relay_client *client, const char *name, - const char *type, struct t_gui_buffer *buffer, + const char *body_type, cJSON *json_body) { return relay_api_msg_send_json_internal (client, RELAY_API_HTTP_0_EVENT, name, - type, buffer, NULL, /* headers */ + body_type, json_body); } diff --git a/src/plugins/relay/api/relay-api-msg.h b/src/plugins/relay/api/relay-api-msg.h index 41b5d307a..686918865 100644 --- a/src/plugins/relay/api/relay-api-msg.h +++ b/src/plugins/relay/api/relay-api-msg.h @@ -25,6 +25,7 @@ enum t_relay_api_colors; extern int relay_api_msg_send_json (struct t_relay_client *client, int return_code, const char *message, + const char *body_type, cJSON *json_body); extern int relay_api_msg_send_error_json (struct t_relay_client *client, int return_code, @@ -33,8 +34,8 @@ extern int relay_api_msg_send_error_json (struct t_relay_client *client, const char *format, ...); extern int relay_api_msg_send_event (struct t_relay_client *client, const char *name, - const char *type, struct t_gui_buffer *buffer, + const char *body_type, cJSON *json_body); extern cJSON *relay_api_msg_buffer_to_json (struct t_gui_buffer *buffer, long lines, diff --git a/src/plugins/relay/api/relay-api-protocol.c b/src/plugins/relay/api/relay-api-protocol.c index b907de441..46a47c180 100644 --- a/src/plugins/relay/api/relay-api-protocol.c +++ b/src/plugins/relay/api/relay-api-protocol.c @@ -103,7 +103,7 @@ relay_api_protocol_signal_buffer_cb (const void *pointer, void *data, ptr_buffer, lines, 0, RELAY_API_DATA(ptr_client, sync_colors)); if (json) { - relay_api_msg_send_event (ptr_client, signal, "buffer", NULL, json); + relay_api_msg_send_event (ptr_client, signal, NULL, "buffer", json); cJSON_Delete (json); } } @@ -127,8 +127,8 @@ relay_api_protocol_signal_buffer_cb (const void *pointer, void *data, ptr_line_data, RELAY_API_DATA(ptr_client, sync_colors)); if (json) { - relay_api_msg_send_event (ptr_client, signal, "line", ptr_buffer, - json); + relay_api_msg_send_event (ptr_client, signal, ptr_buffer, + "line", json); cJSON_Delete (json); } } @@ -174,8 +174,8 @@ relay_api_protocol_hsignal_nicklist_cb (const void *pointer, void *data, json = relay_api_msg_nick_group_to_json (ptr_group); if (json) { - relay_api_msg_send_event (ptr_client, signal, "nick_group", - ptr_buffer, json); + relay_api_msg_send_event (ptr_client, signal, ptr_buffer, + "nick_group", json); cJSON_Delete (json); } } @@ -186,8 +186,8 @@ relay_api_protocol_hsignal_nicklist_cb (const void *pointer, void *data, json = relay_api_msg_nick_to_json (ptr_nick); if (json) { - relay_api_msg_send_event (ptr_client, signal, "nick", ptr_buffer, - json); + relay_api_msg_send_event (ptr_client, signal, ptr_buffer, + "nick", json); cJSON_Delete (json); } } @@ -295,7 +295,7 @@ RELAY_API_PROTOCOL_CALLBACK(handshake) cJSON_AddItemToObject (json, "totp", cJSON_CreateBool ((totp_secret && totp_secret[0]) ? 1 : 0)); - relay_api_msg_send_json (client, RELAY_HTTP_200_OK, json); + relay_api_msg_send_json (client, RELAY_HTTP_200_OK, "handshake", json); free (totp_secret); cJSON_Delete (json); @@ -349,7 +349,7 @@ RELAY_API_PROTOCOL_CALLBACK(version) "relay_api_version_number", cJSON_CreateNumber (RELAY_API_VERSION_NUMBER)); - relay_api_msg_send_json (client, RELAY_HTTP_200_OK, json); + relay_api_msg_send_json (client, RELAY_HTTP_200_OK, "version", json); cJSON_Delete (json); @@ -448,7 +448,7 @@ RELAY_API_PROTOCOL_CALLBACK(buffers) if (!json) goto error; - relay_api_msg_send_json (client, RELAY_HTTP_200_OK, json); + relay_api_msg_send_json (client, RELAY_HTTP_200_OK, "buffer", json); cJSON_Delete (json); return WEECHAT_RC_OK; @@ -485,7 +485,7 @@ RELAY_API_PROTOCOL_CALLBACK(hotlist) ptr_hotlist = weechat_hdata_move (relay_hdata_hotlist, ptr_hotlist, 1); } - relay_api_msg_send_json (client, RELAY_HTTP_200_OK, json); + relay_api_msg_send_json (client, RELAY_HTTP_200_OK, "hotlist", json); cJSON_Delete (json); return WEECHAT_RC_OK; } @@ -610,7 +610,7 @@ RELAY_API_PROTOCOL_CALLBACK(input) weechat_hashtable_free (options); cJSON_Delete (json_body); - relay_api_msg_send_json (client, RELAY_HTTP_204_NO_CONTENT, NULL); + relay_api_msg_send_json (client, RELAY_HTTP_204_NO_CONTENT, NULL, NULL); return WEECHAT_RC_OK; } @@ -646,13 +646,13 @@ RELAY_API_PROTOCOL_CALLBACK(ping) } cJSON_AddItemToObject (json, "data", cJSON_CreateString ((ptr_data) ? ptr_data : "")); - relay_api_msg_send_json (client, RELAY_HTTP_200_OK, json); + relay_api_msg_send_json (client, RELAY_HTTP_200_OK, "ping", json); cJSON_Delete (json); cJSON_Delete (json_body); } else { - relay_api_msg_send_json (client, RELAY_HTTP_204_NO_CONTENT, NULL); + relay_api_msg_send_json (client, RELAY_HTTP_204_NO_CONTENT, NULL, NULL); } return WEECHAT_RC_OK; @@ -703,7 +703,7 @@ RELAY_API_PROTOCOL_CALLBACK(sync) else relay_api_unhook_signals (client); - relay_api_msg_send_json (client, RELAY_HTTP_204_NO_CONTENT, NULL); + relay_api_msg_send_json (client, RELAY_HTTP_204_NO_CONTENT, NULL, NULL); return WEECHAT_RC_OK; } @@ -781,7 +781,7 @@ relay_api_protocol_recv_json (struct t_relay_client *client, const char *json) goto end; error: - relay_api_msg_send_json (client, RELAY_HTTP_400_BAD_REQUEST, NULL); + relay_api_msg_send_json (client, RELAY_HTTP_400_BAD_REQUEST, NULL, NULL); end: if (json_obj) @@ -902,11 +902,11 @@ relay_api_protocol_recv_http (struct t_relay_client *client) goto error404; error400: - relay_api_msg_send_json (client, RELAY_HTTP_400_BAD_REQUEST, NULL); + relay_api_msg_send_json (client, RELAY_HTTP_400_BAD_REQUEST, NULL, NULL); goto error; error404: - relay_api_msg_send_json (client, RELAY_HTTP_404_NOT_FOUND, NULL); + relay_api_msg_send_json (client, RELAY_HTTP_404_NOT_FOUND, NULL, NULL); goto error; error: |