00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 #include <stdbool.h>
00034 #include <string.h>
00035 #include <unistd.h>
00036 #include <errno.h>
00037 #include "md5/md5_global.h"
00038 #include "md5/md5.h"
00039 #include "qDecoder.h"
00040 #include "qInternal.h"
00041
00062 Q_ENTRY *qDecodeQueryString(Q_ENTRY *entry, const char *query, char equalchar, char sepchar, int *count) {
00063 if(entry == NULL) {
00064 entry = qEntryInit();
00065 if(entry == NULL) return NULL;
00066 }
00067
00068 char *newquery = NULL;
00069 int cnt = 0;
00070
00071 if(query != NULL) newquery = strdup(query);
00072 while (newquery && *newquery) {
00073 char *value = _q_makeword(newquery, sepchar);
00074 char *name = qStrTrim(_q_makeword(value, equalchar));
00075 qDecodeUrl(name);
00076 qDecodeUrl(value);
00077
00078 if(qEntryPutStr(entry, name, value, false) == true) cnt++;
00079 free(name);
00080 free(value);
00081 }
00082 if(newquery != NULL) free(newquery);
00083 if(count != NULL) *count = cnt;
00084
00085 return entry;
00086 }
00087
00100 char *qEncodeUrl(const char *str) {
00101 char *encstr, buf[2+1];
00102 unsigned char c;
00103 int i, j;
00104
00105 if (str == NULL) return NULL;
00106 if ((encstr = (char *)malloc((strlen(str) * 3) + 1)) == NULL) return NULL;
00107
00108 for (i = j = 0; str[i]; i++) {
00109 c = (unsigned char)str[i];
00110 if ((c >= '0') && (c <= '9')) encstr[j++] = c;
00111 else if ((c >= 'A') && (c <= 'Z')) encstr[j++] = c;
00112 else if ((c >= 'a') && (c <= 'z')) encstr[j++] = c;
00113 else if ((c == '@') || (c == '.') || (c == '/') || (c == '\\')
00114 || (c == '-') || (c == '_') || (c == ':') ) encstr[j++] = c;
00115 else {
00116 sprintf(buf, "%02x", c);
00117 encstr[j++] = '%';
00118 encstr[j++] = buf[0];
00119 encstr[j++] = buf[1];
00120 }
00121 }
00122 encstr[j] = '\0';
00123
00124 return encstr;
00125 }
00126
00144 char *qDecodeUrl(char *str) {
00145 int i, j;
00146
00147 if (!str) return NULL;
00148 for (i = j = 0; str[j]; i++, j++) {
00149 switch (str[j]) {
00150 case '+': {
00151 str[i] = ' ';
00152 break;
00153 }
00154 case '%': {
00155 str[i] = _q_x2c(str[j + 1], str[j + 2]);
00156 j += 2;
00157 break;
00158 }
00159 default: {
00160 str[i] = str[j];
00161 break;
00162 }
00163 }
00164 }
00165 str[i] = '\0';
00166
00167 return str;
00168 }