/*@@ @file Groups.c @date Wed Sep 14 23:47:43 2000 @author Gabrielle Allen @desc Pages about groups @enddesc @version $Id$ @@*/ #include #include #include "cctk.h" #include "util_String.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) /******************************************************************** ********************* Local Routine Prototypes ********************* ********************************************************************/ int HTTPUTILS_RegisterPages(void); static int MessagesPage(cGH *cctkGH, httpRequest *request, void *data); /******************************************************************** ********************* External Routines ********************** ********************************************************************/ /*@@ @routine HTTPUTILS_RegisterPages @date Wed Sep 14 11:29:43 2000 @author Gabrielle Allen @desc Httpd utils registration routine. @enddesc @@*/ 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); } /******************************************************************** ********************* Local Routines ************************* ********************************************************************/ /*@@ @routine MessagesPage @date Sat Sep 16 @author Gabrielle Allen @desc Message board for simulation. @enddesc @@*/ static int MessagesPage (cGH *GH, httpRequest *request, void *data) { int retval; size_t message_board_len; char message[1024], currtime[64], currdate[64]; const char *const_string, *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) { /* 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 */ const_string = "HTTP/1.0 302 Found\r\n" "Location: /Messages/index.html\r\n\r\n"; } else { const_string = "HTTP/1.0 303 See Other\r\n" "Location: /Messages/index.html\r\n\r\n"; } HTTP_Write (request, const_string, strlen (const_string)); return (0); } /* Status message */ const_string = "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"; HTTP_Write (request, const_string, strlen (const_string)); /* Start the page */ const_string = "CACTUS Messages\n"; HTTP_Write (request, const_string, strlen (const_string)); /* Write out the header part */ HTTP_ContentHeader (GH, 0, sizeof (message), message, NULL); HTTP_Write (request, message, strlen (message)); const_string = "

Message Board

\n" "

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

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

Messages:

" "
"; HTTP_Write (request, const_string, strlen (const_string)); const_string = message_board ? message_board : "No messages yet ... use the form above to add one"; HTTP_Write (request, const_string, strlen (const_string)); const_string = "
"; HTTP_Write (request, const_string, strlen (const_string)); /* Write out the footer part. */ HTTP_ContentFooter (GH, 0, sizeof (message), message); retval = HTTP_Write (request, message, strlen (message)); return (retval); }