Index: libuirc/libuirc.c =================================================================== --- libuirc/libuirc.c (revision 31358) +++ libuirc/libuirc.c (revision 31359) @@ -100,20 +100,22 @@ return 0; } +#define payload(dst, src) \ +do { \ + dst = strpbrk(src, " \t"); \ + if (dst != NULL) { \ + *dst++ = '\0'; \ + if (*dst == ':') dst++; \ + } \ +} while(0) + static uirc_event_t uirc_parse_part(uirc_t *ctx, char *nick, char *arg) { char *reason; int q; -/*:libuirc!~libuirc@78-131-56-146.static.hdsnet.hu PART #pcb-rnd*/ if (*arg == ':') arg++; - reason = strpbrk(arg, " \t"); - if (reason != NULL) { - *reason = 0; - reason++; - if (*reason == ':'); - reason++; - } + payload(reason, arg); q = uirc_query_search(ctx, arg); if (q < 0) @@ -138,7 +140,25 @@ return 0; } +static uirc_event_t uirc_parse_msg(uirc_t *ctx, char *nick, char *arg) +{ + char *text; + int q; + if (*arg == ':') arg++; + payload(text, arg); + + q = uirc_query_search(ctx, arg); + + if (ctx->on_msg != NULL) { + ctx->on_msg(ctx, nick, q, arg, text); + return UIRC_MSG; + } + + return 0; +} + + static uirc_event_t uirc_parse(uirc_t *ctx, char *line) { char *end, *arg, *cmd, *from = line; @@ -184,6 +204,7 @@ if (strcmp(cmd, "001") == 0) return res | uirc_parse_001(ctx, arg); if (strcasecmp(cmd, "join") == 0) return res | uirc_parse_join(ctx, from, arg); if (strcasecmp(cmd, "part") == 0) return res | uirc_parse_part(ctx, from, arg); + if (strcasecmp(cmd, "privmsg") == 0) return res | uirc_parse_msg(ctx, from, arg); return res; } Index: libuirc/libuirc.h =================================================================== --- libuirc/libuirc.h (revision 31358) +++ libuirc/libuirc.h (revision 31359) @@ -32,7 +32,8 @@ UIRC_ME_JOIN = 0x0080, UIRC_JOIN = 0x0100, UIRC_ME_PART = 0x0200, - UIRC_PART = 0x0400 + UIRC_PART = 0x0400, + UIRC_MSG = 0x0800 } uirc_event_t; typedef struct uirc_s uirc_t; @@ -53,6 +54,7 @@ void (*on_join)(uirc_t *ctx, char *nick, int query, char *chan); void (*on_me_part)(uirc_t *ctx, int query, char *chan); void (*on_part)(uirc_t *ctx, char *nick, int query, char *chan, char *reason); + void (*on_msg)(uirc_t *ctx, char *from, int query, char *to, char *text); /* internal */ P_net_socket sk; Index: libuirc/main.c =================================================================== --- libuirc/main.c (revision 31358) +++ libuirc/main.c (revision 31359) @@ -8,7 +8,12 @@ printf("### end query with %s (part)\n", chan); } +static void on_msg(uirc_t *ctx, char *from, int query, char *to, char *text) +{ + printf("(msg:%s) <%s> %s\n", to, from, text); +} + static void read_stdin(uirc_t *ctx) { struct P_pollfd fds[1]; @@ -35,9 +40,10 @@ memset(&irc, 0, sizeof(irc)); irc.on_me_part = on_me_part; + irc.on_msg = on_msg; irc.nick = strdup("libuirc"); - if (uirc_connect(&irc, "repo.hu", 6667, "libuirc test client") != 0) { + if (uirc_connect(&irc, "10.0.0.2", 6667, "libuirc test client") != 0) { printf("Failed to connect.\n"); return 1; }