added experimental multi thread support
[NeonServV5.git] / src / UserNode.c
index 3f20a13eccdf93a8a7a85409bc405f0f8d87fbd2..f90e72f2c1876fc95dcf315bb0b376d34bd6d276 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
  */
 #include "UserNode.h"
+#include "ChanNode.h"
 #include "ChanUser.h"
 #include "tools.h"
 #include "IRCEvents.h"
+#include "IPNode.h"
 
 static struct UserNode **userList;
 
@@ -199,12 +201,15 @@ struct UserNode* addUser(const char *nick) {
     user->created = time(0);
     user->ident[0] = 0;
     user->host[0] = 0;
+    user->ip = NULL;
     user->realname[0] = 0;
     user->flags = 0;
     user->channel = NULL;
     user->last_who = 0;
+    SYNCHRONIZE(cache_sync);
     user->next = userList[userListIndex];
     userList[userListIndex] = user;
+    DESYNCHRONIZE(cache_sync);
     return user;
 }
 
@@ -255,6 +260,7 @@ struct UserNode* createTempUser(const char *nick) {
         }
         user->ident[0] = 0;
         user->host[0] = 0;
+        user->ip = NULL;
         user->realname[0] = 0;
         user->flags = 0;
         user->channel = NULL;
@@ -266,8 +272,10 @@ struct UserNode* createTempUser(const char *nick) {
         user->flags &= ~USERFLAG_ISAUTHED; //remove authed flag (security reasons)
     strcpy(user->nick, nick);
     if(!already_on_list) {
+        SYNCHRONIZE(cache_sync);
         user->next = userList[TEMPUSER_LIST_INDEX];
         userList[TEMPUSER_LIST_INDEX] = user;
+        DESYNCHRONIZE(cache_sync);
     }
     return user;
 }
@@ -299,6 +307,7 @@ struct UserNode* createTempUserMask(const char *mask) {
                 }
                 user->ident[0] = 0;
                 user->host[0] = 0;
+                user->ip = NULL;
                 user->realname[0] = 0;
                 user->flags = 0;
                 user->channel = NULL;
@@ -322,6 +331,7 @@ struct UserNode* createTempUserMask(const char *mask) {
             user->created = time(0);
             user->ident[0] = 0;
             user->host[0] = 0;
+            user->ip = NULL;
             user->realname[0] = 0;
             user->flags = USERFLAG_ISSERVER;
             user->channel = NULL;
@@ -345,6 +355,7 @@ struct UserNode* createTempUserMask(const char *mask) {
                 user->created = time(0);
                 user->ident[0] = 0;
                 user->host[0] = 0;
+                user->ip = NULL;
                 user->realname[0] = 0;
                 user->flags = 0;
                 user->channel = NULL;
@@ -355,8 +366,10 @@ struct UserNode* createTempUserMask(const char *mask) {
         }
     }
     if(!already_on_list) {
+        SYNCHRONIZE(cache_sync);
         user->next = userList[TEMPUSER_LIST_INDEX];
         userList[TEMPUSER_LIST_INDEX] = user;
+        DESYNCHRONIZE(cache_sync);
     }
     return user;
 }
@@ -370,6 +383,7 @@ int renameUser(struct UserNode* user, const char *new_nick) {
     }
     //delUser(user, 0); //EPIC FAIL! This deletes the user from the channel Userlist -.-
     //manually remove the user from the old userList
+    SYNCHRONIZE(cache_sync);
     int userListIndex = get_nicklist_entry(user->nick[0]);
     if(userListIndex != -1) {
         struct UserNode *cuser, *last_user = NULL;
@@ -388,12 +402,14 @@ int renameUser(struct UserNode* user, const char *new_nick) {
     strcpy(user->nick, new_nick);
     user->next = userList[userListIndex];
     userList[userListIndex] = user;
+    DESYNCHRONIZE(cache_sync);
     return 1;
 }
 
 void delUser(struct UserNode* user, int freeUser) {
     int userListIndex = ((user->flags & USERFLAG_ISTMPUSER) ? TEMPUSER_LIST_INDEX : get_nicklist_entry(user->nick[0]));
     if(userListIndex == -1) return;
+    SYNCHRONIZE(cache_sync);
     event_freeuser(user);
     struct UserNode *cuser, *last_user = NULL;
     for(cuser = userList[userListIndex]; cuser; cuser = cuser->next) {
@@ -417,13 +433,17 @@ void delUser(struct UserNode* user, int freeUser) {
             removeChanUserFromLists(chanUser, 1, 0, freeUser);
         }
     }
-    if(freeUser)
+    if(freeUser) {
+        if(user->ip)
+            freeIPNode(user->ip);
         free(user);
-    else
+    else
         user->next = NULL;
+    DESYNCHRONIZE(cache_sync);
 }
 
 void clearTempUsers() {
+    SYNCHRONIZE(cache_sync);
     int userListIndex = TEMPUSER_LIST_INDEX;
     struct UserNode *cuser, *next;
     time_t now = time(0);
@@ -433,4 +453,5 @@ void clearTempUsers() {
             delUser(cuser, 1);
         }
     }
+    DESYNCHRONIZE(cache_sync);
 }