Log unhandled IRC errors as LOG_INFO in bip.log
This will allow for user feedback in main bip.log when an IRC error occurs, like: - 401 ERR_NOSUCHNICK - 404 ERR_CANNOTSENDTOCHAN - 432 ERR_ERRONEUSNICKNAME These should not be logged as LOG_ERROR as they are not bip errors but usually on the end user instead. Signed-off-by: Loïc Gomez <bip@animanova.fr>
This commit is contained in:
parent
f797d25e06
commit
c14f4634b6
16
src/irc.c
16
src/irc.c
@ -33,6 +33,7 @@
|
|||||||
extern int sighup;
|
extern int sighup;
|
||||||
extern bip_t *_bip;
|
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_join(struct link_server *server, struct line *line);
|
||||||
static int irc_part(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);
|
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);
|
ret = irc_quit(server, line);
|
||||||
} else if (irc_line_elem_equals(line, 0, "NICK")) {
|
} else if (irc_line_elem_equals(line, 0, "NICK")) {
|
||||||
ret = irc_nick(server, line);
|
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) {
|
if (ret == OK_COPY) {
|
||||||
@ -1448,6 +1453,17 @@ static int origin_is_me(struct line *l, struct link_server *server)
|
|||||||
return 0;
|
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)
|
static int irc_join(struct link_server *server, struct line *line)
|
||||||
{
|
{
|
||||||
char *s_nick;
|
char *s_nick;
|
||||||
|
@ -143,6 +143,13 @@ void irc_line_drop(struct line *line, int elem)
|
|||||||
bip_cfree(array_drop(&line->words, elem));
|
bip_cfree(array_drop(&line->words, elem));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int irc_line_is_error(struct line *line)
|
||||||
|
{
|
||||||
|
const char *irc_code = irc_line_elem(line, 0);
|
||||||
|
const char *error_code = "4";
|
||||||
|
return (irc_code[0] == error_code[0]);
|
||||||
|
}
|
||||||
|
|
||||||
int irc_line_elem_equals(struct line *line, int elem, const char *cmp)
|
int irc_line_elem_equals(struct line *line, int elem, const char *cmp)
|
||||||
{
|
{
|
||||||
return !strcmp(irc_line_elem(line, elem), cmp);
|
return !strcmp(irc_line_elem(line, elem), cmp);
|
||||||
|
@ -98,6 +98,7 @@ int irc_line_includes(struct line *line, int elem);
|
|||||||
const char *irc_line_elem(struct line *line, int elem);
|
const char *irc_line_elem(struct line *line, int elem);
|
||||||
int irc_line_count(struct line *line);
|
int irc_line_count(struct line *line);
|
||||||
char *irc_line_pop(struct line *l);
|
char *irc_line_pop(struct line *l);
|
||||||
|
unsigned 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_equals(struct line *line, int elem, const char *cmp);
|
||||||
int irc_line_elem_case_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);
|
void irc_line_drop(struct line *line, int elem);
|
||||||
|
Loading…
Reference in New Issue
Block a user