Added SILC Thread Queue API
[runtime.git] / lib / silccore / silcstatus.c
1 /*
2
3   silcstatus.c
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 2003 - 2006 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 "silc.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     {
60       SilcID id;
61       tmp = silc_argument_get_arg_type(args, 2, &len);
62       if (!tmp)
63         return 0;
64       if (silc_id_payload_parse_id(tmp, len, &id))
65         return 0;
66       *ret_arg1 = silc_id_dup(&id.u.client_id, SILC_ID_CLIENT);
67       if (!(*ret_arg1))
68         return 0;
69       num = 1;
70     }
71     break;
72
73   case SILC_STATUS_ERR_NO_SUCH_SERVER_ID:
74   case SILC_STATUS_ERR_BAD_SERVER_ID:
75     {
76       SilcID id;
77       tmp = silc_argument_get_arg_type(args, 2, &len);
78       if (!tmp)
79         return 0;
80       if (silc_id_payload_parse_id(tmp, len, &id))
81         return 0;
82       *ret_arg1 = silc_id_dup(&id.u.server_id, SILC_ID_SERVER);
83       if (!(*ret_arg1))
84         return 0;
85       num = 1;
86     }
87     break;
88
89   case SILC_STATUS_ERR_NO_SUCH_CHANNEL_ID:
90   case SILC_STATUS_ERR_BAD_CHANNEL_ID:
91   case SILC_STATUS_ERR_NOT_ON_CHANNEL:
92   case SILC_STATUS_ERR_CHANNEL_IS_FULL:
93   case SILC_STATUS_ERR_NOT_INVITED:
94   case SILC_STATUS_ERR_BANNED_FROM_CHANNEL:
95   case SILC_STATUS_ERR_NO_CHANNEL_PRIV:
96   case SILC_STATUS_ERR_NO_CHANNEL_FOPRIV:
97     {
98       SilcID id;
99       tmp = silc_argument_get_arg_type(args, 2, &len);
100       if (!tmp)
101         return 0;
102       if (silc_id_payload_parse_id(tmp, len, &id))
103         return 0;
104       *ret_arg1 = silc_id_dup(&id.u.channel_id, SILC_ID_CHANNEL);
105       if (!(*ret_arg1))
106         return 0;
107       num = 1;
108     }
109     break;
110
111   case SILC_STATUS_ERR_USER_NOT_ON_CHANNEL:
112   case SILC_STATUS_ERR_USER_ON_CHANNEL:
113     {
114       SilcID id;
115       tmp = silc_argument_get_arg_type(args, 2, &len);
116       if (!tmp)
117         return 0;
118       if (silc_id_payload_parse_id(tmp, len, &id))
119         return 0;
120       *ret_arg1 = silc_id_dup(&id.u.client_id, id.type);
121       if (!(*ret_arg1))
122         return 0;
123       num = 1;
124       tmp = silc_argument_get_arg_type(args, 3, &len);
125       if (!tmp)
126         return num;
127       if (silc_id_payload_parse_id(tmp, len, &id))
128         return 0;
129       *ret_arg2 = silc_id_dup(&id.u.channel_id, id.type);
130       if (!(*ret_arg2))
131         return num;
132       num = 2;
133     }
134     break;
135
136   default:
137     return 0;
138     break;
139   }
140
141   return num;
142 }