1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-06 09:43:13 +02:00

relay/api: always set "body_type" and "body" (null if there is no body) in websocket frame

This commit is contained in:
Sébastien Helleu
2024-06-29 19:37:44 +02:00
parent 2184af9d99
commit f8f6e100d0
5 changed files with 63 additions and 36 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
### Changed
- **breaking:** relay: flatten JSON event object sent to api relay clients
- **breaking:** relay/api: flatten JSON event object sent to clients, always set "body_type" and "body" (null if there is no body) in websocket frame
- **breaking:** core, plugins: force "short_name" in buffers to non-empty value (name by default), remove buffer property "short_name_is_set"
- **breaking:** alias: display an error with `/alias add` or `/alias addcompletion` when the alias already exists, add options `addreplace` and `addreplacecompletion` in command `/alias` ([#2095](https://github.com/weechat/weechat/issues/2095))
- **breaking:** irc: rename parameter `-re` to `-raw` in command `/list` ([#2124](https://github.com/weechat/weechat/issues/2124))
+25 -13
View File
@@ -1276,7 +1276,13 @@ Response:
----
{
"code": 204,
"message": "No Content"
"message": "No Content",
"request": "POST /api/sync",
"request_body": {
"nicks":false
},
"body_type": null,
"body": null
}
----
@@ -1376,11 +1382,9 @@ Responses to client are made with a JSON object containing these fields:
* `message` (string): message for the code (example: `OK`)
* `request` (string): the request (example: `GET /api/buffers?lines=-100`)
* `request_body` (object): the request body, or `null` if the request had no body
When the response has a body, these two extra fields are returned:
* `body_type` (string): type of objects returned in body (see below)
* `body` (object or array): the body returned
* `body_type` (string): type of objects returned in body (see below), or `null`
if the response has no body
* `body` (object or array): the body returned, or `null` if the response has no body
Body types that can be returned:
@@ -1446,7 +1450,9 @@ Response:
"request_body": {
"buffer_name": "irc.libera.#weechat",
"command": "hello!"
}
},
"body_type": null,
"body": null
}
----
@@ -1480,13 +1486,13 @@ The following events are sent to the client, according to synchronization option
| `buffer_localvar_removed` | buffer id | `buffer` | buffer
| `buffer_cleared` | buffer id | `buffer` | buffer
| `buffer_closing` | buffer id | `buffer` | buffer
| `buffer_closed` | buffer id | (not defined) | (not defined)
| `buffer_closed` | buffer id | null | null
| `buffer_line_added` | buffer id | `line` | buffer line
| `buffer_line_data_changed` | buffer id | `line` | buffer line
| `input_text_changed` | buffer id | `buffer` | buffer
| `input_text_cursor_moved` | buffer id | `buffer` | buffer
| `upgrade` ^(1)^ | -1 | (not defined) | (not defined)
| `upgrade_ended` ^(1)^ | -1 | (not defined) | (not defined)
| `upgrade` ^(1)^ | -1 | null | null
| `upgrade_ended` ^(1)^ | -1 | null | null
| `nicklist_group_changed` | buffer id | `nick_group` | nick group
| `nicklist_group_added` | buffer id | `nick_group` | nick group
| `nicklist_group_removing` | buffer id | `nick_group` | nick group
@@ -1605,7 +1611,9 @@ Example: channel buffer `#weechat` has been closed:
"code": 0,
"message": "Event",
"event_name": "buffer_closed",
"buffer_id": 1709932823649069
"buffer_id": 1709932823649069,
"body_type": null,
"body": null
}
----
@@ -1617,7 +1625,9 @@ Example: WeeChat is upgrading:
"code": 0,
"message": "Event",
"event_name": "upgrade",
"buffer_id": -1
"buffer_id": -1,
"body_type": null,
"body": null
}
----
@@ -1629,6 +1639,8 @@ Example: upgrade of WeeChat is done:
"code": 0,
"message": "Event",
"event_name": "upgrade_ended",
"buffer_id": -1
"buffer_id": -1,
"body_type": null,
"body": null
}
----
+26 -13
View File
@@ -1297,7 +1297,13 @@ Réponse :
----
{
"code": 204,
"message": "No Content"
"message": "No Content",
"request": "POST /api/sync",
"request_body": {
"nicks": false
},
"body_type": null,
"body": null
}
----
@@ -1401,11 +1407,10 @@ les champs suivants :
* `request` (chaîne) : la requête (exemple : `GET /api/buffers?lines=-100`)
* `request_body` (objet) : le corps de la requête, ou `null` si la requête
n'avait pas de corps
Lorsque la réponse a un corps, ces deux champs supplémentaires sont retournés :
* `body_type` (chaîne) : type des objets retournés dans le corps (voir ci-dessous)
* `body` (objet ou tableau) : le corps retourné
* `body_type` (chaîne) : type des objets retournés dans le corps (voir ci-dessous),
ou `null` si la réponse n'a pas de corps
* `body` (objet ou tableau) : le corps retourné, ou `null` si la réponse n'a pas
de corps
Les types de corps qui peuvent être retournés :
@@ -1471,7 +1476,9 @@ Réponse :
"request_body": {
"buffer_name": "irc.libera.#weechat",
"command": "hello!"
}
},
"body_type": null,
"body": null
}
----
@@ -1506,13 +1513,13 @@ Les évènements suivants sont envoyés au client, selon les options de synchron
| `buffer_localvar_removed` | id tampon | `buffer` | tampon
| `buffer_cleared` | id tampon | `buffer` | tampon
| `buffer_closing` | id tampon | `buffer` | tampon
| `buffer_closed` | id tampon | (non défini) | (non défini)
| `buffer_closed` | id tampon | null | null
| `buffer_line_added` | id tampon | `line` | ligne de tampon
| `buffer_line_data_changed` | id tampon | `line` | ligne de tampon
| `input_text_changed` | id tampon | `buffer` | tampon
| `input_text_cursor_moved` | id tampon | `buffer` | tampon
| `upgrade` ^(1)^ | -1 | (non défini) | (non défini)
| `upgrade_ended` ^(1)^ | -1 | (non défini) | (non défini)
| `upgrade` ^(1)^ | -1 | null | null
| `upgrade_ended` ^(1)^ | -1 | null | null
| `nicklist_group_changed` | id tampon | `nick_group` | groupe de pseudos
| `nicklist_group_added` | id tampon | `nick_group` | groupe de pseudos
| `nicklist_group_removing` | id tampon | `nick_group` | groupe de pseudos
@@ -1632,7 +1639,9 @@ Exemple : le tampon du canal `#weechat` a été fermé :
"code": 0,
"message": "Event",
"event_name": "buffer_closed",
"buffer_id": 1709932823649069
"buffer_id": 1709932823649069,
"body_type": null,
"body": null
}
----
@@ -1644,7 +1653,9 @@ Exemple : WeeChat est en cours de mise à jour :
"code": 0,
"message": "Event",
"event_name": "upgrade",
"buffer_id": -1
"buffer_id": -1,
"body_type": null,
"body": null
}
----
@@ -1656,6 +1667,8 @@ Exemple : la mise à jour de WeeChat est terminée :
"code": 0,
"message": "Event",
"event_name": "upgrade_ended",
"buffer_id": -1
"buffer_id": -1,
"body_type": null,
"body": null
}
----
+8 -8
View File
@@ -174,17 +174,17 @@ relay_api_msg_send_json_internal (struct t_relay_client *client,
cJSON_AddItemToObject (
json, "request_body",
(client->http_req->body) ?
cJSON_Parse (client->http_req->body) :cJSON_CreateNull ());
cJSON_Parse (client->http_req->body) : cJSON_CreateNull ());
free (request);
}
}
if (body_type)
{
cJSON_AddItemToObject (json, "body_type",
cJSON_CreateString (body_type));
}
if (json_body)
cJSON_AddItemToObject (json, "body", json_body);
cJSON_AddItemToObject (
json, "body_type",
(body_type) ?
cJSON_CreateString (body_type) : cJSON_CreateNull ());
cJSON_AddItemToObject (
json, "body",
(json_body) ? json_body : cJSON_CreateNull ());
string = cJSON_PrintUnformatted (json);
num_bytes = relay_client_send (
client,
@@ -58,7 +58,9 @@ extern int relay_api_protocol_command_delay;
STRCMP_EQUAL("{\"code\":" #__code "," \
"\"message\":\"" __message "\"," \
"\"request\":\"" __request "\"," \
"\"request_body\":" __body "" \
"\"request_body\":" __body "," \
"\"body_type\":null," \
"\"body\":null" \
"}", \
data_sent);