Updated copyright year.
[umurmur.git] / src / channel.c
index c3ddda8377ed939b211778e153b3094498643a70..4609e4cb786a94fb47b22171396c0b23a203fa59 100644 (file)
@@ -1,5 +1,5 @@
-/* Copyright (C) 2009-2010, Martin Johansson <martin@fatbob.nu>
-   Copyright (C) 2005-2010, Thorvald Natvig <thorvald@natvig.com>
+/* Copyright (C) 2009-2011, Martin Johansson <martin@fatbob.nu>
+   Copyright (C) 2005-2011, Thorvald Natvig <thorvald@natvig.com>
 
    All rights reserved.
 
@@ -29,6 +29,8 @@
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 #include <limits.h>
+#include <stdlib.h>
+#include <string.h>
 #include "log.h"
 #include "list.h"
 #include "client.h"
@@ -212,6 +214,7 @@ void Chan_init()
                        ch_dst = ch_itr;
                
                list_add_tail(&ch_dst->link_node, &ch_src->channel_links);
+               ch_src->linkcount++;
                Log_info("Adding channel link '%s' -> '%s'", ch_src->name, ch_dst->name);
        }
 }
@@ -273,9 +276,12 @@ int Chan_userLeave(client_t *client)
 int Chan_userJoin(channel_t *ch, client_t *client)
 {
        int leaving_id;
+
+       /* Do nothing if user already is in this channel */
+       if ((channel_t *)client->channel == ch)
+               return 0;
        
        Log_debug("Add user %s to channel %s", client->username, ch->name); 
-
        /* Only allowed in one channel at a time */
        leaving_id = Chan_userLeave(client);
        list_add_tail(&client->chan_node, &ch->clients);
@@ -342,3 +348,28 @@ void Chan_removeChannel(channel_t *ch)
 {
        list_del(&ch->node);
 }
+
+void Chan_buildTreeList(channel_t *ch, struct dlist *head)
+{
+       channellist_t *chl;
+       struct dlist *itr;
+       channel_t *sub;
+       
+       chl = malloc(sizeof(channellist_t));
+       chl->chan = ch;
+       init_list_entry(&chl->node);
+       list_add_tail(&chl->node, head);
+
+       list_iterate(itr, &ch->subs) {
+               sub = list_get_entry(itr, channel_t, node);
+               Chan_buildTreeList(sub, head);
+       }
+}
+
+void Chan_freeTreeList(struct dlist *head)
+{
+       struct dlist *itr, *save;
+       list_iterate_safe(itr, save, head) {
+               free(list_get_entry(itr, channellist_t, node));
+       }
+}