diff --git a/src/irc.c b/src/irc.c index dd226df..63a602d 100644 --- a/src/irc.c +++ b/src/irc.c @@ -33,6 +33,7 @@ extern int sighup; extern bip_t *_bip; +static int irc_generic_error(struct link_server *server, struct line *line); static int irc_join(struct link_server *server, struct line *line); static int irc_part(struct link_server *server, struct line *line); static int irc_mode(struct link_server *server, struct line *line); @@ -625,6 +626,10 @@ int irc_dispatch_server(bip_t *bip, struct link_server *server, ret = irc_quit(server, line); } else if (irc_line_elem_equals(line, 0, "NICK")) { ret = irc_nick(server, line); + } else if (irc_line_is_error(line)) { + // IRC errors catchall (for unhandled ones) + // logs error to bip.log + ret = irc_generic_error(server, line); } if (ret == OK_COPY) { @@ -1448,6 +1453,17 @@ static int origin_is_me(struct line *l, struct link_server *server) return 0; } +static int irc_generic_error(struct link_server *server, struct line *line) +{ + if (irc_line_count(line) == 4) + mylog(LOG_INFO, "[%s] IRC error: %s", LINK(server)->name, + irc_line_elem(line, 3)); + else + mylog(LOG_INFO, "[%s] IRC error: %s", LINK(server)->name, + irc_line_to_string(line)); + return OK_COPY; +} + static int irc_join(struct link_server *server, struct line *line) { char *s_nick; diff --git a/src/line.c b/src/line.c index 34cc19d..49efbca 100644 --- a/src/line.c +++ b/src/line.c @@ -143,6 +143,12 @@ void irc_line_drop(struct line *line, int elem) bip_cfree(array_drop(&line->words, elem)); } +int irc_line_is_error(struct line *line) +{ + const char *irc_code = irc_line_elem(line, 0); + return (irc_code[0] == '4'); +} + int irc_line_elem_equals(struct line *line, int elem, const char *cmp) { return !strcmp(irc_line_elem(line, elem), cmp); diff --git a/src/line.h b/src/line.h index 2965766..253b241 100644 --- a/src/line.h +++ b/src/line.h @@ -98,6 +98,7 @@ int irc_line_includes(struct line *line, int elem); const char *irc_line_elem(struct line *line, int elem); int irc_line_count(struct line *line); char *irc_line_pop(struct line *l); +int irc_line_is_error(struct line *line); int irc_line_elem_equals(struct line *line, int elem, const char *cmp); int irc_line_elem_case_equals(struct line *line, int elem, const char *cmp); void irc_line_drop(struct line *line, int elem);