|
@@ -22,6 +22,7 @@ |
|
@@ -22,6 +22,7 @@ |
22
|
|
22
|
|
23
|
#include <time.h>
|
23
|
#include <time.h>
|
24
|
#include <stdlib.h>
|
24
|
#include <stdlib.h>
|
|
|
25
|
+#include <ctype.h>
|
25
|
#include <sys/types.h>
|
26
|
#include <sys/types.h>
|
26
|
#include <string.h>
|
27
|
#include <string.h>
|
27
|
|
28
|
|
|
@@ -33,6 +34,10 @@ |
|
@@ -33,6 +34,10 @@ |
33
|
|
34
|
|
34
|
#include "commons.h"
|
35
|
#include "commons.h"
|
35
|
|
36
|
|
|
|
37
|
+#define ALPHAVAL(x) (tolower((x)) - 'a' + 0xa)
|
|
|
38
|
+#define DIGITVAL(x) ((x) - '0')
|
|
|
39
|
+#define ALNUMVAL(x) (isdigit((x))?DIGITVAL((x)):ALPHAVAL((x)))
|
|
|
40
|
+
|
36
|
|
41
|
|
37
|
static const char *DAY_NAMES[] = {
|
42
|
static const char *DAY_NAMES[] = {
|
38
|
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
43
|
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
|
@@ -68,6 +73,41 @@ rfc1123GmtNow(char * buffer, size_t _nbuf) |
|
@@ -68,6 +73,41 @@ rfc1123GmtNow(char * buffer, size_t _nbuf) |
68
|
return rfc1123Gmt(buffer, _nbuf, &t);
|
73
|
return rfc1123Gmt(buffer, _nbuf, &t);
|
69
|
}
|
74
|
}
|
70
|
|
75
|
|
|
|
76
|
+/**
|
|
|
77
|
+ * Decode an url encoded string. This expects a valid url
|
|
|
78
|
+ * encoded string and it size as arguments, else the behaviour
|
|
|
79
|
+ * of this function is undefined.
|
|
|
80
|
+ * This function modifies the data in buffer. No copy is made.
|
|
|
81
|
+ * The reason for this is only performance.
|
|
|
82
|
+ */
|
|
|
83
|
+size_t
|
|
|
84
|
+urldecode(char * buffer, size_t nbuffer)
|
|
|
85
|
+{
|
|
|
86
|
+ char * buf_ptr = buffer;
|
|
|
87
|
+ char * res_ptr = buffer;
|
|
|
88
|
+
|
|
|
89
|
+ for(; 0 < nbuffer; nbuffer--, buf_ptr++, res_ptr++) {
|
|
|
90
|
+ switch(*buf_ptr) {
|
|
|
91
|
+ case '%':
|
|
|
92
|
+ *res_ptr = (ALNUMVAL(buf_ptr[1]) << 4) | ALNUMVAL(buf_ptr[2]);
|
|
|
93
|
+ buf_ptr += 2;
|
|
|
94
|
+ nbuffer -= 2;
|
|
|
95
|
+ break;
|
|
|
96
|
+
|
|
|
97
|
+ case '+':
|
|
|
98
|
+ *buf_ptr = ' ';
|
|
|
99
|
+ /* intended drop through */
|
|
|
100
|
+
|
|
|
101
|
+ default:
|
|
|
102
|
+ *res_ptr = *buf_ptr;
|
|
|
103
|
+ break;
|
|
|
104
|
+ }
|
|
|
105
|
+ }
|
|
|
106
|
+ *res_ptr = 0;
|
|
|
107
|
+
|
|
|
108
|
+ return res_ptr - buffer;
|
|
|
109
|
+}
|
|
|
110
|
+
|
71
|
char
|
111
|
char
|
72
|
isHttpVersion(const char * str, size_t len)
|
112
|
isHttpVersion(const char * str, size_t len)
|
73
|
{
|
113
|
{
|