updates.
[silc.git] / lib / silcclient / command_reply.c
index 289b19178b1de78a61f9cc85862c026fe6c6b2d1..616b2d86d950cc0b57617c1c5910c7ead070d2d7 100644 (file)
@@ -615,19 +615,53 @@ SILC_CLIENT_CMD_REPLY_FUNC(nick)
 SILC_CLIENT_CMD_REPLY_FUNC(list)
 {
   SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+  SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
   unsigned char *tmp, *name, *topic;
-  SilcUInt32 usercount = 0;
+  SilcUInt32 usercount = 0, len;
+  SilcChannelID *channel_id = NULL;
+  SilcChannelEntry channel_entry;
 
   COMMAND_CHECK_STATUS_LIST;
 
+  tmp = silc_argument_get_arg_type(cmd->args, 2, &len);
+  if (!tmp) {
+    COMMAND_REPLY_ERROR;
+    goto out;
+  }
+
+  channel_id = silc_id_payload_parse_id(tmp, len, NULL);
+  if (!channel_id) {
+    COMMAND_REPLY_ERROR;
+    goto out;
+  }
+
   name = silc_argument_get_arg_type(cmd->args, 3, NULL);
+  if (!name) {
+    COMMAND_REPLY_ERROR;
+    goto out;
+  }
+
   topic = silc_argument_get_arg_type(cmd->args, 4, NULL);
   tmp = silc_argument_get_arg_type(cmd->args, 5, NULL);
   if (tmp)
     SILC_GET32_MSB(usercount, tmp);
 
+  /* Check whether the channel exists, and add it to cache if it doesn't. */
+  channel_entry = silc_client_get_channel_by_id(cmd->client, conn, 
+                                               channel_id);
+  if (!channel_entry) {
+    /* Add new channel entry */
+    channel_entry = silc_client_add_channel(cmd->client, conn, name, 0,
+                                           channel_id);
+    if (!channel_entry) {
+      COMMAND_REPLY_ERROR;
+      goto out;
+    }
+    channel_id = NULL;
+  }
+
   /* Notify application */
-  COMMAND_REPLY((ARGS, NULL, name, topic, usercount));
+  COMMAND_REPLY((ARGS, channel_entry, name, topic, usercount));
 
   /* Pending callbacks are not executed if this was an list entry */
   if (cmd->status != SILC_STATUS_OK &&
@@ -637,6 +671,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(list)
   }
 
  out:
+  silc_free(channel_id);
   SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_LIST);
   silc_client_command_reply_free(cmd);
 }