[fpc-pascal] environmentstrings in windows
Jason P Sage
jasonpsage at jegas.org
Thu Dec 14 23:27:18 CET 2006
Here is a Code Snippet from an application I use to grab environment
stuff for CGI Programming:
Var T: integer; SA: Ansistring; eq: integer;
And the rCGIIN is a record of rtCGI. iEnvVarCount and the arNVPair
should
Make sense if you look at what I have here.
The iVal function is just a wrapper to convert text numbers to integer
Values - its just wrapped around the standard VAL call that's part of
FPC.
//======================================================================
=======
Type rtNameValuePair = Record
saName: AnsiString;
saValue: AnsiString;
End;
Const cn_MaxEnvVariables = 200;
cn_MaxEnvWarnThreshold = 150;
//-------------- The CGI Environment Gets Pushed in here
Type rtCGI = Record
iEnvVarCount: Integer; // How Many ENV Variables
arNVPair: array [0..cn_MaxEnvVariables-1] Of rtNameValuePair;
iRequestMethodIndex: Integer; // Set to WHICH in the Array of EnvPairs
that
// have the request method (GET or POST)
// POST SPECIFIC - if not post - assumed GET or a "got nothing"
//(I think technically a "got nothing" is a GET...).
bPost: Boolean; // true if POST Recieved
saPostData: AnsiString;
iPostContentTypeIndex: Integer; // Set to WHICH in the Array of
EnvPairs that
// have the CONTENT_TYPE Env Values
iPostContentLength: Integer;
End;
//--------------------------------------------------------
//======================================================================
=======
------------BEGIN
For t:=0 To rCGIIN.iEnvVarCount-1 Do
Begin
sa:=envstr(t);
eq:=pos('=',sa);
rCGIIN.arNVPair[t].saName:=copy(sa,1,eq-1);
rCGIIN.arNVPair[t].saValue:=copy(sa,eq+1,length(sa)-eq);
If (rCGIIN.arNVPair[t].saName=csCGI_REQUEST_METHOD) Then
Begin
rCGIIN.iRequestMethodIndex:=t;
End;
If (rCGIIN.arNVPair[t].saName=csCGI_CONTENT_TYPE) Then
Begin
rCGIIN.iPostContentTypeIndex:=t;
End;
If (rCGIIN.arNVPair[t].saName=csCGI_CONTENT_LENGTH) Then
Begin
rCGIIN.iPostContentLength:=iVal(rCGIIN.arNVPair[t].saValue);
End;
End;
------------END
Best Regards,
Jason P Sage
http://www.jegas.com
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.15.18/586 - Release Date:
12/13/2006 6:13 PM
More information about the fpc-pascal
mailing list