Merged silc_1_0_branch to trunk.
[silc.git] / lib / silccore / silcstatus.c
1 /*
2
3   silcstatus.c
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2003 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19 /* $Id$ */
20
21 #include "silcincludes.h"
22 #include "silcstatus.h"
23
24 /* Returns arguments by the status type. */
25
26 SilcUInt32 silc_status_get_args(SilcStatus status,
27                                 SilcArgumentPayload args,
28                                 void **ret_arg1, void **ret_arg2)
29 {
30   SilcUInt32 num, len;
31   unsigned char *tmp;
32
33   assert(ret_arg1 && ret_arg2);
34
35   num = silc_argument_get_arg_num(args);
36   if (num > 3)
37     return 0;
38   if (num == 0)
39     return 0;
40
41   switch (status) {
42
43   case SILC_STATUS_ERR_NO_SUCH_NICK:
44   case SILC_STATUS_ERR_NO_SUCH_CHANNEL:
45   case SILC_STATUS_ERR_NO_SUCH_SERVER:
46   case SILC_STATUS_ERR_NO_SUCH_SERVICE:
47   case SILC_STATUS_ERR_UNKNOWN_ALGORITHM:
48     tmp = silc_argument_get_arg_type(args, 2, &len);
49     if (!tmp)
50       return 0;
51     *ret_arg1 = silc_memdup(tmp, len);
52     if (!(*ret_arg1))
53       return 0;
54     num = 1;
55     break;
56
57   case SILC_STATUS_ERR_NO_SUCH_CLIENT_ID:
58   case SILC_STATUS_ERR_BAD_CLIENT_ID:
59   case SILC_STATUS_ERR_NO_SUCH_SERVER_ID:
60   case SILC_STATUS_ERR_BAD_SERVER_ID:
61   case SILC_STATUS_ERR_NO_SUCH_CHANNEL_ID:
62   case SILC_STATUS_ERR_BAD_CHANNEL_ID:
63   case SILC_STATUS_ERR_NOT_ON_CHANNEL:
64   case SILC_STATUS_ERR_CHANNEL_IS_FULL:
65   case SILC_STATUS_ERR_NOT_INVITED:
66   case SILC_STATUS_ERR_BANNED_FROM_CHANNEL:
67   case SILC_STATUS_ERR_NO_CHANNEL_PRIV:
68   case SILC_STATUS_ERR_NO_CHANNEL_FOPRIV:
69     tmp = silc_argument_get_arg_type(args, 2, &len);
70     if (!tmp)
71       return 0;
72     *ret_arg1 = silc_id_payload_parse_id(tmp, len, NULL);
73     if (!(*ret_arg1))
74       return 0;
75     num = 1;
76     break;
77
78   case SILC_STATUS_ERR_USER_NOT_ON_CHANNEL:
79   case SILC_STATUS_ERR_USER_ON_CHANNEL:
80     tmp = silc_argument_get_arg_type(args, 2, &len);
81     if (!tmp)
82       return 0;
83     *ret_arg1 = silc_id_payload_parse_id(tmp, len, NULL);
84     if (!(*ret_arg1))
85       return 0;
86     num = 1;
87     tmp = silc_argument_get_arg_type(args, 3, &len);
88     if (!tmp)
89       return num;
90     *ret_arg2 = silc_id_payload_parse_id(tmp, len, NULL);
91     if (!(*ret_arg2))
92       return num;
93     num = 2;
94     break;
95
96   default:
97     return 0;
98     break;
99   }
100
101   return num;
102 }