From 63f4bbb61d14833559a1ba3c72496076b2ed507a Mon Sep 17 00:00:00 2001 From: swhite Date: Wed, 7 Apr 2004 14:47:59 +0000 Subject: more stragglers git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPDExtra/trunk@49 61ea717e-8e0c-4c3c-b38e-e9c67f54f1f1 --- interface.ccl | 2 + src/Groups.c | 93 +++++++++++--------- src/HostNames.c | 14 +-- src/IO.c | 262 +++++++++++++++++++++++++------------------------------ src/Processors.c | 70 ++++++--------- 5 files changed, 205 insertions(+), 236 deletions(-) diff --git a/interface.ccl b/interface.ccl index 4bae0d5..78e878d 100644 --- a/interface.ccl +++ b/interface.ccl @@ -2,3 +2,5 @@ # $Header$ implements: http_utils + +USES INCLUDE HEADER: HTTPDUtils.h diff --git a/src/Groups.c b/src/Groups.c index cd4fa5c..eb3f248 100644 --- a/src/Groups.c +++ b/src/Groups.c @@ -14,10 +14,11 @@ #include "cctk.h" #include "util_String.h" - -#include "CactusConnect/HTTPD/src/http_Request.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) @@ -76,10 +77,10 @@ int HTTPUTILS_RegisterPages (void) @@*/ static int MessagesPage (const 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; + int retval = 0; + char currtime[64], currdate[64]; + String *message = String_New(); + const char *temp, *name, *memo; static char *message_board = NULL; @@ -93,6 +94,7 @@ static int MessagesPage (const cGH *GH, httpRequest *request, void *data) 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); @@ -115,7 +117,7 @@ static int MessagesPage (const cGH *GH, httpRequest *request, void *data) if (message_board) { sprintf (message_board + message_board_len, - "

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

", + "

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

", name, currtime, currdate, memo); } } @@ -125,60 +127,65 @@ static int MessagesPage (const cGH *GH, httpRequest *request, void *data) (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" + temp = "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" + temp = "HTTP/1.0 303 See Other\r\n" "Location: /Messages/index.html\r\n\r\n"; } - HTTP_Write (request, const_string, strlen (const_string)); + Send_HTTP (request, temp); 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)); + SendHTTP_OK_Header( request ); + + SetHTML_Doctype( message ); + Send_HTTP_String(request, message); /* Start the page */ - const_string = "CACTUS Messages\n"; - HTTP_Write (request, const_string, strlen (const_string)); + Send_HTTP (request, "CACTUS Messages\n" ); + + SetHTML_HeadHeader( message); + Send_HTTP_String(request, message ); /* 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 : + 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"; - HTTP_Write (request, const_string, strlen (const_string)); + Send_HTTP (request, temp ); - const_string = "
"; - HTTP_Write (request, const_string, strlen (const_string)); + Send_HTTP (request, "
" ); /* Write out the footer part. */ - HTTP_ContentFooter (GH, 0, sizeof (message), message); - retval = HTTP_Write (request, message, strlen (message)); + SetHTML_ContentFooter(GH, 0, message); + retval = Send_HTTP_String(request, message); - return (retval); + String_Delete( message ); + return retval; } diff --git a/src/HostNames.c b/src/HostNames.c index 2ab8d20..1099883 100644 --- a/src/HostNames.c +++ b/src/HostNames.c @@ -90,8 +90,8 @@ char *hostdata = NULL; @@*/ void HTTPDExtra_CollateHostData(void) { - int rank; - int nprocs; + int rank = 0; + int nprocs = 1; char thisdata[HOSTDATALENGTH+1]; Util_GetHostName(thisdata, HOSTDATALENGTH); @@ -103,9 +103,6 @@ void HTTPDExtra_CollateHostData(void) MPI_Comm_size(MPI_COMM_WORLD, &nprocs); /* Work out if this is proc 0 or not. */ MPI_Comm_rank(MPI_COMM_WORLD, &rank); -#else - nprocs = 1; - rank = 0; #endif if(rank == 0) @@ -155,8 +152,8 @@ const char *HTTPDExtra_RemoteHostName(int host) int main(int argc, char *argv[]) { - int rank; - int nprocs; + int rank = 0; + int nprocs = 1; #ifdef CCTK_MPI MPI_Init(&argc, &argv); @@ -166,9 +163,6 @@ int main(int argc, char *argv[]) /* Work out if this is proc 0 or not. */ MPI_Comm_rank(MPI_COMM_WORLD, &rank); -#else - nprocs = 1; - rank = 0; #endif HTTPDExtra_CollateHostData(); diff --git a/src/IO.c b/src/IO.c index 784a327..cfaf886 100644 --- a/src/IO.c +++ b/src/IO.c @@ -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, "Cactus Downloadable Files\n"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "\n" ); + Send_HTTP(request, "Cactus Downloadable Files\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, "

Downloadable Files

"); - strcpy(message, "

Downloadable Files

"); - - HTTP_Write(request, message, strlen(message)); - - strcpy(message, + Send_HTTP(request, "

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.

\n " - "

Some of these output files can be directly viewed on " - "a browser on the simulation " - "viewport

" - "

Many IO methods have steerable parameters which " - "allow you to e.g. add fields and customise behaviour." - "Depending on your authorisation, you can access the" - " parameter steering page

" - "
" - "" + "

Some of these output files can be directly viewed on \n" + "a browser on the simulation \n" + "viewport

\n" + "

Many IO methods have steerable parameters which \n" + "allow you to e.g. add fields and customise behaviour.\n" + "Depending on your authorisation, you can access the \n" + "parameter steering page

\n" + "
\n" + "
" "\n"); - HTTP_Write(request, message, strlen(message)); - for (list = filelist; list; list = list->next) { - sprintf(message, - "" - "\n", - list->linkname, list->filename, - list->data.varname, list->data.description); - HTTP_Write(request, message, strlen(message)); + SetToCString(message, "" ); + ConcatCString(message, "\n" ); + + Send_HTTP_String(request, message); } - strcpy(message,"
File NameVariableDescription
%s%s%s
linkname ); + ConcatCString(message, "\">" ); + ConcatCString(message, list->filename ); + ConcatCString(message, "" ); + ConcatCString(message, list->data.varname ); + ConcatCString(message, "" ); + ConcatCString(message, list->data.description ); + ConcatCString(message, "
"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request,""); /* 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, - "\nError 500: Internal Error\n" - "

Unable to open %s

\n\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, "\n\n"); + Send_HTTP(request, "Error 500: Internal Error\n"); + Send_HTTP(request, "\n\n"); + Send_HTTP(request, "

Unable to open " ); + Send_HTTP(request, list->filename ); + Send_HTTP(request, "

\n"); + Send_HTTP(request, "\n\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, - "\nError 404: Not Found\n" - "

%s does not exist

\n\n", - request->uri); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "\n\n" ); + Send_HTTP(request, "Error 404: Not Found\n" ); + Send_HTTP(request, "\n\n" ); + Send_HTTP(request, "

" ); + Send_HTTP(request, request->uri ); + Send_HTTP(request, " does not exist

\n" ); + Send_HTTP(request, "\n\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, "Cactus Downloadable Files\n"); + Send_HTTP(request, "\n\n"); + Send_HTTP(request, "Cactus Downloadable Files\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, "

Viewport

"); - strcpy(message, "

Viewport

"); + Send_HTTP(request, + "

This page displays certain types of the output files \n" + "from the download page \n" + "as images (currently only jpegs [mime type image/jpeg]).

\n" + "

Many IO methods have steerable parameters which \n" + "allow you to e.g. add fields and customise behaviour.\n" + "Depending on your authorisation, you can access the \n" + "parameter steering page

\n"); - HTTP_Write(request, message, strlen(message)); - - strcpy(message, - "

This page displays certain types of the output files " - "from the download page" - " as images (currently only jpegs [mime type image/jpeg]).

" - "

Many IO methods have steerable parameters which " - "allow you to e.g. add fields and customise behaviour." - "Depending on your authorisation, you can access the" - " parameter steering page

"); - - 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, "
" - "" + "
" "\n" "\n"); - HTTP_Write(request, message, strlen(message)); foundone = 1; } - sprintf(message, - "\n" - "\n" - "\n" - "\n" - "\n", - list->data.varname,list->linkname, list->filename, - list->data.description,list->linkname,list->linkname); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "\n" ); + Send_HTTP(request, "\n" ); + Send_HTTP(request, "\n" ); + Send_HTTP(request, "\n" ); + Send_HTTP(request, "\n" ); } } if (!foundone) { - strcpy(message,"

No viewable images registered!

" - "
\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "

No viewable images registered!

" + "
\n"); } - strcpy(message,"
Variable
File Name
DescriptionImage
%s
\n" - "%s\n" - "
%s
" ); + Send_HTTP(request, list->data.varname ); + Send_HTTP(request, "
\n" ); + Send_HTTP(request, "linkname ); + Send_HTTP(request, "\">" ); + Send_HTTP(request, list->filename ); + Send_HTTP(request, "\n" ); + Send_HTTP(request, "
" ); + Send_HTTP(request, list->data.description ); + Send_HTTP(request, "linkname ); + Send_HTTP(request, "\">" ); + Send_HTTP(request, "linkname ); + Send_HTTP(request, "\" />" ); + Send_HTTP(request, "
\n
\n"); - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "\n
\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; } diff --git a/src/Processors.c b/src/Processors.c index 014c344..f0c3527 100644 --- a/src/Processors.c +++ b/src/Processors.c @@ -14,10 +14,12 @@ #include "cctk.h" #include "util_String.h" - +/* #include "CactusConnect/HTTPD/src/http_Request.h" #include "CactusConnect/HTTPD/src/http_Content.h" +*/ #include "httpextra_HostNames.h" +#include "HTTPDUtils.h" static const char *rcsid = "$Header$"; @@ -92,66 +94,52 @@ int HTTPDExtra_RegisterProcessorsPages(void) @@*/ static int ProcessorsPage(const cGH *cctkGH, httpRequest *request, void *data) { - int retval; - int nprocs,np; - char message[4098]; - - /* Status message */ - strcpy(message,"HTTP/1.0 200 OK\r\n"); - - HTTP_Write(request, message, strlen(message)); + int retval = 0; + int nprocs = 0,np = 0; + String *message = String_New(); - /* 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,"Cactus Simulation Processor Information\n"); - - HTTP_Write(request, message, strlen(message)); + Send_HTTP(request, "\n\n"); + Send_HTTP(request, "Cactus Simulation Processor Information\n"); + SetHTML_HeadHeader( message); + Send_HTTP_String(request, message ); + /* HTTP_Write out the header part. */ + SetHTML_ContentHeader(cctkGH, 0, message, NULL); + retval = Send_HTTP_String(request, message); + + Send_HTTP(request, "

Processor Information

\n"); - HTTP_ContentHeader(cctkGH,0,strlen(message),message,NULL); - - retval = HTTP_Write(request, message, strlen(message)); - - strcpy(message, "

Processor Information

\n"); - retval = HTTP_Write(request, message, strlen(message)); - - strcpy(message, + Send_HTTP(request, "
\n\n" "" "\n" "\n" ""); - retval = HTTP_Write(request, message, strlen(message)); nprocs = CCTK_nProcs(cctkGH); for (np=0;np" - "" - "" - "\n", - np, - HTTPDExtra_RemoteHostName(np) - ); - retval = HTTP_Write(request, message, strlen(message)); + SetToCString( message, "\n"); + Send_HTTP_String(request, message ); } - strcpy(message, - "
NumberMachine Name
%d%s
" ); + ConcatDecimal( message, np ); + ConcatCString( message, "" ); + ConcatCString( message, HTTPDExtra_RemoteHostName(np) ); + ConcatCString( message, "
\n
\n"); - retval = HTTP_Write(request, message, strlen(message)); + retval = Send_HTTP(request, "\n
\n"); - /* Write out the footer part. */ - - HTTP_ContentFooter(cctkGH,0,strlen(message),message); - retval = HTTP_Write(request, message, strlen(message)); + SetHTML_ContentFooter(cctkGH, 0, message); + retval = Send_HTTP_String(request, message); + String_Delete( message ); return retval; } -- cgit v1.2.3