diff options
author | jpadkins <jacobpadkins@gmail.com> | 2017-04-10 22:02:01 +0300 |
---|---|---|
committer | jpadkins <jacobpadkins@gmail.com> | 2017-04-10 22:02:01 +0300 |
commit | fe6071262f960549622d64a3d2afc174bfbb8a0f (patch) | |
tree | bb79c894294615382f30283c9ba80e383e0be65e /check/magma | |
parent | 61a3312c43620993b8910dd3d5a178c5f6e394da (diff) |
Fixed the check_camel_json_write function.
Diffstat (limited to 'check/magma')
-rw-r--r-- | check/magma/servers/camel/camel_check_network.c | 249 |
1 files changed, 88 insertions, 161 deletions
diff --git a/check/magma/servers/camel/camel_check_network.c b/check/magma/servers/camel/camel_check_network.c index 46cad72e..56dcb464 100644 --- a/check/magma/servers/camel/camel_check_network.c +++ b/check/magma/servers/camel/camel_check_network.c @@ -21,9 +21,6 @@ bool_t check_camel_status(client_t *client) { if (client_read_line(client) <= 2) return false; } - chr_t *foo = pl_char_get(client->line); - (void)foo; - return ((*(pl_char_get(client->line) + 9) == '2') ? true : false); } @@ -85,11 +82,9 @@ bool_t check_camel_json_write(client_t *client, stringer_t *json, stringer_t *co "Content-Type: application/x-www-form-urlencoded\r\nCookie: portal=%.*s;\r\nConnection: %s\r\n\r\n%.*s\r\n\r\n"; if (client_print(client, message, st_length_get(json), st_length_int(cookie), (cookie ? st_char_get(cookie) : ""), - (keep_alive ? "keep-alive" : "close"), st_length_int(json), st_char_get(json)) != (ns_length_get(message) - 10 + - st_length_get(json) + (cookie ? st_length_get(cookie) : 0) + (keep_alive ? 10 : 5)) || client_status(client) != 1) { + (keep_alive ? "keep-alive" : "close"), st_length_int(json), st_char_get(json)) != (ns_length_get(message) - 12 + + st_length_get(json) + uint32_digits(st_length_int(json)) + (cookie ? st_length_get(cookie) : 0) + (keep_alive ? 10 : 5))) { - uint32_t foo = (ns_length_get(message) - 10 + st_length_get(json) + (cookie ? st_length_get(cookie) : 0) + (keep_alive ? 10 : 5)); - (void)foo; return false; } @@ -119,8 +114,8 @@ bool_t check_camel_login(client_t *client, uint32_t id, stringer_t *user, string if (client_print(client, st_char_get(message), length, id, st_length_int(user), st_char_get(user), st_length_int(pass), st_char_get(pass)) != ((st_length_get(message) - 12) + uint32_digits(length) + uint32_digits(id) + st_length_get(user) + - st_length_get(pass)) || client_status(client) != 1 || !check_camel_status(client) || - !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length))) { + st_length_get(pass)) || !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) || + !(json = check_camel_json_read(client, content_length))) { return false; } @@ -170,70 +165,70 @@ bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) { json_error_t json_err; client_t *client = NULL; const chr_t *json_value = NULL; - uint32_t content_length = 0;//, folderids[]; - json_t *json_objs[4] = { NULL, NULL, NULL, NULL }; + json_t *json_objs[4] = { [ 0 ... 3] NULL }; + uint32_t content_length = 0;//, folderids[2] = { 0, 0 }; chr_t *choices = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - stringer_t *cookie = MANAGEDBUF(1024), *command = NULL, *rand_strs[2] = { NULL, NULL }, *json = NULL, - *commands[] = { - PLACER("{\"id\":2,\"method\":\"config.edit\",\"params\":{\"%.*s\":\"%.*s\"}}", 68), - PLACER("{\"id\":3,\"method\":\"config.load\"}", 37), - PLACER("{\"id\":4,\"method\":\"config.edit\",\"params\":{\"%.*s\":null}}", 64), - PLACER("{\"id\":5,\"method\":\"config.load\"}", 37), - PLACER("{\"id\":6,\"method\":\"config.edit\",\"params\":{\"%.*s\":\"%.*s\"}}", 68), - PLACER("{\"id\":7,\"method\":\"folders.add\",\"params\":{\"context\":\"contacts\",\"name\":\"%.*s\"}}", 93), - PLACER("{\"id\":8,\"method\":\"folders.list\",\"params\":{\"context\":\"contacts\"}}", 76), - PLACER("{\"id\":9,\"method\":\"contacts.add\",\"params\":{\"folderID\":%u, \"contact\":{\"name\":\"%.*s\", \"email\":\"%.*s\"}}}", 120), - PLACER("{\"id\":10,\"method\":\"contacts.copy\",\"params\":{\"sourceFolderID\":%u, \"targetFolderID\":%u, \"contactID\":%u}}", 116), - PLACER("{\"id\":11,\"method\":\"contacts.list\",\"params\":{\"folderID\":%u}}", 69), - PLACER("{\"id\":12,\"method\":\"contacts.edit\",\"params\":{\"folderID\":%u, \"contactID\":%u, \"contact\":{\"name\":\"%.*s\", \"email\":\"%.*s\"}}}", 140), - PLACER("{\"id\":13,\"method\":\"contacts.load\",\"params\":{\"folderID\":%u, \"contactID\":%u }}", 88), - PLACER("{\"id\":14,\"method\":\"contacts.edit\",\"params\":{\"folderID\":%u, \"contactID\":%u, \"contact\":{\"name\":\"%.*s\", \"email\":\"%.*s\", \"phone\":\"%u\", \"notes\":\"%.*s\"}}}", 178), - PLACER("{\"id\":15,\"method\":\"contacts.load\",\"params\":{\"folderID\":%u, \"contactID\":%u}}", 87), - PLACER("{\"id\":16,\"method\":\"folders.add\",\"params\":{\"context\":\"contacts\",\"name\":\"%.*s\"}}", 94), - PLACER("{\"id\":17,\"method\":\"contacts.move\",\"params\":{ \"contactID\":%u, \"sourceFolderID\":%u, \"targetFolderID\":%u}}", 117), - PLACER("{\"id\":18,\"method\":\"contacts.list\",\"params\":{\"folderID\":%u}}", 69), - PLACER("{\"id\":19,\"method\":\"contacts.list\",\"params\":{\"folderID\":%u}}", 69), - PLACER("{\"id\":20,\"method\":\"contacts.remove\",\"params\":{\"folderID\":%u, \"contactID\":%u}}", 89), - PLACER("{\"id\":21,\"method\":\"contacts.remove\",\"params\":{\"folderID\":%u, \"contactID\":%u}}", 89), - PLACER("{\"id\":22,\"method\":\"contacts.list\",\"params\":{\"folderID\":%u}}", 69), - PLACER("{\"id\":23,\"method\":\"folders.remove\",\"params\":{\"context\":\"contacts\",\"folderID\":%u}}", 95), - PLACER("{\"id\":24,\"method\":\"folders.remove\",\"params\":{\"context\":\"contacts\",\"folderID\":%u}}", 95), - PLACER("{\"id\":25,\"method\":\"cookies\"}", 34), - PLACER("{\"id\":26,\"method\":\"alert.list\"}", 37), - PLACER("{\"id\":27,\"method\":\"alert.acknowledge\",\"params\":[1,7,13]}", 64), - PLACER("{\"id\":28,\"method\":\"alert.list\"}", 37), - PLACER("{\"id\":29,\"method\":\"folders.list\",\"params\":{\"context\":\"mail\"}}", 73), - PLACER("{\"id\":30,\"method\":\"folders.list\",\"params\":{\"context\":\"settings\"}}", 77), - PLACER("{\"id\":31,\"method\":\"folders.list\",\"params\":{\"context\":\"help\"}}", 73), - PLACER("{\"id\":32,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"%.*s\"}}", 90), - PLACER("{\"id\":33,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"parentID\":,\"name\":\"%.*s\"}}", 104), - PLACER("{\"id\":34,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"parentID\":,\"name\":\"%.*s\"}}", 104), - PLACER("{\"id\":35,\"method\":\"folders.rename\",\"params\":{\"context\":\"mail\",\"folderID\":,\"name\":\"%.*s\"}}", 107), - PLACER("{\"id\":36,\"method\":\"folders.rename\",\"params\":{\"context\":\"mail\",\"folderID\":,\"name\":\"%.*s\"}}", 107), - PLACER("{\"id\":37,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91), - PLACER("{\"id\":38,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91), - PLACER("{\"id\":39,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91), - PLACER("{\"id\":40,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91), - PLACER("{\"id\":41,\"method\":\"aliases\"}", 34), - PLACER("{\"id\":42,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"%.*s\"}}", 90), - PLACER("{\"id\":43,\"method\":\"messages.copy\",\"params\":{\"messageIDs\":[%u], \"sourceFolderID\":%u, \"targetFolderID\":%u}}", 119), - PLACER("{\"id\":44,\"method\":\"messages.copy\",\"params\":{\"messageIDs\":[%u], \"sourceFolderID\":%u, \"targetFolderID\":%u}}", 119), - PLACER("{\"id\":45,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91), - PLACER("{\"id\":46,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"%.*s\"}}", 90), - PLACER("{\"id\":47,\"method\":\"messages.load\",\"params\":{\"messageID\":%u, \"folderID\":%u, \"sections\": [\"meta\", \"source\", \"security\", \"server\", \"header\", \"body\", \"attachments\"]}}", 190), - PLACER("{\"id\":48,\"method\":\"messages.copy\",\"params\":{\"messageIDs\":[%u], \"sourceFolderID\":%u, \"targetFolderID\":%u}}", 119), - PLACER("{\"id\":49,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91), - PLACER("{\"id\":50,\"method\":\"messages.flag\",\"params\":{\"action\":\"add\", \"flags\":[\"flagged\"], \"messageIDs\": [%u], \"folderID\":%u}}", 136), - PLACER("{\"id\":51,\"method\":\"messages.tags\",\"params\":{\"action\":\"add\", \"tags\":[\"girlie\",\"girlie-6169\"], \"messageIDs\": [%u], \"folderID\":%u}}", 150), - PLACER("{\"id\":52,\"method\":\"messages.flag\",\"params\":{\"action\":\"list\", \"messageIDs\":[%u], \"folderID\":%u}}", 111), - PLACER("{\"id\":53,\"method\":\"messages.tags\",\"params\":{\"action\":\"list\", \"messageIDs\":[%u], \"folderID\":%u}}", 111), - PLACER("{\"id\":54,\"method\":\"messages.list\",\"params\":{\"folderID\":%u}}", 69), - PLACER("{\"id\":55,\"method\":\"folders.tags\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 89), - PLACER("{\"id\":56,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"Mover\"}}", 91), - PLACER("{\"id\":57,\"method\":\"messages.move\",\"params\":{\"messageIDs\":[%u], \"sourceFolderID\":%u, \"targetFolderID\":%u}}", 119), - PLACER("{\"id\":58,\"method\":\"messages.remove\",\"params\":{\"folderID\":%u,\"messageIDs\":[%u]}}", 91), - PLACER("{\"id\":59,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", 91), - PLACER("{\"id\":60,\"method\":\"logout\"}", 33) + stringer_t *cookie = MANAGEDBUF(1024), *command = MANAGEDBUF(8192), *rand_strs[2] = { MANAGEDBUF(64), MANAGEDBUF(64) }, *json = NULL; + chr_t *commands[] = { + "{\"id\":2,\"method\":\"config.edit\",\"params\":{\"%.*s\":\"%.*s\"}}", + "{\"id\":3,\"method\":\"config.load\"}", + "{\"id\":4,\"method\":\"config.edit\",\"params\":{\"%.*s\":null}}", + "{\"id\":5,\"method\":\"config.load\"}", + "{\"id\":6,\"method\":\"config.edit\",\"params\":{\"%.*s\":\"%.*s\"}}", + "{\"id\":7,\"method\":\"folders.add\",\"params\":{\"context\":\"contacts\",\"name\":\"%.*s\"}}", + "{\"id\":8,\"method\":\"folders.list\",\"params\":{\"context\":\"contacts\"}}", + "{\"id\":9,\"method\":\"contacts.add\",\"params\":{\"folderID\":%u, \"contact\":{\"name\":\"%.*s\", \"email\":\"%.*s\"}}}", + "{\"id\":10,\"method\":\"contacts.copy\",\"params\":{\"sourceFolderID\":%u, \"targetFolderID\":%u, \"contactID\":%u}}", + "{\"id\":11,\"method\":\"contacts.list\",\"params\":{\"folderID\":%u}}", + "{\"id\":12,\"method\":\"contacts.edit\",\"params\":{\"folderID\":%u, \"contactID\":%u, \"contact\":{\"name\":\"%.*s\", \"email\":\"%.*s\"}}}", + "{\"id\":13,\"method\":\"contacts.load\",\"params\":{\"folderID\":%u, \"contactID\":%u }}", + "{\"id\":14,\"method\":\"contacts.edit\",\"params\":{\"folderID\":%u, \"contactID\":%u, \"contact\":{\"name\":\"%.*s\", \"email\":\"%.*s\", \"phone\":\"%u\", \"notes\":\"%.*s\"}}}", + "{\"id\":15,\"method\":\"contacts.load\",\"params\":{\"folderID\":%u, \"contactID\":%u}}", + "{\"id\":16,\"method\":\"folders.add\",\"params\":{\"context\":\"contacts\",\"name\":\"%.*s\"}}", + "{\"id\":17,\"method\":\"contacts.move\",\"params\":{ \"contactID\":%u, \"sourceFolderID\":%u, \"targetFolderID\":%u}}", + "{\"id\":18,\"method\":\"contacts.list\",\"params\":{\"folderID\":%u}}", + "{\"id\":19,\"method\":\"contacts.list\",\"params\":{\"folderID\":%u}}", + "{\"id\":20,\"method\":\"contacts.remove\",\"params\":{\"folderID\":%u, \"contactID\":%u}}", + "{\"id\":21,\"method\":\"contacts.remove\",\"params\":{\"folderID\":%u, \"contactID\":%u}}", + "{\"id\":22,\"method\":\"contacts.list\",\"params\":{\"folderID\":%u}}", + "{\"id\":23,\"method\":\"folders.remove\",\"params\":{\"context\":\"contacts\",\"folderID\":%u}}", + "{\"id\":24,\"method\":\"folders.remove\",\"params\":{\"context\":\"contacts\",\"folderID\":%u}}", + "{\"id\":25,\"method\":\"cookies\"}", + "{\"id\":26,\"method\":\"alert.list\"}", + "{\"id\":27,\"method\":\"alert.acknowledge\",\"params\":[1,7,13]}", + "{\"id\":28,\"method\":\"alert.list\"}", + "{\"id\":29,\"method\":\"folders.list\",\"params\":{\"context\":\"mail\"}}", + "{\"id\":30,\"method\":\"folders.list\",\"params\":{\"context\":\"settings\"}}", + "{\"id\":31,\"method\":\"folders.list\",\"params\":{\"context\":\"help\"}}", + "{\"id\":32,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"%.*s\"}}", + "{\"id\":33,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"parentID\":,\"name\":\"%.*s\"}}", + "{\"id\":34,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"parentID\":,\"name\":\"%.*s\"}}", + "{\"id\":35,\"method\":\"folders.rename\",\"params\":{\"context\":\"mail\",\"folderID\":,\"name\":\"%.*s\"}}", + "{\"id\":36,\"method\":\"folders.rename\",\"params\":{\"context\":\"mail\",\"folderID\":,\"name\":\"%.*s\"}}", + "{\"id\":37,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", + "{\"id\":38,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", + "{\"id\":39,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", + "{\"id\":40,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", + "{\"id\":41,\"method\":\"aliases\"}", + "{\"id\":42,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"%.*s\"}}", + "{\"id\":43,\"method\":\"messages.copy\",\"params\":{\"messageIDs\":[%u], \"sourceFolderID\":%u, \"targetFolderID\":%u}}", + "{\"id\":44,\"method\":\"messages.copy\",\"params\":{\"messageIDs\":[%u], \"sourceFolderID\":%u, \"targetFolderID\":%u}}", + "{\"id\":45,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", + "{\"id\":46,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"%.*s\"}}", + "{\"id\":47,\"method\":\"messages.load\",\"params\":{\"messageID\":%u, \"folderID\":%u, \"sections\": [\"meta\", \"source\", \"security\", \"server\", \"header\", \"body\", \"attachments\"]}}", + "{\"id\":48,\"method\":\"messages.copy\",\"params\":{\"messageIDs\":[%u], \"sourceFolderID\":%u, \"targetFolderID\":%u}}", + "{\"id\":49,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", + "{\"id\":50,\"method\":\"messages.flag\",\"params\":{\"action\":\"add\", \"flags\":[\"flagged\"], \"messageIDs\": [%u], \"folderID\":%u}}", + "{\"id\":51,\"method\":\"messages.tags\",\"params\":{\"action\":\"add\", \"tags\":[\"girlie\",\"girlie-6169\"], \"messageIDs\": [%u], \"folderID\":%u}}", + "{\"id\":52,\"method\":\"messages.flag\",\"params\":{\"action\":\"list\", \"messageIDs\":[%u], \"folderID\":%u}}", + "{\"id\":53,\"method\":\"messages.tags\",\"params\":{\"action\":\"list\", \"messageIDs\":[%u], \"folderID\":%u}}", + "{\"id\":54,\"method\":\"messages.list\",\"params\":{\"folderID\":%u}}", + "{\"id\":55,\"method\":\"folders.tags\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", + "{\"id\":56,\"method\":\"folders.add\",\"params\":{\"context\":\"mail\",\"name\":\"Mover\"}}", + "{\"id\":57,\"method\":\"messages.move\",\"params\":{\"messageIDs\":[%u], \"sourceFolderID\":%u, \"targetFolderID\":%u}}", + "{\"id\":58,\"method\":\"messages.remove\",\"params\":{\"folderID\":%u,\"messageIDs\":[%u]}}", + "{\"id\":59,\"method\":\"folders.remove\",\"params\":{\"context\":\"mail\",\"folderID\":%u}}", + "{\"id\":60,\"method\":\"logout\"}" }; if (!(client = check_camel_connect(secure))) { @@ -248,38 +243,35 @@ bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Test config.edit : commands[0] - // JSON Command : {"id":2,"method":"config.edit","params":{<rand_strs[0]>:<rand_strs[1]}}" + // JSON Command : {"id":2,"method":"config.edit","params":{<rand_strs[0]>:<rand_strs[1]>}}" // Expected Response : {"jsonrpc":"2.0","result":{"config.edit":"success"},"id":2} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Generate the random inputs for "key" and "value". - if (!(rand_strs[0] = rand_choices(choices, 64, NULL)) || !(rand_strs[1] = rand_choices(choices, 64, NULL))) { + if (!rand_choices(choices, 64, rand_strs[0]) || !rand_choices(choices, 64, rand_strs[1])) { - st_sprint(errmsg, "Failed to create random inputs. { command = \"%.*s\" }", st_length_int(commands[0]), st_char_get(commands[0])); - st_cleanup(rand_strs[0], rand_strs[1]); + st_sprint(errmsg, "Failed to create random inputs. { command = \"%.*s\" }", ns_length_int(commands[0]), commands[0]); client_close(client); return false; } // Construct the command string. - else if (!(command = st_alloc(st_length_get(commands[0]) - 8 + st_length_get(rand_strs[0]) + st_length_get(rand_strs[1]))) || - !(st_quick(command, st_char_get(commands[0]), st_length_int(rand_strs[0]), st_char_get(rand_strs[0]), st_length_int(rand_strs[1]), + else if (!(st_sprint(command, commands[0], st_length_int(rand_strs[0]), st_char_get(rand_strs[0]), st_length_int(rand_strs[1]), st_char_get(rand_strs[1])))) { st_sprint(errmsg, "Failed to create command string. { command = \"%.*s\" }", st_length_int(command), st_char_get(command)); - st_cleanup(command, rand_strs[0], rand_strs[1]); client_close(client); return false; } // Submit the command and check the status of the response. if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, command, cookie, true) || - client_status(client) != 1 || !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) || + !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length))) { st_sprint(errmsg, "Failed to return a successful HTTP response. { command = \"%.*s\" }", st_length_int(command), st_char_get(command)); - st_cleanup(json, command, rand_strs[0], rand_strs[1]); client_close(client); + st_cleanup(json); return false; } @@ -290,8 +282,8 @@ bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) { st_sprint(errmsg, "Failed parsing the returned JSON. { command = \"%.*s\", json = \"%.*s\" }", st_length_int(command), st_char_get(command), st_length_int(json), st_char_get(json)); mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]); - st_cleanup(json, command, rand_strs[0], rand_strs[1]); client_close(client); + st_cleanup(json); return false; } @@ -301,13 +293,14 @@ bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) { st_sprint(errmsg, "Failed parsing the returned JSON. { command = \"%.*s\", json = \"%.*s\" }", st_length_int(command), st_char_get(command), st_length_int(json), st_char_get(json)); mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]); - st_cleanup(json, command, rand_strs[0], rand_strs[1]); client_close(client); + st_cleanup(json); return false; } // Clean up before the next check. - st_cleanup(json, command); + st_wipe(command); + st_cleanup(json); mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]); json = NULL; @@ -327,13 +320,13 @@ bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) { /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Submit the command and check the status of the response. - if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, commands[1], cookie, true) || - client_status(client) != 1 || !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) || + if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, PLACER(commands[1], ns_length_get(commands[1])), cookie, true) || + !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) || !(json = check_camel_json_read(client, content_length))) { - st_sprint(errmsg, "Failed to return a successful HTTP response. { command = \"%.*s\" }", st_length_int(commands[1]), st_char_get(commands[1])); - st_cleanup(json, rand_strs[0], rand_strs[1]); + st_sprint(errmsg, "Failed to return a successful HTTP response. { command = \"%.*s\" }", ns_length_int(commands[1]), commands[1]); client_close(client); + st_cleanup(json); return false; } @@ -343,98 +336,32 @@ bool_t check_camel_basic_sthread(bool_t secure, stringer_t *errmsg) { !(json_objs[3] = json_object_get_d(json_objs[2], "value")) || !(json_value = json_string_value_d(json_objs[3]))) { - st_sprint(errmsg, "Failed parsing the returned JSON. { command = \"%.*s\", json = \"%.*s\" }", st_length_int(commands[0]), st_char_get(commands[0]), + st_sprint(errmsg, "Failed parsing the returned JSON. { command = \"%.*s\", json = \"%.*s\" }", ns_length_int(commands[0]), commands[0], st_length_int(json), st_char_get(json)); mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]); - st_cleanup(json, rand_strs[0], rand_strs[1]); client_close(client); + st_cleanup(json); return false; } // Check if the returned JSON is correct. else if (st_cmp_cs_eq(PLACER((chr_t*)json_value, ns_length_get(json_value)), rand_strs[1])) { - st_sprint(errmsg, "Failed to return a successful JSON response. { command = \"%.*s\", json = \"%.*s\" }", st_length_int(commands[0]), st_char_get(commands[0]), + st_sprint(errmsg, "Failed to return a successful JSON response. { command = \"%.*s\", json = \"%.*s\" }", ns_length_int(commands[0]), commands[0], st_length_int(json), st_char_get(json)); mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]); - st_cleanup(json, rand_strs[0], rand_strs[1]); client_close(client); + st_cleanup(json); return false; } // Clean up before the next check. - st_cleanup(json, command, rand_strs[1]); + st_cleanup(json); + st_wipe(command); + st_wipe(rand_strs[1]); mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]); json = NULL; - command = NULL; - rand_strs[1] = NULL; - - for (size_t i = 0; i < sizeof(json_objs)/sizeof(json_t *); i++) { - json_objs[i] = NULL; - } - - client_close(client); - client = NULL; - - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // Test config.edit : commands[2] - // JSON Command : {"id":4,"method":"config.edit","params":{<rand_strs[0]>:null}}" - // Expected Response : {"jsonrpc":"2.0","result":{"config.edit":"success"},"id":4} - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - // Construct the command string. - if (!(command = st_alloc(st_length_get(commands[0]) - 4 + st_length_get(rand_strs[0]))) || !(st_quick(command, st_char_get(commands[0]), - st_length_int(rand_strs[0]), st_char_get(rand_strs[0])))) { - - st_sprint(errmsg, "Failed to create command string. { command = \"%.*s\" }", st_length_int(command), st_char_get(command)); - st_cleanup(command, rand_strs[0]); - client_close(client); - return false; - } - - // Submit the command and check the status of the response. - if (!(client = check_camel_connect(secure)) || !check_camel_json_write(client, command, cookie, true) || - client_status(client) != 1 || !check_camel_status(client) || !(content_length = check_http_content_length_get(client)) || - !(json = check_camel_json_read(client, content_length))) { - - st_sprint(errmsg, "Failed to return a successful HTTP response. { command = \"%.*s\" }", st_length_int(command), st_char_get(command)); - st_cleanup(json, command, rand_strs[0], rand_strs[1]); - client_close(client); - return false; - } - - // Parse the returned JSON. - else if (!(json_objs[0] = json_loads_d(st_char_get(json), 0, &json_err)) || !(json_objs[1] = json_object_get_d(json_objs[0], "result")) || - !(json_objs[2] = json_object_get_d(json_objs[1], "config.edit")) || !(json_value = json_string_value_d(json_objs[2]))) { - - st_sprint(errmsg, "Failed parsing the returned JSON. { command = \"%.*s\", json = \"%.*s\" }", st_length_int(command), st_char_get(command), - st_length_int(json), st_char_get(json)); - mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]); - st_cleanup(json, command, rand_strs[0], rand_strs[1]); - client_close(client); - return false; - } - - // Check if the returned JSON is correct. - else if (st_cmp_cs_eq(PLACER((chr_t*)json_value, ns_length_get(json_value)), PLACER("success", 7))) { - - st_sprint(errmsg, "Failed parsing the returned JSON. { command = \"%.*s\", json = \"%.*s\" }", st_length_int(command), st_char_get(command), - st_length_int(json), st_char_get(json)); - mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]); - st_cleanup(json, command, rand_strs[0], rand_strs[1]); - client_close(client); - return false; - } - - // Clean up before the next check. - st_cleanup(json, command, rand_strs[0]); - mm_cleanup(json_objs[0], json_objs[1], json_objs[2], json_objs[3]); - - json = NULL; - command = NULL; - rand_strs[0] = NULL; for (size_t i = 0; i < sizeof(json_objs)/sizeof(json_t *); i++) { json_objs[i] = NULL; |