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

Go to the source code of this file.

Functions

static void dlr_mem_shutdown ()
 
static long dlr_mem_messages (void)
 
static void dlr_mem_flush (void)
 
static void dlr_mem_add (struct dlr_entry *dlr)
 
static int dlr_mem_entry_match (struct dlr_entry *dlr, const Octstr *smsc, const Octstr *ts, const Octstr *dst)
 
static struct dlr_entrydlr_mem_get (const Octstr *smsc, const Octstr *ts, const Octstr *dst)
 
static void dlr_mem_remove (const Octstr *smsc, const Octstr *ts, const Octstr *dst)
 
struct dlr_storagedlr_init_mem (Cfg *cfg)
 

Variables

static Listdlr_waiting_list
 
static RWLock rwlock
 
static struct dlr_storage handles
 

Function Documentation

struct dlr_storage* dlr_init_mem ( Cfg cfg)

Definition at line 206 of file dlr_mem.c.

References gw_rwlock_init_static(), gwlist_create, and handles.

Referenced by dlr_init().

207 {
210 
211  return &handles;
212 }
static struct dlr_storage handles
Definition: dlr_mem.c:193
#define gwlist_create()
Definition: list.h:136
static RWLock rwlock
Definition: dlr_mem.c:76
void gw_rwlock_init_static(RWLock *lock)
Definition: gw-rwlock.c:96
static List * dlr_waiting_list
Definition: dlr_mem.c:75
static void dlr_mem_add ( struct dlr_entry dlr)
static

Definition at line 115 of file dlr_mem.c.

References gw_rwlock_unlock(), gw_rwlock_wrlock(), and gwlist_append().

116 {
120 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
static RWLock rwlock
Definition: dlr_mem.c:76
static List * dlr_waiting_list
Definition: dlr_mem.c:75
static int dlr_mem_entry_match ( struct dlr_entry dlr,
const Octstr smsc,
const Octstr ts,
const Octstr dst 
)
static

Definition at line 126 of file dlr_mem.c.

References dlr_entry::destination, octstr_compare(), octstr_len(), octstr_search(), dlr_entry::smsc, and dlr_entry::timestamp.

Referenced by dlr_mem_get(), and dlr_mem_remove().

127 {
128  /* XXX: check destination addr too, because e.g. for UCP is not enough to check only
129  * smsc and timestamp (timestamp is even without milliseconds)
130  */
131  if (dst){
132  long pos = octstr_len(dlr->destination) - octstr_len(dst);
133 
134  if (pos < 0)
135  return 1;
136 
137  if (octstr_compare(dlr->smsc, smsc) == 0 && octstr_compare(dlr->timestamp, ts) == 0 && octstr_search(dlr->destination, dst, pos) != -1)
138  return 0;
139  } else if (octstr_compare(dlr->smsc, smsc) == 0 && octstr_compare(dlr->timestamp, ts) == 0)
140  return 0;
141 
142  return 1;
143 }
long octstr_search(const Octstr *haystack, const Octstr *needle, long pos)
Definition: octstr.c:1068
Octstr * timestamp
Definition: dlr_p.h:80
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
Octstr * destination
Definition: dlr_p.h:82
Octstr * smsc
Definition: dlr_p.h:79
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
static void dlr_mem_flush ( void  )
static

Definition at line 97 of file dlr_mem.c.

References dlr_entry_destroy(), gw_rwlock_unlock(), gw_rwlock_wrlock(), gwlist_delete(), gwlist_get(), and gwlist_len().

98 {
99  long i;
100  long len;
101 
104  for (i = 0; i < len; i++) {
105  struct dlr_entry *dlr = gwlist_get(dlr_waiting_list, 0);
107  dlr_entry_destroy(dlr);
108  }
110 }
long gwlist_len(List *list)
Definition: list.c:166
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
void * gwlist_get(List *list, long pos)
Definition: list.c:292
void gwlist_delete(List *list, long pos, long count)
Definition: list.c:232
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void dlr_entry_destroy(struct dlr_entry *dlr)
Definition: dlr.c:142
static RWLock rwlock
Definition: dlr_mem.c:76
Definition: dlr_p.h:78
static List * dlr_waiting_list
Definition: dlr_mem.c:75
static struct dlr_entry* dlr_mem_get ( const Octstr smsc,
const Octstr ts,
const Octstr dst 
)
static

Definition at line 148 of file dlr_mem.c.

References dlr_entry_duplicate(), dlr_mem_entry_match(), gw_rwlock_rdlock(), gw_rwlock_unlock(), gwlist_get(), and gwlist_len().

149 {
150  long i;
151  long len;
152  struct dlr_entry *dlr = NULL, *ret = NULL;
153 
156  for (i=0; i < len; i++) {
157  dlr = gwlist_get(dlr_waiting_list, i);
158 
159  if (dlr_mem_entry_match(dlr, smsc, ts, dst) == 0) {
160  ret = dlr_entry_duplicate(dlr);
161  break;
162  }
163  }
165 
166  /* we couldnt find a matching entry */
167  return ret;
168 }
struct dlr_entry * dlr_entry_duplicate(const struct dlr_entry *dlr)
Definition: dlr.c:119
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
int gw_rwlock_rdlock(RWLock *lock)
Definition: gw-rwlock.c:134
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
static int dlr_mem_entry_match(struct dlr_entry *dlr, const Octstr *smsc, const Octstr *ts, const Octstr *dst)
Definition: dlr_mem.c:126
static RWLock rwlock
Definition: dlr_mem.c:76
Definition: dlr_p.h:78
static List * dlr_waiting_list
Definition: dlr_mem.c:75
static long dlr_mem_messages ( void  )
static

Definition at line 92 of file dlr_mem.c.

References gwlist_len().

93 {
95 }
long gwlist_len(List *list)
Definition: list.c:166
static List * dlr_waiting_list
Definition: dlr_mem.c:75
static void dlr_mem_remove ( const Octstr smsc,
const Octstr ts,
const Octstr dst 
)
static

Definition at line 173 of file dlr_mem.c.

References dlr_entry_destroy(), dlr_mem_entry_match(), gw_rwlock_unlock(), gw_rwlock_wrlock(), gwlist_delete(), gwlist_get(), and gwlist_len().

174 {
175  long i;
176  long len;
177  struct dlr_entry *dlr = NULL;
178 
181  for (i=0; i < len; i++) {
182  dlr = gwlist_get(dlr_waiting_list, i);
183 
184  if (dlr_mem_entry_match(dlr, smsc, ts, dst) == 0) {
186  dlr_entry_destroy(dlr);
187  break;
188  }
189  }
191 }
long gwlist_len(List *list)
Definition: list.c:166
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
void * gwlist_get(List *list, long pos)
Definition: list.c:292
void gwlist_delete(List *list, long pos, long count)
Definition: list.c:232
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void dlr_entry_destroy(struct dlr_entry *dlr)
Definition: dlr.c:142
static int dlr_mem_entry_match(struct dlr_entry *dlr, const Octstr *smsc, const Octstr *ts, const Octstr *dst)
Definition: dlr_mem.c:126
static RWLock rwlock
Definition: dlr_mem.c:76
Definition: dlr_p.h:78
static List * dlr_waiting_list
Definition: dlr_mem.c:75
static void dlr_mem_shutdown ( )
static

Definition at line 81 of file dlr_mem.c.

References dlr_entry_destroy(), gw_rwlock_destroy(), gw_rwlock_unlock(), gw_rwlock_wrlock(), and gwlist_destroy().

82 {
87 }
void gw_rwlock_destroy(RWLock *lock)
Definition: gw-rwlock.c:112
int gw_rwlock_wrlock(RWLock *lock)
Definition: gw-rwlock.c:177
void gwlist_item_destructor_t(void *item)
Definition: list.h:129
int gw_rwlock_unlock(RWLock *lock)
Definition: gw-rwlock.c:155
void dlr_entry_destroy(struct dlr_entry *dlr)
Definition: dlr.c:142
static RWLock rwlock
Definition: dlr_mem.c:76
static List * dlr_waiting_list
Definition: dlr_mem.c:75
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145

Variable Documentation

List* dlr_waiting_list
static

Definition at line 75 of file dlr_mem.c.

struct dlr_storage handles
static
Initial value:
= {
.type = "internal",
.dlr_add = dlr_mem_add,
.dlr_get = dlr_mem_get,
.dlr_remove = dlr_mem_remove,
.dlr_shutdown = dlr_mem_shutdown,
.dlr_messages = dlr_mem_messages,
.dlr_flush = dlr_mem_flush
}
static void dlr_mem_flush(void)
Definition: dlr_mem.c:97
static void dlr_mem_add(struct dlr_entry *dlr)
Definition: dlr_mem.c:115
static long dlr_mem_messages(void)
Definition: dlr_mem.c:92
static void dlr_mem_shutdown()
Definition: dlr_mem.c:81
static void dlr_mem_remove(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
Definition: dlr_mem.c:173
static struct dlr_entry * dlr_mem_get(const Octstr *smsc, const Octstr *ts, const Octstr *dst)
Definition: dlr_mem.c:148

Definition at line 193 of file dlr_mem.c.

Referenced by dlr_init_mem().

RWLock rwlock
static

Definition at line 76 of file dlr_mem.c.

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