Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

wsstdlib.c

Go to the documentation of this file.
00001 /* ==================================================================== 
00002  * The Kannel Software License, Version 1.0 
00003  * 
00004  * Copyright (c) 2001-2008 Kannel Group  
00005  * Copyright (c) 1998-2001 WapIT Ltd.   
00006  * All rights reserved. 
00007  * 
00008  * Redistribution and use in source and binary forms, with or without 
00009  * modification, are permitted provided that the following conditions 
00010  * are met: 
00011  * 
00012  * 1. Redistributions of source code must retain the above copyright 
00013  *    notice, this list of conditions and the following disclaimer. 
00014  * 
00015  * 2. Redistributions in binary form must reproduce the above copyright 
00016  *    notice, this list of conditions and the following disclaimer in 
00017  *    the documentation and/or other materials provided with the 
00018  *    distribution. 
00019  * 
00020  * 3. The end-user documentation included with the redistribution, 
00021  *    if any, must include the following acknowledgment: 
00022  *       "This product includes software developed by the 
00023  *        Kannel Group (http://www.kannel.org/)." 
00024  *    Alternately, this acknowledgment may appear in the software itself, 
00025  *    if and wherever such third-party acknowledgments normally appear. 
00026  * 
00027  * 4. The names "Kannel" and "Kannel Group" must not be used to 
00028  *    endorse or promote products derived from this software without 
00029  *    prior written permission. For written permission, please  
00030  *    contact org@kannel.org. 
00031  * 
00032  * 5. Products derived from this software may not be called "Kannel", 
00033  *    nor may "Kannel" appear in their name, without prior written 
00034  *    permission of the Kannel Group. 
00035  * 
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00039  * DISCLAIMED.  IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS 
00040  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,  
00041  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  
00042  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR  
00043  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,  
00044  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE  
00045  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  
00046  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00047  * ==================================================================== 
00048  * 
00049  * This software consists of voluntary contributions made by many 
00050  * individuals on behalf of the Kannel Group.  For more information on  
00051  * the Kannel Group, please see <http://www.kannel.org/>. 
00052  * 
00053  * Portions of this software are based upon software originally written at  
00054  * WapIT Ltd., Helsinki, Finland for the Kannel project.  
00055  */ 
00056 
00057 /*
00058  * wsstdlib.c - WTA and WTAI standard libraries related implementations
00059  *
00060  * Authors: 
00061  * Markku Rossi <mtr@iki.fi>
00062  * Stipe Tolj <stolj@wapme.de>
00063  * 
00064  * 2005-03-22 - update to latest specs: 
00065  *              WAP-268-WTAI-20010908.pdf 
00066  *              WAP-269-WTAIIS136-20010908-a.pdf
00067  *              WAP-270-WTAIPDC-20010908-a.pdf
00068  *              WAP-228-WTAIIS95-20010908-a.pdf
00069  *              WAP-255-WTAIGSM-20010908-a.pdf
00070  */
00071 
00072 #include "wsint.h"
00073 
00074 /* TODO: the function registry could have argument type specifier
00075  * strings.  These could be used to generate extra warnings when
00076  * functions are called with wrong arguments.  However, this might not
00077  * be fully conformable to the WMLScript specification.  I think that
00078  * the interpreter might do an automatic type conversion so the
00079  * warnings are less useful.  But, these warnings could be enabled in
00080  * the `-Wpedantic' mode. */
00081 
00082 /********************* Types and definitions ****************************/
00083 
00084 /* Calculate the number of function registries in the array `f'. */
00085 #define NF(f) (sizeof(f) / sizeof(f[0]))
00086 
00087 /* Information about a standard library function. */
00088 struct WsStdLibFuncRegRec
00089 {
00090     char *name;
00091 
00092     /* The exact number of arguments. */
00093     int num_args;
00094     
00095     /* The function ID as specified */
00096     WsUInt8 function_id;
00097 };
00098 
00099 typedef struct WsStdLibFuncRegRec WsStdLibFuncReg;
00100 
00101 /* Information about a standard library. */
00102 struct WsStdLibRegRec
00103 {
00104     char *name;
00105 
00106     WsUInt16 library_id;
00107 
00108     /* The number of functions in this library. */
00109     WsUInt8 num_functions;
00110 
00111     /* The functions are given in their index order. */
00112     WsStdLibFuncReg *functions;
00113 };
00114 
00115 typedef struct WsStdLibRegRec WsStdLibReg;
00116 
00117 /********************* Static variables *********************************/
00118 
00119 static WsStdLibFuncReg lib_lang_functions[] =
00120     {
00121         {"abs", 1, 0},
00122         {"min", 2, 1},
00123         {"max", 2, 2},
00124         {"parseInt", 1, 3},
00125         {"parseFloat", 1, 4},
00126         {"isInt", 1, 5},
00127         {"isFloat", 1, 6},
00128         {"maxInt", 0, 7},
00129         {"minInt", 0, 8},
00130         {"float", 0, 9},
00131         {"exit", 1, 10},
00132         {"abort", 1, 11},
00133         {"random", 1, 12},
00134         {"seed", 1, 13},
00135         {"characterSet", 0, 14},
00136     };
00137 
00138 static WsStdLibFuncReg lib_float_functions[] =
00139     {
00140         {"int", 1, 0},
00141         {"floor", 1, 1},
00142         {"ceil", 1, 2},
00143         {"pow", 2, 3},
00144         {"round", 1, 4},
00145         {"sqrt", 1, 5},
00146         {"maxFloat", 0, 6},
00147         {"minFloat", 0, 7},
00148     };
00149 
00150 static WsStdLibFuncReg lib_string_functions[] =
00151     {
00152         {"length", 1, 0},
00153         {"isEmpty", 1, 1},
00154         {"charAt", 2, 2},
00155         {"subString", 3, 3},
00156         {"find", 2, 4},
00157         {"replace", 3, 5},
00158         {"elements", 2, 6},
00159         {"elementAt", 3, 7},
00160         {"removeAt", 3, 8},
00161         {"replaceAt", 4, 9},
00162         {"insertAt", 4, 10},
00163         {"squeeze", 1, 11},
00164         {"trim", 1, 12},
00165         {"compare", 2, 13},
00166         {"toString", 1, 14},
00167         {"format", 2, 15},
00168     };
00169 
00170 static WsStdLibFuncReg lib_url_functions[] =
00171     {
00172         {"isValid", 1, 0},
00173         {"getScheme", 1, 1},
00174         {"getHost", 1, 2},
00175         {"getPort", 1, 3},
00176         {"getPath", 1, 4},
00177         {"getParameters", 1, 5},
00178         {"getQuery", 1, 6},
00179         {"getFragment", 1, 7},
00180         {"getBase", 0, 8},
00181         {"getReferer", 0, 9},
00182         {"resolve", 2, 10},
00183         {"escapeString", 1, 11},
00184         {"unescapeString", 1, 12},
00185         {"loadString", 2, 13},
00186     };
00187 
00188 static WsStdLibFuncReg lib_wmlbrowser_functions[] =
00189     {
00190         {"getVar", 1, 0},
00191         {"setVar", 2, 1},
00192         {"go", 1, 2},
00193         {"prev", 0, 3},
00194         {"newContext", 0, 4},
00195         {"getCurrentCard", 0, 5},
00196         {"refresh", 0, 6},
00197     };
00198 
00199 static WsStdLibFuncReg lib_dialogs_functions[] =
00200     {
00201         {"prompt", 2, 0},
00202         {"confirm", 3, 1},
00203         {"alert", 1, 2},
00204     };
00205 
00206 static WsStdLibFuncReg lib_crypto_functions[] =
00207     {
00208         {"signText", 4, 16},
00209     };
00210 
00211 static WsStdLibFuncReg lib_efi_functions[] =
00212     {
00213         {"set", 3, 0},
00214         {"get", 2, 1},
00215         {"getFirstName", 1, 2},
00216         {"getNextName", 2, 3},
00217         {"getAllAttributes", 1, 4},
00218         {"getAttribute", 2, 5},
00219         {"getClassProperty", 2, 6},
00220         {"getUnits", 1, 7},
00221         {"query", 1, 8},
00222         {"invoke", 3, 9},
00223         {"call", 3, 10},
00224         {"status", 1, 11},
00225         {"control", 3, 12},
00226     };
00227 
00228 static WsStdLibFuncReg lib_wtapublic_functions[] =
00229     {
00230         {"makeCall", 1, 0},
00231         {"sendDTMF", 1, 1},
00232         {"addPBEntry", 2, 2},
00233     };
00234 
00235 static WsStdLibFuncReg lib_wtavoicecall_functions[] =
00236     {
00237         {"setup", 2, 0},
00238         {"accept", 2, 1},
00239         {"release", 1, 2},
00240         {"sendDTMF", 2, 3},
00241         {"callStatus", 2, 4},
00242         {"list", 1, 5},
00243     };
00244 
00245 static WsStdLibFuncReg lib_wtanettext_functions[] =
00246     {
00247         {"send", 2, 0},
00248         {"list", 2, 1},
00249         {"remove", 1, 2},
00250         {"getFieldValue", 2, 3},
00251         {"markAsRead", 1, 4},
00252     };
00253 
00254 static WsStdLibFuncReg lib_wtaphonebook_functions[] =
00255     {
00256         {"write", 3, 0},
00257         {"search", 2, 1},
00258         {"remove", 1, 2},
00259         {"getFieldValue", 2, 3},
00260         {"change", 3, 4},
00261     };
00262 
00263 static WsStdLibFuncReg lib_wtamisc_functions[] =
00264     {
00265         {"setIndicator", 2, 0},
00266         {"endContext", 0, 1},
00267         {"getProtection", 0, 2},
00268         {"setProtection", 1, 3},
00269     };
00270 
00271 static WsStdLibFuncReg lib_wtaansi136_functions[] =
00272     {
00273         {"sendFlash", 2, 0},
00274         {"sendAlert", 2, 1},
00275     };
00276 
00277 static WsStdLibFuncReg lib_wtagsm_functions[] =
00278     {
00279         {"hold", 1, 0},
00280         {"retrieve", 1, 1},
00281         {"transfer", 2, 2},
00282         {"deflect", 2, 3},
00283         {"multiparty", 0, 4},
00284         {"seperate", 1, 5},
00285         {"sendUSSD", 4, 6},
00286         {"netinfo", 1, 7},
00287         {"callWaiting", 1, 8},
00288         {"sendBusy", 1, 9},
00289     };
00290     
00291 static WsStdLibFuncReg lib_wtacalllog_functions[] =
00292     {
00293         {"dialled", 1, 0},
00294         {"missed", 1, 1},
00295         {"received", 1, 2},
00296         {"getFieldValue", 2, 3},
00297     };
00298 
00299 static WsStdLibFuncReg lib_wtapdc_functions[] =
00300     {
00301         {"hold", 1, 0},
00302         {"retrieve", 1, 1},
00303         {"transfer", 2, 2},
00304         {"deflect", 2, 3},
00305         {"multiparty", 0, 4},
00306         {"seperate", 1, 5},
00307     };
00308 
00309 static WsStdLibFuncReg lib_wtais95_functions[] =
00310     {
00311         {"sendText", 6, 0},
00312         {"cancelText", 1, 1},
00313         {"sendAck", 1, 2},
00314     };
00315 
00316 static WsStdLibReg libraries[] =
00317     {
00318         {"Lang", 0, NF(lib_lang_functions), lib_lang_functions},
00319         {"Float", 1, NF(lib_float_functions), lib_float_functions},
00320         {"String", 2, NF(lib_string_functions), lib_string_functions},
00321         {"URL", 3, NF(lib_url_functions), lib_url_functions},
00322         {"WMLBrowser", 4, NF(lib_wmlbrowser_functions), lib_wmlbrowser_functions},
00323         {"Dialogs", 5, NF(lib_dialogs_functions), lib_dialogs_functions},
00324         {"Crypto", 6, NF(lib_crypto_functions), lib_crypto_functions},
00325         {"EFI", 7, NF(lib_efi_functions), lib_efi_functions},
00326         {"WTAPublic", 512, NF(lib_wtapublic_functions), lib_wtapublic_functions},
00327         {"WTAVoiceCall", 513, NF(lib_wtavoicecall_functions), lib_wtavoicecall_functions},
00328         {"WTANetText", 514, NF(lib_wtanettext_functions), lib_wtanettext_functions},
00329         {"WTAPhoneBook", 515, NF(lib_wtaphonebook_functions), lib_wtaphonebook_functions},
00330         {"WTAMisc", 516, NF(lib_wtamisc_functions), lib_wtamisc_functions},
00331         {"WTAANSI163", 517, NF(lib_wtaansi136_functions), lib_wtaansi136_functions},
00332         {"WTAGSM", 518, NF(lib_wtagsm_functions), lib_wtagsm_functions},
00333         {"WTACallLog", 519, NF(lib_wtacalllog_functions), lib_wtacalllog_functions},
00334         {"WTAPDC", 520, NF(lib_wtapdc_functions), lib_wtapdc_functions},
00335         {"WTAIS95", 521, NF(lib_wtais95_functions), lib_wtais95_functions},
00336         {NULL, 0, 0, NULL}
00337     };
00338 
00339 /********************* Global functions *********************************/
00340 
00341 WsBool ws_stdlib_function(const char *library, const char *function,
00342                           WsUInt16 *lindex_return, WsUInt8 *findex_return,
00343                           WsUInt8 *num_args_return, WsBool *lindex_found_return,
00344                           WsBool *findex_found_return)
00345 {
00346     WsUInt16 l;
00347 
00348     *lindex_found_return = WS_FALSE;
00349     *findex_found_return = WS_FALSE;
00350 
00351     for (l = 0; libraries[l].name != NULL; l++) {
00352         if (strcmp(libraries[l].name, library) == 0) {
00353             WsUInt8 f;
00354 
00355             *lindex_return = libraries[l].library_id;
00356             *lindex_found_return = WS_TRUE;
00357 
00358             for (f = 0; f < libraries[l].num_functions; f++) {
00359                 if (strcmp(libraries[l].functions[f].name, function) == 0) {
00360                     *findex_return = libraries[l].functions[f].function_id;
00361                     *findex_found_return = WS_TRUE;
00362 
00363                     *num_args_return = libraries[l].functions[f].num_args;
00364 
00365                     return WS_TRUE;
00366                 }
00367         }
00368         }
00369     }
00370 
00371     return WS_FALSE;
00372 }
00373 
00374 
00375 WsBool ws_stdlib_function_name(WsUInt16 lindex, WsUInt8 findex,
00376                                const char **library_return,
00377                                const char **function_return)
00378 {
00379     WsUInt16 l;
00380     WsUInt8 f;
00381 
00382     *library_return = NULL;
00383     *function_return = NULL;
00384 
00385     for (l = 0; libraries[l].name != NULL; l++)
00386         if (libraries[l].library_id == lindex)
00387             for (f = 0; f < libraries[l].num_functions; f++) {
00388                 if (libraries[l].functions[f].function_id == findex) {
00389                     *library_return = libraries[l].name;
00390                     *function_return = libraries[l].functions[f].name;
00391                     return WS_TRUE;
00392                 }
00393             }
00394 
00395     return WS_FALSE;
00396 }
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.