# HG changeset patch # User Matti Hamalainen # Date 1287788460 -10800 # Node ID f323b137ca08540a94435ee386a27ae2628e7565 # Parent 8037a3a7e4918f8404e95abee2f7dbde9536e99e Tab-completion now works with cycling, but bugs with names that have whitespaces. diff -r 8037a3a7e491 -r f323b137ca08 libnnchat.c --- a/libnnchat.c Fri Oct 22 12:07:38 2010 +0300 +++ b/libnnchat.c Sat Oct 23 02:01:00 2010 +0300 @@ -657,7 +657,7 @@ { uint8_t hash; - if (list == NULL) return NULL; + if (list == NULL || pattern == NULL) return NULL; hash = nn_hash_user(pattern); if (list->buckets[hash] != NULL) { diff -r 8037a3a7e491 -r f323b137ca08 nnchat.c --- a/nnchat.c Fri Oct 22 12:07:38 2010 +0300 +++ b/nnchat.c Sat Oct 23 02:01:00 2010 +0300 @@ -362,10 +362,10 @@ } -int handleUser(int sock, char *str) +int handleUser(int sock, const char *str) { - const char *msg = ""; - char *p = str, *q, *s, *t, *h; + const char *msg = "", *p = str; + char *q, *s, *t, *h, *p2; (void) sock; @@ -381,14 +381,18 @@ s = nn_decode_str1(s); if (!s) return -1; - p = nn_decode_str1(p); - if (!p) { + p2 = nn_decode_str1(p); + if (!p2) { th_free(s); return -2; } - + if (*s == '/') { + /* Ignore room join/leave messages */ + if (strstr(s, "left the room") || strstr(s, "joined the room from")) + goto error; + t = nn_strip_tags(s + 1); if (!strncmp(t, "BPRV", 4)) { h = nn_decode_str2(t + 1); @@ -400,32 +404,33 @@ th_free(h); th_free(t); } else { - BOOL isMine = strcmp(p, optUserName) == 0; + BOOL isMine = strcmp(p2, optUserName) == 0; BOOL logOnly = FALSE; t = nn_strip_tags(s); h = nn_decode_str2(t); if (ignoreMode) { char **user = ignoreList; while (*user != NULL) { - if (strcasecmp(p, *user) == 0) { + if (strcasecmp(p2, *user) == 0) { logOnly = TRUE; break; } user++; } } - printMsgQ(logOnly, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, p, h); + printMsgQ(logOnly, "½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, p2, h); th_free(h); th_free(t); } - + +error: th_free(s); - th_free(p); + th_free(p2); return 0; } -int handleLogin(int sock, char *str) +int handleLogin(int sock, const char *str) { char tmpStr[256] = ""; time_t timeStamp; @@ -448,7 +453,7 @@ } -int handleAddUser(int sock, char *str) +int handleAddUser(int sock, const char *str) { char *p, *s = strstr(str, ""); @@ -468,7 +473,7 @@ } -int handleDeleteUser(int sock, char *str) +int handleDeleteUser(int sock, const char *str) { char *p, *s = strstr(str, ""); @@ -488,7 +493,7 @@ } -int handleFoo(int sock, char *str) +int handleFoo(int sock, const char *str) { (void) sock; (void) str; @@ -496,7 +501,7 @@ } -int handleBoot(int sock, char *str) +int handleBoot(int sock, const char *str) { (void) sock; (void) str; errorMsg("Booted by server.\n"); @@ -506,11 +511,11 @@ typedef struct { char *cmd; - int (*handler)(int, char *); + int (*handler)(int, const char *); } protocmd_t; -protocmd_t protoCmds[] = { +static const protocmd_t protoCmds[] = { { "", handleUser }, { "", handleDeleteUser }, @@ -519,10 +524,10 @@ { "", handleBoot }, }; -const int nprotoCmds = (sizeof(protoCmds) / sizeof(protoCmds[0])); +static const int nprotoCmds = sizeof(protoCmds) / sizeof(protoCmds[0]); -int handleProtocol(const int sock, char *buf, size_t bufLen) +int handleProtocol(const int sock, const char *buf, const size_t bufLen) { int i; @@ -560,23 +565,23 @@ printMsg("Setting color to #%06x\n", optUserColor); nn_send_msg(sock, optUserName2, "%%2FSetFontColor%%20%%2Dcolor%%20%06X", optUserColor); return 0; - } else if (!strncmp(buf, "/flood ", 7)) { - int i; - - snprintf(tmpBuf, sizeof(tmpBuf), "/prv -to %s -msg . .", - buf+7); - - tmpStr = nn_dblencode_str(tmpBuf); - if (!tmpStr) return -2; - - result = TRUE; - for (i = 0; i < 50 && result; i++) { - result = nn_send_msg(sock, optUserName2, "%s", tmpStr); - usleep(250); - } - + } else if (!strncmp(buf, "/w ", 3)) { + char *name = buf + 3; + pid_t pud; + tmpStr = nn_encode_str1(name); + snprintf(tmpBuf, sizeof(tmpBuf), "openurl(http://www.newbienudes.com/profile/%s/,new-tab)", tmpStr); th_free(tmpStr); - return 0; + + printMsg("Opening profile for: %s\n", name); + printMsg("%s\n", tmpBuf); +/* + if ((pud = fork()) < 0) return 0; + if (getpid() == pud) { + execlp("firefox", "-remote", tmpBuf, (char *) NULL); + exit(0); + } else +*/ + return 0; } else if (!strncmp(buf, "/to ", 4)) { th_free(setTarget); setTarget = th_strdup(buf + 4); @@ -630,8 +635,8 @@ { static char *previous = NULL; static char *matsi = NULL; - char *s = NULL, *b = buf->data; - ssize_t pos2, pos1 = buf->pos; + char *b = buf->data; + ssize_t pos2 = 0, pos1 = buf->pos; if (pos1 > 0) pos1--; @@ -639,31 +644,25 @@ pos1 -= 2; pos2 = pos1; while (pos1 > 0 && b[pos1 - 1] != ' ') pos1--; - s = nn_editbuf_get_string(buf, pos1, pos2); } else if (b[pos1] != ' ' && b[pos1] != ':') { pos2 = pos1; while (pos1 > 0 && b[pos1 - 1] != ' ') pos1--; while (pos2 < buf->len && b[pos2] != ' ') pos2++; while (pos2 > 0 && b[pos2] == ' ') pos2--; - s = nn_editbuf_get_string(buf, pos1, pos2); - th_free(previous); th_free(matsi); - matsi = NULL; - previous = NULL; + matsi = nn_editbuf_get_string(buf, pos1, pos2); + th_free(previous); previous = NULL; } - if (s) { - nn_user_t *m; - if (matsi) - m = nn_user_match(nnUsers, matsi, previous); - else - m = nn_user_match(nnUsers, s, previous); + if (matsi) { + nn_user_t *user = nn_user_match(nnUsers, matsi, previous); +// printMsg("pattern '%s'\n", matsi); - if (m) { + if (user) { int i; - char *c = m->name; - printMsg("match '%s'\n", m->name); + char *c = user->name; +// printMsg("match '%s'\n", user->name); for (i = pos1; i <= pos2; i++) nn_editbuf_delete(buf, pos1); @@ -675,14 +674,11 @@ nn_editbuf_insert(buf, i+1, ':'); nn_editbuf_insert(buf, i+2, ' '); } - nn_editbuf_setpos(buf, pos1 + 2 + strlen(m->name)); + nn_editbuf_setpos(buf, pos1 + 2 + strlen(user->name)); - if (previous == NULL) { - previous = th_strdup(m->name); - matsi = th_strdup(s); - } + th_free(previous); + previous = th_strdup(user->name); } - th_free(s); } }