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

Go to the source code of this file.

Data Structures

struct  url_map_struct
 
struct  user_map_struct
 

Functions

void wap_map_add_url (Octstr *name, Octstr *url, Octstr *map_url, Octstr *send_msisdn_query, Octstr *send_msisdn_header, Octstr *send_msisdn_format, int accept_cookies)
 
static void wap_user_map_destroy (void *i)
 
void wap_map_add_user (Octstr *name, Octstr *user, Octstr *pass, Octstr *msisdn)
 
void wap_map_destroy (void)
 
void wap_map_user_destroy (void)
 
void wap_map_url_config (char *s)
 
void wap_map_url_config_device_home (char *to)
 
void wap_map_url (Octstr **osp, Octstr **send_msisdn_query, Octstr **send_msisdn_header, Octstr **send_msisdn_format, int *accept_cookies)
 
int wap_map_user (Octstr **msisdn, Octstr *user, Octstr *pass)
 

Variables

static Listurl_map = NULL
 
static Dictuser_map = NULL
 

Function Documentation

void wap_map_add_url ( Octstr name,
Octstr url,
Octstr map_url,
Octstr send_msisdn_query,
Octstr send_msisdn_header,
Octstr send_msisdn_format,
int  accept_cookies 
)

Definition at line 101 of file wap-maps.c.

References url_map_struct::accept_cookies, gwlist_append(), gwlist_create, url_map_struct::map_url, url_map_struct::name, name, url_map_struct::send_msisdn_format, url_map_struct::send_msisdn_header, url_map_struct::send_msisdn_query, url_map_struct::url, and url.

Referenced by config_reload(), wap_map_url_config(), and wap_map_url_config_device_home().

105  {
106  struct url_map_struct *entry;
107 
108  if (url_map == NULL)
110 
111  entry = gw_malloc(sizeof(*entry));
112  entry->name = name;
113  entry->url = url;
114  entry->map_url = map_url;
119 
120  gwlist_append(url_map, entry);
121 }
void gwlist_append(List *list, void *item)
Definition: list.c:179
Octstr * send_msisdn_query
Definition: wap-maps.c:70
Octstr * send_msisdn_format
Definition: wap-maps.c:72
Octstr * url
Definition: wap-maps.c:68
char * name
Definition: smsc_cimd2.c:212
int accept_cookies
Definition: wap-maps.c:73
Octstr * map_url
Definition: wap-maps.c:69
static List * url_map
Definition: wap-maps.c:93
Octstr * name
Definition: wap-maps.c:67
#define gwlist_create()
Definition: list.h:136
Octstr * send_msisdn_header
Definition: wap-maps.c:71
static Octstr * url
Definition: test_xmlrpc.c:84
void wap_map_add_user ( Octstr name,
Octstr user,
Octstr pass,
Octstr msisdn 
)

Definition at line 136 of file wap-maps.c.

References dict_create(), dict_put(), user_map_struct::msisdn, user_map_struct::name, name, user_map_struct::pass, user_map_struct::user, and wap_user_map_destroy().

Referenced by config_reload().

137  {
138  struct user_map_struct *entry;
139 
140  if (user_map == NULL)
142 
143  entry = gw_malloc(sizeof(*entry));
144  entry->name = name;
145  entry->user = user;
146  entry->pass = pass;
147  entry->msisdn = msisdn;
148  dict_put(user_map, entry->user, entry);
149 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
void dict_put(Dict *dict, Octstr *key, void *value)
Definition: dict.c:240
static void wap_user_map_destroy(void *i)
Definition: wap-maps.c:124
static Dict * user_map
Definition: wap-maps.c:94
Octstr * msisdn
Definition: wap-maps.c:80
char * name
Definition: smsc_cimd2.c:212
Octstr * name
Definition: wap-maps.c:77
Octstr * user
Definition: wap-maps.c:78
Octstr * pass
Definition: wap-maps.c:79
void wap_map_destroy ( void  )

Definition at line 152 of file wap-maps.c.

References gwlist_destroy(), gwlist_get(), gwlist_len(), url_map_struct::map_url, url_map_struct::name, octstr_destroy(), url_map_struct::send_msisdn_format, url_map_struct::send_msisdn_header, url_map_struct::send_msisdn_query, and url_map_struct::url.

Referenced by config_reload(), main(), and wap_appl_shutdown().

153 {
154  long i;
155  struct url_map_struct *entry;
156 
157  if (url_map != NULL) {
158  for (i = 0; i < gwlist_len(url_map); i++) {
159  entry = gwlist_get(url_map, i);
160  octstr_destroy(entry->name);
161  octstr_destroy(entry->url);
162  octstr_destroy(entry->map_url);
166  gw_free(entry);
167  }
168  gwlist_destroy(url_map, NULL);
169  }
170  url_map = NULL;
171 }
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
Octstr * send_msisdn_query
Definition: wap-maps.c:70
Octstr * send_msisdn_format
Definition: wap-maps.c:72
Octstr * url
Definition: wap-maps.c:68
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
Octstr * map_url
Definition: wap-maps.c:69
static List * url_map
Definition: wap-maps.c:93
Octstr * name
Definition: wap-maps.c:67
Octstr * send_msisdn_header
Definition: wap-maps.c:71
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
void wap_map_url ( Octstr **  osp,
Octstr **  send_msisdn_query,
Octstr **  send_msisdn_header,
Octstr **  send_msisdn_format,
int *  accept_cookies 
)

Definition at line 208 of file wap-maps.c.

References url_map_struct::accept_cookies, debug(), gwlist_get(), gwlist_len(), url_map_struct::map_url, octstr_append(), octstr_case_compare(), octstr_copy, octstr_delete(), octstr_destroy(), octstr_duplicate, octstr_get_char(), octstr_get_cstr, octstr_len(), url_map_struct::send_msisdn_format, url_map_struct::send_msisdn_header, url_map_struct::send_msisdn_query, and url_map_struct::url.

Referenced by start_fetch().

211 {
212  long i;
213  Octstr *newurl, *tmp1, *tmp2;
214 
215  newurl = tmp1 = tmp2 = NULL;
216  *send_msisdn_query = *send_msisdn_header = *send_msisdn_format = NULL;
217  *accept_cookies = -1;
218 
219  debug("wsp",0,"WSP: Mapping url <%s>", octstr_get_cstr(*osp));
220  for (i = 0; url_map && i < gwlist_len(url_map); i++) {
221  struct url_map_struct *entry;
222  entry = gwlist_get(url_map, i);
223 
224  /*
225  debug("wsp",0,"WSP: matching <%s> with <%s>",
226  octstr_get_cstr(entry->url), octstr_get_cstr(entry->map_url));
227  */
228 
229  /* DAVI: I only have '*' terminated entry->url implementation for now */
230  tmp1 = octstr_duplicate(entry->url);
231  octstr_delete(tmp1, octstr_len(tmp1)-1, 1); /* remove last '*' */
232  tmp2 = octstr_copy(*osp, 0, octstr_len(tmp1));
233 
234  debug("wsp",0,"WSP: Matching <%s> with <%s>",
235  octstr_get_cstr(tmp1), octstr_get_cstr(tmp2));
236 
237  if (octstr_case_compare(tmp2, tmp1) == 0) {
238  /* rewrite url if configured to do so */
239  if (entry->map_url != NULL) {
240  if (octstr_get_char(entry->map_url,
241  octstr_len(entry->map_url)-1) == '*') {
242  newurl = octstr_duplicate(entry->map_url);
243  octstr_delete(newurl, octstr_len(newurl)-1, 1);
244  octstr_append(newurl, octstr_copy(*osp,
245  octstr_len(entry->url)-1,
246  octstr_len(*osp)-octstr_len(entry->url)+1));
247  } else {
248  newurl = octstr_duplicate(entry->map_url);
249  }
250  debug("wsp",0,"WSP: URL Rewriten from <%s> to <%s>",
251  octstr_get_cstr(*osp), octstr_get_cstr(newurl));
252  octstr_destroy(*osp);
253  *osp = newurl;
254  }
255  *accept_cookies = entry->accept_cookies;
256  *send_msisdn_query = octstr_duplicate(entry->send_msisdn_query);
257  *send_msisdn_header = octstr_duplicate(entry->send_msisdn_header);
258  *send_msisdn_format = octstr_duplicate(entry->send_msisdn_format);
259  octstr_destroy(tmp1);
260  octstr_destroy(tmp2);
261  break;
262  }
263  octstr_destroy(tmp1);
264  octstr_destroy(tmp2);
265  }
266 }
void octstr_append(Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:1502
long gwlist_len(List *list)
Definition: list.c:166
void * gwlist_get(List *list, long pos)
Definition: list.c:292
Octstr * send_msisdn_query
Definition: wap-maps.c:70
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
Octstr * send_msisdn_format
Definition: wap-maps.c:72
void octstr_delete(Octstr *ostr1, long pos, long len)
Definition: octstr.c:1525
Octstr * url
Definition: wap-maps.c:68
#define octstr_duplicate(ostr)
Definition: octstr.h:187
int octstr_case_compare(const Octstr *os1, const Octstr *os2)
Definition: octstr.c:901
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
int accept_cookies
Definition: wap-maps.c:73
Octstr * map_url
Definition: wap-maps.c:69
static List * url_map
Definition: wap-maps.c:93
long octstr_len(const Octstr *ostr)
Definition: octstr.c:340
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
Octstr * send_msisdn_header
Definition: wap-maps.c:71
int octstr_get_char(const Octstr *ostr, long pos)
Definition: octstr.c:404
void wap_map_url_config ( char *  s)

Definition at line 185 of file wap-maps.c.

References octstr_create, octstr_imm(), and wap_map_add_url().

Referenced by config_reload().

186 {
187  char *in, *out;
188 
189  s = gw_strdup(s);
190  in = strtok(s, " \t");
191  if (!in)
192  return;
193  out = strtok(NULL, " \t");
194  if (!out)
195  return;
196  wap_map_add_url(octstr_imm("unknown"), octstr_create(in),
197  octstr_create(out), NULL, NULL, NULL, 0);
198  gw_free(s);
199 }
void wap_map_add_url(Octstr *name, Octstr *url, Octstr *map_url, Octstr *send_msisdn_query, Octstr *send_msisdn_header, Octstr *send_msisdn_format, int accept_cookies)
Definition: wap-maps.c:101
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
#define octstr_create(cstr)
Definition: octstr.h:125
void wap_map_url_config_device_home ( char *  to)

Definition at line 201 of file wap-maps.c.

References octstr_create, octstr_imm(), and wap_map_add_url().

Referenced by config_reload().

202 {
203  wap_map_add_url(octstr_imm("Device Home"), octstr_imm("DEVICE:home*"),
204  octstr_create(to), NULL, NULL, NULL, -1);
205 }
void wap_map_add_url(Octstr *name, Octstr *url, Octstr *map_url, Octstr *send_msisdn_query, Octstr *send_msisdn_header, Octstr *send_msisdn_format, int accept_cookies)
Definition: wap-maps.c:101
Octstr * octstr_imm(const char *cstr)
Definition: octstr.c:281
#define octstr_create(cstr)
Definition: octstr.h:125
int wap_map_user ( Octstr **  msisdn,
Octstr user,
Octstr pass 
)

Definition at line 268 of file wap-maps.c.

References dict_get(), user_map_struct::msisdn, octstr_compare(), octstr_duplicate, and user_map_struct::pass.

269 {
270  struct user_map_struct *entry;
271 
272  entry = dict_get(user_map, user);
273  if (entry != NULL && octstr_compare(pass, entry->pass) == 0) {
274  *msisdn = octstr_duplicate(entry->msisdn);
275  return 1;
276  }
277  return 0;
278 }
static Dict * user_map
Definition: wap-maps.c:94
Octstr * msisdn
Definition: wap-maps.c:80
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
#define octstr_duplicate(ostr)
Definition: octstr.h:187
Octstr * pass
Definition: wap-maps.c:79
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
void wap_map_user_destroy ( void  )

Definition at line 174 of file wap-maps.c.

References dict_destroy().

Referenced by config_reload(), main(), and wap_appl_shutdown().

175 {
177  user_map = NULL;
178 }
static Dict * user_map
Definition: wap-maps.c:94
void dict_destroy(Dict *dict)
Definition: dict.c:215
static void wap_user_map_destroy ( void *  i)
static

Definition at line 124 of file wap-maps.c.

References user_map_struct::msisdn, user_map_struct::name, octstr_destroy(), user_map_struct::pass, and user_map_struct::user.

Referenced by wap_map_add_user().

125 {
126  struct user_map_struct *entry = i;
127 
128  octstr_destroy(entry->name);
129  octstr_destroy(entry->user);
130  octstr_destroy(entry->pass);
131  octstr_destroy(entry->msisdn);
132  gw_free(entry);
133 }
Octstr * msisdn
Definition: wap-maps.c:80
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
Octstr * name
Definition: wap-maps.c:77
Octstr * user
Definition: wap-maps.c:78
Octstr * pass
Definition: wap-maps.c:79

Variable Documentation

List* url_map = NULL
static

Definition at line 93 of file wap-maps.c.

Dict* user_map = NULL
static

Definition at line 94 of file wap-maps.c.

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