summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct5
-rw-r--r--config.c36
-rw-r--r--config.h3
-rw-r--r--export_xml.c8
-rw-r--r--main.c2
-rw-r--r--parsing.c260
-rw-r--r--parsing.h2
-rw-r--r--regexset.c115
-rw-r--r--regexset.h10
-rw-r--r--user.c1
-rw-r--r--user.h3
11 files changed, 361 insertions, 84 deletions
diff --git a/SConstruct b/SConstruct
index 1f20d54..cbc8521 100644
--- a/SConstruct
+++ b/SConstruct
@@ -3,20 +3,19 @@ AddOption('--release', action = 'store_true')
env = Environment()
conf = Configure(env)
-for lib in ('config', 'pcre', 'xml2', 'pthread'):
+for lib in ('config', 'pcre', 'xml2'):
if not conf.CheckLib(lib):
print 'Could not find %s' % lib
Exit(1)
env = conf.Finish()
-env.Append(CCFLAGS = ['-std=c99', '-D_GNU_SOURCE', '-pthread'])
+env.Append(CCFLAGS = ['-std=c99', '-D_GNU_SOURCE'])
if GetOption('release'):
env.Append(CCFLAGS = ['-O2'])
else:
env.Append(CCFLAGS = ['-Wall', '-g'])
-env.Append(LINKFLAGS = ['-pthread'])
env.ParseConfig('pkg-config --cflags --libs libconfig')
env.ParseConfig('pcre-config --cflags --libs')
env.ParseConfig('xml2-config --cflags --libs')
diff --git a/config.c b/config.c
index 2cb6aa6..84bcf39 100644
--- a/config.c
+++ b/config.c
@@ -27,10 +27,6 @@ int cfg_init() {
return 0;
}
- if(!config_lookup_int(&config, "threads", &ircstats_config.threads)) {
- ircstats_config.threads = 1;
- }
-
if(!config_lookup_int(&config, "monolog_min", &ircstats_config.monolog_min)) {
ircstats_config.monolog_min = 5;
}
@@ -39,6 +35,14 @@ int cfg_init() {
ircstats_config.wordlen_min = 3;
}
+ if(!config_lookup_string(&config, "log_date_format", &ircstats_config.log_date_format)) {
+ ircstats_config.log_date_format = NULL;
+ }
+
+ if(!config_lookup_string(&config, "day_date_format", &ircstats_config.day_date_format)) {
+ ircstats_config.day_date_format = NULL;
+ }
+
config_setting_t *regexes_setting = config_lookup(&config, "regexes");
if(!config_setting_is_aggregate(regexes_setting)) {
fprintf(stderr, "Setting \"regexes\" must be an aggregate type.\n");
@@ -49,12 +53,28 @@ int cfg_init() {
for(int i = 0; i < regex_count; i++) {
config_setting_t *re_setting = config_setting_get_elem(regexes_setting, i);
- const char *text, *join, *kick;
- if(!(config_setting_lookup_string(re_setting, "text", &text) && config_setting_lookup_string(re_setting, "join", &join) && config_setting_lookup_string(re_setting, "kick", &kick))) {
+ const char *text, *join, *part, *quit, *kick, *nick_changed, *log_opened, *day_changed, *log_date_format, *day_date_format;
+ if(!(config_setting_lookup_string(re_setting, "text", &text)
+ && config_setting_lookup_string(re_setting, "join", &join)
+ && config_setting_lookup_string(re_setting, "part", &part)
+ && config_setting_lookup_string(re_setting, "quit", &quit)
+ && config_setting_lookup_string(re_setting, "kick", &kick)
+ && config_setting_lookup_string(re_setting, "nick_changed", &nick_changed)
+ && config_setting_lookup_string(re_setting, "log_opened", &log_opened)
+ )) {
fprintf(stderr, "Regex set #%d missing one or more keys.\n", i+1);
return 0;
}
- if(!rs_add(text, join, kick))
+
+ if(!config_setting_lookup_string(re_setting, "day_changed", &day_changed)) {
+ day_changed = NULL;
+ }
+
+ if(!config_setting_lookup_string(re_setting, "log_date_format", &log_date_format))
+ log_date_format = NULL;
+ if(!config_setting_lookup_string(re_setting, "day_date_format", &day_date_format))
+ day_date_format = NULL;
+ if(!rs_add(text, join, part, quit, kick, nick_changed, log_opened, day_changed, log_date_format, day_date_format))
return 0;
}
@@ -86,7 +106,7 @@ int cfg_init() {
}
config_setting_t *files = config_setting_get_member(channel_setting, "files");
if(!config_setting_is_aggregate(files)) {
- fprintf(stderr, "Setting \"files\" must be an aggregate type (no files added).\n", name);
+ fprintf(stderr, "Setting \"files\" must be an aggregate type (no files added).\n");
continue;
}
int file_count = config_setting_length(files);
diff --git a/config.h b/config.h
index c62dfa5..ef2e3a4 100644
--- a/config.h
+++ b/config.h
@@ -5,7 +5,8 @@ int cfg_init();
void cfg_free();
struct ircstats_config_t {
- int threads, monolog_min, wordlen_min;
+ int monolog_min, wordlen_min;
+ const char *log_date_format, *day_date_format;
};
extern struct ircstats_config_t ircstats_config;
diff --git a/export_xml.c b/export_xml.c
index 212b463..1f851d0 100644
--- a/export_xml.c
+++ b/export_xml.c
@@ -79,6 +79,14 @@ int export_xml(struct channel_t *channel, struct user_t *users) {
xmlTextWriterWriteFormatString(writer, "%llu", user->monologs);
xmlTextWriterEndElement(writer);
+ xmlTextWriterStartElement(writer, (const xmlChar*)"seen_first");
+ xmlTextWriterWriteFormatString(writer, "%lu", user->seen_first);
+ xmlTextWriterEndElement(writer);
+
+ xmlTextWriterStartElement(writer, (const xmlChar*)"seen_last");
+ xmlTextWriterWriteFormatString(writer, "%lu", user->seen_last);
+ xmlTextWriterEndElement(writer);
+
/* Add lines for this user. */
xmlTextWriterStartElement(writer, (const xmlChar*)"lines");
for(int h = 0; h < 24; h++) {
diff --git a/main.c b/main.c
index c864b8d..b6fb6ca 100644
--- a/main.c
+++ b/main.c
@@ -25,7 +25,7 @@ int main(int argc, char **argv) {
return 1;
}
- process(ircstats_config.threads);
+ process();
nick_free();
cfg_free();
diff --git a/parsing.c b/parsing.c
index 9653eb8..2447363 100644
--- a/parsing.c
+++ b/parsing.c
@@ -2,7 +2,7 @@
#include <string.h>
#include <wctype.h>
#include <wchar.h>
-#include <pthread.h>
+#include <errno.h>
#include "parsing.h"
#include "channel.h"
@@ -15,29 +15,54 @@
#define TEXT_BUFFER_SIZE 0x400
#define LINE_BUFFER_SIZE 0x400
#define TIME_BUFFER_SIZE 0xf
+#define DATE_BUFFER_SIZE 0x20
-static pthread_mutex_t user_mutex, word_mutex, channel_mutex;
+#define max(a, b) ((a) > (b) ? (a) : (b))
static struct user_t *last_user = NULL;
static int in_monolog = 0, monolog_len = 0;
+static struct tm now_global;
+
static inline void add_word(struct user_t *user, wchar_t *word, int len) {
- pthread_mutex_lock(&user_mutex);
user->words++;
- pthread_mutex_unlock(&user_mutex);
word[len] = '\0';
char mbword[TEXT_BUFFER_SIZE];
wcstombs(mbword, word, TEXT_BUFFER_SIZE);
- pthread_mutex_lock(&word_mutex);
struct word_t *word_s = word_get(mbword);
word_s->count++;
- pthread_mutex_unlock(&word_mutex);
+}
+
+static inline char *parse_getline(char *buffer, int bufsize, FILE *f) {
+ char *r;
+
+ r = fgets(buffer, bufsize, f);
+
+ return r;
}
static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *rs) {
char line[LINE_BUFFER_SIZE];
+ const char *log_date_format, *day_date_format;
+ struct tm now;
+
+ if(rs->log_date_format) {
+ log_date_format = rs->log_date_format;
+ } else if(ircstats_config.log_date_format) {
+ log_date_format = ircstats_config.log_date_format;
+ } else {
+ log_date_format = NULL;
+ }
- while(fgets(line, LINE_BUFFER_SIZE, f)) {
+ if(rs->day_date_format) {
+ day_date_format = rs->day_date_format;
+ } else if(ircstats_config.day_date_format) {
+ day_date_format = ircstats_config.day_date_format;
+ } else {
+ day_date_format = NULL;
+ }
+
+ while(parse_getline(line, LINE_BUFFER_SIZE, f)) {
int rc;
int ovector[30];
@@ -48,7 +73,6 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
pcre_copy_named_substring(rs->text, line, ovector, rc, "text", text, TEXT_BUFFER_SIZE);
pcre_copy_named_substring(rs->text, line, ovector, rc, "hour", hour_s, TIME_BUFFER_SIZE);
pcre_copy_named_substring(rs->text, line, ovector, rc, "minute", min_s, TIME_BUFFER_SIZE);
- pthread_mutex_lock(&user_mutex);
struct user_t *user = user_get(nick);
if(user == last_user) {
monolog_len++;
@@ -65,7 +89,6 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
in_monolog = 0;
monolog_len = 1;
}
- pthread_mutex_unlock(&user_mutex);
/* Calculate array index for lines. */
int hour, min, time_i;
@@ -77,14 +100,21 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
wchar_t wtext[TEXT_BUFFER_SIZE];
mbstowcs(wtext, text, TEXT_BUFFER_SIZE);
- pthread_mutex_lock(&user_mutex);
+ now = now_global;
+
+ now.tm_hour = hour;
+ now.tm_min = min;
+ time_t now_ut = mktime(&now);
+
user->characters += wcslen(wtext);
user->lines[time_i]++;
- pthread_mutex_unlock(&user_mutex);
- pthread_mutex_lock(&channel_mutex);
+ if(user->seen_first == 0 || now_ut < user->seen_first) {
+ user->seen_first = now_ut;
+ }
+ user->seen_last = max(now_ut, user->seen_last);
+
channel->hours[time_i]++;
- pthread_mutex_unlock(&channel_mutex);
wchar_t word[TEXT_BUFFER_SIZE];
wchar_t *end = wcschr(wtext, '\0');
@@ -112,47 +142,187 @@ static void process_file(FILE *f, struct channel_t *channel, struct regexset_t *
rc = pcre_exec(rs->join, rs->join_e, line, strlen(line), 0, 0, ovector, 30);
if(rc > 0) {
- char nick[NICK_BUFFER_SIZE];
+ char nick[NICK_BUFFER_SIZE], hour_s[TIME_BUFFER_SIZE], min_s[TIME_BUFFER_SIZE];
pcre_copy_named_substring(rs->join, line, ovector, rc, "nick", nick, NICK_BUFFER_SIZE);
- pthread_mutex_lock(&user_mutex);
+ pcre_copy_named_substring(rs->join, line, ovector, rc, "hour", hour_s, TIME_BUFFER_SIZE);
+ pcre_copy_named_substring(rs->join, line, ovector, rc, "minute", min_s, TIME_BUFFER_SIZE);
+
+ int hour, min;
+ hour = atoi(hour_s);
+ min = atoi(min_s);
+
+ now = now_global;
+
+ now.tm_hour = hour;
+ now.tm_min = min;
+ time_t now_ut = mktime(&now);
+
struct user_t *user = user_get(nick);
- pthread_mutex_unlock(&user_mutex);
+
+ if(user->seen_first == 0 || now_ut < user->seen_first) {
+ user->seen_first = now_ut;
+ }
+ user->seen_last = max(now_ut, user->seen_last);
+
+ continue;
+ }
+
+ rc = pcre_exec(rs->part, rs->part_e, line, strlen(line), 0, 0, ovector, 30);
+ if(rc > 0) {
+ char nick[NICK_BUFFER_SIZE], hour_s[TIME_BUFFER_SIZE], min_s[TIME_BUFFER_SIZE];
+ pcre_copy_named_substring(rs->part, line, ovector, rc, "nick", nick, NICK_BUFFER_SIZE);
+ pcre_copy_named_substring(rs->part, line, ovector, rc, "hour", hour_s, TIME_BUFFER_SIZE);
+ pcre_copy_named_substring(rs->part, line, ovector, rc, "minute", min_s, TIME_BUFFER_SIZE);
+
+ int hour, min;
+ hour = atoi(hour_s);
+ min = atoi(min_s);
+
+ now = now_global;
+
+ now.tm_hour = hour;
+ now.tm_min = min;
+ time_t now_ut = mktime(&now);
+
+ struct user_t *user = user_get(nick);
+
+ if(user->seen_first == 0 || now_ut < user->seen_first) {
+ user->seen_first = now_ut;
+ }
+ user->seen_last = max(now_ut, user->seen_last);
+
+ continue;
+ }
+
+ rc = pcre_exec(rs->quit, rs->quit_e, line, strlen(line), 0, 0, ovector, 30);
+ if(rc > 0) {
+ char nick[NICK_BUFFER_SIZE], hour_s[TIME_BUFFER_SIZE], min_s[TIME_BUFFER_SIZE];
+ pcre_copy_named_substring(rs->quit, line, ovector, rc, "nick", nick, NICK_BUFFER_SIZE);
+ pcre_copy_named_substring(rs->quit, line, ovector, rc, "hour", hour_s, TIME_BUFFER_SIZE);
+ pcre_copy_named_substring(rs->quit, line, ovector, rc, "minute", min_s, TIME_BUFFER_SIZE);
+
+ int hour, min;
+ hour = atoi(hour_s);
+ min = atoi(min_s);
+
+ now = now_global;
+
+ now.tm_hour = hour;
+ now.tm_min = min;
+ time_t now_ut = mktime(&now);
+
+ struct user_t *user = user_get(nick);
+
+ if(user->seen_first == 0 || now_ut < user->seen_first) {
+ user->seen_first = now_ut;
+ }
+ user->seen_last = max(now_ut, user->seen_last);
+
+ continue;
+ }
+
+ rc = pcre_exec(rs->nick_changed, rs->nick_changed_e, line, strlen(line), 0, 0, ovector, 30);
+ if(rc > 0) {
+ char newnick[NICK_BUFFER_SIZE], hour_s[TIME_BUFFER_SIZE], min_s[TIME_BUFFER_SIZE];
+ pcre_copy_named_substring(rs->nick_changed, line, ovector, rc, "new_nick", newnick, NICK_BUFFER_SIZE);
+ pcre_copy_named_substring(rs->nick_changed, line, ovector, rc, "hour", hour_s, TIME_BUFFER_SIZE);
+ pcre_copy_named_substring(rs->nick_changed, line, ovector, rc, "minute", min_s, TIME_BUFFER_SIZE);
+
+ int hour, min;
+ hour = atoi(hour_s);
+ min = atoi(min_s);
+
+ now = now_global;
+
+ now.tm_hour = hour;
+ now.tm_min = min;
+ time_t now_ut = mktime(&now);
+
+ struct user_t *user = user_get(newnick);
+
+ if(user->seen_first == 0 || now_ut < user->seen_first) {
+ user->seen_first = now_ut;
+ }
+ user->seen_last = max(now_ut, user->seen_last);
+
+ continue;
+ }
+
+ rc = pcre_exec(rs->log_opened, rs->log_opened_e, line, strlen(line), 0, 0, ovector, 30);
+ if(rc > 0) {
+ char date[DATE_BUFFER_SIZE];
+
+ if(!log_date_format) {
+ continue;
+ }
+
+ pcre_copy_named_substring(rs->log_opened, line, ovector, rc, "date", date, DATE_BUFFER_SIZE);
+
+ if(!strptime(date, log_date_format, &now)) {
+ fprintf(stderr, "log fail: %s\n", date);
+ continue;
+ }
+
+ now_global = now;
+
+ continue;
+ }
+
+ /* day_changed is optional */
+ rc = rs->day_changed ? pcre_exec(rs->day_changed, rs->day_changed_e, line, strlen(line), 0, 0, ovector, 30) : 0;
+ if(rc > 0) {
+ char date[DATE_BUFFER_SIZE];
+
+ if(!day_date_format) {
+ continue;
+ }
+
+ pcre_copy_named_substring(rs->day_changed, line, ovector, rc, "date", date, DATE_BUFFER_SIZE);
+
+ if(!strptime(date, day_date_format, &now)) {
+ fprintf(stderr, "day fail: %s\n", date);
+ continue;
+ }
+
+ now_global = now;
+
continue;
}
rc = pcre_exec(rs->kick, rs->kick_e, line, strlen(line), 0, 0, ovector, 30);
if(rc > 0) {
- char nick[NICK_BUFFER_SIZE], victim[NICK_BUFFER_SIZE];
+ char nick[NICK_BUFFER_SIZE], victim[NICK_BUFFER_SIZE], hour_s[TIME_BUFFER_SIZE], min_s[TIME_BUFFER_SIZE];
+ pcre_copy_named_substring(rs->kick, line, ovector, rc, "hour", hour_s, TIME_BUFFER_SIZE);
+ pcre_copy_named_substring(rs->kick, line, ovector, rc, "minute", min_s, TIME_BUFFER_SIZE);
pcre_copy_named_substring(rs->kick, line, ovector, rc, "nick", nick, NICK_BUFFER_SIZE);
pcre_copy_named_substring(rs->kick, line, ovector, rc, "victim", victim, NICK_BUFFER_SIZE);
- pthread_mutex_lock(&user_mutex);
+
+ int hour, min;
+ hour = atoi(hour_s);
+ min = atoi(min_s);
+
+ now = now_global;
+
+ now.tm_hour = hour;
+ now.tm_min = min;
+ time_t now_ut = mktime(&now);
+
struct user_t *user = user_get(nick),
*victim_user = user_get(victim);
user->kicks++;
victim_user->kicked++;
- pthread_mutex_unlock(&user_mutex);
+
+ if(user->seen_first == 0 || now_ut < user->seen_first) {
+ user->seen_first = now_ut;
+ }
+ user->seen_last = max(now_ut, user->seen_last);
+
continue;
}
}
}
-struct thread_arg_t {
- FILE *f;
- struct channel_t *channel;
- struct regexset_t *rs;
-};
-
-static void *thread_func(void *arg) {
- struct thread_arg_t *ta = arg;
- process_file(ta->f, ta->channel, ta->rs);
-
- return NULL;
-}
-
-void process(int thread_n) {
- pthread_mutex_init(&user_mutex, NULL);
- pthread_mutex_init(&word_mutex, NULL);
- pthread_mutex_init(&channel_mutex, NULL);
+void process() {
/* Parsing stuff goes here. */
for(int chan_i = 0; chan_i < channel_get_count(); chan_i++) {
user_init();
@@ -173,28 +343,14 @@ void process(int thread_n) {
last_user = NULL;
in_monolog = monolog_len = 0;
- pthread_t *threads;
- threads = malloc(sizeof(pthread_t) * thread_n);
- struct thread_arg_t ta;
- ta.f = f;
- ta.channel = channel;
- ta.rs = rs;
- for(int i = 0; i < thread_n; i++) {
- pthread_create(&threads[i], NULL, thread_func, &ta);
- }
- for(int i = 0; i < thread_n; i++) {
- pthread_join(threads[i], NULL);
- }
- free(threads);
+ process_file(f, channel, rs);
fclose(f);
file = file->next;
}
+
export_xml(channel, users);
user_free();
word_free();
}
- pthread_mutex_destroy(&user_mutex);
- pthread_mutex_destroy(&word_mutex);
- pthread_mutex_destroy(&channel_mutex);
}
diff --git a/parsing.h b/parsing.h
index b991d55..6188d34 100644
--- a/parsing.h
+++ b/parsing.h
@@ -1,6 +1,6 @@
#ifndef _PARSING_H_
#define _PARSING_H_
-void process(int thread_n);
+void process();
#endif
diff --git a/regexset.c b/regexset.c
index 61a22be..e69b5c7 100644
--- a/regexset.c
+++ b/regexset.c
@@ -20,10 +20,12 @@ static void re_error(const char *name, const char *pattern, const char *error, i
fprintf(stderr, "%s\n", pattern);
for(int i = 0; i < erroffset; i++) fprintf(stderr, " ");
fprintf(stderr, "^\n");
- regexes = realloc(regexes, --rs_count * sizeof(struct regexset_t));
}
-struct regexset_t *rs_add(const char *text, const char *join, const char *kick) {
+struct regexset_t *rs_add(const char *text, const char *join, const char *part,
+ const char *quit, const char *kick, const char *nick_changed,
+ const char *log_opened, const char *day_changed, const char *log_date_format,
+ const char *day_date_format) {
regexes = realloc(regexes, ++rs_count * sizeof(struct regexset_t));
if(!regexes) {
/* If we end up here, we cannot free any previously compiled pcre patterns. */
@@ -39,7 +41,7 @@ struct regexset_t *rs_add(const char *text, const char *join, const char *kick)
rs->text = pcre_compile(text, 0, &error, &erroffset, rs_pcre_tables);
if(rs->text == NULL) {
re_error("text", text, error, erroffset);
- return NULL;
+ goto free_last_regex;
}
rs->text_e = pcre_study(rs->text, 0, &error);
@@ -47,29 +49,95 @@ struct regexset_t *rs_add(const char *text, const char *join, const char *kick)
rs->join = pcre_compile(join, 0, &error, &erroffset, rs_pcre_tables);
if(rs->join == NULL) {
- pcre_free(rs->text);
- if(rs->text_e)
- pcre_free(rs->text_e);
re_error("join", join, error, erroffset);
- return NULL;
+ goto free_text;
}
rs->join_e = pcre_study(rs->join, 0, &error);
+ rs->part = pcre_compile(part, 0, &error, &erroffset, rs_pcre_tables);
+ if(rs->part == NULL) {
+ re_error("part", part, error, erroffset);
+ goto free_join;
+ }
+ rs->part_e = pcre_study(rs->part, 0, &error);
+
+ rs->quit = pcre_compile(quit, 0, &error, &erroffset, rs_pcre_tables);
+ if(rs->quit == NULL) {
+ re_error("quit", quit, error, erroffset);
+ goto free_part;
+ }
+ rs->quit_e = pcre_study(rs->quit, 0, &error);
+
rs->kick = pcre_compile(kick, 0, &error, &erroffset, rs_pcre_tables);
if(rs->kick == NULL) {
- pcre_free(rs->text);
- pcre_free(rs->join);
- if(rs->text_e) {
- pcre_free(rs->text_e);
- pcre_free(rs->join_e);
- }
re_error("kick", kick, error, erroffset);
- return NULL;
-
+ goto free_quit;
}
rs->kick_e = pcre_study(rs->kick, 0, &error);
+ rs->nick_changed = pcre_compile(nick_changed, 0, &error, &erroffset, rs_pcre_tables);
+ if(rs->nick_changed == NULL) {
+ re_error("nick_changed", nick_changed, error, erroffset);
+ goto free_kick;
+ }
+ rs->nick_changed_e = pcre_study(rs->nick_changed, 0, &error);
+
+ rs->log_opened = pcre_compile(log_opened, 0, &error, &erroffset, rs_pcre_tables);
+ if(rs->log_opened == NULL) {
+ re_error("log_opened", log_opened, error, erroffset);
+ goto free_nick_changed;
+ }
+ rs->log_opened_e = pcre_study(rs->log_opened, 0, &error);
+
+ /* day_changed is optional */
+ if(day_changed) {
+ rs->day_changed = pcre_compile(day_changed, 0, &error, &erroffset, rs_pcre_tables);
+ if(rs->day_changed) {
+ rs->day_changed_e = pcre_study(rs->day_changed, 0, &error);
+ }
+ }
+
+ /* These are managed by libconfig and must never be free'd. */
+ rs->log_date_format = log_date_format;
+ rs->day_date_format = day_date_format;
+
return rs;
+
+
+ /* NOTE: Make sure these are in the exact opposite order than above. */
+
+free_log_opened:
+ pcre_free(rs->log_opened);
+ if(rs->log_opened_e) pcre_free(rs->log_opened_e);
+
+free_nick_changed:
+ pcre_free(rs->nick_changed);
+ if(rs->nick_changed_e) pcre_free(rs->nick_changed_e);
+
+free_kick:
+ pcre_free(rs->kick);
+ if(rs->kick_e) pcre_free(rs->kick_e);
+
+free_quit:
+ pcre_free(rs->quit);
+ if(rs->quit_e) pcre_free(rs->quit_e);
+
+free_part:
+ pcre_free(rs->part);
+ if(rs->part_e) pcre_free(rs->part_e);
+
+free_join:
+ pcre_free(rs->join);
+ if(rs->join_e) pcre_free(rs->join_e);
+
+free_text:
+ pcre_free(rs->text);
+ if(rs->text_e) pcre_free(rs->text_e);
+
+free_last_regex:
+ regexes = realloc(regexes, --rs_count * sizeof(struct regexset_t));
+
+ return NULL;
}
struct regexset_t *rs_get(int index) {
@@ -84,9 +152,26 @@ void rs_free() {
pcre_free(regexes[i].join);
if(regexes[i].join_e)
pcre_free(regexes[i].join_e);
+ pcre_free(regexes[i].part);
+ if(regexes[i].part_e)
+ pcre_free(regexes[i].part_e);
+ pcre_free(regexes[i].quit);
+ if(regexes[i].quit_e)
+ pcre_free(regexes[i].quit_e);
pcre_free(regexes[i].kick);
if(regexes[i].kick_e)
pcre_free(regexes[i].kick_e);
+ pcre_free(regexes[i].nick_changed);
+ if(regexes[i].nick_changed_e)
+ pcre_free(regexes[i].nick_changed_e);
+ pcre_free(regexes[i].log_opened);
+ if(regexes[i].log_opened_e)
+ pcre_free(regexes[i].log_opened_e);
+ if(regexes[i].day_changed) {
+ pcre_free(regexes[i].day_changed);
+ if(regexes[i].day_changed_e)
+ pcre_free(regexes[i].day_changed_e);
+ }
}
free(regexes);
regexes = NULL;
diff --git a/regexset.h b/regexset.h
index 3c023f1..aba4431 100644
--- a/regexset.h
+++ b/regexset.h
@@ -4,12 +4,16 @@
#include <pcre.h>
struct regexset_t {
- pcre *text, *join, *kick;
- pcre_extra *text_e, *join_e, *kick_e;
+ pcre *text, *join, *part, *quit, *kick, *nick_changed, *log_opened, *day_changed;
+ pcre_extra *text_e, *join_e, *part_e, *quit_e, *kick_e, *nick_changed_e, *log_opened_e, *day_changed_e;
+ const char *log_date_format, *day_date_format;
};
void rs_init();
-struct regexset_t *rs_add(const char *text, const char *join, const char *kick);
+struct regexset_t *rs_add(const char *text, const char *join, const char *part,
+ const char *quit, const char *kick, const char *nick_changed,
+ const char *log_opened, const char *day_changed, const char *log_date_format,
+ const char *day_date_format);
struct regexset_t *rs_get(int index);
void rs_free();
diff --git a/user.c b/user.c
index b64ca7c..d6171a5 100644
--- a/user.c
+++ b/user.c
@@ -33,6 +33,7 @@ struct user_t *user_get(char *nick) {
user->nick = strdup(nick);
memset(user->lines, 0, 24*4 * sizeof(unsigned long));
user->words = user->characters = user->kicks = user->kicked = user->monolog_lines = user->monologs = 0;
+ user->seen_first = user->seen_last = 0;
user->next = NULL;
char *_nick = nick_get(nick);
user->real_user = strcmp(nick, _nick) ? user_get(_nick) : NULL;
diff --git a/user.h b/user.h
index b08dd36..469c6e7 100644
--- a/user.h
+++ b/user.h
@@ -1,6 +1,8 @@
#ifndef _USER_H_
#define _USER_H_
+#include <time.h>
+
#define USERS_MAX 1000
struct user_t {
@@ -8,6 +10,7 @@ struct user_t {
char *nick;
unsigned long lines[24*4];
unsigned long long words, characters, kicks, kicked, monolog_lines, monologs;
+ time_t seen_first, seen_last;
struct user_t *real_user, *next;
};