Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
wsp_caps.c File Reference
#include "gwlib/gwlib.h"
#include "wsp_caps.h"

Go to the source code of this file.

Functions

static void wsp_cap_destroy_item (void *cap)
 
Capabilitywsp_cap_create (int id, Octstr *name, Octstr *data)
 
void wsp_cap_destroy (Capability *cap)
 
void wsp_cap_dump (Capability *cap)
 
void wsp_cap_dump_list (List *caps_list)
 
void wsp_cap_destroy_list (List *caps_list)
 
Listwsp_cap_duplicate_list (List *caps_list)
 
Capabilitywsp_cap_duplicate (Capability *cap)
 
Listwsp_cap_unpack_list (Octstr *caps)
 
Octstrwsp_cap_pack_list (List *caps_list)
 
static int wsp_cap_get_data (List *caps_list, int id, Octstr *name, Octstr **data)
 
int wsp_cap_count (List *caps_list, int id, Octstr *name)
 
int wsp_cap_get_client_sdu (List *caps_list, unsigned long *sdu)
 
int wsp_cap_get_server_sdu (List *caps_list, unsigned long *sdu)
 
int wsp_cap_get_method_mor (List *caps_list, unsigned long *mor)
 
int wsp_cap_get_push_mor (List *caps_list, unsigned long *mor)
 

Function Documentation

int wsp_cap_count ( List caps_list,
int  id,
Octstr name 
)

Definition at line 282 of file wsp_caps.c.

References wsp_cap_get_data().

Referenced by refuse_unreplied_capabilities(), reply_known_capabilities(), and strip_default_capabilities().

282  {
283  Octstr *data;
284 
285  return wsp_cap_get_data(caps_list, id, name, &data);
286 }
static int wsp_cap_get_data(List *caps_list, int id, Octstr *name, Octstr **data)
Definition: wsp_caps.c:259
Definition: octstr.c:118
Capability* wsp_cap_create ( int  id,
Octstr name,
Octstr data 
)

Definition at line 71 of file wsp_caps.c.

References capability::accept, capability::data, capability::id, capability::name, and name.

Referenced by refuse_unreplied_capabilities(), reply_known_capabilities(), wsp_cap_duplicate(), and wsp_cap_unpack_list().

71  {
72  Capability *new_cap;
73 
74  new_cap = gw_malloc(sizeof(*new_cap));
75  new_cap->id = id;
76  new_cap->name = name;
77  new_cap->data = data;
78  new_cap->accept = 0;
79 
80  return new_cap;
81 }
int id
Definition: wsp_caps.h:72
Octstr * data
Definition: wsp_caps.h:76
char * name
Definition: smsc_cimd2.c:212
int accept
Definition: wsp_caps.h:80
Octstr * name
Definition: wsp_caps.h:73
void wsp_cap_destroy ( Capability cap)

Definition at line 83 of file wsp_caps.c.

References capability::data, capability::name, and octstr_destroy().

Referenced by sanitize_capabilities(), strip_default_capabilities(), and wsp_cap_destroy_item().

83  {
84  if (cap == NULL)
85  return;
86 
87  octstr_destroy(cap->name);
88  octstr_destroy(cap->data);
89  gw_free(cap);
90 }
Octstr * data
Definition: wsp_caps.h:76
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
Octstr * name
Definition: wsp_caps.h:73
static void wsp_cap_destroy_item ( void *  cap)
static

Definition at line 66 of file wsp_caps.c.

References wsp_cap_destroy().

Referenced by wsp_cap_destroy_list().

66  {
67  wsp_cap_destroy(cap);
68 }
void wsp_cap_destroy(Capability *cap)
Definition: wsp_caps.c:83
void wsp_cap_destroy_list ( List caps_list)

Definition at line 121 of file wsp_caps.c.

References gwlist_destroy(), and wsp_cap_destroy_item().

Referenced by make_connectreply_pdu().

121  {
123 }
static void wsp_cap_destroy_item(void *cap)
Definition: wsp_caps.c:66
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
void wsp_cap_dump ( Capability cap)

Definition at line 92 of file wsp_caps.c.

References capability::accept, capability::data, debug(), capability::id, capability::name, and octstr_dump.

Referenced by sanitize_capabilities(), wsp_cap_dump_list(), and wsp_cap_pack_list().

92  {
93  debug("wsp", 0, "Dumping capability at %p:", cap);
94  if (cap) {
95  debug("wsp", 0, " id = %d", cap->id);
96  debug("wsp", 0, " name:");
97  octstr_dump(cap->name, 1);
98  debug("wsp", 0, " data:");
99  octstr_dump(cap->data, 1);
100  if (cap->data == NULL)
101  debug("wsp", 0, " accept: %d", cap->accept);
102  }
103  debug("wsp", 0, "Capability dump ends.");
104 }
int id
Definition: wsp_caps.h:72
Octstr * data
Definition: wsp_caps.h:76
#define octstr_dump(ostr, level,...)
Definition: octstr.h:564
int accept
Definition: wsp_caps.h:80
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
Octstr * name
Definition: wsp_caps.h:73
void wsp_cap_dump_list ( List caps_list)

Definition at line 106 of file wsp_caps.c.

References debug(), gwlist_get(), gwlist_len(), and wsp_cap_dump().

106  {
107  long i;
108 
109  if (caps_list == NULL) {
110  debug("wsp", 0, "NULL capability list");
111  return;
112  }
113  debug("wsp", 0, "Dumping capability list at %p, length %ld",
114  caps_list, gwlist_len(caps_list));
115  for (i = 0; i < gwlist_len(caps_list); i++) {
116  wsp_cap_dump(gwlist_get(caps_list, i));
117  }
118  debug("wsp", 0, "End of capability list dump");
119 }
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
void wsp_cap_dump(Capability *cap)
Definition: wsp_caps.c:92
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
Capability* wsp_cap_duplicate ( Capability cap)

Definition at line 142 of file wsp_caps.c.

References capability::accept, capability::data, capability::id, capability::name, octstr_duplicate, and wsp_cap_create().

Referenced by wsp_cap_duplicate_list().

142  {
143  Capability *new_cap;
144 
145  if (!cap)
146  return NULL;
147 
148  new_cap = wsp_cap_create(cap->id,
149  octstr_duplicate(cap->name),
150  octstr_duplicate(cap->data));
151  new_cap->accept = cap->accept;
152  return new_cap;
153 }
int id
Definition: wsp_caps.h:72
Capability * wsp_cap_create(int id, Octstr *name, Octstr *data)
Definition: wsp_caps.c:71
Octstr * data
Definition: wsp_caps.h:76
#define octstr_duplicate(ostr)
Definition: octstr.h:187
int accept
Definition: wsp_caps.h:80
Octstr * name
Definition: wsp_caps.h:73
List* wsp_cap_duplicate_list ( List caps_list)

Definition at line 125 of file wsp_caps.c.

References gwlist_append(), gwlist_create, gwlist_get(), gwlist_len(), and wsp_cap_duplicate().

Referenced by indicate_push_connection(), make_capabilities_reply(), response_push_connection(), session_machine_create(), and update_session_data().

125  {
126  Capability *cap;
127  List *new_list;
128  long i;
129 
130  new_list = gwlist_create();
131 
132  if (caps_list == NULL)
133  return new_list;
134 
135  for (i = 0; i < gwlist_len(caps_list); i++) {
136  cap = gwlist_get(caps_list, i);
137  gwlist_append(new_list, wsp_cap_duplicate(cap));
138  }
139  return new_list;
140 };
void gwlist_append(List *list, void *item)
Definition: list.c:179
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
Capability * wsp_cap_duplicate(Capability *cap)
Definition: wsp_caps.c:142
#define gwlist_create()
Definition: list.h:136
Definition: list.c:102
int wsp_cap_get_client_sdu ( List caps_list,
unsigned long *  sdu 
)

Definition at line 288 of file wsp_caps.c.

References found, octstr_extract_uintvar(), wsp_cap_get_data(), and WSP_CAPS_CLIENT_SDU_SIZE.

Referenced by reply_known_capabilities().

288  {
289  Octstr *data;
290  int found;
291 
292  found = wsp_cap_get_data(caps_list, WSP_CAPS_CLIENT_SDU_SIZE,
293  NULL, &data);
294  if (found > 0 && octstr_extract_uintvar(data, sdu, 0) < 0)
295  return -1;
296 
297  return found;
298 }
static int wsp_cap_get_data(List *caps_list, int id, Octstr *name, Octstr **data)
Definition: wsp_caps.c:259
static struct pid_list * found
Definition: octstr.c:118
long octstr_extract_uintvar(Octstr *ostr, unsigned long *value, long pos)
Definition: octstr.c:1952
static int wsp_cap_get_data ( List caps_list,
int  id,
Octstr name,
Octstr **  data 
)
static

Definition at line 259 of file wsp_caps.c.

References capability::data, found, gwlist_get(), gwlist_len(), capability::id, capability::name, and octstr_compare().

Referenced by wsp_cap_count(), wsp_cap_get_client_sdu(), wsp_cap_get_method_mor(), wsp_cap_get_push_mor(), and wsp_cap_get_server_sdu().

260  {
261  long i, len;
262  Capability *cap;
263  int found;
264 
265  len = gwlist_len(caps_list);
266  found = 0;
267  *data = NULL;
268  for (i = 0; i < len; i++) {
269  cap = gwlist_get(caps_list, i);
270  if ((name && cap->name
271  && octstr_compare(name, cap->name) == 0)
272  || (!name && cap->id == id)) {
273  if (!found)
274  *data = cap->data;
275  found++;
276  }
277  }
278 
279  return found;
280 }
int id
Definition: wsp_caps.h:72
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
static struct pid_list * found
Octstr * data
Definition: wsp_caps.h:76
Octstr * name
Definition: wsp_caps.h:73
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
int wsp_cap_get_method_mor ( List caps_list,
unsigned long *  mor 
)

Definition at line 312 of file wsp_caps.c.

References found, octstr_get_char(), wsp_cap_get_data(), and WSP_CAPS_METHOD_MOR.

Referenced by reply_known_capabilities().

312  {
313  Octstr *data;
314  int found;
315  int c;
316 
317  found = wsp_cap_get_data(caps_list, WSP_CAPS_METHOD_MOR, NULL, &data);
318  if (found > 0) {
319  c = octstr_get_char(data, 0);
320  if (c < 0)
321  return -1;
322  *mor = c;
323  }
324 
325  return found;
326 }
static int wsp_cap_get_data(List *caps_list, int id, Octstr *name, Octstr **data)
Definition: wsp_caps.c:259
static struct pid_list * found
Definition: octstr.c:118
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
int wsp_cap_get_push_mor ( List caps_list,
unsigned long *  mor 
)

Definition at line 328 of file wsp_caps.c.

References found, octstr_get_char(), wsp_cap_get_data(), and WSP_CAPS_PUSH_MOR.

Referenced by reply_known_capabilities().

328  {
329  Octstr *data;
330  int found;
331  int c;
332 
333  found = wsp_cap_get_data(caps_list, WSP_CAPS_PUSH_MOR, NULL, &data);
334  if (found > 0) {
335  c = octstr_get_char(data, 0);
336  if (c < 0)
337  return -1;
338  *mor = c;
339  }
340 
341  return found;
342 }
static int wsp_cap_get_data(List *caps_list, int id, Octstr *name, Octstr **data)
Definition: wsp_caps.c:259
static struct pid_list * found
Definition: octstr.c:118
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
int wsp_cap_get_server_sdu ( List caps_list,
unsigned long *  sdu 
)

Definition at line 300 of file wsp_caps.c.

References found, octstr_extract_uintvar(), wsp_cap_get_data(), and WSP_CAPS_SERVER_SDU_SIZE.

Referenced by reply_known_capabilities().

300  {
301  Octstr *data;
302  int found;
303 
304  found = wsp_cap_get_data(caps_list, WSP_CAPS_SERVER_SDU_SIZE,
305  NULL, &data);
306  if (found > 0 && octstr_extract_uintvar(data, sdu, 0) < 0)
307  return -1;
308 
309  return found;
310 }
static int wsp_cap_get_data(List *caps_list, int id, Octstr *name, Octstr **data)
Definition: wsp_caps.c:259
static struct pid_list * found
Definition: octstr.c:118
long octstr_extract_uintvar(Octstr *ostr, unsigned long *value, long pos)
Definition: octstr.c:1952
Octstr* wsp_cap_pack_list ( List caps_list)

Definition at line 207 of file wsp_caps.c.

References capability::accept, capability::data, error(), gwlist_get(), gwlist_len(), capability::id, capability::name, octstr_append(), octstr_append_char(), octstr_append_uintvar(), octstr_create, octstr_get_char(), octstr_len(), octstr_search_char(), and wsp_cap_dump().

Referenced by make_connectreply_pdu().

207  {
208  Octstr *result;
209  Capability *cap;
210  long i, len;
211 
212  result = octstr_create("");
213  len = gwlist_len(caps_list);
214  for (i = 0; i < len; i++) {
215  long datalen;
216 
217  cap = gwlist_get(caps_list, i);
218 
219  datalen = 0;
220  if (cap->data)
221  datalen = octstr_len(cap->data);
222 
223  if (datalen == 0 && cap->accept)
224  continue;
225 
226  if (cap->name) {
227  if (octstr_get_char(cap->name, 0) >= 0x80 ||
228  octstr_search_char(cap->name, 0, 0) >= 0) {
229  error(0, "WSP: Bad capability.");
230  wsp_cap_dump(cap);
231  continue;
232  }
233  /* Add length */
234  octstr_append_uintvar(result,
235  octstr_len(cap->name) + 1 + datalen);
236  /* Add identifier */
237  octstr_append(result, cap->name);
238  octstr_append_char(result, 0);
239  } else {
240  if (cap->id >= 0x80 || cap->id < 0) {
241  error(0, "WSP: Bad capability.");
242  wsp_cap_dump(cap);
243  continue;
244  }
245  /* Add length */
246  octstr_append_uintvar(result, 1 + datalen);
247  /* Add identifier */
248  octstr_append_char(result, 0x80 | cap->id);
249  }
250  /* Add payload, if any */
251  if (cap->data) {
252  octstr_append(result, cap->data);
253  }
254  }
255 
256  return result;
257 }
void error(int err, const char *fmt,...)
Definition: log.c:612
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1502
int id
Definition: wsp_caps.h:72
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
void octstr_append_char(Octstr *ostr, int ch)
Definition: octstr.c:1515
void wsp_cap_dump(Capability *cap)
Definition: wsp_caps.c:92
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1010
Octstr * data
Definition: wsp_caps.h:76
int accept
Definition: wsp_caps.h:80
#define octstr_create(cstr)
Definition: octstr.h:125
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
void octstr_append_uintvar(Octstr *ostr, unsigned long value)
Definition: octstr.c:1929
Definition: octstr.c:118
Octstr * name
Definition: wsp_caps.h:73
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
List* wsp_cap_unpack_list ( Octstr caps)

Definition at line 155 of file wsp_caps.c.

References error(), gwlist_append(), gwlist_create, name, octstr_copy, octstr_extract_uintvar(), octstr_get_char(), octstr_len(), octstr_search_char(), warning(), and wsp_cap_create().

155  {
156  List *caps_list;
157  long pos, capslen;
158 
159  caps_list = gwlist_create();
160  if (caps == NULL)
161  return caps_list;
162 
163  capslen = octstr_len(caps);
164  pos = 0;
165  while (pos < capslen) {
166  unsigned long length;
167  int id;
168  Octstr *name;
169  Octstr *data;
170 
171  pos = octstr_extract_uintvar(caps, &length, pos);
172  if (pos < 0 || length == 0)
173  goto error;
174 
175  id = octstr_get_char(caps, pos);
176  if (id >= 0x80) {
177  id &= 0x7f; /* It's encoded as a short-integer */
178  name = NULL;
179  data = octstr_copy(caps, pos + 1, length - 1);
180  } else {
181  long nullpos;
182  id = -1; /* It's encoded as token-text */
183  nullpos = octstr_search_char(caps, 0, pos);
184  if (nullpos < 0)
185  goto error;
186  /* check length
187  * FIXME: If it's not allowed that data is empty then change check
188  * to <= .
189  */
190  if (length < (nullpos + 1 - pos))
191  goto error;
192  name = octstr_copy(caps, pos, nullpos - pos);
193  data = octstr_copy(caps, nullpos + 1,
194  length - (nullpos + 1 - pos));
195  }
196  gwlist_append(caps_list, wsp_cap_create(id, name, data));
197  pos += length;
198  }
199 
200  return caps_list;
201 
202 error:
203  warning(0, "WSP: Error unpacking capabilities");
204  return caps_list;
205 }
void error(int err, const char *fmt,...)
Definition: log.c:612
void gwlist_append(List *list, void *item)
Definition: list.c:179
Capability * wsp_cap_create(int id, Octstr *name, Octstr *data)
Definition: wsp_caps.c:71
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1010
char * name
Definition: smsc_cimd2.c:212
void warning(int err, const char *fmt,...)
Definition: log.c:624
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
Definition: octstr.c:118
#define gwlist_create()
Definition: list.h:136
long octstr_extract_uintvar(Octstr *ostr, unsigned long *value, long pos)
Definition: octstr.c:1952
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
Definition: list.c:102
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.