static void handle_ping(void *data, UNUSED void *udata) { irc_event_t *event; event = (irc_event_t *)data; irc_pong(event->data + 1); }
void test_irc_pong() { char msg[READ_BUF]; irc_pong("irc.freenode.net"); read_mock(msg); mu_assert(s_eq(msg, "PONG irc.freenode.net\r\n"), "test_irc_pong: msg should be 'PONG irc.freenode.net\\r\\n'"); }
static int irc_parse_action(irc_t *irc) { if ( strncmp(irc->servbuf, "PING :", 6) == 0 ) { return irc_pong(irc->s, &irc->servbuf[6]); } else if ( strncmp(irc->servbuf, "NOTICE AUTH :", 13) == 0 ) { // Don't care return 0; } else if ( strncmp(irc->servbuf, "ERROR :", 7) == 0 ) { // Still don't care return 0; } else { // Parses IRC message that pulls out nick and message. // Sample: :[email protected] PRIVMSG #bajrden :test char *ptr; int privmsg = 0; char irc_nick[NICK_LEN]; char irc_msg[MSG_LEN]; char irc_chan[CHAN_LEN]; fprintf(stdout, "%s\n", irc->servbuf); // For debugging // Check for non-message string if ( strchr(irc->servbuf, 1) != NULL ) return 0; if ( irc->servbuf[0] == ':' ) { ptr = strtok(irc->servbuf, " !"); if ( ptr == NULL ) { fprintf(stderr, "ptr == NULL\n"); return 0; } else { strncpy(irc_nick, &ptr[1], NICK_LEN-2); irc_nick[NICK_LEN-1] = '\0'; } while ( (ptr = strtok(NULL, " ")) != NULL ) { if ( strncmp(ptr, "PRIVMSG", strlen("PRIVMSG")) == 0 ) { privmsg = 1; break; } } if ( privmsg ) { ptr = strtok(NULL, ":"); strncpy(irc_chan, ptr, CHAN_LEN - 2); if ( (ptr = strtok(NULL, "")) != NULL ) { strncpy(irc_msg, ptr, MSG_LEN - 2); irc_msg[MSG_LEN-1] = '\0'; } } if ( privmsg == 1 && strlen(irc_nick) > 0 && strlen(irc_msg) > 0 ) { //MOdify this irc_log_message(irc, irc_chan, irc_nick, irc_msg); if ( irc_reply_message(irc, irc_chan, irc_nick, irc_msg) < 0 ) return -1; } } } return 0; }
static char *test_irc_pong() { bstring expected; expected = bfromcstr("PONG server.somewhere.net\r\n"); irc_pong(SOCK, "server.somewhere.net"); mu_assert("Empty message", blength(sent) != 0); mu_assert("Message differs from expected", bstrcmp(expected, sent) == 0); bdestroy(expected); bdestroy(sent); return NULL; }
int irc_parse_action(irc_t *irc) { char irc_nick[128]; char irc_msg[512]; if ( strncmp(irc->servbuf, "PING :", 6) == 0 ) { return irc_pong(irc->s, &irc->servbuf[6]); } else if ( strncmp(irc->servbuf, "NOTICE AUTH :", 13) == 0 ) { // Don't care return 0; } else if ( strncmp(irc->servbuf, "ERROR :", 7) == 0 ) { // Still don't care return 0; } // Here be lvl. 42 dragonn boss // Parses IRC message that pulls out nick and message. else { char *ptr; int privmsg = 0; char irc_nick[128]; char irc_msg[512]; *irc_nick = '\0'; *irc_msg = '\0'; // Checks if we have non-message string if ( strchr(irc->servbuf, 1) != NULL ) return 0; if ( irc->servbuf[0] == ':' ) { ptr = strtok(irc->servbuf, "!"); if ( ptr == NULL ) { printf("ptr == NULL\n"); return 0; } else { strncpy(irc_nick, &ptr[1], 127); irc_nick[127] = '\0'; } while ( (ptr = strtok(NULL, " ")) != NULL ) { if ( strcmp(ptr, "PRIVMSG") == 0 ) { privmsg = 1; break; } } if ( privmsg ) { if ( (ptr = strtok(NULL, ":")) != NULL && (ptr = strtok(NULL, "")) != NULL ) { strncpy(irc_msg, ptr, 511); irc_msg[511] = '\0'; } } if ( privmsg == 1 && strlen(irc_nick) > 0 && strlen(irc_msg) > 0 ) { irc_log_message(irc, irc_nick, irc_msg); if ( irc_reply_message(irc, irc_nick, irc_msg) < 0 ) return -1; } } } return 0; }
static bool handle_ping(int fd, struct ircmsg_ping *ping) { irc_pong(fd, ping->text); return true; }