00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 #include "gwlib/gwlib.h"
00064 #include "wap-maps.h"
00065
00066 struct url_map_struct {
00067 Octstr *name;
00068 Octstr *url;
00069 Octstr *map_url;
00070 Octstr *send_msisdn_query;
00071 Octstr *send_msisdn_header;
00072 Octstr *send_msisdn_format;
00073 int accept_cookies;
00074 };
00075
00076 struct user_map_struct {
00077 Octstr *name;
00078 Octstr *user;
00079 Octstr *pass;
00080 Octstr *msisdn;
00081 };
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 static List *url_map = NULL;
00094 static Dict *user_map = NULL;
00095
00096
00097
00098
00099
00100
00101 void wap_map_add_url(Octstr *name, Octstr *url, Octstr *map_url,
00102 Octstr *send_msisdn_query,
00103 Octstr *send_msisdn_header,
00104 Octstr *send_msisdn_format,
00105 int accept_cookies) {
00106 struct url_map_struct *entry;
00107
00108 if (url_map == NULL)
00109 url_map = gwlist_create();
00110
00111 entry = gw_malloc(sizeof(*entry));
00112 entry->name = name;
00113 entry->url = url;
00114 entry->map_url = map_url;
00115 entry->send_msisdn_query = send_msisdn_query;
00116 entry->send_msisdn_header = send_msisdn_header;
00117 entry->send_msisdn_format = send_msisdn_format;
00118 entry->accept_cookies = accept_cookies;
00119
00120 gwlist_append(url_map, entry);
00121 }
00122
00123
00124 static void wap_user_map_destroy(void *i)
00125 {
00126 struct user_map_struct *entry = i;
00127
00128 octstr_destroy(entry->name);
00129 octstr_destroy(entry->user);
00130 octstr_destroy(entry->pass);
00131 octstr_destroy(entry->msisdn);
00132 gw_free(entry);
00133 }
00134
00135
00136 void wap_map_add_user(Octstr *name, Octstr *user, Octstr *pass,
00137 Octstr *msisdn) {
00138 struct user_map_struct *entry;
00139
00140 if (user_map == NULL)
00141 user_map = dict_create(32, wap_user_map_destroy);
00142
00143 entry = gw_malloc(sizeof(*entry));
00144 entry->name = name;
00145 entry->user = user;
00146 entry->pass = pass;
00147 entry->msisdn = msisdn;
00148 dict_put(user_map, entry->user, entry);
00149 }
00150
00151
00152 void wap_map_destroy(void)
00153 {
00154 long i;
00155 struct url_map_struct *entry;
00156
00157 if (url_map != NULL) {
00158 for (i = 0; i < gwlist_len(url_map); i++) {
00159 entry = gwlist_get(url_map, i);
00160 octstr_destroy(entry->name);
00161 octstr_destroy(entry->url);
00162 octstr_destroy(entry->map_url);
00163 octstr_destroy(entry->send_msisdn_query);
00164 octstr_destroy(entry->send_msisdn_header);
00165 octstr_destroy(entry->send_msisdn_format);
00166 gw_free(entry);
00167 }
00168 gwlist_destroy(url_map, NULL);
00169 }
00170 url_map = NULL;
00171 }
00172
00173
00174 void wap_map_user_destroy(void)
00175 {
00176 dict_destroy(user_map);
00177 user_map = NULL;
00178 }
00179
00180
00181
00182
00183
00184
00185 void wap_map_url_config(char *s)
00186 {
00187 char *in, *out;
00188
00189 s = gw_strdup(s);
00190 in = strtok(s, " \t");
00191 if (!in)
00192 return;
00193 out = strtok(NULL, " \t");
00194 if (!out)
00195 return;
00196 wap_map_add_url(octstr_imm("unknown"), octstr_create(in),
00197 octstr_create(out), NULL, NULL, NULL, 0);
00198 gw_free(s);
00199 }
00200
00201 void wap_map_url_config_device_home(char *to)
00202 {
00203 wap_map_add_url(octstr_imm("Device Home"), octstr_imm("DEVICE:home*"),
00204 octstr_create(to), NULL, NULL, NULL, -1);
00205 }
00206
00207
00208 void wap_map_url(Octstr **osp, Octstr **send_msisdn_query,
00209 Octstr **send_msisdn_header,
00210 Octstr **send_msisdn_format, int *accept_cookies)
00211 {
00212 long i;
00213 Octstr *newurl, *tmp1, *tmp2;
00214
00215 newurl = tmp1 = tmp2 = NULL;
00216 *send_msisdn_query = *send_msisdn_header = *send_msisdn_format = NULL;
00217 *accept_cookies = -1;
00218
00219 debug("wsp",0,"WSP: Mapping url <%s>", octstr_get_cstr(*osp));
00220 for (i = 0; url_map && i < gwlist_len(url_map); i++) {
00221 struct url_map_struct *entry;
00222 entry = gwlist_get(url_map, i);
00223
00224
00225
00226
00227
00228
00229
00230 tmp1 = octstr_duplicate(entry->url);
00231 octstr_delete(tmp1, octstr_len(tmp1)-1, 1);
00232 tmp2 = octstr_copy(*osp, 0, octstr_len(tmp1));
00233
00234 debug("wsp",0,"WSP: Matching <%s> with <%s>",
00235 octstr_get_cstr(tmp1), octstr_get_cstr(tmp2));
00236
00237 if (octstr_case_compare(tmp2, tmp1) == 0) {
00238
00239 if (entry->map_url != NULL) {
00240 if (octstr_get_char(entry->map_url,
00241 octstr_len(entry->map_url)-1) == '*') {
00242 newurl = octstr_duplicate(entry->map_url);
00243 octstr_delete(newurl, octstr_len(newurl)-1, 1);
00244 octstr_append(newurl, octstr_copy(*osp,
00245 octstr_len(entry->url)-1,
00246 octstr_len(*osp)-octstr_len(entry->url)+1));
00247 } else {
00248 newurl = octstr_duplicate(entry->map_url);
00249 }
00250 debug("wsp",0,"WSP: URL Rewriten from <%s> to <%s>",
00251 octstr_get_cstr(*osp), octstr_get_cstr(newurl));
00252 octstr_destroy(*osp);
00253 *osp = newurl;
00254 }
00255 *accept_cookies = entry->accept_cookies;
00256 *send_msisdn_query = octstr_duplicate(entry->send_msisdn_query);
00257 *send_msisdn_header = octstr_duplicate(entry->send_msisdn_header);
00258 *send_msisdn_format = octstr_duplicate(entry->send_msisdn_format);
00259 octstr_destroy(tmp1);
00260 octstr_destroy(tmp2);
00261 break;
00262 }
00263 octstr_destroy(tmp1);
00264 octstr_destroy(tmp2);
00265 }
00266 }
00267
00268 int wap_map_user(Octstr **msisdn, Octstr *user, Octstr *pass)
00269 {
00270 struct user_map_struct *entry;
00271
00272 entry = dict_get(user_map, user);
00273 if (entry != NULL && octstr_compare(pass, entry->pass) == 0) {
00274 *msisdn = octstr_duplicate(entry->msisdn);
00275 return 1;
00276 }
00277 return 0;
00278 }
00279
See file LICENSE for details about the license agreement for using,
modifying, copying or deriving work from this software.