diff options
Diffstat (limited to 'src/IO.c')
-rw-r--r-- | src/IO.c | 262 |
1 files changed, 120 insertions, 142 deletions
@@ -23,9 +23,11 @@ #include "util_String.h" #include "CactusBase/IOUtil/src/ioutil_AdvertisedFiles.h" - +/* #include "CactusConnect/HTTPD/src/http_Request.h" #include "CactusConnect/HTTPD/src/http_Content.h" +*/ +#include "HTTPDUtils.h" static const char *rcsid = "$Header$"; @@ -207,77 +209,67 @@ static int IOFileListener(const cGH *GH, const char *filename, static int AdvertisedFilePage(const cGH *GH, httpRequest *request, void *data) { int retval; - char message[4098]; + String *message = String_New(); struct httpuFileList *list; + data = data; /* avoid compiler warning about unused parameter */ - /* 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>Cactus Downloadable Files</TITLE>\n"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "<html><head>\n" ); + Send_HTTP(request, "<title>Cactus Downloadable Files</title>\n"); + SetHTML_HeadHeader( message); + Send_HTTP_String(request, message ); + /* HTTP_Write out the header part. */ + SetHTML_ContentHeader(GH, 0, message, NULL); + Send_HTTP_String(request, message); - HTTP_ContentHeader(GH, 0, 4098, message,NULL); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "<h1>Downloadable Files</h1>"); - strcpy(message, "<center><h1>Downloadable Files</h1></center>"); - - HTTP_Write(request, message, strlen(message)); - - strcpy(message, + Send_HTTP(request, "<p>From this page you can download various output files \n" - "from the simulation. Depending on the software available on your" - " local machine, you can change the browser properties to launch" + "from the simulation. Depending on the software available on your\n" + " local machine, you can change the browser properties to launch\n" " files directly to visualization clients.</p> \n " - "<p>Some of these output files can be directly viewed on " - "a browser on the simulation " - "<a href=\"/Output/viewport.html\">viewport</a></p>" - "<p>Many IO methods have <i>steerable</i> parameters which " - "allow you to e.g. add fields and customise behaviour." - "Depending on your authorisation, you can access the" - " <a href=\"/Parameters/index.html\">parameter steering page</a></p>" - "<center>" - "<table cellspacing=5 cellpadding=5 border=0\n>" + "<p>Some of these output files can be directly viewed on \n" + "a browser on the simulation \n" + "<a href=\"/Output/viewport.html\">viewport</a></p>\n" + "<p>Many IO methods have <i>steerable</i> parameters which \n" + "allow you to e.g. add fields and customise behaviour.\n" + "Depending on your authorisation, you can access the \n" + "<a href=\"/Parameters/index.html\">parameter steering page</a></p>\n" + "<center>\n" + "<table cellspacing=\"5\" cellpadding=\"5\"\n>" "<tr><th>File Name</th><th>Variable</th><th>Description</th></tr>\n"); - HTTP_Write(request, message, strlen(message)); - for (list = filelist; list; list = list->next) { - sprintf(message, - "<tr><td valign=top><A HREF=\"/Output/%s\">%s</A></td>" - "<td valign=top>%s</td><td valign=top>%s</td></tr>\n", - list->linkname, list->filename, - list->data.varname, list->data.description); - HTTP_Write(request, message, strlen(message)); + SetToCString(message, "<tr><td valign=\"top\"><a href=\"/Output/" ); + ConcatCString(message, list->linkname ); + ConcatCString(message, "\">" ); + ConcatCString(message, list->filename ); + ConcatCString(message, "</a></td>" ); + ConcatCString(message, "<td valign=\"top\">" ); + ConcatCString(message, list->data.varname ); + ConcatCString(message, "</td><td valign=\"top\">" ); + ConcatCString(message, list->data.description ); + ConcatCString(message, "</td></tr>\n" ); + + Send_HTTP_String(request, message); } - strcpy(message,"</table></center>"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request,"</table></center>"); /* Write out the footer part. */ + SetHTML_ContentFooter(GH, 0, message); + Send_HTTP_String(request, message); - /* HTTP_Write out the footer part. */ - - HTTP_ContentFooter(GH, 0, 4098, message); - - retval = HTTP_Write(request, message, strlen(message)); - + String_Delete( message ); return retval; } @@ -292,10 +284,7 @@ static int AdvertisedFilePage(const cGH *GH, httpRequest *request, void *data) @@*/ static int SendFilePage(const cGH *GH, httpRequest *request, void *data) { - char message[4098]; struct httpuFileList *list; - int filedes; - /* avoid compiler warning about unused parameters */ (void) (GH + 0); @@ -305,16 +294,14 @@ static int SendFilePage(const cGH *GH, httpRequest *request, void *data) { if(!strcmp(list->linkname, request->residual)) { + int filedes; if((filedes = open(list->filename, O_RDONLY | O_BINARY)) >= 0) { - 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"); - /* Content-Type */ - sprintf(message,"Content-Type: %s\r\n\r\n", list->data.mimetype); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "Content-Type: " ); + Send_HTTP(request, list->data.mimetype); + Send_HTTP(request, "\r\n\r\n" ); HTTP_ContentSendFromFile(request, filedes); @@ -322,19 +309,16 @@ static int SendFilePage(const cGH *GH, httpRequest *request, void *data) } else { - strcpy(message,"HTTP/1.0 500 Server Internal Error\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)); - - sprintf(message, - "<HTML>\n<HEAD><TITLE>Error 500: Internal Error</TITLE></HEAD>\n" - "<BODY><CENTER><p>Unable to open %s</P></BODY>\n</HTML>\n", - list->filename); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request,"HTTP/1.0 500 Server Internal Error\r\n"); + + Send_HTTP(request, "Content-Type: text/html\r\n\r\n"); + Send_HTTP(request, "<html>\n<head>\n"); + Send_HTTP(request, "<title>Error 500: Internal Error</title>\n"); + Send_HTTP(request, "</head>\n<body>\n"); + Send_HTTP(request, "<center><p>Unable to open " ); + Send_HTTP(request, list->filename ); + Send_HTTP(request, "</p></center>\n"); + Send_HTTP(request, "</body>\n</html>\n" ); } break; } @@ -342,21 +326,18 @@ static int SendFilePage(const cGH *GH, httpRequest *request, void *data) if(!list) { - strcpy(message,"HTTP/1.0 404 Not Found\r\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request,"HTTP/1.0 404 Not Found\r\n"); - /* Content-Type */ - strcpy(message,"Content-Type: text/html\r\n\r\n"); + Send_HTTP(request,"Content-Type: text/html\r\n\r\n"); - HTTP_Write(request, message, strlen(message)); - - sprintf(message, - "<HTML>\n<HEAD><TITLE>Error 404: Not Found</TITLE></HEAD>\n" - "<BODY><CENTER><p>%s does not exist</P></BODY>\n</HTML>\n", - request->uri); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "<html>\n<head>\n" ); + Send_HTTP(request, "<title>Error 404: Not Found</title>\n" ); + Send_HTTP(request, "</head>\n<body>\n" ); + Send_HTTP(request, "<center><p>" ); + Send_HTTP(request, request->uri ); + Send_HTTP(request, " does not exist</p></center>\n" ); + Send_HTTP(request, "</body>\n</html>\n" ); } - return 0; } @@ -371,98 +352,95 @@ static int SendFilePage(const cGH *GH, httpRequest *request, void *data) @@*/ static int ViewportFilePage(const cGH *GH, httpRequest *request, void *data) { - int retval; - int foundone; - char message[4098]; + int retval = 0; + int foundone = 0; + String *message = String_New(); struct httpuFileList *list; - /* avoid compiler warning about unused parameters */ (void) (GH + 0); 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>Cactus Downloadable Files</TITLE>\n"); + Send_HTTP(request, "<html>\n<head>\n"); + Send_HTTP(request, "<title>Cactus Downloadable Files</title>\n"); - HTTP_Write(request, message, strlen(message)); + SetHTML_HeadHeader( message); + Send_HTTP_String(request, message ); /* HTTP_Write out the header part. */ - HTTP_ContentHeader(GH, 0, 4098, message,NULL); + SetHTML_ContentHeader(GH, 0, message, NULL); + Send_HTTP_String(request, message); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "<h1>Viewport</h1>"); - strcpy(message, "<center><h1>Viewport</h1></center>"); + Send_HTTP(request, + "<p>This page displays certain types of the output files \n" + "from the <a href=\"/Output/index.html\">download</a> page \n" + "as images (currently only jpegs [mime type image/jpeg]).</p>\n" + "<p>Many IO methods have <dfn>steerable</dfn> parameters which \n" + "allow you to e.g. add fields and customise behaviour.\n" + "Depending on your authorisation, you can access the \n" + "<a href=\"/Parameters/index.html\">parameter steering page</a></p>\n"); - HTTP_Write(request, message, strlen(message)); - - strcpy(message, - "<p>This page displays certain types of the output files " - "from the <a href=\"/Output/index.html\">download</a> page" - " as images (currently only jpegs [mime type image/jpeg]).</p>" - "<p>Many IO methods have <i>steerable</i> parameters which " - "allow you to e.g. add fields and customise behaviour." - "Depending on your authorisation, you can access the" - " <a href=\"/Parameters/index.html\">parameter steering page</a></p>"); - - HTTP_Write(request, message, strlen(message)); - - foundone = 0; for (list = filelist; list; list = list->next) { if (CCTK_Equals(list->data.mimetype,"image/jpeg")) { if (!foundone) { - strcpy(message, + Send_HTTP(request, "<center>" - "<table cellspacing=5 cellpadding=5 border=0\n>" + "<table cellspacing=\"5\" cellpadding=\"5\" border=\"0\"\n>" "<tr><th>Variable<br>File Name</th>\n" "<th>Description</th><th>Image</th></tr>\n"); - HTTP_Write(request, message, strlen(message)); foundone = 1; } - sprintf(message, - "<tr>\n" - "<td valign=center><small>%s<br>\n" - "<A HREF=\"/Output/%s\">%s</A>\n" - "</small></td>\n" - "<td valign=center>%s</td>\n" - "<td valign=center><A HREF=\"/Output/%s\"><img border=0 width=100 height=100 src=\"%s\"></A></td>\n" - "</tr>\n", - list->data.varname,list->linkname, list->filename, - list->data.description,list->linkname,list->linkname); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "<tr>\n" ); + Send_HTTP(request, "<td valign=center><small>" ); + Send_HTTP(request, list->data.varname ); + Send_HTTP(request, "<br />\n" ); + Send_HTTP(request, "<a href=\"/Output/" ); + Send_HTTP(request, list->linkname ); + Send_HTTP(request, "\">" ); + Send_HTTP(request, list->filename ); + Send_HTTP(request, "</a>\n" ); + Send_HTTP(request, "</small></td>\n" ); + Send_HTTP(request, "<td valign=center>" ); + Send_HTTP(request, list->data.description ); + Send_HTTP(request, "</td>\n" ); + Send_HTTP(request, "<td valign=center><a href=\"/Output/" ); + Send_HTTP(request, list->linkname ); + Send_HTTP(request, "\">" ); + Send_HTTP(request, "<img border=\"0\" width=\"100\" height=\"100\" src=\"" ); + Send_HTTP(request, list->linkname ); + Send_HTTP(request, "\" />" ); + Send_HTTP(request, "</a></td>\n" ); + Send_HTTP(request, "</tr>\n" ); } } if (!foundone) { - strcpy(message,"<center><b><p>No viewable images registered!</p>" - "<b><center>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "<center><strong><p>No viewable images registered!</p>" + "<strong></center>\n"); } - strcpy(message,"</table>\n</center>\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "</table>\n</center>\n"); /* Write out the footer part. */ - HTTP_ContentFooter(GH, 0, 4098, message); - - retval = HTTP_Write(request, message, strlen(message)); + SetHTML_ContentFooter(GH, 0, message); + retval = Send_HTTP_String(request, message); + String_Delete( message ); return retval; } |