mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-26 18:33:27 +01:00
add valid nick function
This commit is contained in:
parent
7ca087b5e7
commit
a04c8964ee
@ -232,9 +232,9 @@ void cmd_nick(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA
|
||||
nick[len] = L'\0';
|
||||
}
|
||||
|
||||
if (!len) {
|
||||
wprintw(window, "Invalid name.\n");
|
||||
return;
|
||||
if (!valid_nick(nick)) {
|
||||
wprintw(window, "Invalid name.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (len > TOXIC_MAX_NAME_LENGTH) {
|
||||
|
@ -117,14 +117,14 @@ void alert_window(ToxWindow *self)
|
||||
/* case-insensitive string compare function for use with qsort - same return logic as strcmp */
|
||||
int name_compare(const void *nick1, const void *nick2)
|
||||
{
|
||||
char s[strlen((const char *) nick1) + 1];
|
||||
char t[strlen((const char *) nick2) + 1];
|
||||
char s[TOX_MAX_NAME_LENGTH];
|
||||
char t[TOX_MAX_NAME_LENGTH];
|
||||
strcpy(s, (const char *) nick1);
|
||||
strcpy(t, (const char *) nick2);
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; s[i] != '\0' && t[i] != '\0'; ++i) {
|
||||
for (i = 0; s[i] && t[i]; ++i) {
|
||||
s[i] = tolower(s[i]);
|
||||
t[i] = tolower(t[i]);
|
||||
|
||||
@ -134,3 +134,22 @@ int name_compare(const void *nick1, const void *nick2)
|
||||
|
||||
return s[i] - t[i];
|
||||
}
|
||||
|
||||
/* Returns true if nick is valid. A valid toxic nick:
|
||||
- cannot be empty
|
||||
- cannot start with a space
|
||||
- must not contain contiguous spaces */
|
||||
bool valid_nick(uint8_t *nick)
|
||||
{
|
||||
if (!nick[0] || nick[0] == ' ')
|
||||
return false;
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; nick[i]; ++i) {
|
||||
if (nick[i] == ' ' && nick[i+1] == ' ')
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
@ -30,3 +30,9 @@ void alert_window(ToxWindow *self);
|
||||
|
||||
/* case-insensitive string compare function for use with qsort - same return logic as strcmp */
|
||||
int name_compare(const void *nick1, const void *nick2);
|
||||
|
||||
/* Returns true if nick is valid. A valid toxic nick:
|
||||
- cannot be empty
|
||||
- cannot start with a space
|
||||
- must not contain contiguous spaces */
|
||||
bool valid_nick(uint8_t *nick);
|
@ -22,7 +22,7 @@
|
||||
#define MAX_GROUPCHAT_NUM MAX_WINDOWS_NUM - N_DEFAULT_WINS
|
||||
#define MAX_STR_SIZE 256
|
||||
#define KEY_SIZE_BYTES 32
|
||||
#define TOXIC_MAX_NAME_LENGTH 30 /* Must be <= TOX_MAX_NAME_LENGTH */
|
||||
#define TOXIC_MAX_NAME_LENGTH 32 /* Must be <= TOX_MAX_NAME_LENGTH */
|
||||
#define N_DEFAULT_WINS 2 /* number of permanent default windows */
|
||||
#define CURS_Y_OFFSET 3 /* y-axis cursor offset for chat contexts */
|
||||
#define CHATBOX_HEIGHT 4
|
||||
|
Loading…
Reference in New Issue
Block a user