Mon Jun 18 22:21:37 CEST 2007 Jochen Eisinger <coffee@silcnet.org>
[silc.git] / lib / silcclient / command_reply.c
index 3c041113b70157cc139bea90bbf6ef96dd56e9ca..13fab10a168ad506500ec3996b8be031ef4c3ccd 100644 (file)
@@ -131,7 +131,7 @@ void silc_client_command_reply_process(SilcClient client,
       /* No specific identifier for command reply, call first one found */
       (*reply)(ctx, NULL);
     else
-      silc_free(ctx);
+      silc_client_command_reply_free(ctx);
   }
 }
 
@@ -155,6 +155,8 @@ void silc_client_command_reply_free(SilcClientCommandReplyContext cmd)
   SILC_LOG_DEBUG(("Command reply context %p refcnt %d->%d", cmd,
                  cmd->users + 1, cmd->users));
   if (cmd->users < 1) {
+    if (cmd->callbacks)
+      silc_free(cmd->callbacks);
     silc_command_payload_free(cmd->payload);
     silc_free(cmd);
   }
@@ -934,7 +936,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(ping)
 {
   SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
   SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
-  void *id;
+  void *id = NULL;
   int i;
   time_t diff, curtime;
 
@@ -972,12 +974,12 @@ SILC_CLIENT_CMD_REPLY_FUNC(ping)
     }
   }
 
-  silc_free(id);
-
   /* Notify application */
   COMMAND_REPLY((SILC_ARGS));
 
  out:
+  if (id)
+    silc_free(id);
   SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_PING);
   silc_client_command_reply_free(cmd);
 }
@@ -2046,6 +2048,32 @@ SILC_CLIENT_CMD_REPLY_FUNC(getkey)
   silc_client_command_reply_free(cmd);
 }
 
+/* Reply to SERVICE command. */
+/* XXX incomplete */
+
+SILC_CLIENT_CMD_REPLY_FUNC(service)
+{
+  SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
+  SilcUInt32 tmp_len;
+  unsigned char *service_list, *name;
+
+  COMMAND_CHECK_STATUS;
+
+  /* Get service list */
+  service_list = silc_argument_get_arg_type(cmd->args, 2, &tmp_len);
+
+  /* Get requested service name */
+  name = silc_argument_get_arg_type(cmd->args, 3, &tmp_len);
+
+  /* Notify application */
+  COMMAND_REPLY((SILC_ARGS, service_list, name));
+
+ out:
+  SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_SERVICE);
+ err:
+  silc_client_command_reply_free(cmd);
+}
+
 SILC_CLIENT_CMD_REPLY_FUNC(quit)
 {
   silc_client_command_reply_free(context);