diff options
author | jpadkins <jacobpadkins@gmail.com> | 2017-03-23 15:50:19 +0300 |
---|---|---|
committer | jpadkins <jacobpadkins@gmail.com> | 2017-03-23 15:50:19 +0300 |
commit | f611e8a10914da542ec0a2818f504fe6b9f35fb1 (patch) | |
tree | 368a5478491484d7d3d7b6e4ace46467ad2960c0 /check/magma/servers | |
parent | c0675bbc5e8f1d455c1b5be795f7ec6d92c138ec (diff) |
Dirty Commit: troubleshooting imap refactor
Diffstat (limited to 'check/magma/servers')
-rw-r--r-- | check/magma/servers/http/http_check_network.c | 5 | ||||
-rw-r--r-- | check/magma/servers/imap/imap_check_network.c | 55 | ||||
-rw-r--r-- | check/magma/servers/smtp/smtp_check_network.c | 2 |
3 files changed, 52 insertions, 10 deletions
diff --git a/check/magma/servers/http/http_check_network.c b/check/magma/servers/http/http_check_network.c index 496e86c4..9ea10fc4 100644 --- a/check/magma/servers/http/http_check_network.c +++ b/check/magma/servers/http/http_check_network.c @@ -90,12 +90,13 @@ bool_t check_http_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_ else if (client_print(client, "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n") != 35 || client_status(client) != 1 || !(content_length = check_http_content_length_get(client, errmsg))) { - if (!errmsg) st_sprint(errmsg, "Failed to return a valid GET response."); + if (st_empty(errmsg)) st_sprint(errmsg, "Failed to return a valid GET response."); return false; } // Test the response. else if (check_http_content_length_test(client, content_length, errmsg)) { - if (!errmsg) st_sprint(errmsg, "The content length and actual body length of the GET response did not match."); + + if (st_empty(errmsg)) st_sprint(errmsg, "The content length and actual body length of the GET response did not match."); return false; } diff --git a/check/magma/servers/imap/imap_check_network.c b/check/magma/servers/imap/imap_check_network.c index ca690cda..d211c4a3 100644 --- a/check/magma/servers/imap/imap_check_network.c +++ b/check/magma/servers/imap/imap_check_network.c @@ -9,7 +9,7 @@ #include "magma_check.h" /** - * @brief Calls client_read_line on a client until it finds a line matching "<token> OK". + * @brief Calls client_read_line on a client until it finds a line matching "<tag> OK". * * @param client The client to read from (which should be connected to an IMAP server). * @param token The unique token that identifies the current imap command dialogue. @@ -17,7 +17,7 @@ * @return Returns true if client_read_line was successful until the last line was found. * specified in num and there was no error. Otherwise returns false. */ -bool_t check_imap_client_read_lines_to_end(client_t *client, chr_t *tag) { +bool_t check_imap_client_read_end(client_t *client, chr_t *tag) { bool_t outcome = false; stringer_t *last_line = st_merge("ss", NULLER(tag), NULLER(" OK")); @@ -30,6 +30,42 @@ bool_t check_imap_client_read_lines_to_end(client_t *client, chr_t *tag) { return outcome; } +bool_t check_imap_network_login(client_t *client, chr_t *user, chr_t *pass, chr_t *tag, stringer_t *errmsg) { + + stringer_t *login_line = NULL; + uint32_t login_line_len = ns_length_get(tag) + ns_length_get(user) + ns_length_get(pass) + 10; + + // Construct the login command + if (!(login_line = st_merge("nsnsns", tag, NULLER(" LOGIN "), user, NULLER(' '), pass, NULLER("\r\n")))) { + + st_sprint(errmsg, "Failed to construct the login command."); + return false; + } + // Test the LOGIN command. + else if (client_print(client, st_char_get(login_line)) != login_line_len || !check_imap_client_read_end(client, tag) || + client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER(tag))) { + + st_sprint(errmsg, "Failed to return a successful state after LOGIN."); + return false; + } + + st_cleanup(login_line); + return true; +} + +bool_t check_imap_network_select(client_t *client, chr_t *folder, chr_t *tag, stringer_t *errmsg) { + + // Test the SELECT command. + if (client_print(client, "A2 SELECT Inbox\r\n") <= 0 || !check_imap_client_read_end(client, tag) || + client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER(tag))) { + + st_sprint(errmsg, "Failed to return a successful state after SELECT."); + return false; + } + + return true; +} + bool_t check_imap_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t secure) { client_t *client = NULL; @@ -45,7 +81,7 @@ bool_t check_imap_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_ } // Test the LOGIN command. - else if (client_print(client, "A1 LOGIN princess password\r\n") <= 0 || !check_imap_client_read_lines_to_end(client, "A1") || + else if (client_print(client, "A1 LOGIN princess password\r\n") <= 0 || !check_imap_client_read_end(client, "A1") || client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("A1 OK"))) { st_sprint(errmsg, "Failed to return a successful state after LOGIN."); @@ -54,7 +90,7 @@ bool_t check_imap_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_ } // Test the SELECT command. - else if (client_print(client, "A2 SELECT Inbox\r\n") <= 0 || !check_imap_client_read_lines_to_end(client, "A2") || + else if (client_print(client, "A2 SELECT Inbox\r\n") <= 0 || !check_imap_client_read_end(client, "A2") || client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("A2 OK"))) { st_sprint(errmsg, "Failed to return a successful state after SELECT."); @@ -63,7 +99,7 @@ bool_t check_imap_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_ } // Test the FETCH command. - else if (client_print(client, "A3 FETCH 1 RFC822\r\n") <= 0 || !check_imap_client_read_lines_to_end(client, "A3") || + else if (client_print(client, "A3 FETCH 1 RFC822\r\n") <= 0 || !check_imap_client_read_end(client, "A3") || client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("A3 OK"))) { st_sprint(errmsg, "Failed to return a successful state after FETCH."); @@ -72,7 +108,7 @@ bool_t check_imap_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_ } // Test the CLOSE command. - else if (client_print(client, "A4 CLOSE\r\n") <= 0 || !check_imap_client_read_lines_to_end(client, "A4") || + else if (client_print(client, "A4 CLOSE\r\n") <= 0 || !check_imap_client_read_end(client, "A4") || client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("A4 OK"))) { st_sprint(errmsg, "Failed to return a successful state after CLOSE."); @@ -81,7 +117,7 @@ bool_t check_imap_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_ } // Test the LOGOUT command. - else if (client_print(client, "A5 LOGOUT\r\n") <= 0 || !check_imap_client_read_lines_to_end(client, "A5") || + else if (client_print(client, "A5 LOGOUT\r\n") <= 0 || !check_imap_client_read_end(client, "A5") || client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("A5 OK"))) { st_sprint(errmsg, "Failed to return a successful state after LOGOUT."); @@ -98,11 +134,16 @@ bool_t check_imap_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_ bool_t check_imap_network_search_sthread(stringer_t *errmsg, uint32_t port) { bool_t outcome = true; + + + return outcome; } bool_t check_imap_network_fetch_sthread(stringer_t *errmsg, uint32_t port) { bool_t outcome = true; + + return outcome; } diff --git a/check/magma/servers/smtp/smtp_check_network.c b/check/magma/servers/smtp/smtp_check_network.c index b599f314..3a14e2c7 100644 --- a/check/magma/servers/smtp/smtp_check_network.c +++ b/check/magma/servers/smtp/smtp_check_network.c @@ -278,7 +278,7 @@ bool_t check_smtp_network_auth_sthread(stringer_t *errmsg, uint32_t port, bool_t client_print(client, ".\r\n") != 3 || !check_smtp_client_read_end(client) || client_status(client) != 1 || st_cmp_cs_starts(&(client->line), NULLER("250"))) { - if (!errmsg) st_sprint(errmsg, "Failed to return successful status after sending from an authenticated account."); + if (st_empty(errmsg)) st_sprint(errmsg, "Failed to return successful status after sending from an authenticated account."); client_close(client); return false; } |