aboutsummaryrefslogtreecommitdiff
path: root/src/Content.c
diff options
context:
space:
mode:
authorgoodale <goodale@1faa4e14-9dd3-4be0-9f0e-ffe519881164>2000-09-18 21:45:02 +0000
committergoodale <goodale@1faa4e14-9dd3-4be0-9f0e-ffe519881164>2000-09-18 21:45:02 +0000
commite23063a8ac86291d2b640c1cac8b2dc600a3ef8c (patch)
tree029e11bac700946ddc82678b31f38d17db045311 /src/Content.c
parent713755db4ba19ad39ef8593f8592a45cf3a53609 (diff)
Changed the auth calls to the new semantics.
Now a cookie gets created to track the authenticated username. Tom git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPD/trunk@47 1faa4e14-9dd3-4be0-9f0e-ffe519881164
Diffstat (limited to 'src/Content.c')
-rw-r--r--src/Content.c96
1 files changed, 94 insertions, 2 deletions
diff --git a/src/Content.c b/src/Content.c
index da1139b..dcca26e 100644
--- a/src/Content.c
+++ b/src/Content.c
@@ -26,6 +26,7 @@
#include "http_Auth.h"
#include "http_Steer.h"
+#include "http_Cookies.h"
#include "http_Content.h"
@@ -75,6 +76,8 @@ static int ControlPage(cGH *cctkGH, httpRequest *request, void *data);
static int ControlSet(cGH *cctkGH, httpRequest *request);
static int ControlTerminationPage(cGH *cctkGH, httpRequest *request);
+static int CookieTestPage(cGH *cctkGH, httpRequest *request, void *data);
+
/********************************************************************
********************* Other Routine Prototypes *********************
********************************************************************/
@@ -85,6 +88,7 @@ static int ControlTerminationPage(cGH *cctkGH, httpRequest *request);
static struct httpLink *ContentLinks = NULL;
+#define USER_LENGTH 255
/********************************************************************
********************* External Routines **********************
********************************************************************/
@@ -150,6 +154,10 @@ int HTTP_RegisterPages(void)
/* Register images */
RegisterImages();
+
+ HTTP_RegisterPage("/cookies.html", CookieTestPage, NULL);
+
+
}
/*@@
@@ -641,13 +649,14 @@ static int ThornParameterPage(cGH *cctkGH, httpRequest *request, void *data)
char *value;
const char *prefix;
const httpArg *argument;
+ char user[USER_LENGTH+1];
int notauthorised;
int readonly;
thorn = (const char *)data;
- notauthorised = HTTP_AuthenticateBasic(request, "user");
+ notauthorised = HTTP_AuthenticateBasic(request, "user", user, USER_LENGTH);
readonly = notauthorised;
@@ -964,7 +973,9 @@ static int ControlPage(cGH *cctkGH, httpRequest *request, void *data)
int notauthorised;
struct httpLink *link;
- notauthorised = HTTP_AuthenticateBasic(request, "user");
+ char thisuser[USER_LENGTH+1];
+
+ notauthorised = HTTP_AuthenticateBasic(request, "user", thisuser, USER_LENGTH);
if(!notauthorised)
{
@@ -980,6 +991,8 @@ static int ControlPage(cGH *cctkGH, httpRequest *request, void *data)
HTTP_Write(request, message, strlen(message));
+ HTTP_CookieSend(request,"user", thisuser, "/", NULL, NULL, 0);
+
strcpy(message,"Content-Type: text/html\r\n\r\n");
HTTP_Write(request, message, strlen(message));
@@ -1064,6 +1077,8 @@ static int ControlPage(cGH *cctkGH, httpRequest *request, void *data)
HTTP_Write(request, message, strlen(message));
+ HTTP_CookieCancel(request,"user", "/");
+
strcpy(message,"Content-Type: text/html\r\n\r\n");
HTTP_Write(request, message, strlen(message));
@@ -1327,3 +1342,80 @@ int HTTP_ContentSendFromFile(httpRequest *request, int filedes)
return bytes_sent;
}
+
+
+ /*@@
+ @routine CookieTestPage
+ @date Mon Sep 18 23:28:19 2000
+ @author Tom Goodale
+ @desc
+ Test and example page for cookies. This will disappear
+ soon.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+static int CookieTestPage(cGH *cctkGH, httpRequest *request, void *data)
+{
+ int retval;
+ char message[4098];
+ struct httpuFileList *list;
+ const char *value;
+ char *value2;
+
+ /* Status message */
+ strcpy(message,"HTTP/1.0 200 OK\r\n");
+
+ HTTP_Write(request, message, strlen(message));
+
+ /* Cookie */
+ HTTP_CookieSend(request, "user1", "foobar4", NULL,NULL,NULL,0);
+
+ HTTP_CookieSend(request, "user2", "foobar3", NULL,NULL,NULL,0);
+
+ HTTP_CookieSend(request, "user3", "foobar2", NULL,NULL,NULL,0);
+
+ HTTP_CookieSend(request, "user4", "foobar1", NULL,NULL,NULL,0);
+
+ strcpy(message,"Content-Type: text/html\r\n\r\n");
+
+ HTTP_Write(request, message, strlen(message));
+
+ /* Start the page */
+ strcpy(message, "<HTML><HEAD><TITLE>Cookie Test</TITLE>\n");
+ strcat(message, cactus_header);
+
+ strcat(message, "<center><h1>Cookie Test</h1></center>");
+
+ HTTP_Write(request, message, strlen(message));
+
+ strcpy(message, "<center>");
+ HTTP_Write(request, message, strlen(message));
+
+ value = HTTP_HeaderValue(request, "Cookie");
+
+ sprintf(message, "<p>Cookie was '%s'</p>\n", value);
+
+ HTTP_Write(request, message, strlen(message));
+
+ value2 = HTTP_CookieGet(request,"user3");
+
+ sprintf(message, "<p>Cookie from decoder was '%s'</p>\n", value2);
+
+ free(value2);
+
+ HTTP_Write(request, message, strlen(message));
+
+ strcpy(message,"</center>");
+ HTTP_Write(request, message, strlen(message));
+
+ /* Write out the footer part. */
+
+ retval = HTTP_Write(request, cactus_footer, strlen(cactus_footer));
+
+ return retval;
+}