diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Cookies.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/Cookies.c b/src/Cookies.c index 0558006..559c052 100644 --- a/src/Cookies.c +++ b/src/Cookies.c @@ -160,35 +160,33 @@ int HTTP_CookieCancel(httpRequest *request, char *HTTP_CookieGet(httpRequest *request, const char *cookie_name) { char *retval = NULL; - const String *COOKIE = String_Make("cookie"); + String *attribute = String_Make("Cookie"); String *header = String_New(); + /* Get the cookie header */ - if( HTTP_GetHeaderValueString( request, COOKIE, header ) ) + if( HTTP_GetHeaderValueString( request, attribute, header ) ) { String *name = String_Make( cookie_name ); String *value = String_New(); size_t index = 0; - /* Search for name=value */ - while( SetNextToken( header, value, ";", index ) ) + /* Search for "name=" */ + ConcatCString (name, "="); + if (FindStringFrom (header, name, &index)) { - size_t position = 0; - if( FindStringFrom( value, name, &position ) - && position == 0 ) + /* cut "value" at the next ';' char or at EOS */ + size_t position = index + StringLength (name); + if (FindCharFrom (header, ';', &position)) { - if( FindCharFrom( value, '=', &position ) - && position == Length( name ) ) - { - TrimLeading( value, position + 1 ); - retval = Util_Strdup( GetBuffer( value ) ); - } - break; + TrimLeading (header, position); } + retval = Util_Strdup (GetBuffer (header) + index); } String_Delete(name); String_Delete(value); } String_Delete(header); + String_Delete(attribute); return retval; } |