Send channel links info at client connect
authorfatbob313 <martin@fatbob.nu>
Tue, 9 Feb 2010 17:14:56 +0000 (17:14 +0000)
committerfatbob313 <martin@fatbob.nu>
Tue, 9 Feb 2010 17:14:56 +0000 (17:14 +0000)
src/channel.c
src/channel.h
src/messagehandler.c
src/messages.c

index 4de6490329e73b578c8fa54772fe6053cee9487f..1fab5a4a793cdde82849bb36373798d03697c40e 100644 (file)
@@ -212,6 +212,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);
        }
 }
index e20bfad6ec9919c0e266010eddcef6d707208904..61346467cec71597023a659a4ad47a88ed4222fb 100644 (file)
@@ -46,6 +46,7 @@ typedef struct channel {
        struct dlist clients;
        struct dlist flatlist_node;
        struct dlist channel_links;
+       int linkcount;
        struct dlist link_node;
 } channel_t;
 
index 98a9953b2996256e351a6619b534c38cff8b1d84..b2f5670e90d6c0c1f08fdd67b531a465bde7fefb 100644 (file)
@@ -172,8 +172,7 @@ void Mh_handle_message(client_t *client, message_t *msg)
                
                /* Iterate channels and send channel info */
                ch_itr = NULL;
-               Chan_iterate(&ch_itr);
-               do {
+               while (Chan_iterate(&ch_itr) != NULL) {
                        sendmsg = Msg_create(ChannelState);
                        sendmsg->payload.channelState->has_channel_id = true;
                        sendmsg->payload.channelState->channel_id = ch_itr->id;
@@ -185,12 +184,32 @@ void Mh_handle_message(client_t *client, message_t *msg)
                        if (ch_itr->desc)
                                sendmsg->payload.channelState->description = strdup(ch_itr->desc);
                        Log_debug("Send channel info: %s", sendmsg->payload.channelState->name);
-                       Client_send_message(client, sendmsg);
-                       
-                       Chan_iterate(&ch_itr);
-               } while (ch_itr != NULL);
+                       Client_send_message(client, sendmsg);                   
+               }
 
-               /* Not supporting channel links yet */
+               /* Iterate channels and send channel links info */
+               ch_itr = NULL;
+               while (Chan_iterate(&ch_itr) != NULL) {
+                       if (ch_itr->linkcount > 0) { /* Has links */
+                               uint32_t *links;
+                               int i = 0;
+                               struct dlist *itr;
+                               
+                               sendmsg = Msg_create(ChannelState);
+                               sendmsg->payload.channelState->has_channel_id = true;
+                               sendmsg->payload.channelState->channel_id = ch_itr->id;
+                               sendmsg->payload.channelState->n_links = ch_itr->linkcount;
+                               
+                               links = (uint32_t *)malloc(ch_itr->linkcount * sizeof(uint32_t));
+                               list_iterate(itr, &ch_itr->channel_links) { /* Iterate links */
+                                       channel_t *ch;
+                                       ch = list_get_entry(itr, channel_t, link_node);
+                                       links[i++] = ch->id;
+                               }
+                               sendmsg->payload.channelState->links = links;
+                               Client_send_message(client, sendmsg);
+                       }
+               }
                
                /* Send user state for connecting user to other users */
                sendmsg = Msg_create(UserState);
index 109f5eb22af6c8844262678e5519e676ef78f73f..06a72eb4fae8c696fb1493594a9b0077b3835c0e 100644 (file)
@@ -436,8 +436,12 @@ void Msg_free(message_t *msg)
                if (msg->unpacked)
                        mumble_proto__channel_state__free_unpacked(msg->payload.channelState, NULL);
                else {
-                       free(msg->payload.channelState->name);
-                       free(msg->payload.channelState->description);
+                       if (msg->payload.channelState->name)
+                               free(msg->payload.channelState->name);
+                       if (msg->payload.channelState->description)
+                               free(msg->payload.channelState->description);
+                       if (msg->payload.channelState->links)
+                               free(msg->payload.channelState->links);
                        free(msg->payload.channelState);
                }
                break;