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

Go to the source code of this file.

Data Structures

struct  wsp_pdu
 

Macros

#define PDU(name, docstring, fields, is_valid)   name,
 
#define PDU(name, docstring, fields, is_valid)   struct name { fields } name;
 
#define UINT(field, docstring, bits)   unsigned long field;
 
#define UINTVAR(field, docstring)   unsigned long field;
 
#define OCTSTR(field, docstring, lengthfield)   Octstr *field;
 
#define REST(field, docstring)   Octstr *field;
 
#define TYPE(bits, value)
 
#define RESERVED(bits)
 
#define TPI(confield)
 

Typedefs

typedef struct wsp_pdu WSP_PDU
 

Enumerations

enum  { GET_METHODS = 0x40, POST_METHODS = 0x60 }
 
enum  wsp_pdu_types { PDU, PDU }
 

Functions

WSP_PDUwsp_pdu_create (int type)
 
WSP_PDUwsp_pdu_unpack (Octstr *data)
 
Octstrwsp_pdu_pack (WSP_PDU *pdu)
 
void wsp_pdu_dump (WSP_PDU *pdu, int level)
 
void wsp_pdu_destroy (WSP_PDU *pdu)
 

Macro Definition Documentation

#define OCTSTR (   field,
  docstring,
  lengthfield 
)    Octstr *field;

Definition at line 94 of file wsp_pdu.h.

#define PDU (   name,
  docstring,
  fields,
  is_valid 
)    name,

Definition at line 91 of file wsp_pdu.h.

#define PDU (   name,
  docstring,
  fields,
  is_valid 
)    struct name { fields } name;

Definition at line 91 of file wsp_pdu.h.

#define RESERVED (   bits)

Definition at line 97 of file wsp_pdu.h.

#define REST (   field,
  docstring 
)    Octstr *field;

Definition at line 95 of file wsp_pdu.h.

#define TPI (   confield)

Definition at line 98 of file wsp_pdu.h.

#define TYPE (   bits,
  value 
)

Definition at line 96 of file wsp_pdu.h.

#define UINT (   field,
  docstring,
  bits 
)    unsigned long field;

Definition at line 92 of file wsp_pdu.h.

#define UINTVAR (   field,
  docstring 
)    unsigned long field;

Definition at line 93 of file wsp_pdu.h.

Typedef Documentation

typedef struct wsp_pdu WSP_PDU

Definition at line 110 of file wsp_pdu.h.

Enumeration Type Documentation

anonymous enum
Enumerator
GET_METHODS 
POST_METHODS 

Definition at line 74 of file wsp_pdu.h.

74  {
75  GET_METHODS = 0x40,
76  POST_METHODS = 0x60
77 };
Enumerator
PDU 
PDU 

Definition at line 80 of file wsp_pdu.h.

80  {
81 #define PDU(name, docstring, fields, is_valid) name,
82 #include "wsp_pdu.def"
83 #undef PDU
84 };

Function Documentation

WSP_PDU* wsp_pdu_create ( int  type)

Definition at line 68 of file wsp_pdu.c.

References panic, wsp_pdu::type, and type.

Referenced by make_confirmedpush_pdu(), make_connectreply_pdu(), make_push_pdu(), make_resume_reply_pdu(), pack_into_push_datagram(), pack_into_result_datagram(), and pack_sia().

68  {
69  WSP_PDU *pdu;
70 
71  pdu = gw_malloc(sizeof(*pdu));
72  pdu->type = type;
73 
74  switch (pdu->type) {
75 #define PDU(name, docstring, fields, is_valid) \
76  case name: {\
77  struct name *p; p = &pdu->u.name; \
78  fields \
79  } break;
80 #define UINT(field, docstring, bits) p->field = 0;
81 #define UINTVAR(field, docstring) p->field = 0;
82 #define OCTSTR(field, docstring, lengthfield) p->field = NULL;
83 #define REST(field, docstring) p->field = NULL;
84 #define TYPE(bits, value)
85 #define RESERVED(bits)
86 #include "wsp_pdu.def"
87 #undef RESERVED
88 #undef TYPE
89 #undef REST
90 #undef OCTSTR
91 #undef UINTVAR
92 #undef UINT
93 #undef PDU
94  default:
95  panic(0, "Internal error: Unknown PDU type %d", pdu->type);
96  break;
97  }
98 
99  return pdu;
100 }
int type
Definition: smsc_cimd2.c:215
int type
Definition: wsp_pdu.h:87
#define panic
Definition: log.h:87
void wsp_pdu_destroy ( WSP_PDU pdu)

Definition at line 102 of file wsp_pdu.c.

References panic, and wsp_pdu::type.

Referenced by main(), main_thread(), make_connectreply_pdu(), make_resume_reply_pdu(), pack_into_push_datagram(), pack_into_result_datagram(), pack_sia(), push_client_event_handle(), send_invoke(), and unpack_datagram().

102  {
103  if (pdu == NULL)
104  return;
105 
106  switch (pdu->type) {
107 #define PDU(name, docstring, fields, is_valid) \
108  case name: {\
109  struct name *p; p = &pdu->u.name; \
110  fields \
111  } break;
112 #define UINT(field, docstring, bits)
113 #define UINTVAR(field, docstring)
114 #define OCTSTR(field, docstring, lengthfield) octstr_destroy(p->field);
115 #define REST(field, docstring) octstr_destroy(p->field);
116 #define TYPE(bits, value)
117 #define RESERVED(bits)
118 #include "wsp_pdu.def"
119 #undef RESERVED
120 #undef TYPE
121 #undef REST
122 #undef OCTSTR
123 #undef UINTVAR
124 #undef UINT
125 #undef PDU
126  default:
127  panic(0, "Cannot destroy unknown WSP PDU type %d", pdu->type);
128  break;
129  }
130 
131  gw_free(pdu);
132 }
int type
Definition: wsp_pdu.h:87
#define panic
Definition: log.h:87
void wsp_pdu_dump ( WSP_PDU pdu,
int  level 
)

Definition at line 324 of file wsp_pdu.c.

References debug(), and wsp_pdu::type.

Referenced by main(), and pack_into_push_datagram().

324  {
325  char *dbg = "wap.wsp";
326 
327  switch (pdu->type) {
328 #define PDU(name, docstring, fields, is_valid) \
329  case name: { \
330  struct name *p = &pdu->u.name; \
331  debug(dbg, 0, "%*sWSP %s PDU at %p:", \
332  level, "", #name, (void *)pdu); \
333  fields \
334  } break;
335 #define UINT(field, docstring, bits) \
336  debug(dbg, 0, "%*s %s: %lu", level, "", docstring, p->field);
337 #define UINTVAR(field, docstring) \
338  debug(dbg, 0, "%*s %s: %lu", level, "", docstring, p->field);
339 #define OCTSTR(field, docstring, lengthfield) \
340  debug(dbg, 0, "%*s %s:", level, "", docstring); \
341  octstr_dump(p->field, level + 1);
342 #define REST(field, docstring) \
343  debug(dbg, 0, "%*s %s:", level, "", docstring); \
344  octstr_dump(p->field, level + 1);
345 #define TYPE(bits, value)
346 #define RESERVED(bits)
347 #include "wsp_pdu.def"
348 #undef RESERVED
349 #undef TYPE
350 #undef REST
351 #undef OCTSTR
352 #undef UINTVAR
353 #undef UINT
354 #undef PDU
355  default:
356  debug(dbg, 0, "%*sWSP PDU at %p:", level, "", (void *)pdu);
357  debug(dbg, 0, "%*s unknown type %u", level, "", pdu->type);
358  break;
359  }
360  debug("wap.wsp", 0, "%*sWSP PDU dump ends.", level, "");
361 }
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
int type
Definition: wsp_pdu.h:87
Octstr* wsp_pdu_pack ( WSP_PDU pdu)

Definition at line 271 of file wsp_pdu.c.

References fixup_length_fields(), octstr_create, panic, and wsp_pdu::type.

Referenced by main(), make_connectreply_pdu(), make_resume_reply_pdu(), pack_into_push_datagram(), pack_into_result_datagram(), pack_sia(), and send_invoke().

271  {
272  Octstr *data;
273  long bitpos;
274 
275  /* We rely on octstr_set_bits to lengthen our octstr as needed. */
276  data = octstr_create("");
277 
278  fixup_length_fields(pdu);
279 
280  bitpos = 0;
281  switch (pdu->type) {
282 #define PDU(name, docstring, fields, is_valid) \
283  case name: { \
284  struct name *p = &pdu->u.name; \
285  fields \
286  gw_assert(bitpos % 8 == 0); \
287  } break;
288 #define UINT(field, docstring, bits) \
289  octstr_set_bits(data, bitpos, (bits), p->field); \
290  bitpos += (bits);
291 #define UINTVAR(field, docstring) \
292  gw_assert(bitpos % 8 == 0); \
293  octstr_append_uintvar(data, p->field); \
294  bitpos = 8 * octstr_len(data);
295 #define OCTSTR(field, docstring, lengthfield) \
296  gw_assert(bitpos % 8 == 0); \
297  if (p->field != NULL) \
298  octstr_append(data, p->field); \
299  bitpos += 8 * octstr_len(p->field);
300 #define REST(field, docstring) \
301  gw_assert(bitpos % 8 == 0); \
302  if (p->field != NULL) \
303  octstr_append(data, p->field); \
304  bitpos += 8 * octstr_len(p->field);
305 #define TYPE(bits, value) \
306  octstr_set_bits(data, bitpos, (bits), (value)); \
307  bitpos += (bits);
308 #define RESERVED(bits) bitpos += (bits);
309 #include "wsp_pdu.def"
310 #undef RESERVED
311 #undef TYPE
312 #undef REST
313 #undef OCTSTR
314 #undef UINTVAR
315 #undef UINT
316 #undef PDU
317  default:
318  panic(0, "Packing unknown WSP PDU type %ld", (long) pdu->type);
319  }
320 
321  return data;
322 }
static void fixup_length_fields(WSP_PDU *pdu)
Definition: wsp_pdu.c:246
#define octstr_create(cstr)
Definition: octstr.h:125
Definition: octstr.c:118
int type
Definition: wsp_pdu.h:87
#define panic
Definition: log.h:87
WSP_PDU* wsp_pdu_unpack ( Octstr data)

Definition at line 178 of file wsp_pdu.c.

References gw_assert(), wsp_pdu::type, warning(), and wsp_pdu_type().

Referenced by client_session(), main(), main_thread(), push_client_event_handle(), and unpack_datagram().

178  {
179  WSP_PDU *pdu = NULL;
180  long bitpos = 0;
181 
182  gw_assert(data != NULL);
183 
184  pdu = gw_malloc(sizeof(*pdu));
185 
186  pdu->type = wsp_pdu_type(data);
187 
188  switch (pdu->type) {
189 #define PDU(name, docstring, fields, is_valid) \
190  case name: { \
191  struct name *p = &pdu->u.name; \
192  fields \
193  gw_assert(bitpos % 8 == 0); \
194  if (bitpos / 8 != octstr_len(data)) { \
195  warning(0, "Bad length for " #name " PDU, " \
196  "expected %ld", bitpos / 8); \
197  } \
198  if (!(is_valid)) { \
199  warning(0, #name " PDU failed %s", #is_valid); \
200  } \
201  } break;
202 #define UINT(field, docstring, bits) \
203  p->field = octstr_get_bits(data, bitpos, (bits)); \
204  bitpos += (bits);
205 #define UINTVAR(field, docstring) \
206  gw_assert(bitpos % 8 == 0); \
207  p->field = octstr_get_bits(data, bitpos + 1, 7); \
208  while (octstr_get_bits(data, bitpos, 1)) { \
209  bitpos += 8; \
210  p->field <<= 7; \
211  p->field |= octstr_get_bits(data, bitpos + 1, 7); \
212  } \
213  bitpos += 8;
214 #define OCTSTR(field, docstring, lengthfield) \
215  gw_assert(bitpos % 8 == 0); \
216  p->field = octstr_copy(data, bitpos / 8, p->lengthfield); \
217  bitpos += 8 * p->lengthfield;
218 #define REST(field, docstring) \
219  gw_assert(bitpos % 8 == 0); \
220  if (bitpos / 8 <= octstr_len(data)) { \
221  p->field = octstr_copy(data, bitpos / 8, \
222  octstr_len(data) - bitpos / 8); \
223  bitpos = octstr_len(data) * 8; \
224  } else { \
225  p->field = octstr_create(""); \
226  }
227 #define TYPE(bits, value) bitpos += (bits);
228 #define RESERVED(bits) bitpos += (bits);
229 #include "wsp_pdu.def"
230 #undef RESERVED
231 #undef TYPE
232 #undef REST
233 #undef OCTSTR
234 #undef UINTVAR
235 #undef UINT
236 #undef PDU
237  default:
238  warning(0, "WSP PDU with unknown type %d", pdu->type);
239  gw_free(pdu);
240  return NULL;
241  }
242 
243  return pdu;
244 }
void warning(int err, const char *fmt,...)
Definition: log.c:624
static int wsp_pdu_type(Octstr *data)
Definition: wsp_pdu.c:136
gw_assert(wtls_machine->packet_to_send!=NULL)
int type
Definition: wsp_pdu.h:87
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.