1
0
forked from bip/bip

Cleanup and fixes of the backlog code

This commit is contained in:
Arnaud Cornet 2009-01-10 12:35:59 +01:00
parent 32cf2d462f
commit f536a0546d
5 changed files with 64 additions and 65 deletions

View File

@ -2180,7 +2180,7 @@ int adm_bip(bip_t *bip, struct link_client *ic, struct line *line, int privmsg)
}
} else {
adm_blreset_store(ic, irc_line_elem(line,
privmsg + 3));
privmsg + 2));
}
} else {
adm_blreset(ic);

View File

@ -175,9 +175,7 @@ void irc_start_lagtest(struct link_server *l)
*/
void irc_compute_lag(struct link_server *is)
{
if (is->laginit_ts == -1)
fatal("irc_compute_lag");
assert(is->laginit_ts != -1);
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;
user = LINK(ic)->user;
if (!user)
fatal("irc_send_join: No user associated");
assert(user);
/* user ircmask here for rbot */
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++)
if (l->l_clientv[i] == ic)
break;
if (i == l->l_clientc)
fatal("unbind_from_link");
assert(i != l->l_clientc);
if (l->who_client == ic) {
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;
user = LINK(ic)->user;
if (!user)
fatal("irc_cli_backlog: No user associated");
assert(user);
assert(LINK(ic)->l_server);
if (!user->backlog) {
mylog(LOG_DEBUG, "Backlog disabled for %s, not backlogging",
user->name);
@ -672,7 +670,8 @@ static void irc_cli_backlog(struct link_client *ic)
backlogl = log_backlogs(LINK(ic)->log);
while ((bl = list_remove_first(backlogl))) {
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);
write_lines(CONN(ic), bllines);
list_free(bllines);
@ -688,8 +687,7 @@ static int irc_cli_startup(bip_t *bip, struct link_client *ic,
char *user, *pass, *connname;
(void)line;
if (!ic->init_pass)
fatal("internal irc_cli_startup");
assert(ic->init_pass);
user = get_str_elem(ic->init_pass, 0);
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"))
return adm_bip(bip, ic, line, 1);
printf("%d<-\n", LINK(ic)->user->blreset_on_talk);
if (LINK(ic)->user->blreset_on_talk)
log_reset_store(LINK(ic)->log, irc_line_elem(line, 1));
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 (line->origin)
fatal("internal error: line->origin should be null");
assert(!line->origin);
line->origin = LINK(src)->l_server->nick;
str = irc_line_to_string(line);
line->origin = NULL;
@ -2126,8 +2124,7 @@ connection_t *irc_server_connect(struct link *link)
0, 0, NULL, NULL,
#endif
CONNECT_TIMEOUT);
if (!conn)
fatal("connection_new");
assert(conn);
if (conn->handle == -1) {
mylog(LOG_INFO, "Cannot connect.");
connection_free(conn);
@ -2386,8 +2383,7 @@ void bip_on_event(bip_t *bip, connection_t *conn)
if (conn == bip->listener) {
struct link_client *n = irc_accept_new(conn);
if (!n)
fatal("Problem while binding local socket");
assert(n);
list_add_last(&bip->conn_list, CONN(n));
list_add_last(&bip->connecting_client_list, n);
return;

View File

@ -25,9 +25,9 @@
#define OK_COPY_CLI (4)
#define OK_COPY_WHO (5)
#define P_SERV "bip.bip.bip"
#define P_SERV "b.i.p"
#define S_PING "BIPPING"
#define P_IRCMASK "-bip!bip@bip.bip.bip"
#define P_IRCMASK "-bip!bip@" P_SERV
struct server {
char *host;

View File

@ -32,8 +32,8 @@ void logfile_free(logfile_t *lf);
static void log_drop(log_t *log, const char *storename);
#define BOLD_CHAR 0x02
#define LAMESTRING "!bip@bip.bip.bip PRIVMSG "
#define PMSG_ARROW " \002->\002 "
#define LAMESTRING "!bip@" P_SERV " PRIVMSG "
#define PMSG_ARROW "\002->\002"
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;
}
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->file = f;
lf->filename = uniq_fname;
fseek(lf->file, 0, SEEK_END);
if (ftell(f) < 0)
fatal("ftell");
lf->len = ftell(f);
lf->filename = uniq_fname;
log_updatelast(lf);
}
@ -394,12 +397,10 @@ logstore_t *log_find_file(log_t *logdata, const char *destination)
if (!logdata->user->backlog) {
/* remove oldlf from file_group */
if (list_remove_first(&store->file_group) != oldlf)
fatal("internal log_find_file 2");
assert(list_remove_first(&store->file_group) == oldlf);
logfile_free(oldlf);
if (list_get_first(&store->file_group)
!= list_get_last(&store->file_group))
fatal("internal log_find_file 3");
assert(list_get_first(&store->file_group) ==
list_get_last(&store->file_group));
} else {
fclose(oldlf->file);
oldlf->file = NULL;
@ -692,6 +693,7 @@ void log_reinit_all(log_t *logdata)
void log_reset_store(log_t *log, const char *storename)
{
logstore_t *store;
store = hash_get(&log->logfgs, storename);
if (store)
log_reset(store);
@ -779,18 +781,14 @@ int log_has_backlog(log_t *logdata, const char *destination)
return store->file_offset != lf->len;
}
/*
* chan:
* 13-05-2005 12:14:29 > nohar: coucou
* 13-05-2005 12:14:30 < nohar!~nohar@je.suis.t1r.net: coucou
*
* private:
* 13-05-2005 12:14:53 > nohar (jj): 1 luv PHP
* 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
*/
query:
09-01-2009 14:16:10 < nohar!~nohar@haruka.t1r.net: repl querytest
09-01-2009 14:16:37 > bip4ever: je dis yo la quand meem
chan:
09-01-2009 14:15:57 > bip4ever: chantest
09-01-2009 14:16:21 < nohar!~nohar@haruka.t1r.net: chantestrepl
*/
char *log_beautify(log_t *logdata, const char *buf, const char *dest)
{
int action = 0;
@ -805,8 +803,7 @@ char *log_beautify(log_t *logdata, const char *buf, const char *dest)
int out;
int done;
if (!buf)
fatal("BUG log_beautify not called correctly!");
assert(buf);
p = strchr(buf, ' ');
if (!p || !p[0] || !p[1])
@ -884,7 +881,7 @@ char *log_beautify(log_t *logdata, const char *buf, const char *dest)
sod = dest;
lod = strlen(dest);
}
#if 0
if (out && !ischannel(*dest)) {
const char *stmp;
size_t ltmp;
@ -898,6 +895,7 @@ char *log_beautify(log_t *logdata, const char *buf, const char *dest)
son = stmp;
lon = ltmp;
}
#endif
som = p;
lom = strlen(p);
@ -950,7 +948,8 @@ char *log_beautify(log_t *logdata, const char *buf, const char *dest)
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;
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;
if (buf[0] == 0 || buf[0] == '\n')
continue;
logbr = log_beautify(log, buf, store->name);
logbr = log_beautify(log, buf, dest);
if (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;
}
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;
@ -1053,7 +1053,7 @@ list_t *log_backread(log_t *log, const char *storename)
for (list_it_init(&store->file_group, &file_it);
(logf = list_it_item(&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);
return ret;
}
@ -1293,26 +1293,29 @@ list_t *backlog_hours(log_t *log, const char *storename, int hours)
}
#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;
struct line l;
const char *dest;
ret = list_new(NULL);
if (ischannel(*bl))
dest = bl;
else
dest = cli_nick;
if (log_has_backlog(log, bl)) {
ret = log_backread(log, bl);
if (ischannel(*bl)) {
/* clean this up */
irc_line_init(&l);
l.origin = P_IRCMASK;
_irc_line_append(&l, "PRIVMSG");
_irc_line_append(&l, bl);
_irc_line_append(&l, "End of backlog");
list_add_last(ret, irc_line_to_string(&l));
_irc_line_deinit(&l);
}
ret = log_backread(log, bl, dest);
/* clean this up */
irc_line_init(&l);
l.origin = P_IRCMASK;
_irc_line_append(&l, "PRIVMSG");
_irc_line_append(&l, dest);
_irc_line_append(&l, "End of backlog");
list_add_last(ret, irc_line_to_string(&l));
_irc_line_deinit(&l);
}
return ret;
}

View File

@ -103,5 +103,5 @@ int check_dir(char *filename, int is_fatal);
void log_reset_store(log_t *log, const char *storename);
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