From 4f9bcc73ca93194b59f41aca844e6cc22172e241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sun, 10 Mar 2024 10:15:41 +0100 Subject: relay/api: allow POST /api/handshake without a body --- src/plugins/relay/api/relay-api-protocol.c | 40 ++++++++++++++++-------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'src/plugins/relay') diff --git a/src/plugins/relay/api/relay-api-protocol.c b/src/plugins/relay/api/relay-api-protocol.c index 6f75b96f8..83be148c1 100644 --- a/src/plugins/relay/api/relay-api-protocol.c +++ b/src/plugins/relay/api/relay-api-protocol.c @@ -234,30 +234,30 @@ RELAY_API_PROTOCOL_CALLBACK(handshake) char *totp_secret; int hash_algo_found, index_hash_algo; - json_body = cJSON_Parse(client->http_req->body); - if (!json_body) - return WEECHAT_RC_ERROR; - hash_algo_found = -1; - json_algos = cJSON_GetObjectItem (json_body, "password_hash_algo"); - if (json_algos) + json_body = cJSON_Parse(client->http_req->body); + if (json_body) { - cJSON_ArrayForEach(json_algo, json_algos) + json_algos = cJSON_GetObjectItem (json_body, "password_hash_algo"); + if (json_algos) { - ptr_algo = (cJSON_IsString (json_algo)) ? - cJSON_GetStringValue (json_algo) : NULL; - if (ptr_algo) + cJSON_ArrayForEach(json_algo, json_algos) { - index_hash_algo = relay_auth_password_hash_algo_search (ptr_algo); - if ((index_hash_algo >= 0) && (index_hash_algo > hash_algo_found)) + ptr_algo = (cJSON_IsString (json_algo)) ? + cJSON_GetStringValue (json_algo) : NULL; + if (ptr_algo) { - if (weechat_string_match_list ( - relay_auth_password_hash_algo_name[index_hash_algo], - (const char **)relay_config_network_password_hash_algo_list, - 1)) + index_hash_algo = relay_auth_password_hash_algo_search (ptr_algo); + if ((index_hash_algo >= 0) && (index_hash_algo > hash_algo_found)) { - hash_algo_found = index_hash_algo; + if (weechat_string_match_list ( + relay_auth_password_hash_algo_name[index_hash_algo], + (const char **)relay_config_network_password_hash_algo_list, + 1)) + { + hash_algo_found = index_hash_algo; + } } } } @@ -267,7 +267,8 @@ RELAY_API_PROTOCOL_CALLBACK(handshake) json = cJSON_CreateObject (); if (!json) { - cJSON_Delete (json_body); + if (json_body) + cJSON_Delete (json_body); return WEECHAT_RC_ERROR; } @@ -293,7 +294,8 @@ RELAY_API_PROTOCOL_CALLBACK(handshake) free (totp_secret); cJSON_Delete (json); - cJSON_Delete (json_body); + if (json_body) + cJSON_Delete (json_body); return WEECHAT_RC_OK; } -- cgit v1.2.3