Kannel: Open Source WAP and SMS gateway  svn-r5335
wtp_tid.h File Reference
#include <math.h>
#include <stdlib.h>
#include "gwlib/gwlib.h"
#include "wap_events.h"
#include "wtp_resp.h"

Go to the source code of this file.

Data Structures

struct  WTPCached_tid
 

Macros

#define WTP_TID_WINDOW_SIZE   (1L << 14)
 

Typedefs

typedef struct WTPCached_tid WTPCached_tid
 

Enumerations

enum  { no_cached_tid, ok, fail }
 

Functions

void wtp_tid_cache_init (void)
 
void wtp_tid_cache_shutdown (void)
 
int wtp_tid_is_valid (WAPEvent *event, WTPRespMachine *machine)
 
void wtp_tid_set_by_machine (WTPRespMachine *machine, long tid)
 

Macro Definition Documentation

◆ WTP_TID_WINDOW_SIZE

#define WTP_TID_WINDOW_SIZE   (1L << 14)

Definition at line 75 of file wtp_tid.h.

Referenced by tid_in_window().

Typedef Documentation

◆ WTPCached_tid

typedef struct WTPCached_tid WTPCached_tid

Definition at line 66 of file wtp_tid.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
no_cached_tid 
ok 
fail 

Definition at line 80 of file wtp_tid.h.

80  {
82  ok,
83  fail
84 };
Definition: wtp_tid.h:82
Definition: wtp_tid.h:83

Function Documentation

◆ wtp_tid_cache_init()

void wtp_tid_cache_init ( void  )

Definition at line 102 of file wtp_tid.c.

References gwlist_create, and tid_cache.

Referenced by wtp_resp_init().

103 {
105 }
static List * tid_cache
Definition: wtp_tid.c:82
#define gwlist_create()
Definition: list.h:136

◆ wtp_tid_cache_shutdown()

void wtp_tid_cache_shutdown ( void  )

Definition at line 107 of file wtp_tid.c.

References cache_item_destroy(), debug(), gwlist_destroy(), gwlist_len(), and tid_cache.

Referenced by wtp_resp_shutdown().

108 {
109  debug("wap.wtp_tid", 0, "%ld items left in the tid cache",
112 }
long gwlist_len(List *list)
Definition: list.c:166
static List * tid_cache
Definition: wtp_tid.c:82
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
static void cache_item_destroy(void *item)
Definition: wtp_tid.c:247
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

◆ wtp_tid_is_valid()

int wtp_tid_is_valid ( WAPEvent event,
WTPRespMachine machine 
)

Definition at line 119 of file wtp_tid.c.

References add_tid(), debug(), fail, info(), no_cached_tid, ok, rcv_tid(), WAPEvent::RcvInvoke, set_tid_by_item(), WTPCached_tid::tid, tid_cached(), tid_in_window(), and WAPEvent::u.

120 {
121  long rcv_tid = -1,
122  last_tid = -1;
123 
124  WTPCached_tid *item = NULL;
125 
126 #if 0
127  debug("wap.wtp.tid", 0, "starting validation");
128 #endif
129  rcv_tid = resp_machine->tid;
130 
131  if (!event->u.RcvInvoke.tid_new) {
132 /*
133  * First we check whether the current initiator has a cache item for it.
134  */
135  if ((item = tid_cached(resp_machine)) == NULL) {
136  if (event->u.RcvInvoke.no_cache_supported)
137  return no_cached_tid;
138  else {
139 #if 0
140  debug("wap.wtp.tid", 0, "empty cache");
141 #endif
142  add_tid(resp_machine, rcv_tid);
143  return ok;
144  }
145  }
146 /*
147  * If it has, we check if the message is a duplicate or has tid wrapped up
148  * confusingly.
149  */
150  last_tid = item->tid;
151 
152  if (tid_in_window(rcv_tid, last_tid) == 0){
153  info(0, "WTP_TID: tid out of the window");
154  return fail;
155  } else {
156 #if 0
157  debug("wap.wtp.tid", 0, "tid in the window");
158 #endif
159  set_tid_by_item(item, rcv_tid);
160  return ok;
161  }
162 
163  } else {
164  info(0, "WTP_TID: tid_new flag on");
165  rcv_tid = 0;
166 
167  if (item == NULL) {
168  add_tid(resp_machine, rcv_tid);
169  } else {
170  set_tid_by_item(item, rcv_tid);
171  }
172 
173  return fail;
174  }
175 /*
176  * This return is unnecessary but the compiler demands it
177  */
178  return fail;
179 }
void info(int err, const char *fmt,...)
Definition: log.c:672
static unsigned short rcv_tid(unsigned short tid)
Definition: wtp_init.c:541
static WTPCached_tid * tid_cached(WTPRespMachine *resp_machine)
Definition: wtp_tid.c:274
static int tid_in_window(long rcv_tid, long last_tid)
Definition: wtp_tid.c:204
static void add_tid(WTPRespMachine *resp_machine, long tid)
Definition: wtp_tid.c:287
long tid
Definition: wtp_tid.h:91
T DUnitdata TR Invoke TR Invoke TR Result TR Abort S Connect S Suspend S Resume S Suspend S Resume S Disconnect S MethodInvoke S MethodInvoke S MethodResult S MethodInvoke S MethodResult S MethodAbort S Push S ConfirmedPush S ConfirmedPush S PushAbort RcvInvoke
Definition: wap_events.h:491
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
Definition: wtp_tid.h:82
static void set_tid_by_item(WTPCached_tid *item, long tid)
Definition: wtp_tid.c:301
union WAPEvent::@87 u
Definition: wtp_tid.h:83

◆ wtp_tid_set_by_machine()

void wtp_tid_set_by_machine ( WTPRespMachine machine,
long  tid 
)

Definition at line 185 of file wtp_tid.c.

References set_tid_by_item(), and tid_cached().

186 {
187  WTPCached_tid *item = NULL;
188 
189  item = tid_cached(resp_machine);
190  set_tid_by_item(item, tid);
191 }
long tid
Definition: wtp.h:190
static WTPCached_tid * tid_cached(WTPRespMachine *resp_machine)
Definition: wtp_tid.c:274
static void set_tid_by_item(WTPCached_tid *item, long tid)
Definition: wtp_tid.c:301
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.