unit uncgi; { $Id$ UNCGI UNIT 2.0.11 ---------------- } interface uses strings {$ifdef linux} ,linux {$endif} {$IFDEF OS2} , DosCalls {$ENDIF OS2} ; {***********************************************************************} const maxquery = 100; hextable : array[0..15] of char=('0','1','2','3','4','5','6','7', '8','9','A','B','C','D','E','F'); uncgi_version = 'UNCGI 2.0.11'; uncgi_year = '1999'; maintainer_name = 'Your Name Here'; maintainer_email= 'your@email.address.here'; Type cgi_error_proc = procedure (Const Proc,Err : String); var get_nodata : boolean; query_read : word; query_array : array[1..2,1..maxquery] of pchar; uncgi_error : cgi_error_proc; {***********************************************************************} { FUNCTION This function returns the REQUEST METHOD of the CGI-BIN script Input - Nothing Output - [GET|POST] } function http_request_method: pchar; { FUNCTION This function returns the "referring" page. i.e. the page you followed the link to this CGI-BIN from Input - Nothing Output - [http://somewhere.a.tld] } function http_referer: pchar; { FUNCTION This function returns the users's USER AGENT, the browser name etc. Input - Nothing Output - user agent string } function http_useragent: pchar; { FUNCTION This function returns a value from an id=value pair Input - The identifier you want the value from Output - If the identifier was found, the resulting value is the output, otherwise the output is NIL } function get_value(id: pchar): pchar; { PROCEDURE This procedure writes the content-type to the screen Input - The content type in MIME format Output - Nothing Example - set_content('text/plain'); set_content('text/html'); } procedure set_content(ctype: string); procedure cgi_init; procedure cgi_deinit; implementation {$IFDEF OS2} function GetEnv (EnvVar: string): PChar; var RC: longint; P, Q: PChar; begin GetMem (Q, Succ (Length (EnvVar))); RC := DosScanEnv (Q, P); FreeMem (Q, Succ (Length (EnvVar))); GetEnv := P; end; {$ENDIF OS2} {$ifdef win32} Var EnvP : PChar; EnvLen : Longint; OldExitProc : Pointer; function GetEnvironmentStrings : pchar; external 'kernel32' name 'GetEnvironmentStringsA'; function FreeEnvironmentStrings(p : pchar) : longbool; external 'kernel32' name 'FreeEnvironmentStringsA'; Procedure FInitWin32CGI; begin { Free memory } FreeMem (EnvP,EnvLen); ExitProc:=OldExitProc; end; Procedure InitWin32CGI; var s : String; i,len : longint; hp,p : pchar; begin { Make a local copy of environment} p:=GetEnvironmentStrings; hp:=p; envp:=Nil; envlen:=0; while hp[0]<>#0 do begin len:=strlen(hp); hp:=hp+len+1; EnvLen:=Envlen+len+1; end; GetMem(EnvP,Envlen); Move(P^,EnvP^,EnvLen); FreeEnvironmentStrings(p); OldExitProc:=ExitProc; ExitProc:=@FinitWin32CGI; end; Function GetEnv(envvar: string): pchar; { Getenv that can return environment vars of length>255 } var s : String; i,len : longint; hp : pchar; begin s:=Envvar+#0; getenv:=Nil; hp:=envp; while hp[0]<>#0 do begin len:=strlen(hp); i:=Longint(strscan(hp,'='))-longint(hp); if StrLIComp(@s[1],HP,i-1)=0 then begin Len:=Len-i; getmem (getenv,len); Move(HP[I+1],getenv^,len+1); break; end; { next string entry} hp:=hp+len+1; end; end; {$endif} {$ifdef GO32V2} Function GetEnv(envvar: string): pchar; var hp : ppchar; p : pchar; hs : string; eqpos : longint; begin envvar:=upcase(envvar); hp:=envp; getenv:=nil; while assigned(hp^) do begin hs:=strpas(hp^); eqpos:=pos('=',hs); if copy(hs,1,eqpos-1)=envvar then begin getenv:=hp^+eqpos; exit; end; inc(hp); end; end; {$endif} var done_init : boolean; procedure set_content(ctype: string); begin writeln('Content-Type: ',ctype); writeln; end; function http_request_method: pchar; begin http_request_method :=getenv('REQUEST_METHOD'); end; function http_referer: pchar; begin http_referer :=getenv('HTTP_REFERER'); end; function http_useragent: pchar; begin http_useragent :=getenv('HTTP_USER_AGENT'); end; function hexconv(h1,h2: char): char; var cnt : byte; thex : byte; begin for cnt :=0 to 15 do if upcase(h1)=hextable[cnt] then thex := cnt * 16; for cnt :=0 to 15 do if upcase(h2)=hextable[cnt] then thex := thex + cnt; hexconv := chr(thex); end; procedure def_uncgi_error(const pname,perr: string); begin set_content('text/html'); writeln('UNCGI ERROR'); writeln(''); writeln('

UNCGI ERROR




'); writeln('UnCgi encountered the following error:
'); writeln('