aboutsummaryrefslogtreecommitdiff
path: root/src/Cookies.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Cookies.c')
-rw-r--r--src/Cookies.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/src/Cookies.c b/src/Cookies.c
index 766d942..c153608 100644
--- a/src/Cookies.c
+++ b/src/Cookies.c
@@ -11,13 +11,11 @@
#include "cctk.h"
#include <stdlib.h>
-#include <string.h>
#include "util_String.h"
-#include "http_Request.h"
-#include "http_Cookies.h"
-#include "http_SString.h"
+#include "httpRequest.h"
+#include "Cookies.h"
#include "SString_Namespace.h"
static const char *rcsid = "$Header$";
@@ -97,7 +95,7 @@ int HTTP_CookieSend(httpRequest *request,
ConcatCString(message, "\r\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
String_Delete( message );
return 0;
@@ -138,7 +136,7 @@ int HTTP_CookieCancel(httpRequest *request,
ConcatCString(message, "; expires Sun Sep 17 21:57:45 CEST 2000");
ConcatCString(message, "\r\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
String_Delete( message );
return 0;
@@ -158,38 +156,39 @@ int HTTP_CookieCancel(httpRequest *request,
@endhistory
@@*/
-char *HTTP_CookieGet(httpRequest *request,
- const char *name)
+
+char *HTTP_CookieGet(httpRequest *request, const char *cookie_name)
{
char *retval = NULL;
+ const String *COOKIE = String_Make("cookie");
+ String *header = String_New();
/* Get the cookie header */
- const char *header = HTTP_HeaderValue(request,"Cookie");
-
- if(header)
+ if( HTTP_GetHeaderValueString( request, COOKIE, header ) )
{
- char *copy = Util_Strdup(header);
- char *position = copy;
+ String *name = String_Make( cookie_name );
+ String *value = String_New();
+ size_t index = 0;
/* Search for name=value */
- while((position = strstr(position, name)) != NULL)
+ while( SetNextToken( header, value, ";", index ) )
{
- position += strlen(name);
- if(*position == '=')
+ size_t position = 0;
+ if( FindStringFrom( value, name, &position )
+ && position == 0 )
{
- char *start = position+1;
-
- position=strstr(start, ";");
-
- if(position)
+ if( FindCharFrom( value, '=', &position )
+ && position == Length( name ) )
{
- *position = 0;
+ TrimLeading( value, position + 1 );
+ retval = Util_Strdup( GetBuffer( value ) );
}
- retval = Util_Strdup(start);
- break;
+ break;
}
}
- free(copy);
+ String_Delete(name);
+ String_Delete(value);
}
+ String_Delete(header);
return retval;
}