diff --git a/src/dns.c b/src/dns.c index ecbe56a..e9a266a 100644 --- a/src/dns.c +++ b/src/dns.c @@ -37,8 +37,8 @@ #include "line_info.h" #include "dns.h" #include "global_commands.h" +#include "misc_tools.h" -#define MAX_DNS_THREADS 10 #define MAX_DNS_REQST_SIZE 256 #define NUM_DNS3_SERVERS 1 /* must correspond to number of items in dns3_servers array */ #define TOX_DNS3_TXT_PREFIX "v=tox3;id=" @@ -173,6 +173,7 @@ static int parse_addr(uint8_t *addr, uint8_t *namebuf, uint8_t *dombuf) if (tmpname == NULL || tmpdom == NULL) return -1; + str_to_lower(tmpdom); strcpy(namebuf, tmpname); strcpy(dombuf, tmpdom); @@ -190,7 +191,7 @@ void *dns3_lookup_thread(void *data) int namelen = parse_addr(t_data.addr, name, domain); if (namelen == -1) { - dns_error(self, "Must be a Tox key or an address in the form username@domain"); + dns_error(self, "Must be a Tox ID or an address in the form username@domain"); kill_dns_thread(NULL); } @@ -245,9 +246,8 @@ void *dns3_lookup_thread(void *data) uint8_t ans_id[MAX_DNS_REQST_SIZE]; /* extract TXT from DNS response */ - if (parse_dns_response(self, answer, ans_len, ans_id) == -1) { + if (parse_dns_response(self, answer, ans_len, ans_id) == -1) kill_dns_thread(dns_obj); - } uint8_t encrypted_id[MAX_DNS_REQST_SIZE]; int prfx_len = strlen(TOX_DNS3_TXT_PREFIX); diff --git a/src/global_commands.c b/src/global_commands.c index e140318..59235d0 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -461,20 +461,16 @@ void cmd_status(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[ } char *status = argv[1]; + str_to_lower(status); int len = strlen(status); - char l_status[len + 1]; - int i; - - for (i = 0; i <= len; ++i) - l_status[i] = tolower(status[i]); TOX_USERSTATUS status_kind; - if (!strcmp(l_status, "online")) + if (!strcmp(status, "online")) status_kind = TOX_USERSTATUS_NONE; - else if (!strcmp(l_status, "away")) + else if (!strcmp(status, "away")) status_kind = TOX_USERSTATUS_AWAY; - else if (!strcmp(l_status, "busy")) + else if (!strcmp(status, "busy")) status_kind = TOX_USERSTATUS_BUSY; else { errmsg = "Invalid status. Valid statuses are: online, busy and away."; diff --git a/src/misc_tools.c b/src/misc_tools.c index 93b93df..5350ccf 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -250,3 +250,12 @@ void get_file_name(uint8_t *namebuf, uint8_t *pathname) snprintf(namebuf, MAX_STR_SIZE, "%s", filename); } + +/* converts str to all lowercase */ +void str_to_lower(uint8_t *str) +{ + int i; + + for (i = 0; str[i]; ++i) + str[i] = tolower(str[i]); +} diff --git a/src/misc_tools.h b/src/misc_tools.h index 6f3baef..699ab20 100644 --- a/src/misc_tools.h +++ b/src/misc_tools.h @@ -86,4 +86,7 @@ void mv_curs_end(WINDOW *w, size_t len, int max_y, int max_x); /* gets base file name from path or original file name if no path is supplied */ void get_file_name(uint8_t *namebuf, uint8_t *pathname); +/* converts str to all uppercase */ +void str_to_lower(uint8_t *str); + #endif /* #define _misc_tools_h */