mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-25 04:33:03 +01:00
Fix ID lookup error messages
We now properly distinguish between ID lookups and domain name lookups and print the appropriate error message for each given case
This commit is contained in:
parent
ff669be8d1
commit
4c77e80a7f
@ -173,10 +173,16 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
|
||||
char id_bin[TOX_ADDRESS_SIZE] = {0};
|
||||
|
||||
const bool is_tox_id = (char_find(0, id, '@') == arg_length) && (arg_length >= TOX_ADDRESS_SIZE * 2);
|
||||
const bool is_domain = char_find(0, id, '@') != arg_length;
|
||||
const bool valid_id_size = arg_length >= TOX_ADDRESS_SIZE * 2; // arg_length may include invite message
|
||||
|
||||
if (!is_tox_id) {
|
||||
name_lookup(self, m, id_bin, id, msg);
|
||||
if (is_domain) {
|
||||
if (!name_lookup(self, m, id_bin, id, msg)) {
|
||||
return;
|
||||
}
|
||||
} else if (!valid_id_size) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Invalid Tox ID.");
|
||||
return;
|
||||
}
|
||||
|
||||
char xx[3];
|
||||
|
@ -362,16 +362,20 @@ on_exit:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void name_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr, const char *message)
|
||||
/* Attempts to do a tox name lookup.
|
||||
*
|
||||
* Returns true on success.
|
||||
*/
|
||||
bool name_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr, const char *message)
|
||||
{
|
||||
if (t_data.disabled) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "nameservers list is empty or does not exist.");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (t_data.busy) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, 0, "Please wait for previous name lookup to finish.");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
snprintf(t_data.id_bin, sizeof(t_data.id_bin), "%s", id_bin);
|
||||
@ -384,22 +388,24 @@ void name_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr,
|
||||
if (pthread_attr_init(&lookup_thread.attr) != 0) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, "Error: lookup thread attr failed to init");
|
||||
clear_thread_data();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pthread_attr_setdetachstate(&lookup_thread.attr, PTHREAD_CREATE_DETACHED) != 0) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, "Error: lookup thread attr failed to set");
|
||||
pthread_attr_destroy(&lookup_thread.attr);
|
||||
clear_thread_data();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pthread_create(&lookup_thread.tid, &lookup_thread.attr, lookup_thread_func, NULL) != 0) {
|
||||
line_info_add(self, false, NULL, NULL, SYS_MSG, 0, RED, "Error: lookup thread failed to init");
|
||||
pthread_attr_destroy(&lookup_thread.attr);
|
||||
clear_thread_data();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Initializes http based name lookups. Note: This function must be called only once before additional
|
||||
|
@ -23,14 +23,19 @@
|
||||
#ifndef NAME_LOOKUP
|
||||
#define NAME_LOOKUP
|
||||
|
||||
/* Initializes http based name lookups. Note: This function must be called only once before additional
|
||||
* threads are spawned.
|
||||
/* Initializes http based name lookups.
|
||||
*
|
||||
* Note: This function must be called only once before additional threads are spawned.
|
||||
*
|
||||
* Returns 0 on success.
|
||||
* Returns -1 on failure.
|
||||
*/
|
||||
int name_lookup_init(int curl_init_status);
|
||||
|
||||
int name_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr, const char *message);
|
||||
/* Attempts to do a tox name lookup.
|
||||
*
|
||||
* Returns true on success.
|
||||
*/
|
||||
bool name_lookup(ToxWindow *self, Tox *m, const char *id_bin, const char *addr, const char *message);
|
||||
|
||||
#endif /* NAME_LOOKUP */
|
||||
|
Loading…
Reference in New Issue
Block a user