X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_api.c;h=811acba2f6dc3470459d72b9f3dfed5b2269a3ca;hp=0b0eea748831e87098ab354dacad0f3a778b57a1;hb=d650022122969644c33bd03a552af1a631429e16;hpb=0dbc3c8eb4ec78fd58d6cc1c80e5189f5ae91094 diff --git a/http_api.c b/http_api.c index 0b0eea7..811acba 100644 --- a/http_api.c +++ b/http_api.c @@ -84,113 +84,6 @@ char *_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool x } /* }}} */ -/* {{{ */ -void _http_key_list_default_decoder(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC) -{ - *decoded = estrndup(encoded, encoded_len); - *decoded_len = (size_t) php_url_decode(*decoded, encoded_len); -} -/* }}} */ - -/* {{{ */ -STATUS _http_parse_key_list(const char *list, HashTable *items, char separator, http_key_list_decode_t decode, zend_bool first_entry_is_name_value_pair TSRMLS_DC) -{ - char *str = estrdup(list), *key = str, *val = NULL; - int vallen = 0, keylen = 0, done = 0; - zval array; - - INIT_ZARR(array, items); - - if (!(val = strchr(str, '='))) { - efree(str); - return FAILURE; - } - -#define HTTP_KEYLIST_VAL(array, k, str, len) \ - { \ - char *decoded; \ - size_t decoded_len; \ - if (decode) { \ - decode(str, len, &decoded, &decoded_len TSRMLS_CC); \ - } else { \ - decoded_len = len; \ - decoded = estrndup(str, decoded_len); \ - } \ - add_assoc_stringl(array, k, decoded, decoded_len, 0); \ - } -#define HTTP_KEYLIST_FIXKEY() \ - { \ - while (isspace(*key)) ++key; \ - keylen = val - key; \ - while (isspace(key[keylen - 1])) --keylen; \ - } -#define HTTP_KEYLIST_FIXVAL() \ - { \ - ++val; \ - while (isspace(*val)) ++val; \ - vallen = key - val; \ - while (isspace(val[vallen - 1])) --vallen; \ - if (val[0] == '"' && val[vallen - 1] == '"') { \ - int i; \ - ++val; \ - vallen -= 2; \ - for (i = 0; i < vallen; ++i) { \ - if (val[i] == '\\' && val[i+1] == '"' && (!i || val[i-1] != '\\')) { \ - memmove(&val[i], &val[i+1], vallen - i); \ - --vallen; \ - } \ - } \ - } \ - } - - HTTP_KEYLIST_FIXKEY(); - - if (first_entry_is_name_value_pair) { - HTTP_KEYLIST_VAL(&array, "name", key, keylen); - - /* just one name=value */ - if (!(key = strchr(val, separator))) { - key = val + strlen(val); - HTTP_KEYLIST_FIXVAL(); - HTTP_KEYLIST_VAL(&array, "value", val, vallen); - efree(str); - return SUCCESS; - } - /* additional info appended */ - else { - HTTP_KEYLIST_FIXVAL(); - HTTP_KEYLIST_VAL(&array, "value", val, vallen); - } - } - - do { - char *keydup = NULL; - - if (!(val = strchr(key, '='))) { - break; - } - - /* start at 0 if first_entry_is_name_value_pair==0 */ - if (zend_hash_num_elements(items)) { - ++key; - } - - HTTP_KEYLIST_FIXKEY(); - keydup = estrndup(key, keylen); - if (!(key = strchr(val, separator))) { - done = 1; - key = val + strlen(val); - } - HTTP_KEYLIST_FIXVAL(); - HTTP_KEYLIST_VAL(&array, keydup, val, vallen); - efree(keydup); - } while (!done); - - efree(str); - return SUCCESS; -} -/* }}} */ - /* {{{ void http_error(long, long, char*) */ void _http_error_ex(long type TSRMLS_DC, long code, const char *format, ...) {