A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.

Dependents:   oldheating gps motorhome heating

Committer:
andrewboyson
Date:
Fri Jan 18 17:41:06 2019 +0000
Revision:
110:67c96c143c2a
Child:
129:9c57197fb698
Tidies up the http query module

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewboyson 110:67c96c143c2a 1 #include <stdio.h>
andrewboyson 110:67c96c143c2a 2
andrewboyson 110:67c96c143c2a 3 static int hexToInt(char c)
andrewboyson 110:67c96c143c2a 4 {
andrewboyson 110:67c96c143c2a 5 int nibble;
andrewboyson 110:67c96c143c2a 6 if (c >= '0' && c <= '9') nibble = c - '0';
andrewboyson 110:67c96c143c2a 7 if (c >= 'A' && c <= 'F') nibble = c - 'A' + 0xA;
andrewboyson 110:67c96c143c2a 8 if (c >= 'a' && c <= 'f') nibble = c - 'a' + 0xA;
andrewboyson 110:67c96c143c2a 9 return nibble;
andrewboyson 110:67c96c143c2a 10 }
andrewboyson 110:67c96c143c2a 11 void HttpQueryUnencode(char* pValue)
andrewboyson 110:67c96c143c2a 12 {
andrewboyson 110:67c96c143c2a 13 char* pDst = pValue;
andrewboyson 110:67c96c143c2a 14 int a;
andrewboyson 110:67c96c143c2a 15 for (char* pSrc = pValue; *pSrc; pSrc++)
andrewboyson 110:67c96c143c2a 16 {
andrewboyson 110:67c96c143c2a 17 char c = *pSrc;
andrewboyson 110:67c96c143c2a 18 switch (c)
andrewboyson 110:67c96c143c2a 19 {
andrewboyson 110:67c96c143c2a 20 case '+':
andrewboyson 110:67c96c143c2a 21 c = ' ';
andrewboyson 110:67c96c143c2a 22 break;
andrewboyson 110:67c96c143c2a 23 case '%':
andrewboyson 110:67c96c143c2a 24 c = *++pSrc;
andrewboyson 110:67c96c143c2a 25 if (c == 0) break;
andrewboyson 110:67c96c143c2a 26 a = hexToInt(c);
andrewboyson 110:67c96c143c2a 27 a <<= 4;
andrewboyson 110:67c96c143c2a 28 c = *++pSrc;
andrewboyson 110:67c96c143c2a 29 if (c == 0) break;
andrewboyson 110:67c96c143c2a 30 a += hexToInt(c);
andrewboyson 110:67c96c143c2a 31 c = a;
andrewboyson 110:67c96c143c2a 32 break;
andrewboyson 110:67c96c143c2a 33 default:
andrewboyson 110:67c96c143c2a 34 c = *pSrc;
andrewboyson 110:67c96c143c2a 35 break;
andrewboyson 110:67c96c143c2a 36 }
andrewboyson 110:67c96c143c2a 37 *pDst++ = c;
andrewboyson 110:67c96c143c2a 38 }
andrewboyson 110:67c96c143c2a 39 *pDst = 0;
andrewboyson 110:67c96c143c2a 40 }
andrewboyson 110:67c96c143c2a 41 char* HttpQuerySplit(char* p, char** ppName, char** ppValue) //returns the start of the next name value pair
andrewboyson 110:67c96c143c2a 42 {
andrewboyson 110:67c96c143c2a 43 *ppName = p; //Record the start of the name
andrewboyson 110:67c96c143c2a 44 *ppValue = NULL;
andrewboyson 110:67c96c143c2a 45
andrewboyson 110:67c96c143c2a 46 while (*p != '=') //Loop to an '='
andrewboyson 110:67c96c143c2a 47 {
andrewboyson 110:67c96c143c2a 48 if (*p == 0) return 0;
andrewboyson 110:67c96c143c2a 49 p++;
andrewboyson 110:67c96c143c2a 50 }
andrewboyson 110:67c96c143c2a 51 *p = 0; //Terminate the name by replacing the '=' with a NUL char
andrewboyson 110:67c96c143c2a 52 p++; //Move on to the start of the value
andrewboyson 110:67c96c143c2a 53 *ppValue = p; //Record the start of the value
andrewboyson 110:67c96c143c2a 54 while (*p != '&') //Loop to a '&'
andrewboyson 110:67c96c143c2a 55 {
andrewboyson 110:67c96c143c2a 56 if (*p == 0) return 0;
andrewboyson 110:67c96c143c2a 57 p++;
andrewboyson 110:67c96c143c2a 58 }
andrewboyson 110:67c96c143c2a 59 *p = 0; //Terminate the value by replacing the '&' with a NULL
andrewboyson 110:67c96c143c2a 60 return p + 1;
andrewboyson 110:67c96c143c2a 61 }