diff options
Diffstat (limited to 'src/Content.c')
-rw-r--r-- | src/Content.c | 971 |
1 files changed, 507 insertions, 464 deletions
diff --git a/src/Content.c b/src/Content.c index 2cf34a7..425b9f2 100644 --- a/src/Content.c +++ b/src/Content.c @@ -40,10 +40,13 @@ #include "cctk_Arguments.h" #include "cctk_Parameters.h" +#include "http_SString.h" + static const char *rcsid = "$Header$"; CCTK_FILEVERSION(CactusConnect_HTTPD_Content_c) +#define EMPTYSTRING {'\0'} /******************************************************************** ********************* Local Data Types *********************** ********************************************************************/ @@ -103,11 +106,10 @@ int HTTPi_RegisterParameterPages(void); struct httpLink *ContentLinks = NULL; static const char *notauthorized_page = -"<HTML>\n<HEAD><TITLE>Error 401: Not Authorized</TITLE></HEAD>\ -<BODY>You are not authorized to access this page</BODY>\n<HTML>\n"; +"<html>\n<title>Error 401: Not Authorized</title>\n</head>\n" +"<body>\nYou are not authorized to access this page\n</body>\n<html>\n"; -#define USER_LENGTH 255 /******************************************************************** ********************* External Routines ********************** ********************************************************************/ @@ -212,12 +214,10 @@ int HTTP_ContentLink(const char *URL, const char *description, int flags) { - int retval; - struct httpLink *hlink; + int retval = -1; struct httpLink *last; struct httpLink *current; - - hlink = (struct httpLink *)malloc(sizeof(struct httpLink)); + struct httpLink *hlink = (struct httpLink *)malloc(sizeof(struct httpLink)); if(hlink) { @@ -243,10 +243,6 @@ int HTTP_ContentLink(const char *URL, retval = 0; } - else - { - retval = -1; - } return retval; } @@ -297,146 +293,211 @@ static int CompareStrings(const void *string1, const void *string2) @endhistory @@*/ +int +Send_HTTP( httpRequest * request, const char * message ) +{ + return HTTP_Write(request, message, strlen(message)); +} + +int +Send_HTTP_String( httpRequest *request, const String * message ) +{ + return Send_HTTP(request, GetBuffer( message ) ); +} + +void +SendHTTP_OK_Header( httpRequest *request ) +{ + /* Status message */ + Send_HTTP(request, "HTTP/1.0 200 OK\r\n"); + + /* Content-Type */ + Send_HTTP(request, "Content-Type: text/html\r\n"); + Send_HTTP(request, "\r\n"); +} + +void +SSUtil_SplitFilename(const char **dir,const char **file, const String *message) +{ + Util_SplitFilename((char **)dir,(char **)file,GetBuffer(message)); +} + +static void +TimeListItem( String *message, int time, const char *units ) +{ + ConcatCString(message, " <li><span class=\"hilite\">" ); + ConcatDecimal(message, time ); + ConcatCString(message, "</span> " ); + ConcatCString(message, units ); + ConcatCString(message, "</li>\n" ); +} + +void +CCTK_GetRunTitleString( String *s ) +{ + char buf[1024] = EMPTYSTRING; + CCTK_RunTitle(sizeof(buf)-1,buf); + SetToCString( s, buf ); +} + +void +CCTK_GetParameterFilenameString( String *name ) +{ + char buf[1024] = EMPTYSTRING; + CCTK_ParameterFilename(sizeof(buf)-1,buf); + SetToCString( name, buf ); +} + static int MainPage(const cGH *cctkGH, httpRequest *request, void *data) { DECLARE_CCTK_PARAMETERS - int retval; - char message[10098]; - char title[4098]; - char menu[4098]; - char *dir; - char *file; - char *user; - struct httpLink *hlink; + int retval = -1; + String *message = String_New(); + String *title = String_New(); + String *menu = String_New(); + const char *dir = NULL; + const char *file = NULL; + char *user = NULL; + struct httpLink *hlink = NULL; int seconds,minutes,hours,days,weeks,months,years,millenia; - char host[HOSTLENGTH+1]; + char host[HOSTLENGTH+1] = EMPTYSTRING; /* avoid compiler warning about unused parameter */ data = data; - /* Status message */ - strcpy(message,"HTTP/1.0 200 OK\r\n"); - - HTTP_Write(request, message, strlen(message)); - - /* Content-Type */ - strcpy(message,"Content-Type: text/html\r\n\r\n"); - - HTTP_Write(request, message, strlen(message)); + SendHTTP_OK_Header( request ); + SetHTML_Doctype( message ); + Send_HTTP_String(request, message); /* Start the page */ - strcpy(message,"<HTML><HEAD><TITLE>Running CACTUS Status Information</TITLE>\n"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "<html>\n<head>\n"); + Send_HTTP(request, "<title>Running CACTUS Status Information</title>\n"); + SetHTML_HeadHeader( message); + Send_HTTP_String(request, message ); + Send_HTTP(request, "</head>\n<body>\n"); /* Write out the main header part */ /* LIST COMPILED THORNS */ { int i; - int nthorns; - const char **thorns; - - nthorns = CCTK_NumCompiledThorns(); - thorns = (const char **)malloc(nthorns * sizeof(char *)); - for(i=0; i < nthorns; i++) + int nthorns = CCTK_NumCompiledThorns(); + if( nthorns > 0 ) { - thorns[i] = CCTK_CompiledThorn (i); - } - qsort(thorns, nthorns, sizeof(char *), CompareStrings); - - strcpy(menu, "<DT> <B>Active Thorns:</B>\n"); - for(i=0; i < nthorns; i++) - { - if (CCTK_IsThornActive(thorns[i])) + const char **thorns = (const char **)malloc(nthorns * sizeof(char *)); + if( thorns != NULL ) { - sprintf(menu,"%s<DT><A HREF=\"/Thorns/%s/\">%s</A>\n", - menu, thorns[i], thorns[i]); + for(i=0; i < nthorns; i++) + thorns[i] = CCTK_CompiledThorn (i); + + qsort(thorns, nthorns, sizeof(char *), CompareStrings); + + SetToCString( menu,"<h3>Active Thorns:</h3>\n"); + for(i=0; i < nthorns; i++) + if (CCTK_IsThornActive(thorns[i])) + { + ConcatCString( menu,"<a href=\"/Thorns/"); + ConcatCString( menu, thorns[i]); + ConcatCString( menu,"/\">"); + ConcatCString( menu, thorns[i]); + ConcatCString( menu,"</a><br />\n"); + } + free(thorns); } } - free(thorns); } - HTTP_ContentHeader(cctkGH, 0, 10096, message, menu); - HTTP_Write(request, message, strlen(message)); + SetHTML_ContentHeader(cctkGH, 0, message, menu); + Send_HTTP_String(request, message ); - strcpy(message,"<CENTER>\n" - "<IMG SRC=\"/Images/wwwcactuscodeorg.jpg\"" - " ALT=\"Cactus\" BORDER=0></CENTER>\n"); + Send_HTTP(request, + "<div class=\"banner\">\n" + "<img src=\"/Images/wwwcactuscodeorg.jpg\"" + " alt=\"Cactus\" /></div>\n"); - HTTP_Write(request, message, strlen(message)); - - CCTK_RunTitle(4098,title); + CCTK_GetRunTitleString(title); /* Some blurb */ - sprintf(message, "<br>" - "<CENTER>\n" - "<TABLE WIDTH=60%%>\n" - "<TR>\n" - "<TD ALIGN=CENTER>\n" - "<H2>%s</H2>\n" - "<P>This browser is connected to a Cactus simulation which " - "contains a web server thorn. This thorn provides information " - " and control for the simulation.</P>\n" - "<TABLE CELLPADDING=15>\n" - "<TR>\n" - "<TD ALIGN=CENTER BGCOLOR=#E5FFA2>\n" - "<P><B>Before controlling any features of the simulation, users " - "must <A HREF=\"/control.html\">authenticate</A>.</B></P>\n" - "</TD></TR></TABLE>\n" - "</TD>\n" - "</TR>\n" - "</TABLE>\n",title); - - HTTP_Write(request, message, strlen(message)); - - strcpy(message, - "<CENTER>\n" - "<TABLE CELLPADDING=10>\n" - "<TR>\n" - "<TD VALIGN=TOP>\n"); - HTTP_Write(request, message, strlen(message)); + SetToCString(message, + "<div class=\"centered\">\n" + "<table width=\"60%\">\n" + "<tr>\n" + "<td>\n" + "<h2>"); + Concat(message, title ); + ConcatCString(message, + "</h2>\n" + "<p>This browser is connected to a Cactus simulation which \n" + "contains a web server thorn. This thorn provides information \n" + " and control for the simulation.</p>\n" + "<table cellpadding=\"15\">\n" + "<tr>\n" + "<td class=\"authenticate\">\n" + "<p><strong>Before controlling any features of the simulation, users \n" + "must <a href=\"/control.html\">authenticate</a>.</strong></p>\n" + "</td></tr></table>\n" + "</td>\n" + "</tr>\n" + "</table>\n" + "</div>\n"); + + Send_HTTP_String(request, message ); + + Send_HTTP(request, + "<table cellpadding=\"10\">\n" + "<tr>\n" + "<td>\n"); /* AVAILABLE OPTIONS */ if(ContentLinks) { - strcpy(message, - "<H3>Available options:</H3>\n" - "<dl>\n"); + SetToCString(message, + "<h3>Available options:</h3>\n" + "<dl>\n"); for(hlink = ContentLinks; hlink; hlink=hlink->next) { - sprintf(message, - "%s<dt> <A HREF=\"%s\">%s</a> <dd>%s \n", - message, hlink->URL, hlink->name, hlink->description); - + ConcatCString(message, "<dt> <a href=\""); + ConcatCString(message, hlink->URL ); + ConcatCString(message, "\">" ); + ConcatCString(message, hlink->name ); + ConcatCString(message, "</a> </dt>\n<dd>" ); + ConcatCString(message, hlink->description ); + ConcatCString(message, "</dd>\n" ); } - sprintf(message,"%s</dl>\n",message); - HTTP_Write(request, message, strlen(message)); + ConcatCString(message, "</dl>\n" ); + Send_HTTP_String(request, message ); } - strcpy(message, - "</TD>\n" - "<TD VALIGN=TOP>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, + "</td>\n" + "<td>\n"); /* CONFIGURATION DETAILS */ - sprintf(message, + SetToCString(message, "<h3>Simulation:</h3>\n" "<ul>\n" - "<li>Flesh version <FONT COLOR=RED> %s</FONT></li>\n" - "<li>Flesh compiled on <FONT COLOR=RED>%s</FONT>" - " at <FONT COLOR=RED>%s</font></li>\n", - CCTK_FullVersion(),CCTK_CompileDate(),CCTK_CompileTime()); - - HTTP_Write(request, message, strlen(message)); + "<li>Flesh version <span class=\"hilite\"> "); + ConcatCString(message, CCTK_FullVersion() ); + ConcatCString(message, + "</span></li>\n" + "<li>Flesh compiled on <span class=\"hilite\">"); + ConcatCString(message, CCTK_CompileDate() ); + ConcatCString(message, + "</span>\n" + " at <span class=\"hilite\">"); + ConcatCString(message, CCTK_CompileTime() ); + ConcatCString(message, + "</span></li>\n"); + + Send_HTTP_String(request, message ); seconds = CCTK_RunTime(); minutes = seconds/60; @@ -454,66 +515,59 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data) millenia=years/1000; years=years-millenia*1000; - strcpy(message,"<li>Time since start up\n<ul>"); + SetToCString(message, "<li>Time since start up\n<ul>"); if (millenia) { - sprintf(message, - "%s <li><font color=red>%d</font> millenia\n",message,millenia); + TimeListItem( message, millenia, "millenia" ); } if (years) { - sprintf(message, - "%s <li><font color=red>%d</font> years\n",message,years); + TimeListItem( message, years, "years" ); } if (months) { - sprintf(message, - "%s <li><font color=red>%d</font> months\n",message,months); + TimeListItem( message, months, "months" ); } if (weeks) { - sprintf(message, - "%s <li><font color=red>%d</font> weeks\n",message,weeks); + TimeListItem( message, weeks, "weeks" ); } if (days) { - sprintf(message, - "%s <li><font color=red>%d</font> days\n",message,days); + TimeListItem( message, days, "days" ); } if (hours) { - sprintf(message, - "%s <li><font color=red>%d</font> hours\n",message,hours); + TimeListItem( message, hours, "hours" ); } if (minutes) { - sprintf(message, - "%s <li><font color=red>%d</font> minutes\n",message,minutes); + TimeListItem( message, minutes, "minutes" ); } if (seconds) { - sprintf(message, - "%s <li><font color=red>%d</font> seconds\n",message,seconds); + TimeListItem( message, seconds, "seconds" ); } - strcat(message,"</ul><li>Parameter filename <font color=red>"); - HTTP_Write(request, message, strlen(message)); + ConcatCString(message, "</ul></li>\n<li> Parameter filename <span class=\"parfile\">" ); + Send_HTTP_String(request, message ); - CCTK_ParameterFilename(4098,message); - Util_SplitFilename(&dir,&file,message); - HTTP_Write(request, file, strlen(file)); + CCTK_GetParameterFilenameString(message); + SSUtil_SplitFilename(&dir,&file,message); + Send_HTTP(request, file); - strcpy(message,"</font>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "</span></li>\n"); if (cctkGH && cctkGH->cctk_iteration) { - strcpy(message,"<li>Estimated time per iteration:<UL> "); - sprintf(message,"%s <LI><font color=red>%f</font> seconds</UL>", - message,CCTK_RunTime()/(double)cctkGH->cctk_iteration); - HTTP_Write(request, message, strlen(message)); + SetToCString(message, "<li>Estimated time per iteration:<ul>\n"); + ConcatCString(message, " <li><span class=\"hilite\">"); + ConcatDouble(message, CCTK_RunTime()/(double)cctkGH->cctk_iteration ); + ConcatCString(message, "</span> seconds</li></ul></li>\n"); - strcpy(message,"<li>Estimated time to completion:<UL> "); + Send_HTTP_String(request, message ); + + SetToCString(message, "<li>Estimated time to completion:\n<ul>"); if (cctk_final_time<cctk_initial_time) { @@ -544,48 +598,40 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data) if (millenia) { - sprintf(message, - "%s <li><font color=red>%d</font> millenia\n",message,millenia); + TimeListItem( message, millenia, "millenia" ); } if (years) { - sprintf(message, - "%s <li><font color=red>%d</font> years\n",message,years); + TimeListItem( message, years, "years" ); } if (months) { - sprintf(message, - "%s <li><font color=red>%d</font> months\n",message,months); + TimeListItem( message, months, "months" ); } if (weeks) { - sprintf(message, - "%s <li><font color=red>%d</font> weeks\n",message,weeks); + TimeListItem( message, months, "months" ); } if (days) { - sprintf(message, - "%s <li><font color=red>%d</font> days\n",message,days); + TimeListItem( message, days, "days" ); } if (hours) { - sprintf(message, - "%s <li><font color=red>%d</font> hours\n",message,hours); + TimeListItem( message, hours, "hours" ); } if (minutes) { - sprintf(message, - "%s <li><font color=red>%d</font> minutes\n",message,minutes); + TimeListItem( message, minutes, "minutes" ); } if (seconds) { - sprintf(message, - "%s <li><font color=red>%d</font> seconds\n",message,seconds); + TimeListItem( message, seconds, "seconds" ); } - strcat(message,"</UL>"); + ConcatCString(message, "</ul></li>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP_String(request, message ); } Util_GetHostName(host,HOSTLENGTH); @@ -593,41 +639,44 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data) if (CCTK_nProcs(cctkGH) == 1) { - sprintf(message, - "<li>Single processor run</li>\n" - "<li>Running on <FONT COLOR=RED>%s</FONT></li>\n",host); + SetToCString(message, "<li>Single processor run</li>\n" + "<li>Running on <span class=\"hilite\">" ); + ConcatCString(message, host); + ConcatCString(message, "</span></li>\n"); } else { - sprintf(message, - " <li>Multiprocessor run on %d CPUs</li>\n" - " <li>Processor 0 running on <FONT COLOR=RED>%s</FONT></li>\n", - CCTK_nProcs(cctkGH),host); + SetToCString(message, " <li>Multiprocessor run on " ); + ConcatDecimal(message, CCTK_nProcs(cctkGH)); + ConcatCString(message, " CPUs</li>\n" + " <li>Processor 0 running on <span class=\"hilite\">"); + ConcatCString(message, host); + ConcatCString(message, "</span></li>\n"); } - HTTP_Write(request, message, strlen(message)); + Send_HTTP_String(request, message ); user = getenv ("USER"); if (user) { - sprintf(message, " <li> Started by <FONT COLOR=RED>%s</FONT></li>\n",user); + SetToCString(message, " <li> Started by <span class=\"hilite\">"); + ConcatCString(message, user); + ConcatCString(message, "</span></li>\n"); + Send_HTTP_String(request, message ); } - HTTP_Write(request, message, strlen(message)); - strcpy(message,"</UL>"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "</ul>\n"); /* Finish table started by blurb */ - strcpy(message, - "</TD>\n" - "</TR>\n" - "</TABLE>\n" - "</CENTER>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "</td>\n</tr>\n</table>\n\n"); /* Write out the footer part. */ - HTTP_ContentFooter(cctkGH, 0, 4096, message); - retval = HTTP_Write(request, message, strlen(message)); + SetHTML_ContentFooter(cctkGH, 0, message); + retval = Send_HTTP_String(request, message ); + + String_Delete( message ); + String_Delete( title ); + String_Delete( menu ); return retval; } @@ -657,10 +706,9 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data) @@*/ static int RegisterImages(void) { - struct httpStaticPage *image; - struct httpStaticPage *image2; - - image = (struct httpStaticPage *)malloc(sizeof(struct httpStaticPage)); + struct httpStaticPage *image2 = NULL; + struct httpStaticPage *image + = (struct httpStaticPage *)malloc(sizeof(struct httpStaticPage)); if(image) { @@ -709,37 +757,35 @@ static int RegisterImages(void) @@*/ static int ShowStaticPage(const cGH *cctkGH, httpRequest *request, void *data) { - int retval; - char message[1024]; - struct httpStaticPage *page; + int retval = -1; /* avoid compiler warning about unused parameter */ cctkGH = cctkGH; if(data) { - page = (struct httpStaticPage *)data; + struct httpStaticPage *page = (struct httpStaticPage *)data; + String *message = String_New(); - strcpy(message,"HTTP/1.0 200 OK\r\n"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "HTTP/1.0 200 OK\r\n"); - sprintf(message,"Content-Length: %d\r\nContent-Type: %s\r\n\r\n", page->length, page->mime_type); + SetToCString(message, "Content-Length: "); + ConcatDecimal(message, page->length ); + ConcatCString(message, "\r\nContent-Type: "); + ConcatCString(message, page->mime_type ); + ConcatCString(message, "\r\n\r\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP_String(request, message); retval = HTTP_Write(request, page->page, page->length); - } - else - { - retval = -1; - } + String_Delete( message ); + } return retval; } - +#define USER_LENGTH 255 /*@@ @routine ControlPage @date Sun Sep 17 14:37:59 2000 @@ -758,142 +804,155 @@ static int ControlPage(const cGH *cctkGH, httpRequest *request, void *data) { DECLARE_CCTK_PARAMETERS - char message[4098]; - - int notauthorised; + int notauthorised = 0; + char thisuser[USER_LENGTH+1] = EMPTYSTRING; - char thisuser[USER_LENGTH+1]; + data = data; /* avoid compiler warning about unused parameter */ - /* avoid compiler warning about unused parameter */ - data = data; - - notauthorised = HTTP_AuthenticateBasic(request, "user", thisuser, USER_LENGTH); + notauthorised = HTTP_AuthenticateBasic(request, "user", thisuser, + sizeof(thisuser)); if(!notauthorised) { /* Ok the person is authorised. */ if(request->n_arguments == 0) { + String *message = String_New(); /* No arguments, so just display the page */ - strcpy(message,"HTTP/1.0 200 Ok\r\n"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request,"HTTP/1.0 200 Ok\r\n"); - strcpy(message,"WWW-Authenticate: Basic realm=\"Cactus Control\"\r\n"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request,"WWW-Authenticate: Basic realm=\"Cactus Control\"\r\n"); HTTP_CookieSend(request,"user", thisuser, "/", NULL, NULL, 0); - strcpy(message,"Content-Type: text/html\r\n\r\n"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request,"Content-Type: text/html\r\n\r\n"); + SetHTML_Doctype( message ); + Send_HTTP_String(request, message); /* Start the page */ - strcpy(message, "<HTML><HEAD><TITLE>Cactus Control and Status Page</TITLE>\n"); - - HTTP_Write(request, message, strlen(message)); - HTTP_ContentHeader(cctkGH, 0,4098,message,NULL); + Send_HTTP(request, "<html><head>\n"); + Send_HTTP(request, "<title>Cactus Control and Status Page</title>\n"); - strcat(message, "<center><h1>Control and Status Page</h1></center>"); + SetHTML_HeadHeader( message); + Send_HTTP_String(request, message ); - HTTP_Write(request, message, strlen(message)); - - strcpy(message, - "<P>This page is the control center for interacting with" - " the current simulation. It is possible to steer certain" - " parameters, as well as pause, restart, or terminate the" - " simulation.</P>"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "</head>\n<body>\n"); + + SetHTML_ContentHeader(cctkGH, 0,message,NULL); - strcpy(message, - "<CENTER>\n" - "<FORM action=\"/control.html\" method=\"GET\">\n"); + ConcatCString(message, "<h1>Control and Status Page</h1>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP_String(request, message); - strcpy(message, - "<H4> Run Control </H4>\n" - "<p> Select if the run should be paused, running normally, or terminated." - " You may also single step to the next iteration.</p>"); + Send_HTTP(request, + "<p>This page is the control center for interacting with\n" + " the current simulation. It is possible to steer certain\n" + " parameters, as well as pause, restart, or terminate the" + " simulation.</p>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, + "<div class=\"centered\">\n" + "<form action=\"/control.html\" method=\"get\">\n"); - strcpy(message, - "<TABLE BORDER= 0 CELLSPACING=5 CELLPADDING=5>\n" - "<TR>\n"); + Send_HTTP(request, + "<h4> Run Control </h4>\n" + "<p> Select if the run should be paused, running normally, " + "or terminated.\n" + " You may also single step to the next iteration.</p>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, + "<table class=\"controls\" cellspacing=\"5\" cellpadding=\"5\">\n" + "<tr>\n"); - sprintf(message, - "<TD align=left valign=center><INPUT type=\"radio\" name=\"runstate\" %s value=\"PAUSE\"> PAUSE</TD>\n", - pause ? "checked" : ""); - HTTP_Write(request, message, strlen(message)); + SetToCString(message, + "<td><input type=\"radio\" name=\"runstate\" "); + ConcatCString(message, pause ? "checked=\"checked\"" : ""); + ConcatCString(message, + " value=\"PAUSE\" /> PAUSE</td>\n"); + Send_HTTP_String(request, message); - sprintf(message, - "<TD align=left valign=center><INPUT type=\"radio\" name=\"runstate\" %s value=\"RUN\"> RUN</TD>\n", - pause ? "" : "checked"); - HTTP_Write(request, message, strlen(message)); + SetToCString(message, + "<td><input type=\"radio\" name=\"runstate\" "); + ConcatCString(message, pause ? "checked=\"checked\"" : ""); + ConcatCString(message, + " value=\"RUN\" /> RUN</td>\n"); + Send_HTTP_String(request, message); - strcpy(message, - "<TD align=left valign=center><INPUT type=\"radio\" name=\"runstate\" value=\"TERMINATE\"> TERMINATE</TD>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, + "<td><input type=\"radio\" name=\"runstate\" " + "value=\"TERMINATE\" /> TERMINATE</td>\n"); - strcpy(message, - "<TD align=left valign=center><INPUT type=\"submit\" name=\"step\" value=\"STEP\"></TD>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, + "<td><input type=\"submit\" name=\"step\" " + "value=\"STEP\" /></td>\n"); - strcpy(message, - "</TR></TABLE>\n" - "<TABLE>\n" - "<TR><TD><INPUT type=\"submit\" value=\"OK\"></TD><TD> <INPUT type=\"reset\"></TD>\n" - "</TR>\n" - "</TABLE>\n"); - - HTTP_Write(request, message, strlen(message)); - - strcpy(message, - "<H4> Run Until </H4>\n" - "<p> The following parameters allow you to select an iteration number" - " or physical time at which the code will pause.\n" - " You may also choose to pause if a particular expression made up" - " of grid scalars, simulation time and iteration is true. \n" - " Note that even if 'run' is selected above, the settings here have" - " precedence. </p>"); - - HTTP_Write(request, message, strlen(message)); - - strcpy(message, - "<TABLE>\n"); - - sprintf(message,"%s<TR><TD>Iteration</TD>" - "<TD><INPUT type=\"text\" value=\"%d\" name=\"iteration\"></TD>" - "<TD><INPUT type=\"checkbox\" value=\"yes\" %s name=\"until_it_active\"></TD>\n" - "</TR>\n", message, until_it, until_it_active ? "checked" : ""); - sprintf(message,"%s<TR><TD>Time</TD>" - "<TD><INPUT type=\"text\" value=\"%f\" name=\"time\"></TD>" - "<TD><INPUT type=\"checkbox\" value=\"yes\" %s name=\"until_time_active\"></TD>\n" - "</TR>\n", message, until_time, until_time_active ? "checked" : ""); - sprintf(message,"%s<TR><TD>Expression</TD>" - "<TD><INPUT type=\"text\" value=\"%s\" name=\"expression\"></TD>" - "<TD><INPUT type=\"checkbox\" value=\"yes\" %s name=\"until_expression_active\"></TD>\n" - "</TR>\n", message, until_expression, until_expression_active ? "checked" : ""); - - strcat(message,"</TABLE>\n"); + Send_HTTP(request, + "</tr></table>\n" + "<table>\n" + "<tr><td><input type=\"submit\" value=\"OK\" /></td>\n" + "<td> <input type=\"reset\" /></td>\n" + "</tr>\n" + "</table>\n"); + + Send_HTTP(request, + "<h4> Run Until </h4>\n" + "<p> The following parameters allow you to select an iteration\n" + "number or physical time at which the code will pause.\n" + " You may also choose to pause if a particular expression made up\n" + " of grid scalars, simulation time and iteration is true. \n" + " Note that even if 'run' is selected above, the settings here have" + " precedence. </p>\n"); + + SetToCString(message, + "<table>\n"); + + ConcatCString(message,"<tr><td>Iteration</td>" + "<td><input type=\"text\" value=\""); + ConcatDecimal(message, until_it ); + ConcatCString(message, + "\" name=\"iteration\" /></td>\n" + "<td><input type=\"checkbox\" value=\"yes\" "); + ConcatCString(message, until_it_active ? "checked=\"checked\"" : "" ); + ConcatCString(message, + " name=\"until_it_active\" /></td>\n" + "</tr>\n"); + ConcatCString(message, + "<tr><td>Time</td>" + "<td><input type=\"text\" value=\""); + ConcatDouble(message, until_time ); + ConcatCString(message, + "\" name=\"time\" /></td>\n" + "<td><input type=\"checkbox\" value=\"yes\" "); + ConcatCString(message, until_time_active ? "checked=\"checked\"" : "" ); + ConcatCString(message, + " name=\"until_time_active\" /></td>\n" + "</tr>\n"); + ConcatCString(message, + "<tr><td>Expression</td>\n" + "<td><input type=\"text\" value=\""); + ConcatCString(message, until_expression ); + ConcatCString(message, + "\" name=\"expression\" /></td>\n" + "<td><input type=\"checkbox\" value=\"yes\" "); + ConcatCString(message, until_expression_active ? " checked=\"checked\"" : "" ); + ConcatCString(message, + " name=\"until_expression_active\" /></td>\n" + "</tr>\n"); + + ConcatCString(message,"</table>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP_String(request, message); - strcpy(message, - "</FORM>\n" - "</CENTER>\n"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, + "</form>\n" + "</div>\n"); /* Write out the footer part. */ - HTTP_ContentFooter(cctkGH, 0, 4098, message); - HTTP_Write(request, message, strlen(message)); + SetHTML_ContentFooter(cctkGH, 0, message); + Send_HTTP_String(request, message); + + String_Delete( message ); } else { @@ -904,24 +963,17 @@ static int ControlPage(const cGH *cctkGH, httpRequest *request, void *data) else { /* Not authorised */ - strcpy(message,"HTTP/1.0 401 Unauthorized\r\n"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request,"HTTP/1.0 401 Unauthorized\r\n"); - strcpy(message,"WWW-Authenticate: Basic realm=\"Cactus Control\"\r\n"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request,"WWW-Authenticate: Basic realm=\"Cactus Control\"\r\n"); HTTP_CookieCancel(request,"user", "/"); - strcpy(message,"Content-Type: text/html\r\n\r\n"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request,"Content-Type: text/html\r\n\r\n"); - HTTP_Write(request, notauthorized_page, strlen(notauthorized_page)); + Send_HTTP(request, notauthorized_page); } - return 0; } @@ -942,8 +994,8 @@ static int ControlPage(const cGH *cctkGH, httpRequest *request, void *data) static int ControlSet(const cGH *cctkGH, httpRequest *request) { DECLARE_CCTK_PARAMETERS - char message[4098]; - const char *value; + String *message = String_New(); + const char *value = NULL; /* What is the runstate ? */ value = HTTP_ArgumentValue(request,"runstate"); @@ -1074,22 +1126,27 @@ static int ControlSet(const cGH *cctkGH, httpRequest *request) /**************************************************************************** **************** Now redirect the browser to the normal page *************** */ + /* SW: I don't think this is working right. On my browsers, it just + * displays the ControlTerminationPage, with the following lines + * of text rendered at the bottom. */ /* Status message */ if(request->http_major_version < 1 || (request->http_major_version == 1 && request->http_minor_version < 1)) { /* Older browsers don't understand 303 */ - strcpy(message,"HTTP/1.0 302 Found\r\n"); + SetToCString(message,"HTTP/1.0 302 Found\r\n"); } else { - strcpy(message,"HTTP/1.0 303 See Other\r\n"); + SetToCString(message,"HTTP/1.0 303 See Other\r\n"); } - sprintf(message, "%sLocation: /control.html\r\n\r\n", message); + ConcatCString(message, "Location: /control.html\r\n\r\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP_String(request, message); + + String_Delete( message ); return 0; } @@ -1110,121 +1167,109 @@ static int ControlSet(const cGH *cctkGH, httpRequest *request) @@*/ static int ControlTerminationPage(const cGH *cctkGH, httpRequest *request) { - int retval; - char message[4098]; - - /* Status message */ - strcpy(message,"HTTP/1.0 200 OK\r\n"); - - HTTP_Write(request, message, strlen(message)); - - /* Content-Type */ - strcpy(message,"Content-Type: text/html\r\n\r\n"); - - HTTP_Write(request, message, strlen(message)); + int retval = -1; + String *message = String_New(); + SendHTTP_OK_Header( request ); + SetHTML_Doctype( message ); + Send_HTTP_String(request, message); /* Start the page */ - strcpy(message,"<HTML><HEAD><TITLE>Running CACTUS Status Information : Terminated</TITLE>\n"); + Send_HTTP(request, "<html><head>\n"); + Send_HTTP(request, "<title>Running CACTUS Status Information : Terminated</title>\n"); - HTTP_Write(request, message, strlen(message)); + SetHTML_HeadHeader( message); + Send_HTTP_String(request, message ); - /* Write out the main header part */ - HTTP_ContentHeader(cctkGH,1,4098,message,NULL); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "</head>\n<body>\n"); - strcpy(message, "<center><h1>Simulation Home Page</h1></center>"); + /* Write out the main header part */ + SetHTML_ContentHeader(cctkGH,1,message,NULL); + Send_HTTP_String(request, message); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "<h1>Simulation Home Page</h1>\n"); /* Some blurb */ - strcpy(message, "<br>" - "<center><table cellspacing=5 cellpadding=5 border=0><tr><td valign=top>" - "<h3>Simulation web server:</h3>" - "<p>This browser is connected to a Cactus simulation which contains " - "a web server thorn. This thorn allows you to monitor the simulation, " - "and view and change parameters</p>" - "<p>Depending on which other thorns are active, there may be additional " - "features available, such as the viewing and downloading of output files</p>"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, + "<div class=\"centered\">\n" + "<table cellspacing=\"5\" cellpadding=\"5\" border=\"0\"><tr><td>\n" + "<h3>Simulation web server:</h3>\n" + "<p>This browser is connected to a Cactus simulation which \n" + "contains a web server thorn. This thorn allows you to monitor \n" + "the simulation,\n" + "and view and change parameters</p>\n" + "<p>Depending on which other thorns are active, there may be \n" + "additional features available, such as the viewing and \n" + "downloading of output files</p>\n"); /* CONFIGURATION DETAILS */ - sprintf(message, "<h3>Simulation:</h3>" - "<ul><li>Flesh version <FONT COLOR=RED>%s" - "</FONT></li>\n" - "<li>Flesh compiled on <FONT COLOR=RED>" - __DATE__ "</FONT> at <FONT COLOR=RED>"__TIME__ "</font></li>\n" - ,CCTK_FullVersion()); + SetToCString(message, + "<h3>Simulation:</h3>\n" + "<ul> <li>Flesh version <span class=\"hilite\"> "); + ConcatCString(message, CCTK_FullVersion() ); + ConcatCString(message, + "</span></li>\n" + "<li>Flesh compiled on <span class=\"hilite\"> __DATE__ </span>\n" + "at <span class=\"hilite\"> __TIME__ </span></li>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP_String(request, message); if (cctkGH) { if (CCTK_nProcs(cctkGH) == 1) { - strcpy(message,"<li>Single processor run</li>"); + SetToCString(message,"<li>Single processor run</li>\n"); } else { - sprintf(message," <li>Multiprocessor run on %d CPUs</li>", - CCTK_nProcs(cctkGH)); + SetToCString(message," <li>Multiprocessor run on "); + ConcatDecimal( message, CCTK_nProcs(cctkGH) ); + ConcatCString( message, " CPUs</li>\n"); } - HTTP_Write(request, message, strlen(message)); + Send_HTTP_String(request, message); } - strcpy(message,"</UL>"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request,"</ul>\n"); - /******************************************************************************/ + /************************************************************************/ /* NEW COLUMN */ - strcpy(message, "</td><td valign=top>"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "</td><td>"); - /*******************************************************************************/ + /************************************************************************/ /* CURRENT STATE OF SIMULATION */ if (cctkGH) { - sprintf(message, "<H3> Current state:</h3> " - "<ul><li>Physical time <FONT COLOR=RED>%f" - "</FONT>\n" - "<li>Iteration number <FONT COLOR=RED>%d" - "</FONT></li>\n", - cctkGH->cctk_time, - cctkGH->cctk_iteration); + SetToCString(message, + "<h3> Current state:</h3> \n" + "<ul><li>Physical time <span class=\"hilite\"> "); + ConcatDouble(message, cctkGH->cctk_time ); + ConcatCString(message, + "</span></li> \n" + "<li>Iteration number <span class=\"hilite\"> "); + ConcatDecimal(message, cctkGH->cctk_iteration ); + ConcatCString(message, "</li>\n"); } else { - strcpy(message, "<li>Current cactus state is unknown</li>\n"); + SetToCString(message, "<li>Current cactus state is unknown</li>\n"); } - HTTP_Write(request, message, strlen(message)); - - strcpy(message, "<li>This Cactus run is over.</li>\n"); - - HTTP_Write(request, message, strlen(message)); - - strcpy(message, "</ul>"); + Send_HTTP_String(request, message); + Send_HTTP(request, "<li>This Cactus run is over.</li>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "</ul>"); /* LIST COMPILED THORNS */ - { int i; - int nthorns; - const char **thorns; - - nthorns = CCTK_NumCompiledThorns(); - - thorns = (const char **)malloc(nthorns * sizeof(char *)); + int nthorns = CCTK_NumCompiledThorns(); + const char **thorns = (const char **)malloc(nthorns * sizeof(char *)); for(i=0; i < nthorns; i++) { @@ -1234,42 +1279,45 @@ static int ControlTerminationPage(const cGH *cctkGH, httpRequest *request) /* Sort the thorns */ qsort(thorns, nthorns, sizeof(char *), CompareStrings); - strcpy(message, "<h3>Compiled thorns:</h3>" - "<p>This list shows all thorns compiled into the executable, " - "those thorns which have been activated in the parameter " - "file for this simulation are shown in " - "<font color=red>red</font></p>" - "<UL>\n"); + SetToCString(message, + "<h3>Compiled thorns:</h3>\n" + "<p>This list shows all thorns compiled into the executable; those \n" + "thorns which have been activated in the parameter file for this \n" + "simulation are shown in <span class=\"hilite\">red</span></p>\n" + "<ul>\n"); for(i=0; i < nthorns; i++) { - strcat(message, "<LI>"); + ConcatCString(message, "<li>"); if (CCTK_IsThornActive(thorns[i])) { - sprintf(message,"%s<FONT COLOR=red>%s</FONT>\n", message, thorns[i]); + ConcatCString(message, " <span class=\"hilite\">"); + ConcatCString(message, thorns[i]); + ConcatCString(message, " </span>"); } else { - sprintf(message, "%s%s\n", message, thorns[i]); + ConcatCString(message, thorns[i]); } + ConcatCString(message, "</li>\n"); } - strcat(message, "</UL>\n"); + ConcatCString(message, "</ul>\n"); free(thorns); } - HTTP_Write(request, message, strlen(message)); + Send_HTTP_String(request, message); /* Finish table started by blurb */ - strcpy(message, "</td></tr></table>"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "</td></tr></table>\n"); /* Write out the footer part. */ - HTTP_ContentFooter(cctkGH,0,4098,message); - retval = HTTP_Write(request, message, strlen(message)); + SetHTML_ContentFooter(cctkGH,0,message); + retval = Send_HTTP_String(request, message); + + String_Delete( message ); return retval; } @@ -1289,12 +1337,12 @@ static int ControlTerminationPage(const cGH *cctkGH, httpRequest *request) @@*/ int HTTP_ContentSendFromFile(httpRequest *request, int filedes) { - int bytes_sent; - int n_bytes; - char buffer[4098]; + int bytes_sent = 0; + int n_bytes = 0; + char buffer[4098] = EMPTYSTRING; bytes_sent = 0; - while((n_bytes = read(filedes, buffer,4098)) > 0) + while((n_bytes = read(filedes, buffer,sizeof(buffer))) > 0) { HTTP_Write(request, buffer, n_bytes); bytes_sent += n_bytes; @@ -1309,7 +1357,6 @@ int HTTP_ContentSendFromFile(httpRequest *request, int filedes) } - /*@@ @routine AboutPage @date Sun Sep 17 2000 @@ -1322,60 +1369,54 @@ int HTTP_ContentSendFromFile(httpRequest *request, int filedes) @@*/ static int AboutPage(const cGH *cctkGH, httpRequest *request, void *data) { - int retval; - char message[4098]; + int retval = -1; + String *message = String_New(); /* avoid compiler warning about unused parameter */ data = data; - /* Status message */ - strcpy(message,"HTTP/1.0 200 OK\r\n"); - - HTTP_Write(request, message, strlen(message)); - - /* Content-Type */ - strcpy(message,"Content-Type: text/html\r\n\r\n"); - - HTTP_Write(request, message, strlen(message)); + SendHTTP_OK_Header( request ); + SetHTML_Doctype( message ); + Send_HTTP_String(request, message); /* Start the page */ - strcpy(message, "<HTML><HEAD><TITLE>About Cactus Server</TITLE></HEAD>\n"); - HTTP_ContentHeader(cctkGH,0,4098,message,NULL); - strcat(message,"<BODY>"); - HTTP_Write(request, message, strlen(message)); + SetToCString(message, "<html><head>\n<title>About Cactus Server</title>\n"); + SetHTML_HeadHeader( message); + Send_HTTP_String(request, message ); - strcpy(message, "<center>"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "</head>\n<body>\n"); + SetHTML_ContentHeader(cctkGH,0,message,NULL); + Send_HTTP_String(request, message); - strcpy(message, "<h1>About this Web Server</h1>"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "<h1>About this Web Server</h1>\n"); - strcpy(message, "</center><p>These web pages are served by a simulation " - "which is using the Cactus Code and Computational ToolKit, " + SetToCString(message, "<p>These web pages are served by a simulation \n" + "which is using the Cactus Code and Computational ToolKit, \n" "a freely available, parallel, collaborative," - " portable and " - "modular programming environment for HPC.</p>" - "<p>The HTTPD module, or <i>thorn</i> " - "which is serving these pages" - " can be added to any Cactus application to provide on-line " - "monitoring and control of simulations from any web browser.</p>" - "<p>This HTTPD server and thorn interface has been designed and " - "and implemented by Tom Goodale, based on the original idea and " - "implementation by Werner Benger.</p>"); + " portable and \n" + "modular programming environment for HPC.</p>\n" + "<p>The HTTPD module, or <dfn>thorn</dfn> " + "which is serving these pages\n" + " can be added to any Cactus application to provide on-line \n" + "monitoring and control of simulations from any web browser.</p>\n" + "<p>This HTTPD server and thorn interface has been designed and \n" + "and implemented by Tom Goodale, based on the original idea and \n" + "implementation by Werner Benger.</p>\n"); - retval = HTTP_Write(request, message, strlen(message)); + retval = Send_HTTP_String(request, message); - strcpy(message, "<p>For more information about Cactus, visit our " - "permanent home page at " - "<a href=\"http://www.cactuscode.org\">www.cactuscode.org</a></p>"); + SetToCString(message, "<p>For more information about Cactus, visit our " + "permanent home page at \n" + "<a href=\"http://www.cactuscode.org\">www.cactuscode.org</a></p>\n"); - retval = HTTP_Write(request, message, strlen(message)); + retval = Send_HTTP_String(request, message); /* Write out the footer part. */ - HTTP_ContentFooter(cctkGH,0,4098,message); - retval = HTTP_Write(request, message, strlen(message)); + SetHTML_ContentFooter(cctkGH,0,message); + retval = Send_HTTP_String(request, message); + String_Delete( message); return retval; } @@ -1397,18 +1438,16 @@ static int AboutPage(const cGH *cctkGH, httpRequest *request, void *data) @@*/ static int CookieTestPage(const cGH *cctkGH, httpRequest *request, void *data) { - int retval; - char message[4098]; - const char *value; - char *value2; + int retval = -1; + String *message = String_New(); + const char *value = NULL; + char *value2 = NULL; /* avoid compiler warning about unused parameter */ data = data; /* Status message */ - strcpy(message,"HTTP/1.0 200 OK\r\n"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request,"HTTP/1.0 200 OK\r\n"); /* Cookie */ HTTP_CookieSend(request, "user1", "foobar4", NULL,NULL,NULL,0); @@ -1419,45 +1458,49 @@ static int CookieTestPage(const cGH *cctkGH, httpRequest *request, void *data) 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)); + Send_HTTP(request,"Content-Type: text/html\r\n\r\n"); + SetHTML_Doctype( message ); + Send_HTTP_String(request, message); /* Start the page */ - strcpy(message, "<HTML><HEAD><TITLE>Cookie Test</TITLE>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "<html><head><title>Cookie Test</title>\n"); + SetHTML_HeadHeader( message); + Send_HTTP_String(request, message ); - HTTP_ContentHeader(cctkGH,0,4098,message,NULL); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "</head>\n<body>\n"); - strcat(message, "<center><h1>Cookie Test</h1></center>"); + SetHTML_ContentHeader(cctkGH,0,message,NULL); + Send_HTTP_String(request, message); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "<h1>Cookie Test</h1>\n"); - strcpy(message, "<center>"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "<div class=\"centered\">"); value = HTTP_HeaderValue(request, "Cookie"); - sprintf(message, "<p>Cookie was '%s'</p>\n", value); + SetToCString(message, "<p>Cookie was '"); + ConcatCString(message, value); + ConcatCString(message, "'</p>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP_String(request, message); value2 = HTTP_CookieGet(request,"user3"); - sprintf(message, "<p>Cookie from decoder was '%s'</p>\n", value2); + SetToCString(message, "<p>Cookie from decoder was '"); + ConcatCString(message, value2); + ConcatCString(message, "'</p>\n"); free(value2); - HTTP_Write(request, message, strlen(message)); + Send_HTTP_String(request, message); - strcpy(message,"</center>"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request,"</div>\n"); /* Write out the footer part. */ - HTTP_ContentFooter(cctkGH,0,4098,message); - retval = HTTP_Write(request, message, strlen(message)); + SetHTML_ContentFooter(cctkGH,0,message); + retval = Send_HTTP_String(request, message); + String_Delete( message ); return retval; } |