console.c

Go to the documentation of this file.
00001 #include "cgi.h"
00002 
00003 static char* JSSQLEscape(ScriptEnvironment* Env, char* cmd, int argc, char** argv, CGINameValue* Params)
00004 {
00005    size_t i=0,j=0;
00006    char *in;
00007     char *out;
00008    char *extra = NULL;;
00009    if (argc == 0) return NULL;
00010 
00011    in = argv[0];
00012    out = CGIMALLOC(1 + (strlen(in) * 2));
00013    if (argc > 1) extra = argv[1];
00014 
00015    while (in[i])
00016    {
00017     if (in[i] == '\'')
00018       {
00019        out[j++] = '\'';
00020        out[j++] = '\'';
00021       }
00022     else if (strchr("\t\r\n",in[i]))
00023      {
00024        out[j++] = ' ';
00025      }
00026     else if (extra && strchr(extra,in[i]))
00027      {
00028       out[j++] = '\\';
00029       out[j++] = in[i];
00030      }
00031     else out[j++] = in[i];
00032 
00033     i++;
00034    }
00035 
00036    out[j]=0;
00037    return out;
00038 }
00039 
00040 int CGImain(char * argv0,CGINameValue* Params,STREAM htmlout)
00041 {
00042  char cmdline[1024];
00043  CGINameValue * nvp = NewNVP(16);
00044      int ret;
00045     ScriptFunction Functions[] =
00046      {{"print",10,(ScriptFunctionCall)*JSPrint},
00047       {"write",10,(ScriptFunctionCall)*JSPrint},
00048       {"eval",1,(ScriptFunctionCall)*JSEval},
00049       {"timestamp",0,(ScriptFunctionCall)*JSTimeStamp},
00050       {"toFixed",2,(ScriptFunctionCall)*JStoFixed},
00051       {"escape",1,(ScriptFunctionCall)*JSHTMLEscape},
00052       {"escapeSQL",1,(ScriptFunctionCall)*JSSQLEscape},
00053       {"subStr",3,(ScriptFunctionCall)*JSsubstr},
00054       {"indexOf",4,(ScriptFunctionCall)*JSIndexOf},
00055       {"length",1,(ScriptFunctionCall)*JSstrlen},
00056       {"hasRecord",1,(ScriptFunctionCall)*JSHasRecord},
00057       {"runReport",8,(ScriptFunctionCall)*JSReport},
00058       {"number",1,(ScriptFunctionCall)*JSToNumber},
00059       {"environment",1,(ScriptFunctionCall)*JSGetEnv},
00060       {"toNumber",1,(ScriptFunctionCall)*JSToNumber},
00061       {"random",1,(ScriptFunctionCall)*JSRandom},
00062       {0,0,0}};
00063     ScriptObject Objects[] =
00064      {{"data",0},
00065       {0,0}};
00066     ScriptEnvironment Env;
00067 
00068    memset(&Env,0,sizeof(Env));
00069     Env.Functions = Functions;
00070     Env.Objects   = Objects;
00071     Env.htmlout   = htmlout;
00072     Env.argv0     = argv0;
00073     Env.F2 = 0;
00074 
00075     Objects[0].data=0;
00076 
00077     ret = RunScript(&Env,stdin,nvp);
00078     if (ret > 0)
00079     {
00080      HTMLWriteL(htmlout,"***",3);
00081      PrintScriptError(htmlout,&Env, 0, ret);
00082      HTMLWriteL(htmlout,"***",3);
00083     }
00084 
00085  DeleteNVP(nvp);
00086  return 0;
00087 }


Raosoft, Inc.
Raosoft EZReport, EZSurvey, InterForm, RapidReport, Raosoft, and SurveyWin are registered trademarks of Raosoft, Inc. Page contents © 1996-2007 by Raosoft, Inc. You may use and modify this file for your own use, but may not distribute it or derivative works without the prior written consent of Raosoft, Inc. This software is provided "as is," and Raosoft makes no warranty, express or implied, of fitness for a particular application. Every measure has been taken to anticipate risks inherent to computer networks, but we cannot guarantee safety or reliability of this program in every situation.
Tel: 206-525-4025 (US) Email: raosoft@raosoft.com
http://www.raosoft.com/