A LOT updates. Cannot separate. :)
[silc.git] / apps / silcd / command_reply.c
index b3054faed7d3e07354912ca511c70ebee2b8f9e5..4ec3a8c37629d2d4a2a34d30b1efcfff8dafa10f 100644 (file)
   GNU General Public License for more details.
 
 */
-/*
- * $Id$
- * $Log$
- * Revision 1.4  2000/07/12 05:59:41  priikone
- *     Major rewrite of ID Cache system. Support added for the new
- *     ID cache system. Major rewrite of ID List stuff on server.  All
- *     SilcXXXList's are now called SilcXXXEntry's and they are pointers
- *     by default. A lot rewritten ID list functions.
- *
- * Revision 1.3  2000/07/05 06:14:01  priikone
- *     Global costemic changes.
- *
- * Revision 1.2  2000/07/03 05:52:22  priikone
- *     Implemented LEAVE command.
- *
- * Revision 1.1.1.1  2000/06/27 11:36:56  priikone
- *     Imported from internal CVS/Added Log headers.
- *
- *
- */
+/* $Id$ */
 
 #include "serverincludes.h"
 #include "server_internal.h"
@@ -62,7 +43,7 @@ void silc_server_command_reply_process(SilcServer server,
   SilcCommandPayload payload;
 
   /* Get command reply payload from packet */
-  payload = silc_command_parse_payload(buffer);
+  payload = silc_command_payload_parse(buffer);
   if (!payload) {
     /* Silently ignore bad reply packet */
     SILC_LOG_DEBUG(("Bad command reply packet"));
@@ -75,6 +56,7 @@ void silc_server_command_reply_process(SilcServer server,
   ctx->server = server;
   ctx->sock = sock;
   ctx->payload = payload;
+  ctx->args = silc_command_get_args(ctx->payload);
       
   /* Check for pending commands and mark to be exeucted */
   SILC_SERVER_COMMAND_CHECK_PENDING(ctx);
@@ -104,35 +86,39 @@ SILC_SERVER_CMD_REPLY_FUNC(join)
   SilcCommandStatus status;
   SilcChannelID *id;
   SilcChannelEntry entry;
+  unsigned int len;
   unsigned char *id_string;
   char *channel_name, *tmp;
 
   SILC_LOG_DEBUG(("Start"));
 
-  tmp = silc_command_get_arg_type(cmd->payload, 1, NULL);
+  tmp = silc_argument_get_arg_type(cmd->args, 1, NULL);
   SILC_GET16_MSB(status, tmp);
   if (status != SILC_STATUS_OK)
     goto out;
 
   /* Get channel name */
-  tmp = silc_command_get_arg_type(cmd->payload, 2, NULL);
+  tmp = silc_argument_get_arg_type(cmd->args, 2, NULL);
   if (!tmp)
     goto out;
 
   /* Get channel ID */
-  id_string = silc_command_get_arg_type(cmd->payload, 3, NULL);
+  id_string = silc_argument_get_arg_type(cmd->args, 3, &len);
   if (!id_string)
     goto out;
 
   channel_name = strdup(tmp);
 
   /* Add the channel to our local list. */
-  id = silc_id_str2id(id_string, SILC_ID_CHANNEL);
+  id = silc_id_payload_parse_id(id_string, len);
   entry = silc_idlist_add_channel(server->local_list, channel_name, 
                                  SILC_CHANNEL_MODE_NONE, id, 
                                  server->id_entry->router, NULL);
-  if (!entry)
+  if (!entry) {
+    silc_free(channel_name);
+    silc_free(id);
     goto out;
+  }
 
   entry->global_users = TRUE;
 
@@ -154,35 +140,34 @@ SILC_SERVER_CMD_REPLY_FUNC(identify)
   SilcServerCommandReplyContext cmd = (SilcServerCommandReplyContext)context;
   SilcServer server = cmd->server;
   SilcCommandStatus status;
-  unsigned char *tmp;
 
   SILC_LOG_DEBUG(("Start"));
 
-  tmp = silc_command_get_arg_type(cmd->payload, 1, NULL);
-  SILC_GET16_MSB(status, tmp);
+  SILC_GET16_MSB(status, silc_argument_get_arg_type(cmd->args, 1, NULL));
   if (status != SILC_STATUS_OK)
     goto out;
 
   /* Process one identify reply */
   if (status == SILC_STATUS_OK) {
+    SilcClientID *client_id;
+    unsigned int len;
     unsigned char *id_data;
-    char *nickname;
+    char *nickname, *username;
 
-    id_data = silc_command_get_arg_type(cmd->payload, 2, NULL);
-    nickname = silc_command_get_arg_type(cmd->payload, 3, NULL);
+    id_data = silc_argument_get_arg_type(cmd->args, 2, &len);
+    nickname = silc_argument_get_arg_type(cmd->args, 3, NULL);
     if (!id_data || !nickname)
       goto out;
 
-#if 0
-    /* Allocate client entry */
-    client_entry = silc_calloc(1, sizeof(*client_entry));
-    client_entry->id = silc_id_str2id(id_data, SILC_ID_CLIENT);
-    client_entry->nickname = strdup(nickname);
+    username = silc_argument_get_arg_type(cmd->args, 4, NULL);
+    client_id = silc_id_payload_parse_id(id_data, len);
 
-    /* Save received Client ID to ID cache */
-    silc_idcache_add(win->client_cache, client_entry->nickname,
-                    SILC_ID_CLIENT, client_entry->id, client_entry, TRUE);
-#endif
+    /* Add the client always to our global list. If normal or router server
+       ever gets here it means they don't have this client's information
+       in their cache. */
+    silc_idlist_add_client(server->global_list, strdup(nickname),
+                          username, NULL, client_id, NULL, NULL, NULL,
+                          NULL, NULL, NULL, NULL);
   }
 
   if (status == SILC_STATUS_LIST_START) {