Kannel: Open Source WAP and SMS gateway  svn-r5335
wap_push_ota.c File Reference
#include <errno.h>
#include "wap_push_ota.h"
#include "gwlib/gwlib.h"
#include "wap/wsp.h"
#include "wap/wsp_strings.h"
#include "wap/wsp_pdu.h"

Go to the source code of this file.

Data Structures

struct  BearerboxAddress
 

Typedefs

typedef struct BearerboxAddress BearerboxAddress
 

Enumerations

enum  { limbo, running, terminating }
 

Functions

static void main_thread (void *arg)
 
static void handle_ota_event (WAPEvent *e)
 
static void make_session_request (WAPEvent *e)
 
static void make_push_request (WAPEvent *e)
 
static void make_confirmed_push_request (WAPEvent *e)
 
static void make_unit_push_request (WAPEvent *e)
 
static void abort_push (WAPEvent *e)
 
static Listadd_push_flag (WAPEvent *e)
 
static void check_session_request_headers (List *headers)
 
static Octstrpack_sia (List *headers)
 
static void flags_assert (WAPEvent *e)
 
static void reason_assert (long reason)
 
static Octstrpack_server_address (void)
 
static Octstrpack_appid_list (List *headers)
 
static Octstrname (Octstr *os)
 
static BearerboxAddressbearerbox_address_create (void)
 
static void bearerbox_address_destroy (BearerboxAddress *ba)
 
void wap_push_ota_init (wap_dispatch_func_t *wsp_dispatch, wap_dispatch_func_t *wsp_unit_dispatch)
 
void wap_push_ota_shutdown (void)
 
void wap_push_ota_dispatch_event (WAPEvent *e)
 
void wap_push_ota_bb_address_set (Octstr *in)
 

Variables

static enum { ... }  run_status = limbo
 
static BearerboxAddressbearerbox = NULL
 
static Listota_queue = NULL
 
static wap_dispatch_func_tdispatch_to_wsp
 
static wap_dispatch_func_tdispatch_to_wsp_unit
 

Typedef Documentation

◆ BearerboxAddress

Definition at line 110 of file wap_push_ota.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
limbo 
running 
terminating 

Definition at line 101 of file wap_push_ota.c.

Function Documentation

◆ abort_push()

static void abort_push ( WAPEvent e)
static

Definition at line 408 of file wap_push_ota.c.

References dispatch_to_wsp, gw_assert(), reason_assert(), WAPEvent::type, WAPEvent::u, and wap_event_create.

Referenced by handle_ota_event().

409 {
410  WAPEvent *wsp_event;
411  long reason;
412 
413  reason = e->u.Po_PushAbort_Req.reason;
414  gw_assert(e->type == Po_PushAbort_Req);
415  reason_assert(reason);
416 
417  wsp_event = wap_event_create(S_PushAbort_Req);
418  wsp_event->u.S_PushAbort_Req.push_id = e->u.Po_PushAbort_Req.push_id;
419  wsp_event->u.S_PushAbort_Req.reason = reason;
420  wsp_event->u.S_PushAbort_Req.session_handle =
421  e->u.Po_PushAbort_Req.session_id;
422 
423  dispatch_to_wsp(wsp_event);
424 }
gw_assert(wtls_machine->packet_to_send !=NULL)
static wap_dispatch_func_t * dispatch_to_wsp
Definition: wap_push_ota.c:116
#define wap_event_create(type)
Definition: wap_events.h:107
static void reason_assert(long reason)
Definition: wap_push_ota.c:513
WAPEventName type
Definition: wap_events.h:88
union WAPEvent::@87 u

◆ add_push_flag()

static List * add_push_flag ( WAPEvent e)
static

Definition at line 430 of file wap_push_ota.c.

References debug(), flags_assert(), http_header_add(), http_header_duplicate(), octstr_destroy(), octstr_format(), octstr_get_cstr, WAPEvent::type, WAPEvent::u, and wap_event_dump().

Referenced by make_confirmed_push_request(), make_push_request(), and make_unit_push_request().

431 {
432  int push_flag,
433  trusted,
434  authenticated,
435  last;
436 
437  Octstr *buf;
438  List *headers;
439 
440  flags_assert(e);
441 
442  if (e->type == Po_Unit_Push_Req) {
443  trusted = e->u.Po_Unit_Push_Req.trusted << 1;
444  authenticated = e->u.Po_Unit_Push_Req.authenticated;
445  last = e->u.Po_Unit_Push_Req.last << 2;
446 
447  headers = http_header_duplicate(e->u.Po_Unit_Push_Req.push_headers);
448 
449  } else if (e->type == Po_Push_Req) {
450  trusted = e->u.Po_Push_Req.trusted << 1;
451  authenticated = e->u.Po_Push_Req.authenticated;
452  last = e->u.Po_Push_Req.last << 2;
453 
454  headers = http_header_duplicate(e->u.Po_Push_Req.push_headers);
455 
456  } else if (e->type == Po_ConfirmedPush_Req) {
457  trusted = e->u.Po_ConfirmedPush_Req.trusted << 1;
458  authenticated = e->u.Po_ConfirmedPush_Req.authenticated;
459  last = e->u.Po_ConfirmedPush_Req.last << 2;
460 
461  headers = http_header_duplicate(
462  e->u.Po_ConfirmedPush_Req.push_headers);
463 
464  } else {
465  debug("wap.ota", 0, "OTA: no push flag when the event is: \n");
466  wap_event_dump(e);
467  return NULL;
468  }
469 
470  push_flag = 0;
471  push_flag = push_flag | authenticated | trusted | last;
472 
473  if (push_flag) {
474  buf = octstr_format("%d", push_flag);
475  http_header_add(headers, "Push-Flag", octstr_get_cstr(buf));
476  octstr_destroy(buf);
477  }
478 
479  return headers;
480 }
void http_header_add(List *headers, char *name, char *contents)
Definition: http.c:2886
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void wap_event_dump(WAPEvent *event)
Definition: wap_events.c:181
static void flags_assert(WAPEvent *e)
Definition: wap_push_ota.c:482
Octstr * octstr_format(const char *fmt,...)
Definition: octstr.c:2464
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
WAPEventName type
Definition: wap_events.h:88
List * http_header_duplicate(List *headers)
Definition: http.c:2969
union WAPEvent::@87 u
Definition: list.c:102

◆ bearerbox_address_create()

static BearerboxAddress * bearerbox_address_create ( void  )
static

Definition at line 634 of file wap_push_ota.c.

References BearerboxAddress::address, BearerboxAddress::mutex, and mutex_create.

Referenced by wap_push_ota_init().

635 {
636  BearerboxAddress *ba;
637 
638  ba = gw_malloc(sizeof(BearerboxAddress));
639  ba->mutex = mutex_create();
640  ba->address = NULL;
641 
642  return ba;
643 }
#define mutex_create()
Definition: thread.h:96

◆ bearerbox_address_destroy()

static void bearerbox_address_destroy ( BearerboxAddress ba)
static

Definition at line 645 of file wap_push_ota.c.

References BearerboxAddress::address, BearerboxAddress::mutex, mutex_destroy(), and octstr_destroy().

Referenced by wap_push_ota_shutdown().

646 {
647  if (ba == NULL)
648  return;
649 
650  octstr_destroy(ba->address);
651  mutex_destroy(ba->mutex);
652  gw_free(ba);
653 }
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
void mutex_destroy(Mutex *mutex)
Definition: thread.c:97

◆ check_session_request_headers()

static void check_session_request_headers ( List headers)
static

Definition at line 526 of file wap_push_ota.c.

References http_header_add(), and http_type_accepted().

Referenced by make_session_request().

527 {
528  if (!http_type_accepted(headers, "application/wnd.wap.sia"))
529  http_header_add(headers, "Content-Type", "application/vnd.wap.sia");
530 }
void http_header_add(List *headers, char *name, char *contents)
Definition: http.c:2886
int http_type_accepted(List *headers, char *type)
Definition: http.c:3503

◆ flags_assert()

static void flags_assert ( WAPEvent e)
static

Definition at line 482 of file wap_push_ota.c.

References gw_assert(), WAPEvent::type, and WAPEvent::u.

Referenced by add_push_flag().

483 {
484  if (e->type == Po_Unit_Push_Req) {
485  gw_assert(e->u.Po_Unit_Push_Req.trusted == 0 ||
486  e->u.Po_Unit_Push_Req.trusted == 1);
487  gw_assert(e->u.Po_Unit_Push_Req.authenticated == 0 ||
488  e->u.Po_Unit_Push_Req.authenticated == 1);
489  gw_assert(e->u.Po_Unit_Push_Req.last == 0 ||
490  e->u.Po_Unit_Push_Req.last == 1);
491 
492  } else if (e->type == Po_Push_Req) {
493  gw_assert(e->u.Po_Push_Req.trusted == 0 ||
494  e->u.Po_Push_Req.trusted == 1);
495  gw_assert(e->u.Po_Push_Req.authenticated == 0 ||
496  e->u.Po_Push_Req.authenticated == 1);
497  gw_assert(e->u.Po_Push_Req.last == 0 ||
498  e->u.Po_Push_Req.last == 1);
499 
500  } else if (e->type == Po_ConfirmedPush_Req) {
501  gw_assert(e->u.Po_ConfirmedPush_Req.trusted == 0 ||
502  e->u.Po_ConfirmedPush_Req.trusted == 1);
503  gw_assert(e->u.Po_ConfirmedPush_Req.authenticated == 0 ||
504  e->u.Po_ConfirmedPush_Req.authenticated == 1);
505  gw_assert(e->u.Po_ConfirmedPush_Req.last == 0 ||
506  e->u.Po_ConfirmedPush_Req.last == 1);
507  }
508 }
gw_assert(wtls_machine->packet_to_send !=NULL)
WAPEventName type
Definition: wap_events.h:88
union WAPEvent::@87 u

◆ handle_ota_event()

static void handle_ota_event ( WAPEvent e)
static

Definition at line 227 of file wap_push_ota.c.

References abort_push(), debug(), make_confirmed_push_request(), make_push_request(), make_session_request(), make_unit_push_request(), WAPEvent::type, wap_event_destroy(), and wap_event_dump().

Referenced by main_thread().

228 {
229  debug("wap.push.ota", 0, "OTA: event arrived");
230 
231  switch (e->type) {
232  case Pom_SessionRequest_Req:
234  break;
235 
236  case Po_Push_Req:
238  break;
239 
240  case Po_ConfirmedPush_Req:
242  break;
243 
244  case Po_Unit_Push_Req:
246  break;
247 
248  case Po_PushAbort_Req:
249  abort_push(e);
250  break;
251 
252  default:
253  debug("wap.push.ota", 0, "OTA: unhandled event");
254  wap_event_dump(e);
255  break;
256  }
257 
259 }
static void make_push_request(WAPEvent *e)
Definition: wap_push_ota.c:309
static void abort_push(WAPEvent *e)
Definition: wap_push_ota.c:408
static void make_unit_push_request(WAPEvent *e)
Definition: wap_push_ota.c:355
static void make_session_request(WAPEvent *e)
Definition: wap_push_ota.c:261
void wap_event_dump(WAPEvent *event)
Definition: wap_events.c:181
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
WAPEventName type
Definition: wap_events.h:88
static void make_confirmed_push_request(WAPEvent *e)
Definition: wap_push_ota.c:329
void wap_event_destroy(WAPEvent *event)
Definition: wap_events.c:102

◆ main_thread()

static void main_thread ( void *  arg)
static

Definition at line 217 of file wap_push_ota.c.

References gwlist_consume(), handle_ota_event(), ota_queue, run_status, and running.

Referenced by wap_push_ota_init(), and wap_push_ota_shutdown().

218 {
219  WAPEvent *e;
220 
221  while (run_status == running && (e = gwlist_consume(ota_queue)) != NULL) {
222  handle_ota_event(e);
223  }
224 
225 }
static enum @32 run_status
static void handle_ota_event(WAPEvent *e)
Definition: wap_push_ota.c:227
static List * ota_queue
Definition: wap_push_ota.c:114
void * gwlist_consume(List *list)
Definition: list.c:427

◆ make_confirmed_push_request()

static void make_confirmed_push_request ( WAPEvent e)
static

Definition at line 329 of file wap_push_ota.c.

References add_push_flag(), debug(), dispatch_to_wsp, gw_assert(), octstr_duplicate, WAPEvent::type, WAPEvent::u, and wap_event_create.

Referenced by handle_ota_event().

330 {
331  WAPEvent *wsp_event;
332  List *push_headers;
333 
334  gw_assert(e->type == Po_ConfirmedPush_Req);
335  push_headers = add_push_flag(e);
336 
337  wsp_event = wap_event_create(S_ConfirmedPush_Req);
338  wsp_event->u.S_ConfirmedPush_Req.server_push_id =
339  e->u.Po_ConfirmedPush_Req.server_push_id;
340  wsp_event->u.S_ConfirmedPush_Req.push_headers = push_headers;
341 
342  if (e->u.Po_ConfirmedPush_Req.push_body != NULL)
343  wsp_event->u.S_ConfirmedPush_Req.push_body =
344  octstr_duplicate(e->u.Po_ConfirmedPush_Req.push_body);
345  else
346  wsp_event->u.S_ConfirmedPush_Req.push_body = NULL;
347 
348  wsp_event->u.S_ConfirmedPush_Req.session_id =
349  e->u.Po_ConfirmedPush_Req.session_handle;
350  debug("wap.push.ota", 0, "OTA: making confirmed push request to wsp");
351 
352  dispatch_to_wsp(wsp_event);
353 }
gw_assert(wtls_machine->packet_to_send !=NULL)
static wap_dispatch_func_t * dispatch_to_wsp
Definition: wap_push_ota.c:116
static List * add_push_flag(WAPEvent *e)
Definition: wap_push_ota.c:430
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define wap_event_create(type)
Definition: wap_events.h:107
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
WAPEventName type
Definition: wap_events.h:88
union WAPEvent::@87 u
Definition: list.c:102

◆ make_push_request()

static void make_push_request ( WAPEvent e)
static

Definition at line 309 of file wap_push_ota.c.

References add_push_flag(), dispatch_to_wsp, gw_assert(), octstr_duplicate, WAPEvent::type, WAPEvent::u, and wap_event_create.

Referenced by handle_ota_event().

310 {
311  WAPEvent *wsp_event;
312  List *push_headers;
313 
314  gw_assert(e->type == Po_Push_Req);
315  push_headers = add_push_flag(e);
316 
317  wsp_event = wap_event_create(S_Push_Req);
318  wsp_event->u.S_Push_Req.push_headers = push_headers;
319  if (e->u.Po_Push_Req.push_body != NULL)
320  wsp_event->u.S_Push_Req.push_body =
321  octstr_duplicate(e->u.Po_Push_Req.push_body);
322  else
323  wsp_event->u.S_Push_Req.push_body = NULL;
324  wsp_event->u.S_Push_Req.session_id = e->u.Po_Push_Req.session_handle;
325 
326  dispatch_to_wsp(wsp_event);
327 }
gw_assert(wtls_machine->packet_to_send !=NULL)
static wap_dispatch_func_t * dispatch_to_wsp
Definition: wap_push_ota.c:116
static List * add_push_flag(WAPEvent *e)
Definition: wap_push_ota.c:430
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define wap_event_create(type)
Definition: wap_events.h:107
WAPEventName type
Definition: wap_events.h:88
union WAPEvent::@87 u
Definition: list.c:102

◆ make_session_request()

static void make_session_request ( WAPEvent e)
static

Definition at line 261 of file wap_push_ota.c.

References check_session_request_headers(), debug(), dispatch_to_wsp_unit, gw_assert(), http_header_duplicate(), http_header_find_all(), octstr_duplicate, pack_sia(), WAPEvent::type, WAPEvent::u, wap_addr_tuple_duplicate(), and wap_event_create.

Referenced by handle_ota_event().

262 {
263  WAPEvent *wsp_event;
264  List *appid_headers, *push_headers;
265 
266  gw_assert(e->type == Pom_SessionRequest_Req);
267  push_headers = e->u.Pom_SessionRequest_Req.push_headers;
268 
269  check_session_request_headers(push_headers);
270 
271  wsp_event = wap_event_create(S_Unit_Push_Req);
272  wsp_event->u.S_Unit_Push_Req.address_type =
273  e->u.Pom_SessionRequest_Req.address_type;
274  if (e->u.Pom_SessionRequest_Req.smsc_id != NULL)
275  wsp_event->u.S_Unit_Push_Req.smsc_id =
276  octstr_duplicate(e->u.Pom_SessionRequest_Req.smsc_id);
277  else
278  wsp_event->u.S_Unit_Push_Req.smsc_id = NULL;
279  if (e->u.Pom_SessionRequest_Req.dlr_url != NULL)
280  wsp_event->u.S_Unit_Push_Req.dlr_url =
281  octstr_duplicate(e->u.Pom_SessionRequest_Req.dlr_url);
282  else
283  wsp_event->u.S_Unit_Push_Req.dlr_url = NULL;
284  wsp_event->u.S_Unit_Push_Req.dlr_mask = e->u.Pom_SessionRequest_Req.dlr_mask;
285  if (e->u.Pom_SessionRequest_Req.smsbox_id != NULL)
286  wsp_event->u.S_Unit_Push_Req.smsbox_id =
287  octstr_duplicate(e->u.Pom_SessionRequest_Req.smsbox_id);
288  else
289  wsp_event->u.S_Unit_Push_Req.smsbox_id = NULL;
290  wsp_event->u.S_Unit_Push_Req.service_name =
291  octstr_duplicate(e->u.Pom_SessionRequest_Req.service_name);
292 
293  wsp_event->u.S_Unit_Push_Req.push_id =
294  e->u.Pom_SessionRequest_Req.push_id;
295  wsp_event->u.S_Unit_Push_Req.addr_tuple =
296  wap_addr_tuple_duplicate(e->u.Pom_SessionRequest_Req.addr_tuple);
297  wsp_event->u.S_Unit_Push_Req.push_headers =
298  http_header_duplicate(push_headers);
299 
300  appid_headers = http_header_find_all(push_headers, "X-WAP-Application-Id");
301  wsp_event->u.S_Unit_Push_Req.push_body = pack_sia(appid_headers);
302 
303  debug("wap.push.ota", 0, "OTA: making a connectionless session request for"
304  " creating a session");
305 
306  dispatch_to_wsp_unit(wsp_event);
307 }
List * http_header_find_all(List *headers, char *name)
Definition: http.c:3115
static wap_dispatch_func_t * dispatch_to_wsp_unit
Definition: wap_push_ota.c:117
gw_assert(wtls_machine->packet_to_send !=NULL)
static void check_session_request_headers(List *headers)
Definition: wap_push_ota.c:526
WAPAddrTuple * wap_addr_tuple_duplicate(WAPAddrTuple *tuple)
Definition: wap_addr.c:125
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define wap_event_create(type)
Definition: wap_events.h:107
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
WAPEventName type
Definition: wap_events.h:88
List * http_header_duplicate(List *headers)
Definition: http.c:2969
union WAPEvent::@87 u
Definition: list.c:102
static Octstr * pack_sia(List *headers)
Definition: wap_push_ota.c:536

◆ make_unit_push_request()

static void make_unit_push_request ( WAPEvent e)
static

Definition at line 355 of file wap_push_ota.c.

References add_push_flag(), debug(), dispatch_to_wsp_unit, dlr_url, gw_assert(), octstr_duplicate, service_name, smsbox_id, smsc_id, WAPEvent::type, WAPEvent::u, wap_addr_tuple_duplicate(), and wap_event_create.

Referenced by handle_ota_event().

356 {
357  WAPEvent *wsp_event;
358  List *push_headers;
359  Octstr *smsc_id;
360  Octstr *dlr_url;
361  Octstr *smsbox_id;
362  Octstr *push_body;
364 
365  gw_assert(e->type == Po_Unit_Push_Req);
366  gw_assert(e->u.Po_Unit_Push_Req.addr_tuple);
367  gw_assert(e->u.Po_Unit_Push_Req.service_name);
368 
369  smsc_id = octstr_duplicate(e->u.Po_Unit_Push_Req.smsc_id);
370  dlr_url = octstr_duplicate(e->u.Po_Unit_Push_Req.dlr_url);
371  smsbox_id = octstr_duplicate(e->u.Po_Unit_Push_Req.smsbox_id);
372  push_body = octstr_duplicate(e->u.Po_Unit_Push_Req.push_body);
373  service_name = octstr_duplicate(e->u.Po_Unit_Push_Req.service_name);
374  push_headers = add_push_flag(e);
375 
376  wsp_event = wap_event_create(S_Unit_Push_Req);
377  wsp_event->u.S_Unit_Push_Req.addr_tuple =
378  wap_addr_tuple_duplicate(e->u.Po_Unit_Push_Req.addr_tuple);
379  wsp_event->u.S_Unit_Push_Req.push_id = e->u.Po_Unit_Push_Req.push_id;
380  wsp_event->u.S_Unit_Push_Req.push_headers = push_headers;
381 
382  wsp_event->u.S_Unit_Push_Req.address_type =
383  e->u.Po_Unit_Push_Req.address_type;
384  if (smsc_id != NULL)
385  wsp_event->u.S_Unit_Push_Req.smsc_id = smsc_id;
386  else
387  wsp_event->u.S_Unit_Push_Req.smsc_id = NULL;
388  if (dlr_url != NULL)
389  wsp_event->u.S_Unit_Push_Req.dlr_url = dlr_url;
390  else
391  wsp_event->u.S_Unit_Push_Req.dlr_url = NULL;
392  wsp_event->u.S_Unit_Push_Req.dlr_mask = e->u.Po_Unit_Push_Req.dlr_mask;
393  if (smsbox_id != NULL)
394  wsp_event->u.S_Unit_Push_Req.smsbox_id = smsbox_id;
395  else
396  wsp_event->u.S_Unit_Push_Req.smsbox_id = NULL;
397  wsp_event->u.S_Unit_Push_Req.service_name = service_name;
398  if (push_body != NULL)
399  wsp_event->u.S_Unit_Push_Req.push_body = push_body;
400  else
401  wsp_event->u.S_Unit_Push_Req.push_body = NULL;
402 
403  dispatch_to_wsp_unit(wsp_event);
404  debug("wap.push.ota", 0, "OTA: made connectionless session service"
405  " request");
406 }
static Octstr * service_name
Definition: wap_push_ppg.c:205
static wap_dispatch_func_t * dispatch_to_wsp_unit
Definition: wap_push_ota.c:117
gw_assert(wtls_machine->packet_to_send !=NULL)
static List * add_push_flag(WAPEvent *e)
Definition: wap_push_ota.c:430
static Octstr * smsbox_id
Definition: smsbox.c:120
WAPAddrTuple * wap_addr_tuple_duplicate(WAPAddrTuple *tuple)
Definition: wap_addr.c:125
static Octstr * dlr_url
Definition: test_ppg.c:107
#define octstr_duplicate(ostr)
Definition: octstr.h:187
static Octstr * smsc_id
Definition: mtbatch.c:98
#define wap_event_create(type)
Definition: wap_events.h:107
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
WAPEventName type
Definition: wap_events.h:88
union WAPEvent::@87 u
Definition: list.c:102

◆ name()

static Octstr* name ( Octstr os)
static

Definition at line 626 of file wap_push_ota.c.

References get_official_ip(), octstr_compare(), octstr_duplicate, and octstr_imm().

Referenced by wap_push_ota_bb_address_set().

627 {
628  if (octstr_compare(in, octstr_imm("localhost")) != 0)
629  return octstr_duplicate(in);
630  else
632 }
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Octstr * get_official_ip(void)
Definition: socket.c:634
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ pack_appid_list()

static Octstr * pack_appid_list ( List headers)
static

Definition at line 563 of file wap_push_ota.c.

References gw_assert(), gwlist_len(), http_header_get(), octstr_compare(), octstr_create, octstr_destroy(), octstr_format_append(), and octstr_imm().

Referenced by pack_sia().

564 {
565  Octstr *appid_os,
566  *header_name,
567  *header_value;
568  long i;
569  size_t len;
570 
571  i = 0;
572  appid_os = octstr_create("");
573  len = (size_t) gwlist_len(headers);
574 
575  gw_assert(len);
576 
577  while (i < len) {
578  http_header_get(headers, i, &header_name, &header_value);
579  gw_assert(octstr_compare(header_name,
580  octstr_imm("X-WAP-Application-Id")) == 0);
581  octstr_format_append(appid_os, "%S", header_value);
582  octstr_destroy(header_name);
583  octstr_destroy(header_value);
584  ++i;
585  }
586 
587  return appid_os;
588 }
void http_header_get(List *headers, long i, Octstr **name, Octstr **value)
Definition: http.c:2902
gw_assert(wtls_machine->packet_to_send !=NULL)
long gwlist_len(List *list)
Definition: list.c:166
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:283
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
Definition: octstr.c:118
void octstr_format_append(Octstr *os, const char *fmt,...)
Definition: octstr.c:2507
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ pack_server_address()

static Octstr * pack_server_address ( void  )
static

Definition at line 594 of file wap_push_ota.c.

References BearerboxAddress::address, bearerbox, CONNECTED_PORT, GSM_CSD_IPV4, BearerboxAddress::mutex, mutex_lock, mutex_unlock, octstr_append(), octstr_append_char(), octstr_append_decimal(), octstr_create, octstr_destroy(), octstr_duplicate, octstr_len(), octstr_set_bits(), and port.

Referenced by pack_sia().

595 {
596  Octstr *address,
597  *ip_address;
598  unsigned char address_len;
599  long port;
600  int bearer_type;
601 
602  bearer_type = GSM_CSD_IPV4;
604 
606  ip_address = octstr_duplicate(bearerbox->address);
607  address_len = octstr_len(bearerbox->address);
609 
610  address = octstr_create("");
611  octstr_append_char(address, address_len);
612  octstr_set_bits(address, 0, 1, 1); /* bearer type included */
613  octstr_set_bits(address, 1, 1, 1); /* port number included */
614  octstr_append_char(address, bearer_type);
615  octstr_append_decimal(address, port);
616  octstr_append(address, ip_address);
617  octstr_destroy(ip_address);
618 
619  return address;
620 }
Definition: http.c:2014
#define mutex_unlock(m)
Definition: thread.h:136
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1504
void octstr_set_bits(Octstr *ostr, long bitpos, int numbits, unsigned long value)
Definition: octstr.c:1849
void octstr_append_char(Octstr *ostr, int ch)
Definition: octstr.c:1517
static int port
Definition: fakesmsc.c:121
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
#define octstr_create(cstr)
Definition: octstr.h:125
long octstr_len(const Octstr *ostr)
Definition: octstr.c:342
static BearerboxAddress * bearerbox
Definition: wap_push_ota.c:112
void octstr_append_decimal(Octstr *ostr, long value)
Definition: octstr.c:1976
Definition: octstr.c:118
#define CONNECTED_PORT
Definition: wap_push_ota.h:70
#define mutex_lock(m)
Definition: thread.h:130

◆ pack_sia()

static Octstr * pack_sia ( List headers)
static

Definition at line 536 of file wap_push_ota.c.

References CURRENT_VERSION, http_destroy_headers(), pack_appid_list(), pack_server_address(), wsp_pdu::u, wsp_pdu_create(), wsp_pdu_destroy(), and wsp_pdu_pack().

Referenced by make_session_request().

537 {
538  Octstr *sia_content;
539  WSP_PDU *pdu;
540 
541  pdu = wsp_pdu_create(sia);
542 
543  pdu->u.sia.version = CURRENT_VERSION;
544  pdu->u.sia.application_id_list = pack_appid_list(headers);
545  pdu->u.sia.contactpoints = pack_server_address();
546  sia_content = wsp_pdu_pack(pdu);
547 
548  wsp_pdu_destroy(pdu);
549  http_destroy_headers(headers);
550 
551  return sia_content;
552 }
static Octstr * pack_appid_list(List *headers)
Definition: wap_push_ota.c:563
union wsp_pdu::@89 u
Octstr * wsp_pdu_pack(WSP_PDU *pdu)
Definition: wsp_pdu.c:271
void http_destroy_headers(List *headers)
Definition: http.c:2879
WSP_PDU * wsp_pdu_create(int type)
Definition: wsp_pdu.c:68
static Octstr * pack_server_address(void)
Definition: wap_push_ota.c:594
void wsp_pdu_destroy(WSP_PDU *pdu)
Definition: wsp_pdu.c:102
Definition: octstr.c:118
#define CURRENT_VERSION
Definition: wap_push_ota.h:69

◆ reason_assert()

static void reason_assert ( long  reason)
static

Definition at line 513 of file wap_push_ota.c.

References gw_assert(), WSP_ABORT_USERDCR, WSP_ABORT_USERDCU, WSP_ABORT_USERPND, WSP_ABORT_USERREQ, and WSP_ABORT_USERRFS.

Referenced by abort_push().

514 {
515  gw_assert(reason == WSP_ABORT_USERREQ || reason == WSP_ABORT_USERRFS ||
516  reason == WSP_ABORT_USERPND || reason == WSP_ABORT_USERDCR ||
517  reason == WSP_ABORT_USERDCU);
518 }
gw_assert(wtls_machine->packet_to_send !=NULL)

◆ wap_push_ota_bb_address_set()

void wap_push_ota_bb_address_set ( Octstr in)

Definition at line 203 of file wap_push_ota.c.

References BearerboxAddress::address, bearerbox, gw_assert(), BearerboxAddress::mutex, mutex_lock, mutex_unlock, and name().

Referenced by main().

204 {
205  gw_assert(in);
206 
208  bearerbox->address = name(in);
210 }
gw_assert(wtls_machine->packet_to_send !=NULL)
#define mutex_unlock(m)
Definition: thread.h:136
static Octstr * name(Octstr *os)
Definition: wap_push_ota.c:626
static BearerboxAddress * bearerbox
Definition: wap_push_ota.c:112
#define mutex_lock(m)
Definition: thread.h:130

◆ wap_push_ota_dispatch_event()

void wap_push_ota_dispatch_event ( WAPEvent e)

Definition at line 193 of file wap_push_ota.c.

References gw_assert(), gwlist_produce(), ota_queue, run_status, and running.

Referenced by main().

194 {
197 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void gwlist_produce(List *list, void *item)
Definition: list.c:411
static enum @32 run_status
static List * ota_queue
Definition: wap_push_ota.c:114

◆ wap_push_ota_init()

void wap_push_ota_init ( wap_dispatch_func_t wsp_dispatch,
wap_dispatch_func_t wsp_unit_dispatch 
)

Definition at line 166 of file wap_push_ota.c.

References bearerbox, bearerbox_address_create(), dispatch_to_wsp, dispatch_to_wsp_unit, gw_assert(), gwlist_add_producer(), gwlist_create, gwthread_create, limbo, main_thread(), ota_queue, run_status, and running.

Referenced by main().

168 {
171 
172  dispatch_to_wsp = wsp_dispatch;
173  dispatch_to_wsp_unit = wsp_unit_dispatch;
174 
176 
180 }
static wap_dispatch_func_t * dispatch_to_wsp_unit
Definition: wap_push_ota.c:117
gw_assert(wtls_machine->packet_to_send !=NULL)
static wap_dispatch_func_t * dispatch_to_wsp
Definition: wap_push_ota.c:116
static enum @32 run_status
static BearerboxAddress * bearerbox_address_create(void)
Definition: wap_push_ota.c:634
#define gwthread_create(func, arg)
Definition: gwthread.h:90
static List * ota_queue
Definition: wap_push_ota.c:114
static BearerboxAddress * bearerbox
Definition: wap_push_ota.c:112
#define gwlist_create()
Definition: list.h:136
static void main_thread(void *arg)
Definition: wap_push_ota.c:217
void gwlist_add_producer(List *list)
Definition: list.c:383

◆ wap_push_ota_shutdown()

void wap_push_ota_shutdown ( void  )

Definition at line 182 of file wap_push_ota.c.

References bearerbox, bearerbox_address_destroy(), gw_assert(), gwlist_destroy(), gwlist_remove_producer(), gwthread_join_every(), main_thread(), ota_queue, run_status, running, terminating, and wap_event_destroy_item().

Referenced by main().

183 {
188 
191 }
gw_assert(wtls_machine->packet_to_send !=NULL)
static enum @32 run_status
void gwthread_join_every(gwthread_func_t *func)
void gwlist_remove_producer(List *list)
Definition: list.c:401
void wap_event_destroy_item(void *event)
Definition: wap_events.c:130
static void bearerbox_address_destroy(BearerboxAddress *ba)
Definition: wap_push_ota.c:645
static List * ota_queue
Definition: wap_push_ota.c:114
static BearerboxAddress * bearerbox
Definition: wap_push_ota.c:112
static void main_thread(void *arg)
Definition: wap_push_ota.c:217
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

Variable Documentation

◆ bearerbox

◆ dispatch_to_wsp

wap_dispatch_func_t* dispatch_to_wsp
static

◆ dispatch_to_wsp_unit

wap_dispatch_func_t* dispatch_to_wsp_unit
static

Definition at line 117 of file wap_push_ota.c.

Referenced by make_session_request(), make_unit_push_request(), and wap_push_ota_init().

◆ ota_queue

List* ota_queue = NULL
static

◆ run_status

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.