/*@@ @file Groups.c @date Wed Sep 14 23:47:43 2000 @author Gabrielle Allen @desc Pages about groups. @enddesc @version $Id$ @@*/ #include #include #include #include "cctk.h" #include "util_String.h" #include "HTTPDUtils.h" /* * #include "CactusConnect/HTTPD/src/http_Request.h" #include "CactusConnect/HTTPD/src/http_Content.h" */ static const char *rcsid = "$Header$"; CCTK_FILEVERSION(CactusConnect_HTTPDExtra_Groups_c) /******************************************************************** ********************* External Routines ********************** ********************************************************************/ int HTTPUTILS_RegisterPages (void); /******************************************************************** ********************* Internal Routines ********************** ********************************************************************/ static int MessagesPage(const cGH *cctkGH, httpRequest *request, void *data); /*@@ @routine HTTPUTILS_RegisterPages @date Wed Sep 14 11:29:43 2000 @author Gabrielle Allen @desc Httpd utils registration routine. @enddesc @calls HTTP_RegisterPage HTTP_ContentLink @returntype int @returndesc 0 for success @endreturndesc @@*/ int HTTPUTILS_RegisterPages (void) { /* Register the message board page. */ HTTP_RegisterPage ("/Messages", MessagesPage, NULL); HTTP_ContentLink ("/Messages/index.html", "Message Board", "Collaborative simulation notepad", HTTP_QUICKLINK); return (0); } /******************************************************************** ******************** Internal Routines ************************ ********************************************************************/ /*@@ @routine MessagesPage @date Sat Sep 16 @author Gabrielle Allen @desc Message board for simulation. @enddesc @@*/ static int MessagesPage (const cGH *GH, httpRequest *request, void *data) { int retval = 0; char currtime[64], currdate[64]; String *message = String_New(); const char *temp, *name, *memo; static char *message_board = NULL; /* avoid compiler warning about unused parameter */ data = data; if (request->n_arguments > 0) { name = HTTP_ArgumentValue (request, "name"); memo = HTTP_ArgumentValue (request, "memo"); if (name && *name && memo && *memo) { size_t message_board_len = 0; /* concatenate new message, labeled with current date/time, to the message board */ Util_CurrentTime (sizeof (currtime), currtime); Util_CurrentDate (sizeof (currdate), currdate); if (message_board) { message_board_len = strlen (message_board); message_board = (char *) realloc (message_board, message_board_len + strlen (currtime) + strlen (currdate)+ strlen (name) + strlen (memo) + 60); } else { message_board_len = 0; message_board = (char *) malloc (strlen (currtime) + strlen (currdate) + strlen (name) + strlen (memo) + 60); } if (message_board) { sprintf (message_board + message_board_len, "

%s %s %s
\n\n%s

", name, currtime, currdate, memo); } } /* Now redirect the browser to the normal message board page */ if (request->http_major_version < 1 || (request->http_major_version == 1 && request->http_minor_version < 1)) { /* Older browsers don't understand 303 */ temp = "HTTP/1.0 302 Found\r\n" "Location: /Messages/index.html\r\n\r\n"; } else { temp = "HTTP/1.0 303 See Other\r\n" "Location: /Messages/index.html\r\n\r\n"; } Send_HTTP (request, temp); return (0); } /* Status message */ SendHTTP_OK_Header( request ); SetHTML_Doctype( message ); Send_HTTP_String(request, message); /* Start the page */ Send_HTTP (request, "CACTUS Messages\n" ); SetHTML_HeadHeader( message); Send_HTTP_String(request, message ); /* Write out the header part */ SetHTML_ContentHeader(GH, 0, message, NULL); Send_HTTP_String(request, message); Send_HTTP (request, "

Message Board

\n" "

This page can be used to post messages during a \n" "simulation. At the moment the messages will disappear \n" "when the simulation finishes, but soon there will be an \n" "option to save them to a file.

\n" "
\n" "" "\n" "
Name:
Message:" "\n" "
\n" "\n" "\n" "
\n" "

Messages:

" "
" ); temp = message_board ? message_board : "No messages yet ... use the form above to add one"; Send_HTTP (request, temp ); Send_HTTP (request, "
" ); /* Write out the footer part. */ SetHTML_ContentFooter(GH, 0, message); retval = Send_HTTP_String(request, message); String_Delete( message ); return retval; }