************************************************************************ FUNCTION URLDecode ****************** *** Function: URLDecodes a text string to normal text. *** Assume: Uses wwIPStuff.dll *** Pass: lcText - Text string to decode *** Return: Decoded string or "" ************************************************************************ LPARAMETERS lcText LOCAL lnSize, lnLoc, lcHex, lcRetval *** Use wwIPStuff for large buffers IF LEN(lcText) > 255 DECLARE INTEGER URLDecode ; IN WWIPSTUFF AS API_URLDecode ; STRING @cText lnSize=API_URLDecode(@lcText) IF lnSize > 0 lcText = SUBSTR(lcText,1,lnSize) ELSE lcText = "" ENDIF RETURN lcText ENDIF *** First convert + to spaces lcText=STRTRAN(lcText,"+"," ") *** Handle Hex Encoded Control chars lcRetval = "" DO WHILE .T. *** Format: %0A ( CHR(10) ) lnLoc = AT('%',lcText) *** No Hex chars IF lnLoc > LEN(lcText) - 2 OR lnLoc < 1 lcRetval = lcRetval + lcText EXIT ENDIF *** Now read the next 2 characters *** Check for digits - at this point we must have hex pair! lcHex=SUBSTR(lcText,lnLoc+1,2) *** Now concat the string plus the evaled hex code lcRetval = lcRetval + LEFT(lcText,lnLoc-1) + ; CHR( EVAL("0x"+lcHex) ) *** Trim out the input string IF LEN(lcText) > lnLoc + 2 lcText = SUBSTR(lcText,lnLoc+3) ELSE EXIT ENDIF ENDDO RETURN lcRetval ENDFUNC * EOF URLDecode ************************************************************************ FUNCTION GetURLEncodedKey ********************************* *** Function: Retrieves a 'parameter' from the query string that *** is encoded with standard CGI/ISAPI URL encoding. *** Typical URL encoding looks like this: *** *** "User=Rick+Strahl&ID=0011&Address=400+Morton%0A%0DHood+River" *** *** Pass: lcVal - Form Variable to retrieve *** Return: Value or "" ************************************************************************ LPARAMETERS tcURLString, lcKey LOCAL lnLoc,c2, cStr, lcURLString, lcRetval lcURLString=IIF(EMPTY(tcURLString),"","&"+tcURLString) lcKey=IIF(EMPTY(lcKey)," ",lcKey) lcKey=STRTRAN(lcKey," ","+") #IF wwVFPVersion > 6 lcRetval = STREXTRACT(lcUrlString,"&"+lcKey+"=","&",1,3) #ELSE lcRetval=Extract(@lcUrlString,"&"+lcKey+"=","&",,.T.) #ENDIF RETURN URLDecode(lcRetval) ENDFUNC ******************************************************** FUNCTION URLEncode ******************* *** Function: Encodes a string in URL encoded format *** for use on URL strings or when passing a *** POST buffer to wwIPStuff::HTTPGetEx *** Pass: tcValue - String to encode *** Return: URLEncoded string or "" ******************************************************** LPARAMETER tcValue LOCAL lcResult, lcChar, lnSize, x *** Large Buffers use the wwIPStuff function *** for quicker response if LEN(tcValue) > 255 lnSize=LEN(tcValue) tcValue=PADR(tcValue,lnSize * 3) DECLARE INTEGER VFPURLEncode ; IN WWIPSTUFF ; STRING @cText,; INTEGER cInputTextSize lnSize=VFPUrlEncode(@tcValue,lnSize) IF lnSize > 0 RETURN SUBSTR(TRIM(tcValue),1,lnSize) ENDIF RETURN "" ENDIF *** Do it in VFP Code lcResult="" FOR x=1 to len(tcValue) lcChar = SUBSTR(tcValue,x,1) IF ATC(lcChar,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") > 0 lcResult=lcResult + lcChar LOOP ENDIF IF lcChar=" " lcResult = lcResult + "+" LOOP ENDIF *** Convert others to Hex equivalents lcResult = lcResult + "%" + RIGHT(transform(ASC(lcChar),"@0"),2) ENDFOR && x=1 to len(tcValue) RETURN lcResult * EOF URLEncodeTo fix these to work without wwIPStuff just change the length to a very large number to avoid the call to the external DLL.