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 #include "KeyValuePairs.h"
00026 #include "util.h"
00027
00028
00029 #include <stdlib.h>
00030
00031 namespace IXE {
00032
00033 KeyValuePairs::~KeyValuePairs()
00034 {
00035 TO_EACH (KeyValuePairs, *this, it) {
00036 free((void*)it->first);
00037 free((void*)it->second); it->second = 0;
00038 }
00039 }
00040
00041 void KeyValuePairs::FillFromQueryString(char const* query)
00042 {
00043 char dekey[URL_MAX];
00044 char devalue[URL_MAX];
00045 char const* qend = query + ::strlen(query);
00046 char const* key = query;
00047 do {
00048 char const* valend = ::strchr(key, '&');
00049 valend = valend ? valend : qend;
00050 char const* keyend = key;
00051 while (keyend < valend && *keyend != '=')
00052 keyend++;
00053 if (keyend == valend) {
00054 url_decode(dekey, key, keyend - key);
00055 insert(value_type(::strdup(dekey), ::strdup("")));
00056 } else {
00057 url_decode(dekey, key, keyend - key);
00058 keyend++;
00059 url_decode(devalue, keyend, valend - keyend);
00060 insert(value_type(::strdup(dekey), ::strdup(devalue)));
00061 }
00062 key = valend + 1;
00063 } while (key < qend);
00064 }
00065
00066 }