1
0
forked from bip/bip

sexy backlog (untested)

This commit is contained in:
nohar 2005-05-13 10:28:15 +00:00
parent 0a9a61954f
commit 9a005cbb80

View File

@ -595,6 +595,11 @@ int log_has_backlog(log_t *logdata, char *destination)
#define BOLD_CHAR 0x02 #define BOLD_CHAR 0x02
#define LAMESTRING "!bip@bip.bip.bip PRIVMSG " #define LAMESTRING "!bip@bip.bip.bip PRIVMSG "
/*
* 13-05-2005 12:14:29 nohar (nohar): coucou
* 13-05-2005 12:14:30 nohar!~nohar@je.suis.t1r.net (nohar): coucou
*/
/* must *not* return NULL */ /* must *not* return NULL */
static char *log_beautify(char *buf, char *dest, int *raw) static char *log_beautify(char *buf, char *dest, int *raw)
{ {
@ -604,8 +609,8 @@ static char *log_beautify(char *buf, char *dest, int *raw)
* so = start, lo = length * so = start, lo = length
* ts = timestamp, n = sender nick, m = message or action * ts = timestamp, n = sender nick, m = message or action
*/ */
char *sots, *son, *som; char *sots, *son, *som, *sod = NULL;
size_t lots, lon, lom; size_t lots, lon, lom, lod;
char *ret; char *ret;
@ -635,7 +640,7 @@ static char *log_beautify(char *buf, char *dest, int *raw)
/* 'date time blawithnoexcl bla bla ! bla' --> ? */ /* 'date time blawithnoexcl bla bla ! bla' --> ? */
while (*p && *p != '!' && *p != ' ' && *p != ':') while (*p && *p != '!' && *p != ' ' && *p != ':')
p++; p++;
if (!p || !p[0] || !p[1]) if (!p[0] || !p[1])
return buf; return buf;
lon = p - son; lon = p - son;
p = strchr(p, ' '); p = strchr(p, ' ');
@ -643,24 +648,51 @@ static char *log_beautify(char *buf, char *dest, int *raw)
return buf; return buf;
p++; p++;
if (*p == '(') {
sod = p;
while (*p && *p != ')' && *p != ' ')
p++;
if (*p != ')')
return buf;
lod = p - sod;
p++;
if (*p != ':')
return buf;
p++;
if (*p != ' ')
return buf;
p++;
if (!p[0] || !p[1])
return buf;
} else {
sod = dest;
lod = strlen(dest);
}
som = p; som = p;
lom = strlen(p); lom = strlen(p);
*raw = 1; *raw = 1;
p = ret = (char *)malloc( p = ret = (char *)malloc(
1 + lon + strlen(LAMESTRING) + strlen(dest) + 2 + lots + 1 + lon + strlen(LAMESTRING) + lod + 2 + lots +
1 + lom + 3 + action * (2 + strlen("ACTION "))); 1 + lom + 3 + action * (2 + strlen("ACTION ")));
if (!p) if (!p)
fatal("out of memory"); fatal("out of memory");
*p++ = ':'; *p++ = ':';
memcpy(p, son, lon); memcpy(p, son, lon);
p += lon; p += lon;
strcpy(p, LAMESTRING); strcpy(p, LAMESTRING);
p += strlen(LAMESTRING); p += strlen(LAMESTRING);
strcpy(p, dest);
p += strlen(dest); memcpy(p, sod, lod);
p += lod;
strcpy(p, " :"); strcpy(p, " :");
p += 2; p += 2;
if (action) { if (action) {
*p++ = 1; *p++ = 1;
memcpy(p, "ACTION ", strlen("ACTION ")); memcpy(p, "ACTION ", strlen("ACTION "));
@ -668,16 +700,19 @@ static char *log_beautify(char *buf, char *dest, int *raw)
} }
memcpy(p, sots, lots); memcpy(p, sots, lots);
p += lots; p += lots;
*p++ = ' '; *p++ = ' ';
memcpy(p, som, lom); memcpy(p, som, lom);
p += lom; p += lom;
if (action) if (action)
*p++ = 1; *p++ = 1;
*p++ = '\r'; *p++ = '\r';
*p++ = '\n'; *p++ = '\n';
*p = 0; *p = 0;
free(buf); free(buf);
mylog(LOG_INFO, "beautify in: \"%s\"", raw); mylog(LOG_INFO, "beautify in: \"%s\"", buf);
mylog(LOG_INFO, "beautify out: \"%s\"", ret); mylog(LOG_INFO, "beautify out: \"%s\"", ret);
return ret; return ret;
} }