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

Go to the source code of this file.

Enumerations

enum  { no_cache = -1, iniatilised = -2, not_iniatilised = -3, cached = 0 }
 

Functions

static WTPCached_tidcache_item_create_empty (void)
 
static void cache_item_destroy (void *item)
 
static void add_tid (WTPRespMachine *resp_machine, long tid)
 
static void set_tid_by_item (WTPCached_tid *item, long tid)
 
static int tid_in_window (long rcv_tid, long last_tid)
 
static WTPCached_tidtid_cached (WTPRespMachine *resp_machine)
 
void wtp_tid_cache_init (void)
 
void wtp_tid_cache_shutdown (void)
 
int wtp_tid_is_valid (WAPEvent *event, WTPRespMachine *resp_machine)
 
void wtp_tid_set_by_machine (WTPRespMachine *resp_machine, long tid)
 
static int tid_is_cached (void *a, void *b)
 

Variables

static Listtid_cache = NULL
 

Enumeration Type Documentation

anonymous enum
Enumerator
no_cache 
iniatilised 
not_iniatilised 
cached 

Definition at line 70 of file wtp_tid.c.

70  {
71  no_cache = -1,
72  iniatilised = -2,
73  not_iniatilised = -3,
74  cached = 0
75 };
Definition: wtp_tid.c:74

Function Documentation

static void add_tid ( WTPRespMachine resp_machine,
long  tid 
)
static

Definition at line 287 of file wtp_tid.c.

References WTPCached_tid::addr_tuple, cache_item_create_empty(), gwlist_append(), new_item(), WTPCached_tid::tid, and wap_addr_tuple_duplicate().

Referenced by wtp_tid_is_valid().

288 {
289  WTPCached_tid *new_item = NULL;
290 
291  new_item = cache_item_create_empty();
292  new_item->addr_tuple = wap_addr_tuple_duplicate(resp_machine->addr_tuple);
293  new_item->tid = tid;
294 
295  gwlist_append(tid_cache, new_item);
296 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
long tid
Definition: wtp.h:190
static Item * new_item(long producer, long num, long index)
Definition: check_list.c:88
WAPAddrTuple * wap_addr_tuple_duplicate(WAPAddrTuple *tuple)
Definition: wap_addr.c:125
WAPAddrTuple * addr_tuple
Definition: wtp_tid.h:90
static WTPCached_tid * cache_item_create_empty(void)
Definition: wtp_tid.c:236
static List * tid_cache
Definition: wtp_tid.c:82
long tid
Definition: wtp_tid.h:91
static WTPCached_tid * cache_item_create_empty ( void  )
static

Definition at line 236 of file wtp_tid.c.

References WTPCached_tid::addr_tuple, and WTPCached_tid::tid.

Referenced by add_tid().

237 {
238  WTPCached_tid *item = NULL;
239 
240  item = gw_malloc(sizeof(*item));
241  item->addr_tuple = NULL;
242  item->tid = 0;
243 
244  return item;
245 }
WAPAddrTuple * addr_tuple
Definition: wtp_tid.h:90
long tid
Definition: wtp_tid.h:91
static void cache_item_destroy ( void *  item)
static

Definition at line 247 of file wtp_tid.c.

References WTPCached_tid::addr_tuple, and wap_addr_tuple_destroy().

Referenced by wtp_tid_cache_shutdown().

248 {
249  WTPCached_tid *item;
250 
251  item = p;
253  gw_free(item);
254 }
WAPAddrTuple * addr_tuple
Definition: wtp_tid.h:90
void wap_addr_tuple_destroy(WAPAddrTuple *tuple)
Definition: wap_addr.c:108
static void set_tid_by_item ( WTPCached_tid item,
long  tid 
)
static

Definition at line 301 of file wtp_tid.c.

References gwlist_lock(), gwlist_unlock(), and WTPCached_tid::tid.

Referenced by wtp_tid_is_valid(), and wtp_tid_set_by_machine().

302 {
304  item->tid = tid;
306 }
long tid
Definition: wtp.h:190
void gwlist_unlock(List *list)
Definition: list.c:354
static List * tid_cache
Definition: wtp_tid.c:82
long tid
Definition: wtp_tid.h:91
void gwlist_lock(List *list)
Definition: list.c:347
static WTPCached_tid * tid_cached ( WTPRespMachine resp_machine)
static

Definition at line 274 of file wtp_tid.c.

References gwlist_search(), and tid_is_cached().

Referenced by wtp_tid_is_valid(), and wtp_tid_set_by_machine().

275 {
276  WTPCached_tid *item = NULL;
277 
278  item = gwlist_search(tid_cache, resp_machine->addr_tuple, tid_is_cached);
279 
280  return item;
281 }
void * gwlist_search(List *list, void *pattern, int(*cmp)(void *, void *))
Definition: list.c:486
static List * tid_cache
Definition: wtp_tid.c:82
static int tid_is_cached(void *a, void *b)
Definition: wtp_tid.c:263
static int tid_in_window ( long  rcv_tid,
long  last_tid 
)
static

Definition at line 204 of file wtp_tid.c.

References debug(), and WTP_TID_WINDOW_SIZE.

Referenced by wtp_tid_is_valid().

205 {
206 #if 0
207  debug("wap.wtp.tid", 0, "tids were rcv_tid, %ld and last_tid, %ld"
208  " and test window %ld", rcv_tid, last_tid, WTP_TID_WINDOW_SIZE);
209 #endif
210  if (last_tid == rcv_tid) {
211  return 0;
212  }
213 
214  if (rcv_tid > last_tid) {
215  if (abs(rcv_tid - last_tid) <= WTP_TID_WINDOW_SIZE) {
216  return 1;
217  } else {
218  return 0;
219  }
220  }
221 
222  if (rcv_tid < last_tid) {
223  if (abs(rcv_tid - last_tid) >= WTP_TID_WINDOW_SIZE){
224  return 1;
225  } else {
226  return 0;
227  }
228  }
229 
230 /*
231  * Following return is unnecessary but our compiler demands it
232  */
233  return 0;
234 }
#define WTP_TID_WINDOW_SIZE
Definition: wtp_tid.h:75
static unsigned short rcv_tid(unsigned short tid)
Definition: wtp_init.c:541
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
static int tid_is_cached ( void *  a,
void *  b 
)
static

Definition at line 263 of file wtp_tid.c.

References WTPCached_tid::addr_tuple, and wap_addr_tuple_same().

Referenced by tid_cached().

264 {
265  WAPAddrTuple *initiator_profile;
266  WTPCached_tid *item;
267 
268  item = a;
269  initiator_profile = b;
270 
271  return wap_addr_tuple_same(item->addr_tuple, initiator_profile);
272 }
WAPAddrTuple * addr_tuple
Definition: wtp_tid.h:90
int wap_addr_tuple_same(WAPAddrTuple *a, WAPAddrTuple *b)
Definition: wap_addr.c:118
void wtp_tid_cache_init ( void  )

Definition at line 102 of file wtp_tid.c.

References gwlist_create.

Referenced by wtp_resp_init().

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

Definition at line 107 of file wtp_tid.c.

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

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:690
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
int wtp_tid_is_valid ( WAPEvent event,
WTPRespMachine resp_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:636
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:690
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
void wtp_tid_set_by_machine ( WTPRespMachine resp_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

Variable Documentation

List* tid_cache = NULL
static

Definition at line 82 of file wtp_tid.c.

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