G:/ScriptBasic/source/extensions/cgi/interface.c File Reference

#include <stdio.h>
#include <string.h>
#include "../../basext.h"
#include "cgi.h"

Go to the source code of this file.

Data Structures

struct  _ModuleObject

Defines

#define ENVIRFUNC(XXX)

Typedefs

typedef _ModuleObject ModuleObject
typedef _ModuleObjectpModuleObject

Functions

static void DBGPR (char *s,...)
besVERSION_NEGOTIATE return (int)
 if (besMODULEPOINTER==NULL)
 if (p->Cgi.lBufferIncrease=lOptionValue=besOPTION("cgi$bufferincrease"))
 if (p->symboltable!=NULL)
besEND besFUNCTION (getget)
 besCONVERT2ZCHAR (Argument, pszArgument)
 besFREE (pszArgument)
 if (pszResult)
 besDEREFERENCE (Argument)
 if (Argument==NULL)
 besLEFTVALUE (SymVAR, pSymVAR)
 if (pSymVAR)
 besDEREFERENCE (FileName)
 if (fi==NULL)
 besCONVERT2ZCHAR (FileName, pszFileName)
 DBGPR ("file %s handle is %p\n", pszFileName, fp)
 besFREE (pszFileName)
 if (fp==NULL)
 while ((ch=fgetc(fi))!=EOF)
 if (besRETURNVALUE==NULL)
 if (besARGNR >=1)
 if (p->symboltable==NULL)
 besFREE (pszName)
static besEND void freesymbol_callback (char *SymbolName, char *SymbolValue, void *p)
 besFUNCTION (resetsymt)
besEND besFUNCTION (defsfile)
 besFREE (pszFile)
 for (i=0;i< lFileLength &&(ch=besFGETC(fp))!=EOF;i++)
 besFCLOSE (fp)
besEND besFUNCTION (getfile)
 for (i=0;pszValue[i];i++)
 besALLOC_RETURN_STRING (cTotalChars)
 for (j=i=0;pszValue[i];i++)

Variables

return Unknown CGI module error
besEND besSUB_START pModuleObject p
long lOptionValue
long lErrorCode
char * s
 besMODULEPOINTER = besALLOC(sizeof(ModuleObject))
 return
 Argument = besCONVERT2STRING(Argument)
 pszResult = cgi_GetParam(&(p->Cgi),pszArgument)
VARIABLE Argument
char * pszArgument
char * pszResult
long slen
 p = (pModuleObject)besMODULEPOINTER
 Argument = besARGUMENT(1)
 Argument = besCONVERT2STRING(Argument)
 pszResult = cgi_PostParam(&(p->Cgi),pszArgument)
VARIABLE Argument
VARIABLE * pSymVAR
VARIABLE SymVAR
pSymbolList pSYM
char * pszArgument
char * pszResult
long slen
unsigned long __refcount_
 p = (pModuleObject)besMODULEPOINTER
 Argument = besARGUMENT(1)
 SymVAR = besARGUMENT(2)
 pszResult = cgi_GetParamEx(&(p->Cgi),pszArgument,&pSYM)
VARIABLE Argument
VARIABLE * pSymVAR
VARIABLE SymVAR
pSymbolList pSYM
char * pszArgument
char * pszResult
long slen
unsigned long __refcount_
 p = (pModuleObject)besMODULEPOINTER
 Argument = besARGUMENT(1)
 SymVAR = besARGUMENT(2)
 pszResult = cgi_PostParamEx(&(p->Cgi),pszArgument,&pSYM)
VARIABLE Argument
VARIABLE FileName
char * pszArgument
char * pszFileName
FILE * fp
FILE * fi
int ch
 p = (pModuleObject)besMODULEPOINTER
 Argument = besARGUMENT(1)
 FileName = besARGUMENT(2)
 Argument = besCONVERT2STRING(Argument)
 FileName = besCONVERT2STRING(FileName)
 fi = cgi_FILEp(&(p->Cgi),pszArgument)
 fp = besHOOK_FOPEN(pszFileName,"wb")
 Argument = besCONVERT2STRING(Argument)
 pszResult = cgi_OriginalFileName(&(p->Cgi),pszArgument)
VARIABLE Argument
char * pszArgument
long lResult
 p = (pModuleObject)besMODULEPOINTER
 Argument = besARGUMENT(1)
 Argument = besCONVERT2STRING(Argument)
 lResult = cgi_FileLength(&(p->Cgi),pszArgument)
 besRETURNVALUE = besNEWMORTALLONG
long slen
pModuleObject p
 p = (pModuleObject)besMODULEPOINTER
 pszResult = cgi_Cookie( &(p->Cgi) )
VARIABLE Argument
char * pszName
char * pszValue = (char)0
void ** q
 p = (pModuleObject)besMODULEPOINTER
 pszName = pszValue = NULL
 q = besLOOKUPSYMBOL(pszName,p->symboltable,1)
if q besFREE * q
q = pszValue
 fp = besFOPEN(pszFile,"rb")
 lFileLength = besSIZE(pszFile)
 pszValue = besALLOC(lFileLength+1)
 q = besLOOKUPSYMBOL(pszName,p->symboltable,1)
if q besFREE * q
q = pszValue
else return COMMAND_ERROR_FILE_CANNOT_BE_OPENED
 cInsertedChars = 0
 cTotalChars = i - cRemovedChars + cInsertedChars
 pszResult = STRINGVALUE(besRETURNVALUE )
 return
besEND SLFST CGI_SLFST []


Define Documentation

#define ENVIRFUNC XXX   ) 
 

Value:


Typedef Documentation

typedef struct _ModuleObject ModuleObject
 

typedef struct _ModuleObject* pModuleObject
 


Function Documentation

besALLOC_RETURN_STRING cTotalChars   ) 
 

besCONVERT2ZCHAR FileName  ,
pszFileName 
 

besCONVERT2ZCHAR Argument  ,
pszArgument 
 

besDEREFERENCE FileName   ) 
 

besDEREFERENCE Argument   ) 
 

besFCLOSE fp   ) 
 

Referenced by besFUNCTION(), and CHECK_OPTION().

besFREE pszFile   ) 
 

besFREE pszName   ) 
 

besFREE pszFileName   ) 
 

besFREE pszArgument   ) 
 

besEND besFUNCTION getfile   ) 
 

Definition at line 1321 of file interface.c.

besEND besFUNCTION defsfile   ) 
 

Definition at line 1264 of file interface.c.

besFUNCTION resetsymt   ) 
 

Definition at line 1247 of file interface.c.

besEND besFUNCTION getget   ) 
 

=section GetParam =H cgi::GetParam("name")

This function returns the value of the GET parameter named in the argument. If there are multiple GET parameter with the same name the function returns the first one.

The CGI parameter names are case sensitive according to the CGI standard.

Definition at line 322 of file interface.c.

besLEFTVALUE SymVAR  ,
pSymVAR 
 

Referenced by besFUNCTION().

DBGPR "file %s handle is %p\n"  ,
pszFileName  ,
fp 
 

static void DBGPR char *  s,
  ...
[static]
 

=H Handle CGI input and output

=abstract Functions that handle web input data for the standalone module running as CGI or ISAPI or Eszter SB Engine variation. =end

The module CGI is implemented as an external module written in the language C. Whenever the programmer wants to write a program using the language ScriptBasic that uses the CGI interface of the web server he or she can use this module. Although this is not a must to use this module for CGI programming it IS a wise choice.

The module comes from the developers of the language interpreter. Most of its code is implemented as C code, executing fast and efficient. In its very first version of the module it already supports such advanced features as file upload in a robust and secure way. It handles cookies, POST and GET operations and will support other interfaces in the future like Apache Module interface or FastCGI in a compatible manner.

The basic programs using the ISAPI interpreter should use the module the same way as CGI versions. In other words if you write a CGI program it should work executed by the ISAPI version of the interpreter without modification. /** =section ack =H Acknowledgements

The core code of the CGI handling routines was not written just looking at the RFC. I have learned a lot from other works. The most important to mention is the CGI.pm Perl module written by Lincoln D. Stein (http://www-genome.wi.mit.edu/ftp/pub/software/WWW/cgi_docs.html) Another work was named cgi-lib.c created by eekim@eekim.com. This piece of code gave me the last push to finish looking for readily available free library to interface with ScriptBasic and write instead a new one.

The ISAPI interface was developed using the Microsoft Developer Network CD documentation and I really learned a lot while testing the different uses of the function ReadClient until I could figure out that the official Microsoft documentation is wrong.

It says: "If more than lpdwSize bytes are immediately available to be read, ReadClient will block until some amount of data has been returned, and will return with less than the requested amount of data." In fact it has to be "If less than lpdwSize bytes are immediately available to be read, ReadClient will block until some amount of data has been returned, and will return with possibly less than the requested amount of data."

Definition at line 200 of file interface.c.

for j  = i=0 ; pszValue[i] ; i++  ) 
 

Definition at line 1460 of file interface.c.

for i  = 0 ; pszValue[i] ; i++  ) 
 

Definition at line 1367 of file interface.c.

for  ) 
 

Definition at line 1299 of file interface.c.

static besEND void freesymbol_callback char *  SymbolName,
char *  SymbolValue,
void *  p
[static]
 

Definition at line 1236 of file interface.c.

if p->  symboltable = NULL  ) 
 

Definition at line 1224 of file interface.c.

if besARGNR >=  1  ) 
 

Definition at line 1210 of file interface.c.

if besRETURNVALUE  = NULL  ) 
 

Definition at line 664 of file interface.c.

if fp  = NULL  ) 
 

Definition at line 590 of file interface.c.

if fi  = NULL  ) 
 

Definition at line 582 of file interface.c.

if pSymVAR   ) 
 

Definition at line 434 of file interface.c.

if Argument  = NULL  ) 
 

Definition at line 369 of file interface.c.

if pszResult   ) 
 

Definition at line 339 of file interface.c.

if p->symboltable!  = NULL  ) 
 

Definition at line 306 of file interface.c.

if p->Cgi.lBufferIncrease =  lOptionValue = besOPTION("cgi$bufferincrease")  ) 
 

Definition at line 262 of file interface.c.

if besMODULEPOINTER  = NULL  ) 
 

Definition at line 250 of file interface.c.

besVERSION_NEGOTIATE return int   ) 
 

=H Error Codes

Definition at line 211 of file interface.c.

while (ch=fgetc(fi))!  = EOF  ) 
 

Definition at line 594 of file interface.c.


Variable Documentation

unsigned long __refcount_
 

Definition at line 488 of file interface.c.

unsigned long __refcount_
 

Definition at line 426 of file interface.c.

Referenced by execute_LeftValueArray(), and execute_LeftValueSarray().

VARIABLE Argument
 

Definition at line 1202 of file interface.c.

Argument = besCONVERT2STRING(Argument)
 

Definition at line 659 of file interface.c.

Argument = besARGUMENT(1)
 

Definition at line 653 of file interface.c.

VARIABLE Argument
 

Definition at line 647 of file interface.c.

Argument = besCONVERT2STRING(Argument)
 

Definition at line 622 of file interface.c.

Argument = besCONVERT2STRING(Argument)
 

Definition at line 576 of file interface.c.

Argument = besARGUMENT(1)
 

Definition at line 572 of file interface.c.

VARIABLE Argument
 

Definition at line 564 of file interface.c.

Argument = besARGUMENT(1)
 

Definition at line 492 of file interface.c.

VARIABLE Argument
 

Definition at line 483 of file interface.c.

Argument = besARGUMENT(1)
 

Definition at line 430 of file interface.c.

VARIABLE Argument
 

Definition at line 421 of file interface.c.

Argument = besCONVERT2STRING(Argument)
 

Definition at line 373 of file interface.c.

Argument = besARGUMENT(1)
 

Definition at line 367 of file interface.c.

VARIABLE Argument
 

Definition at line 361 of file interface.c.

Argument = besCONVERT2STRING(Argument)
 

Definition at line 335 of file interface.c.

besMODULEPOINTER = besALLOC(sizeof(ModuleObject))
 

Definition at line 249 of file interface.c.

Referenced by __InsertImage(), __RemoveImage(), besFUNCTION(), F_LibraryLoaded(), and if().

besRETURNVALUE = besNEWMORTALLONG
 

Definition at line 663 of file interface.c.

Referenced by besFUNCTION(), if(), and switch().

besEND SLFST CGI_SLFST[]
 

Definition at line 1543 of file interface.c.

int ch
 

Definition at line 568 of file interface.c.

cInsertedChars = 0
 

Definition at line 1363 of file interface.c.

else return COMMAND_ERROR_FILE_CANNOT_BE_OPENED
 

Definition at line 1342 of file interface.c.

Referenced by besFUNCTION(), CHECK_OPTION(), and if().

cTotalChars = i - cRemovedChars + cInsertedChars
 

Definition at line 1455 of file interface.c.

return Unknown CGI module error
 

Definition at line 241 of file interface.c.

Referenced by main().

fi = cgi_FILEp(&(p->Cgi),pszArgument)
 

Definition at line 580 of file interface.c.

FILE * fi
 

Definition at line 567 of file interface.c.

Referenced by build_SaveECode().

FileName = besCONVERT2STRING(FileName)
 

Definition at line 577 of file interface.c.

FileName = besARGUMENT(2)
 

Definition at line 573 of file interface.c.

VARIABLE FileName
 

Definition at line 564 of file interface.c.

fp = besFOPEN(pszFile,"rb")
 

Definition at line 1290 of file interface.c.

fp = besHOOK_FOPEN(pszFileName,"wb")
 

Definition at line 587 of file interface.c.

FILE* fp
 

Definition at line 567 of file interface.c.

long lErrorCode
 

Definition at line 246 of file interface.c.

Referenced by cgi_GetMultipartParameters().

lFileLength = besSIZE(pszFile)
 

Definition at line 1296 of file interface.c.

long lOptionValue
 

Definition at line 246 of file interface.c.

lResult = cgi_FileLength(&(p->Cgi),pszArgument)
 

Definition at line 661 of file interface.c.

long lResult
 

Definition at line 650 of file interface.c.

p = (pModuleObject)besMODULEPOINTER
 

Definition at line 1207 of file interface.c.

p = (pModuleObject)besMODULEPOINTER
 

Definition at line 936 of file interface.c.

pModuleObject p
 

Definition at line 935 of file interface.c.

p = (pModuleObject)besMODULEPOINTER
 

Definition at line 651 of file interface.c.

p = (pModuleObject)besMODULEPOINTER
 

Definition at line 570 of file interface.c.

p = (pModuleObject)besMODULEPOINTER
 

Definition at line 490 of file interface.c.

p = (pModuleObject)besMODULEPOINTER
 

Definition at line 428 of file interface.c.

p = (pModuleObject)besMODULEPOINTER
 

Definition at line 365 of file interface.c.

besEND besSUB_START pModuleObject p
 

Definition at line 245 of file interface.c.

pSymbolList pSYM
 

Definition at line 485 of file interface.c.

pSymbolList pSYM
 

Definition at line 423 of file interface.c.

VARIABLE * pSymVAR
 

Definition at line 483 of file interface.c.

VARIABLE * pSymVAR
 

Definition at line 421 of file interface.c.

char* pszArgument
 

Definition at line 649 of file interface.c.

char* pszArgument
 

Definition at line 566 of file interface.c.

char* pszArgument
 

Definition at line 486 of file interface.c.

char* pszArgument
 

Definition at line 424 of file interface.c.

char* pszArgument
 

Definition at line 363 of file interface.c.

char * pszFileName
 

Definition at line 566 of file interface.c.

Referenced by ex_Command_l(), GetSourceLineNumber(), if(), and lex_ReadInput().

pszName = pszValue = NULL
 

Definition at line 1208 of file interface.c.

char* pszName
 

Definition at line 1204 of file interface.c.

pszResult = STRINGVALUE(besRETURNVALUE )
 

Definition at line 1457 of file interface.c.

pszResult = cgi_Cookie( &(p->Cgi) )
 

Definition at line 937 of file interface.c.

pszResult = cgi_OriginalFileName(&(p->Cgi),pszArgument)
 

Definition at line 624 of file interface.c.

pszResult = cgi_PostParamEx(&(p->Cgi),pszArgument,&pSYM)
 

Definition at line 514 of file interface.c.

char * pszResult
 

Definition at line 486 of file interface.c.

pszResult = cgi_GetParamEx(&(p->Cgi),pszArgument,&pSYM)
 

Definition at line 452 of file interface.c.

char * pszResult
 

Definition at line 424 of file interface.c.

pszResult = cgi_PostParam(&(p->Cgi),pszArgument)
 

Definition at line 375 of file interface.c.

char * pszResult
 

Definition at line 363 of file interface.c.

pszResult = cgi_GetParam(&(p->Cgi),pszArgument)
 

Definition at line 337 of file interface.c.

pszValue = besALLOC(lFileLength+1)
 

Definition at line 1298 of file interface.c.

pszValue[i] = (char)0
 

Definition at line 1204 of file interface.c.

Referenced by cgi_ReadHeader(), and main().

* q = pszValue
 

Definition at line 1313 of file interface.c.

if q besFREE* q
 

Definition at line 1312 of file interface.c.

q = besLOOKUPSYMBOL(pszName,p->symboltable,1)
 

Definition at line 1310 of file interface.c.

* q = pszValue
 

Definition at line 1232 of file interface.c.

if q besFREE* q
 

Definition at line 1231 of file interface.c.

q = besLOOKUPSYMBOL(pszName,p->symboltable,1)
 

Definition at line 1229 of file interface.c.

void** q
 

Definition at line 1205 of file interface.c.

return
 

Definition at line 1540 of file interface.c.

return
 

Definition at line 310 of file interface.c.

char* s
 

Definition at line 247 of file interface.c.

long slen
 

Definition at line 933 of file interface.c.

long slen
 

Definition at line 487 of file interface.c.

long slen
 

Definition at line 425 of file interface.c.

long slen
 

Definition at line 364 of file interface.c.

SymVAR = besARGUMENT(2)
 

Definition at line 493 of file interface.c.

VARIABLE SymVAR
 

Definition at line 483 of file interface.c.

SymVAR = besARGUMENT(2)
 

Definition at line 431 of file interface.c.

VARIABLE SymVAR
 

Definition at line 421 of file interface.c.


Generated on Sun Mar 12 23:56:35 2006 for ScriptBasic by  doxygen 1.4.6-NO