diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/http.c | 82 |
2 files changed, 83 insertions, 1 deletions
@@ -3,7 +3,7 @@ OSARCH=$(shell uname -s) OSREV=$(shell uname -r) -VERSION := 1.20 +VERSION := 1.21pre DESTDIR ?= CONFDIR:=/etc/asterisk CONFDIR_REAL := $(DESTDIR)/etc/asterisk @@ -9,6 +9,87 @@ #include "astmanproxy.h" +// SwapChar: This routine swaps one character for another +void SwapChar(char * pOriginal, char cBad, char cGood) { + int i; // generic counter variable + + // Loop through the input string (cOriginal), character by + // character, replacing each instance of cBad with cGood + + i = 0; + while (pOriginal[i]) { + if (pOriginal[i] == cBad) pOriginal[i] = cGood; + i++; + } +} + +// IntFromHex: A subroutine to unescape escaped characters. +static int IntFromHex(char *pChars) { + int Hi; // holds high byte + int Lo; // holds low byte + int Result; // holds result + + // Get the value of the first byte to Hi + + Hi = pChars[0]; + if ('0' <= Hi && Hi <= '9') { + Hi -= '0'; + } else + if ('a' <= Hi && Hi <= 'f') { + Hi -= ('a'-10); + } else + if ('A' <= Hi && Hi <= 'F') { + Hi -= ('A'-10); + } + + // Get the value of the second byte to Lo + + Lo = pChars[1]; + if ('0' <= Lo && Lo <= '9') { + Lo -= '0'; + } else + if ('a' <= Lo && Lo <= 'f') { + Lo -= ('a'-10); + } else + if ('A' <= Lo && Lo <= 'F') { + Lo -= ('A'-10); + } + Result = Lo + (16 * Hi); + return (Result); +} + +// URLDecode: This routine loops through the string pEncoded +// (passed as a parameter), and decodes it in place. It checks for +// escaped values, and changes all plus signs to spaces. The result +// is a normalized string. It calls the two subroutines directly +// above in this listing, IntFromHex() and SwapChar(). + +void URLDecode(unsigned char *pEncoded) { + char *pDecoded; // generic pointer + + // First, change those pesky plusses to spaces + SwapChar (pEncoded, '+', ' '); + + // Now, loop through looking for escapes + pDecoded = pEncoded; + while (*pEncoded) { + if (*pEncoded=='%') { + // A percent sign followed by two hex digits means + // that the digits represent an escaped character. We + // must decode it. + + pEncoded++; + if (isxdigit(pEncoded[0]) && isxdigit(pEncoded[1])) { + *pDecoded++ = (char) IntFromHex(pEncoded); + pEncoded += 2; + } + } else { + *pDecoded ++ = *pEncoded++; + } + } + *pDecoded = '\0'; +} + int ParseHTTPInput(char *buf, struct message *m) { char *n, *v; @@ -139,6 +220,7 @@ int _read(struct mansession *s, struct message *m) { /* now, let's transform and copy into a standard message block */ if (!strcmp("200 OK", status) ) { + URLDecode(formdata); res = ParseHTTPInput(formdata, m); return res; } else { |