void ParseCommandValue(int argc, char *argv[], int pos, int Flag, char **String) { if (pos >= argc) { fprintf(stderr,"ERROR: Argument missing after '%s'\n",argv[pos-1]); exit(1); } Flags |= Flag; if (String) *String=DeQuoteStr(*String,argv[pos]); }
HTTPSession *ParseSessionInfo(char *Data) { HTTPSession *Response=NULL; char *Name=NULL, *Value=NULL, *Tempstr=NULL, *ptr; Response=HTTPSessionCreate(); Response->ContentType=CopyStr(Response->ContentType,""); Response->ContentSize=0; Response->LastModified=0; Response->CacheTime=Settings.DocumentCacheTime; Response->RealUser=CopyStr(Response->RealUser, Settings.DefaultUser); Response->Group=CopyStr(Response->Group, Settings.DefaultGroup); //if we got as far as calling this function, then the original session must be //authenticated. Response->Flags |= SESSION_AUTHENTICATED; Response->Flags &= ~SESSION_UPLOAD; ptr=GetNameValuePair(Data," ","=",&Name,&Tempstr); while (ptr) { Value=DeQuoteStr(Value,Tempstr); if (strcmp(Name,"User")==0) Response->UserName=CopyStr(Response->UserName,Value); else if (strcmp(Name,"RealUser")==0) Response->RealUser=CopyStr(Response->RealUser,Value); else if (strcmp(Name,"Group")==0) Response->Group=CopyStr(Response->Group,Value); else if (strcmp(Name,"Host")==0) Response->Host=CopyStr(Response->Host,Value); else if (strcmp(Name,"UserAgent")==0) Response->UserAgent=CopyStr(Response->UserAgent,Value); else if (strcmp(Name,"Method")==0) Response->Method=CopyStr(Response->Method,Value); else if (strcmp(Name,"ContentType")==0) HTTPServerParsePostContentType(Response, Value); else if (strcmp(Name,"SearchPath")==0) Response->SearchPath=DeQuoteStr(Response->SearchPath,Value); else if (strcmp(Name,"Path")==0) Response->Path=DeQuoteStr(Response->Path,Value); else if (strcmp(Name,"URL")==0) Response->URL=DeQuoteStr(Response->URL,Value); else if (strcmp(Name,"Arguments")==0) Response->Arguments=SanitizeQueryString(Response->Arguments,Value); else if (strcmp(Name,"ServerName")==0) Response->ServerName=CopyStr(Response->ServerName,Value); else if (strcmp(Name,"ServerPort")==0) Response->ServerPort=atoi(Value); else if (strcmp(Name,"ClientIP")==0) Response->ClientIP=CopyStr(Response->ClientIP,Value); else if (strcmp(Name,"ClientMAC")==0) Response->ClientMAC=CopyStr(Response->ClientMAC,Value); else if (strcmp(Name,"ContentLength")==0) Response->ContentSize=atoi(Value); else if (strcmp(Name,"StartDir")==0) Response->StartDir=DeQuoteStr(Response->StartDir,Value); else if (strcmp(Name,"ClientReferrer")==0) Response->ClientReferrer=DeQuoteStr(Response->ClientReferrer,Value); else if (strcmp(Name,"RemoteAuthenticate")==0) Response->RemoteAuthenticate=CopyStr(Response->RemoteAuthenticate,Value); else if (strcmp(Name,"Cipher")==0) Response->Cipher=CopyStr(Response->Cipher,Value); else if (strcmp(Name,"Cookies")==0) Response->Cookies=CopyStr(Response->Cookies,Value); else if (strcmp(Name,"KeepAlive")==0) Response->Flags |= SESSION_KEEPALIVE; else if (strcmp(Name,"Upload")==0) Response->Flags |= SESSION_UPLOAD; else if (strcmp(Name,"AuthCookie")==0) Response->AuthFlags |= FLAG_AUTH_HASCOOKIE; else if (strcmp(Name,"Cache")==0) Response->CacheTime=atoi(Value); ptr=GetNameValuePair(ptr," ","=",&Name,&Tempstr); } DestroyString(Name); DestroyString(Value); DestroyString(Tempstr); return(Response); }
//This function Extracts Text from a line that's found between two specified //chunks of text 'ItemStart' and 'ItemEnd' char *GenericExtractFromLine(char *Line, char *ItemName, char *ItemStart, char *ItemEnd, ListNode *Vars, int Flags) { char *ptr, *ptr2, *Token=NULL, *Item=NULL; int GTF=0; if (Flags & EXTRACT_WITHIN_QUOTES) GTF=GETTOKEN_QUOTES; if (StrLen(ItemStart)) ptr=Gettoken(Line,ItemStart,&Token,0); else ptr=Line; ptr=Gettoken(ptr,ItemEnd,&Token,GTF); //check if the start string occurs more than once in the Token that we've grabbed if (StrLen(ItemStart)) ptr2=strstr(Token,ItemStart); else ptr2=NULL; while (ptr2) { ptr2+=StrLen(ItemStart); memmove(Token,ptr2,Token+StrLen(Token)-ptr2+1); //because of memmove we can strstr in Token again ptr2=strstr(Token,ItemStart); } if (Flags & EXTRACT_INCLUDE_START) { Item=MCopyStr(Item,ItemStart,Token,NULL); Token=CopyStr(Token,Item); } if (Flags & EXTRACT_DEQUOTE) Item=HTTPUnQuote(Item,Token); else if (Flags & EXTRACT_DEHTMLQUOTE) Item=HtmlDeQuote(Item,Token); else if (Flags & EXTRACT_DESLASHQUOTE) Item=DeQuoteStr(Item,Token); else Item=CopyStr(Item,Token); StripLeadingWhitespace(Item); StripTrailingWhitespace(Item); StripQuotes(Item); if (Flags & EXTRACT_NOSPACES) { ptr2=strchr(Item,' '); while (ptr2) { *ptr2='+'; ptr2=strchr(ptr2,' '); } } //Do this without disturbing ptr, as we must return ptr ptr2=ItemName; if (Flags & EXTRACT_GUESSTYPE) { Token=ItemCodeFromFileExtension(Token, ItemName, Item); } SetVar(Vars,ptr2,Item); DestroyString(Token); DestroyString(Item); return(ptr); }