X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_cookie_api.c;h=fa6b2536e1bfe775e0a6e0741d88e9b44a006777;hp=bc02315e6f9098880f3a6f416d0d4c0487c66222;hb=669d2e6a8bdc642b6b52693f4593f199ddd7e8d2;hpb=e6b35fbe072a13b0e792952852fcd1499bd8e610 diff --git a/http_cookie_api.c b/http_cookie_api.c index bc02315..fa6b253 100644 --- a/http_cookie_api.c +++ b/http_cookie_api.c @@ -26,10 +26,10 @@ PHP_MINIT_FUNCTION(http_cookie) return SUCCESS; } -PHP_HTTP_API http_cookie_list *_http_cookie_list_init(http_cookie_list *list TSRMLS_DC) +PHP_HTTP_API http_cookie_list *_http_cookie_list_init(http_cookie_list *list ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC) { if (!list) { - list = emalloc(sizeof(http_cookie_list)); + list = emalloc_rel(sizeof(http_cookie_list)); } zend_hash_init(&list->cookies, 0, NULL, ZVAL_PTR_DTOR, 0); @@ -66,7 +66,7 @@ PHP_HTTP_API void _http_cookie_list_free(http_cookie_list **list TSRMLS_DC) PHP_HTTP_API const char *_http_cookie_list_get_cookie(http_cookie_list *list, const char *name, size_t name_len TSRMLS_DC) { zval **cookie = NULL; - if ((SUCCESS != zend_hash_find(&list->cookies, name, name_len + 1, (void **) &cookie)) || (Z_TYPE_PP(cookie) != IS_STRING)) { + if ((SUCCESS != zend_hash_find(&list->cookies, (char *) name, name_len + 1, (void *) &cookie)) || (Z_TYPE_PP(cookie) != IS_STRING)) { return NULL; } return Z_STRVAL_PP(cookie); @@ -75,7 +75,7 @@ PHP_HTTP_API const char *_http_cookie_list_get_cookie(http_cookie_list *list, co PHP_HTTP_API const char *_http_cookie_list_get_extra(http_cookie_list *list, const char *name, size_t name_len TSRMLS_DC) { zval **extra = NULL; - if ((SUCCESS != zend_hash_find(&list->extras,name, name_len + 1, (void **) &extra)) || (Z_TYPE_PP(extra) != IS_STRING)) { + if ((SUCCESS != zend_hash_find(&list->extras, (char *) name, name_len + 1, (void *) &extra)) || (Z_TYPE_PP(extra) != IS_STRING)) { return NULL; } return Z_STRVAL_PP(extra); @@ -86,7 +86,7 @@ PHP_HTTP_API void _http_cookie_list_add_cookie(http_cookie_list *list, const cha zval *cookie_value; MAKE_STD_ZVAL(cookie_value); ZVAL_STRINGL(cookie_value, estrndup(value, value_len), value_len, 0); - zend_hash_update(&list->cookies, name, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL); + zend_hash_update(&list->cookies, (char *) name, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL); } PHP_HTTP_API void _http_cookie_list_add_extra(http_cookie_list *list, const char *name, size_t name_len, const char *value, size_t value_len TSRMLS_DC) @@ -94,7 +94,7 @@ PHP_HTTP_API void _http_cookie_list_add_extra(http_cookie_list *list, const char zval *cookie_value; MAKE_STD_ZVAL(cookie_value); ZVAL_STRINGL(cookie_value, estrndup(value, value_len), value_len, 0); - zend_hash_update(&list->extras, name, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL); + zend_hash_update(&list->extras, (char *) name, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL); } #define http_cookie_list_set_item_ex(l, i, il, v, vl, f, a) _http_cookie_list_set_item_ex((l), (i), (il), (v), (vl), (f), (a) TSRMLS_CC) @@ -107,7 +107,7 @@ static inline void _http_cookie_list_set_item_ex(http_cookie_list *list, const c } else if (!strcasecmp(key, "domain")) { STR_SET(list->domain, estrndup(value, value_len)); } else if (!strcasecmp(key, "expires")) { - const char *date = estrndup(value, value_len); + char *date = estrndup(value, value_len); list->expires = http_parse_date(date); efree(date); } else if (!strcasecmp(key, "secure")) { @@ -185,11 +185,13 @@ PHP_HTTP_API http_cookie_list *_http_parse_cookie_ex(http_cookie_list *list, con switch (st) { case ST_QUOTE: + quote: if (*c == '"') { - if (*(c-1) != '\\') { - st = ST_ADD; - } else { + if (*(c-1) == '\\') { memmove(c-1, c, strlen(c)+1); + goto quote; + } else { + goto add; } } else { if (!val) { @@ -215,11 +217,8 @@ PHP_HTTP_API http_cookie_list *_http_parse_cookie_ex(http_cookie_list *list, con break; case ';': - if (!*(c+1)) { - goto add; - } case '\0': - st = ST_ADD; + goto add; break; default: @@ -288,8 +287,9 @@ PHP_HTTP_API http_cookie_list *_http_parse_cookie_ex(http_cookie_list *list, con add: if (val) { vallen = c - val; - if (*c) --vallen; - while (val[vallen-1] == ' ') --vallen; + if (st != ST_QUOTE) { + while (val[vallen-1] == ' ') --vallen; + } } else { val = ""; vallen = 0; @@ -321,7 +321,7 @@ failure: http_cookie_list_dtor(list); } efree(s); - return FAILURE; + return NULL; } /* }}} */