From c1af999ee417b7e80a828f9f7d1b39915814595a Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Fri, 21 Aug 2009 13:02:22 +0200 Subject: Implemented nick_get - nicks can now be mapped --- main.c | 2 +- nick.c | 17 +++++++++++++++++ nick.h | 1 + user.c | 4 +++- user.h | 2 +- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 69435ac..ee23264 100644 --- a/main.c +++ b/main.c @@ -20,6 +20,7 @@ int main(int argc, char **argv) { /* Regex sets must be initialized before config. */ rs_init(); channel_init(); + nick_init(); if(!cfg_init()) { /* Free any registered regex sets and channels when config fails. Config will fail if a regex set fails to compile all parts. */ @@ -27,7 +28,6 @@ int main(int argc, char **argv) { channel_free(); return 1; } - nick_init(); /* Parsing stuff goes here. */ for(int chan_i = 0; chan_i < channel_get_count(); chan_i++) { diff --git a/nick.c b/nick.c index 8b336de..54a0b2f 100644 --- a/nick.c +++ b/nick.c @@ -67,6 +67,23 @@ int nick_regex_add(struct nick_t *nick, const char *re_s) { return 1; } +char *nick_get(char *name) { + struct nick_t *nick = nicks; + while(nick) { + struct nick_regex_t *nre = nick->regexes; + while(nre) { + int ovector[6]; + int rc; + rc = pcre_exec(nre->re, nre->re_e, name, strlen(name), 0, 0, ovector, 6); + if(rc > 0) + return nick->name; + nre = nre->next; + } + nick = nick->next; + } + return name; +} + void nick_free() { struct nick_t *nick = nicks; while(nick) { diff --git a/nick.h b/nick.h index 580ebf1..3ba1e3d 100644 --- a/nick.h +++ b/nick.h @@ -16,6 +16,7 @@ struct nick_t { void nick_init(); struct nick_t *nick_add(const char *name); int nick_regex_add(struct nick_t *nick, const char *re_s); +char *nick_get(char *name); void nick_free(); #endif diff --git a/user.c b/user.c index aed1ea6..edb8fb3 100644 --- a/user.c +++ b/user.c @@ -3,6 +3,7 @@ #include "user.h" #include "sdbm.h" +#include "nick.h" struct user_t *users; @@ -11,7 +12,8 @@ void user_init() { memset(users, 0, sizeof(struct user_t) * USERS_MAX); } -struct user_t *user_get(char *nick) { +struct user_t *user_get(char *_nick) { + char *nick = nick_get(_nick); unsigned long hash = sdbm(nick); int index = hash % USERS_MAX; diff --git a/user.h b/user.h index 042eb32..7c69584 100644 --- a/user.h +++ b/user.h @@ -12,7 +12,7 @@ struct user_t { }; void user_init(); -struct user_t *user_get(char *nick); +struct user_t *user_get(char *_nick); void user_free(); extern struct user_t *users; -- cgit v1.2.3