diff options
author | jpadkins <jpadkins@gmail.com> | 2017-03-23 22:39:38 +0300 |
---|---|---|
committer | jpadkins <jpadkins@gmail.com> | 2017-03-23 22:39:38 +0300 |
commit | cfe544e8e1961e898906a1a910742042f71d52dc (patch) | |
tree | 7787a3f3b551dd4673880ea634115f7799aca93c /check | |
parent | f611e8a10914da542ec0a2818f504fe6b9f35fb1 (diff) |
Dirty commit: switching workstations so commiting what I have so far
Diffstat (limited to 'check')
-rw-r--r-- | check/magma/servers/imap/imap_check_network.c | 80 |
1 files changed, 73 insertions, 7 deletions
diff --git a/check/magma/servers/imap/imap_check_network.c b/check/magma/servers/imap/imap_check_network.c index d211c4a3..db72e6cb 100644 --- a/check/magma/servers/imap/imap_check_network.c +++ b/check/magma/servers/imap/imap_check_network.c @@ -30,9 +30,19 @@ bool_t check_imap_client_read_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) { +/** + * @brief Prints the LOGIN command to the passed client using the passed credentials. + * + * @param client The client_t* to print the commands to. It should be connected to an IMAP server. + * @param user A chr_t* holding the username to use in the LOGIN command. + * @param pass A chr_t* holding the password to use in the LOGIN command. + * @param tag A chr_t* holding the tag to place at the beginning of the LOGIN command. + * @param errmsg A stringer_t* into which the error message will be printed in the even of an error. + * @return True if the LOGIN command was successful, otherwise false. + */ +bool_t check_imap_client_login(client_t *client, chr_t *user, chr_t *pass, chr_t *tag, stringer_t *errmsg) { - stringer_t *login_line = NULL; + stringer_t *login_line; uint32_t login_line_len = ns_length_get(tag) + ns_length_get(user) + ns_length_get(pass) + 10; // Construct the login command @@ -53,7 +63,16 @@ bool_t check_imap_network_login(client_t *client, chr_t *user, chr_t *pass, chr_ return true; } -bool_t check_imap_network_select(client_t *client, chr_t *folder, chr_t *tag, stringer_t *errmsg) { +/** + * @brief Prints the SELECT command to the passed client using the passed parameter. + * + * @param client The client_t* to print the command to. It should be connected to an IMAP server. + * @param folder A chr_t* holding the name of the folder to select. + * @param tag A chr_t* holding the tag to place at the beginning of the SELECT command. + * @param errmsg A stringer_t* into which the error message will be printed in the even of an error. + * @return True if the SELECT command was successful, otherwise false. + */ +bool_t check_imap_client_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) || @@ -66,6 +85,27 @@ bool_t check_imap_network_select(client_t *client, chr_t *folder, chr_t *tag, st return true; } +bool_t check_imap_client_close_logout(client_t *client, stringer_t *errmsg) { + + // Test the CLOSE command. + 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."); + return false; + } + + // Test the LOGOUT command. + 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."); + return false; + } + + return true; +} + bool_t check_imap_network_basic_sthread(stringer_t *errmsg, uint32_t port, bool_t secure) { client_t *client = NULL; @@ -133,17 +173,43 @@ 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; + client_t *client = NULL; + // Check the initial response. + if (!(client = client_connect("localhost", port)) || (secure && (client_secure(client) == -1)) || + !net_set_timeout(client->sockd, 20, 20) || client_read_line(client) <= 0 || (client->status != 1) || + st_cmp_cs_starts(&(client->line), NULLER("* OK"))) { + st_sprint(errmsg, "Failed to connect with the IMAP server."); + client_close(client); + return false; + } + // Test the LOGIN command. + else if (!check_imap_client_login(client, "princess", "password", errmsg)) { + return false; + } - return outcome; + return true; } bool_t check_imap_network_fetch_sthread(stringer_t *errmsg, uint32_t port) { - bool_t outcome = true; + client_t *client = NULL; + // Check the initial response. + if (!(client = client_connect("localhost", port)) || (secure && (client_secure(client) == -1)) || + !net_set_timeout(client->sockd, 20, 20) || client_read_line(client) <= 0 || (client->status != 1) || + st_cmp_cs_starts(&(client->line), NULLER("* OK"))) { - return outcome; + st_sprint(errmsg, "Failed to connect with the IMAP server."); + client_close(client); + return false; + } + // Test the LOGIN command. + else if (!check_imap_client_login(client, "princess", "password", errmsg)) { + return false; + } + + return true; } + |