Cleanup and fixes of the backlog code
This commit is contained in:
parent
32cf2d462f
commit
f536a0546d
@ -2180,7 +2180,7 @@ int adm_bip(bip_t *bip, struct link_client *ic, struct line *line, int privmsg)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
adm_blreset_store(ic, irc_line_elem(line,
|
adm_blreset_store(ic, irc_line_elem(line,
|
||||||
privmsg + 3));
|
privmsg + 2));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
adm_blreset(ic);
|
adm_blreset(ic);
|
||||||
|
32
src/irc.c
32
src/irc.c
@ -175,9 +175,7 @@ void irc_start_lagtest(struct link_server *l)
|
|||||||
*/
|
*/
|
||||||
void irc_compute_lag(struct link_server *is)
|
void irc_compute_lag(struct link_server *is)
|
||||||
{
|
{
|
||||||
if (is->laginit_ts == -1)
|
assert(is->laginit_ts != -1);
|
||||||
fatal("irc_compute_lag");
|
|
||||||
|
|
||||||
is->lag = time(NULL) - is->laginit_ts;
|
is->lag = time(NULL) - is->laginit_ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,8 +502,7 @@ static void irc_send_join(struct link_client *ic, struct channel *chan)
|
|||||||
char *ircmask;
|
char *ircmask;
|
||||||
|
|
||||||
user = LINK(ic)->user;
|
user = LINK(ic)->user;
|
||||||
if (!user)
|
assert(user);
|
||||||
fatal("irc_send_join: No user associated");
|
|
||||||
|
|
||||||
/* user ircmask here for rbot */
|
/* user ircmask here for rbot */
|
||||||
ircmask = bip_malloc(strlen(LINK(ic)->l_server->nick) +
|
ircmask = bip_malloc(strlen(LINK(ic)->l_server->nick) +
|
||||||
@ -566,8 +563,8 @@ void unbind_from_link(struct link_client *ic)
|
|||||||
for (i = 0; i < l->l_clientc; i++)
|
for (i = 0; i < l->l_clientc; i++)
|
||||||
if (l->l_clientv[i] == ic)
|
if (l->l_clientv[i] == ic)
|
||||||
break;
|
break;
|
||||||
if (i == l->l_clientc)
|
|
||||||
fatal("unbind_from_link");
|
assert(i != l->l_clientc);
|
||||||
|
|
||||||
if (l->who_client == ic) {
|
if (l->who_client == ic) {
|
||||||
mylog(LOG_DEBUG, "unbind_from_link: %p: %d", l->who_client,
|
mylog(LOG_DEBUG, "unbind_from_link: %p: %d", l->who_client,
|
||||||
@ -658,8 +655,9 @@ static void irc_cli_backlog(struct link_client *ic)
|
|||||||
struct user *user;
|
struct user *user;
|
||||||
|
|
||||||
user = LINK(ic)->user;
|
user = LINK(ic)->user;
|
||||||
if (!user)
|
assert(user);
|
||||||
fatal("irc_cli_backlog: No user associated");
|
assert(LINK(ic)->l_server);
|
||||||
|
|
||||||
if (!user->backlog) {
|
if (!user->backlog) {
|
||||||
mylog(LOG_DEBUG, "Backlog disabled for %s, not backlogging",
|
mylog(LOG_DEBUG, "Backlog disabled for %s, not backlogging",
|
||||||
user->name);
|
user->name);
|
||||||
@ -672,7 +670,8 @@ static void irc_cli_backlog(struct link_client *ic)
|
|||||||
backlogl = log_backlogs(LINK(ic)->log);
|
backlogl = log_backlogs(LINK(ic)->log);
|
||||||
while ((bl = list_remove_first(backlogl))) {
|
while ((bl = list_remove_first(backlogl))) {
|
||||||
list_t *bllines;
|
list_t *bllines;
|
||||||
bllines = backlog_lines_from_last_mark(LINK(ic)->log, bl);
|
bllines = backlog_lines_from_last_mark(LINK(ic)->log, bl,
|
||||||
|
LINK(ic)->l_server->nick);
|
||||||
mylog(LOG_INFO, "backlogging: %s", bl);
|
mylog(LOG_INFO, "backlogging: %s", bl);
|
||||||
write_lines(CONN(ic), bllines);
|
write_lines(CONN(ic), bllines);
|
||||||
list_free(bllines);
|
list_free(bllines);
|
||||||
@ -688,8 +687,7 @@ static int irc_cli_startup(bip_t *bip, struct link_client *ic,
|
|||||||
char *user, *pass, *connname;
|
char *user, *pass, *connname;
|
||||||
(void)line;
|
(void)line;
|
||||||
|
|
||||||
if (!ic->init_pass)
|
assert(ic->init_pass);
|
||||||
fatal("internal irc_cli_startup");
|
|
||||||
|
|
||||||
user = get_str_elem(ic->init_pass, 0);
|
user = get_str_elem(ic->init_pass, 0);
|
||||||
if (!user)
|
if (!user)
|
||||||
@ -870,6 +868,7 @@ static int irc_cli_privmsg(bip_t *bip, struct link_client *ic,
|
|||||||
if (irc_line_elem_equals(line, 1, "-bip"))
|
if (irc_line_elem_equals(line, 1, "-bip"))
|
||||||
return adm_bip(bip, ic, line, 1);
|
return adm_bip(bip, ic, line, 1);
|
||||||
|
|
||||||
|
printf("%d<-\n", LINK(ic)->user->blreset_on_talk);
|
||||||
if (LINK(ic)->user->blreset_on_talk)
|
if (LINK(ic)->user->blreset_on_talk)
|
||||||
log_reset_store(LINK(ic)->log, irc_line_elem(line, 1));
|
log_reset_store(LINK(ic)->log, irc_line_elem(line, 1));
|
||||||
return OK_COPY_CLI;
|
return OK_COPY_CLI;
|
||||||
@ -1143,8 +1142,7 @@ static void irc_copy_cli(struct link_client *src, struct link_client *dest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ischannel(*irc_line_elem(line, 1)) || LINK(src) != LINK(dest)) {
|
if (ischannel(*irc_line_elem(line, 1)) || LINK(src) != LINK(dest)) {
|
||||||
if (line->origin)
|
assert(!line->origin);
|
||||||
fatal("internal error: line->origin should be null");
|
|
||||||
line->origin = LINK(src)->l_server->nick;
|
line->origin = LINK(src)->l_server->nick;
|
||||||
str = irc_line_to_string(line);
|
str = irc_line_to_string(line);
|
||||||
line->origin = NULL;
|
line->origin = NULL;
|
||||||
@ -2126,8 +2124,7 @@ connection_t *irc_server_connect(struct link *link)
|
|||||||
0, 0, NULL, NULL,
|
0, 0, NULL, NULL,
|
||||||
#endif
|
#endif
|
||||||
CONNECT_TIMEOUT);
|
CONNECT_TIMEOUT);
|
||||||
if (!conn)
|
assert(conn);
|
||||||
fatal("connection_new");
|
|
||||||
if (conn->handle == -1) {
|
if (conn->handle == -1) {
|
||||||
mylog(LOG_INFO, "Cannot connect.");
|
mylog(LOG_INFO, "Cannot connect.");
|
||||||
connection_free(conn);
|
connection_free(conn);
|
||||||
@ -2386,8 +2383,7 @@ void bip_on_event(bip_t *bip, connection_t *conn)
|
|||||||
|
|
||||||
if (conn == bip->listener) {
|
if (conn == bip->listener) {
|
||||||
struct link_client *n = irc_accept_new(conn);
|
struct link_client *n = irc_accept_new(conn);
|
||||||
if (!n)
|
assert(n);
|
||||||
fatal("Problem while binding local socket");
|
|
||||||
list_add_last(&bip->conn_list, CONN(n));
|
list_add_last(&bip->conn_list, CONN(n));
|
||||||
list_add_last(&bip->connecting_client_list, n);
|
list_add_last(&bip->connecting_client_list, n);
|
||||||
return;
|
return;
|
||||||
|
@ -25,9 +25,9 @@
|
|||||||
#define OK_COPY_CLI (4)
|
#define OK_COPY_CLI (4)
|
||||||
#define OK_COPY_WHO (5)
|
#define OK_COPY_WHO (5)
|
||||||
|
|
||||||
#define P_SERV "bip.bip.bip"
|
#define P_SERV "b.i.p"
|
||||||
#define S_PING "BIPPING"
|
#define S_PING "BIPPING"
|
||||||
#define P_IRCMASK "-bip!bip@bip.bip.bip"
|
#define P_IRCMASK "-bip!bip@" P_SERV
|
||||||
|
|
||||||
struct server {
|
struct server {
|
||||||
char *host;
|
char *host;
|
||||||
|
89
src/log.c
89
src/log.c
@ -32,8 +32,8 @@ void logfile_free(logfile_t *lf);
|
|||||||
static void log_drop(log_t *log, const char *storename);
|
static void log_drop(log_t *log, const char *storename);
|
||||||
|
|
||||||
#define BOLD_CHAR 0x02
|
#define BOLD_CHAR 0x02
|
||||||
#define LAMESTRING "!bip@bip.bip.bip PRIVMSG "
|
#define LAMESTRING "!bip@" P_SERV " PRIVMSG "
|
||||||
#define PMSG_ARROW " \002->\002 "
|
#define PMSG_ARROW "\002->\002"
|
||||||
|
|
||||||
int check_dir(char *filename, int is_fatal)
|
int check_dir(char *filename, int is_fatal)
|
||||||
{
|
{
|
||||||
@ -270,14 +270,17 @@ static int log_add_file(log_t *logdata, const char *destination,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fseek(f, 0, SEEK_END) == -1) {
|
||||||
|
mylog(LOG_ERROR, "fseek(%s) %s", uniq_fname,
|
||||||
|
strerror(errno));
|
||||||
|
free(uniq_fname);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
lf = bip_malloc(sizeof(logfile_t));
|
lf = bip_malloc(sizeof(logfile_t));
|
||||||
lf->file = f;
|
lf->file = f;
|
||||||
lf->filename = uniq_fname;
|
|
||||||
|
|
||||||
fseek(lf->file, 0, SEEK_END);
|
|
||||||
if (ftell(f) < 0)
|
|
||||||
fatal("ftell");
|
|
||||||
lf->len = ftell(f);
|
lf->len = ftell(f);
|
||||||
|
lf->filename = uniq_fname;
|
||||||
log_updatelast(lf);
|
log_updatelast(lf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,12 +397,10 @@ logstore_t *log_find_file(log_t *logdata, const char *destination)
|
|||||||
|
|
||||||
if (!logdata->user->backlog) {
|
if (!logdata->user->backlog) {
|
||||||
/* remove oldlf from file_group */
|
/* remove oldlf from file_group */
|
||||||
if (list_remove_first(&store->file_group) != oldlf)
|
assert(list_remove_first(&store->file_group) == oldlf);
|
||||||
fatal("internal log_find_file 2");
|
|
||||||
logfile_free(oldlf);
|
logfile_free(oldlf);
|
||||||
if (list_get_first(&store->file_group)
|
assert(list_get_first(&store->file_group) ==
|
||||||
!= list_get_last(&store->file_group))
|
list_get_last(&store->file_group));
|
||||||
fatal("internal log_find_file 3");
|
|
||||||
} else {
|
} else {
|
||||||
fclose(oldlf->file);
|
fclose(oldlf->file);
|
||||||
oldlf->file = NULL;
|
oldlf->file = NULL;
|
||||||
@ -692,6 +693,7 @@ void log_reinit_all(log_t *logdata)
|
|||||||
void log_reset_store(log_t *log, const char *storename)
|
void log_reset_store(log_t *log, const char *storename)
|
||||||
{
|
{
|
||||||
logstore_t *store;
|
logstore_t *store;
|
||||||
|
|
||||||
store = hash_get(&log->logfgs, storename);
|
store = hash_get(&log->logfgs, storename);
|
||||||
if (store)
|
if (store)
|
||||||
log_reset(store);
|
log_reset(store);
|
||||||
@ -779,18 +781,14 @@ int log_has_backlog(log_t *logdata, const char *destination)
|
|||||||
return store->file_offset != lf->len;
|
return store->file_offset != lf->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* chan:
|
query:
|
||||||
* 13-05-2005 12:14:29 > nohar: coucou
|
09-01-2009 14:16:10 < nohar!~nohar@haruka.t1r.net: repl querytest
|
||||||
* 13-05-2005 12:14:30 < nohar!~nohar@je.suis.t1r.net: coucou
|
09-01-2009 14:16:37 > bip4ever: je dis yo la quand meem
|
||||||
*
|
chan:
|
||||||
* private:
|
09-01-2009 14:15:57 > bip4ever: chantest
|
||||||
* 13-05-2005 12:14:53 > nohar (jj): 1 luv PHP
|
09-01-2009 14:16:21 < nohar!~nohar@haruka.t1r.net: chantestrepl
|
||||||
* 13-05-2005 12:14:55 < jj!john@thebox.ofjj.net (nohar): t00 s3xy
|
*/
|
||||||
* 01-08-2005 10:46:11 < * jj!john@thebox.ofjj.net
|
|
||||||
*/
|
|
||||||
|
|
||||||
char *log_beautify(log_t *logdata, const char *buf, const char *dest)
|
char *log_beautify(log_t *logdata, const char *buf, const char *dest)
|
||||||
{
|
{
|
||||||
int action = 0;
|
int action = 0;
|
||||||
@ -805,8 +803,7 @@ char *log_beautify(log_t *logdata, const char *buf, const char *dest)
|
|||||||
int out;
|
int out;
|
||||||
int done;
|
int done;
|
||||||
|
|
||||||
if (!buf)
|
assert(buf);
|
||||||
fatal("BUG log_beautify not called correctly!");
|
|
||||||
|
|
||||||
p = strchr(buf, ' ');
|
p = strchr(buf, ' ');
|
||||||
if (!p || !p[0] || !p[1])
|
if (!p || !p[0] || !p[1])
|
||||||
@ -884,7 +881,7 @@ char *log_beautify(log_t *logdata, const char *buf, const char *dest)
|
|||||||
sod = dest;
|
sod = dest;
|
||||||
lod = strlen(dest);
|
lod = strlen(dest);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
if (out && !ischannel(*dest)) {
|
if (out && !ischannel(*dest)) {
|
||||||
const char *stmp;
|
const char *stmp;
|
||||||
size_t ltmp;
|
size_t ltmp;
|
||||||
@ -898,6 +895,7 @@ char *log_beautify(log_t *logdata, const char *buf, const char *dest)
|
|||||||
son = stmp;
|
son = stmp;
|
||||||
lon = ltmp;
|
lon = ltmp;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
som = p;
|
som = p;
|
||||||
lom = strlen(p);
|
lom = strlen(p);
|
||||||
@ -950,7 +948,8 @@ char *log_beautify(log_t *logdata, const char *buf, const char *dest)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf, list_t *res)
|
static int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf,
|
||||||
|
list_t *res, const char *dest)
|
||||||
{
|
{
|
||||||
char *buf, *logbr;
|
char *buf, *logbr;
|
||||||
int close = 0;
|
int close = 0;
|
||||||
@ -1004,7 +1003,8 @@ int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf, list_t *res)
|
|||||||
buf[slen - 2] = 0;
|
buf[slen - 2] = 0;
|
||||||
if (buf[0] == 0 || buf[0] == '\n')
|
if (buf[0] == 0 || buf[0] == '\n')
|
||||||
continue;
|
continue;
|
||||||
logbr = log_beautify(log, buf, store->name);
|
|
||||||
|
logbr = log_beautify(log, buf, dest);
|
||||||
if (logbr)
|
if (logbr)
|
||||||
list_add_last(res, logbr);
|
list_add_last(res, logbr);
|
||||||
|
|
||||||
@ -1017,7 +1017,7 @@ int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf, list_t *res)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
list_t *log_backread(log_t *log, const char *storename)
|
static list_t *log_backread(log_t *log, const char *storename, const char *dest)
|
||||||
{
|
{
|
||||||
list_t *ret;
|
list_t *ret;
|
||||||
|
|
||||||
@ -1053,7 +1053,7 @@ list_t *log_backread(log_t *log, const char *storename)
|
|||||||
for (list_it_init(&store->file_group, &file_it);
|
for (list_it_init(&store->file_group, &file_it);
|
||||||
(logf = list_it_item(&file_it));
|
(logf = list_it_item(&file_it));
|
||||||
list_it_next(&file_it)) {
|
list_it_next(&file_it)) {
|
||||||
if (!log_backread_file(log, store, logf, ret)) {
|
if (!log_backread_file(log, store, logf, ret, dest)) {
|
||||||
log_reinit(store);
|
log_reinit(store);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1293,26 +1293,29 @@ list_t *backlog_hours(log_t *log, const char *storename, int hours)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
list_t *backlog_lines_from_last_mark(log_t *log, const char *bl)
|
list_t *backlog_lines_from_last_mark(log_t *log, const char *bl,
|
||||||
|
const char *cli_nick)
|
||||||
{
|
{
|
||||||
list_t *ret;
|
list_t *ret;
|
||||||
struct line l;
|
struct line l;
|
||||||
|
const char *dest;
|
||||||
|
|
||||||
ret = list_new(NULL);
|
ret = list_new(NULL);
|
||||||
|
if (ischannel(*bl))
|
||||||
|
dest = bl;
|
||||||
|
else
|
||||||
|
dest = cli_nick;
|
||||||
|
|
||||||
if (log_has_backlog(log, bl)) {
|
if (log_has_backlog(log, bl)) {
|
||||||
ret = log_backread(log, bl);
|
ret = log_backread(log, bl, dest);
|
||||||
|
/* clean this up */
|
||||||
if (ischannel(*bl)) {
|
irc_line_init(&l);
|
||||||
/* clean this up */
|
l.origin = P_IRCMASK;
|
||||||
irc_line_init(&l);
|
_irc_line_append(&l, "PRIVMSG");
|
||||||
l.origin = P_IRCMASK;
|
_irc_line_append(&l, dest);
|
||||||
_irc_line_append(&l, "PRIVMSG");
|
_irc_line_append(&l, "End of backlog");
|
||||||
_irc_line_append(&l, bl);
|
list_add_last(ret, irc_line_to_string(&l));
|
||||||
_irc_line_append(&l, "End of backlog");
|
_irc_line_deinit(&l);
|
||||||
list_add_last(ret, irc_line_to_string(&l));
|
|
||||||
_irc_line_deinit(&l);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -103,5 +103,5 @@ int check_dir(char *filename, int is_fatal);
|
|||||||
void log_reset_store(log_t *log, const char *storename);
|
void log_reset_store(log_t *log, const char *storename);
|
||||||
|
|
||||||
list_t *log_backlogs(log_t *log);
|
list_t *log_backlogs(log_t *log);
|
||||||
list_t *backlog_lines_from_last_mark(log_t *log, const char *bl);
|
list_t *backlog_lines_from_last_mark(log_t *log, const char *bl, const char *);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user