Kannel: Open Source WAP and SMS gateway  svn-r5335
wsp_push_client.c File Reference
#include "wsp_push_client.h"
#include "wsp.h"
#include "wtp.h"
#include "wsp_pdu.h"
#include "wsp_headers.h"
#include "wap.h"
#include "wsp_push_client_states.def"
#include "wsp_push_client_machine.def"

Go to the source code of this file.

Macros

#define PUSH_CLIENT_STATE_NAME(state)   case state : return (unsigned char *)#state;
 
#define ROW(state, event, condition, action, new_state)
 
#define PUSH_CLIENT_STATE_NAME(state)
 
#define ROW(push_state, event_type, condition, action, next_state)
 
#define INTEGER(name)   m->name = 0;
 
#define HTTPHEADERS(name)   m->name = NULL;
 
#define MACHINE(fields)   fields
 
#define INTEGER(name)   m->name = 0;
 
#define HTTPHEADERS(name)   http_destroy_headers(m->name);
 
#define MACHINE(fields)   fields;
 

Enumerations

enum  { limbo, running, terminating }
 

Functions

static WSPPushClientMachinepush_client_machine_create (long cpid)
 
static void push_client_machine_destroy (void *a)
 
static WSPPushClientMachinepush_client_machine_find_or_create (WAPEvent *e)
 
static void push_client_event_handle (WSPPushClientMachine *cpm, WAPEvent *e)
 
static unsigned char * name_push_client_state (int name)
 
static void main_thread (void *)
 
static WAPEventindicate_confirmedpush (WSPPushClientMachine *cpm, Octstr *push_body)
 
static WAPEventindicate_pushabort (WSPPushClientMachine *cpm, long abort_reason)
 
static WAPEventresponse_confirmedpush (WSPPushClientMachine *cpm)
 
static WAPEventsend_abort_to_responder (WSPPushClientMachine *cpm, long reason)
 
static WAPEventresponse_responder_invoke (WSPPushClientMachine *cpm)
 
void wsp_push_client_init (wap_dispatch_func_t *dispatch_self, wap_dispatch_func_t *dispatch_wtp_resp)
 
void wsp_push_client_shutdown (void)
 
void wsp_push_client_dispatch_event (WAPEvent *e)
 
static int push_client_machine_has_transid (void *a, void *b)
 
static WSPPushClientMachinepush_client_machine_find_using_transid (long transid)
 

Variables

static Listpush_client_machines = NULL
 
static Counterpush_client_machine_id_counter = NULL
 
static enum { ... }  push_client_run_status = limbo
 
static Listpush_client_queue = NULL
 
wap_dispatch_func_tdispatch_to_self
 
wap_dispatch_func_tdispatch_to_wtp_resp
 

Macro Definition Documentation

◆ HTTPHEADERS [1/2]

#define HTTPHEADERS (   name)    m->name = NULL;

◆ HTTPHEADERS [2/2]

#define HTTPHEADERS (   name)    http_destroy_headers(m->name);

◆ INTEGER [1/2]

#define INTEGER (   name)    m->name = 0;

◆ INTEGER [2/2]

#define INTEGER (   name)    m->name = 0;

◆ MACHINE [1/2]

#define MACHINE (   fields)    fields

◆ MACHINE [2/2]

#define MACHINE (   fields)    fields;

◆ PUSH_CLIENT_STATE_NAME [1/2]

#define PUSH_CLIENT_STATE_NAME (   state)    case state : return (unsigned char *)#state;

◆ PUSH_CLIENT_STATE_NAME [2/2]

#define PUSH_CLIENT_STATE_NAME (   state)

◆ ROW [1/2]

#define ROW (   state,
  event,
  condition,
  action,
  new_state 
)

◆ ROW [2/2]

#define ROW (   push_state,
  event_type,
  condition,
  action,
  next_state 
)
Value:
if (cpm->state == push_state && \
e->type == event_type && \
(condition)) { \
action \
cpm->state = next_state; \
debug("wap.wsp", 0, "WSP_PUSH %ld: new state %s", \
cpm->client_push_id, #next_state); \
} else

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
limbo 
running 
terminating 

Definition at line 94 of file wsp_push_client.c.

Function Documentation

◆ indicate_confirmedpush()

static WAPEvent * indicate_confirmedpush ( WSPPushClientMachine cpm,
Octstr push_body 
)
static

Definition at line 416 of file wsp_push_client.c.

References http_header_duplicate(), octstr_duplicate, WAPEvent::u, and wap_event_create.

418 {
419  WAPEvent *e;
420 
421  e = wap_event_create(S_ConfirmedPush_Ind);
422  e->u.S_ConfirmedPush_Ind.client_push_id = cpm->client_push_id;
423  e->u.S_ConfirmedPush_Ind.push_headers =
424  http_header_duplicate(cpm->push_headers);
425  e->u.S_ConfirmedPush_Ind.push_body = octstr_duplicate(push_body);
426 
427  return e;
428 }
#define octstr_duplicate(ostr)
Definition: octstr.h:187
#define wap_event_create(type)
Definition: wap_events.h:107
List * http_header_duplicate(List *headers)
Definition: http.c:2969
union WAPEvent::@87 u

◆ indicate_pushabort()

static WAPEvent * indicate_pushabort ( WSPPushClientMachine cpm,
long  abort_reason 
)
static

Definition at line 430 of file wsp_push_client.c.

References WAPEvent::u, and wap_event_create.

432 {
433  WAPEvent *e;
434 
435  e = wap_event_create(S_PushAbort_Ind);
436  e->u.S_PushAbort_Ind.push_id = cpm->client_push_id;
437  e->u.S_PushAbort_Ind.reason = abort_reason;
438 
439  return e;
440 }
#define wap_event_create(type)
Definition: wap_events.h:107
union WAPEvent::@87 u

◆ main_thread()

static void main_thread ( void *  arg)
static

Definition at line 188 of file wsp_push_client.c.

References gwlist_consume(), push_client_event_handle(), push_client_machine_find_or_create(), push_client_queue, push_client_run_status, running, and wap_event_destroy().

Referenced by wsp_push_client_init(), and wsp_push_client_shutdown().

189 {
191  WAPEvent *e;
192 
193  while (push_client_run_status == running &&
194  (e = gwlist_consume(push_client_queue)) != NULL) {
196  if (cpm == NULL)
198  else
199  push_client_event_handle(cpm, e);
200  }
201 }
static List * push_client_queue
void * gwlist_consume(List *list)
Definition: list.c:427
static void push_client_event_handle(WSPPushClientMachine *cpm, WAPEvent *e)
static WSPPushClientMachine * push_client_machine_find_or_create(WAPEvent *e)
static enum @90 push_client_run_status
void wap_event_destroy(WAPEvent *event)
Definition: wap_events.c:102

◆ name_push_client_state()

static unsigned char * name_push_client_state ( int  name)
static

Definition at line 206 of file wsp_push_client.c.

Referenced by push_client_event_handle().

206  {
207 
208  switch (n) {
209  #define PUSH_CLIENT_STATE_NAME(state) case state : return (unsigned char *)#state;
210  #define ROW(state, event, condition, action, new_state)
211  #include "wsp_push_client_states.def"
212  default:
213  return (unsigned char *)"unknown state";
214  }
215 }

◆ push_client_event_handle()

static void push_client_event_handle ( WSPPushClientMachine cpm,
WAPEvent e 
)
static

Definition at line 221 of file wsp_push_client.c.

References debug(), error(), gw_assert(), name_push_client_state(), PROTOERR, push_client_machine_destroy(), send_abort_to_responder(), wsp_pdu::type, WAPEvent::type, WAPEvent::u, wap_event_assert(), wap_event_destroy(), wap_event_dump(), wap_event_name(), wsp_pdu_destroy(), wsp_pdu_unpack(), and wtp_resp_dispatch_event().

Referenced by main_thread().

223 {
224  WAPEvent *wtp_event;
225  WSP_PDU *pdu = NULL;
226 
227  wap_event_assert(e);
228  gw_assert(cpm);
229 
230  if (e->type == TR_Invoke_Ind) {
231  pdu = wsp_pdu_unpack(e->u.TR_Invoke_Ind.user_data);
232 /*
233  * Class 1 tests here
234  * Case 4, no session matching address quadruplet, handled by the session mach-
235  * ine.
236  * Tests from table WSP, page 45. Case 5, a PDU state tables cannot handle.
237  */
238  if (pdu == NULL || pdu->type != ConfirmedPush) {
240  wtp_event = send_abort_to_responder(cpm, PROTOERR);
241  wtp_resp_dispatch_event(wtp_event);
242  return;
243  }
244  }
245 
246  debug("wap.wsp", 0, "WSP_PUSH: WSPPushClientMachine %ld, state %s,"
247  " event %s",
248  cpm->client_push_id,
249  name_push_client_state(cpm->state),
250  wap_event_name(e->type));
251  #define PUSH_CLIENT_STATE_NAME(state)
252  #define ROW(push_state, event_type, condition, action, next_state) \
253  if (cpm->state == push_state && \
254  e->type == event_type && \
255  (condition)) { \
256  action \
257  cpm->state = next_state; \
258  debug("wap.wsp", 0, "WSP_PUSH %ld: new state %s", \
259  cpm->client_push_id, #next_state); \
260  } else
261  #include "wsp_push_client_states.def"
262  {
263  error(0, "WSP_PUSH: handle_event: unhandled event!");
264  debug("wap.wsp", 0, "Unhandled event was:");
265  wap_event_dump(e);
267  return;
268  }
269 
270  wsp_pdu_destroy(pdu);
272 
273  if (cpm->state == PUSH_CLIENT_NULL_STATE)
275 }
void error(int err, const char *fmt,...)
Definition: log.c:648
gw_assert(wtls_machine->packet_to_send !=NULL)
static void push_client_machine_destroy(void *a)
void wap_event_dump(WAPEvent *event)
Definition: wap_events.c:181
static unsigned char * name_push_client_state(int name)
static WAPEvent * send_abort_to_responder(WSPPushClientMachine *cpm, long reason)
void wap_event_assert(WAPEvent *event)
Definition: wap_events.c:220
const char * wap_event_name(WAPEventName type)
Definition: wap_events.c:169
void wsp_pdu_destroy(WSP_PDU *pdu)
Definition: wsp_pdu.c:102
void wtp_resp_dispatch_event(WAPEvent *event)
Definition: wtp_resp.c:253
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
int type
Definition: wsp_pdu.h:87
WAPEventName type
Definition: wap_events.h:88
union WAPEvent::@87 u
WSP_PDU * wsp_pdu_unpack(Octstr *data)
Definition: wsp_pdu.c:178
void wap_event_destroy(WAPEvent *event)
Definition: wap_events.c:102
Definition: wtp.h:133

◆ push_client_machine_create()

static WSPPushClientMachine * push_client_machine_create ( long  cpid)
static

Definition at line 377 of file wsp_push_client.c.

References counter_increase(), debug(), gwlist_append(), push_client_machine_id_counter, and push_client_machines.

Referenced by push_client_machine_find_or_create().

378 {
380 
381  m = gw_malloc(sizeof(WSPPushClientMachine));
382  debug("wap.wsp", 0, "WSP_PUSH_CLIENT: Created WSPPushClientMachine %p",
383  (void *) m);
384 
385  #define INTEGER(name) m->name = 0;
386  #define HTTPHEADERS(name) m->name = NULL;
387  #define MACHINE(fields) fields
388  #include "wsp_push_client_machine.def"
389 
390  m->state = PUSH_CLIENT_NULL_STATE;
391  m->transaction_id = transid;
393 
395 
396  return m;
397 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
static Counter * push_client_machine_id_counter
unsigned long counter_increase(Counter *counter)
Definition: counter.c:123
static List * push_client_machines
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726

◆ push_client_machine_destroy()

static void push_client_machine_destroy ( void *  a)
static

Definition at line 399 of file wsp_push_client.c.

References debug(), gwlist_delete_equal(), and push_client_machines.

Referenced by push_client_event_handle(), and wsp_push_client_shutdown().

400 {
402 
403  m = a;
404  debug("wap.wsp", 0, "Destroying WSPPushClientMachine %p", (void *) m);
406 
407  #define INTEGER(name) m->name = 0;
408  #define HTTPHEADERS(name) http_destroy_headers(m->name);
409  #define MACHINE(fields) fields;
410  #include "wsp_push_client_machine.def"
411 
412  gw_free(m);
413 }
long gwlist_delete_equal(List *list, void *item)
Definition: list.c:266
static List * push_client_machines
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726

◆ push_client_machine_find_or_create()

static WSPPushClientMachine * push_client_machine_find_or_create ( WAPEvent e)
static

Definition at line 305 of file wsp_push_client.c.

References debug(), error(), gw_assert(), push_client_machine_create(), push_client_machine_find_using_transid(), WAPEvent::type, WAPEvent::u, wap_event_destroy(), wap_event_dump(), and wap_event_name().

Referenced by main_thread().

306 {
308  long transid;
309 
310  cpm = NULL;
311  transid = -1;
312 
313  switch (e->type) {
314  case TR_Invoke_Ind:
315  transid = e->u.TR_Invoke_Ind.handle;
316  break;
317 
318  case S_ConfirmedPush_Res:
319  transid = e->u.S_ConfirmedPush_Res.client_push_id;
320  break;
321 
322  case S_PushAbort_Req:
323  transid = e->u.S_PushAbort_Req.push_id;
324  break;
325 
326  case Abort_Event:
327  break;
328 
329  case TR_Abort_Ind:
330  transid = e->u.TR_Abort_Ind.handle;
331  break;
332 
333  default:
334  debug("wap.wsp", 0, "WSP PUSH: push_client_find_or_create: unhandled"
335  " event");
336  wap_event_dump(e);
338  return NULL;
339  }
340 
341  gw_assert(transid != -1);
342 
344 
345  if (cpm == NULL) {
346  switch (e->type) {
347  case TR_Invoke_Ind:
348  cpm = push_client_machine_create(transid);
349  break;
350 
351  case S_ConfirmedPush_Res:
352  case S_PushAbort_Req:
353  error(0, "WSP_PUSH_CLIENT: POT primitive to a nonexisting"
354  " push client machine");
355  break;
356 
357  case Abort_Event:
358  error(0, "WSP_PUSH_CLIENT: internal abort to a nonexisting"
359  " push client machine");
360  break;
361 
362  case TR_Abort_Ind:
363  error(0, "WSP_PUSH_CLIENT: WTP abort to a nonexisting push client"
364  " machine");
365  break;
366 
367  default:
368  error(0, "WSP_PUSH_CLIENT: Cannot handle event type %s",
369  wap_event_name(e->type));
370  break;
371  }
372  }
373 
374  return cpm;
375 }
void error(int err, const char *fmt,...)
Definition: log.c:648
gw_assert(wtls_machine->packet_to_send !=NULL)
static WSPPushClientMachine * push_client_machine_create(long cpid)
void wap_event_dump(WAPEvent *event)
Definition: wap_events.c:181
const char * wap_event_name(WAPEventName type)
Definition: wap_events.c:169
static WSPPushClientMachine * push_client_machine_find_using_transid(long transid)
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
void wap_event_destroy(WAPEvent *event)
Definition: wap_events.c:102

◆ push_client_machine_find_using_transid()

static WSPPushClientMachine* push_client_machine_find_using_transid ( long  transid)
static

Definition at line 287 of file wsp_push_client.c.

References gwlist_search(), push_client_machine_has_transid(), and push_client_machines.

Referenced by push_client_machine_find_or_create().

289 {
291 
292  m = gwlist_search(push_client_machines, &transid,
294  return m;
295 }
void * gwlist_search(List *list, void *pattern, int(*cmp)(void *, void *))
Definition: list.c:486
static int push_client_machine_has_transid(void *a, void *b)
static List * push_client_machines

◆ push_client_machine_has_transid()

static int push_client_machine_has_transid ( void *  a,
void *  b 
)
static

Definition at line 277 of file wsp_push_client.c.

Referenced by push_client_machine_find_using_transid().

278 {
279  long transid;
281 
282  m = a;
283  transid = *(long *)b;
284  return m->transaction_id == transid;
285 }

◆ response_confirmedpush()

static WAPEvent * response_confirmedpush ( WSPPushClientMachine cpm)
static

Definition at line 446 of file wsp_push_client.c.

References WAPEvent::u, and wap_event_create.

447 {
448  WAPEvent *e;
449 
450  e = wap_event_create(S_ConfirmedPush_Res);
451  e->u.S_ConfirmedPush_Res.client_push_id = cpm->client_push_id;
452 
453  return e;
454 }
#define wap_event_create(type)
Definition: wap_events.h:107
union WAPEvent::@87 u

◆ response_responder_invoke()

static WAPEvent * response_responder_invoke ( WSPPushClientMachine cpm)
static

Definition at line 470 of file wsp_push_client.c.

References WAPEvent::u, and wap_event_create.

471 {
472  WAPEvent *e;
473 
474  e = wap_event_create(TR_Invoke_Res);
475  e->u.TR_Invoke_Res.handle = cpm->transaction_id;
476 
477  return e;
478 }
#define wap_event_create(type)
Definition: wap_events.h:107
union WAPEvent::@87 u

◆ send_abort_to_responder()

static WAPEvent * send_abort_to_responder ( WSPPushClientMachine cpm,
long  reason 
)
static

Definition at line 456 of file wsp_push_client.c.

References WAPEvent::u, USER, and wap_event_create.

Referenced by push_client_event_handle().

458 {
459  WAPEvent *e;
460 
461  e = wap_event_create(TR_Abort_Req);
462  e->u.TR_Abort_Req.abort_type = USER;
463  e->u.TR_Abort_Req.abort_reason = reason;
464  e->u.TR_Abort_Req.handle = cpm->client_push_id;
465 
466  return e;
467 }
Definition: wtp.h:125
#define wap_event_create(type)
Definition: wap_events.h:107
union WAPEvent::@87 u

◆ wsp_push_client_dispatch_event()

void wsp_push_client_dispatch_event ( WAPEvent e)

Definition at line 177 of file wsp_push_client.c.

References gwlist_produce(), and push_client_queue.

Referenced by main().

178 {
180 }
void gwlist_produce(List *list, void *item)
Definition: list.c:411
static List * push_client_queue

◆ wsp_push_client_init()

void wsp_push_client_init ( wap_dispatch_func_t dispatch_self,
wap_dispatch_func_t dispatch_wtp_resp 
)

Definition at line 145 of file wsp_push_client.c.

References counter_create(), dispatch_to_self, dispatch_to_wtp_resp, gw_assert(), gwlist_add_producer(), gwlist_create, gwthread_create, limbo, main_thread(), push_client_machine_id_counter, push_client_machines, push_client_queue, push_client_run_status, and running.

Referenced by main().

147 {
150 
153 
154  dispatch_to_self = dispatch_self;
155  dispatch_to_wtp_resp = dispatch_wtp_resp;
156 
160 }
gw_assert(wtls_machine->packet_to_send !=NULL)
static Counter * push_client_machine_id_counter
Counter * counter_create(void)
Definition: counter.c:94
#define gwthread_create(func, arg)
Definition: gwthread.h:90
static List * push_client_machines
static void main_thread(void *)
static List * push_client_queue
wap_dispatch_func_t * dispatch_to_self
wap_dispatch_func_t * dispatch_to_wtp_resp
#define gwlist_create()
Definition: list.h:136
void gwlist_add_producer(List *list)
Definition: list.c:383
static enum @90 push_client_run_status

◆ wsp_push_client_shutdown()

void wsp_push_client_shutdown ( void  )

Definition at line 162 of file wsp_push_client.c.

References counter_destroy(), debug(), gw_assert(), gwlist_destroy(), gwlist_len(), gwlist_remove_producer(), gwthread_join_every(), main_thread(), push_client_machine_destroy(), push_client_machine_id_counter, push_client_machines, push_client_queue, push_client_run_status, running, terminating, and wap_event_destroy_item().

Referenced by main().

163 {
168 
169  debug("wap.wsp", 0, "wsp_push_client_shutdown: %ld push client machines"
173 
175 }
gw_assert(wtls_machine->packet_to_send !=NULL)
void counter_destroy(Counter *counter)
Definition: counter.c:110
long gwlist_len(List *list)
Definition: list.c:166
static void push_client_machine_destroy(void *a)
static Counter * push_client_machine_id_counter
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 List * push_client_machines
static void main_thread(void *)
static List * push_client_queue
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
static enum @90 push_client_run_status
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

Variable Documentation

◆ dispatch_to_self

wap_dispatch_func_t* dispatch_to_self

Definition at line 101 of file wsp_push_client.c.

Referenced by wsp_push_client_init().

◆ dispatch_to_wtp_resp

wap_dispatch_func_t* dispatch_to_wtp_resp

Definition at line 102 of file wsp_push_client.c.

Referenced by wsp_push_client_init().

◆ push_client_machine_id_counter

Counter* push_client_machine_id_counter = NULL
static

◆ push_client_machines

◆ push_client_queue

List* push_client_queue = NULL
static

◆ push_client_run_status

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