summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Troy <dave@popvox.com>2006-04-13 17:14:32 +0000
committerDavid Troy <dave@popvox.com>2006-04-13 17:14:32 +0000
commitd04144e41c0076359bbcee64cd2835f786cafac4 (patch)
treef3a590a9bc19e0eb8b6917b46de1e21ac57128aa
parentc8edc58f3d94445f154f0d01e183328127dc0939 (diff)
downloadastmanproxy-d04144e41c0076359bbcee64cd2835f786cafac4.tar.gz
astmanproxy-d04144e41c0076359bbcee64cd2835f786cafac4.tar.xz
astmanproxy-d04144e41c0076359bbcee64cd2835f786cafac4.zip
git-svn-id: http://svncommunity.digium.com/svn/astmanproxy/trunk@110 f02b47b9-160a-0410-81a6-dc3441afb0ec
-rw-r--r--Makefile2
-rw-r--r--src/http.c82
2 files changed, 83 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index b18fd8d..71d2224 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/src/http.c b/src/http.c
index 4f107db..b0af09f 100644
--- a/src/http.c
+++ b/src/http.c
@@ -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 {