Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
wsstdlib.c
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2016 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  * wsstdlib.c - WTA and WTAI standard libraries related implementations
59  *
60  * Authors:
61  * Markku Rossi <mtr@iki.fi>
62  * Stipe Tolj <stolj@wapme.de>
63  *
64  * 2005-03-22 - update to latest specs:
65  * WAP-268-WTAI-20010908.pdf
66  * WAP-269-WTAIIS136-20010908-a.pdf
67  * WAP-270-WTAIPDC-20010908-a.pdf
68  * WAP-228-WTAIIS95-20010908-a.pdf
69  * WAP-255-WTAIGSM-20010908-a.pdf
70  */
71 
72 #include "wsint.h"
73 
74 /* TODO: the function registry could have argument type specifier
75  * strings. These could be used to generate extra warnings when
76  * functions are called with wrong arguments. However, this might not
77  * be fully conformable to the WMLScript specification. I think that
78  * the interpreter might do an automatic type conversion so the
79  * warnings are less useful. But, these warnings could be enabled in
80  * the `-Wpedantic' mode. */
81 
82 /********************* Types and definitions ****************************/
83 
84 /* Calculate the number of function registries in the array `f'. */
85 #define NF(f) (sizeof(f) / sizeof(f[0]))
86 
87 /* Information about a standard library function. */
89 {
90  char *name;
91 
92  /* The exact number of arguments. */
93  int num_args;
94 
95  /* The function ID as specified */
97 };
98 
100 
101 /* Information about a standard library. */
103 {
104  char *name;
105 
107 
108  /* The number of functions in this library. */
110 
111  /* The functions are given in their index order. */
113 };
114 
116 
117 /********************* Static variables *********************************/
118 
120  {
121  {"abs", 1, 0},
122  {"min", 2, 1},
123  {"max", 2, 2},
124  {"parseInt", 1, 3},
125  {"parseFloat", 1, 4},
126  {"isInt", 1, 5},
127  {"isFloat", 1, 6},
128  {"maxInt", 0, 7},
129  {"minInt", 0, 8},
130  {"float", 0, 9},
131  {"exit", 1, 10},
132  {"abort", 1, 11},
133  {"random", 1, 12},
134  {"seed", 1, 13},
135  {"characterSet", 0, 14},
136  };
137 
139  {
140  {"int", 1, 0},
141  {"floor", 1, 1},
142  {"ceil", 1, 2},
143  {"pow", 2, 3},
144  {"round", 1, 4},
145  {"sqrt", 1, 5},
146  {"maxFloat", 0, 6},
147  {"minFloat", 0, 7},
148  };
149 
151  {
152  {"length", 1, 0},
153  {"isEmpty", 1, 1},
154  {"charAt", 2, 2},
155  {"subString", 3, 3},
156  {"find", 2, 4},
157  {"replace", 3, 5},
158  {"elements", 2, 6},
159  {"elementAt", 3, 7},
160  {"removeAt", 3, 8},
161  {"replaceAt", 4, 9},
162  {"insertAt", 4, 10},
163  {"squeeze", 1, 11},
164  {"trim", 1, 12},
165  {"compare", 2, 13},
166  {"toString", 1, 14},
167  {"format", 2, 15},
168  };
169 
171  {
172  {"isValid", 1, 0},
173  {"getScheme", 1, 1},
174  {"getHost", 1, 2},
175  {"getPort", 1, 3},
176  {"getPath", 1, 4},
177  {"getParameters", 1, 5},
178  {"getQuery", 1, 6},
179  {"getFragment", 1, 7},
180  {"getBase", 0, 8},
181  {"getReferer", 0, 9},
182  {"resolve", 2, 10},
183  {"escapeString", 1, 11},
184  {"unescapeString", 1, 12},
185  {"loadString", 2, 13},
186  };
187 
189  {
190  {"getVar", 1, 0},
191  {"setVar", 2, 1},
192  {"go", 1, 2},
193  {"prev", 0, 3},
194  {"newContext", 0, 4},
195  {"getCurrentCard", 0, 5},
196  {"refresh", 0, 6},
197  };
198 
200  {
201  {"prompt", 2, 0},
202  {"confirm", 3, 1},
203  {"alert", 1, 2},
204  };
205 
207  {
208  {"signText", 4, 16},
209  };
210 
212  {
213  {"set", 3, 0},
214  {"get", 2, 1},
215  {"getFirstName", 1, 2},
216  {"getNextName", 2, 3},
217  {"getAllAttributes", 1, 4},
218  {"getAttribute", 2, 5},
219  {"getClassProperty", 2, 6},
220  {"getUnits", 1, 7},
221  {"query", 1, 8},
222  {"invoke", 3, 9},
223  {"call", 3, 10},
224  {"status", 1, 11},
225  {"control", 3, 12},
226  };
227 
229  {
230  {"makeCall", 1, 0},
231  {"sendDTMF", 1, 1},
232  {"addPBEntry", 2, 2},
233  };
234 
236  {
237  {"setup", 2, 0},
238  {"accept", 2, 1},
239  {"release", 1, 2},
240  {"sendDTMF", 2, 3},
241  {"callStatus", 2, 4},
242  {"list", 1, 5},
243  };
244 
246  {
247  {"send", 2, 0},
248  {"list", 2, 1},
249  {"remove", 1, 2},
250  {"getFieldValue", 2, 3},
251  {"markAsRead", 1, 4},
252  };
253 
255  {
256  {"write", 3, 0},
257  {"search", 2, 1},
258  {"remove", 1, 2},
259  {"getFieldValue", 2, 3},
260  {"change", 3, 4},
261  };
262 
264  {
265  {"setIndicator", 2, 0},
266  {"endContext", 0, 1},
267  {"getProtection", 0, 2},
268  {"setProtection", 1, 3},
269  };
270 
272  {
273  {"sendFlash", 2, 0},
274  {"sendAlert", 2, 1},
275  };
276 
278  {
279  {"hold", 1, 0},
280  {"retrieve", 1, 1},
281  {"transfer", 2, 2},
282  {"deflect", 2, 3},
283  {"multiparty", 0, 4},
284  {"seperate", 1, 5},
285  {"sendUSSD", 4, 6},
286  {"netinfo", 1, 7},
287  {"callWaiting", 1, 8},
288  {"sendBusy", 1, 9},
289  };
290 
292  {
293  {"dialled", 1, 0},
294  {"missed", 1, 1},
295  {"received", 1, 2},
296  {"getFieldValue", 2, 3},
297  };
298 
300  {
301  {"hold", 1, 0},
302  {"retrieve", 1, 1},
303  {"transfer", 2, 2},
304  {"deflect", 2, 3},
305  {"multiparty", 0, 4},
306  {"seperate", 1, 5},
307  };
308 
310  {
311  {"sendText", 6, 0},
312  {"cancelText", 1, 1},
313  {"sendAck", 1, 2},
314  };
315 
317  {
318  {"Lang", 0, NF(lib_lang_functions), lib_lang_functions},
319  {"Float", 1, NF(lib_float_functions), lib_float_functions},
320  {"String", 2, NF(lib_string_functions), lib_string_functions},
321  {"URL", 3, NF(lib_url_functions), lib_url_functions},
322  {"WMLBrowser", 4, NF(lib_wmlbrowser_functions), lib_wmlbrowser_functions},
323  {"Dialogs", 5, NF(lib_dialogs_functions), lib_dialogs_functions},
324  {"Crypto", 6, NF(lib_crypto_functions), lib_crypto_functions},
325  {"EFI", 7, NF(lib_efi_functions), lib_efi_functions},
326  {"WTAPublic", 512, NF(lib_wtapublic_functions), lib_wtapublic_functions},
327  {"WTAVoiceCall", 513, NF(lib_wtavoicecall_functions), lib_wtavoicecall_functions},
328  {"WTANetText", 514, NF(lib_wtanettext_functions), lib_wtanettext_functions},
329  {"WTAPhoneBook", 515, NF(lib_wtaphonebook_functions), lib_wtaphonebook_functions},
330  {"WTAMisc", 516, NF(lib_wtamisc_functions), lib_wtamisc_functions},
331  {"WTAANSI163", 517, NF(lib_wtaansi136_functions), lib_wtaansi136_functions},
332  {"WTAGSM", 518, NF(lib_wtagsm_functions), lib_wtagsm_functions},
333  {"WTACallLog", 519, NF(lib_wtacalllog_functions), lib_wtacalllog_functions},
334  {"WTAPDC", 520, NF(lib_wtapdc_functions), lib_wtapdc_functions},
335  {"WTAIS95", 521, NF(lib_wtais95_functions), lib_wtais95_functions},
336  {NULL, 0, 0, NULL}
337  };
338 
339 /********************* Global functions *********************************/
340 
341 WsBool ws_stdlib_function(const char *library, const char *function,
342  WsUInt16 *lindex_return, WsUInt8 *findex_return,
343  WsUInt8 *num_args_return, WsBool *lindex_found_return,
344  WsBool *findex_found_return)
345 {
346  WsUInt16 l;
347 
348  *lindex_found_return = WS_FALSE;
349  *findex_found_return = WS_FALSE;
350 
351  for (l = 0; libraries[l].name != NULL; l++) {
352  if (strcmp(libraries[l].name, library) == 0) {
353  WsUInt8 f;
354 
355  *lindex_return = libraries[l].library_id;
356  *lindex_found_return = WS_TRUE;
357 
358  for (f = 0; f < libraries[l].num_functions; f++) {
359  if (strcmp(libraries[l].functions[f].name, function) == 0) {
360  *findex_return = libraries[l].functions[f].function_id;
361  *findex_found_return = WS_TRUE;
362 
363  *num_args_return = libraries[l].functions[f].num_args;
364 
365  return WS_TRUE;
366  }
367  }
368  }
369  }
370 
371  return WS_FALSE;
372 }
373 
374 
376  const char **library_return,
377  const char **function_return)
378 {
379  WsUInt16 l;
380  WsUInt8 f;
381 
382  *library_return = NULL;
383  *function_return = NULL;
384 
385  for (l = 0; libraries[l].name != NULL; l++)
386  if (libraries[l].library_id == lindex)
387  for (f = 0; f < libraries[l].num_functions; f++) {
388  if (libraries[l].functions[f].function_id == findex) {
389  *library_return = libraries[l].name;
390  *function_return = libraries[l].functions[f].name;
391  return WS_TRUE;
392  }
393  }
394 
395  return WS_FALSE;
396 }
static WsStdLibFuncReg lib_float_functions[]
Definition: wsstdlib.c:138
Definition: wsint.h:131
static WsStdLibFuncReg lib_string_functions[]
Definition: wsstdlib.c:150
static WsStdLibFuncReg lib_wmlbrowser_functions[]
Definition: wsstdlib.c:188
static WsStdLibFuncReg lib_wtapdc_functions[]
Definition: wsstdlib.c:299
static WsStdLibFuncReg lib_wtapublic_functions[]
Definition: wsstdlib.c:228
WsBool ws_stdlib_function(const char *library, const char *function, WsUInt16 *lindex_return, WsUInt8 *findex_return, WsUInt8 *num_args_return, WsBool *lindex_found_return, WsBool *findex_found_return)
Definition: wsstdlib.c:341
WsUInt8 num_functions
Definition: wsstdlib.c:109
static WsStdLibReg libraries[]
Definition: wsstdlib.c:316
char * name
Definition: wsstdlib.c:104
WsUInt8 function_id
Definition: wsstdlib.c:96
static WsStdLibFuncReg lib_wtais95_functions[]
Definition: wsstdlib.c:309
static WsStdLibFuncReg lib_wtacalllog_functions[]
Definition: wsstdlib.c:291
unsigned char WsUInt8
Definition: wsint.h:116
static WsStdLibFuncReg lib_efi_functions[]
Definition: wsstdlib.c:211
static WsStdLibFuncReg lib_crypto_functions[]
Definition: wsstdlib.c:206
static WsStdLibFuncReg lib_wtamisc_functions[]
Definition: wsstdlib.c:263
unsigned short WsUInt16
Definition: wsint.h:119
static WsStdLibFuncReg lib_wtagsm_functions[]
Definition: wsstdlib.c:277
static WsStdLibFuncReg lib_dialogs_functions[]
Definition: wsstdlib.c:199
char * name
Definition: smsc_cimd2.c:212
WsUInt16 library_id
Definition: wsstdlib.c:106
WsBool
Definition: wsint.h:128
WsBool ws_stdlib_function_name(WsUInt16 lindex, WsUInt8 findex, const char **library_return, const char **function_return)
Definition: wsstdlib.c:375
WsStdLibFuncReg * functions
Definition: wsstdlib.c:112
static WsStdLibFuncReg lib_lang_functions[]
Definition: wsstdlib.c:119
static WsStdLibFuncReg lib_url_functions[]
Definition: wsstdlib.c:170
static WsStdLibFuncReg lib_wtanettext_functions[]
Definition: wsstdlib.c:245
static WsStdLibFuncReg lib_wtavoicecall_functions[]
Definition: wsstdlib.c:235
#define NF(f)
Definition: wsstdlib.c:85
static WsStdLibFuncReg lib_wtaansi136_functions[]
Definition: wsstdlib.c:271
static WsStdLibFuncReg lib_wtaphonebook_functions[]
Definition: wsstdlib.c:254
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.