- need php_stream_open_wrapper_*ex* to pass a stream context
[m6w6/ext-http] / http_cookie_api.c
index d43d0fe86850c58ca9a16368d37f851ba61519b5..bf9af4048c74cfae088374c8b475f52583257c67 100644 (file)
@@ -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,10 +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':
+                                               goto add;
                                                st = ST_ADD;
                                        break;
                                        
@@ -288,8 +288,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 +322,7 @@ failure:
                http_cookie_list_dtor(list);
        }
        efree(s);
-       return FAILURE;
+       return NULL;
 }
 /* }}} */