#include <sys/stat.h>
#include <windows.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
Include dependency graph for cgi.h:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Data Structures | |
class | CGINameValue |
Generic data storage class. More... | |
struct | TextBuffer |
struct | SQLDB |
struct | EZSSTREAM |
struct | ScriptFunction |
struct | ScriptObject |
struct | ScriptEnvironment |
Access modes | |
#define | CGI_ALLOW_NONE 0 |
#define | CGI_ALLOW_READ 1 |
#define | CGI_ALLOW_UPDATE 2 |
#define | CGI_ALLOW_APPEND 4 |
#define | CGI_ALLOW_DELETE 8 |
#define | CGI_ALLOW_WRITE 16 |
#define | CGI_ALLOW_ADMIN 32 |
#define | CGI_ALLOW_REPORT 64 |
#define | CGI_ALLOW_ALL 127 |
Handy functions | |
Some utility functions not available on all compilers | |
void | swapchars (char *str, char find, char repl) |
int | stricmp (const char *a, const char *b) |
int | strnicmp (const char *a, const char *b, size_t length) |
char * | strdup (const char *s) |
char * | strdup3 (char *a, char *b, char *c) |
char * | strndup (char *s, size_t length) |
char * | strn2istr (char *s1, char *s2, size_t l2) |
char * | stristr (char *s1, char *s2) |
int | strmatch (char *c1, char *c2, size_t len, char *end, int cs) |
void | ClearToken (char *c, char *code) |
int | HasToken (char *c, char *code, int *loc) |
int | HasTokenI (char *c, char *code, int *loc) |
char * | PopList2 (char *list, int end) |
char * | PopList (CGINameValue *list, char *key, int end) |
Write a file | |
Sends an entire file to the browser. | |
int | HTMLWriteFile (EZSSTREAM *htmlout, char *filename) |
void | HTMLWriteFileF (EZSSTREAM *htmlout, FILE *f) |
void | SetLoggingLevel (int i) |
void | LogMessage (char *c) |
void | LogError (char *c) |
void | LogTrx (CGINameValue *data) |
void | LogConnection (char *program, char *host) |
void | LogStartup (EZSSTREAM *htmlout, char *argv0) |
Defines | |
#define | RAOSOFT_CGI_VERSION "6.4.2" |
#define | RAOSOFT_CGI_COPYRIGHT "Copyright 2000-2007 by Raosoft Inc. All Rights Reserved." |
#define | _WINSOCKAPI_ |
#define | NULLSTR "" |
#define | CONSOLECGI |
#define | NULL null |
#define | MAXPATH 1024 |
#define | MAXBUF 8196 |
#define | MAXDATA 65535 |
#define | CGIMALLOC(s) (void*)malloc(s); |
#define | CGIFREE(p) {if (p) free(p); p=NULL;} |
#define | CGIFOPEN(n, f) fopen(n,f); |
#define | CGIFCLOSE(h) {if (h) {fclose(h); h=0;}} |
#define | SLASH "/" |
#define | STREAM EZSSTREAM * |
#define | DATABASE FILE |
#define | CGI_DEFAULT_HEADER "Content-type: text/html; charset: utf-8\n\n" |
#define | GetFieldValue(d, f) GetSetting(d,f,"") |
#define | RemoveFieldValue(a, b) SetFieldValue(a,b,NULL) |
#define | RemoveField(a, b) RenameField(a,b,NULL) |
Typedefs | |
typedef char *(* | ScriptFunctionCall )(void *Global, char *cmd, int argc, char **argv, CGINameValue *Variables) |
Functions | |
TextBuffer * | NewBuffer (int length) |
void | DeleteBuffer (TextBuffer *t) |
size_t | BufferRead (TextBuffer *t, char *out, size_t length) |
size_t | BufferWrite (TextBuffer *start, char *text) |
size_t | BufferWriteL (TextBuffer *start, char *text, size_t length) |
size_t | BufferSize (TextBuffer *t) |
char * | CopyBuffer (TextBuffer *t) |
SQLDB * | ODBCConnect (char *service, char *uid, char *pwd, TextBuffer *errors) |
int | ODBCDisconnect (SQLDB *database) |
int | ODBCSelect (SQLDB *database, char *command, void **handle) |
CGINameValue * | ODBCRead (void *handle) |
int | ODBCFinish (void *handle, int *numModified) |
CGINameValue * | ODBCQuery (SQLDB *database, char *command, int *numModified) |
int | ODBCExec (SQLDB *database, char *command, int *numModified) |
int | ODBCCommit (SQLDB *database) |
void | ExpandLocalPath (char *argv0, char *out, char *in, char *extension) |
FILE * | FileOpen (char *argv0, char *file, char *extension) |
int | ExpandUrl (char *url) |
int | CGImain (char *progname, CGINameValue *argv, EZSSTREAM *htmlout) |
int | SendCGIHeader (EZSSTREAM *htmlout, char *header) |
char * | GetSetting (CGINameValue *section, char *key, char *def) |
char * | GetEnvironment (EZSSTREAM *htmlout, char *key) |
EZSSTREAM * | NewStream (int size) |
void | DeleteStream (EZSSTREAM *d) |
char * | CopyStream (EZSSTREAM *s) |
void | HTMLEscape (EZSSTREAM *htmlout, char *out) |
void | HTMLWriteL (EZSSTREAM *htmlout, char *out, size_t length) |
void | HTMLWrite (EZSSTREAM *htmlout, char *out) |
void | HTMLSend (EZSSTREAM *htmlout, TextBuffer *in) |
void | HTMLPrintf (EZSSTREAM *htmlout, char *formatting,...) |
int | SaveDataToASC (CGINameValue *data, char *filename, int *pos) |
int | SaveDataToXML (CGINameValue *data, char *filename, int *pos) |
void | WriteXML (FILE *f, CGINameValue *data) |
int | SendMail (char *recip, char *subject, char *textnote, char *server, char *profile, char *name, char *password) |
int | CheckAllowDeny (char *host, char *allow, char *deny) |
int | GetSecurityFlags (char *argv0, char *host, char *database, char *pwd) |
void | GetTime (char *date, char *time, int type) |
void | ResetList (CGINameValue *header) |
int | DatabaseSaveNewRecord (char *filename, CGINameValue *values, int *pos) |
int | DatabaseSaveIndex (char *indexfile, CGINameValue *Params, int pos) |
int | DatabaseOpen (char *filename, FILE **database, CGINameValue **header, int extra, int rw) |
int | DatabaseReset (FILE *database) |
int | DatabaseFFD (FILE *database, int skiprecords) |
int | DatabaseReadRecord (FILE *database, CGINameValue *v, int *flags) |
int | DatabaseDeleteRecord (char *database, int record) |
int | DatabaseFindNextRecord (FILE *database, CGINameValue *header, CGINameValue *cgidata, char *query) |
int | DatabaseFindFast (FILE *database, CGINameValue *header, CGINameValue *query, int *pos) |
int | DatabaseSearchRecord (FILE *database, char *find, int casesensitive) |
void | DatabaseClose (FILE *database, CGINameValue *header) |
int | ReadUntilWordS2 (FILE *in, EZSSTREAM *out, char *check1, char *check2) |
int | ReadUntilWordS (FILE *in, EZSSTREAM *out, char *check) |
int | ReadUntilWord2 (FILE *in, char *out, size_t max, char *check1, char *check2) |
int | ReadUntilWord (FILE *in, char *out, size_t max, char *check) |
int | ReadNextWord (FILE *source, char *name, size_t length) |
int | ReadNextToken (FILE *source, char *buf, int size, int end, int *isSyntax) |
int | ReadUntilChar (FILE *in, char *out, size_t max, char *stop, int skip) |
CGINameValue * | NewNVP (size_t count) |
void | ExtendNVP (CGINameValue *v, size_t count) |
void | DeleteNVP (CGINameValue *v) |
void | DebugShowNVP (EZSSTREAM *htmlout, CGINameValue *v) |
int | FileSize (char *filename) |
CGINameValue * | ReadHTMLAttributes (FILE *source, size_t max) |
CGINameValue * | ReadINIFileSection (char *file, char *section, int reserve) |
CGINameValue * | ReadPairedValues (int argc, char **argv, int reserve) |
CGINameValue * | ReadPairedString (char *, char delim, int reserve) |
int | SOAPExec (char *host, int port, char *function, char *action, char *data) |
int | WinsockConnect (char *host, int port, unsigned int *s) |
char * | EvaluateExpression (CGINameValue *v, CGINameValue *v2, char *equation) |
char * | EvaluateExpressionL (CGINameValue *v, CGINameValue *v2, char *equation, size_t length) |
double | EvaluateAlgebra (CGINameValue *v, CGINameValue *v2, char *equation) |
int | IsNumber (char *value, size_t len) |
int | EvaluateComparison (char *Comparison, CGINameValue *v, CGINameValue *Var2, char **lastc) |
int | EvaluateLogic (char *line, CGINameValue *Variables, CGINameValue *Var2) |
CGINameValue * | GetField (CGINameValue *v, char *fieldname) |
size_t | ListLength (CGINameValue *header) |
CGINameValue * | CopyList (CGINameValue *header, size_t extra) |
CGINameValue * | CopyListJoin (CGINameValue *a, CGINameValue *b, size_t extra) |
CGINameValue * | CopyListDeep (CGINameValue *header, size_t extra) |
CGINameValue * | CopyListN (CGINameValue *header, size_t extra,...) |
int | RenameField (CGINameValue *d, char *oldname, char *newname) |
int | SetFieldValue (CGINameValue *d, char *fieldname, char *value) |
void | SetValue (CGINameValue *d, char *value) |
void | SetName (CGINameValue *d, char *name) |
int | IsValueSelected (CGINameValue *data, char *fieldname, char *value) |
char * | JStoFixed (ScriptEnvironment *Global, char *cmd, int argc, char **argv, CGINameValue *Params) |
char * | JSsubstr (ScriptEnvironment *Global, char *cmd, int argc, char **argv, CGINameValue *Params) |
char * | JSIndexOf (ScriptEnvironment *Global, char *cmd, int argc, char **argv, CGINameValue *Params) |
char * | JSstrlen (ScriptEnvironment *Global, char *cmd, int argc, char **argv, CGINameValue *Params) |
char * | JSPrint (ScriptEnvironment *Global, char *cmd, int argc, char **argv, CGINameValue *Params) |
char * | JSEval (ScriptEnvironment *Global, char *cmd, int argc, char **argv, CGINameValue *Params) |
char * | JSReport (ScriptEnvironment *Env, char *cmd, int argc, char **argv, CGINameValue *Params) |
char * | JSRandom (ScriptEnvironment *Env, char *cmd, int argc, char **argv, CGINameValue *Params) |
char * | JSHasRecord (ScriptEnvironment *Env, char *cmd, int argc, char **argv, CGINameValue *Params) |
char * | JSGetEnv (ScriptEnvironment *Env, char *cmd, int argc, char **argv, CGINameValue *Params) |
char * | JSToNumber (ScriptEnvironment *Env, char *cmd, int argc, char **argv, CGINameValue *Params) |
char * | JSHTMLEscape (ScriptEnvironment *Env, char *cmd, int argc, char **argv, CGINameValue *Params) |
char * | JSTimeStamp (ScriptEnvironment *Env, char *cmd, int argc, char **argv, CGINameValue *Params) |
int | RunScript (ScriptEnvironment *Env, FILE *script, CGINameValue *Variables) |
int | PrintScriptError (EZSSTREAM *htmlout, ScriptEnvironment *Env, FILE *script, int errcode) |
int | RunReport (char *argv0, EZSSTREAM *htmlout, FILE *source, CGINameValue *cgidata, CGINameValue *dbdata, CGINameValue *unused, int preset, char *stop) |
int | RunReportF (char *argv0, EZSSTREAM *htmlout, FILE *source, CGINameValue *cgidata, CGINameValue *dbdata, CGINameValue *unused, int preset, char *stop, char *lastData, ScriptFunction *extra) |
int | CheckCGISendMethod (EZSSTREAM *htmlin) |
CGINameValue * | ReadCGIGetData (EZSSTREAM *htmlin, int extra) |
CGINameValue * | ReadCGIPostData (EZSSTREAM *htmlin, int extra) |
int | B64encode (char *in, char *out) |
void | B64decode (char *text) |
void | qpdecode (char *text) |
void | UTF7toUTF8 (char *text) |
size_t | UTF8ToUCS2C (char *in, int *c) |
char * | ANSItoUTF8 (char *s) |
int | ContainsANSIChars (char *s) |
|
|
|
Definition at line 924 of file cgi.h. Referenced by GetSecurityFlags(), and ShowProgramStatus(). |
|
Definition at line 926 of file cgi.h. Referenced by GetSecurityFlags(). |
|
Definition at line 921 of file cgi.h. Referenced by CGImain(), GetSecurityFlags(), Login(), SecurityError(), and ShowProgramStatus(). |
|
Definition at line 922 of file cgi.h. Referenced by GetSecurityFlags(), and ShowProgramStatus(). |
|
Definition at line 918 of file cgi.h. Referenced by CGImain(), GetSecurityFlags(), and ShowProgramStatus(). |
|
Definition at line 919 of file cgi.h. Referenced by CGImain(), GetSecurityFlags(), and ShowProgramStatus(). |
|
Definition at line 925 of file cgi.h. Referenced by CGImain(), GetSecurityFlags(), and SecurityError(). |
|
Definition at line 920 of file cgi.h. Referenced by CGImain(), GetSecurityFlags(), SecurityError(), and ShowProgramStatus(). |
|
Definition at line 923 of file cgi.h. Referenced by GetSecurityFlags(), and ShowProgramStatus(). |
|
Definition at line 914 of file cgi.h. Referenced by CGImain(), and SendCGIHeader(). |
|
Definition at line 765 of file cgi.h. Referenced by _loaddbheader(), AdminRunScript(), CGImain(), DatabaseClose(), DatabaseDeleteRecord(), DatabaseOpen(), EZSInclude(), GenerateUniqueID(), HTMLWriteFile(), JSReport(), LogError(), LogMessage(), LogTrx(), ODBCRunScript(), PrintFinish(), ReadINIFileSection(), SaveData(), SaveDataToASC(), SaveDataToXML(), ShowFormPage(), ValidateBack(), ValidatePage(), and WFmain(). |
|
Definition at line 764 of file cgi.h. Referenced by CGImain(), CreateDatabase(), DatabaseDeleteRecord(), DatabaseOpen(), DatabaseSaveIndex(), FileOpen(), GenerateUniqueID(), GetRespcount(), HTMLWriteFile(), JSReport(), LogError(), LogMessage(), LogStartup(), LogTrx(), ReadINIFileSection(), SaveData(), SaveDataToASC(), SaveDataToXML(), SetRespcount(), and ShowFormPage(). |
|
|
Definition at line 762 of file cgi.h. Referenced by CGImain(), CopyBuffer(), DatabaseReadRecord(), EvaluateAlgebraL(), EvaluateExpression(), EvaluateExpressionL(), fmakeword(), FormatReplacement(), JSHTMLEscape(), JSRandom(), JSRankSort(), JSSQLEscape(), NewBuffer(), NewNVP(), NewStream(), ODBCConnect(), ODBCRead(), PopList2(), PrintFinish(), ReadCGIGetData(), ReadINIFileSection(), ReadUntilWord2(), ReadUntilWordS2(), RunScript(), RunScriptFunction(), strdup3(), strndup(), and WriteINIFileSection(). |
|
|
|
This is the structure for accessing data. For now, this is always a FILE pointer. Some day, it'll be a pointer to an ODBC structure. Definition at line 878 of file cgi.h. Referenced by CGImain(), DatabaseOpen(), and EZSReport(). |
|
Returns "" if the entry does not exist. Definition at line 1187 of file cgi.h. Referenced by Authenticate(), CGImain(), CheckPass(), DatabaseSaveIndex(), DeleteOldRecords(), EvaluateArgument(), EZSRandom(), EZSReport(), FindUserRecordASC(), GetField2(), GetFieldFloat(), GetFieldInt(), GetSecurityFlags(), Instructions(), JSShowPage(), LoadUserDataASC(), Login(), LogStartup(), main(), PopList(), RunReportF(), RunScript(), RunScriptObject(), SaveData(), ShowFormPage(), ShowPage(), SpaceAdd(), SpaceUpdate(), UpdateCounts(), UserAddSpace(), UserUpdate(), VerifyPassword(), and VerifyUser(). |
|
Definition at line 684 of file cgi.h. Referenced by _loaddbheader(), HTMLPrintf(), and RunReportF(). |
|
Definition at line 685 of file cgi.h. Referenced by DatabaseReadRecord(), and DatabaseSearchRecord(). |
|
Definition at line 671 of file cgi.h. Referenced by AdminPrintPage(), CGImain(), DatabaseSaveNewRecord(), ExpandLocalPath(), EZSCounts(), EZSInclude(), EZSReport(), EZSSource(), FileOpen(), GetProjectExtra(), GetRespcount(), GetSecurityFlags(), HTMLWriteFileF(), HTMLWriteL(), Index(), JSHasRecord(), JSReport(), LoadUserDataASC(), Login(), LogStartup(), main(), OpenPage(), Project(), ProjectUpdate(), SaveData(), SaveDataToXML(), SendImage(), SetRespcount(), ShowFormPage(), Space(), SpaceAdd(), SpaceUpdate(), User(), UserAdd(), UserAddSpace(), UserList(), UserUpdate(), VerifyPassword(), VerifyUser(), and WFmain(). |
|
|
Definition at line 603 of file cgi.h. Referenced by CGImain(), CheckCGISendMethod(), CopyList(), CopyListDeep(), CreateDatabase(), DatabaseSaveNewRecord(), ExtendNVP(), GenerateReport(), GetEnvironment(), LoadUserDataASC(), Login(), main(), PrintFinish(), ReadCGIGetData(), ReadCGIPostData(), ReadPairedString(), ReadPairedValues(), RunReportF(), SaveData(), and SetupCGIData(). |
|
Definition at line 20 of file cgi.h. Referenced by PrintInstructions(). |
|
Definition at line 19 of file cgi.h. Referenced by main(), and PrintInstructions(). |
|
|
|
|
|
Definition at line 832 of file cgi.h. Referenced by CGImain(), OpenPage(), RecurseDirectories(), ShowFormPage(), VerifyPassword(), and VerifyUser(). |
|
This is the environment and platform-dependent structure used for printing data to the browser. For FastCGI, it's a fancy structure. For ISAPI, it's the Windows EXTENSION_CONTROL_BLOCK. Otherwise, it's a structure containing either a FILE or TextBuffer pointer. Definition at line 876 of file cgi.h. Referenced by main(), and NewStream(). |
|
runs a script, possibly modifying DataValues and ExportValues. Instructions to execute (which aren't handled by the script functions) are return as command |
|
Definition at line 204 of file cgi_util.c. References int16ToUTF8(). Referenced by CGImain(), ReadCGIGetData(), and ReadCGIPostData(). 00205 { 00206 char* r = malloc(strlen(s)*4+1); /* worst case */ 00207 char* c = r; 00208 for (; *s; s++) 00209 { 00210 unsigned x = (*s) & 0x00ff; 00211 if ((x & 0x80) == 0) 00212 { 00213 *c++ = x; 00214 continue; 00215 } 00216 00217 if ((x & 0x60) == 0) //between 128 and 159, remap from the table 00218 x = ANSIchars[x - 128]; 00219 00220 c += int16ToUTF8(x, c); 00221 } 00222 *c=0; 00223 return r; 00224 }
|
|
Definition at line 257 of file cgi_util.c. References unB64(). 00258 { 00259 char* read = write; 00260 int x, step=0, i[2]; 00261 while (*read && *read != '=') 00262 { 00263 x = unB64(*read); 00264 if (x == -1) break; 00265 i[step % 2]=x; 00266 00267 if (step % 4) 00268 *write++ = (char)((i[(step+1)%2] << ((step%4) * 2)) | (i[step%2] >> (6 - ((step%4) * 2)))) & 0x00ff; 00269 00270 read++; 00271 step = (step + 1) % 8; 00272 } 00273 *write = 0; 00274 }
|
|
returns 1 if more data is needed, otherwise 0 at end of string. Someday, this will be useful for ESMTP logins. Definition at line 58 of file cgi_util.c. 00059 { 00060 unsigned char c1=in[0], c2=0, c3=0; 00061 if (c1) c2 = in[1]; 00062 if (c2) c3 = in[2]; 00063 out[0] = basis_64[c1>>2]; 00064 out[1] = basis_64[((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)]; 00065 00066 if (c2) 00067 { 00068 out[2] = basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)]; 00069 out[3] = basis_64[c3 & 0x3F]; 00070 return c3; 00071 } 00072 else if (c2) 00073 out[2] = basis_64[((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)]; 00074 else 00075 out[2] = '='; 00076 00077 out[3] = '='; 00078 return 0; 00079 }
|
|
Definition at line 452 of file cgi_util.c. References TextBuffer::data, MIN, TextBuffer::Next, and TextBuffer::used. Referenced by CopyBuffer(). 00453 { 00454 size_t read=0; 00455 00456 while( read < length) 00457 { 00458 size_t x = MIN((length - read), start->used); 00459 memcpy(out + read, start->data, x); 00460 read += x; 00461 if (!start->Next) break; 00462 start = (TextBuffer*)start->Next; 00463 } 00464 return read; 00465 }
|
|
Definition at line 430 of file cgi_util.c. References TextBuffer::Next, and TextBuffer::used. Referenced by CopyBuffer(). 00431 { 00432 size_t length = 0; 00433 while (t) 00434 { 00435 TextBuffer* n = t->Next; 00436 length += t->used; 00437 t = n; 00438 } 00439 return length; 00440 }
|
|
Definition at line 387 of file cgi_util.c. References BufferWriteL(). Referenced by CGImain(), EvaluateArgument(), ListErrors(), and ODBCStart(). 00388 { 00389 if (text) return BufferWriteL(start,text,strlen(text)); 00390 return 0; 00391 }
|
|
Definition at line 393 of file cgi_util.c. References TextBuffer::data, TextBuffer::Last, NewBuffer(), TextBuffer::Next, TextBuffer::size, and TextBuffer::used. Referenced by BufferWrite(), DatabaseSaveNewRecord(), and HTMLWriteL(). 00394 { 00395 size_t current, next; 00396 TextBuffer* t = (TextBuffer*)start->Last; 00397 00398 if (length == 0) return 0; 00399 00400 if (length >= (t->size - t->used)) 00401 { 00402 current = (t->size - t->used); 00403 next = length - current; 00404 } 00405 else 00406 { 00407 current = length; 00408 next = 0; 00409 } 00410 00411 memcpy(t->data + t->used,text,current); 00412 t->used += current; 00413 00414 if (next) 00415 { 00416 size_t i = 1024u; /* allocate a new block for anything this big */ 00417 TextBuffer* tn; 00418 00419 if (i < next) i = next; 00420 start->Last = NewBuffer(i); 00421 t->Next = start->Last; 00422 tn = (TextBuffer*)t->Next; 00423 memcpy(tn->data, text + current, next); 00424 tn->used = next; 00425 } 00426 00427 return length; 00428 }
|
|
For both of these lists, the "current" value is taken from the beginning of the comma-delimited values. Definition at line 1116 of file admin.c. References AdminInfo::argv0, Authenticate(), CGI_DEFAULT_HEADER, AdminInfo::Config, DeleteNVP(), Error(), ExpandLocalPath(), GetEnvironment(), GetFieldValue, AdminInfo::htmlout, Index(), Login(), MAXPATH, AdminInfo::Params, ReadINIFileSection(), SendCGIHeader(), SendImage(), SetFieldValue(), ShowAdmin(), ShowPage(), SLASH, strdup3(), stricmp(), stristr(), strnicmp(), UserList(), and WFmain(). 01117 { 01118 char * directory = GetFieldValue(Params,"DIRECTORY"); 01119 char * name = GetFieldValue(Params,"NAME"); 01120 char * page = GetFieldValue(Params,"PAGE"); 01121 char * image = GetFieldValue(Params,"IMAGE"); 01122 char * cookie = GetEnvironment(htmlout,"HTTP_COOKIE");//"USER=newuser; SESSION=; PASSWORD=5678," ; // 01123 char fname[MAXPATH]; 01124 int ret, r2; 01125 AdminInfo Self; 01126 Self.argv0 = argv0; 01127 Self.Config = 0; 01128 Self.Params = Params; 01129 Self.htmlout= htmlout; 01130 01131 if (strchr(name,'/') || strchr(name,'\\') 01132 || stristr(name,".ini") || 01133 !stricmp(page,"LOGOUT")) 01134 {/* access error -- kick 'em out! */ 01135 SendCGIHeader(htmlout,"Set-Cookie: USER=;\nSet-Cookie: SESSION=;\nSet-Cookie: PASSWORD=;\n" CGI_DEFAULT_HEADER); 01136 Self.Params = 0; 01137 Login(&Self); 01138 return 0; 01139 } 01140 01141 if (!strnicmp(page,"USER",4) && !*directory) 01142 directory = "admin"; 01143 01144 if (*image) 01145 { 01146 SendImage(&Self,image); 01147 return 0; 01148 } 01149 01150 ExpandLocalPath(argv0,fname,"admin",SLASH "cgi.ini"); 01151 Self.Config= ReadINIFileSection(fname,"admin",0); 01152 01153 ret = Authenticate(&Self,directory,&cookie); 01154 if (ret == 2 && !*page && !*directory) /* new login, go to the home directory */ 01155 directory = GetFieldValue(Params,"DIRECTORY"); 01156 01157 if (ret) /* login valid, maybe write a new cookie */ 01158 { 01159 if (cookie) 01160 { 01161 char* header = strdup3(cookie, "\n", CGI_DEFAULT_HEADER); 01162 SendCGIHeader(htmlout,header); 01163 free(header); 01164 free(cookie); 01165 } 01166 else 01167 SendCGIHeader(htmlout,0); 01168 } 01169 else 01170 { 01171 if (*directory) SetFieldValue(Self.Params,"DIRECTORY",directory); 01172 SendCGIHeader(htmlout,0); 01173 Login(&Self); 01174 goto atexit; 01175 } 01176 /* must be logged in! */ 01177 01178 ret = 0; 01179 r2 = 0; 01180 if (!stricmp(directory,"admin")) 01181 { 01182 ret = ShowAdmin(&Self,name,page); 01183 r2 = 2; 01184 } 01185 01186 if (!ret) 01187 { 01188 ret =ShowPage(&Self,directory,name,page); 01189 if (!ret) ret = r2; 01190 } 01191 01192 switch (ret) 01193 { 01194 case 0: 01195 case 1: Index(&Self,directory); break; 01196 case 2: UserList(&Self); 01197 case 3: break; 01198 default: Error(&Self); 01199 } 01200 01201 atexit: 01202 DeleteNVP(Self.Config); 01203 return 0; 01204 }
|
|
returns true if allow is empty, false if host is blank Remember to configure your server to do name lookups! Referenced by GetSecurityFlags(). |
|
0 = POST, 1 = GET, 2 = POST_ERROR, 3=CONSOLE Definition at line 571 of file cgi_cgi.c. References GetEnvironment(), NULLSTR, stricmp(), and strnicmp(). Referenced by main(). 00572 { 00573 #ifdef WINCGI 00574 char c[256],host[256]; 00575 if (!*WinCGIFile) return 3; 00576 GetPrivateProfileString("CGI","Request Method",NULLSTR,c,256,WinCGIFile); 00577 #else 00578 char * c; 00579 00580 c = GetEnvironment(htmlin,"REQUEST_METHOD"); 00581 #endif 00582 00583 if (!c) return 3; /* not cgi */ 00584 00585 if (c && (stricmp(c,"GET") == 0)) 00586 { 00587 return 1; 00588 } 00589 00590 #ifndef WINCGI 00591 if (c && (stricmp(c,"POST") == 0)) 00592 { 00593 c = getenv("CONTENT_TYPE"); 00594 00595 if(c && strnicmp(c,"application/x-www-form-urlencoded",33)) 00596 { 00597 return 2; 00598 } 00599 return 0; 00600 } 00601 return 0; 00602 #else 00603 return 0; 00604 #endif 00605 }
|
|
removes an element from a comma-delimited string (from EZSurvey's DBF driver) Definition at line 914 of file cgi_util.c. References strmatch(). Referenced by CGImain(). 00915 { /* removes an element from a , delimited list */ 00916 size_t length=strlen(c); 00917 while (length) 00918 { 00919 if (*c == ',' || *c == ' ') { c++; length--; } 00920 else 00921 { 00922 if (strmatch(c,code,length,", ",1)) 00923 { 00924 size_t cl = strlen(code); 00925 while (c[cl] == ',' || c[cl] == ' ') cl++; 00926 /* don't bother to check the length here. */ 00927 if (length >= cl) 00928 { 00929 length -= cl; 00930 memmove(c,c+cl,length); 00931 memset(c+length,0,cl); /* pad the end with nulls */ 00932 } 00933 return; 00934 } 00935 while (length && *c != ',' && *c != ' ') {c++; length--;} 00936 } 00937 } 00938 } /* wasn't that clever? */
|
|
If you write a sentence in MS Word and paste it into IE, IE will not do the form-appropriate character type conversion. Thus, ANSI characters appear in our http data. You can test for this by looking for isolated high-bit characters. Properly encoded UTF-8 text always has two or more adjacent characters with the high bit set. If this post looks like it contains ANSI characters, we'll convert them to utf-8. All the character codes from 127 to 160 are excluded from unicode and the leading character in a UTF08 sequence is always >= 192. We detect ANSI characters by looking for an isolated high-bit character or a character with an invalid value. Unfortunately, this is a field-by- field effect, and so we need to test every field value. Definition at line 105 of file cgi_util.c. Referenced by CGImain(), ReadCGIGetData(), and ReadCGIPostData(). 00106 { 00107 /* 00108 ansi 00109 128 10000000 00110 159 10011111 00111 160 10100000 00112 utf-8 00113 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 00114 1110xxxx 10xxxxxx 10xxxxxx 00115 110xxxxx 10xxxxxx 00116 non-ansi characters: 127, 129, 141, 143, 144, 157, 00117 01111111 10000001 10001101 10001111 10010000 10011101 00118 are also all non-unicode values 00119 */ 00120 unsigned c = *s++ & 0x00ff; 00121 unsigned d; 00122 00123 while (c) 00124 { 00125 if (c & 0x80) 00126 { 00127 if ((c & 0x60) == 0) return 1; /*ANSI remap range -- no unicode characters*/ 00128 d = *s; /*look at the next character */ 00129 if ((d & 0xc0) != 0x80) return 1; 00130 /* require c & 0x60 == 0x40 || c & 0x70 == 0x60 || c & 0xf8 == 0xf0 */ 00131 /*eos | not a utf-8 start sequnce | not a utf-8 sequence */ 00132 00133 /* a valid UTF-8 sequence is unlikely inside an ANSI sequence, but not impossible. */ 00134 if ((c & 0x60) == 0x40) /* 110xxxxx 10xxxxxx */ 00135 { 00136 s++; 00137 goto next; 00138 } 00139 00140 d = s[1]; 00141 if ((d & 0xc0) != 0x80) return 1; 00142 00143 if ((c & 0xf0) == 0xe0) /* 1110xxxx 10xxxxxx 10xxxxxx */ 00144 { 00145 s += 2; 00146 goto next; 00147 } 00148 00149 d = s[2]; 00150 if ((d & 0xc0) != 0x80) return 1; 00151 00152 if ((c & 0xf8) == 0xf0) /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ 00153 { 00154 s += 3; 00155 goto next; 00156 } 00157 00158 return 1; /* isolated high-bit character */ 00159 } 00160 next: 00161 c = *s++ & 0x00ff; 00162 } 00163 00164 return 0; 00165 }
|
|
Definition at line 442 of file cgi_util.c. References BufferRead(), BufferSize(), and CGIMALLOC. Referenced by CGImain(), CopyStream(), EvaluateArgument(), JSReport(), LoadUserDataSQL(), SaveData(), and TryODBC(). 00443 { 00444 size_t l = BufferSize(t); 00445 char * x = CGIMALLOC(l+4); 00446 BufferRead(t,x,l+4); 00447 memset(x+l,0,4); 00448 return x; 00449 }
|
|
inserts unnamed parameters at the beginning Definition at line 2032 of file cgi_util.c. References ListLength(), CGINameValue::name, NewNVP(), NULL, NULLSTR, strdup(), and CGINameValue::value. Referenced by CopyListJoin(), CopyListN(), FindUserRecordASC(), and ShowFormPage(). 02033 { 02034 CGINameValue * v; 02035 02036 size_t x = ListLength(header); 02037 size_t y = 0; 02038 v = NewNVP(x+extra); 02039 02040 if (header) 02041 for (x=0;header[x].name != NULL;x++) 02042 { 02043 if (header[x].name[0]) 02044 { 02045 v[y+extra].name = strdup(header[x].name); 02046 if (header[y].value) 02047 v[y+extra].value = strdup(header[x].value); 02048 y++; 02049 } 02050 } 02051 02052 for (x=0;x<extra;x++) 02053 { 02054 v[x].name = strdup(NULLSTR); 02055 v[x].value = strdup(NULLSTR); 02056 } 02057 return v; 02058 }
|
|
includes 'hidden' variables Definition at line 1979 of file cgi_util.c. References CGINameValue::name, NewNVP(), NULL, NULLSTR, strdup(), and CGINameValue::value. Referenced by LoadUserDataSQL(). 01980 { 01981 CGINameValue * v, *c=header; 01982 01983 size_t x=0; 01984 while (c) 01985 { 01986 size_t i=0; 01987 while (c[i].name != NULL) {if (c[i].name[0]) x++;i++; } 01988 if (!c[i].last) break; 01989 c = (CGINameValue*) c[i].value; 01990 } 01991 01992 v = NewNVP(x+extra); 01993 c = header; 01994 x=0; 01995 while (c) 01996 { 01997 size_t i=0; 01998 while (c[i].name) 01999 { 02000 if (!c[i].name[0]) {i++; continue;} 02001 v[x+extra].name = strdup(c[i].name); 02002 if (c[i].value) 02003 v[x+extra].value = strdup(c[i].value); 02004 i++; 02005 x++; 02006 } 02007 if (!c[i].last) break; 02008 c = (CGINameValue*) c[i].value; 02009 } 02010 02011 for (x=0;x<extra;x++) 02012 { 02013 v[x].name = strdup(NULLSTR); 02014 v[x].value = strdup(NULLSTR); 02015 } 02016 return v; 02017 }
|
|
Definition at line 1936 of file cgi_util.c. References CopyList(), GetField(), CGINameValue::name, NewNVP(), NULL, strdup(), and CGINameValue::value. Referenced by CGImain(), and EZSCounts(). 01937 { 01938 CGINameValue * v; 01939 size_t x=0; 01940 size_t y=0; 01941 if (b == NULL) return CopyList(a,extra); 01942 01943 while (a[x].name != NULL) x++; 01944 01945 while (b[y].name != NULL) 01946 { 01947 if (GetField(a,b[y].name)== NULL) x++; 01948 y++; 01949 } 01950 01951 v = NewNVP(x+extra); 01952 01953 for (x=0; x<extra; x++) 01954 { 01955 v[x].name = strdup(""); 01956 } 01957 x=0; 01958 while (a[x].name != NULL) 01959 { v[x+extra].name = strdup(a[x].name); 01960 if (a[x].value) 01961 v[x+extra].value = strdup(a[x].value); 01962 x++; 01963 } 01964 y=0; 01965 while (b[y].name != NULL) 01966 { 01967 if (GetField(a,b[y].name)== NULL) 01968 { 01969 v[x+extra].name = strdup(b[y].name); 01970 if (b[y].value) 01971 v[x+extra].value = strdup(b[y].value); 01972 x++; 01973 } 01974 y++; 01975 } 01976 return v; 01977 }
|
|
write the new values in the first available blank slots. Definition at line 2061 of file cgi_util.c. References CGIFREE, CopyList(), CGINameValue::name, NULL, and strdup(). 02062 { 02063 va_list ap; 02064 CGINameValue * n; 02065 size_t x; 02066 02067 n = CopyList(header,extra); 02068 va_start(ap, extra); 02069 02070 for (x=0; extra > 0 && n[x].name != NULL; x++) 02071 {char *c; 02072 if (n[x].name[0]) continue; 02073 02074 c = va_arg(ap, char*); 02075 CGIFREE(n[x].name); 02076 n[x].name = strdup(c); 02077 extra--; 02078 } 02079 02080 va_end(ap); 02081 return n; 02082 }
|
|
copies an in-memory stream to a string. use CGIFREE() when done Definition at line 980 of file cgi_util.c. References CopyBuffer(). 00981 { 00982 return CopyBuffer(str->t); 00983 }
|
|
Frees memory allocated for database and header, if non-null. Definition at line 911 of file cgi_data.c. References CGIFCLOSE, and DeleteNVP(). Referenced by CGImain(), DatabaseSaveIndex(), DatabaseSaveNewRecord(), JSHasRecord(), LoadUserDataASC(), and Login().
|
|
Returns 0 on success. May return error code 15. Definition at line 355 of file cgi_data.c. References CGIFCLOSE, CGIFOPEN, and NULL. 00356 {/* can't use CGIFOPEN for writing, since it would truncate the data */ 00357 char c; 00358 int count = 0; 00359 #ifdef __WINCE__ 00360 FILE* f = CGIFOPEN(database,"r+"); 00361 00362 if (f == NULL) return 7; 00363 00364 while (count < record) 00365 { 00366 if (fread(&c,1,1,f) != 1) {CGIFCLOSE(f); return 15;} 00367 if (c == '\n') count ++; 00368 } 00369 00370 fread(&c,1,1,f); 00371 if (c == '\n') return 0; /* can't delete an empty row, sorry */ 00372 00373 fseek(f,-1,SEEK_CUR); 00374 if (fwrite("#",1,1,f) != 1) {CGIFCLOSE(f); return 15;} 00375 CGIFCLOSE(f); 00376 #else 00377 int f = open(database,O_RDWR); 00378 00379 if (f < 0) return 7; 00380 00381 while (count < record) 00382 { 00383 if (read(f,&c,1) != 1) {close(f); return 15;} 00384 if (c == '\n') count ++; 00385 } 00386 00387 read(f,&c,1); 00388 if (c == '\n') return 0; /* can't delete an empty row, sorry */ 00389 00390 lseek(f,-1,SEEK_CUR); 00391 if (write(f,"#",1) != 1) { close(f);return 15;} 00392 close(f); 00393 #endif 00394 /* deletes a row from the database. Minor data loss. */ 00395 /* if the first row is named STATUS, everything will work great! */ 00396 00397 return 0; 00398 }
|
|
Definition at line 332 of file cgi_data.c. References DatabaseReset(), and SkipLines(). Referenced by CGImain(). 00333 { 00334 if (skiprecords < 0) return DatabaseReset(database); 00335 if (skiprecords == 0) return 0; 00336 return SkipLines(database,skiprecords); 00337 }
|
|
Returns 1 on success. Definition at line 72 of file cgi_search.c. References DatabaseReadRecord(), Matches(), and NULL. Referenced by DeleteOldRecords(), and FindUserRecordASC(). 00075 { 00076 while (1) 00077 { 00078 int flags = 0; 00079 if (pos) *pos = ftell(database); 00080 if (DatabaseReadRecord(database, header,&flags) == 0) break; 00081 if (flags != 0) continue; /* indicates a deleted record */ 00082 00083 if (query == NULL) return 1; 00084 00085 if (Matches(header,query)) return 1; 00086 } 00087 return 0; /* ran out */ 00088 }
|
|
Returns 1 on success. Query logic is the same as for scripted IF statements. Definition at line 31 of file cgi_search.c. References CGIFREE, DatabaseReadRecord(), EvaluateLogic(), NULL, and strdup(). Referenced by CGImain(), EZSReport(), and JSHasRecord(). 00035 { 00036 int ret = 0; 00037 char * Comparison = strdup(query); 00038 00039 while (1) 00040 { 00041 int flags = 0; 00042 00043 if (DatabaseReadRecord(database, header,&flags) == 0) break; 00044 if (flags != 0) continue; /* indicates a deleted record */ 00045 00046 if (query == NULL) {ret = 1; break;} 00047 00048 if (EvaluateLogic(Comparison,header,cgidata)) {ret = 1; break;} 00049 strcpy(Comparison,query); 00050 } 00051 CGIFREE(Comparison); 00052 return ret; /* ran out */ 00053 }
|
|
Definition at line 294 of file cgi_data.c. References _loaddbheader(), CGIFCLOSE, CGIFOPEN, DATABASE, and NULL. Referenced by CGImain(), DatabaseSaveIndex(), DatabaseSaveNewRecord(), EZSReport(), JSHasRecord(), LoadUserDataASC(), and Login(). 00295 { 00296 /*char newname[MAXPATH]; */ 00297 DATABASE * file; 00298 int ret; 00299 #ifdef __BORLANDC__ 00300 file = CGIFOPEN(filename,"rb+"); /* open a buffered file in text mode*/ 00301 #else 00302 file = CGIFOPEN(filename,rw ? "rb+" : "rb"); /* open a buffered file in text mode*/ 00303 #endif 00304 00305 if (database) { *database = file; } 00306 00307 if (file == NULL) 00308 { 00309 if (header) *header = 0; 00310 ret = 0; 00311 } 00312 else 00313 { 00314 CGINameValue * v = _loaddbheader(file,extra); 00315 if (header) *header = v; 00316 ret = v ? 1 : 0; 00317 if (database == NULL) CGIFCLOSE(file); 00318 } 00319 return ret; 00320 }
|
|
When reading data, it uses FixQuotes() to remove leading/trailing quotes and convert doubled quotes to single quotes. The file pointer is advanced to the next record. v comes from DatabaseOpen(). Definition at line 449 of file cgi_data.c. References CGIFREE, CGIMALLOC, FixQuotes(), MAXDATA, CGINameValue::name, NULL, ReadUntilChar(), ResetList(), strdup(), UnfixQuotes(), and CGINameValue::value. Referenced by CGImain(), DatabaseFindFast(), DatabaseFindNextRecord(), LoadUserDataASC(), and PrintRecords(). 00450 { 00451 int c = 0; 00452 char*d = 0; 00453 char *data = 0; 00454 int any = 0; 00455 00456 data = CGIMALLOC(MAXDATA); 00457 00458 if (flags) *flags = 0; 00459 if (data == NULL) return 0; 00460 00461 ResetList(v); /* clear the record, just to be sure */ 00462 00463 do { 00464 if (v->name == NULL) /* end of header, but not end of line? */ 00465 { /* finish off the line and continue */ 00466 ReadUntilChar(database,0,0,"\n",0); 00467 break; 00468 } 00469 c = ReadUntilChar(database,data,MAXDATA,"\t\n",'\r'); 00470 00471 d = strchr(data,'\r'); 00472 if (d != NULL) *d = 0; /* just in case we opened it in binary mode */ 00473 00474 if (any == 0 && flags != NULL) 00475 { 00476 switch (data[0]) 00477 { case 0 : *flags = 2; if (*data) if (strstr(data+1,"\"\t")) data[0]='\"'; break; 00478 case '#': *flags = 1; if (*data) if (strstr(data+1,"\"\t")) data[0]='\"'; break; 00479 default: *flags = 0; 00480 } 00481 } 00482 00483 if (*data) 00484 { 00485 v->value = strdup(data); 00486 if (v->value[0] == '\"') 00487 UnfixQuotes(v->value); 00488 any = 1; 00489 } 00490 00491 v++; 00492 00493 if (c == EOF ) /* premature end of file */ 00494 { 00495 CGIFREE(data); 00496 if (any) FixQuotes(v); 00497 return any; 00498 } 00499 } while (c != '\n'); 00500 00501 CGIFREE(data); 00502 if (any) FixQuotes(v); 00503 return any; 00504 }
|
|
Definition at line 322 of file cgi_data.c. References SkipLines(). Referenced by DatabaseFFD(). 00323 { 00324 #ifdef __WINCE__ 00325 fseek(database,0,SEEK_SET); 00326 #else 00327 rewind(database); 00328 #endif 00329 return SkipLines(database,1); 00330 }
|
|
Definition at line 568 of file cgi_data.c. References CGIFOPEN, DatabaseClose(), DatabaseOpen(), GetFieldValue, and NULL. 00569 { 00570 FILE * indexdb; 00571 CGINameValue * indexheader; 00572 int ret = 0; 00573 00574 if (DatabaseOpen(indexfile,&indexdb,&indexheader,0,0)) 00575 { 00576 FILE* ndx; 00577 00578 DatabaseClose(indexdb,NULL); 00579 ndx = CGIFOPEN(indexfile,"ab"); 00580 if (ndx) 00581 { 00582 size_t i; 00583 for ( i=0; indexheader[i].name; i++) 00584 { 00585 if (!strcmp(indexheader[i].name,"_POS")) 00586 { fprintf(ndx,"%d",pos); } 00587 else 00588 { fprintf(ndx,"\"%s\"\t",GetFieldValue(Params,indexheader[i].name)); } 00589 } 00590 fprintf(ndx,"\n"); 00591 fclose(ndx); 00592 } 00593 else 00594 ret = 9; 00595 00596 DatabaseClose(NULL,indexheader); 00597 } 00598 return ret; 00599 }
|
|
Uses WriteValue() to save data in a quoted, tab-delimited file. Linefeeds and newlines are removed, but data inside quotes can have tabs, and Excel 97 will read it fine. Definition at line 605 of file cgi_data.c. References BufferWriteL(), DatabaseClose(), DatabaseOpen(), MAXPATH, CGINameValue::name, NewBuffer(), NULLSTR, stricmp(), CGINameValue::value, and WriteValue(). Referenced by SaveDataToASC(). 00606 { 00607 int x,y; 00608 CGINameValue * header; 00609 char *c, * lastfieldname; 00610 int ret = 0, writecomma; 00611 #ifdef XP_WIN 00612 HANDLE fh; 00613 DWORD written=0; 00614 #ifndef VPWSCGI 00615 HANDLE Mutex; 00616 #endif 00617 #else 00618 TextBuffer * buf; 00619 int fh; 00620 static struct flock myLock ; 00621 #endif 00622 00623 if (!DatabaseOpen(filename,0,&header,0,0)) 00624 { 00625 /*LogError("\nTried to read a data file, failed: "); 00626 LogError(filename);*/ 00627 return 2; 00628 } 00629 00630 /* do this early to minimize the time the file is open 00631 if (!DoesFileMatchForm(v, header)) ret = 5; 00632 */ 00633 00634 00635 /* personal web server is single-threaded, no need for file locks */ 00636 #if defined(XP_WIN) && !defined(VPWSCGI) 00637 { 00638 #ifdef UNICODE 00639 wchar_t Mutex_name[MAXPATH+1]; 00640 ToWideChar(_filename,strlen(_filename),Mutex_name,MAXPATH); 00641 #else 00642 char Mutex_name[MAXPATH+1]; 00643 strncpy(Mutex_name,filename,MAXPATH); 00644 #endif 00645 Mutex_name[MAXPATH] = 0; 00646 for (x=0; Mutex_name[x]; x++) if (Mutex_name[x] == '\\') Mutex_name[x] = '/'; 00647 Mutex = CreateMutex(0,FALSE,Mutex_name); 00648 00649 /* wait up to 20 seconds */ 00650 if(Mutex) if ( WaitForSingleObject(Mutex,20000) == WAIT_TIMEOUT) 00651 { 00652 CloseHandle(Mutex); 00653 DatabaseClose(0,header); 00654 return 23; 00655 } 00656 } 00657 #endif 00658 00659 #ifdef XP_WIN /* binary mode, direct write */ 00660 00661 #ifdef __WINCE__ 00662 { 00663 wchar_t fn[MAXPATH+1]; 00664 ToWideChar(filename,strlen(filename),fn,MAXPATH+1); 00665 fh = CreateFileW(fn,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); 00666 } 00667 #else 00668 fh = CreateFileA(filename,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0); 00669 #endif 00670 00671 if (fh == INVALID_HANDLE_VALUE) 00672 { 00673 #if !defined(VPWSCGI) 00674 if (Mutex) CloseHandle(Mutex); 00675 #endif 00676 x = GetLastError(); 00677 return 6; 00678 } 00679 x = SetFilePointer(fh,0,0,FILE_END); 00680 #else 00681 fh = open(filename,O_WRONLY|O_APPEND); 00682 00683 if (fh == -1) 00684 { 00685 return 6; 00686 } 00687 #endif 00688 00689 00690 /* Wait for a file lock to become available */ 00691 #ifdef XP_POSIX 00692 myLock.l_type = F_WRLCK ; 00693 myLock.l_start = 0 ; 00694 myLock.l_whence = SEEK_END ; 00695 myLock.l_len = 0 ; 00696 myLock.l_pid = getpid() ; 00697 fcntl(fh, F_SETLKW, &myLock); 00698 #endif 00699 00700 if (pos) 00701 { 00702 #ifdef XP_WIN 00703 *pos = x; 00704 #else 00705 *pos = lseek(fh,0,SEEK_END); 00706 #endif 00707 } 00708 00709 #ifndef XP_WIN 00710 buf = NewBuffer(16384); 00711 #endif 00712 00713 for(x=0; header[x].name; x++) 00714 { 00715 /* if two consecutive questions have the same fieldname, append their data together */ 00716 if (!header[x].name[0]) continue; 00717 /*don't write empty fieldnames */ 00718 00719 #ifdef XP_WIN 00720 WriteFile(fh,"\"",1,&written,0); 00721 #else 00722 BufferWriteL(buf,"\"",1); 00723 /* write(fh,"\"",1); */ 00724 #endif 00725 y = 0; 00726 lastfieldname = NULLSTR; 00727 writecomma = 0; 00728 while (v[y].name) 00729 { 00730 if (v[y].name[0] && stricmp(header[x].name,v[y].name)==0) 00731 {/*write this entry*/ 00732 c = v[y].value; 00733 if ( c && *c ) 00734 { 00735 if (*lastfieldname && writecomma) 00736 #ifdef XP_WIN 00737 WriteFile(fh,",",1,&written,0); 00738 WriteValue(fh,c); 00739 #else 00740 BufferWriteL(buf,",",1); 00741 WriteValue(buf,c); 00742 /* write(fh,",",1); WriteValue(fh,c); */ 00743 #endif 00744 if (*c) writecomma = 1; 00745 } 00746 lastfieldname=header[x].name; 00747 } 00748 y++; 00749 } 00750 #ifdef XP_WIN 00751 WriteFile(fh,"\"\t",2,&written,0); 00752 #else 00753 BufferWriteL(buf,"\"\t",2); 00754 /*write(fh,"\"\t",2); */ 00755 #endif 00756 } 00757 00758 #ifdef XP_WIN 00759 WriteFile(fh,"\r\n",2,&written,0); 00760 #else 00761 BufferWriteL(buf,"\r\n",2); 00762 /*write(fh,"\r\n",2);*/ 00763 #endif 00764 00765 #if defined(XP_WIN) && !defined(VPWSCGI) 00766 if (Mutex) 00767 { 00768 ReleaseMutex(Mutex); 00769 CloseHandle(Mutex); 00770 } 00771 #endif 00772 00773 #ifndef XP_WIN 00774 c = CopyBuffer(buf); 00775 x = lseek(fh,0,SEEK_END); 00776 if (pos) *pos = x; 00777 write(fh,c,BufferSize(buf)); 00778 free(c); 00779 DeleteBuffer(buf); 00780 #endif 00781 00782 #ifdef XP_POSIX 00783 myLock.l_type = F_UNLCK; 00784 fcntl(fh, F_SETLKW, &myLock); 00785 #endif 00786 00787 #ifdef XP_WIN 00788 CloseHandle(fh); 00789 #else 00790 close(fh); 00791 #endif 00792 00793 DatabaseClose(0,header); 00794 return ret; 00795 }
|
|
Searches the current record for any instance of a substring. If found, it returns 1 and positions the database pointer to the beginning of the record. If a substring is not found, it advances the pointer to the next record. Definition at line 156 of file cgi_search.c. References CGIFREE, MAXDATA, ReadUntilChar(), and stristr(). 00157 { 00158 int c; 00159 char *name = malloc(MAXDATA); 00160 long int fpos; 00161 int column=0; 00162 00163 fpos = ftell(database); 00164 if (fpos < 0) 00165 { 00166 CGIFREE(name); 00167 return -1; 00168 } 00169 do { 00170 c = ReadUntilChar(database,name,MAXDATA,"\t\n",'\r'); 00171 if (column++ == 0 && name[0] == '#') 00172 { /* skip comment lines and deleted records */ 00173 ReadUntilChar(database,name,MAXDATA,"\n",'\r'); 00174 CGIFREE(name); 00175 return 0; 00176 } 00177 00178 if (name[0] == 0) continue; /* skip blank fields */ 00179 if (casesensitive) 00180 { 00181 if (strstr(name,querystr)) 00182 { 00183 fseek(database,fpos,0); 00184 CGIFREE(name); 00185 return 1; 00186 } 00187 } 00188 else 00189 { 00190 if (stristr(name,querystr)) 00191 { 00192 fseek(database,fpos,0); 00193 CGIFREE(name); 00194 return 1; 00195 } 00196 } 00197 } while (c != '\r' && c != '\n' && c != EOF); 00198 00199 CGIFREE(name); 00200 return 0; 00201 }
|
|
Definition at line 1159 of file cgi_util.c. References HTMLWrite(), CGINameValue::name, and CGINameValue::value. Referenced by CGImain(), Error(), and PrintFinish(). 01160 { 01161 if (!htmlout) return; 01162 while (v->name) 01163 { 01164 if (*v->name) 01165 { 01166 HTMLWrite(htmlout,v->name); 01167 if (v->value) 01168 { 01169 HTMLWrite(htmlout,"="); 01170 HTMLWrite(htmlout,v->value); 01171 } 01172 HTMLWrite(htmlout,"\n"); 01173 } 01174 v++; 01175 } 01176 }
|
|
Definition at line 376 of file cgi_util.c. References CGIFREE, TextBuffer::data, and TextBuffer::Next. Referenced by CGImain(), DeleteStream(), EvaluateArgument(), JSReport(), LoadUserDataSQL(), ODBCDisconnect(), SaveData(), and TryODBC(). 00377 { 00378 while (t) 00379 { 00380 TextBuffer* n = t->Next; 00381 CGIFREE(t->data); 00382 CGIFREE(t); 00383 t = n; 00384 } 00385 }
|
|
deletes a list, deallocating strings with CGIFREE() Definition at line 1865 of file cgi_util.c. References CGIFREE, DeleteNVP(), and NULL. Referenced by _loaddbheader(), AdminPrintPage(), Authenticate(), CGImain(), DatabaseClose(), DeleteNVP(), EZSCounts(), FindUserRecordASC(), GetSecurityFlags(), Index(), LoadUserDataSQL(), LogStartup(), main(), ODBCRead(), ProjectUpdate(), ReadCGIPostData(), RunReportF(), ShowFormPage(), SpaceUpdate(), UserAddSpace(), UserList(), UserUpdate(), VerifyPassword(), VerifyUser(), and WFmain(). 01866 { 01867 int i,l; 01868 if (v == NULL) return; 01869 for (i=0; v[i].last == 0 ; i++) 01870 { 01871 if (v[i].name) CGIFREE(v[i].name); 01872 if (v[i].value) CGIFREE(v[i].value); 01873 l=i; 01874 } 01875 l++; 01876 if (v[l].last && v[l].value) 01877 { 01878 DeleteNVP((CGINameValue*)(void*)v[l].value); 01879 } 01880 CGIFREE(v); 01881 }
|
|
Definition at line 972 of file cgi_util.c. References CGIFREE, and DeleteBuffer(). 00973 { 00974 if (!str) return; 00975 if (str->t) DeleteBuffer(str->t); 00976 CGIFREE(str); 00977 }
|
|
Recursive mathematical evaluation, with variables stored in v. Nifty, huh? Parentheses are respected, but order of operations is ignored. Since this uses a global value to store the result, you better use it fast or copy it to another memory location. Definition at line 1369 of file cgi_util.c. References CGIFREE, Div(), EATWHITE, EvaluateAlgebraL(), FindEndChar(), GetField2(), IsNumber(), NULL, Power(), strdup(), and strndup(). Referenced by EvaluateAlgebraL(), and EvaluateExpression(). 01370 { 01371 char * c, *left, *right; 01372 double lastmath; 01373 size_t length; 01374 01375 if (equation == NULL) return 0.0; 01376 01377 EATWHITE(equation); 01378 if (*equation == '=') equation++; 01379 01380 c = strrchr(equation,' '); /* strip trailing blanks */ 01381 if (c) *c = 0; 01382 01383 /* the number of characters in the first part of the expression */ 01384 length = strcspn(equation,"(+-*/^%"); 01385 01386 /* if that's all there is, return the replacement value of the field */ 01387 if ((length) == strlen(equation)) 01388 return strtod(GetField2(v,v2,equation),0); 01389 01390 /* copy out the mathematical section of the expression */ 01391 right = strdup(equation + length); /* fmath=operator + rvalue */ 01392 01393 /* copy out the leading fieldname of the expression */ 01394 left = strndup(equation,length); /* fname=lvalue */ 01395 01396 /* if it's non-blank, get the replacement value */ 01397 if (*left && !IsNumber(left,0)) 01398 c = GetField2(v,v2,left); 01399 else 01400 c = 0; /* else, ignore the first statement */ 01401 01402 if (c && *c) 01403 lastmath = strtod(c,0); /* lastmath is the accumulated return value */ 01404 else 01405 lastmath = strtod(left,0); /* the thing on the left was probably a number */ 01406 01407 c = right; /* start working on the next part */ 01408 01409 while (c && *c) /* iterate through that section */ 01410 { 01411 double math; 01412 char * d, * argument ; /* variables we'll need */ 01413 EATWHITE(c); /* duh */ 01414 if (*c == '(') /* is it parenthesized? */ 01415 argument = c; 01416 else 01417 argument = c + 1; 01418 EATWHITE(argument); 01419 if (isdigit(*argument)) /* it's just a number */ 01420 math = strtod(argument,&d); 01421 else if (*argument != '(') /* evaluate the next variable name */ 01422 { 01423 length = strcspn(argument,"(+-*/^% \t\r\n"); 01424 d = argument+length; 01425 math = EvaluateAlgebraL(v,v2,argument,length); 01426 } 01427 else /* recurse through parentheses */ 01428 { 01429 int l = FindEndChar(argument,'(',')',0); /* where does the parenthesis end? */ 01430 d = argument + l + 1; 01431 if (l < 2) break; /* whoops! someone screwed up. Can't have empty parens.*/ 01432 math = EvaluateAlgebraL(v,v2,argument+1,l-2); 01433 } 01434 01435 switch (*c) { 01436 case '(': lastmath = math; break; /* only happens when the expression begins with a paren */ 01437 case '+': lastmath += math; break; 01438 case '-': lastmath -= math; break; 01439 case '*': lastmath *= math; break; 01440 case '^': lastmath = Power(lastmath,math); break; 01441 case '/': lastmath = Div(lastmath,math); break; 01442 case '%': lastmath = ((int)(math)) ?((int)lastmath)%(int)(math):0; break; 01443 default: break; /* leave while loop */} 01444 c = d; 01445 } /* of while */ 01446 01447 CGIFREE(left); 01448 CGIFREE(right); 01449 return lastmath; 01450 }
|
|
In case of error, lastc = Comparison. EvaluateComparison() may modify the input string. Logical operators are
Definition at line 1751 of file cgi_util.c. References DoEvaluateComparison(). Referenced by FormatReplacement(). 01752 { 01753 return DoEvaluateComparison(Comparison ,v,Var2,lastc,1); 01754 }
|
|
if equation is a single word, it looks up the variable from v. Otherwise, returns a new string containing the value returned by EvaluateAlgebra(). Variables beginning with $ are taken from v2. Definition at line 1341 of file cgi_util.c. References CGIMALLOC, EATWHITE, EvaluateAlgebra(), GetField2(), IsNumber(), and strdup(). Referenced by EvaluateArgument(), EvaluateExpressionL(), FormatReplacement(), and JSEval(). 01342 { 01343 char *c = strrchr(equation,' '); /* strip trailing blanks */ 01344 if (c) *c = 0; 01345 EATWHITE(equation); 01346 /* an equation or a number*/ 01347 if (strcspn(equation,"(+-*/^%") != strlen(equation)) 01348 { 01349 double d = EvaluateAlgebra(v,v2,equation); 01350 int i = (int)d; 01351 char*t = CGIMALLOC(64); 01352 if (i == d) 01353 sprintf(t,"%d",i); 01354 else 01355 sprintf(t,"%f",d); 01356 return t; 01357 } 01358 else if (IsNumber(equation,0)) 01359 return strdup(equation); 01360 else 01361 return strdup(GetField2(v,v2,equation)); 01362 }
|
|
Definition at line 1307 of file cgi_util.c. References CGIFREE, CGIMALLOC, and EvaluateExpression(). Referenced by DoEvaluateComparison(), and FormatReplacement(). 01308 { 01309 char * c; 01310 char * x = CGIMALLOC(length+1); 01311 strncpy(x,equation,length); 01312 x[length]=0; 01313 c = EvaluateExpression(v,v2,x); 01314 CGIFREE(x); 01315 return c; 01316 }
|
|
EvaluateLogic() does not modify the input. Nested parenthesis are allowed. Logical operators are && & || | ^^ ^ (a=b && c gt e || d =! $var2) Definition at line 1535 of file cgi_util.c. References DoEvaluateLogic(). Referenced by DatabaseFindNextRecord(), PrintRecords(), RunReportF(), RunScript(), UpdateCounts(), and UpdateStatistics(). 01536 { 01537 return DoEvaluateLogic(line,Variables,Var2,0,1); 01538 }
|
|
out = /path.../InExtension Definition at line 639 of file cgi_util.c. Referenced by CGImain(), EZSCounts(), EZSReport(), EZSSource(), FileOpen(), GetProjectExtra(), GetRespcount(), GetSecurityFlags(), Index(), JSHasRecord(), JSReport(), LoadUserDataASC(), Login(), LogStartup(), main(), OpenPage(), Project(), ProjectUpdate(), SaveData(), SendImage(), SetRespcount(), ShowFormPage(), Space(), SpaceAdd(), SpaceUpdate(), User(), UserAdd(), UserAddSpace(), UserList(), UserUpdate(), VerifyPassword(), VerifyUser(), and WFmain(). 00640 { 00641 char * c; 00642 #ifdef XP_WIN 00643 int i; 00644 #endif 00645 #ifdef __WINCE__ /* fully qualified path already? */ 00646 if (finish[0] == '\\') 00647 #elif defined XP_WIN 00648 if ((finish[0] == '\\' && finish[1] == '\\') || (finish[0] != 0 && finish[1] == ':')) 00649 #else /* unix */ 00650 if (finish[0] == '/') 00651 #endif 00652 { 00653 strcpy(fn,finish); 00654 if (a != NULL) strcat(fn,a); 00655 return; 00656 } 00657 00658 strcpy(fn,argv0); 00659 #ifdef XP_WIN 00660 c = strrchr(fn,'\\'); 00661 #else 00662 c = strrchr(fn,'/'); 00663 #endif 00664 if (c) 00665 { 00666 c++; 00667 } 00668 else 00669 { 00670 #ifdef __WINCE__ 00671 strcpy(fn,serverRootA); 00672 #else 00673 getcwd(fn, MAXPATH); 00674 #ifdef XP_WIN 00675 strcat(fn, "\\"); 00676 #else 00677 strcat(fn, "/"); 00678 #endif 00679 #endif 00680 c = fn + strlen(fn); 00681 00682 } 00683 strcpy(c,finish); 00684 if (a != NULL) strcat(c,a); 00685 #ifdef XP_WIN 00686 for (i=0; c[i]; i++) 00687 if (c[i] == '/') c[i] = '\\'; 00688 #endif 00689 }
|
|
Decodes URLs, returns the string length. Definition at line 336 of file cgi_util.c. References x2c(). Referenced by ReadCGIGetData(), and ReadCGIPostData(). 00336 { 00337 register int x,y; 00338 00339 for(x=0,y=0;url[y];++x,++y) { 00340 if((url[x] = url[y]) == '%') { 00341 url[x] = x2c(&url[y+1]); 00342 y+=2; 00343 } 00344 } 00345 url[x] = '\0'; 00346 return x; /* return the finished string length */ 00347 }
|
|
Allows adding 'shadow' variables for JS. Variables are accessible by GetField('name'), but not by index Definition at line 1883 of file cgi_util.c. References ExtendNVP(), CGINameValue::name, NewNVP(), NULL, NULLSTR, strdup(), and CGINameValue::value. Referenced by DoSetValue(), ExtendNVP(), and RunScript(). 01884 { 01885 size_t i,l; 01886 if (v == NULL) return; 01887 for (i=0; v[i].last == 0 ; i++) 01888 { 01889 l=i; 01890 } 01891 l++; 01892 if (v[l].last) 01893 { 01894 if (v[l].value) 01895 ExtendNVP((CGINameValue*)(void*)v[l].value,count); 01896 else 01897 { 01898 CGINameValue* n = NewNVP(count); 01899 v[l].value = (char*)(void*)n; 01900 for (i=0; i<count; i++) 01901 { 01902 n[i].name = strdup(NULLSTR); 01903 } 01904 } 01905 } 01906 }
|
|
runs ExpandLocalPath and opens a file in the program directory Definition at line 562 of file cgi_util.c. References CGIFOPEN, ExpandLocalPath(), and MAXPATH. Referenced by CGImain(), EZSInclude(), ODBCRunScript(), PrintFinish(), SaveData(), ShowForm(), ShowFormPage(), ValidateBack(), ValidatePage(), and WFmain(). 00563 { 00564 char filename[MAXPATH]; 00565 if (!file) return 0; 00566 if (!*file) return 0; 00567 ExpandLocalPath(argv0,filename,file,extension); 00568 return CGIFOPEN(filename,"rb"); 00569 }
|
|
Definition at line 2098 of file cgi_util.c. Referenced by ReadINIFileSection(), and WriteINIFileSection(). 02099 { 02100 struct stat StatBuf; 02101 if (!fname) return 0; 02102 if (!*fname) return 0; 02103 if (stat(fname, & StatBuf) != 0) return 0; 02104 return StatBuf.st_size; 02105 }
|
|
Definition at line 334 of file cgi_cgi.c. Referenced by CGImain(), CheckCGISendMethod(), JSGetEnv(), LogStartup(), main(), PrintFinish(), ReadCGIGetData(), and SetupCGIData(). 00335 { 00336 #ifdef WINCGI 00337 GetPrivateProfileString("System",key,NULLSTR,WINCGIenv,256,WinCGIFile); 00338 return WINCGIenv; 00339 #elif defined(FASTCGI) 00340 return FCGX_GetParam(key,htmlout->envp); 00341 #else 00342 return getenv(key); 00343 #endif 00344 }
|
|
Definition at line 1908 of file cgi_util.c. References CGINameValue::last, NULL, and stricmp(). Referenced by CalcCountSummary(), CGImain(), CheckPass(), CopyListJoin(), DoesFileMatchForm(), FindUserRecordASC(), GetSetting(), LoadUserDataASC(), Login(), LogStartup(), Matches(), RenameField(), SetFieldValue(), ShowFormPage(), UpdateStatistics(), ValidateBack(), and ValidatePage(). 01909 { 01910 int x,i=0; 01911 if (data == NULL) 01912 return NULL; 01913 01914 for(x=0; data[x].last == 0; x++) 01915 { 01916 i = x; 01917 if (!data[x].name) 01918 continue; 01919 01920 if (!data[x].name[0] && !fieldname[0]) 01921 return &data[x]; 01922 01923 if (stricmp(fieldname,data[x].name)==0) 01924 return &data[x]; 01925 } 01926 01927 i++; 01928 01929 if (data[i].last && data[i].value) 01930 return GetField((CGINameValue*)(void*)data[i].value,fieldname); 01931 01932 return NULL; 01933 }
|
|
Gets global security for a site Definition at line 84 of file cgi_access.c. References CGI_ALLOW_ADMIN, CGI_ALLOW_ALL, CGI_ALLOW_APPEND, CGI_ALLOW_DELETE, CGI_ALLOW_NONE, CGI_ALLOW_READ, CGI_ALLOW_REPORT, CGI_ALLOW_UPDATE, CGI_ALLOW_WRITE, CheckAllowDeny(), CheckPass(), DeleteNVP(), ExpandLocalPath(), GetFieldValue, LogError(), MAXPATH, NULL, and ReadINIFileSection(). Referenced by CGImain(). 00085 { 00086 int i = CGI_ALLOW_NONE; /* default settings for a database */ 00087 CGINameValue *n; 00088 #ifdef CGI_ALLOW 00089 CGINameValue *m; 00090 #endif 00091 00092 int j = strcspn(database,"/.\\*?$|'\"<>~"); 00093 00094 if (database[j] != 0 || strlen(database) > 128 || strlen(pwd) > 128) 00095 { 00096 LogError("\nSecurity breach attempted\tHOST="); 00097 LogError(host); 00098 return CGI_ALLOW_NONE; 00099 } 00100 /* stop buffer overflow attacks */ 00101 00102 #ifdef CGI_ALLOW 00103 { 00104 char fn[MAXPATH]; 00105 ExpandLocalPath(argv0,fn,"cgi",".ini"); 00106 m = ReadINIFileSection(fn,"access",0); 00107 00108 /*m = LoadSettings(argv0,"cgi","access");*/ 00109 } 00110 #endif 00111 00112 n = NULL; 00113 if (database != NULL) 00114 if (database[0] != 0) 00115 { 00116 char fn[MAXPATH]; 00117 ExpandLocalPath(argv0,fn,database,".ini"); 00118 n = ReadINIFileSection(fn,"access",0); 00119 /*n = LoadSettings(argv0, database, "access");*/ 00120 } 00121 00122 if (n != NULL) 00123 { 00124 CheckPass(n,&i,CGI_ALLOW_READ,pwd,"PWDREAD"); 00125 CheckPass(n,&i,CGI_ALLOW_UPDATE,pwd,"PWDUPDATE"); 00126 CheckPass(n,&i,CGI_ALLOW_APPEND,pwd,"PWDAPPEND"); 00127 CheckPass(n,&i,CGI_ALLOW_DELETE,pwd,"PWDDELETE"); 00128 CheckPass(n,&i,CGI_ALLOW_WRITE,pwd,"PWDWRITE"); 00129 CheckPass(n,&i,CGI_ALLOW_ADMIN,pwd,"PWDADMIN"); 00130 CheckPass(n,&i,CGI_ALLOW_REPORT,pwd,"PWDREPORT"); 00131 CheckPass(n,&i,CGI_ALLOW_ALL,pwd,"PWD"); 00132 } 00133 00134 #ifdef CGI_ALLOW 00135 if (n != NULL) 00136 { 00137 if (CheckAllowDeny(host,GetFieldValue(n,"ALLOW"), 00138 GetFieldValue(n,"DENY")) ==0) i = CGI_ALLOW_NONE; 00139 00140 if (i && m != NULL) 00141 if (CheckAllowDeny(host,GetFieldValue(m,"ALLOW"), 00142 GetFieldValue(m,"DENY")) ==0) i = CGI_ALLOW_NONE; 00143 00144 if (i) CheckAllow(host,n,"ALLOWREAD","DENYREAD",CGI_ALLOW_READ,&i); 00145 if (i) CheckAllow(host,n,"ALLOWUPDATE","DENYUPDATE",CGI_ALLOW_UPDATE,&i); 00146 if (i) CheckAllow(host,n,"ALLOWAPPEND","DENYAPPEND",CGI_ALLOW_APPEND,&i); 00147 if (i) CheckAllow(host,n,"ALLOWWRITE","DENYWRITE",CGI_ALLOW_WRITE,&i); 00148 if (i) CheckAllow(host,n,"ALLOWDELETE","DENYDELETE",CGI_ALLOW_DELETE,&i); 00149 if (i) CheckAllow(host,n,"ALLOWREPORT","DENYREPORT",CGI_ALLOW_REPORT,&i); 00150 if (i) CheckAllow(host,n,"ALLOWADMIN","DENYADMIN",CGI_ALLOW_ADMIN,&i); 00151 } 00152 00153 /* if access is granted by the password, check domains */ 00154 if (m != NULL) 00155 { 00156 if (i) CheckAllow(host,m,"ALLOWREAD","DENYREAD",CGI_ALLOW_READ,&i); 00157 if (i) CheckAllow(host,m,"ALLOWUPDATE","DENYUPDATE",CGI_ALLOW_UPDATE,&i); 00158 if (i) CheckAllow(host,m,"ALLOWAPPEND","DENYAPPEND",CGI_ALLOW_APPEND,&i); 00159 if (i) CheckAllow(host,m,"ALLOWWRITE","DENYWRITE",CGI_ALLOW_WRITE,&i); 00160 if (i) CheckAllow(host,m,"ALLOWDELETE","DENYDELETE",CGI_ALLOW_DELETE,&i); 00161 if (i) CheckAllow(host,m,"ALLOWREPORT","DENYREPORT",CGI_ALLOW_REPORT,&i); 00162 if (i) CheckAllow(host,m,"ALLOWADMIN","DENYADMIN",CGI_ALLOW_ADMIN,&i); 00163 } 00164 00165 if (m != NULL) DeleteNVP(m); 00166 #endif 00167 00168 if (n != NULL) DeleteNVP(n); 00169 return i; 00170 }
|
|
Returns the appropriate settings or the default value Definition at line 705 of file cgi_util.c. References GetField(), NULL, and CGINameValue::value. Referenced by CGImain(), JSSendMail(), LoadUserData(), LoadUserDataASC(), LoadUserDataSQL(), Login(), PrintFinish(), ProjectUpdate(), SaveData(), and SpaceUpdate(). 00706 { 00707 CGINameValue * n; 00708 n = GetField(section, key); 00709 if (n == NULL) return def; 00710 if (n->value == NULL) return def; 00711 if (n->value[0] == 0) return def; 00712 return n->value; 00713 }
|
|
0 = YYYYMMDD, 1 = MM/DD/YYYY, 2 = DD/MM/YYYY Definition at line 1178 of file cgi_util.c. Referenced by CGImain(), JSTimeDate(), JSTimeStamp(), JSTimeTime(), LogConnection(), and SetupCGIData(). 01179 { 01180 #ifdef __WINCE__ 01181 SYSTEMTIME tb; 01182 01183 /* gets time of day */ 01184 GetLocalTime(&tb); 01185 01186 switch (type) 01187 { 01188 case 2: 01189 if (Date) sprintf(Date,"%2.2d/%2.2d/%4.4d", 01190 tb.wMonth,tb.wDay,tb.wYear); 01191 if (Time) sprintf(Time,"%2.2d:%2.2d:%2.2d", 01192 tb.wHour,tb.wMinute,tb.wSecond); break; 01193 case 1: 01194 if (Date) sprintf(Date,"%2.2d/%2.2d/%4.4d", 01195 tb.wDay,tb.wMonth,tb.wYear); 01196 if (Time) sprintf(Time,"%2.2d:%2.2d:%2.2d", 01197 tb.wHour,tb.wMinute,tb.wSecond); break; 01198 01199 default: 01200 if (Date) sprintf(Date,"%4.4d%2.2d%2.2d", 01201 tb.wYear,tb.wMonth,tb.wDay); 01202 if (Time) sprintf(Time,"%2.2d%2.2d%2.2d", 01203 tb.wHour,tb.wMinute,tb.wSecond); 01204 } 01205 01206 #else 01207 time_t timer; 01208 struct tm *tb; 01209 01210 /* gets time of day */ 01211 time(&timer); 01212 01213 /* converts date/time to a structure */ 01214 tb = localtime(&timer); 01215 switch (type) 01216 { 01217 case 2: 01218 if (Date) sprintf(Date,"%2.2d/%2.2d/%4.4d", 01219 tb->tm_mday,tb->tm_mon+1,tb->tm_year+1900); 01220 if (Time) sprintf(Time,"%2.2d:%2.2d:%2.2d", 01221 tb->tm_hour,tb->tm_min,tb->tm_sec); break; 01222 case 1: 01223 if (Date) sprintf(Date,"%2.2d/%2.2d/%4.4d", 01224 tb->tm_mon+1,tb->tm_mday,tb->tm_year+1900); 01225 if (Time) sprintf(Time,"%2.2d:%2.2d:%2.2d", 01226 tb->tm_hour,tb->tm_min,tb->tm_sec); break; 01227 01228 default: 01229 if (Date) sprintf(Date,"%4.4d%2.2d%2.2d", 01230 tb->tm_year+1900,tb->tm_mon+1,tb->tm_mday); 01231 if (Time) sprintf(Time,"%2.2d%2.2d%2.2d", 01232 tb->tm_hour,tb->tm_min,tb->tm_sec); 01233 } 01234 #endif 01235 }
|
|
searches a comma-delimited string for a specific token Definition at line 908 of file cgi_util.c. References HasTokenX(). Referenced by Authenticate(), CalcCountSummary(), CGImain(), CheckFileName(), CheckPass(), ComparisonEvaluation(), IsValueSelected(), JSRankIndex(), JSShowPage(), RunReportF(), ShowFormPage(), and VerifyPassword(). 00909 {return HasTokenX(c,code,loc,1);}
|
|
Definition at line 911 of file cgi_util.c. References HasTokenX(). Referenced by DoesFileMatchForm(), Login(), ProjectUpdate(), RunScript(), ShowFormPage(), SpaceUpdate(), UserUpdate(), and VerifyUser(). 00912 {return HasTokenX(c,code,loc,0);}
|
|
Definition at line 1032 of file cgi_util.c. References HTMLWriteL(), and UTF8ToUCS2C(). Referenced by CGImain(), FormatReplacement(), GenerateForm(), Login(), PrintRecords(), RunReportF(), SecurityError(), ShowFormPage(), and WriteHTMLAttributes(). 01033 { 01034 size_t k; 01035 int c=0; 01036 01037 if (!htmlout) return; 01038 01039 while (out && out[0]) 01040 { 01041 k = UTF8ToUCS2C(out,&c); 01042 if (k > 1) 01043 { 01044 char x[32]; 01045 sprintf(x,"&#%d;",c); 01046 HTMLWriteL(htmlout,x,strlen(x)); 01047 out += k; 01048 continue; 01049 } 01050 01051 switch (out[0]) 01052 { 01053 case '<': HTMLWriteL(htmlout,"<",4); out++; break; 01054 case '>': HTMLWriteL(htmlout,">",4); out++; break; 01055 case '&': HTMLWriteL(htmlout,"&",5); out++; break; 01056 case '\"': HTMLWriteL(htmlout,""",6); out++; break; 01057 default: HTMLWriteL(htmlout,out,1); out++; 01058 } 01059 } 01060 }
|
|
With ISAPI, HTMLPrintf uses an 8k fixed buffer. It can overflow. If there's any chance of that happening, use HTMLWrite() instead. Definition at line 987 of file cgi_util.c. References HTMLWrite(), and MAXBUF. Referenced by CGImain(), EZSError(), GenerateForm(), Login(), main(), PrintAdminForm(), PrintFinish(), PrintQueryForm(), PrintRangeLinks(), PrintRecords(), and PrintScriptError(). 00988 { 00989 if (htmlout) 00990 { 00991 va_list argptr; 00992 va_start(argptr, formatting); 00993 #ifdef FASTCGI 00994 if (htmlout->strp) 00995 { 00996 FCGX_VFPrintF(htmlout->strp,formatting,argptr); 00997 } 00998 else 00999 #endif 01000 if (htmlout->f) 01001 vfprintf(htmlout->f,formatting, argptr); 01002 else 01003 { 01004 char temp[MAXBUF]; 01005 vsprintf(temp,formatting,argptr); 01006 HTMLWrite(htmlout,temp); 01007 } 01008 01009 va_end(argptr); 01010 } 01011 }
|
|
Definition at line 552 of file cgi_util.c. References TextBuffer::data, HTMLWriteL(), TextBuffer::Next, and TextBuffer::used. 00553 { 00554 if (!htmlout) return; 00555 while (start) 00556 { 00557 HTMLWriteL(htmlout,start->data,start->used); 00558 start = (TextBuffer*)start->Next; 00559 } 00560 }
|
|
Definition at line 1079 of file cgi_util.c. References HTMLWriteL(). Referenced by CGImain(), DebugShowNVP(), Error(), EZSError(), EZSReport(), FormatReplacement(), GenerateForm(), GenerateReport(), GenerateTableHeader(), HTMLPrintf(), Instructions(), JSPrint(), Login(), main(), PrintAdminForm(), PrintCSS(), PrintFinish(), PrintInstructions(), PrintPassword(), PrintQueryForm(), PrintRangeLinks(), PrintRecords(), ReadUntilWordS2(), RecurseDirectories(), RunReportF(), SaveData(), SecurityError(), SendCGIHeader(), ShowFormPage(), ShowProgramStatus(), WFmain(), and WriteHTMLAttributes(). 01080 { 01081 if (!data) return; 01082 if (!htmlout) return; 01083 HTMLWriteL(htmlout,data,strlen(data)); 01084 }
|
|
Definition at line 1146 of file cgi_util.c. References CGIFCLOSE, CGIFOPEN, and HTMLWriteFileF(). Referenced by CGImain(), EZSSource(), main(), SendImage(), and ShowFormPage(). 01147 { 01148 FILE * handle; 01149 if (!htmlout) return 0; 01150 handle = CGIFOPEN(filename,"rb"); 01151 if (!handle) return 0; 01152 01153 HTMLWriteFileF(htmlout,handle); 01154 CGIFCLOSE(handle); 01155 01156 return 1; 01157 }
|
|
Definition at line 1133 of file cgi_util.c. References HTMLWriteL(), and MAXPATH. Referenced by HTMLWriteFile(), and WFmain(). 01134 { 01135 char temp[MAXPATH]; 01136 size_t length; 01137 if (!htmlout) return; 01138 length = fread(temp,1,sizeof(temp),handle); 01139 while(length>0) 01140 { 01141 HTMLWriteL(htmlout,temp,length); 01142 length = fread(temp,1,sizeof(temp),handle); 01143 } 01144 }
|
|
Definition at line 1088 of file cgi_util.c. References BufferWriteL(), MAXPATH, and NULL. Referenced by CGImain(), HTMLEscape(), HTMLSend(), HTMLWrite(), HTMLWriteFileF(), PrintScriptError(), RecurseDirectories(), and RunReportF(). 01089 { 01090 if (length==0||data==NULL||htmlout==NULL) return; 01091 01092 #if defined(FASTCGI) 01093 if (htmlout->strp) 01094 FCGX_PutStr(data,length,htmlout->strp); 01095 else 01096 #endif 01097 #ifdef ISAPICGI 01098 if (htmlout->ecb !=NULL) 01099 { 01100 int c = length + htmlout->pos; 01101 if (c < MAXPATH) 01102 { 01103 memcpy(htmlout->buffer + htmlout->pos,data,length); 01104 htmlout->pos = c; 01105 return; 01106 } 01107 01108 c = MAXPATH - htmlout->pos; 01109 01110 if (c) memcpy(htmlout->buffer + htmlout->pos, data, c); 01111 htmlout->pos = MAXPATH; 01112 htmlout->ecb->WriteClient(htmlout->ecb->ConnID, (PVOID)htmlout->buffer,&htmlout->pos,0); 01113 htmlout->pos = length - c; 01114 01115 /*cache or send? */ 01116 if (htmlout->pos >= MAXPATH) 01117 { 01118 htmlout->ecb->WriteClient(htmlout->ecb->ConnID, (PVOID) (data + c), &htmlout->pos,0); 01119 htmlout->pos = 0; 01120 return; 01121 } 01122 memcpy(htmlout->buffer,data+c,htmlout->pos); 01123 } 01124 else 01125 #endif 01126 if (htmlout->f !=NULL) 01127 fwrite(data,1,length,htmlout->f); 01128 else if (htmlout->t !=NULL) 01129 BufferWriteL(htmlout->t,data,length); 01130 }
|
|
Definition at line 349 of file cgi_util.c. Referenced by DoEvaluateComparison(), EvaluateAlgebra(), EvaluateArgument(), EvaluateExpression(), JSToNumber(), and RunScript(). 00350 { /* -.3e5 */ 00351 /* int i=0; 00352 if (c[0] == '+' || c[0]=='-') i++; 00353 if (c[i] == '.') i++; 00354 if (c[i] >= '0' && c[i] <= '9') return 1;*/ 00355 char *x; 00356 size_t i; 00357 if (!c) return 0; 00358 if (!*c) return 0; 00359 strtod(c,&x); 00360 i = x - c; 00361 return ((length == 0 && *x == 0) || (length != 0 && length == i)); 00362 }
|
|
Definition at line 620 of file cgi_html.c. References HasToken(), CGINameValue::name, NULL, and stricmp(). Referenced by RunReportF(). 00621 {int x; 00622 int ret=0; 00623 for(x=0; data[x].name; x++) 00624 { 00625 if (!data[x].name[0]) continue; 00626 if (!stricmp(fieldname,data[x].name)) 00627 { 00628 ret = 2; 00629 if (!data[x].value) continue; 00630 if (data[x].value == 0 && value[0] == 0) return 1; 00631 if (HasToken(data[x].value,value,NULL)) return 1; 00632 } 00633 } 00634 return ret; 00635 }
|
|
Definition at line 338 of file cgi_js.c. References EvaluateExpression(). Referenced by AdminRunScript(), CGImain(), ODBCRunScript(), RunReportF(), ValidateBack(), ValidatePage(), and WFmain(). 00339 { 00340 if (!argc) return 0; 00341 return EvaluateExpression(Params,0,argv[0]); 00342 }
|
|
Definition at line 215 of file cgi_js.c. References GetEnvironment(), ScriptEnvironment::htmlout, and strdup(). Referenced by CGImain(), ODBCRunScript(), RunReportF(), ValidateBack(), and ValidatePage(). 00216 { 00217 #ifndef VPWSCGI 00218 char* c; 00219 if (argc == 0) return 0; 00220 c = GetEnvironment(Env->htmlout,argv[0]); 00221 if (c) return strdup(c); 00222 #endif 00223 return 0; 00224 }
|
|
Definition at line 290 of file cgi_js.c. References ScriptEnvironment::argv0, DatabaseClose(), DatabaseFindNextRecord(), DatabaseOpen(), ExpandLocalPath(), MAXPATH, and strdup(). Referenced by CGImain(), RunReportF(), and WFmain(). 00291 { 00292 FILE* database; 00293 CGINameValue* header; 00294 char dbfile[MAXPATH]; 00295 00296 int r = 0; 00297 00298 if (argc < 2) return 0; 00299 00300 if (strlen(argv[0]) > MAXPATH) return 0; 00301 00302 dbfile[0] =0; 00303 00304 if (Env->argv0) 00305 if (strlen(argv[0]) + strlen(Env->argv0) < MAXPATH ) 00306 ExpandLocalPath(Env->argv0,dbfile,argv[0],0); 00307 00308 if (DatabaseOpen(*dbfile?dbfile:argv[0],&database,&header,0,0)) 00309 { 00310 r = DatabaseFindNextRecord(database,header,Params,argv[1]); 00311 DatabaseClose(database,header); 00312 } 00313 return strdup(r?"1":"0"); 00314 }
|
|
in: jack & jill have < 2 broken heads out: jack & jill have < 2 broken heads Definition at line 236 of file cgi_js.c. References CGIMALLOC, NULL, and UTF8ToUCS2C(). Referenced by CGImain(), RunReportF(), and WFmain(). 00237 { 00238 int c=0; 00239 size_t i,j,k=1; 00240 char *in; 00241 char *out; 00242 j=0; 00243 00244 if (argc != 1) return NULL; 00245 00246 in = argv[0]; 00247 for (i=0; in[i]; i++) 00248 { 00249 j++; //2 chars, 11 bits. max 4095 -> 4 + 3 = 7 00250 //3 chars, 16 bits. max 65535 -> 5 + 3 = 8 00251 //4 chars, 23 bits. max 16777215 -> 8 + 3 = 11 00252 if (in[i] & 0x80) j+= 3; 00253 else if (strchr("<>&\"",in[i])) j += 5; 00254 } 00255 out = CGIMALLOC(strlen(in) + j); 00256 00257 j = 0; 00258 for (i=0; in[i]; ) 00259 { 00260 k = UTF8ToUCS2C(in+i,&c); 00261 if (k > 1) 00262 { 00263 j += sprintf(out+j,"&#%d;",c); 00264 i += k; 00265 } 00266 else 00267 { 00268 switch(in[i]) 00269 { 00270 case '<': memcpy(out+j,"<",4); j+=4; break; 00271 case '>': memcpy(out+j,">",4); j+=4; break; 00272 case '&': memcpy(out+j,"&",5); j+=5; break; 00273 case '\"': memcpy(out+j,""",6); j+=6; break; 00274 default: 00275 out[j++] = in[i]; 00276 } 00277 i++; 00278 } 00279 } 00280 return out; 00281 }
|
|
indexOf(string,substring,startpos,reverse) Definition at line 399 of file cgi_js.c. References strdup(), and stristr(). Referenced by AdminRunScript(), CGImain(), ODBCRunScript(), RunReportF(), ValidateBack(), ValidatePage(), and WFmain(). 00400 { 00401 char* str; 00402 char* sub; 00403 int start=0; 00404 int dir=0; 00405 int length; 00406 char*c=0; 00407 char temp[32]; 00408 if (argc < 2) return strdup("-1"); 00409 str = argv[0]; 00410 sub = argv[1]; 00411 if (argc > 2) start = atoi(argv[2]); 00412 if (argc > 3) dir = atoi(argv[3]); 00413 length = strlen(str); 00414 if (start < 0) start = length - start; 00415 if (start < 0) start = 0; 00416 if (sub && start < length) 00417 { 00418 if (dir) 00419 { 00420 int i = length - strlen(sub); 00421 while (i > start && c == 0) 00422 { 00423 c = (char*)stristr(str + i,sub); 00424 i--; 00425 } 00426 } 00427 if (!c) 00428 c = (char*)stristr(str + start,sub); 00429 } 00430 00431 if (!c) return strdup("-1"); 00432 start = c - str; 00433 sprintf(temp,"%d",start); 00434 return strdup(temp); 00435 }
|
|
Definition at line 438 of file cgi_js.c. References ScriptEnvironment::htmlout, HTMLWrite(), NULL, and stristr(). Referenced by AdminRunScript(), CGImain(), ODBCRunScript(), RunReportF(), ValidateBack(), ValidatePage(), and WFmain(). 00439 { 00440 int i; 00441 for (i=0; i<argc; i++) 00442 { 00443 HTMLWrite(Env->htmlout,argv[i]); 00444 } 00445 if (stristr(cmd,"ln")) HTMLWrite(Env->htmlout,"\r\n"); 00446 return NULL; 00447 }
|
|
Definition at line 319 of file cgi_js.c. References CGIMALLOC, and random_seed. Referenced by AdminRunScript(), CGImain(), ODBCRunScript(), RunReportF(), ValidateBack(), ValidatePage(), and WFmain(). 00320 { 00321 unsigned int x; 00322 char* result = (char*)CGIMALLOC(32); 00323 #ifdef __WINCE__ 00324 random_seed += GetTickCount(); 00325 #else 00326 random_seed += time(0); 00327 #endif 00328 if (argc == 0) x = random_seed; 00329 else 00330 { x = atoi(argv[0]); 00331 if (!x ) x = random_seed; 00332 else x = random_seed % x; 00333 } 00334 sprintf(result,"%d",x); 00335 return result; 00336 }
|
|
Definition at line 173 of file cgi_js.c. References ScriptEnvironment::argv0, CGIFCLOSE, CGIFOPEN, ScriptEnvironment::config, CopyBuffer(), DeleteBuffer(), ExpandLocalPath(), MAXPATH, NewBuffer(), NULL, and RunReport(). Referenced by AdminRunScript(), CGImain(), ODBCRunScript(), RunReportF(), ValidateBack(), ValidatePage(), and WFmain(). 00174 { 00175 EZSSTREAM result; 00176 int i; 00177 char*c = 0; 00178 00179 if (!Env->config || !argc) return 0; 00180 00181 memset(&result,0,sizeof(result)); 00182 result.t = NewBuffer(1024); 00183 00184 00185 for (i=0; i< argc; i ++) 00186 { 00187 if (*argv[i]) 00188 { 00189 char filename[MAXPATH]; 00190 FILE* script = 0; 00191 if (Env->argv0) 00192 if (strlen(argv[i]) + strlen(Env->argv0) < MAXPATH ) 00193 { 00194 ExpandLocalPath(Env->argv0,filename,argv[i],0); 00195 script = CGIFOPEN(filename,"rb"); 00196 } 00197 if (!script) script = CGIFOPEN(argv[i],"rb"); 00198 00199 if (script) 00200 { 00201 RunReport(Env->argv0,&result,script,Params,NULL,NULL,0,NULL); 00202 CGIFCLOSE(script); 00203 } 00204 } 00205 } 00206 if (argc) 00207 { 00208 c = CopyBuffer(result.t); 00209 } 00210 DeleteBuffer(result.t); 00211 return c; 00212 }
|
|
length(string) Definition at line 363 of file cgi_js.c. References strdup(). Referenced by AdminRunScript(), CGImain(), ODBCRunScript(), RunReportF(), ValidateBack(), ValidatePage(), and WFmain(). 00364 { 00365 char temp[32]; 00366 sprintf(temp,"%d",argc ? strlen(argv[0]) : 0); 00367 return strdup(temp); 00368 }
|
|
substr(string,start,length) Definition at line 370 of file cgi_js.c. References NULL, strdup(), and strndup(). Referenced by AdminRunScript(), CGImain(), ODBCRunScript(), RunReportF(), ValidateBack(), ValidatePage(), and WFmain(). 00371 { 00372 char* str; 00373 int start=0; 00374 int delta=65535; 00375 int length; 00376 int end; 00377 00378 if (!argc) return NULL; 00379 str = argv[0]; 00380 if (argc > 1) start = atoi(argv[1]); 00381 if (argc > 2) delta= atoi(argv[2]); 00382 00383 length = strlen(str); 00384 if (start < 0) start = length + start; 00385 if (start < 0) start = 0; 00386 end = start + delta; 00387 00388 if (end == start || start >= length) return strdup(""); 00389 00390 if (end >= length) end = length; 00391 00392 length = abs(start - end); 00393 if (end < start) start = end; 00394 00395 return strndup(str + start, length); 00396 }
|
|
Definition at line 283 of file cgi_js.c. References GetTime(), and strdup(). Referenced by CGImain(), ODBCRunScript(), RunReportF(), ValidateBack(), ValidatePage(), and WFmain(). 00284 { 00285 char datetime[16]; 00286 GetTime(datetime,datetime+8,0); 00287 return strdup(datetime); 00288 }
|
|
Definition at line 344 of file cgi_js.c. References NULL, and strdup(). Referenced by AdminRunScript(), CGImain(), ODBCRunScript(), RunReportF(), ValidateBack(), ValidatePage(), and WFmain(). 00345 { 00346 double d; 00347 int x; 00348 char format[32]; 00349 char result[128]; 00350 00351 if (argc == 0) return 0; 00352 d = strtod(argv[0],NULL); 00353 if (argc == 2) x = atoi(argv[1]); 00354 else x = 0; 00355 00356 sprintf(format,"%%.%df",x); 00357 sprintf(result,format,d); 00358 00359 return strdup(result); 00360 }
|
|
Definition at line 226 of file cgi_js.c. References IsNumber(), and strdup(). Referenced by AdminRunScript(), CGImain(), ODBCRunScript(), RunReportF(), ValidateBack(), ValidatePage(), and WFmain(). 00227 { 00228 if (argc == 0) return 0; 00229 if (!IsNumber(argv[0],0)) return 0; 00230 return strdup(argv[0]); 00231 }
|
|
Definition at line 2019 of file cgi_util.c. References CGINameValue::name, and NULL. Referenced by CopyList(), and ProjectUpdate(). 02020 { 02021 size_t x = 0; 02022 if (header) 02023 while (header->name != NULL) 02024 { 02025 if (header->name[0]) 02026 x++; 02027 header++; 02028 } 02029 return x; 02030 }
|
|
Definition at line 64 of file cgi_cgi.c. References GetTime(), and LogMessage(). Referenced by main(). 00065 { 00066 char Date[14],Time[14]; 00067 00068 GetTime(Date,Time,0); 00069 LogMessage("Run\tPROGRAM="); 00070 LogMessage(program); 00071 LogMessage(",HOST="); 00072 LogMessage(host); 00073 LogMessage(",DATE="); 00074 LogMessage(Date); 00075 LogMessage(",TIME="); 00076 LogMessage(Time); 00077 LogMessage("\n"); 00078 }
|
|
Definition at line 19 of file cgi_console.c. References CGIFCLOSE, and CGIFOPEN. Referenced by CGImain(), DoesFileMatchForm(), EZSReport(), GetSecurityFlags(), ListErrors(), LoadUserDataSQL(), main(), ODBCConnect(), ODBCStart(), PrintFinish(), ShowFormPage(), and TryODBC().
|
|
Definition at line 69 of file cgi_log.c. References CGIFCLOSE, CGIFOPEN, and CGILogLevel. Referenced by CGImain(), LogConnection(), main(), and PrintFinish(). 00070 { 00071 FILE * h; 00072 if (CGILogLevel < 1) return; 00073 h = CGIFOPEN("logmsg.txt","at"); 00074 if (h) 00075 { 00076 if (c) fputs(c,h); 00077 else fputs("*NULL*",h); 00078 CGIFCLOSE(h); 00079 } 00080 }
|
|
Definition at line 119 of file cgi_log.c. References CGIFOPEN, CGIHeaders, CGILogLevel, DeleteNVP(), ExpandLocalPath(), GetEnvironment(), GetField(), GetFieldValue, MAXPATH, NULL, ReadINIFileSection(), and SetLoggingLevel(). Referenced by main(). 00120 { 00121 FILE * h; 00122 int i; 00123 char fn[MAXPATH]; 00124 CGINameValue* m; 00125 00126 ExpandLocalPath(argv0,fn,"cgi.ini",""); 00127 00128 m = ReadINIFileSection(fn, "admin",0); 00129 00130 if (m != NULL) 00131 { 00132 if (GetField(m,"LOGLEVEL")) 00133 { 00134 SetLoggingLevel(atoi(GetFieldValue(m,"LOGLEVEL"))); 00135 } 00136 DeleteNVP(m); 00137 } 00138 00139 if (CGILogLevel < 3) return; 00140 h = CGIFOPEN("logenv.txt","at"); 00141 if (!h) return; 00142 fprintf(h,"Starting %s\n",argv0); 00143 fprintf(h,"Environment:\n"); 00144 00145 for(i=0; CGIHeaders[i]; i++) 00146 { 00147 char* y = GetEnvironment(htmlout,CGIHeaders[i]); 00148 if (y) fprintf(h,"%s=%s\n",CGIHeaders[i],y); 00149 } 00150 fprintf(h,"\n\n"); 00151 CGIFCLOSE(h); 00152 }
|
|
Definition at line 154 of file cgi_log.c. References CGIFCLOSE, CGIFOPEN, and CGILogLevel. Referenced by main(). 00155 { 00156 int i; 00157 FILE * h; 00158 if (CGILogLevel < 2) return; 00159 h = CGIFOPEN("logtrx.txt","at"); 00160 if (h) 00161 { 00162 for (i=0;data[i].name;i++) 00163 { 00164 if (!data[i].name[0]) continue; 00165 fprintf(h,"%s=%s\n",data[i].name,data[i].value); 00166 } 00167 fputs("\n",h); 00168 CGIFCLOSE(h); 00169 } 00170 }
|
|
Definition at line 364 of file cgi_util.c. References CGIMALLOC, TextBuffer::data, TextBuffer::Last, TextBuffer::Next, NULL, TextBuffer::size, and TextBuffer::used. Referenced by BufferWriteL(), CGImain(), DatabaseSaveNewRecord(), EvaluateArgument(), JSReport(), LoadUserDataSQL(), NewStream(), ODBCConnect(), SaveData(), and TryODBC(). 00365 { 00366 TextBuffer* t = CGIMALLOC(sizeof(TextBuffer)); 00367 t->data = CGIMALLOC(length+1); 00368 t->data[length] = 0; 00369 t->size = length; 00370 t->used = 0; 00371 t->Next = NULL; 00372 t->Last = t; 00373 return t; 00374 }
|
|
Creates anew name-value-pair list, with an extra entry as a null terminator, which can also be used for extending the list. Definition at line 1850 of file cgi_util.c. References CGIMALLOC, CGINameValue::last, CGINameValue::name, and CGINameValue::value. Referenced by _loaddbheader(), CGImain(), CopyList(), CopyListDeep(), CopyListJoin(), ExtendNVP(), GetTotal(), main(), ODBCRead(), ReadCGIPostData(), ReadHTMLAttributes(), ReadPairedString(), and ReadPairedValues(). 01851 { 01852 CGINameValue * v; 01853 size_t i; 01854 v = (CGINameValue*) CGIMALLOC((count + 1) * sizeof(CGINameValue)); 01855 for (i = 0; i <= count; i++) 01856 { 01857 v[i].name = 0; 01858 v[i].value = 0; 01859 v[i].last = 0; 01860 } 01861 v[count].last = 1; 01862 return v; 01863 }
|
|
Creates an in-memory stream Definition at line 952 of file cgi_util.c. References CGIMALLOC, NewBuffer(), and STREAM. 00953 { 00954 #if defined(FASTCGI) 00955 STREAM str = (STREAM)CGIMALLOC(sizeof(FCGISTREAM)); 00956 str->strp=0; 00957 #else 00958 STREAM str = (STREAM)CGIMALLOC(sizeof(EZSSTREAM)); 00959 str->f=0; 00960 #endif 00961 #ifdef __WINCE__ 00962 str->s = 0; 00963 #endif 00964 #ifdef ISAPICGI 00965 str->ecb = 0; 00966 str->pos = 0; 00967 #endif 00968 str->t = NewBuffer(size); 00969 return str; 00970 }
|
|
Definition at line 218 of file cgi_odbc.c. References ODBCSession::hdbc. 00219 { 00220 ODBCSession* database = (ODBCSession*)db; 00221 if (!database) return 0; 00222 return (SQL_SUCCEEDED(SQLEndTran(SQL_HANDLE_DBC,database->hdbc,SQL_COMMIT))); 00223 }
|
|
Free errors if non-zero Definition at line 125 of file cgi_odbc.c. References CGIFREE, CGIMALLOC, ODBCSession::debug, ODBCSession::ErrorMessage, ODBCSession::hdbc, ODBCSession::henv, ListErrors(), LogError(), and NewBuffer(). Referenced by LoadUserDataSQL(). 00126 { 00127 int r; 00128 ODBCSession * database = (ODBCSession*)CGIMALLOC(sizeof(ODBCSession)); 00129 database->debug = 0; 00130 if (strlen(service) > 256 || strlen(uid) > 256 || strlen(pwd) > 256) return 0; 00131 00132 if (service[0] == '?') 00133 { 00134 database->debug=1; 00135 service++; 00136 } 00137 00138 r = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &database->henv); 00139 if (!SQL_SUCCEEDED(r)) 00140 { 00141 CGIFREE(database); 00142 LogError("\nCouldn't allocate a SQL environment handle"); 00143 return 0; 00144 } 00145 00146 r = SQLSetEnvAttr(database->henv, SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3,0); 00147 if (!SQL_SUCCEEDED(r)||database->debug) 00148 { 00149 ListErrors(errors,database->henv,SQL_HANDLE_ENV); 00150 } 00151 if (!SQL_SUCCEEDED(r)) 00152 { 00153 SQLFreeHandle(SQL_HANDLE_ENV, database->henv); 00154 CGIFREE(database); 00155 return 0; 00156 } 00157 00158 r = SQLAllocHandle(SQL_HANDLE_DBC,database->henv,&database->hdbc); 00159 00160 if (!SQL_SUCCEEDED(r)||database->debug) 00161 { 00162 ListErrors(errors,database->henv,SQL_HANDLE_ENV); 00163 } 00164 00165 if (!SQL_SUCCEEDED(r)) 00166 { 00167 LogError("\nCouldn't allocate a SQL database handle"); 00168 SQLFreeHandle(SQL_HANDLE_ENV, database->henv); 00169 CGIFREE(database); 00170 return 0; 00171 } 00172 00173 if (strchr(service,'=')) 00174 { 00175 SQLCHAR outConn[1024]; 00176 SQLSMALLINT l = 1024; 00177 r = SQLDriverConnect(database->hdbc,0,(SQLCHAR*)service, SQL_NTS, 00178 outConn,l,&l,SQL_DRIVER_NOPROMPT); 00179 } 00180 else 00181 { 00182 r = SQLConnect(database->hdbc, 00183 (SQLCHAR*)service, SQL_NTS, 00184 (SQLCHAR*)uid, SQL_NTS, 00185 (SQLCHAR*)pwd, SQL_NTS); 00186 } 00187 if (!SQL_SUCCEEDED(r)||database->debug) 00188 { 00189 ListErrors(errors,database->hdbc,SQL_HANDLE_DBC); 00190 ListErrors(errors,database->henv,SQL_HANDLE_ENV); 00191 } 00192 if (!SQL_SUCCEEDED(r)) 00193 { 00194 SQLFreeHandle(SQL_HANDLE_DBC, database->hdbc); 00195 SQLFreeHandle(SQL_HANDLE_ENV, database->henv); 00196 CGIFREE(database); 00197 return 0; 00198 } 00199 00200 database->ErrorMessage = NewBuffer(1024); 00201 return (SQLDB*)database; 00202 }
|
|
Definition at line 204 of file cgi_odbc.c. References CGIFREE, DeleteBuffer(), ODBCSession::ErrorMessage, ODBCSession::hdbc, and ODBCSession::henv. Referenced by LoadUserDataSQL(). 00205 { 00206 ODBCSession* database = (ODBCSession*)db; 00207 if (!database) return 0; 00208 00209 SQLDisconnect(database->hdbc); 00210 SQLFreeHandle(SQL_HANDLE_DBC, database->hdbc); 00211 SQLFreeHandle(SQL_HANDLE_ENV, database->henv); 00212 00213 DeleteBuffer(database->ErrorMessage); 00214 CGIFREE(database); 00215 return 0; 00216 }
|
|
Definition at line 285 of file cgi_odbc.c. References ODBCFinish(), and ODBCStart(). Referenced by TryODBC(). 00286 { 00287 ODBCSession* database = (ODBCSession*)db; 00288 SQLHSTMT st; 00289 int ret; 00290 if (!database) return 0; 00291 00292 ret = ODBCStart(database,command,&st); 00293 if (ret) 00294 { 00295 SQLFreeHandle(SQL_HANDLE_STMT, (SQLHSTMT)st); 00296 return ret; 00297 } 00298 00299 ODBCFinish(st,modified); 00300 00301 return 0; 00302 }
|
|
Definition at line 271 of file cgi_odbc.c. Referenced by ODBCExec(), and ODBCQuery(). 00272 { 00273 if (modified) 00274 { 00275 SQLINTEGER i=0; 00276 SQLRowCount((SQLHSTMT)st,&i); 00277 *modified = i; 00278 } 00279 if (!SQL_SUCCEEDED(SQLFreeHandle(SQL_HANDLE_STMT, (SQLHSTMT)st))) 00280 return 54; 00281 00282 return 0; 00283 }
|
|
Definition at line 305 of file cgi_odbc.c. References NULL, ODBCFinish(), ODBCRead(), and ODBCSelect(). Referenced by LoadUserDataSQL(). 00306 { 00307 void* handle=0; 00308 CGINameValue* ret; 00309 if (ODBCSelect(database,command,&handle)) return NULL; 00310 ret = ODBCRead(handle); 00311 ODBCFinish(handle,modified); 00312 return ret; 00313 }
|
|
Definition at line 326 of file cgi_odbc.c. References CGIMALLOC, DeleteNVP(), CGINameValue::name, NewNVP(), NULL, strndup(), and CGINameValue::value. Referenced by ODBCQuery(). 00327 { 00328 SQLSMALLINT columnCount = 0; 00329 CGINameValue * data; 00330 SQLSMALLINT i; 00331 00332 int ret = SQLNumResultCols((SQLHSTMT)st,&columnCount); 00333 if (columnCount ==0) return NULL; 00334 00335 data = NewNVP(columnCount); 00336 /* bind*/ 00337 for (i=1; i<= columnCount; i++) 00338 { 00339 char szTitle[256]; 00340 long size=0; 00341 szTitle[0]=0; 00342 00343 ret = SQLColAttribute((SQLHSTMT)st,i,SQL_DESC_LENGTH, 00344 NULL,0,NULL,&size); 00345 00346 if (!SQL_SUCCEEDED(ret) || size <= 0) size = 128; 00347 00348 SQLColAttribute((SQLHSTMT)st,i,SQL_DESC_NAME,szTitle, 00349 sizeof(szTitle),NULL,NULL); 00350 00351 data[i-1].name = strndup(szTitle,sizeof(szTitle)); 00352 data[i-1].value = (char*)CGIMALLOC(size+1); 00353 memset(data[i-1].value,0,size+1); 00354 00355 SQLBindCol((SQLHSTMT)st,i,SQL_C_CHAR,(SQLPOINTER) data[i-1].value, 00356 (size + 1) * sizeof(char),&size); 00357 } 00358 /* end bind */ 00359 ret = SQLFetch((SQLHSTMT)st); 00360 if (SQL_SUCCEEDED(ret)) return data; 00361 DeleteNVP(data); 00362 return NULL; 00363 }
|
|
Definition at line 316 of file cgi_odbc.c. References ODBCStart(). Referenced by ODBCQuery(). 00317 { 00318 ODBCSession* database = (ODBCSession*)db; 00319 int ret; 00320 if (!database) return 0; 00321 00322 ret= ODBCStart(database,command,st); 00323 return ret; 00324 }
|
|
This version handles null-entry lists gracefully. It assumes that all entries in the CGINameValue were created with strdup() or strndup(), which pads the text buffers with at least two extra bytes. Definition at line 840 of file cgi_util.c. References GetFieldValue, NULL, and PopList2(). Referenced by CGImain(). 00841 { 00842 char* x = GetFieldValue(list,key); 00843 char* p; 00844 size_t i = 0; 00845 00846 /* remove leading delimiters */ 00847 while (x[i] == ',' || x[i] == ' ') i++; 00848 if (i) 00849 memmove(x,x+i,strlen(x+i) + 1); 00850 00851 p = PopList2(x,end); 00852 00853 /* remove trailing delimiters */ 00854 i = strlen(x); 00855 while (i && (x[i-1] == ',' || x[i-1] == ' ')) i--; 00856 x[i]=0; 00857 00858 if (p != NULL) return p; 00859 else 00860 { 00861 size_t l = strlen(x); 00862 memmove(x+1,x,strlen(x)); 00863 x[l+1] = 0; 00864 x[0]=0; 00865 return x+1; 00866 } 00867 }
|
|
Removes the first entry from a comma-delimited list, shifts the list, and rewrites the remove entry to the unused space at the end. Returns a pointer to the popped value, that does not need to be CGIFREEd. Definition at line 809 of file cgi_util.c. References CGIFREE, CGIMALLOC, and NULL. Referenced by CGImain(), and PopList(). 00810 { 00811 char* r; 00812 size_t l,m; 00813 char* x = list; 00814 l=0; 00815 00816 if (end) 00817 while (x[l] && x[l] != end) l++; 00818 else 00819 while (x[l] && x[l] != ',' && x[l] != ' ') l++; 00820 00821 if (!x[l]) return NULL; /* not found */ 00822 x = list + l + 1; 00823 m = strlen(x); 00824 r = CGIMALLOC(l+1); 00825 00826 memcpy(r,list,l); 00827 r[l]=0; 00828 00829 memmove(list,x,m); 00830 list[m]=0; 00831 00832 x = list + m + 1; /* tail of the new list */ 00833 memcpy(x,r,l); 00834 x[l]=0; 00835 00836 CGIFREE(r); 00837 return x; 00838 }
|
|
Definition at line 636 of file cgi_html.c. References ScriptEnvironment::curpos, HTMLPrintf(), HTMLWriteL(), ScriptEnvironment::lastLine, and NULL. Referenced by CGImain(), ODBCRunScript(), RunReportF(), ValidateBack(), and ValidatePage(). 00637 { 00638 char * err; 00639 int len = Env->curpos - Env->lastLine; 00640 switch (errcode) 00641 { 00642 case 40: err="Need a closing quote";break; 00643 case 41: err="( expected after if or elsif";break; 00644 case 42: err="Need a closing paren";break; 00645 case 43: err="Misplaced string constant";break; 00646 case 44: err="An else or elsif must come after an if";break; 00647 case 45: err="Object variable not found";break; 00648 case 46: err="Unable to process this command";break; 00649 case 47: err="Check for an unterminated string, unescaped quote, or missing + sign"; break; 00650 case 48: err="Function not found"; break; 00651 case 49: err="Expecting an expression"; break; 00652 case 70: err="{ expected after an if "; break; 00653 case 71: err="Need a closing brace";break; 00654 default: err="Unknown scripting error"; 00655 } 00656 HTMLPrintf(htmlout,"Script error %d: %s:",errcode,err); 00657 if (len > 1024) len = 1024; 00658 if (len > 0 && script != NULL) 00659 { 00660 char c[1024]; 00661 fseek(script,Env->lastLine,0); 00662 fread(c,len,1,script); 00663 HTMLWriteL(htmlout,c,len); 00664 } 00665 return 0; 00666 }
|
|
|
|
Definition at line 376 of file cgi_cgi.c. References ANSItoUTF8(), CGIFREE, CGIMALLOC, ContainsANSIChars(), ExpandUrl(), GetEnvironment(), NULLSTR, ReadPairedString(), SetupCGIData(), swapchars(), Translate(), UTF7toUTF8(), and CGINameValue::value. Referenced by main(). 00377 { 00378 char * c; 00379 CGINameValue* data; 00380 int x; 00381 #ifdef WINCGI 00382 c = CGIMALLOC(65535); 00383 GetPrivateProfileString("CGI","Query String",NULLSTR,c,65535,WinCGIFile); 00384 #else 00385 c = GetEnvironment(htmlin,"QUERY_STRING"); 00386 #endif 00387 00388 if (c && *c) 00389 { 00390 #ifdef EBCDIC 00391 Translate(c,ascii2ebcdic); 00392 #endif 00393 /*2005 this is really old code, before web browsers were standardized. 00394 if (!strchr(c,'&')) data = ReadPairedString(c,'/',3+extra); 00395 else */ 00396 data = ReadPairedString(c,'&',3+extra); 00397 } 00398 else 00399 { 00400 #ifdef WINCGI 00401 GetPrivateProfileString("CGI","Logical Path",NULLSTR,c,65535,WinCGIFile); 00402 #else 00403 c = GetEnvironment(htmlin,"PATH_INFO"); 00404 #endif 00405 if (c &&*c) 00406 { 00407 #ifdef EBCDIC 00408 Translate(c,ascii2ebcdic); 00409 #endif 00410 if (*c=='/') c++; 00411 if (!strchr(c,'&')) data = ReadPairedString(c,'/',3+extra); 00412 else data = ReadPairedString(c,'&',3+extra); 00413 } 00414 else return 0; 00415 } 00416 00417 if (!data) return 0; 00418 SetupCGIData(htmlin,data); 00419 00420 #ifndef WINCGI 00421 for (x = 3+extra; data[x].name; x++) 00422 { 00423 swapchars(data[x].name,'+',' '); /*plus to space*/ 00424 swapchars(data[x].value,'+',' '); /*plus to space*/ 00425 ExpandUrl(data[x].name); 00426 ExpandUrl(data[x].value); 00427 00428 if (strstr(data[x].name,"+AAA")) 00429 { 00430 UTF7toUTF8(data[x].name); 00431 UTF7toUTF8(data[x].value); 00432 } 00433 else if (ContainsANSIChars(data[x].value)) 00434 { 00435 char* c = data[x].value; 00436 data[x].value = ANSItoUTF8(c); 00437 free(c); 00438 } 00439 swapchars(data[x].name,'\t',' '); /*remove tabs*/ 00440 swapchars(data[x].name,'\r',' '); /*remove carriage-returns*/ 00441 swapchars(data[x].name,'\n',' '); /*remove linefeeds*/ 00442 swapchars(data[x].value,'\t',' '); /*remove tabs*/ 00443 swapchars(data[x].value,'\r',' '); /*remove carriage-returns*/ 00444 swapchars(data[x].value,'\n',' '); /*remove linefeeds*/ 00445 } 00446 #endif 00447 00448 #ifdef WINCGI 00449 CGIFREE(c); 00450 #endif 00451 return data; 00452 }
|
|
Definition at line 466 of file cgi_cgi.c. References ANSItoUTF8(), CGIFREE, ContainsANSIChars(), DeleteNVP(), ExpandUrl(), fmakeword(), MAX_ENTRIES, CGINameValue::name, NewNVP(), NULL, NULLSTR, SetupCGIData(), strdup(), swapchars(), Translate(), UTF7toUTF8(), and CGINameValue::value. Referenced by main(). 00467 {int cl; 00468 register int x; 00469 char * c; 00470 int maxsize = MAX_ENTRIES + reserve; 00471 int growcount = 0; /* that should do the trick! */ 00472 #ifdef EBCDIC 00473 char stopstr[2]; 00474 #endif 00475 00476 CGINameValue* data; 00477 00478 #ifdef EBCDIC 00479 stopstr[0]='&'; 00480 stopstr[1]=0; 00481 Translate(stopstr,ebcdic2ascii); 00482 #endif 00483 00484 c = getenv("CONTENT_LENGTH"); 00485 cl = c ? atoi(c) : 0; 00486 00487 if (cl == 0) return NULL; 00488 if (!htmlin->f) return NULL; 00489 /* Read the host information */ 00490 00491 data = NewNVP(maxsize); 00492 00493 for (x=0; x<reserve; x++) 00494 { 00495 data[x].name=strdup(NULLSTR); 00496 data[x].value=strdup(NULLSTR); 00497 } 00498 00499 SetupCGIData(htmlin,data); 00500 x=reserve; 00501 00502 while((cl > 0) && (!feof(htmlin->f)) && (growcount < 64 )) 00503 { 00504 /* Convert the CGI data back to ASCII, read from stdin */ 00505 if (x == maxsize) /* running out of space? grow the list */ 00506 { 00507 CGINameValue* newdata = NewNVP(maxsize+ MAX_ENTRIES); 00508 if (newdata == NULL) return data; 00509 memcpy(newdata,data,maxsize * sizeof(CGINameValue)); 00510 CGIFREE(data); 00511 data = newdata; 00512 maxsize += MAX_ENTRIES; 00513 growcount++; 00514 } 00515 00516 #ifdef EBCDIC 00517 /* Translate binary data to EBCDIC text before doing anything. */ 00518 c = fmakeword(htmlin,stopstr[0],&cl); 00519 #else 00520 c = fmakeword(htmlin,'&',&cl); 00521 #endif 00522 00523 #ifdef EBCDIC 00524 Translate(c,ascii2ebcdic); 00525 #endif 00526 00527 if (!c) {DeleteNVP(data); return NULL;} 00528 swapchars(c,'+',' '); /*plus to space*/ 00529 ExpandUrl(c); /*converts %xx to characters*/ 00530 /* swapchars(c,'\t',' '); remove tabs*/ 00531 data[x].name = c; 00532 00533 c = strchr(c,'='); 00534 if ((c) && (*c)) 00535 { 00536 *c++ = 0; 00537 data[x].value = strdup(c); 00538 } 00539 else 00540 { 00541 data[x].value = strdup(NULLSTR); 00542 } 00543 00544 if (strstr(data[x].name,"+AAA")) 00545 { 00546 UTF7toUTF8(data[x].name); 00547 UTF7toUTF8(data[x].value); 00548 } /*application/x-www-form-urlencoded*/ 00549 else if (ContainsANSIChars(data[x].value)) 00550 { 00551 char* c = data[x].value; 00552 data[x].value = ANSItoUTF8(c); 00553 free(c); 00554 } 00555 00556 swapchars(data[x].name,'\t',' '); /*remove tabs*/ 00557 swapchars(data[x].name,'\r',' '); /*remove carriage-returns*/ 00558 swapchars(data[x].name,'\n',' '); /*remove linefeeds*/ 00559 swapchars(data[x].value,'\t',' '); /*remove tabs*/ 00560 swapchars(data[x].value,'\r',' '); /*remove carriage-returns*/ 00561 swapchars(data[x].value,'\n',' '); /*remove linefeeds*/ 00562 /*not all compilers reliably increment x after for loops*/ 00563 x++; 00564 } 00565 return data; 00566 } /* end of ReadCGIData */
|
|
Reads the first 20 property values in a markup tag Definition at line 601 of file cgi_util.c. References CGINameValue::name, NewNVP(), NULL, ReadUntilChar(), strdup(), and CGINameValue::value. Referenced by RunReportF(), and ShowFormPage(). 00602 { 00603 CGINameValue * v = NewNVP(max > 0 ? max : 16); 00604 int i = 0; /* max 20 options per tag, 1k per option*/ 00605 char temp[4096]; 00606 00607 while (i < 20) 00608 { 00609 int e = ReadUntilChar(source,temp,sizeof(temp)-1,"=> \t\r\n",0); 00610 char *s = temp; 00611 while (*s && strchr(" \t\r\n",*s)!=NULL) s++; 00612 00613 if (*s) 00614 { 00615 v[i].name = strdup(s); 00616 00617 if (e == '=') 00618 { 00619 fread(temp,1,1,source); 00620 if (temp[0] == '\"') 00621 e = ReadUntilChar(source,temp,sizeof(temp),"\"",0); 00622 else 00623 e = ReadUntilChar(source,temp+1,sizeof(temp)-1,"> \t\r\n",0); 00624 00625 v[i].value = strdup(temp); 00626 } 00627 i++; 00628 } 00629 if (e == '>' || e == -1) return v; 00630 } 00631 ReadUntilChar(source,0,0,">",0); /* chomp all the remaining tags */ 00632 return v; 00633 }
|
|
Definition at line 2186 of file cgi_util.c. References CGIFCLOSE, CGIFOPEN, CGIFREE, CGIMALLOC, FileSize(), killchar(), NULL, ReadPairedString(), ReadUntilChar(), ReadUntilWord(), and stricmp(). Referenced by AdminPrintPage(), CGImain(), EZSCounts(), GetSecurityFlags(), Index(), LogStartup(), ProjectUpdate(), SaveData(), SpaceUpdate(), UserAddSpace(), UserList(), UserUpdate(), VerifyPassword(), VerifyUser(), and WFmain(). 02187 { 02188 CGINameValue* ret = NULL; 02189 int d; 02190 int maxsize = FileSize(filename); 02191 char * str; 02192 FILE * file= NULL; 02193 if (maxsize <= 0) return NULL; 02194 str = CGIMALLOC(maxsize+1); 02195 if (str == NULL) return NULL; 02196 str[maxsize]=0; 02197 02198 file = CGIFOPEN(filename,"rt"); 02199 if (file != NULL) 02200 while (1) 02201 { 02202 d = ReadUntilChar(file,0,0,"[",'\r'); 02203 if (d < 0) break; 02204 d = ReadUntilChar(file,str,maxsize,"]\n",'\r'); 02205 if (d == ']') 02206 { 02207 if (stricmp(str,section)==0) 02208 { 02209 ReadUntilWord(file,str,maxsize,"\n["); 02210 killchar(str,'\r'); 02211 ret = ReadPairedString(str,'\n',reserve); 02212 break; 02213 } 02214 } 02215 } 02216 CGIFCLOSE(file); 02217 CGIFREE(str); 02218 return ret; 02219 }
|
|
read the next token from the file stream. Punctuation such as { } ; count as words. Strings may be ' or " delimited Definition at line 116 of file cgi_js.c. References ReadUntilChar(), SkipWhitespace(), and SpecialWord(). Referenced by DelimitedSection(), EvaluateArgument(), RunScript(), and RunScriptObject(). 00117 { 00118 /* <= >= += -= *= /= == are awkward */ 00119 buf[0]=0; 00120 if (end == -1) return -1; /* already hit the EOF */ 00121 buf[0] = (char)SkipWhitespace(source,end); 00122 00123 while (1) 00124 { 00125 if (strchr("\r\n#*-/^,;{}()[]<>+=",buf[0])) /* 1 or 2 character word */ 00126 { 00127 if (isSyntax) *isSyntax = 1; 00128 if (buf[0] == '\r') buf[0] = '\n'; 00129 if (buf[0] && strchr("<>+=/",buf[0])) /* check for 2-character operators */ 00130 return SpecialWord(source,buf,size,buf[0]); 00131 00132 /* syntax char -- don't need to check the next word */ 00133 buf[1]=0; 00134 return ' '; /* pretend that whitespace stopped the scan */ 00135 } 00136 00137 if (buf[0] == '%') /* %> ends an inline script, and % is a modulus */ 00138 { 00139 if (!fread(buf+1,1,1,source)) return -1; 00140 if (buf[1] == '>') {buf[0]=0; return -1;} 00141 else {end=buf[1]; buf[1]=0; return end;} 00142 } 00143 00144 if (buf[0] == '\"' || buf[0] == '\'') /* read a string */ 00145 { 00146 int i = 1; 00147 end = buf[0]; 00148 buf[0] = '\''; /* mark as a string by setting the first character */ 00149 while (1) 00150 { 00151 if (!fread(buf+i,1,1,source)) return -1; 00152 if (buf[i] == '\\') 00153 { 00154 if (!fread(buf+i,1,1,source)) return -1; 00155 if (buf[i] == 'n') buf[i] = '\n'; /* special replacement codes */ 00156 else if (buf[i] == 'r') buf[i] = '\r'; 00157 else if (buf[i] == 't') buf[i] = '\t'; 00158 } 00159 else if (buf[i] == end) break; 00160 if (i < size-1) i++; 00161 } 00162 buf[i] = 0; /* terminate the string */ 00163 return ' '; /* Done! Treat as whitespace termination */ 00164 } 00165 else /* ordinary word -- read until whitespace or grammar*/ 00166 { /* if whitespace stopped the scan, keep reading until the next char */ 00167 end = ReadUntilChar(source,buf+1,size-1," \t\r\n#*-/,;{}()[]<>+=",0); 00168 return SkipWhitespace(source,end); 00169 } 00170 } /* while */ 00171 }
|
|
Read the next whitespace-delimited word Definition at line 279 of file cgi_html.c. References ReadUntilChar(). Referenced by ExecEZSCommand(), and ReadParameter(). 00280 { 00281 name[0]=0; 00282 while (fread(name,1,1,source)) 00283 { 00284 if (!strchr(" \t\r\n",name[0])) break; 00285 name[0]=0; 00286 } 00287 if (name[0] == '\'' || name[0] == '\"') 00288 { 00289 size_t i=0; 00290 int end = name[0]; 00291 char* buf = name; 00292 while (1) 00293 { 00294 if (!fread(buf+i,1,1,source)) return -1; 00295 if (buf[i] == '\\') 00296 { 00297 if (!fread(buf+i,1,1,source)) break; 00298 if (buf[i] == 'n') buf[i] = '\n'; /* special replacement codes */ 00299 else if (buf[i] == 'r') buf[i] = '\r'; 00300 else if (buf[i] == 't') buf[i] = '\t'; 00301 } 00302 else if (buf[i] == end) break; 00303 if (i < length-1) i++; 00304 } 00305 buf[i] = 0; 00306 } 00307 else return ReadUntilChar(source,name+1,length-1," \t\r\n",0); 00308 return name[0]; //quotation mark 00309 }
|
|
might allocate an extra slot if the last character is the delimiter Definition at line 2251 of file cgi_util.c. References CGINameValue::name, NewNVP(), NULL, NULLSTR, strdup(), strndup(), and CGINameValue::value. Referenced by Authenticate(), CGImain(), FindUserRecordASC(), JSRankSort(), Login(), ReadCGIGetData(), ReadINIFileSection(), and ShowFormPage(). 02252 { 02253 CGINameValue *v; 02254 char *c; 02255 int i,j,count,done; 02256 if (!str) return NULL; 02257 count = reserve; 02258 if (str[0]) count++; 02259 02260 for (i=1; str[i]; i++) 02261 { 02262 if (str[i] == delim) count++; 02263 } 02264 02265 if (count == 0 && reserve == 0) 02266 { 02267 if (str[0]) 02268 count = 1; 02269 else 02270 return NULL; 02271 } 02272 02273 v = NewNVP(count); 02274 02275 c = str; 02276 done =0; 02277 for (i=0; i<reserve; i++) 02278 { 02279 v[i].name = strdup(NULLSTR); 02280 v[i].value = strdup(NULLSTR); 02281 } 02282 02283 if (count == reserve) return v; 02284 02285 i = reserve; 02286 while(!done && *c) 02287 { 02288 int x=1; 02289 /* eat empties */ 02290 while (*c == delim) c++; 02291 if (isalnum(*c) || *c == '_') /* legal start characters for a field value */ 02292 { 02293 for (j=1; c[j] != '=' && c[j] != delim && c[j]; j++){x++;}/* name length*/ 02294 v[i].name = strndup(c, x); 02295 if (c[x] == '=') 02296 { 02297 c = c + x + 1; 02298 x=0; 02299 for (j=0; c[j] != delim && c[j]; j++) {x++;} 02300 v[i].value = strndup(c, x); 02301 } 02302 else 02303 { 02304 v[i].value = strdup(""); 02305 } 02306 if (*c) 02307 c = c + x + 1; 02308 i++; 02309 } 02310 else if (*c == '=') /* "=blah" is deleted */ 02311 while (*c && *c != delim) c++; 02312 else c++; /* whitespace */ 02313 if (i >= count) done = 1; 02314 } 02315 02316 return v; 02317 }
|
|
Read values of the form { "name1=value1", "name2=value2", ... } Definition at line 2222 of file cgi_util.c. References CGINameValue::name, NewNVP(), NULL, NULLSTR, strdup(), strndup(), and CGINameValue::value. Referenced by JSRankSort(), and main(). 02223 { 02224 CGINameValue* v; 02225 char * c; 02226 int i,length,max; 02227 max = argc + reserve; 02228 if (max <= 0) return NULL; 02229 02230 v = NewNVP(max); 02231 02232 for (i=0; i<reserve; i++) 02233 { 02234 v[i].name = strdup(NULLSTR); 02235 v[i].value = strdup(NULLSTR); 02236 } 02237 02238 for (i = 0 ; i < argc ; i++ ) 02239 { 02240 c = argv[i]; 02241 length=0; 02242 while (*c && *c != '=') {c++;length++;} 02243 if (*c) c++; 02244 v[i+reserve].name=strndup(argv[i],length); 02245 v[i+reserve].value=strdup(c); 02246 } 02247 return v; 02248 }
|
|
If out is nonzero, then it is filled with a null-terminated string of characters that were skipped, with length up to max-1. skip= lets you skip linefeed characters in binary files Definition at line 571 of file cgi_util.c. Referenced by _loaddbheader(), CGImain(), DatabaseReadRecord(), DatabaseSearchRecord(), ODBCRunScript(), ReadHTMLAttributes(), ReadINIFileSection(), ReadNextToken(), ReadNextWord(), RunReportF(), RunScript(), RunScriptObject(), ShowFormPage(), and SpecialWord(). 00572 { 00573 char c; 00574 if (out) *out = 0; 00575 if (max) max--; 00576 if (feof(in)) return -1; 00577 while (fread(&c,1,1,in)>0) 00578 { 00579 if (skip && skip == c) 00580 continue; 00581 00582 if (strchr(stop,c)) 00583 { 00584 if (out && max) *out = 0; 00585 return c; 00586 } 00587 else 00588 { 00589 if (out && max) 00590 { 00591 *out = c; 00592 out++; 00593 *out = 0; 00594 max--; 00595 } 00596 } 00597 } 00598 return -1; 00599 }
|
|
Definition at line 507 of file cgi_util.c. References ReadUntilWord2(). Referenced by EZSReport(), FinishTag(), ReadINIFileSection(), RunReportF(), and RunScript(). 00508 { 00509 return ReadUntilWord2(in,out,max,check,check); 00510 }
|
|
Definition at line 468 of file cgi_util.c. References CGIFREE, CGIMALLOC, and stricmp(). Referenced by ReadUntilWord(). 00469 { 00470 size_t len = strlen(check1); 00471 size_t pos = 0; 00472 char* buf = 0; 00473 int quit = 0; 00474 00475 if (len == 0) {return 0;} 00476 00477 buf = CGIMALLOC(len+1); 00478 buf[len]=0; 00479 00480 if (fread(buf,len,1,in) != 1) {CGIFREE(buf); return 0;} 00481 00482 len --; 00483 00484 while (stricmp(buf,check1) && (check1 == check2 ? 1 : stricmp(buf,check2))) 00485 { 00486 if (out) 00487 if (pos < max) 00488 { 00489 out[pos] = buf[0]; 00490 pos ++; 00491 if (pos < max) out[pos]=0; 00492 } 00493 00494 if(quit) {CGIFREE(buf); return 0;} 00495 00496 memmove((char*)buf,(char*)buf+1,len); 00497 00498 if (fread((char*)buf + len,1,1,in) != 1) {quit=1;} 00499 } 00500 00501 if (!stricmp(buf,check1)) len = 1; 00502 else len = 2; 00503 CGIFREE(buf); 00504 return len; 00505 }
|
|
Definition at line 547 of file cgi_util.c. References ReadUntilWordS2(). Referenced by EZSCounts(), EZSInclude(), EZSRandom(), EZSSource(), Index(), ODBCRunScript(), RunReportF(), ShowFormPage(), UserList(), ValidateBack(), and ValidatePage(). 00548 { 00549 return ReadUntilWordS2(in,out,check,check); 00550 }
|
|
scans a file until it reaches one of two strings of equal length. Returns 0 (not found), 1, or 2 Definition at line 512 of file cgi_util.c. References CGIFREE, CGIMALLOC, HTMLWrite(), and stricmp(). Referenced by EZSRandom(), ReadUntilWordS(), and RunReportF(). 00513 { 00514 size_t len = strlen(check1); 00515 size_t l2; 00516 char* buf; 00517 00518 if (len == 0) return 0; 00519 buf = CGIMALLOC(len+1); 00520 buf[len]=0; 00521 l2 = len - 1; 00522 00523 if (fread(buf,len,1,in) != 1) 00524 { 00525 CGIFREE(buf); return 0; 00526 } 00527 00528 while (stricmp(buf,check1) && (check1 == check2 ? 1 : stricmp(buf,check2))) 00529 { 00530 if (out) 00531 { 00532 char c[2]; 00533 c[0]=buf[0]; 00534 c[1]=0; 00535 HTMLWrite(out,c); 00536 } 00537 memmove((char*)buf,(char*)buf+1,len); 00538 if (fread((char*)buf + l2,1,1,in) != 1) {CGIFREE(buf); return 0;} 00539 } 00540 00541 if (!stricmp(buf,check1)) len = 1; 00542 else len = 2; 00543 CGIFREE(buf); 00544 return len; 00545 }
|
|
Definition at line 1756 of file cgi_util.c. References GetField(), NULL, and SetName(). Referenced by Authenticate(), CGImain(), EZSReport(), RunReportF(), RunScript(), SaveData(), ShowFormPage(), ValidateBack(), and ValidatePage(). 01757 { 01758 d = GetField(d,oldname); 01759 if (d == NULL) return 0; 01760 SetName(d,newname); 01761 return 1; 01762 }
|
|
Definition at line 339 of file cgi_data.c. References CGIFREE, CGINameValue::name, NULL, and CGINameValue::value. Referenced by DatabaseReadRecord(). 00340 { 00341 for (; v->name; v++) 00342 { 00343 #ifdef CGIFREE 00344 CGIFREE(v->value); 00345 #else 00346 if (v->value != NULL) 00347 { 00348 CGIFREE(v->value); 00349 v->value = NULL; 00350 } 00351 #endif 00352 } 00353 }
|
|
where to stop processing, like /report
Definition at line 681 of file cgi_html.c. References RunReportF(). Referenced by CGImain(), EZSCounts(), EZSInclude(), EZSRandom(), EZSReport(), JSReport(), Login(), PrintFinish(), SaveData(), ShowForm(), ShowFormPage(), and WFmain(). 00685 {fieldname} */ 00686 CGINameValue * unused, 00687 int preset, 00688 char* stop) 00689 { 00690 return RunReportF( argv0, htmlout,source,cgidata,dbdata,unused,preset,stop,0,0); 00691 }
|
|
Definition at line 693 of file cgi_html.c. References DeleteNVP(), EvaluateLogic(), ExecEZSCommand(), EZSCounts(), EZSInclude(), EZSRandom(), EZSReport(), EZSSource(), FinishTag(), FormatReplacement(), GetFieldValue, HasToken(), HTMLEscape(), HTMLWrite(), HTMLWriteL(), IsValueSelected(), JSEval(), JSGetEnv(), JSHasRecord(), JSHTMLEscape(), JSIndexOf(), JSPrint(), JSRandom(), JSReport(), JSstrlen(), JSsubstr(), JSTimeStamp(), JStoFixed(), JSToNumber(), MAXBUF, NULL, NULLSTR, PrintScriptError(), PROFILEBEGIN, PROFILEEND, ReadHTMLAttributes(), ReadUntilChar(), ReadUntilWord(), ReadUntilWordS(), ReadUntilWordS2(), RenameField(), RunScript(), START, STOP, stricmp(), strnicmp(), and WriteHTMLAttributes(). Referenced by AdminPrintPage(), Index(), RunReport(), SpaceAdd(), and UserList(). 00697 {fieldname} */ 00698 CGINameValue * unused, 00699 int preset, 00700 char* stop, 00701 char* lastData, 00702 ScriptFunction * extra 00703 ) 00704 { 00705 char c[2],tag[MAXBUF],currentname[128]; 00706 int inscript=0; 00707 int e; 00708 00709 currentname[0]=0; 00710 PROFILEBEGIN(32) 00711 c[1]=0; 00712 00713 while (1) 00714 { 00715 00716 START(0); 00717 if (fread(c,1,1,source) == 0) {STOP(0) break;} 00718 STOP(0) 00719 00720 if (dbdata && inscript == 0) 00721 {/* search for {} replacements */ 00722 if (c[0] == '{') 00723 { 00724 fread(tag,1,1,source); 00725 if (strchr("} \t\r\n",tag[0])) 00726 {/* skip it */ 00727 HTMLWrite(htmlout,"{"); 00728 HTMLWriteL(htmlout,tag,1); 00729 continue; 00730 } 00731 else 00732 { 00733 START(2) 00734 ReadUntilChar(source,tag+1,sizeof(tag)-3,"}",0); 00735 tag[sizeof(tag)-2] = tag[sizeof(tag)-1] = 0; 00736 STOP(2) 00737 if (!*tag) 00738 continue; 00739 00740 if (stop) 00741 if (!stricmp(stop,tag)) 00742 return 0; 00743 00744 START(3) 00745 FormatReplacement(tag, htmlout, dbdata,0); 00746 STOP(3) 00747 continue; 00748 } 00749 } 00750 } 00751 00752 if (c[0] != '<') /* it's a potential tag */ 00753 { 00754 START(1) 00755 HTMLWrite(htmlout,c); 00756 STOP(1) 00757 continue; 00758 } 00759 00760 START(4) 00761 e = ReadUntilChar(source,tag,sizeof(tag)-2,"> \t\r\n",0); 00762 tag[sizeof(tag)-2] = tag[sizeof(tag)-1] = 0; 00763 STOP(4) 00764 if (e == EOF) break; 00765 00766 if (stop) 00767 if (!stricmp(stop,tag)) 00768 { 00769 if (e != '>') 00770 ReadUntilChar(source,lastData,lastData?MAXPATH:0,">",0); 00771 return 0; 00772 } 00773 00774 if (strnicmp(tag,"!--$",4) == 0) 00775 { 00776 START(5) 00777 FinishTag(source,tag, sizeof(tag), e, "-->"," \t\r\n"); 00778 FormatReplacement(tag+4,htmlout,cgidata,dbdata); 00779 STOP(5) 00780 continue; 00781 } 00782 00783 if (tag[0]=='%' && tag[1] == '=') 00784 { /* <%=variable_name %> */ 00785 // //HERE(""); 00786 START(6) 00787 FinishTag(source,tag, sizeof(tag), e, "%>"," \t\r\n"); 00788 FormatReplacement(tag+2,htmlout,cgidata,dbdata); 00789 STOP(6) 00790 continue; 00791 } 00792 00793 if (!strnicmp(tag,"%end",4)) /* %end or %endif */ 00794 { 00795 // //HERE(""); 00796 START(7) 00797 if (e != '>') ReadUntilChar(source,0,0,">",0); /* finish the tag */ 00798 STOP(7) 00799 continue; 00800 } 00801 00802 if (!stricmp(tag,"%break")) 00803 break; 00804 00805 startif: 00806 00807 if (!strnicmp(tag,"%if",3) ||!strnicmp(tag,"%elsif",6)||!strnicmp(tag,"%elif",5)) 00808 {/* note that nested %if doesn't work */ 00809 START(8) 00810 FinishTag(source,tag,sizeof(tag), e, "%>"," \t\r\n"); 00811 e = 0; 00812 if (!EvaluateLogic(tag+3,cgidata,dbdata)) 00813 { /* skip ahead to the next condition */ 00814 if (ReadUntilWordS2(source,0,"<%el","<%en") == 1) /* not case sensitive */ 00815 {/* '%elsif' '%elif ' '%else%' '%else ' '%else>' (condition) */ 00816 strcpy(tag,"%el"); 00817 e = ReadUntilChar(source,tag+3,sizeof(tag)-5,"> \t\r\n",0); 00818 00819 if (!stricmp(tag,"%else") && e &&strchr(" \t\r\n",e)) 00820 {/* '%else %>' '%else >' '%else if (...) %>' */ 00821 e = ReadUntilChar(source,tag,sizeof(tag)-2,"> \t\r\n",0); 00822 00823 if (!stricmp(tag,"if") && e != '>') 00824 strcpy(tag,"%elif"); 00825 else 00826 strcpy(tag,"%else"); 00827 } 00828 if (!strnicmp(tag,"%elsif",6)||!strnicmp(tag,"%elif",5)) 00829 goto startif; 00830 } 00831 if (e != '>') /* EOF or %endif or %else */ 00832 e = ReadUntilChar(source,0,0,">",0);/* finish the tag */ 00833 /* Resume from the %else and continue until %endif */ 00834 } 00835 STOP(8) 00836 continue; 00837 } 00838 if (!strnicmp(tag,"%else",5)) /* %if must have been true, skip to the end */ 00839 { 00840 START(9) 00841 ReadUntilWordS(source,NULL,"<%end"); 00842 ReadUntilChar(source,0,0,">",0); /* finish the tag */ 00843 STOP(9) 00844 continue; 00845 } 00846 00847 if (!strnicmp(tag,"%ezs",4)) 00848 { 00849 START(10) 00850 ExecEZSCommand(argv0,htmlout,source,cgidata,dbdata,unused,preset); 00851 STOP(10) 00852 continue; 00853 } 00854 00855 if (!stricmp(tag,"%include")) 00856 { 00857 START(11) 00858 EZSInclude(argv0,htmlout,source,cgidata,dbdata); 00859 STOP(11) 00860 continue; 00861 } 00862 00863 if (!stricmp(tag,"%source")) 00864 {START(12) 00865 EZSSource(argv0,htmlout,source); 00866 STOP(12) 00867 continue; 00868 } 00869 00870 if (!stricmp(tag,"%report")) 00871 { 00872 START(13) 00873 EZSReport(argv0,htmlout,source,cgidata); 00874 STOP(13) 00875 continue; 00876 } 00877 00878 if (!strnicmp(tag,"%random",7)) 00879 { 00880 START(14) 00881 EZSRandom(argv0,htmlout,source,cgidata,dbdata,unused,preset); 00882 STOP(14) 00883 continue; 00884 } 00885 00886 if (!stricmp(tag,"%stats")) 00887 { 00888 START(15) 00889 EZSCounts(argv0,htmlout,source, cgidata); 00890 STOP(15) 00891 continue; 00892 } 00893 if (tag[0] == '%' && tag[1] == 0 && htmlout) 00894 { 00895 int ret; 00896 ScriptFunction Functions[] = 00897 {{"print",10,(ScriptFunctionCall)*JSPrint}, 00898 {"write",10,(ScriptFunctionCall)*JSPrint}, 00899 {"eval",1,(ScriptFunctionCall)*JSEval}, 00900 {"timestamp",0,(ScriptFunctionCall)*JSTimeStamp}, 00901 {"toFixed",2,(ScriptFunctionCall)*JStoFixed}, 00902 {"escape",1,(ScriptFunctionCall)*JSHTMLEscape}, 00903 {"subStr",3,(ScriptFunctionCall)*JSsubstr}, 00904 {"indexOf",4,(ScriptFunctionCall)*JSIndexOf}, 00905 {"length",1,(ScriptFunctionCall)*JSstrlen}, 00906 {"hasRecord",1,(ScriptFunctionCall)*JSHasRecord}, 00907 {"runReport",8,(ScriptFunctionCall)*JSReport}, 00908 {"number",1,(ScriptFunctionCall)*JSToNumber}, 00909 {"environment",1,(ScriptFunctionCall)*JSGetEnv}, 00910 {"toNumber",1,(ScriptFunctionCall)*JSToNumber}, 00911 {"random",1,(ScriptFunctionCall)*JSRandom}, 00912 {0,0,0}}; 00913 ScriptObject Objects[] = 00914 {{"data",0}, 00915 {0,0}}; 00916 ScriptEnvironment Env; 00917 00918 START(16) 00919 memset(&Env,0,sizeof(Env)); 00920 Env.Functions = Functions; 00921 Env.Objects = Objects; 00922 Env.htmlout = htmlout; 00923 Env.argv0 = argv0; 00924 Env.F2 = extra; 00925 00926 Objects[0].data=dbdata; 00927 00928 ret = RunScript(&Env,source,cgidata); 00929 if (ret > 0) 00930 { 00931 HTMLWriteL(htmlout,"***",3); 00932 PrintScriptError(htmlout,&Env, source, ret); 00933 HTMLWriteL(htmlout,"***",3); 00934 } 00935 STOP(16) 00936 continue; 00937 } 00938 00939 if (stricmp(tag,"SCRIPT") == 0) inscript = 1; 00940 else if (stricmp(tag,"/SCRIPT")==0) inscript = 0; 00941 00942 if (preset && inscript == 0 && !stricmp(tag,"/SELECT")) 00943 { 00944 currentname[0] = 0; 00945 goto disregard; 00946 } 00947 00948 if (preset && inscript == 0) 00949 if (!stricmp(tag,"INPUT") 00950 || !stricmp(tag,"SELECT") 00951 || !stricmp(tag,"OPTION") 00952 || !stricmp(tag,"TEXTAREA") 00953 || !stricmp(tag,"/TEXTAREA")) 00954 { 00955 CGINameValue * attributes = 0; 00956 char *type, *name, *value, *fv; 00957 START(17) 00958 if (e != '>') attributes = ReadHTMLAttributes(source,32); 00959 00960 type = GetFieldValue(attributes,"TYPE"); 00961 name = GetFieldValue(attributes,"NAME"); 00962 value = GetFieldValue(attributes,"VALUE"); 00963 fv = *name ? GetFieldValue(cgidata,name) : NULLSTR; 00964 STOP(17) 00965 00966 if (stricmp(tag,"INPUT")==0) /* password, radio, checkbox, submit, reset, or text */ 00967 { 00968 START(18) 00969 if (unused && *name) while (RenameField(unused,name,0)); 00970 00971 HTMLWrite(htmlout,"<INPUT"); 00972 if (*name) 00973 { 00974 if (stricmp(type,"RADIO")==0 || stricmp(type,"CHECKBOX")==0) 00975 { 00976 if (*fv) 00977 { 00978 if (*value && HasToken(fv,value,0)) 00979 HTMLWrite(htmlout," CHECKED"); 00980 else 00981 RenameField(attributes,"CHECKED",0); 00982 } 00983 } 00984 else /* submit, password, or reset */ 00985 { 00986 HTMLWrite(htmlout," VALUE=\""); 00987 if (*fv) 00988 HTMLEscape(htmlout,fv); 00989 else 00990 HTMLWrite(htmlout,value); 00991 00992 HTMLWrite(htmlout,"\""); 00993 RenameField(attributes,"VALUE",NULL); 00994 } 00995 } 00996 WriteHTMLAttributes(htmlout,attributes); 00997 HTMLWrite(htmlout,">"); 00998 STOP(18) 00999 } 01000 else if (stricmp(tag,"SELECT")==0) 01001 { 01002 START(19) 01003 if (unused && *name) RenameField(unused,name,0); 01004 01005 strncpy(currentname,name,sizeof(currentname)); 01006 currentname[sizeof(currentname)-1]=0; 01007 HTMLWrite(htmlout,"<SELECT"); 01008 WriteHTMLAttributes(htmlout,attributes); 01009 HTMLWrite(htmlout,">"); 01010 STOP(19) 01011 } 01012 else if (stricmp(tag,"OPTION")==0) 01013 { 01014 char* query = GetFieldValue(attributes,"query"); 01015 START(20) 01016 if (*query && (EvaluateLogic(query,cgidata,0) != 1)) 01017 { 01018 ReadUntilWord(source,0,0,"</OPTION>"); 01019 } 01020 else if (*currentname) 01021 { 01022 HTMLWrite(htmlout,"<OPTION"); 01023 switch (IsValueSelected(cgidata,currentname,value)) 01024 { 01025 case 1: HTMLWrite(htmlout," SELECTED "); break; 01026 case 0: RenameField(attributes,"SELECTED",0); 01027 } 01028 WriteHTMLAttributes(htmlout,attributes); 01029 HTMLWrite(htmlout,">"); 01030 } 01031 STOP(20) 01032 } 01033 else if (*name && stricmp(tag,"TEXTAREA")==0) 01034 { 01035 START(21) 01036 if (unused && *name) RenameField(unused,name,0); 01037 01038 HTMLWrite(htmlout,"<TEXTAREA"); 01039 WriteHTMLAttributes(htmlout,attributes); 01040 HTMLWrite(htmlout,">"); 01041 01042 if (*fv) 01043 HTMLEscape(htmlout,fv); 01044 else 01045 HTMLEscape(htmlout,value); 01046 01047 HTMLWrite(htmlout,"</TEXTAREA>"); 01048 ReadUntilWordS(source,0,"</TEXTAREA>"); 01049 STOP(21) 01050 } 01051 /* /TEXTAREA does nothing */ 01052 01053 if (attributes) DeleteNVP(attributes); 01054 continue; /* we processed the tag */ 01055 } 01056 01057 /* disregard the tag */ 01058 START(22) 01059 disregard: 01060 HTMLWrite(htmlout,"<"); 01061 HTMLWrite(htmlout,tag); 01062 STOP(22) 01063 if (e == EOF) break; 01064 START(23) 01065 c[0]=(char)e; 01066 HTMLWrite(htmlout,c); 01067 STOP(23) 01068 } 01069 PROFILEEND 01070 return EOF; 01071 }
|
|
return values are
Definition at line 719 of file cgi_js.c. References CGIFREE, CGIMALLOC, ScriptEnvironment::curpos, DelimitedSection(), ScriptEnvironment::endchar, EvaluateArgument(), EvaluateLogic(), ExtendNVP(), GetFieldValue, HasTokenI(), IsNumber(), ScriptEnvironment::lastLine, ReadNextToken(), ReadUntilChar(), ReadUntilWord(), RenameField(), RunScript(), RunScriptFunction(), SetFieldValue(), strdup(), strdup3(), and stricmp(). Referenced by AdminRunScript(), CGImain(), ODBCRunScript(), RunReportF(), RunScript(), ValidateBack(), ValidatePage(), and WFmain(). 00720 { 00721 char* name; 00722 char word[4096]; 00723 /* int end = 0; */ 00724 int inif = 0; 00725 int CurrentTruth = 0; 00726 int ret = 0; 00727 int end = ' '; /* start with a clean slate */ 00728 /* HTMLPrintf(htmlout,"<P>Q3=%s\n",GetFieldValue(Variables,"Q3")); */ 00729 00730 name = 0; 00731 while (ret==0 && Env->endchar != -1) 00732 { 00733 Env->lastLine = ftell(script); 00734 end = ReadNextToken(script,word,sizeof(word),end,0); 00735 if (end <= 0) break; 00736 00737 if (word[0] == '#') /* Perl comments */ 00738 { 00739 end = ReadUntilChar(script,0,0,"\n",'\r'); 00740 continue; 00741 } 00742 if (word[0] == 0) continue; /* oops, between words. ignore it. */ 00743 if (word[0] == ';' || word[0] == '\n' || word[0] == ',') continue; 00744 /* comma or space can be delimiters, we don't care */ 00745 if (word[0] == '\'') ret = 43; /* misplaced string constant */ 00746 if (word[0] == '}') break; 00747 if (word[0] == '{') 00748 { 00749 ret = RunScript(Env,script,Variables); 00750 if (ret) break; 00751 end = Env->endchar; 00752 continue; 00753 } 00754 00755 /* C++ comments */ 00756 if (!strcmp(word,"//") && (end != '\n' && end != '\r')) 00757 { 00758 end = ReadUntilChar(script,0,0,"\r\n",0); 00759 continue; 00760 } 00761 00762 if (word[0] == '/') /* C comments */ 00763 if (word[1] == '*' && !strstr(word+2,"*/")) 00764 { 00765 ReadUntilWord(script,0,0,"*/"); 00766 end = ' '; 00767 continue; 00768 } 00769 00770 if (!stricmp(word,"var")) 00771 continue; 00772 00773 if (HasTokenI("</script>,&exit,quit,exit,&end,&return,%>",word,0)) 00774 {end = -1; break;} 00775 00776 // delete variable_name 00777 if (!stricmp(word,"delete")) 00778 { 00779 end = ReadNextToken(script,word,sizeof(word),end,0); 00780 if (*word) RenameField(Variables,word,0); 00781 if (end < 0) break; 00782 continue; 00783 } 00784 00785 if (!stricmp(word,"if")) /*evaluate a condition, and run the child code */ 00786 {/* end resets after DelimitedSection() */ 00787 startif: 00788 ret = DelimitedSection(script,word,sizeof(word),end,"(",")",41); 00789 if (ret) break; 00790 00791 CurrentTruth = EvaluateLogic(word,Variables,0); 00792 inif = 1; 00793 00794 if (CurrentTruth) 00795 { 00796 word[0] = '\n'; 00797 while (word[0] == '\n') 00798 end = ReadNextToken(script,word,sizeof(word),0,0); 00799 if (word[0] != '{') {ret = 70; break;} 00800 ret = RunScript(Env,script,Variables); 00801 if (ret) break; 00802 end = Env->endchar; 00803 } 00804 else 00805 { 00806 ret = DelimitedSection(script,0,0,0,"{","}",70); 00807 if (ret) break; 00808 end = ' '; 00809 } 00810 continue; 00811 } 00812 00813 if (!stricmp(word,"else")) /* finish an if condition */ 00814 { 00815 if (!inif) {ret = 44; break; } 00816 00817 if (end != '{') 00818 { 00819 end = ReadNextToken(script,word,sizeof(word),end,0); 00820 if (!stricmp(word,"if")) /* else if {foo()} , next token = if*/ 00821 goto elsif; 00822 else if (end < 0) 00823 break; 00824 else /* else {foo()}, next token = { */ 00825 end=word[0]; 00826 } 00827 00828 inif = 0; 00829 if (!CurrentTruth) 00830 { 00831 if (end != '{') 00832 { 00833 ret = 70; 00834 break; 00835 } 00836 ret = RunScript(Env,script,Variables); 00837 if (ret) break; 00838 end = Env->endchar; 00839 } 00840 else 00841 { 00842 skip: 00843 ret = DelimitedSection(script,0,0,end,"{","}",70); 00844 if (ret) break; 00845 end = ' '; 00846 } 00847 continue; 00848 } 00849 00850 if (!stricmp(word,"elif") || !stricmp(word,"elsif")) /*evaluate a condition, and run the child code*/ 00851 { 00852 elsif: 00853 if (!inif) {ret = 44; break; } 00854 if (CurrentTruth) 00855 goto skip; /* previous was false, so OK to evaluate this section */ 00856 else 00857 goto startif; /* evaluate this section */ 00858 } 00859 00860 /* out of an if section */ 00861 inif = 0; 00862 00863 /* variable assignment or function call*/ 00864 CGIFREE(name); 00865 name = strdup(word); 00866 00867 end = ReadNextToken(script,word,sizeof(word),end,0); 00868 00869 /* email = email + "@" "caltech.edu" */ 00870 /* total = Q1 + Q2 + Q3 + (Q4 * 4) */ 00871 if (!strcmp(word,"=") || !stricmp(word,"+=")) /* variable assignment */ 00872 { 00873 char* value = 0; 00874 ret = EvaluateArgument(Env,script,&end,Variables,"\r\n;}",&value,0); 00875 if (ret) break; 00876 00877 if (word[0] == '+') 00878 { 00879 char * c = GetFieldValue(Variables,name); 00880 if (IsNumber(c,0) && IsNumber(value,0)) 00881 { 00882 char* x=0; 00883 double a = strtod(c,&x); 00884 if (*x) goto concat; 00885 a += strtod(value,&x); 00886 if (*x) goto concat; 00887 CGIFREE(value); 00888 value = CGIMALLOC(64); 00889 sprintf(value,"%f",a); 00890 } 00891 else 00892 { 00893 concat: 00894 c = strdup3(c,value,""); 00895 CGIFREE(value); 00896 value = c; 00897 } 00898 } 00899 00900 if (!SetFieldValue(Variables,name,value)) 00901 { 00902 ExtendNVP(Variables,128); 00903 SetFieldValue(Variables,name,value); 00904 /* add to the list of 'shadow variables' that won't get saved */ 00905 } 00906 CGIFREE(value); 00907 } 00908 else if (!strcmp(word,"++")) /* numeric increment */ 00909 { 00910 char * c = GetFieldValue(Variables,name); 00911 char value[128]; 00912 sprintf(value,"%f",strtod(c,0) + 1.0); 00913 SetFieldValue(Variables,name,value); 00914 } 00915 else if (!strcmp(word,"(")) /* command, no lvalue */ 00916 { 00917 ret = RunScriptFunction(Env,script,end,name,Variables,0); 00918 end = ' '; /* eat the paren */ 00919 } 00920 else 00921 { 00922 ret = 46; /* unknown command */ 00923 break; 00924 } 00925 } /* while */ 00926 00927 CGIFREE(name); 00928 Env->endchar = end; 00929 Env->curpos = ftell(script); 00930 if (ret == -1) ret = 0; /* -1 is OK */ 00931 return ret; 00932 } /* RunScript */
|
|
Adds a new record to the database Definition at line 952 of file cgi_data.c. References CGIFCLOSE, CGIFOPEN, CreateDatabase(), and DatabaseSaveNewRecord(). 00953 { 00954 #if 0 00955 int x; 00956 FILE* handle; 00957 00958 /* Check to see if file exists*/ 00959 00960 handle=CGIFOPEN(filename,"rb"); 00961 if ( handle == 0 ) 00962 { 00963 x = CreateDatabase(data,filename); 00964 if (x) return x; 00965 /* that should ensure that the file exists, now open it in append mode*/ 00966 } 00967 else 00968 { 00969 CGIFCLOSE(handle); 00970 } 00971 #endif 00972 return DatabaseSaveNewRecord(filename,data,pos); 00973 }
|
|
Adds a new record to the database Definition at line 198 of file cgi_data.c. References CGIFCLOSE, CGIFOPEN, MAXPATH, NULL, swapchars(), and WriteXML(). 00199 { 00200 FILE* f = NULL; 00201 #ifndef __WINCE__ 00202 int fh; 00203 #endif 00204 #ifdef XP_POSIX 00205 static struct flock myLock ; 00206 #endif 00207 #if defined(XP_WIN) && !defined(VPWSCGI) 00208 HANDLE Mutex; 00209 char Mutex_name[MAXPATH+1]; 00210 #endif 00211 00212 /* 00213 #ifndef __WINCE__ 00214 if (access(filename,2)) return 6; 00215 #endif 00216 */ 00217 00218 #if defined(XP_WIN) && !defined(VPWSCGI) 00219 strncpy(Mutex_name,filename,MAXPATH); 00220 Mutex_name[MAXPATH] = 0; 00221 swapchars(Mutex_name, '\\', '/'); 00222 00223 Mutex = CreateMutex(0,FALSE,Mutex_name); 00224 00225 /* wait up to 20 seconds */ 00226 if (Mutex) if (WaitForSingleObject(Mutex,20000) == WAIT_TIMEOUT) 00227 { 00228 CloseHandle(Mutex); 00229 return 23; 00230 } 00231 #endif 00232 00233 #ifdef __WINCE__ 00234 f = CGIFOPEN(filename,"ab"); 00235 #else 00236 fh = open(filename,O_WRONLY|O_APPEND); 00237 if (fh != -1) 00238 { 00239 f = fdopen(fh,"ab"); 00240 } 00241 #endif 00242 00243 if (!f) return 8; 00244 00245 /* Wait for a file lock to become available */ 00246 #ifdef XP_POSIX 00247 myLock.l_type = F_WRLCK ; 00248 myLock.l_start = 0 ; 00249 myLock.l_whence = SEEK_END ; 00250 myLock.l_len = 0 ; 00251 myLock.l_pid = getpid() ; 00252 fcntl(fh, F_SETLKW, &myLock); 00253 #endif 00254 00255 00256 if (pos) *pos = ftell(f); 00257 WriteXML(f,data); 00258 00259 #ifdef XP_POSIX 00260 myLock.l_type = F_UNLCK; 00261 fcntl(fh, F_SETLKW, &myLock); 00262 #endif 00263 00264 #if defined(XP_WIN) && !defined(VPWSCGI) 00265 if (Mutex) 00266 { 00267 ReleaseMutex(Mutex); 00268 CloseHandle(Mutex); 00269 } 00270 #endif 00271 00272 CGIFCLOSE(f); 00273 return 0; 00274 }
|
|
send NULL for the default header "Content-type: text/html" Definition at line 262 of file cgi_cgi.c. Referenced by CGImain(), PrintFinish(), SendImage(), and WFmain(). 00263 { 00264 if (header != NULL) 00265 if (strlen(header)) 00266 { HTMLWrite(htmlout,header); return 1;} 00267 HTMLWrite(htmlout,CGI_DEFAULT_HEADER); 00268 return 1; 00269 }
|
|
Use sendmail -t on UNIX, Exchange on Windows on UNIX, the last 4 parameters are ignored. Definition at line 295 of file cgi_mail.c. References CMCSendMail(), and SMTPSendMail(). Referenced by CGImain(), JSSendMail(), and SaveData(). 00297 { 00298 int i = 1; 00299 00300 if (server) 00301 if (*server) 00302 i = SMTPSendMail(server, subject, recip, text); 00303 00304 if (i != 0) 00305 i = CMCSendMail(recip, subject,text,profile,name,password); 00306 00307 return i; 00308 }
|
|
Definition at line 1820 of file cgi_util.c. References GetField(), NULL, SetName(), and SetValue(). Referenced by Authenticate(), CGImain(), DoSetValue(), EZSReport(), JSShowPage(), ProjectUpdate(), RunScript(), SetupCGIData(), ShowFormPage(), ShowPage(), SpaceUpdate(), UserAddSpace(), UserUpdate(), and VerifyUser(). 01821 { 01822 CGINameValue *d = GetField(f,fieldname); 01823 if (d == NULL) 01824 { 01825 d = GetField(f,""); 01826 if (d == NULL) return 0; 01827 SetName(d,fieldname); 01828 } 01829 01830 if (d == NULL) return 0; 01831 01832 SetValue(d,value); 01833 return 1; 01834 }
|
|
Definition at line 53 of file cgi_log.c. References CGILogLevel. Referenced by LogStartup(). 00054 {CGILogLevel = i;}
|
|
Set the value to a zero-length string, which is faster than freeing memory, which might not have been malloced anyway. int RemoveFieldValue(CGINameValue*d, char* name) { d = GetField(d,name); if (d == NULL) return 0; if (d->value) d->value[0]=0; return 1; } Definition at line 1774 of file cgi_util.c. References CGIFREE, CGINameValue::name, NULL, strdup(), and CGINameValue::value. Referenced by RenameField(), and SetFieldValue(). 01775 { 01776 if (name == NULL) 01777 { 01778 if (d->name) d->name[0]=0; 01779 if (d->value) d->value[0]=0; 01780 } 01781 else 01782 { 01783 char *n = name; 01784 char *o = d->name; 01785 while (*n && *o) *o++ = *n++; 01786 if (*n == 0 && *o != 0) *o = 0; 01787 else if (*o == 0 && *n != 0) 01788 { 01789 CGIFREE(d->name); 01790 d->name = strdup(name); 01791 } 01792 } 01793 }
|
|
Definition at line 1795 of file cgi_util.c. References CGIFREE, NULL, strdup(), and CGINameValue::value. Referenced by CGImain(), SetFieldValue(), and UpdateStatistics(). 01796 { 01797 if (value == NULL) 01798 { 01799 if (d->value) d->value[0]=0; 01800 } 01801 else if (d->value == NULL) 01802 { 01803 goto set; 01804 } 01805 else 01806 { 01807 char *n = value; 01808 char *o = d->value; 01809 while (*n && *o) *o++ = *n++; 01810 if (*n == 0 && *o != 0) *o = 0; 01811 else if (*o == 0 && *n != 0) 01812 { 01813 CGIFREE(d->value); 01814 set: 01815 d->value = strdup(value); 01816 } 01817 } 01818 }
|
|
Definition at line 66 of file cgi_soap.c. References WinsockConnect(). 00067 { 00068 unsigned int s; 00069 #ifdef XP_WIN 00070 WSADATA d; 00071 #endif 00072 int err; 00073 char temp[128]; 00074 00075 #if 0 00076 #define send(a,b,c,d) fwrite(b,c,1,stdout) 00077 #endif 00078 00079 #ifdef XP_WIN 00080 if (WSAStartup(2, &d) != 0) /* init winsock lib. want v2.0 */ 00081 { 00082 WSACleanup(); 00083 return 61; 00084 } 00085 #endif 00086 00087 err = WinsockConnect(host, port, &s); 00088 if (!err) 00089 { 00090 send(s, "POST /", 6, 0); 00091 send(s, function, strlen(function), 0); 00092 send(s, " HTTP/1.1\r\n", 11, 0); 00093 send(s, "Host: ", 6, 0); 00094 send(s, host, strlen(host), 0); 00095 send(s, "\r\nContent-Type: text/xml; charset=\"utf-8\"\r\n", 43, 0); 00096 send(s, "Content-Length: ", 16, 0); 00097 sprintf(temp,"%d",strlen(data)); 00098 /* itoa(strlen(data), temp, 10); */ 00099 send(s, temp, strlen(temp), 0); 00100 send(s, "\r\nSOAPAction: " , 14, 0); 00101 send(s, action, strlen(action), 0); 00102 send(s, "\r\n\r\n", 4, 0); 00103 send(s, data, strlen(data), 0); 00104 } 00105 00106 if (s != INVALID_SOCKET) /* shutdown and close the socket if needed */ 00107 { shutdown(s, 2); /* shutdown both channels (read+write) */ 00108 #ifdef XP_WIN 00109 closesocket(s); 00110 #else 00111 close(s); 00112 #endif 00113 } 00114 #ifdef XP_WIN 00115 WSACleanup(); 00116 #endif 00117 return err; 00118 }
|
|
Definition at line 777 of file cgi_util.c. References strndup(). Referenced by _loaddbheader(), Authenticate(), CalcCountSummary(), CGImain(), CopyList(), CopyListDeep(), CopyListJoin(), CopyListN(), DatabaseFindNextRecord(), DatabaseReadRecord(), EvaluateAlgebra(), EvaluateExpression(), ExtendNVP(), FindUserRecordASC(), GenerateReport(), GetProjectExtra(), GetTotal(), Index(), JSGetEnv(), JSHasRecord(), JSIndexOf(), JSRankIndex(), JSstrlen(), JSsubstr(), JSTimeDate(), JSTimeStamp(), JSTimeTime(), JStoFixed(), JSToNumber(), JSUniqueId(), ReadCGIPostData(), ReadHTMLAttributes(), ReadPairedString(), ReadPairedValues(), RelativeName(), RunScript(), RunScriptObject(), SetName(), SetValue(), UpdateStatistics(), UserList(), and WriteXML(). 00778 { 00779 size_t length ; 00780 length = s ? strlen(s) : 0; 00781 return strndup((char*)s,length); 00782 }
|
|
Definition at line 785 of file cgi_util.c. References CGIMALLOC. Referenced by Authenticate(), CGImain(), EZSCounts(), GetTotal(), JSShowPage(), RecurseDirectories(), RelativeName(), RunScript(), ShowFormPage(), UpdateStatistics(), UserAddSpace(), ValidateBack(), ValidatePage(), and WriteINIFileSection(). 00786 { 00787 size_t l = strlen(a) + strlen(b)+strlen(c); 00788 char* x = CGIMALLOC(l+1); 00789 x[0]=0; 00790 if (x) strcpy(x,a); 00791 if (b) strcat(x,b); 00792 if (c) strcat(x,c); 00793 return x; 00794 }
|
|
Definition at line 748 of file cgi_util.c. Referenced by CGImain(), CheckCGISendMethod(), CheckPass(), CreateDatabase(), DatabaseSaveNewRecord(), ExecEZSCommand(), GenerateTableHeader(), GetField(), IsValueSelected(), LoadUserDataASC(), PrintPassword(), PrintRecords(), ReadINIFileSection(), ReadUntilWord2(), ReadUntilWordS2(), RunReportF(), RunScript(), RunScriptFunction(), RunScriptObject(), ShowAdmin(), ShowPage(), and WriteXML(). 00749 { 00750 int i; 00751 while (*a && *b) 00752 { 00753 i = toupper(*a) - toupper(*b); 00754 if (i != 0) return i; 00755 a++; 00756 b++; 00757 } 00758 return *a - *b; 00759 }
|
|
Definition at line 1462 of file cgi_util.c. Referenced by CGImain(), DatabaseSearchRecord(), GetProjectExtra(), Index(), JSIndexOf(), JSPrint(), RecurseDirectories(), SendImage(), UserList(), WFmain(), and WriteINIFileSection(). 01463 { 01464 return strn2istr(s1,s2,strlen(s2)); 01465 }
|
|
search c1 up to length len for token c2, stopping at a character from end Definition at line 869 of file cgi_util.c. Referenced by ClearToken(), and HasTokenX(). 00870 { 00871 if (length) do 00872 { 00873 if (cs) 00874 { 00875 if (*c1 != *c2) return 0; 00876 } 00877 else if (toupper(*c1) != toupper(*c2)) return 0; 00878 00879 c1++; 00880 c2++; 00881 length--; 00882 /* if (end of token AND end of comparison) */ 00883 if ((*c2==0) && (!length||*c1==0||strchr(end,*c1))) return 1; 00884 } while (length); 00885 return 0; 00886 }
|
|
Definition at line 1452 of file cgi_util.c. Referenced by ComparisonEvaluation(), and stristr(). 01453 { 01454 while (*s1) 01455 { 01456 if (strnicmp(s1,s2,l2) == 0) return s1; 01457 s1++; 01458 } 01459 return 0; 01460 }
|
|
Definition at line 796 of file cgi_util.c. References CGIMALLOC. Referenced by ComparisonEvaluation(), DoEvaluateComparison(), EvaluateAlgebra(), JSsubstr(), ODBCRead(), ReadPairedString(), ReadPairedValues(), and strdup(). 00797 { 00798 char * c; 00799 c = CGIMALLOC(length+3); 00800 if (s && length) strncpy(c,s,length); 00801 c[length]=0; 00802 return c; 00803 }
|
|
Definition at line 761 of file cgi_util.c. Referenced by CGImain(), CheckCGISendMethod(), ComparisonEvaluation(), DoEvaluateComparison(), FormatReplacement(), LoadUserData(), RunReportF(), ShowAdmin(), ShowFormPage(), ShowPage(), SMTPSendMail(), and strn2istr(). 00762 { 00763 int i; 00764 while (*a && *b && length) 00765 { 00766 i = toupper(*a) - toupper(*b); 00767 if (i != 0) return i; 00768 ++a; 00769 ++b; 00770 --length; 00771 } 00772 return length ? toupper(*a) - toupper(*b) : 0; 00773 }
|
|
Definition at line 741 of file cgi_util.c. Referenced by AdminPrintPage(), CGImain(), EZSRandom(), main(), ReadCGIGetData(), ReadCGIPostData(), SaveData(), and SaveDataToXML().
|
|
Definition at line 280 of file cgi_util.c. References int16ToUTF8(), and unB64(). Referenced by ReadCGIGetData(), and ReadCGIPostData(). 00281 { 00282 char* read = write; 00283 00284 while (*read) 00285 { 00286 if (*read == '+') 00287 { 00288 int x, step, out, i[2], ch[2]; 00289 if (read[1] == '-') 00290 { 00291 *write++ = *read++; 00292 read++; 00293 continue; 00294 } 00295 read++; 00296 step = 0; 00297 out = 0; 00298 00299 while (*read && *read != '-') 00300 { 00301 x = unB64(*read); 00302 if (x == -1) break; 00303 i[step % 2]=x; 00304 00305 if (step % 4) 00306 ch[out++%2] = ((i[(step+1)%2] << ((step%4) * 2)) | (i[step%2] >> (6 - ((step%4) * 2)))) & 0x00ff; 00307 00308 if (step == 2 || step == 5 || step == 7) 00309 write += int16ToUTF8((ch[0] << 8) | ch[1],write); 00310 read++; 00311 step = (step + 1) % 8; 00312 } 00313 if (*read == '-') read++; /* eat the - */ 00314 else if (*read) *write++ = *read++; 00315 } 00316 else 00317 { 00318 *write++ = *read++; 00319 } 00320 } 00321 *write = 0; 00322 }
|
|
Definition at line 1013 of file cgi_util.c. Referenced by HTMLEscape(), and JSHTMLEscape(). 01014 { 01015 if ((in[0] & 0x80) == 0) {*c=in[0]; return 1;} /* 1 character OK */ 01016 01017 /* 110xxxxx 10xxxxxx */ 01018 if (((in[0] & 0xe0) == 0xc0) && ((in[1] & 0xc0) == 0x80)) 01019 { *c = (int)( ((in[0] & 0x1f) << 6) | (in[1] & 0x3f)); return 2;} 01020 01021 /* 1110xxxx 10xxxxxx 10xxxxxx */ 01022 if (((in[0] & 0xf0) == 0xe0) && ((in[1] & 0xc0) == 0x80) && ((in[2] & 0xc0 )== 0x80)) 01023 { *c = (int)(((in[0] & 0x0f) << 12) | ((in[1] & 0x3f) << 6)| (in[2] & 0x3f)); return 3;} 01024 01025 /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ 01026 if (((in[0] & 0xf8) == 0xf0) && ((in[1] & 0xc0) == 0x80) && ((in[2] & 0xc0 )== 0x80)&& ((in[3] & 0xc0) == 0x80)) 01027 { *c = (int)(((in[0] & 0x0f) << 18) | ((in[1] & 0x3f) << 12)| ((in[2] & 0x3f) <<6)| ((in[3] & 0x3f))); return 4;} 01028 01029 return 0; /*error */ 01030 }
|
|
Definition at line 31 of file cgi_soap.c. Referenced by main(), SMTPSendMail(), and SOAPExec(). 00032 { 00033 long int hostaddr = 0; 00034 unsigned long *p; 00035 struct sockaddr_in svraddr; 00036 struct hostent *he; 00037 *s = INVALID_SOCKET; 00038 00039 if (isdigit(host[0])) /* something like 192.168.0.1 */ 00040 { 00041 hostaddr = inet_addr(host); /* convert to 32bit unsigned int */ 00042 } 00043 else /* something like phoenix.ttdev.com */ 00044 { 00045 he = gethostbyname(host); /* convert to 32bit unsigned int */ 00046 if (!he) {return 62;} 00047 p = (unsigned long*)he->h_addr_list[0]; 00048 hostaddr = *p; 00049 } 00050 00051 *s = socket(AF_INET, SOCK_STREAM, 0); /* make Internet socket */ 00052 00053 if (*s == INVALID_SOCKET) return 63; 00054 00055 svraddr.sin_family = AF_INET; /* Internet address family */ 00056 svraddr.sin_port = htons(port); /* port */ 00057 memcpy(&svraddr.sin_addr.s_addr, &hostaddr, sizeof(INADDR_ANY)); /* host addr */ 00058 memset(svraddr.sin_zero,0,sizeof(svraddr.sin_zero)); 00059 00060 if (connect(*s, (SOCKADDR*)&svraddr, sizeof(svraddr)) != 0) 00061 return 64; 00062 00063 return 0; 00064 }
|
|
Generates an XML TRANSACTION tag from data. Links are expected to be seen as parentfield_number_childfield Definition at line 127 of file cgi_data.c. References CGIFREE, CGINameValue::name, NULL, strdup(), and stricmp(). Referenced by SaveDataToXML(). 00128 { 00129 int i; 00130 char * currentchild = NULL; 00131 int currentitem = -1; 00132 00133 fprintf(f,"<TRANSACTION>"); 00134 00135 for(i=0;data[i].name;i++) /* skip host, date, time */ 00136 { 00137 char * c; 00138 int inchild = 0; 00139 char* name; 00140 if (!data[i].name[0]) continue; 00141 if (data[i].name[0] == '_') continue; 00142 00143 name = data[i].name; 00144 c = strchr(name,'_'); 00145 00146 if (c) 00147 if (strchr(c+2,'_')) 00148 if (strchr("1234567890",c[1])) /* item_1_name */ 00149 { 00150 int thisitem; 00151 int newobj = 0; 00152 char* newchild = strdup(name); 00153 00154 inchild = 1; 00155 c = strchr(newchild,'_'); 00156 00157 thisitem = atoi(c+1); 00158 00159 name = strchr(c+2,'_'); 00160 if (name) name++; 00161 00162 c[0] = 0; 00163 00164 if (thisitem != currentitem || stricmp(currentchild,newchild)) 00165 { 00166 newobj = 1; 00167 currentitem = thisitem; 00168 } 00169 00170 if (newobj && currentchild) fprintf(f,"</%s>\n",currentchild); 00171 00172 if (name) 00173 { 00174 if (currentchild) CGIFREE(currentchild); 00175 currentchild = newchild; 00176 if (newobj) fprintf(f,"<%s id=%d>\n",currentchild,thisitem); 00177 } 00178 else name=data[1].name; 00179 } 00180 00181 if (inchild == 0 && currentchild) 00182 { 00183 fprintf(f,"</%s>\n",currentchild); 00184 if (currentchild) CGIFREE(currentchild); 00185 currentchild = NULL; 00186 00187 } 00188 00189 fprintf(f,"<%s>%s</%s>\n",name,data[i].value,name); 00190 00191 } 00192 00193 if (currentchild) printf("</%s>\n",currentchild); 00194 if (currentchild) CGIFREE(currentchild); 00195 fprintf(f,"</TRANSACTION>\n"); 00196 }
|