From bb27270534e7c2c9218145a99bbbfaee119e58b0 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Wed, 8 Oct 2003 12:34:41 +0000 Subject: [PATCH] Implemented SilcStatus error argument returning in client library. --- CHANGES | 9 ++ lib/doc/silcstatus_args.html | 42 ++++----- lib/silcclient/client_resume.c | 10 +-- lib/silcclient/command_reply.c | 158 ++++++++++++++++----------------- lib/silcclient/command_reply.h | 26 ++++-- lib/silccore/Makefile.am | 5 +- lib/silccore/silccommand.h | 76 ++++++++-------- lib/silccore/silcstatus.c | 102 +++++++++++++++++++++ lib/silccore/silcstatus.h | 26 +++++- 9 files changed, 300 insertions(+), 154 deletions(-) create mode 100644 lib/silccore/silcstatus.c diff --git a/CHANGES b/CHANGES index cbaa6ef1..ac13f727 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,15 @@ Wed Oct 8 09:32:12 CEST 2003 Pekka Riikonen * Implemented INVITE and BAN announcing. Affected files are silcd/server.[ch], server_util.c. + * Implemented SilcStatus error type argument returning in + command reply error in server. Affected file silcd/command.c. + + * Implemented SilcStatus argument returning in comand reply + in client library. The command_reply client operation now + returns error specific arguments as well. Affected files + are lib/silcclient/command_reply.[ch], client_resume.c, + lib/silccore/silcstatus.[ch]. + Sun Oct 5 20:22:08 EEST 2003 Pekka Riikonen * Backup router protocol version 1.2 implemented. Testing still diff --git a/lib/doc/silcstatus_args.html b/lib/doc/silcstatus_args.html index da54fb14..2a696085 100644 --- a/lib/doc/silcstatus_args.html +++ b/lib/doc/silcstatus_args.html @@ -64,10 +64,9 @@ are defined in lib/silccore/silcstatus.h header file. A short example.
 
The following table describes all status values and arguments that the client library sends in the 'command_reply' client operation to the application -in case of error. By default all arguments that the library sends to -application are valid pointers. However, it is possible that some pointers -may be NULL. If this is the case it is separately mentioned that the -argument may be NULL. In this case application must ignore that argument. +in case of error. All arguments listed below are usually valid when +returned by the library. However applicationn must be able to handle that +any of those arguments may be NULL.
 
The 'command_reply' arguments in case of error are as follows: @@ -232,9 +231,9 @@ Server ID provided does not exist. The unknown ID is returned. SILC_STATUS_ERR_NOT_ON_CHANNEL The command required for you to be on channel but you were not. -The channel is returned. The 'channel' may be NULL. +The channel ID is returned. -SilcChannelEntry channel +const SilcChannelID *channel_id @@ -242,9 +241,10 @@ The channel is returned. The 'channel' may be NULL. SILC_STATUS_ERR_USER_NOT_ON_CHANNEL The requested target client is not on requested channel. Returns the -target client and channel. The 'target_client' and 'channel' may be NULL. +target client ID and channel ID. -SilcClientEntry target_client, SilcChannelEntry channel +const SilcClientID *client_id, +const SilcChannelID *channel_id @@ -252,9 +252,10 @@ target client and channel. The 'target_client' and 'channel' may be NULL. SILC_STATUS_ERR_USER_ON_CHANNEL User were invited on channel they already are on. Returns the -target client and channel. The 'target_client' and 'channel' may be NULL. +target client ID and channel ID. -SilcClientEntry target_client, SilcChannelEntry channel +const SilcClientID *client_id, +const SilcChannelID *channel_id @@ -309,9 +310,9 @@ Password provided for channel were not accepted. No arguments returned. SILC_STATUS_ERR_CHANNEL_IS_FULL The channel is full and client cannot join the channel. Returns the -channel, which may be NULL. +channel ID. -SilcChannelEntry channel +const SilcChannelID *channel_id @@ -319,19 +320,18 @@ channel, which may be NULL. SILC_STATUS_ERR_NOT_INVITED The channel is invite only channel and client has not been invited. -Returns the channel, which may be NULL. +Returns the channel ID. -SilcChannelEntry channel +const SilcChannelID *channel_id SILC_STATUS_ERR_BANNED_FROM_CHANNEL -The client has been banned from the channel. Returns the channel, which -may be NULL. +The client has been banned from the channel. Returns the channel ID. -SilcChannelEntry channel +const SilcChannelID *channel_id @@ -359,9 +359,9 @@ No arguments returned. SILC_STATUS_ERR_NO_CHANNEL_PRIV Command may be executed only by channel operator. The next argument is -the channel, which may be NULL. +the channel ID. -SilcChannelEntry channel +const SilcChannelID *channel_id @@ -369,9 +369,9 @@ the channel, which may be NULL. SILC_STATUS_ERR_NO_CHANNEL_FOPRIV Command may be executed only by channel founder. The next argument is -the channel, which may be NULL. +the channel ID. -SilcChannelEntry channel +const SilcChannelID *channel_id diff --git a/lib/silcclient/client_resume.c b/lib/silcclient/client_resume.c index 02c460da..3efe64ad 100644 --- a/lib/silcclient/client_resume.c +++ b/lib/silcclient/client_resume.c @@ -502,19 +502,19 @@ SILC_CLIENT_CMD_FUNC(resume_users) /* Get channel ID */ tmp = silc_argument_get_arg_type(cmd->args, 2, &tmp_len); if (!tmp) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto err; } channel_id = silc_id_payload_parse_id(tmp, tmp_len, NULL); if (!channel_id) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto err; } /* Get the list count */ tmp = silc_argument_get_arg_type(cmd->args, 3, &tmp_len); if (!tmp) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto err; } SILC_GET32_MSB(list_count, tmp); @@ -522,7 +522,7 @@ SILC_CLIENT_CMD_FUNC(resume_users) /* Get Client ID list */ tmp = silc_argument_get_arg_type(cmd->args, 4, &tmp_len); if (!tmp) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto err; } silc_buffer_set(&client_id_list, tmp, tmp_len); @@ -530,7 +530,7 @@ SILC_CLIENT_CMD_FUNC(resume_users) /* Get client mode list */ tmp = silc_argument_get_arg_type(cmd->args, 5, &tmp_len); if (!tmp) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto err; } silc_buffer_set(&client_mode_list, tmp, tmp_len); diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index df78d5ae..a737af8d 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -48,11 +48,11 @@ do { \ if (!silc_command_get_status(cmd->payload, NULL, NULL)) { \ if (SILC_STATUS_IS_ERROR(cmd->status)) { \ /* Single error */ \ - COMMAND_REPLY_ERROR; \ + COMMAND_REPLY_ERROR(cmd->status); \ goto out; \ } \ /* List of errors */ \ - COMMAND_REPLY_ERROR; \ + COMMAND_REPLY_ERROR(cmd->error); \ if (cmd->status == SILC_STATUS_LIST_END) \ goto out; \ goto err; \ @@ -181,14 +181,14 @@ silc_client_command_reply_whois_save(SilcClientCommandReplyContext cmd, id_data = silc_argument_get_arg_type(cmd->args, 2, &len); if (!id_data) { if (notify) - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); return; } client_id = silc_id_payload_parse_id(id_data, len, NULL); if (!client_id) { if (notify) - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); return; } @@ -197,7 +197,7 @@ silc_client_command_reply_whois_save(SilcClientCommandReplyContext cmd, realname = silc_argument_get_arg_type(cmd->args, 5, &len); if (!nickname || !username || !realname) { if (notify) - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); return; } @@ -323,13 +323,13 @@ SILC_CLIENT_CMD_REPLY_FUNC(whowas) id_data = silc_argument_get_arg_type(cmd->args, 2, &len); if (!id_data) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } client_id = silc_id_payload_parse_id(id_data, len, NULL); if (!client_id) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -341,7 +341,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(whowas) username = silc_argument_get_arg_type(cmd->args, 4, &len); realname = silc_argument_get_arg_type(cmd->args, 5, &len); if (!nickname || !username) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -385,13 +385,13 @@ silc_client_command_reply_identify_save(SilcClientCommandReplyContext cmd, id_data = silc_argument_get_arg_type(cmd->args, 2, &len); if (!id_data) { if (notify) - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); return; } idp = silc_id_payload_parse(id_data, len); if (!idp) { if (notify) - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); return; } @@ -438,7 +438,7 @@ silc_client_command_reply_identify_save(SilcClientCommandReplyContext cmd, silc_id_dup(server_id, id_type)); if (!server_entry) { if (notify) - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); return; } } else { @@ -547,7 +547,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(nick) SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot set nickname: %s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -555,7 +555,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(nick) if (argc < 2 || argc > 3) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot set nickname: bad reply to command"); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -566,7 +566,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(nick) tmp = silc_argument_get_arg_type(cmd->args, 2, &len); idp = silc_id_payload_parse(tmp, len); if (!idp) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } silc_client_receive_new_id(cmd->client, cmd->sock, idp); @@ -609,19 +609,19 @@ SILC_CLIENT_CMD_REPLY_FUNC(list) tmp = silc_argument_get_arg_type(cmd->args, 2, &len); if (!tmp) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } channel_id = silc_id_payload_parse_id(tmp, len, NULL); if (!channel_id) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } name = silc_argument_get_arg_type(cmd->args, 3, NULL); if (!name) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -638,7 +638,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(list) channel_entry = silc_client_add_channel(cmd->client, conn, name, 0, channel_id); if (!channel_entry) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } channel_id = NULL; @@ -676,13 +676,13 @@ SILC_CLIENT_CMD_REPLY_FUNC(topic) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot set topic: %s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } argc = silc_argument_get_arg_num(cmd->args); if (argc < 1 || argc > 3) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -704,7 +704,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(topic) channel = silc_client_get_channel_by_id(cmd->client, conn, channel_id); if (!channel) { silc_free(channel_id); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -731,7 +731,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(invite) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot invite: %s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -748,7 +748,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(invite) channel = silc_client_get_channel_by_id(cmd->client, conn, channel_id); if (!channel) { silc_free(channel_id); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -779,7 +779,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(kill) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot kill: %s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -787,7 +787,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(kill) if (id_data) { client_id = silc_id_payload_parse_id(id_data, len, NULL); if (!client_id) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -822,7 +822,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(info) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -877,7 +877,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(stats) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -910,7 +910,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(ping) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -918,7 +918,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(ping) id = silc_id_str2id(cmd->packet->src_id, cmd->packet->src_id_len, cmd->packet->src_id_type); if (!id || !conn->internal->ping) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -973,7 +973,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) if (cmd->error != SILC_STATUS_ERR_USER_ON_CHANNEL) SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot join channel: %s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -981,7 +981,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) if (argc < 7) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot join channel: Bad reply packet"); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -990,7 +990,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) if (!tmp) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot join channel: Bad reply packet"); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } channel_name = tmp; @@ -1000,12 +1000,12 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) if (!tmp) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot join channel: Bad reply packet"); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } channel_id = silc_id_payload_parse_id(tmp, len, NULL); if (!channel_id) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -1044,7 +1044,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(join) if (!silc_hmac_alloc(hmac, NULL, &channel->hmac)) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot join channel: Unsupported HMAC `%s'", hmac); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } } @@ -1160,20 +1160,20 @@ SILC_CLIENT_CMD_REPLY_FUNC(motd) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); return; } argc = silc_argument_get_arg_num(cmd->args); if (argc > 3) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } if (argc == 3) { motd = silc_argument_get_arg_type(cmd->args, 3, NULL); if (!motd) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -1217,13 +1217,13 @@ SILC_CLIENT_CMD_REPLY_FUNC(umode) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot change mode: %s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } tmp = silc_argument_get_arg_type(cmd->args, 2, NULL); if (!tmp) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -1255,7 +1255,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(cmode) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot change mode: %s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -1271,7 +1271,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(cmode) channel = silc_client_get_channel_by_id(cmd->client, conn, channel_id); if (!channel) { silc_free(channel_id); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -1279,7 +1279,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(cmode) tmp = silc_argument_get_arg_type(cmd->args, 3, NULL); if (!tmp) { silc_free(channel_id); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -1329,14 +1329,14 @@ SILC_CLIENT_CMD_REPLY_FUNC(cumode) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot change mode: %s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } /* Get channel mode */ modev = silc_argument_get_arg_type(cmd->args, 2, NULL); if (!modev) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -1352,7 +1352,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(cumode) channel = silc_client_get_channel_by_id(cmd->client, conn, channel_id); if (!channel) { silc_free(channel_id); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -1360,13 +1360,13 @@ SILC_CLIENT_CMD_REPLY_FUNC(cumode) id = silc_argument_get_arg_type(cmd->args, 4, &len); if (!id) { silc_free(channel_id); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } client_id = silc_id_payload_parse_id(id, len, NULL); if (!client_id) { silc_free(channel_id); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -1375,7 +1375,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(cumode) if (!client_entry) { silc_free(channel_id); silc_free(client_id); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -1409,7 +1409,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(kick) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Cannot kick: %s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -1418,14 +1418,14 @@ SILC_CLIENT_CMD_REPLY_FUNC(kick) if (tmp) { channel_id = silc_id_payload_parse_id(tmp, len, NULL); if (!channel_id) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } /* Get the channel entry */ channel = silc_client_get_channel_by_id(cmd->client, conn, channel_id); if (!channel) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } } @@ -1435,14 +1435,14 @@ SILC_CLIENT_CMD_REPLY_FUNC(kick) if (tmp) { client_id = silc_id_payload_parse_id(tmp, len, NULL); if (!client_id) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } /* Get client entry */ client_entry = silc_client_get_client_by_id(cmd->client, conn, client_id); if (!client_entry) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } } @@ -1465,7 +1465,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(silcoper) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -1485,7 +1485,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(oper) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -1506,7 +1506,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(detach) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -1535,7 +1535,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(watch) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -1560,7 +1560,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(ban) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -1577,7 +1577,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(ban) channel = silc_client_get_channel_by_id(cmd->client, conn, channel_id); if (!channel) { silc_free(channel_id); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -1609,7 +1609,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(leave) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -1624,7 +1624,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(leave) channel = silc_client_get_channel_by_id(cmd->client, conn, channel_id); if (!channel) { silc_free(channel_id); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -1666,7 +1666,7 @@ static void silc_client_command_reply_users_cb(SilcClient client, cmd->status = cmd->error = SILC_STATUS_ERR_NO_SUCH_CHANNEL; SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_USERS); silc_client_command_reply_free(cmd); return; @@ -1701,19 +1701,19 @@ silc_client_command_reply_users_save(SilcClientCommandReplyContext cmd, /* Get channel ID */ tmp = silc_argument_get_arg_type(cmd->args, 2, &tmp_len); if (!tmp) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } channel_id = silc_id_payload_parse_id(tmp, tmp_len, NULL); if (!channel_id) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } /* Get the list count */ tmp = silc_argument_get_arg_type(cmd->args, 3, &tmp_len); if (!tmp) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } SILC_GET32_MSB(list_count, tmp); @@ -1721,7 +1721,7 @@ silc_client_command_reply_users_save(SilcClientCommandReplyContext cmd, /* Get Client ID list */ tmp = silc_argument_get_arg_type(cmd->args, 4, &tmp_len); if (!tmp) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } silc_buffer_set(&client_id_list, tmp, tmp_len); @@ -1729,7 +1729,7 @@ silc_client_command_reply_users_save(SilcClientCommandReplyContext cmd, /* Get client mode list */ tmp = silc_argument_get_arg_type(cmd->args, 5, &tmp_len); if (!tmp) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } silc_buffer_set(&client_mode_list, tmp, tmp_len); @@ -1858,7 +1858,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(users) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Query failed: %s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -1874,7 +1874,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(users) } else { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "Query failed: %s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } } @@ -1911,18 +1911,18 @@ SILC_CLIENT_CMD_REPLY_FUNC(getkey) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } tmp = silc_argument_get_arg_type(cmd->args, 2, &len); if (!tmp) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } idp = silc_id_payload_parse(tmp, len); if (!idp) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -1939,7 +1939,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(getkey) client_id = silc_id_payload_get_id(idp); client_entry = silc_client_get_client_by_id(cmd->client, conn, client_id); if (!client_entry) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -1958,7 +1958,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(getkey) server_id = silc_id_payload_get_id(idp); server_entry = silc_client_get_server_by_id(cmd->client, conn, server_id); if (!server_entry) { - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; } @@ -2146,7 +2146,7 @@ static void silc_client_command_reply_users_i_cb(SilcClient client, cmd->status = cmd->error = SILC_STATUS_ERR_NO_SUCH_CHANNEL; SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_USERS); silc_client_command_reply_free(cmd); return; @@ -2191,7 +2191,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(connect) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -2211,7 +2211,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(close) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } @@ -2231,7 +2231,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(shutdown) if (cmd->error != SILC_STATUS_OK) { SAY(cmd->client, conn, SILC_CLIENT_MESSAGE_ERROR, "%s", silc_get_status_message(cmd->error)); - COMMAND_REPLY_ERROR; + COMMAND_REPLY_ERROR(cmd->error); goto out; } diff --git a/lib/silcclient/command_reply.h b/lib/silcclient/command_reply.h index 3f9e7598..9c6ca6b2 100644 --- a/lib/silcclient/command_reply.h +++ b/lib/silcclient/command_reply.h @@ -1,10 +1,10 @@ /* - command_reply.h + command_reply.h Author: Pekka Riikonen - Copyright (C) 1997 - 2001 Pekka Riikonen + Copyright (C) 1997 - 2003 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -51,16 +51,30 @@ struct SilcClientCommandReplyContextStruct { /* Macros */ -/* Command reply operation that is called at the end of all command replys. +/* Command reply operation that is called at the end of all command replys. Usage: COMMAND_REPLY((ARGS, argument1, argument2, etc...)), */ #define COMMAND_REPLY(args) cmd->client->internal->ops->command_reply args #define SILC_ARGS cmd->client, cmd->sock->user_data, \ cmd->payload, TRUE, silc_command_get(cmd->payload), cmd->status /* Error reply to application. Usage: COMMAND_REPLY_ERROR; */ -#define COMMAND_REPLY_ERROR cmd->client->internal->ops-> \ - command_reply(cmd->client, cmd->sock->user_data, cmd->payload, \ - FALSE, silc_command_get(cmd->payload), cmd->status) +#define COMMAND_REPLY_ERROR(error) \ +do { \ + if (cmd->status == SILC_STATUS_OK) { \ + cmd->client->internal->ops-> \ + command_reply(cmd->client, cmd->sock->user_data, cmd->payload, \ + FALSE, silc_command_get(cmd->payload), error); \ + } else { \ + void *arg1 = NULL, *arg2 = NULL; \ + silc_status_get_args(cmd->status, cmd->args, &arg1, &arg2); \ + cmd->client->internal->ops-> \ + command_reply(cmd->client, cmd->sock->user_data, cmd->payload, \ + FALSE, silc_command_get(cmd->payload), cmd->status, \ + arg1, arg2); \ + silc_free(arg1); \ + silc_free(arg2); \ + } \ +} while(0) /* Macro used to declare command reply functions */ #define SILC_CLIENT_CMD_REPLY_FUNC(func) \ diff --git a/lib/silccore/Makefile.am b/lib/silccore/Makefile.am index f01af8d6..7dae4012 100644 --- a/lib/silccore/Makefile.am +++ b/lib/silccore/Makefile.am @@ -3,7 +3,7 @@ # # Author: Pekka Riikonen # -# Copyright (C) 2000 - 2002 Pekka Riikonen +# Copyright (C) 2000 - 2003 Pekka Riikonen # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -29,7 +29,8 @@ libsilccore_la_SOURCES = \ silcargument.c \ silcnotify.c \ silcauth.c \ - silcattrs.c + silcattrs.c \ + silcstatus.c if SILC_DIST_TOOLKIT include_HEADERS = \ diff --git a/lib/silccore/silccommand.h b/lib/silccore/silccommand.h index 363bbe01..dc0e6482 100644 --- a/lib/silccore/silccommand.h +++ b/lib/silccore/silccommand.h @@ -1,16 +1,16 @@ /* - + silccommand.h - + Author: Pekka Riikonen - + Copyright (C) 1997 - 2001 Pekka Riikonen - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -51,7 +51,7 @@ typedef void (*SilcCommandCb)(void *context, void *context2); /****s* silccore/SilcCommandAPI/SilcCommandPayload * * NAME - * + * * typedef struct SilcCommandPayloadStruct *SilcCommandPayload; * * DESCRIPTION @@ -67,7 +67,7 @@ typedef struct SilcCommandPayloadStruct *SilcCommandPayload; /****d* silccore/SilcCommandAPI/SilcCommandFlags * * NAME - * + * * typedef enum { ... } SilcCommandFlags; * * DESCRIPTION @@ -98,7 +98,7 @@ typedef enum { /* Command is available only for server operators */ SILC_CF_OPER = (1L << 4), - /* Command is available only for SILC (router) operators. If this + /* Command is available only for SILC (router) operators. If this is set SILC_CF_OPER is not necessary to be set. */ SILC_CF_SILC_OPER = (1L << 5), @@ -108,7 +108,7 @@ typedef enum { /****d* silccore/SilcCommandAPI/SilcCommand * * NAME - * + * * typedef SilcUInt8 SilcCommand; * * DESCRIPTION @@ -168,7 +168,7 @@ typedef SilcUInt8 SilcCommand; * * SYNOPSIS * - * SilcCommandPayload + * SilcCommandPayload * silc_command_payload_parse(const unsigned char *payload, * SilcUInt32 payload_len); * @@ -208,7 +208,7 @@ SilcBuffer silc_command_payload_encode(SilcCommand cmd, * * SYNOPSIS * - * SilcBuffer + * SilcBuffer * silc_command_payload_encode_payload(SilcCommandPayload payload); * * DESCRIPTION @@ -223,31 +223,31 @@ SilcBuffer silc_command_payload_encode_payload(SilcCommandPayload payload); * * SYNOPSIS * - * SilcBuffer silc_command_payload_encode_va(SilcCommand cmd, - * SilcUInt16 ident, + * SilcBuffer silc_command_payload_encode_va(SilcCommand cmd, + * SilcUInt16 ident, * SilcUInt32 argc, ...); * * DESCRIPTION * * Encodes Command payload with variable argument list. The arguments - * must be: SilcUInt32, unsigned char *, unsigned int, ... One - * {SilcUInt32, unsigned char * and unsigned int} forms one argument, - * thus `argc' in case when sending one {SilcUInt32, unsigned char * + * must be: SilcUInt32, unsigned char *, unsigned int, ... One + * {SilcUInt32, unsigned char * and unsigned int} forms one argument, + * thus `argc' in case when sending one {SilcUInt32, unsigned char * * and SilcUInt32} equals one (1) and when sending two of those it * equals two (2), and so on. This has to be preserved or bad things * will happen. The variable arguments is: {type, data, data_len}. * ***/ -SilcBuffer silc_command_payload_encode_va(SilcCommand cmd, - SilcUInt16 ident, +SilcBuffer silc_command_payload_encode_va(SilcCommand cmd, + SilcUInt16 ident, SilcUInt32 argc, ...); /****f* silccore/SilcCommandAPI/silc_command_payload_encode_vap * * SYNOPSIS * - * SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd, - * SilcUInt16 ident, + * SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd, + * SilcUInt16 ident, * SilcUInt32 argc, va_list ap); * * DESCRIPTION @@ -256,16 +256,16 @@ SilcBuffer silc_command_payload_encode_va(SilcCommand cmd, * takes the va_list as argument. * ***/ -SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd, - SilcUInt16 ident, +SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd, + SilcUInt16 ident, SilcUInt32 argc, va_list ap); /****f* silccore/SilcCommandAPI/silc_command_reply_payload_encode_va * * SYNOPSIS * - * SilcBuffer - * silc_command_reply_payload_encode_va(SilcCommand cmd, + * SilcBuffer + * silc_command_reply_payload_encode_va(SilcCommand cmd, * SilcStatus status, * SilcStatus error, * SilcUInt16 ident, @@ -273,8 +273,8 @@ SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd, * * DESCRIPTION * - * Same as silc_command_payload_encode_va except that this is used to - * encode strictly command reply packets. The `argc' must not count + * Same as silc_command_payload_encode_va except that this is used to + * encode strictly command reply packets. The `argc' must not count * `status' and `error' as arguments. The `status' includes the * command reply status. If single reply will be sent then it includes * SILC_STATUS_OK if error did not occur. It includes an error value @@ -292,8 +292,8 @@ SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd, * replies are sent after the successful replies. * ***/ -SilcBuffer -silc_command_reply_payload_encode_va(SilcCommand cmd, +SilcBuffer +silc_command_reply_payload_encode_va(SilcCommand cmd, SilcStatus status, SilcStatus error, SilcUInt16 ident, @@ -303,8 +303,8 @@ silc_command_reply_payload_encode_va(SilcCommand cmd, * * SYNOPSIS * - * SilcBuffer - * silc_command_reply_payload_encode_vap(SilcCommand cmd, + * SilcBuffer + * silc_command_reply_payload_encode_vap(SilcCommand cmd, * SilcStatus status, * SilcStatus error, * SilcUInt16 ident, SilcUInt32 argc, @@ -316,11 +316,11 @@ silc_command_reply_payload_encode_va(SilcCommand cmd, * takes the va_list as argument. * ***/ -SilcBuffer -silc_command_reply_payload_encode_vap(SilcCommand cmd, +SilcBuffer +silc_command_reply_payload_encode_vap(SilcCommand cmd, SilcStatus status, SilcStatus error, - SilcUInt16 ident, SilcUInt32 argc, + SilcUInt16 ident, SilcUInt32 argc, va_list ap); /****f* silccore/SilcCommandAPI/silc_command_free @@ -383,7 +383,7 @@ SilcUInt16 silc_command_get_ident(SilcCommandPayload payload); * * SYNOPSIS * - * bool silc_command_get_status(SilcCommandPayload payload, + * bool silc_command_get_status(SilcCommandPayload payload, * SilcStatus *status, * SilcStatus *error); * @@ -397,7 +397,7 @@ SilcUInt16 silc_command_get_ident(SilcCommandPayload payload); * which indicates that there will be list of errors. * ***/ -bool silc_command_get_status(SilcCommandPayload payload, +bool silc_command_get_status(SilcCommandPayload payload, SilcStatus *status, SilcStatus *error); @@ -405,14 +405,14 @@ bool silc_command_get_status(SilcCommandPayload payload, * * SYNOPSIS * - * void silc_command_set_ident(SilcCommandPayload payload, + * void silc_command_set_ident(SilcCommandPayload payload, * SilcUInt16 ident); * * DESCRIPTION * * Function to set identifier to already allocated Command Payload. Command * payloads are frequentlly resent in SILC and thusly this makes it easy - * to set the identifier without encoding new Command Payload. + * to set the identifier without encoding new Command Payload. * ***/ void silc_command_set_ident(SilcCommandPayload payload, SilcUInt16 ident); @@ -421,7 +421,7 @@ void silc_command_set_ident(SilcCommandPayload payload, SilcUInt16 ident); * * SYNOPSIS * - * void silc_command_set_command(SilcCommandPayload payload, + * void silc_command_set_command(SilcCommandPayload payload, * SilcCommand command); * * DESCRIPTION diff --git a/lib/silccore/silcstatus.c b/lib/silccore/silcstatus.c new file mode 100644 index 00000000..43370721 --- /dev/null +++ b/lib/silccore/silcstatus.c @@ -0,0 +1,102 @@ +/* + + silcstatus.c + + Author: Pekka Riikonen + + Copyright (C) 2003 Pekka Riikonen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + +*/ +/* $Id$ */ + +#include "silcincludes.h" +#include "silcstatus.h" + +/* Returns arguments by the status type. */ + +SilcUInt32 silc_status_get_args(SilcStatus status, + SilcArgumentPayload args, + void **ret_arg1, void **ret_arg2) +{ + SilcUInt32 num, len; + unsigned char *tmp; + + assert(ret_arg1 && ret_arg2); + + num = silc_argument_get_arg_num(args); + if (num > 2) + return 0; + if (num == 0) + return 0; + + switch (status) { + + case SILC_STATUS_ERR_NO_SUCH_NICK: + case SILC_STATUS_ERR_NO_SUCH_CHANNEL: + case SILC_STATUS_ERR_NO_SUCH_SERVER: + case SILC_STATUS_ERR_NO_SUCH_SERVICE: + case SILC_STATUS_ERR_UNKNOWN_ALGORITHM: + tmp = silc_argument_get_arg_type(args, 2, &len); + if (!tmp) + return 0; + *ret_arg1 = silc_memdup(tmp, len); + if (!(*ret_arg1)) + return 0; + num = 1; + break; + + case SILC_STATUS_ERR_NO_SUCH_CLIENT_ID: + case SILC_STATUS_ERR_BAD_CLIENT_ID: + case SILC_STATUS_ERR_NO_SUCH_SERVER_ID: + case SILC_STATUS_ERR_BAD_SERVER_ID: + case SILC_STATUS_ERR_NO_SUCH_CHANNEL_ID: + case SILC_STATUS_ERR_BAD_CHANNEL_ID: + case SILC_STATUS_ERR_NOT_ON_CHANNEL: + case SILC_STATUS_ERR_CHANNEL_IS_FULL: + case SILC_STATUS_ERR_NOT_INVITED: + case SILC_STATUS_ERR_BANNED_FROM_CHANNEL: + case SILC_STATUS_ERR_NO_CHANNEL_PRIV: + case SILC_STATUS_ERR_NO_CHANNEL_FOPRIV: + tmp = silc_argument_get_arg_type(args, 2, &len); + if (!tmp) + return 0; + *ret_arg1 = silc_id_payload_parse_id(tmp, len, NULL); + if (!(*ret_arg1)) + return 0; + num = 1; + break; + + case SILC_STATUS_ERR_USER_NOT_ON_CHANNEL: + case SILC_STATUS_ERR_USER_ON_CHANNEL: + tmp = silc_argument_get_arg_type(args, 2, &len); + if (!tmp) + return 0; + *ret_arg1 = silc_id_payload_parse_id(tmp, len, NULL); + if (!(*ret_arg1)) + return 0; + num = 1; + tmp = silc_argument_get_arg_type(args, 3, &len); + if (!tmp) + return num; + *ret_arg2 = silc_id_payload_parse_id(tmp, len, NULL); + if (!(*ret_arg2)) + return num; + num = 2; + break; + + default: + return 0; + break; + } + + return num; +} diff --git a/lib/silccore/silcstatus.h b/lib/silccore/silcstatus.h index 4564a55d..3b5c7cd0 100644 --- a/lib/silccore/silcstatus.h +++ b/lib/silccore/silcstatus.h @@ -1,10 +1,10 @@ /* - silcstatus.h + silcstatus.h Author: Pekka Riikonen - Copyright (C) 2002 Pekka Riikonen + Copyright (C) 2002 - 2003 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -36,7 +36,7 @@ /****d* silccore/StatusTypes/SilcStatus * * NAME - * + * * typedef SilcUInt8 SilcStatus * * DESCRIPTION @@ -106,4 +106,24 @@ typedef SilcUInt8 SilcStatus; #define SILC_STATUS_IS_ERROR(status) (status >= SILC_STATUS_ERR_NO_SUCH_NICK) +/****f* silccore/SilcStatusTypes/silc_status_get_args + * + * SYNOPSIS + * + * SilcUInt32 silc_status_get_args(SilcStatus status, + * SilcArgumentPayload args, + * void **ret_arg1, **ret_arg2); + * + * DESCRIPTION + * + * Parses and returns the arguments from the `args' by the status type + * indicated by `status'. Returns the number of arguments (0, 1 or 2) + * parsed. The caller must free with silc_free the returned arguments. + * + ***/ +SilcUInt32 silc_status_get_args(SilcStatus status, + SilcArgumentPayload args, + void **ret_arg1, void **ret_arg2); + + #endif /* SILCSTATUS_H */ -- 2.43.0