aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorswhite <swhite@1faa4e14-9dd3-4be0-9f0e-ffe519881164>2004-04-13 13:42:54 +0000
committerswhite <swhite@1faa4e14-9dd3-4be0-9f0e-ffe519881164>2004-04-13 13:42:54 +0000
commit310f5363afe8ed31b6381ff002991d5c7cfa6d96 (patch)
tree8915b41c6318d49e0577f63e4cce0cad2cdcdaad
parent373f2b276ec87294bb96e5b148972303308f7763 (diff)
Made HTTPD to correctly describe interface by INCLUDE HEADER mechanism.
Changed internal names of http_Auth.h http_Cookies.h http_Steer.h http_Content.h so that HTTPD thorn developers will be required to use this interface, rather than incorrectly explicitly including the source header files. * Protected SString against C++ name mangling * Gave exported functions the HTTP_ prefix * Wrote doc/Content.h * Fixed bug that disabled some steering functionality git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPD/trunk@192 1faa4e14-9dd3-4be0-9f0e-ffe519881164
-rw-r--r--doc/Content.txt97
-rw-r--r--interface.ccl6
-rw-r--r--src/Auth.h (renamed from src/http_Auth.h)6
-rw-r--r--src/Authorisation.c5
-rw-r--r--src/Content.c366
-rw-r--r--src/Content.h48
-rw-r--r--src/Cookies.c49
-rw-r--r--src/Cookies.h (renamed from src/http_Cookies.h)7
-rw-r--r--src/Expression.c98
-rw-r--r--src/Expression.h (renamed from src/http_Expression.h)4
-rw-r--r--src/Groups.c47
-rw-r--r--src/Headers.c99
-rw-r--r--src/Parameters.c231
-rw-r--r--src/Redirect.c19
-rw-r--r--src/Redirect.h (renamed from src/http_Redirect.h)4
-rw-r--r--src/SString.c196
-rw-r--r--src/SString.h86
-rw-r--r--src/SStringHTML.c2
-rw-r--r--src/SStringHTML.h8
-rw-r--r--src/SStringIO.h8
-rw-r--r--src/SStringIO_Namespace.h15
-rw-r--r--src/SString_Namespace.h25
-rw-r--r--src/Server.c48
-rw-r--r--src/Sockets.c55
-rw-r--r--src/Startup.c4
-rw-r--r--src/Steer.c7
-rw-r--r--src/Steer.h (renamed from src/http_Steer.h)8
-rw-r--r--src/Thorns.c99
-rw-r--r--src/http.c132
-rw-r--r--src/httpRequest.h59
-rw-r--r--src/httpSString.h (renamed from src/http_SString.h)7
-rw-r--r--src/http_Content.h43
-rw-r--r--src/http_Request.h91
-rw-r--r--src/httpd.h2
34 files changed, 1192 insertions, 789 deletions
diff --git a/doc/Content.txt b/doc/Content.txt
new file mode 100644
index 0000000..1149ea9
--- /dev/null
+++ b/doc/Content.txt
@@ -0,0 +1,97 @@
+ /*@@
+ @file Content.txt
+ @date 08.04.2004
+ @author Steve White
+ @desc
+ Description of the Content interface
+ @enddesc
+ @version $Header$
+ @@*/
+
+There is an interface for setting HTML page content information, which is
+accessed by including http_Content.h.
+
+
+This provides functions
+
+int HTTP_SendString(httpRequest *request, const String* message);
+
+which sends the string message to HTTP,
+
+void HTTP_SetHeadInfo( String *header);
+
+which copies a string containing typical content of the HEAD element of
+the standard Cactus HTTPD web pages. Particularly, it includes style
+information, but not the title of the page.
+
+void HTTP_SetDoctype( String *header);
+
+which copies a standard DOCTYPE tag into the string. Typical use will
+be to emit this string immediately before the first HTML tag of the
+web page being generated.
+
+int HTTP_SetContentHeaderString(const cGH *cctkGH, int choice, String *mess,
+ const String *menu);
+
+This copies standard Cactus body HTML information into the string mess.
+If choice is nonzero, the information is appropriate for a main page;
+if it is 0, the information is appropriate for non-main pages.
+If the menu argument is non-null, that string will be appended as
+HTML to the standard menus.
+
+int HTTP_SetContentFooterString(const cGH *cctkGH, int choice, String *mess );
+
+This copies standard Cactus footer HTML into the string mess; if choice is
+nonzero, the information is appropriate for the main page.
+
+int HTTP_ContentSendFromFile(httpRequest *request, int filedes);
+
+which emits the entirety of the file referred to by file descriptor filedes
+to HTTP,
+
+int HTTP_ContentLink(const char *URL,
+ const char *name,
+ const char *description,
+ int flags);
+
+which...I don't know what this does.
+
+The functions
+
+int HTTP_ContentHeader(const cGH *cctkGH, int choice, int len, char *mess,
+ const char *menu);
+int HTTP_ContentFooter(const cGH *cctkGH, int choice, int len, char *mess);
+
+are a little dangerous. They are like the corresponding ContentHeader and
+Footer calls above, with the len attribute indicating the length of the
+character buffer mess.
+
+------------------------------------
+Other included functions
+
+int HTTP_SendString(httpRequest *request, const String* message);
+
+
+Example:
+--------
+
+A web page is typically generated in the following sequence.
+The HTTP connection has already been established and saved in the httpRequest
+pointer, and a String instance 'message' has been created.
+
+ 0) HTTP_Send_OK_Header( httpRequest )
+ 1a) HTTP_SetDoctype( message );
+ 1b) HTTP_SendString( httpRequest, message );
+ 2) HTTP_Send( httpRequest, "<html><head>\n" );
+ 3) HTTP_Send( httpRequest, "<title>My Title</title>\n" );
+ 4a) HTTP_HeadInfo( message );
+ 4b) HTTP_SendString( httpRequest, message );
+ 5) HTTP_Send( httpRequest, "</head><body>\n" );
+ 6) HTTP_HeadInfo( httpRequest );
+ 7a) HTTP_SetContentHeaderString(cctkGH, choice, message, menu);
+ 7b) HTTP_SendString( httpRequest, message );
+ 8) Page content
+ 9a) HTTP_SetContentFooterString(cctkGH, choice, message);
+ 9b) HTTP_SendString( httpRequest, message );
+ 10) HTTP_Send( httpRequest, "</body></html>\n" );
+
diff --git a/interface.ccl b/interface.ccl
index b3558e8..e47f5ce 100644
--- a/interface.ccl
+++ b/interface.ccl
@@ -5,4 +5,8 @@ Implements: HTTPD
Inherits: Socket
USES INCLUDE HEADER: SocketUtils.h
-INCLUDE HEADER: HTTPDUtils.h in HTTPDUtils.h
+
+INCLUDE HEADER: Auth.h in http_Auth.h
+INCLUDE HEADER: Cookies.h in http_Cookies.h
+INCLUDE HEADER: Steer.h in http_Steer.h
+INCLUDE HEADER: Content.h in http_Content.h
diff --git a/src/http_Auth.h b/src/Auth.h
index c5bf70e..73129ac 100644
--- a/src/http_Auth.h
+++ b/src/Auth.h
@@ -1,9 +1,9 @@
/*@@
- @header http_Auth.h
+ @header Auth.h
@date Fri Sep 15 13:20:01 2000
@author Tom Goodale
@desc
-
+ Was httpd_Auth.h; still exported by that name.
@enddesc
@version $Header$
@@*/
@@ -11,6 +11,8 @@
#ifndef __HTTP_AUTH_H__
#define __HTTP_AUTH_H__ 1
+#include "httpRequest.h"
+
#ifdef __cplusplus
extern "C"
{
diff --git a/src/Authorisation.c b/src/Authorisation.c
index 6ca76c6..e909eec 100644
--- a/src/Authorisation.c
+++ b/src/Authorisation.c
@@ -25,9 +25,8 @@
#include "util_Hash.h"
#include "util_String.h"
-#include "http_Request.h"
-#include "http_Auth.h"
-#include "http_SString.h"
+#include "httpRequest.h"
+#include "Auth.h"
#include "SString_Namespace.h"
#include "base64.h"
diff --git a/src/Content.c b/src/Content.c
index be751c5..357c04d 100644
--- a/src/Content.c
+++ b/src/Content.c
@@ -29,20 +29,21 @@
#include "util_String.h"
#include "util_Network.h"
-#include "http_Request.h"
+#include "httpRequest.h"
-#include "http_Auth.h"
-#include "http_Steer.h"
-#include "http_Cookies.h"
+#include "Auth.h"
+#include "Steer.h"
+#include "Cookies.h"
-#include "http_Content.h"
+#include "Content.h"
#include "cctk_Arguments.h"
#include "cctk_Parameters.h"
-#include "http_SString.h"
#include "SString_Namespace.h"
+#define EMPTYSTRING {'\0'}
+
static const char *rcsid = "$Header$";
CCTK_FILEVERSION(CactusConnect_HTTPD_Content_c)
@@ -113,7 +114,44 @@ static const char *notauthorized_page =
/********************************************************************
********************* External Routines **********************
********************************************************************/
+int
+HTTP_SendString( httpRequest *request, const String * message )
+{
+ return HTTP_Send(request, GetBuffer( message ) );
+}
+
+void
+HTTP_Send_OK_Header( httpRequest *request )
+{
+ /* Status message */
+ HTTP_Send(request, "HTTP/1.0 200 OK\r\n");
+
+ /* Content-Type */
+ HTTP_Send(request, "Content-Type: text/html\r\n");
+ HTTP_Send(request, "\r\n");
+}
+void
+SSUtil_SplitFilename(const char **dir,const char **file, const String *message)
+{
+ Util_SplitFilename((char **)dir,(char **)file,GetBuffer(message));
+}
+
+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 );
+}
/*@@
@routine HTTP_ContentWork
@date Sat Sep 16 15:22:59 2000
@@ -270,6 +308,30 @@ static int CompareStrings(const void *string1, const void *string2)
return Util_StrCmpi(*(const char * const *)string1, *(const char * const *)string2);
}
+ /*@@
+ @routine TimeListItem
+ @date 10.04.2004
+ @author Steve White
+ @desc
+ Reduce repetition in MainPage below
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+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" );
+}
+
/******************************************************************************
***************************** Main Page **************************************
******************************************************************************/
@@ -293,60 +355,6 @@ 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)
{
@@ -367,18 +375,18 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data)
/* avoid compiler warning about unused parameter */
data = data;
- SendHTTP_OK_Header( request );
+ HTTP_Send_OK_Header( request );
- SetHTML_Doctype( message );
- Send_HTTP_String(request, message);
+ HTTP_SetDoctype( message );
+ HTTP_SendString(request, message);
/* Start the page */
- 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 );
+ HTTP_Send(request, "<html>\n<head>\n");
+ HTTP_Send(request, "<title>Running CACTUS Status Information</title>\n");
+ HTTP_SetHeadInfo( message);
+ HTTP_SendString(request, message );
- Send_HTTP(request, "</head>\n<body>\n");
+ HTTP_Send(request, "</head>\n<body>\n");
/* Write out the main header part */
/* LIST COMPILED THORNS */
@@ -410,10 +418,10 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data)
}
}
- SetHTML_ContentHeader(cctkGH, 0, message, menu);
- Send_HTTP_String(request, message );
+ HTTP_SetContentHeaderString(cctkGH, 0, message, menu);
+ HTTP_SendString(request, message );
- Send_HTTP(request,
+ HTTP_Send(request,
"<div class=\"banner\">\n"
"<img src=\"/Images/wwwcactuscodeorg.jpg\""
" alt=\"Cactus\" /></div>\n");
@@ -444,9 +452,9 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data)
"</table>\n"
"</div>\n");
- Send_HTTP_String(request, message );
+ HTTP_SendString(request, message );
- Send_HTTP(request,
+ HTTP_Send(request,
"<table cellpadding=\"10\">\n"
"<tr>\n"
"<td>\n");
@@ -471,10 +479,10 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data)
}
ConcatCString(message, "</dl>\n" );
- Send_HTTP_String(request, message );
+ HTTP_SendString(request, message );
}
- Send_HTTP(request,
+ HTTP_Send(request,
"</td>\n"
"<td>\n");
@@ -497,7 +505,7 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message,
"</span></li>\n");
- Send_HTTP_String(request, message );
+ HTTP_SendString(request, message );
seconds = CCTK_RunTime();
minutes = seconds/60;
@@ -550,13 +558,13 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data)
}
ConcatCString(message, "</ul></li>\n<li> Parameter filename <span class=\"parfile\">" );
- Send_HTTP_String(request, message );
+ HTTP_SendString(request, message );
CCTK_GetParameterFilenameString(message);
SSUtil_SplitFilename(&dir,&file,message);
- Send_HTTP(request, file);
+ HTTP_Send(request, file);
- Send_HTTP(request, "</span></li>\n");
+ HTTP_Send(request, "</span></li>\n");
if (cctkGH && cctkGH->cctk_iteration)
{
@@ -565,7 +573,7 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatDouble(message, CCTK_RunTime()/(double)cctkGH->cctk_iteration );
ConcatCString(message, "</span> seconds</li></ul></li>\n");
- Send_HTTP_String(request, message );
+ HTTP_SendString(request, message );
SetToCString(message, "<li>Estimated time to completion:\n<ul>");
@@ -631,7 +639,7 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message, "</ul></li>\n");
- Send_HTTP_String(request, message );
+ HTTP_SendString(request, message );
}
Util_GetHostName(host,HOSTLENGTH);
@@ -653,7 +661,7 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message, host);
ConcatCString(message, "</span></li>\n");
}
- Send_HTTP_String(request, message );
+ HTTP_SendString(request, message );
user = getenv ("USER");
if (user)
@@ -661,18 +669,18 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data)
SetToCString(message, " <li> Started by <span class=\"hilite\">");
ConcatCString(message, user);
ConcatCString(message, "</span></li>\n");
- Send_HTTP_String(request, message );
+ HTTP_SendString(request, message );
}
- Send_HTTP(request, "</ul>\n");
+ HTTP_Send(request, "</ul>\n");
/* Finish table started by blurb */
- Send_HTTP(request, "</td>\n</tr>\n</table>\n\n");
+ HTTP_Send(request, "</td>\n</tr>\n</table>\n\n");
/* Write out the footer part. */
- SetHTML_ContentFooter(cctkGH, 0, message);
- retval = Send_HTTP_String(request, message );
+ HTTP_SetContentFooterString(cctkGH, 0, message);
+ retval = HTTP_SendString(request, message );
String_Delete( message );
String_Delete( title );
@@ -767,7 +775,7 @@ static int ShowStaticPage(const cGH *cctkGH, httpRequest *request, void *data)
struct httpStaticPage *page = (struct httpStaticPage *)data;
String *message = String_New();
- Send_HTTP(request, "HTTP/1.0 200 OK\r\n");
+ HTTP_Send(request, "HTTP/1.0 200 OK\r\n");
SetToCString(message, "Content-Length: ");
ConcatDecimal(message, page->length );
@@ -775,7 +783,7 @@ static int ShowStaticPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message, page->mime_type );
ConcatCString(message, "\r\n\r\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
retval = HTTP_Write(request, page->page, page->length);
@@ -815,52 +823,52 @@ static int ControlPage(const cGH *cctkGH, httpRequest *request, void *data)
if(!notauthorised)
{
/* Ok the person is authorised. */
- if(request->n_arguments == 0)
+ if(HTTP_Num_Arguments( request ) == 0)
{
String *message = String_New();
/* No arguments, so just display the page */
- Send_HTTP(request,"HTTP/1.0 200 Ok\r\n");
+ HTTP_Send(request,"HTTP/1.0 200 Ok\r\n");
- Send_HTTP(request,"WWW-Authenticate: Basic realm=\"Cactus Control\"\r\n");
+ HTTP_Send(request,"WWW-Authenticate: Basic realm=\"Cactus Control\"\r\n");
HTTP_CookieSend(request,"user", thisuser, "/", NULL, NULL, 0);
- Send_HTTP(request,"Content-Type: text/html\r\n\r\n");
+ HTTP_Send(request,"Content-Type: text/html\r\n\r\n");
- SetHTML_Doctype( message );
- Send_HTTP_String(request, message);
+ HTTP_SetDoctype( message );
+ HTTP_SendString(request, message);
/* Start the page */
- Send_HTTP(request, "<html><head>\n");
- Send_HTTP(request, "<title>Cactus Control and Status Page</title>\n");
+ HTTP_Send(request, "<html><head>\n");
+ HTTP_Send(request, "<title>Cactus Control and Status Page</title>\n");
- SetHTML_HeadHeader( message);
- Send_HTTP_String(request, message );
+ HTTP_SetHeadInfo( message);
+ HTTP_SendString(request, message );
- Send_HTTP(request, "</head>\n<body>\n");
+ HTTP_Send(request, "</head>\n<body>\n");
- SetHTML_ContentHeader(cctkGH, 0,message,NULL);
+ HTTP_SetContentHeaderString(cctkGH, 0,message,NULL);
ConcatCString(message, "<h1>Control and Status Page</h1>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
- Send_HTTP(request,
+ HTTP_Send(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");
- Send_HTTP(request,
+ HTTP_Send(request,
"<div class=\"centered\">\n"
"<form action=\"/control.html\" method=\"get\">\n");
- Send_HTTP(request,
+ HTTP_Send(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");
- Send_HTTP(request,
+ HTTP_Send(request,
"<table class=\"controls\" cellspacing=\"5\" cellpadding=\"5\">\n"
"<tr>\n");
@@ -869,24 +877,24 @@ static int ControlPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message, pause ? "checked=\"checked\"" : "");
ConcatCString(message,
" value=\"PAUSE\" /> PAUSE</td>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, 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);
+ HTTP_SendString(request, message);
- Send_HTTP(request,
+ HTTP_Send(request,
"<td><input type=\"radio\" name=\"runstate\" "
"value=\"TERMINATE\" /> TERMINATE</td>\n");
- Send_HTTP(request,
+ HTTP_Send(request,
"<td><input type=\"submit\" name=\"step\" "
"value=\"STEP\" /></td>\n");
- Send_HTTP(request,
+ HTTP_Send(request,
"</tr></table>\n"
"<table>\n"
"<tr><td><input type=\"submit\" value=\"OK\" /></td>\n"
@@ -894,7 +902,7 @@ static int ControlPage(const cGH *cctkGH, httpRequest *request, void *data)
"</tr>\n"
"</table>\n");
- Send_HTTP(request,
+ HTTP_Send(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"
@@ -941,16 +949,16 @@ static int ControlPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message,"</table>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
- Send_HTTP(request,
+ HTTP_Send(request,
"</form>\n"
"</div>\n");
/* Write out the footer part. */
- SetHTML_ContentFooter(cctkGH, 0, message);
- Send_HTTP_String(request, message);
+ HTTP_SetContentFooterString(cctkGH, 0, message);
+ HTTP_SendString(request, message);
String_Delete( message );
}
@@ -963,15 +971,15 @@ static int ControlPage(const cGH *cctkGH, httpRequest *request, void *data)
else
{
/* Not authorised */
- Send_HTTP(request,"HTTP/1.0 401 Unauthorized\r\n");
+ HTTP_Send(request,"HTTP/1.0 401 Unauthorized\r\n");
- Send_HTTP(request,"WWW-Authenticate: Basic realm=\"Cactus Control\"\r\n");
+ HTTP_Send(request,"WWW-Authenticate: Basic realm=\"Cactus Control\"\r\n");
HTTP_CookieCancel(request,"user", "/");
- Send_HTTP(request,"Content-Type: text/html\r\n\r\n");
+ HTTP_Send(request,"Content-Type: text/html\r\n\r\n");
- Send_HTTP(request, notauthorized_page);
+ HTTP_Send(request, notauthorized_page);
}
return 0;
@@ -995,10 +1003,7 @@ static int ControlSet(const cGH *cctkGH, httpRequest *request)
{
DECLARE_CCTK_PARAMETERS
String *message = String_New();
- const char *value = NULL;
-
- /* What is the runstate ? */
- value = HTTP_ArgumentValue(request,"runstate");
+ const char *value = HTTP_ArgumentValue(request,"runstate");
if(value)
{
@@ -1131,8 +1136,8 @@ static int ControlSet(const cGH *cctkGH, httpRequest *request)
* of text rendered at the bottom. */
/* Status message */
- if(request->http_major_version < 1 ||
- (request->http_major_version == 1 && request->http_minor_version < 1))
+ if(HTTP_Major_Version( request ) < 1 ||
+ (HTTP_Major_Version( request ) == 1 && HTTP_Minor_Version( request ) < 1))
{
/* Older browsers don't understand 303 */
SetToCString(message,"HTTP/1.0 302 Found\r\n");
@@ -1144,7 +1149,7 @@ static int ControlSet(const cGH *cctkGH, httpRequest *request)
ConcatCString(message, "Location: /control.html\r\n\r\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
String_Delete( message );
@@ -1169,27 +1174,27 @@ static int ControlTerminationPage(const cGH *cctkGH, httpRequest *request)
{
int retval = -1;
String *message = String_New();
- SendHTTP_OK_Header( request );
+ HTTP_Send_OK_Header( request );
- SetHTML_Doctype( message );
- Send_HTTP_String(request, message);
+ HTTP_SetDoctype( message );
+ HTTP_SendString(request, message);
/* Start the page */
- Send_HTTP(request, "<html><head>\n");
- Send_HTTP(request, "<title>Running CACTUS Status Information : Terminated</title>\n");
+ HTTP_Send(request, "<html><head>\n");
+ HTTP_Send(request, "<title>Running CACTUS Status Information : Terminated</title>\n");
- SetHTML_HeadHeader( message);
- Send_HTTP_String(request, message );
+ HTTP_SetHeadInfo( message);
+ HTTP_SendString(request, message );
- Send_HTTP(request, "</head>\n<body>\n");
+ HTTP_Send(request, "</head>\n<body>\n");
/* Write out the main header part */
- SetHTML_ContentHeader(cctkGH,1,message,NULL);
- Send_HTTP_String(request, message);
+ HTTP_SetContentHeaderString(cctkGH,1,message,NULL);
+ HTTP_SendString(request, message);
- Send_HTTP(request, "<h1>Simulation Home Page</h1>\n");
+ HTTP_Send(request, "<h1>Simulation Home Page</h1>\n");
/* Some blurb */
- Send_HTTP(request,
+ HTTP_Send(request,
"<div class=\"centered\">\n"
"<table cellspacing=\"5\" cellpadding=\"5\" border=\"0\"><tr><td>\n"
"<h3>Simulation web server:</h3>\n"
@@ -1201,7 +1206,6 @@ static int ControlTerminationPage(const cGH *cctkGH, httpRequest *request)
"additional features available, such as the viewing and \n"
"downloading of output files</p>\n");
-
/* CONFIGURATION DETAILS */
SetToCString(message,
@@ -1213,7 +1217,7 @@ static int ControlTerminationPage(const cGH *cctkGH, httpRequest *request)
"<li>Flesh compiled on <span class=\"hilite\"> __DATE__ </span>\n"
"at <span class=\"hilite\"> __TIME__ </span></li>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
if (cctkGH)
{
@@ -1227,16 +1231,16 @@ static int ControlTerminationPage(const cGH *cctkGH, httpRequest *request)
ConcatDecimal( message, CCTK_nProcs(cctkGH) );
ConcatCString( message, " CPUs</li>\n");
}
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
}
- Send_HTTP(request,"</ul>\n");
+ HTTP_Send(request,"</ul>\n");
/************************************************************************/
/* NEW COLUMN */
- Send_HTTP(request, "</td><td>");
+ HTTP_Send(request, "</td><td>");
/************************************************************************/
@@ -1260,10 +1264,10 @@ static int ControlTerminationPage(const cGH *cctkGH, httpRequest *request)
SetToCString(message, "<li>Current cactus state is unknown</li>\n");
}
- Send_HTTP_String(request, message);
- Send_HTTP(request, "<li>This Cactus run is over.</li>\n");
+ HTTP_SendString(request, message);
+ HTTP_Send(request, "<li>This Cactus run is over.</li>\n");
- Send_HTTP(request, "</ul>");
+ HTTP_Send(request, "</ul>");
/* LIST COMPILED THORNS */
{
@@ -1306,16 +1310,16 @@ static int ControlTerminationPage(const cGH *cctkGH, httpRequest *request)
free(thorns);
}
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
/* Finish table started by blurb */
- Send_HTTP(request, "</td></tr></table>\n");
+ HTTP_Send(request, "</td></tr></table>\n");
/* Write out the footer part. */
- SetHTML_ContentFooter(cctkGH,0,message);
- retval = Send_HTTP_String(request, message);
+ HTTP_SetContentFooterString(cctkGH,0,message);
+ retval = HTTP_SendString(request, message);
String_Delete( message );
return retval;
@@ -1375,20 +1379,20 @@ static int AboutPage(const cGH *cctkGH, httpRequest *request, void *data)
/* avoid compiler warning about unused parameter */
data = data;
- SendHTTP_OK_Header( request );
+ HTTP_Send_OK_Header( request );
- SetHTML_Doctype( message );
- Send_HTTP_String(request, message);
+ HTTP_SetDoctype( message );
+ HTTP_SendString(request, message);
/* Start the page */
SetToCString(message, "<html><head>\n<title>About Cactus Server</title>\n");
- SetHTML_HeadHeader( message);
- Send_HTTP_String(request, message );
+ HTTP_SetHeadInfo( message);
+ HTTP_SendString(request, message );
- Send_HTTP(request, "</head>\n<body>\n");
- SetHTML_ContentHeader(cctkGH,0,message,NULL);
- Send_HTTP_String(request, message);
+ HTTP_Send(request, "</head>\n<body>\n");
+ HTTP_SetContentHeaderString(cctkGH,0,message,NULL);
+ HTTP_SendString(request, message);
- Send_HTTP(request, "<h1>About this Web Server</h1>\n");
+ HTTP_Send(request, "<h1>About this Web Server</h1>\n");
SetToCString(message, "<p>These web pages are served by a simulation \n"
"which is using the Cactus Code and Computational ToolKit, \n"
@@ -1403,18 +1407,18 @@ static int AboutPage(const cGH *cctkGH, httpRequest *request, void *data)
"and implemented by Tom Goodale, based on the original idea and \n"
"implementation by Werner Benger.</p>\n");
- retval = Send_HTTP_String(request, message);
+ retval = HTTP_SendString(request, message);
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 = Send_HTTP_String(request, message);
+ retval = HTTP_SendString(request, message);
/* Write out the footer part. */
- SetHTML_ContentFooter(cctkGH,0,message);
- retval = Send_HTTP_String(request, message);
+ HTTP_SetContentFooterString(cctkGH,0,message);
+ retval = HTTP_SendString(request, message);
String_Delete( message);
return retval;
@@ -1447,7 +1451,7 @@ static int CookieTestPage(const cGH *cctkGH, httpRequest *request, void *data)
data = data;
/* Status message */
- Send_HTTP(request,"HTTP/1.0 200 OK\r\n");
+ HTTP_Send(request,"HTTP/1.0 200 OK\r\n");
/* Cookie */
HTTP_CookieSend(request, "user1", "foobar4", NULL,NULL,NULL,0);
@@ -1458,23 +1462,23 @@ static int CookieTestPage(const cGH *cctkGH, httpRequest *request, void *data)
HTTP_CookieSend(request, "user4", "foobar1", NULL,NULL,NULL,0);
- Send_HTTP(request,"Content-Type: text/html\r\n\r\n");
+ HTTP_Send(request,"Content-Type: text/html\r\n\r\n");
- SetHTML_Doctype( message );
- Send_HTTP_String(request, message);
+ HTTP_SetDoctype( message );
+ HTTP_SendString(request, message);
/* Start the page */
- Send_HTTP(request, "<html><head><title>Cookie Test</title>\n");
- SetHTML_HeadHeader( message);
- Send_HTTP_String(request, message );
+ HTTP_Send(request, "<html><head><title>Cookie Test</title>\n");
+ HTTP_SetHeadInfo( message);
+ HTTP_SendString(request, message );
- Send_HTTP(request, "</head>\n<body>\n");
+ HTTP_Send(request, "</head>\n<body>\n");
- SetHTML_ContentHeader(cctkGH,0,message,NULL);
- Send_HTTP_String(request, message);
+ HTTP_SetContentHeaderString(cctkGH,0,message,NULL);
+ HTTP_SendString(request, message);
- Send_HTTP(request, "<h1>Cookie Test</h1>\n");
+ HTTP_Send(request, "<h1>Cookie Test</h1>\n");
- Send_HTTP(request, "<div class=\"centered\">");
+ HTTP_Send(request, "<div class=\"centered\">");
value = HTTP_HeaderValue(request, "Cookie");
@@ -1482,7 +1486,7 @@ static int CookieTestPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message, value);
ConcatCString(message, "'</p>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
value2 = HTTP_CookieGet(request,"user3");
@@ -1492,14 +1496,14 @@ static int CookieTestPage(const cGH *cctkGH, httpRequest *request, void *data)
free(value2);
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
- Send_HTTP(request,"</div>\n");
+ HTTP_Send(request,"</div>\n");
/* Write out the footer part. */
- SetHTML_ContentFooter(cctkGH,0,message);
- retval = Send_HTTP_String(request, message);
+ HTTP_SetContentFooterString(cctkGH,0,message);
+ retval = HTTP_SendString(request, message);
String_Delete( message );
return retval;
diff --git a/src/Content.h b/src/Content.h
new file mode 100644
index 0000000..d979ef7
--- /dev/null
+++ b/src/Content.h
@@ -0,0 +1,48 @@
+ /*@@
+ @header Content.h
+ @date Sun Sep 17 14:19:23 2000
+ @author Tom Goodale
+ @desc
+ Routines exported by the Content stuff. Was httpd_Content.h; still
+ exported by that name.
+ @enddesc
+ @version $Header$
+ @@*/
+
+#ifndef __HTTP_CONTENT_H__
+#define __HTTP_CONTENT_H__ 1
+
+#define HTTP_QUICKLINK 1
+
+#include "SString.h"
+#include "httpRequest.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+int HTTP_ContentLink(const char *URL,
+ const char *name,
+ const char *description,
+ int flags);
+
+int HTTP_ContentSendFromFile(httpRequest *request, int filedes);
+
+int HTTP_ContentHeader(const cGH *cctkGH, int choice, int len, char *mess,
+ const char *menu);
+int HTTP_ContentFooter(const cGH *cctkGH, int choice, int len, char *mess);
+
+int HTTP_SetContentHeaderString(const cGH *cctkGH, int choice, String *mess,
+ const String *menu);
+int HTTP_SetContentFooterString(const cGH *cctkGH, int choice, String *mess);
+
+void HTTP_SetHeadInfo( String *header);
+
+void HTTP_SetDoctype( String *header);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __HTTP_CONENT_H__ */
diff --git a/src/Cookies.c b/src/Cookies.c
index 766d942..c153608 100644
--- a/src/Cookies.c
+++ b/src/Cookies.c
@@ -11,13 +11,11 @@
#include "cctk.h"
#include <stdlib.h>
-#include <string.h>
#include "util_String.h"
-#include "http_Request.h"
-#include "http_Cookies.h"
-#include "http_SString.h"
+#include "httpRequest.h"
+#include "Cookies.h"
#include "SString_Namespace.h"
static const char *rcsid = "$Header$";
@@ -97,7 +95,7 @@ int HTTP_CookieSend(httpRequest *request,
ConcatCString(message, "\r\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
String_Delete( message );
return 0;
@@ -138,7 +136,7 @@ int HTTP_CookieCancel(httpRequest *request,
ConcatCString(message, "; expires Sun Sep 17 21:57:45 CEST 2000");
ConcatCString(message, "\r\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
String_Delete( message );
return 0;
@@ -158,38 +156,39 @@ int HTTP_CookieCancel(httpRequest *request,
@endhistory
@@*/
-char *HTTP_CookieGet(httpRequest *request,
- const char *name)
+
+char *HTTP_CookieGet(httpRequest *request, const char *cookie_name)
{
char *retval = NULL;
+ const String *COOKIE = String_Make("cookie");
+ String *header = String_New();
/* Get the cookie header */
- const char *header = HTTP_HeaderValue(request,"Cookie");
-
- if(header)
+ if( HTTP_GetHeaderValueString( request, COOKIE, header ) )
{
- char *copy = Util_Strdup(header);
- char *position = copy;
+ String *name = String_Make( cookie_name );
+ String *value = String_New();
+ size_t index = 0;
/* Search for name=value */
- while((position = strstr(position, name)) != NULL)
+ while( SetNextToken( header, value, ";", index ) )
{
- position += strlen(name);
- if(*position == '=')
+ size_t position = 0;
+ if( FindStringFrom( value, name, &position )
+ && position == 0 )
{
- char *start = position+1;
-
- position=strstr(start, ";");
-
- if(position)
+ if( FindCharFrom( value, '=', &position )
+ && position == Length( name ) )
{
- *position = 0;
+ TrimLeading( value, position + 1 );
+ retval = Util_Strdup( GetBuffer( value ) );
}
- retval = Util_Strdup(start);
- break;
+ break;
}
}
- free(copy);
+ String_Delete(name);
+ String_Delete(value);
}
+ String_Delete(header);
return retval;
}
diff --git a/src/http_Cookies.h b/src/Cookies.h
index 5179227..2b6c43d 100644
--- a/src/http_Cookies.h
+++ b/src/Cookies.h
@@ -1,9 +1,10 @@
/*@@
- @header http_Cookies.h
+ @header Cookies.h
@date Mon Sep 18 22:40:06 2000
@author Tom Goodale
@desc
- Functions to manipulate cookies.
+ Functions to manipulate cookies. Was http_Cookies.h; still exported by
+ that name
@enddesc
@version $Header$
@@*/
@@ -11,6 +12,8 @@
#ifndef __HTTP_COOKIES_H__
#define __HTTP_COOKIES_H__ 1
+#include "httpRequest.h"
+
#ifdef __cplusplus
extern "C"
{
diff --git a/src/Expression.c b/src/Expression.c
index 4065d90..174698e 100644
--- a/src/Expression.c
+++ b/src/Expression.c
@@ -16,7 +16,7 @@
#include <stdlib.h>
#include <string.h>
-#include "http_Expression.h"
+#include "Expression.h"
static const char *rcsid = "$Header$";
@@ -89,26 +89,19 @@ static void FreeTokens(pToken *list);
@@*/
char *HTTP_ExpressionParse(const char *expression)
{
- pToken *list;
- pToken *temp;
-
- char *buffer;
- int buffer_length;
-
- buffer_length = INITIAL_BUFFER_LENGTH;
-
- buffer = (char *)malloc(buffer_length);
+ int buffer_length = INITIAL_BUFFER_LENGTH;
+ char *buffer = (char *)malloc(buffer_length);
if(buffer)
{
/* Split the list into tokens */
- list = Tokenise(expression);
+ pToken *list = Tokenise(expression);
+ pToken *temp = list;
#ifdef TEST_HTTP_EVALUATE
printtokens(list);
#endif
- temp = list;
/* Convert the list into a string in RPN order */
buffer = RPParse(&temp, buffer, &buffer_length);
@@ -138,14 +131,10 @@ double HTTP_ExpressionEvaluate(char *buffer,
double (*eval)(const char *, void *),
void *data)
{
- char *first;
- char *token;
double stack[MAX_STACK_SIZE];
- int stackpointer;
-
-
- first = buffer;
- stackpointer = 0;
+ int stackpointer = 0;
+ char *first = buffer;
+ char *token;
/* Tokens are seperated by @ signs */
while((token = strtok(first,"@")))
@@ -197,27 +186,19 @@ double HTTP_ExpressionEvaluate(char *buffer,
@@*/
static pToken *Tokenise(const char *expression)
{
- pToken *start;
- pToken *current;
- pToken *new;
-
- const char *tokenstart;
- const char *tokenend;
- const char *position;
-
- start = NULL;
- current = NULL;
+ pToken *start = NULL;
+ pToken *current = NULL;
+ pToken *new = NULL;
- tokenstart = expression;
+ const char *tokenstart = expression;
while(*tokenstart)
{
/* Remove leading whitespace */
for(; *tokenstart == ' ' || *tokenstart == '\t'; tokenstart++);
- tokenend = NULL;
-
- position = tokenstart;
+ const char *tokenend = NULL;
+ const char *position = tokenstart;
for(position=tokenstart; *position && *(position+1); position++)
{
@@ -343,19 +324,11 @@ static pToken *Tokenise(const char *expression)
static char *RPParse(pToken **current, char *stack, int *stacklength)
{
- char *retval;
- pToken *this;
- char *operator;
+ char *retval = stack;
+ pToken *this = *current;
+ char *operator = NULL;
+ int numops = 0;
char *opstack[MAX_OPS];
- int numops;
- int precedence;
-
- numops = 0;
- this = *current;
-
- retval = stack;
-
- operator = NULL;
for(this = *current; this && strcmp(this->token,")"); this = this->next)
{
@@ -379,7 +352,7 @@ static char *RPParse(pToken **current, char *stack, int *stacklength)
if(operator)
{
/* We already have an operator */
- precedence = cmpprecendence(operator, this->token);
+ int precedence = cmpprecendence(operator, this->token);
if(precedence > 0)
{
@@ -446,7 +419,7 @@ static char *RPParse(pToken **current, char *stack, int *stacklength)
@@*/
static double Evaluate(double val1, const char *operator, double val2)
{
- double retval;
+ double retval = 0.0;
if(!strcmp(operator, "+"))
{
@@ -495,7 +468,6 @@ static double Evaluate(double val1, const char *operator, double val2)
else
{
fprintf(stderr, "Unknown operation %s", operator);
- retval = 0;
}
return retval;
@@ -517,14 +489,14 @@ static double Evaluate(double val1, const char *operator, double val2)
@@*/
void FreeTokens(pToken *list)
{
- pToken *token;
- pToken *next;
+ pToken *token = list;
- for(token = list; token; token = next)
+ while( token )
{
- next = token->next;
+ pToken *next = token->next;
free(token->token);
free(token);
+ token = next;
}
}
@@ -545,7 +517,7 @@ void FreeTokens(pToken *list)
@@*/
static int isoperator(const char *token)
{
- int retval;
+ int retval = 0;
if(!strcmp(token, "+") ||
!strcmp(token, "-") ||
@@ -561,10 +533,6 @@ static int isoperator(const char *token)
{
retval = 1;
}
- else
- {
- retval = 0;
- }
return retval;
}
@@ -585,7 +553,6 @@ static int isoperator(const char *token)
@@*/
static int cmpprecendence(const char *op1, const char *op2)
{
- int retval;
const char *op;
int op1prec;
int op2prec;
@@ -628,9 +595,8 @@ static int cmpprecendence(const char *op1, const char *op2)
}
/* Now see which has the higher precedence */
- retval = op2prec-op1prec;
- return retval;
+ return op2prec-op1prec;
}
/*@@
@@ -649,11 +615,7 @@ static int cmpprecendence(const char *op1, const char *op2)
@@*/
static pToken *newtoken(const char *tokenstart, const char *tokenend)
{
- pToken *this;
- const char *position;
- char *newpos;
-
- this = (pToken *)malloc(sizeof(pToken *));
+ pToken *this = (pToken *)malloc(sizeof(pToken *));
if(this)
{
@@ -663,6 +625,8 @@ static pToken *newtoken(const char *tokenstart, const char *tokenend)
this->token = (char *)malloc(tokenend-tokenstart+2);
if(this->token)
{
+ const char *position;
+ char *newpos;
for(position=tokenstart, newpos=this->token;
position <= tokenend;
position++, newpos++)
@@ -813,9 +777,7 @@ static void printstack(char *stack)
double evaluator(const char *token, void *data)
{
- double retval;
-
- retval = strtod(token, NULL);
+ double retval = strtod(token, NULL);
/* fprintf(stderr, "Evaluated '%s' to %f\n", token,retval); */
diff --git a/src/http_Expression.h b/src/Expression.h
index 57c3a72..5b734ea 100644
--- a/src/http_Expression.h
+++ b/src/Expression.h
@@ -1,9 +1,9 @@
/*@@
- @header http_Expression.h
+ @header Expression.h
@date Tue Sep 19 22:02:45 2000
@author Tom Goodale
@desc
- Header for expression stuff.
+ Header for expression stuff. Was http_Expression.h
@enddesc
@version $Header$
@@*/
diff --git a/src/Groups.c b/src/Groups.c
index 3df8f40..b16ff8a 100644
--- a/src/Groups.c
+++ b/src/Groups.c
@@ -16,10 +16,9 @@
#include "util_String.h"
-#include "http_Request.h"
-#include "http_Content.h"
+#include "httpRequest.h"
+#include "Content.h"
-#include "http_SString.h"
#include "SString_Namespace.h"
static const char *rcsid = "$Header$";
@@ -107,29 +106,29 @@ static int GroupsPage(const cGH *cctkGH, httpRequest *request, void *data)
/* avoid compiler warning about unused parameter */
data = data;
- SendHTTP_OK_Header( request );
+ HTTP_Send_OK_Header( request );
/* Start the page */
- SetHTML_Doctype( message );
- Send_HTTP_String(request, message);
+ HTTP_SetDoctype( message );
+ HTTP_SendString(request, message);
- Send_HTTP(request,"<html><head>\n");
- Send_HTTP(request,"<title>Cactus Simulation Group Information</title>\n");
+ HTTP_Send(request,"<html><head>\n");
+ HTTP_Send(request,"<title>Cactus Simulation Group Information</title>\n");
- SetHTML_HeadHeader( message);
- Send_HTTP_String(request, message );
+ HTTP_SetHeadInfo( message);
+ HTTP_SendString(request, message );
- Send_HTTP(request,"</head>\n<body>\n");
+ HTTP_Send(request,"</head>\n<body>\n");
/* HTTP_Write out the header part. */
- SetHTML_ContentHeader(cctkGH,0,message,NULL);
+ HTTP_SetContentHeaderString(cctkGH,0,message,NULL);
- retval = Send_HTTP_String(request, message);
+ retval = HTTP_SendString(request, message);
ngroups = CCTK_NumGroups();
- retval = Send_HTTP(request, "<h1>Groups and Grid Variables</h1>\n"
+ retval = HTTP_Send(request, "<h1>Groups and Grid Variables</h1>\n"
"<p>These pages describe the grid variables and groups \n"
"active in this simulation.</p>\n");
@@ -148,11 +147,11 @@ static int GroupsPage(const cGH *cctkGH, httpRequest *request, void *data)
"assigned are written in <span class=\"hilite\">red</span>. \n"
"The numbers in square brackets are the group and variable indices."
"</p>\n");
- retval = Send_HTTP_String(request, message);
+ retval = HTTP_SendString(request, message);
- retval = Send_HTTP(request,"<form action=\"/Groups.html\" method=\"get\">\n");
+ retval = HTTP_Send(request,"<form action=\"/Groups.html\" method=\"get\">\n");
- retval = Send_HTTP(request,"<div class=\"centered\">\n"
+ retval = HTTP_Send(request,"<div class=\"centered\">\n"
"<table class=\"groups\" width=\"100%\" cellpadding=\"5\" "
"cellspacing=\"5\">\n"
"<tr><th>Groups</th><th>Group Properties</th>"
@@ -182,7 +181,7 @@ static int GroupsPage(const cGH *cctkGH, httpRequest *request, void *data)
free(groupname);
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
/* Group Description */
@@ -215,10 +214,10 @@ static int GroupsPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message, " <br />\nTimelevels ");
ConcatDecimal(message, gdata.numtimelevels);
}
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
}
- Send_HTTP(request,"</td>");
+ HTTP_Send(request,"</td>");
nvars = CCTK_NumVarsInGroupI(i);
SetToCString(message,"<td>");
@@ -231,16 +230,16 @@ static int GroupsPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message, "<br />\n" );
}
ConcatCString(message,"</td></tr>");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
}
- Send_HTTP(request,"</table></div></form>\n");
+ HTTP_Send(request,"</table></div></form>\n");
/* Write out the footer part. */
- SetHTML_ContentFooter(cctkGH,0,message);
- retval = Send_HTTP_String(request, message);
+ HTTP_SetContentFooterString(cctkGH,0,message);
+ retval = HTTP_SendString(request, message);
String_Delete( message );
diff --git a/src/Headers.c b/src/Headers.c
index 25534d0..97b50e9 100644
--- a/src/Headers.c
+++ b/src/Headers.c
@@ -12,8 +12,6 @@
#include "util_String.h"
-#include <string.h>
-
#include "SString_Namespace.h"
#define EMPTYSTRING { '\0' }
@@ -113,11 +111,11 @@ static const char * cactus_doctype =
********************* External Routines **********************
********************************************************************/
-void SetHTML_HeadHeader( String *header)
+void HTTP_SetHeadInfo( String *header)
{
SetToCString( header, cactus_styles );
}
-void SetHTML_Doctype( String *header)
+void HTTP_SetDoctype( String *header)
{
SetToCString( header, cactus_doctype );
}
@@ -137,7 +135,7 @@ void SetHTML_Doctype( String *header)
@@*/
extern void CCTK_GetRunTitleString( String *s );
-int SetHTML_ContentHeader(const cGH *GH, int choice,
+int HTTP_SetContentHeaderString(const cGH *GH, int choice,
String *header, const String *menu)
{
String *title = String_New();
@@ -153,11 +151,10 @@ int SetHTML_ContentHeader(const cGH *GH, int choice,
if (choice == 0)
{
- ConcatCString( header,
- "<table cellpadding=\"10\" width=\"100%\" border=\"0\">\n"
- "<tr>\n"
- "<td class=\"menu\" valign=\"top\">\n"
- "<h2><a href=\"/\">Master Run Page</a></h2>\n");
+ ConcatCString( header, "<table cellpadding=\"10\" width=\"100%\">\n"
+ "<tr>\n"
+ "<td class=\"menu\" valign=\"top\">\n"
+ "<h2><a href=\"/\">Master Run Page</a></h2>\n");
}
if(ContentLinks)
@@ -184,34 +181,26 @@ int SetHTML_ContentHeader(const cGH *GH, int choice,
Util_CurrentTime(sizeof(currenttime),currenttime);
/* Build the header */
- ConcatCString( header,
- "\n"
- "<h3>Environment:</h3>\n"
- "Time: ");
+ ConcatCString( header, "\n"
+ "<h3>Environment:</h3>\n"
+ "Time: ");
ConcatCString( header, currenttime );
- ConcatCString( header,
- "<br />\n"
- "Date: " );
+ ConcatCString( header, "<br />\n"
+ "Date: " );
ConcatCString( header, currentdate );
- ConcatCString( header,
- "<br />\n" );
- ConcatCString( header,
- "<h3>Simulation:</h3>\n"
- "<span class=\"simulation_name\">");
+ ConcatCString( header, "<br />\n" );
+ ConcatCString( header, "<h3>Simulation:</h3>\n"
+ "<span class=\"simulation_name\">");
Concat( header, title );
- ConcatCString( header,
- "</span><br />\n"
- "<kbd>");
+ ConcatCString( header, "</span><br />\n"
+ "<kbd>");
ConcatCString( header, file );
- ConcatCString( header,
- "</kbd><br />\n"
- "Iteration: ");
+ ConcatCString( header, "</kbd><br />\n"
+ "Iteration: ");
ConcatDecimal( header, GH ? GH->cctk_iteration : 0 );
- ConcatCString( header,
- "<br />\nPhysical time: ");
- ConcatFormattedDouble( header, 4, 2, GH ? GH->cctk_time : 0 );
- ConcatCString( header,
- "<br />\n");
+ ConcatCString( header, "<br />\nPhysical time: ");
+ ConcatFormattedDouble( header, GH ? GH->cctk_time : 0, 4, 2, SFMT_DEFAULT );
+ ConcatCString( header, "<br />\n");
if (ContentLinks)
{
Concat( header, quicklinks);
@@ -246,7 +235,7 @@ int SetHTML_ContentHeader(const cGH *GH, int choice,
@endhistory
@@*/
-int SetHTML_ContentFooter(const cGH *GH, int choice, String *footer)
+int HTTP_SetContentFooterString(const cGH *GH, int choice, String *footer)
{
/* avoid compiler warnings about unused parameters */
GH = GH;
@@ -256,3 +245,45 @@ int SetHTML_ContentFooter(const cGH *GH, int choice, String *footer)
SetToCString(footer,cactus_footer);
return Length(footer);
}
+
+int HTTP_ContentHeader(const cGH *GH, int choice, int len,
+ char *header, const char *menu)
+{
+ String *menuString = NULL;
+ String *headerString = String_New();
+ int retval = 0;
+
+ if( menu )
+ menuString = String_Make( menu );
+
+ retval = HTTP_SetContentHeaderString( GH, choice, headerString, menuString );
+
+ /* SW: original didn't use len, although it was clearly meant
+ * to indicate the length of the buffer, and all calls I saw to it
+ * passed a buffer length */
+ if( len > 0 )
+ {
+ SetToBuffer( headerString, header, len );
+ }
+ String_Delete( menuString );
+ String_Delete( headerString );
+ return retval;
+}
+
+int HTTP_ContentFooter(const cGH *GH, int choice, int len, char *header)
+{
+ String *headerString = String_New();
+ int retval = 0;
+
+ retval = HTTP_SetContentFooterString( GH, choice, headerString );
+
+ /* note: original didn't use len, although it was clearly meant
+ * to indicate the length of the buffer, and all calls I saw to it
+ * passed a buffer length */
+ if( len > 0 )
+ {
+ SetToBuffer( headerString, header, len );
+ }
+ String_Delete( headerString );
+ return retval;
+}
diff --git a/src/Parameters.c b/src/Parameters.c
index 44b17f8..020e538 100644
--- a/src/Parameters.c
+++ b/src/Parameters.c
@@ -8,7 +8,6 @@
@version $Header$
@@*/
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -23,14 +22,13 @@
#include "util_String.h"
-#include "http_Request.h"
+#include "httpRequest.h"
-#include "http_Auth.h"
-#include "http_Steer.h"
-#include "http_Cookies.h"
+#include "Auth.h"
+#include "Steer.h"
+#include "Cookies.h"
-#include "http_Content.h"
-#include "http_SString.h"
+#include "Content.h"
#include "cctk_Arguments.h"
#include "cctk_Parameters.h"
@@ -95,11 +93,8 @@ int HTTPi_RegisterParameterPages(void)
DECLARE_CCTK_PARAMETERS
int i;
- int first;
- const char *thorn;
char pagename[27+20+100]; /* Thorns have maximum length
then added 100 for parameters */
- char *namecopy;
union
{
const cParamData *pData;
@@ -122,7 +117,9 @@ int HTTPi_RegisterParameterPages(void)
for (i = 0; i < CCTK_NumCompiledThorns (); i++)
{
- thorn = CCTK_CompiledThorn(i);
+ const char *thorn = CCTK_CompiledThorn(i);
+ char *namecopy;
+ int first = 1;
sprintf(pagename,"/Parameters/%s", thorn);
@@ -131,7 +128,6 @@ int HTTPi_RegisterParameterPages(void)
HTTP_RegisterPage(pagename, ThornParameterPage, namecopy);
/* Walk through all parameters of given implementation. */
- first = 1;
while(CCTK_ParameterWalk(first, thorn, NULL, &u.pData) == 0)
{
first = 0;
@@ -154,26 +150,26 @@ SendHTTP_Redirect_Header( httpRequest *request )
{
/* Now redirect the browser to the normal page */
/* Status message */
- if(request->http_major_version < 1 ||
- (request->http_major_version == 1 && request->http_minor_version < 1))
+ if(HTTP_Major_Version( request ) < 1 ||
+ (HTTP_Major_Version( request ) == 1 && HTTP_Minor_Version( request ) < 1))
{
/* Older browsers don't understand 303 */
- Send_HTTP(request,"HTTP/1.0 302 Found\r\n");
+ HTTP_Send(request,"HTTP/1.0 302 Found\r\n");
}
else
{
- Send_HTTP(request,"HTTP/1.0 303 See Other\r\n");
+ HTTP_Send(request,"HTTP/1.0 303 See Other\r\n");
}
}
static void
SendHTTP_Uauthorized_Header( httpRequest *request )
{
- Send_HTTP(request,"HTTP/1.0 401 Unauthorized\r\n");
+ HTTP_Send(request,"HTTP/1.0 401 Unauthorized\r\n");
- Send_HTTP(request,"WWW-Authenticate: Basic realm=\"foo\"\r\n");
+ HTTP_Send(request,"WWW-Authenticate: Basic realm=\"foo\"\r\n");
- Send_HTTP(request,"Content-Type: text/html\r\n\r\n");
+ HTTP_Send(request,"Content-Type: text/html\r\n\r\n");
}
@@ -204,27 +200,26 @@ static int MainParameterPage(const cGH *cctkGH, httpRequest *request, void *data
int retval = -1;
String *message = String_New();
int i;
- const char *thorn = NULL;
/* avoid compiler warning about unused parameter */
data = data;
- SendHTTP_OK_Header( request );
+ HTTP_Send_OK_Header( request );
- SetHTML_Doctype( message );
- Send_HTTP_String(request, message);
+ HTTP_SetDoctype( message );
+ HTTP_SendString(request, message);
/* Start the page */
- Send_HTTP(request, "<html><head><title>Cactus Parameters Request</title>\n");
- SetHTML_HeadHeader( message);
- Send_HTTP_String(request, message );
+ HTTP_Send(request, "<html><head><title>Cactus Parameters Request</title>\n");
+ HTTP_SetHeadInfo( message);
+ HTTP_SendString(request, message );
Truncate( message, 0 );
- Send_HTTP(request, "\n</head>\n<body>\n");
+ HTTP_Send(request, "\n</head>\n<body>\n");
- SetHTML_ContentHeader(cctkGH,0,message,NULL);
- Send_HTTP_String(request, message);
+ HTTP_SetContentHeaderString(cctkGH,0,message,NULL);
+ HTTP_SendString(request, message);
- Send_HTTP(request,
+ HTTP_Send(request,
"<h1>Check/Modify Parameters</h1>\n"
"<p>From this page you can check the values of all parameters for \n"
"the simulation, and modify any parameters which have been \n"
@@ -244,7 +239,7 @@ static int MainParameterPage(const cGH *cctkGH, httpRequest *request, void *data
for (i = 0; i < CCTK_NumCompiledThorns (); i++)
{
- thorn = CCTK_CompiledThorn (i);
+ const char *thorn = CCTK_CompiledThorn (i);
if (CCTK_IsThornActive (thorn))
{
@@ -255,17 +250,17 @@ static int MainParameterPage(const cGH *cctkGH, httpRequest *request, void *data
ConcatCString(message, "</a></td>\n<td>");
ConcatCString(message, CCTK_ThornImplementation(thorn));
ConcatCString(message, "</td>\n</tr>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
}
}
- Send_HTTP(request,"</table></div>");
+ HTTP_Send(request,"</table></div>");
/* Write out the footer part. */
- SetHTML_ContentFooter(cctkGH, 0, message);
- retval = Send_HTTP_String(request, message);
+ HTTP_SetContentFooterString(cctkGH, 0, message);
+ retval = HTTP_SendString(request, message);
String_Delete( message );
return retval;
@@ -300,29 +295,16 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat
String * message = String_New();
String * menu = String_New();
String * temp = String_New();
- const char *thorn, *menuthorn;
- int first;
+ const char *thorn = (const char *)data;
const cParamData *pData;
- t_range *range;
- char *value;
- const httpArg *argument;
char user[USER_LENGTH+1] = EMPTYSTRING;
- int notauthorised;
- int readonly;
-
- int param_type;
- int param_bool;
- int nsteerable=0;
- int nfixed=0;
-
- thorn = (const char *)data;
- notauthorised = HTTP_AuthenticateBasic(request, "user", user, USER_LENGTH);
-
- readonly = notauthorised;
+ int notauthorised = HTTP_AuthenticateBasic(request, "user", user,
+ USER_LENGTH);
+ int readonly = notauthorised;
- if(request->n_arguments > 0)
+ if(HTTP_Num_Arguments( request ) > 0)
{
/* This is a parameter set request */
@@ -330,14 +312,17 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat
{
if(!readonly)
{
+ const httpArg *argument;
/* Queue parameters for steering */
- first = 1;
+ int first = 1;
while((argument = HTTP_ArgumentWalk(request, first)) != NULL)
{
first = 0;
- fprintf(stderr, "Setting %s::%s to %s\n", thorn, argument->arg,
- argument->value);
- HTTP_SteerQueue(thorn, argument->arg, argument->value);
+ fprintf(stderr, "Setting %s::%s to %s\n", thorn,
+ HTTP_Arg_Name( argument),
+ HTTP_Arg_Value( argument ));
+ HTTP_SteerQueue(thorn, HTTP_Arg_Name( argument),
+ HTTP_Arg_Value( argument ));
}
}
SendHTTP_Redirect_Header( request );
@@ -346,13 +331,13 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat
ConcatCString(message, thorn);
ConcatCString(message, "/\r\n\r\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
}
else
{
SendHTTP_Uauthorized_Header( request );
- Send_HTTP(request, notauthorized_page);
+ HTTP_Send(request, notauthorized_page);
}
}
@@ -360,22 +345,22 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat
{
/* Display the page. */
/* Status message */
- SendHTTP_OK_Header( request );
+ HTTP_Send_OK_Header( request );
- SetHTML_Doctype( message );
- Send_HTTP_String(request, message);
+ HTTP_SetDoctype( message );
+ HTTP_SendString(request, message);
/* Start the page */
SetToCString(message, "<html><head>\n<title>Cactus Parameters Request : ");
ConcatCString(message, thorn);
ConcatCString(message, "</title>\n");
- Send_HTTP_String(request, message );
+ HTTP_SendString(request, message );
- SetHTML_HeadHeader( message);
- Send_HTTP_String(request, message );
+ HTTP_SetHeadInfo( message);
+ HTTP_SendString(request, message );
Truncate( message, 0 );
- Send_HTTP(request, "</head>\n<body>\n");
+ HTTP_Send(request, "</head>\n<body>\n");
if (CCTK_NumCompiledThorns()>0)
@@ -385,7 +370,7 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat
/* Menu for this page */
for (i = 0; i < CCTK_NumCompiledThorns (); i++)
{
- menuthorn = CCTK_CompiledThorn (i);
+ const char *menuthorn = CCTK_CompiledThorn (i);
if (CCTK_IsThornActive (menuthorn))
{
ConcatCString(menu, " <a href=\"/Parameters/");
@@ -395,18 +380,21 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat
ConcatCString(menu, "</a><br />\n");
}
}
- SetHTML_ContentHeader(cctkGH,0,message,menu);
- Send_HTTP_String(request, message);
+ HTTP_SetContentHeaderString(cctkGH,0,message,menu);
+ HTTP_SendString(request, message);
if (!CCTK_IsThornActive(thorn))
{
SetToCString(message, "<strong> Thorn ");
ConcatCString(message, thorn);
ConcatCString(message, " is not active !!!</strong><br />\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
}
else
{
+ int nfixed=0;
+ int nsteerable=0;
+ int first = 1;
/* Send table of available parameters for given thorn */
/* Steerable parameters can be edited in a FORM. */
SetToCString(message,
@@ -427,26 +415,25 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat
"The default value of each parameter is shown in brackets at the end of the description.</p>"
"\n");
- Send_HTTP_String(request, message);
- Send_HTTP(request, "<div class=\"centered\">\n");
+ HTTP_SendString(request, message);
+ HTTP_Send(request, "<div class=\"centered\">\n");
if(!readonly )
{
SetToCString(message,"<form action=\"/Parameters/");
ConcatCString(message, thorn);
ConcatCString(message, "/\">\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
}
/* Walk through all steerable parameters of given implementation. */
- first = 1;
while(CCTK_ParameterWalk(first, thorn, NULL, &pData) == 0)
{
- first = 0;
+ char *value = CCTK_ParameterValString (pData->name, pData->thorn);
Truncate(message,0);
-
- value = CCTK_ParameterValString (pData->name, pData->thorn);
+ first = 0;
+
if(value)
{
if (pData->steerable == CCTK_STEERABLE_ALWAYS)
@@ -471,10 +458,11 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat
if (!readonly)
{
+ int param_type;
if (pData->type == PARAMETER_BOOLEAN)
{
/* Steerable boolean */
- param_bool =
+ int param_bool =
*((const CCTK_INT *)CCTK_ParameterGet(pData->name,thorn,&param_type));
ConcatCString(message, "<tr>\n<td><a href=\"/Parameters/");
ConcatCString(message, pData->thorn);
@@ -506,6 +494,7 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat
}
else if (pData->type == PARAMETER_KEYWORD)
{
+ t_range *range;
/* Steerable keyword */
CCTK_ParameterGet(pData->name,thorn,&param_type);
@@ -589,22 +578,22 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat
}
free (value);
}
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
}
if (nsteerable>0)
{
- Send_HTTP(request, "</table>\n");
+ HTTP_Send(request, "</table>\n");
}
else
{
- Send_HTTP(request, "<p>This thorn has no steerable parameters.</p>\n");
+ HTTP_Send(request, "<p>This thorn has no steerable parameters.</p>\n");
}
if(!readonly && nsteerable>0)
{
- Send_HTTP(request,
+ HTTP_Send(request,
"<input type=\"submit\" value=\"Update all parameters\" />\n"
"</form>\n");
}
@@ -618,7 +607,7 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat
first = 0;
Truncate(message,0);
- value = CCTK_ParameterValString (pData->name, pData->thorn);
+ char *value = CCTK_ParameterValString (pData->name, pData->thorn);
if(value)
{
if (!(pData->steerable == CCTK_STEERABLE_ALWAYS))
@@ -644,8 +633,7 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat
ConcatCString(message, pData->name);
ConcatCString(message, "\">");
ConcatCString(message, pData->name);
- ConcatCString(message, "</a></td>\n"
- "<td>");
+ ConcatCString(message, "</a></td>\n<td>");
ConcatCString(message, value);
ConcatCString(message, "</td>\n<td class=\"description\">");
SetToEncodedHTMLCString( temp, pData->description );
@@ -658,27 +646,26 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat
}
free(value);
}
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
}
if (nfixed>0)
{
- Send_HTTP(request, "</table>\n");
+ HTTP_Send(request, "</table>\n");
}
else
{
- Send_HTTP(request, "<p>This thorn has no fixed parameters.</p>\n");
+ HTTP_Send(request, "<p>This thorn has no fixed parameters.</p>\n");
}
- Send_HTTP(request, "</div>\n");
+ HTTP_Send(request, "</div>\n");
}
-
/* Write out the footer part. */
- SetHTML_ContentFooter(cctkGH, 0, message);
- retval = Send_HTTP_String(request, message);
+ HTTP_SetContentFooterString(cctkGH, 0, message);
+ retval = HTTP_SendString(request, message);
} /* n_arguments > 0 */
String_Delete( message );
String_Delete( menu );
@@ -707,18 +694,16 @@ static int ParameterPage(const cGH *cctkGH, httpRequest *request, void *data)
String * message = String_New();
String * menu = String_New();
String * temp = String_New();
- int first;
+ int first = 1;
const cParamData *pData = (cParamData *)data;
const cParamData *pDataWalk=NULL;
- t_range *range;
char *value;
- const httpArg *argument;
char user[USER_LENGTH+1] = EMPTYSTRING;
int notauthorised = HTTP_AuthenticateBasic(request, "user", user,
USER_LENGTH);
int readonly = notauthorised;
- if(request->n_arguments > 0)
+ if(HTTP_Num_Arguments( request ) > 0)
{
/* This is a parameter set request */
@@ -726,14 +711,17 @@ static int ParameterPage(const cGH *cctkGH, httpRequest *request, void *data)
{
if(!readonly)
{
+ const httpArg *argument;
/* Queue parameters for steering */
first = 1;
while((argument = HTTP_ArgumentWalk(request, first)) != NULL)
{
first = 0;
fprintf(stderr, "Setting %s::%s to %s\n", pData->thorn,
- argument->arg, argument->value);
- HTTP_SteerQueue(pData->thorn, argument->arg, argument->value);
+ HTTP_Arg_Name( argument),
+ HTTP_Arg_Value( argument ));
+ HTTP_SteerQueue(pData->thorn, HTTP_Arg_Name( argument),
+ HTTP_Arg_Value( argument ));
}
}
SendHTTP_Redirect_Header( request );
@@ -741,36 +729,37 @@ static int ParameterPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message, pData->thorn);
ConcatCString(message, "/\r\n\r\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
}
else
{
SendHTTP_Uauthorized_Header( request );
- Send_HTTP(request, notauthorized_page);
+ HTTP_Send(request, notauthorized_page);
}
}
else
{
+ t_range *range;
/* Display the page. */
- SendHTTP_OK_Header( request );
+ HTTP_Send_OK_Header( request );
- SetHTML_Doctype( message );
- Send_HTTP_String(request, message);
+ HTTP_SetDoctype( message );
+ HTTP_SendString(request, message);
/* Start the page */
- Send_HTTP(request, "<html><head>\n");
+ HTTP_Send(request, "<html><head>\n");
SetToCString(message, "<title>Cactus Parameter Request : ");
ConcatCString(message, pData->name);
ConcatCString(message, "</title>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
- SetHTML_HeadHeader( message);
- Send_HTTP_String(request, message );
+ HTTP_SetHeadInfo( message);
+ HTTP_SendString(request, message );
Truncate( message, 0 );
- Send_HTTP(request,"</head>\n<body>\n");
+ HTTP_Send(request,"</head>\n<body>\n");
/* Menu for this page */
@@ -793,15 +782,15 @@ static int ParameterPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(menu, "</a><br />\n");
}
- SetHTML_ContentHeader(cctkGH,0,message,menu);
- Send_HTTP_String(request, message);
+ HTTP_SetContentHeaderString(cctkGH,0,message,menu);
+ HTTP_SendString(request, message);
SetToCString(message,"<h1>");
ConcatCString(message, pData->thorn);
ConcatCString(message, ": ");
ConcatCString(message, pData->name);
ConcatCString(message, "</h1>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
SetToCString(message,
"<div class=\"centered\">Return to all parameters for this \n"
@@ -811,7 +800,7 @@ static int ParameterPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message,
"\">thorn</a>.</div> ");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
value = CCTK_ParameterValString (pData->name, pData->thorn);
@@ -845,7 +834,7 @@ static int ParameterPage(const cGH *cctkGH, httpRequest *request, void *data)
SetToEncodedHTMLCString( temp, pData->defval );
Concat(message, temp);
ConcatCString(message, "</td>\n</tr>");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
SetToCString(message,"<tr>\n<th>Steerable:</th>\n<td>");
switch(pData->steerable)
@@ -863,7 +852,7 @@ static int ParameterPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message,"Not matched");
}
ConcatCString(message,"</td>\n</tr>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
SetToCString(message,"<tr>\n"
"<th>Type:</th>\n<td>");
@@ -892,7 +881,7 @@ static int ParameterPage(const cGH *cctkGH, httpRequest *request, void *data)
}
ConcatCString(message,"</td>\n</tr>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
SetToCString(message,"<tr><th>Scope:</th><td>");
@@ -911,7 +900,7 @@ static int ParameterPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message,"Not matched</td></tr>\n");
}
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
Truncate(message,0);
first = 1;
@@ -945,24 +934,24 @@ static int ParameterPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message, "</dl></td>\n</tr>\n");
}
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
SetToCString(message, "<tr>\n<th>Times Set:</th>\n<td>");
ConcatDecimal(message, pData->n_set);
ConcatCString(message, "</td>\n</tr>\n</table>\n</div>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
}
else
{
- Send_HTTP(request,"<p>Hidden parameter, information is not available</p>\n");
+ HTTP_Send(request,"<p>Hidden parameter, information is not available</p>\n");
}
/* Write out the footer part. */
- SetHTML_ContentFooter(cctkGH, 0, message);
- retval = Send_HTTP_String(request, message);
+ HTTP_SetContentFooterString(cctkGH, 0, message);
+ retval = HTTP_SendString(request, message);
}
String_Delete( message );
String_Delete( menu );
diff --git a/src/Redirect.c b/src/Redirect.c
index 24f9729..5502e5c 100644
--- a/src/Redirect.c
+++ b/src/Redirect.c
@@ -22,11 +22,10 @@
#include "httpd.h"
-#include "http_Request.h"
-#include "http_Content.h"
+#include "httpRequest.h"
+#include "Content.h"
-#include "http_Redirect.h"
-#include "http_SString.h"
+#include "Redirect.h"
#include "SString_Namespace.h"
static const char *rcsid = "$Header$";
@@ -292,28 +291,28 @@ static int RedirectPage(const cGH *cctkGH, httpRequest *request, void *data)
/* avoid compiler warning about unused parameter */
data = data;
- SendHTTP_OK_Header(request);
+ HTTP_Send_OK_Header(request);
/* Start the page */
SetToCString(message,"<html><head><title>Server Redirect</title>\n");
/* Write out the main header part */
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
SetToCString(message,"<meta http-equiv=\"refresh\" content=\"1; URL=http://");
ConcatCString(message,HTTP_Master());
ConcatCString(message, ":");
ConcatDecimal(message,(unsigned int) HTTP_Port());
ConcatCString(message, "\" />\n</head>\n<body>\n");
- Send_HTTP_String(request,message);
+ HTTP_SendString(request,message);
/* ********** Server Redirect To Master ************* */
SetToCString(message,"<h1>Redirect to master host=");
ConcatCString(message,HTTP_Master());
ConcatCString(message, ":");
ConcatDecimal(message,(unsigned int) HTTP_Port());
ConcatCString(message, "</h1>\n");
- Send_HTTP_String(request,message);
+ HTTP_SendString(request,message);
- SetHTML_ContentFooter(cctkGH, 0, message);
- retval = Send_HTTP_String(request, message);
+ HTTP_SetContentFooterString(cctkGH, 0, message);
+ retval = HTTP_SendString(request, message);
String_Delete( message );
return retval;
diff --git a/src/http_Redirect.h b/src/Redirect.h
index 0cfad1a..808ffdf 100644
--- a/src/http_Redirect.h
+++ b/src/Redirect.h
@@ -1,9 +1,9 @@
/*@@
- @header http_Redirect.h
+ @header Redirect.h
@date Fri May 18 11:08:25 2001
@author Tom Goodale
@desc
- Rdirection stuff.
+ Rdirection stuff. Was http_Redirect.h.
@enddesc
@version
@@*/
diff --git a/src/SString.c b/src/SString.c
index 63aa8c5..b0b1477 100644
--- a/src/SString.c
+++ b/src/SString.c
@@ -24,10 +24,13 @@ typedef enum { MAKE_NULL_ALLOC, NEW_NULL_ALLOC, BUFFER_NULL_ALLOC }
SSTRING_ERROR;
static void String_HandleSeriousError( SSTRING_ERROR );
+#define LINE_END_BUFSIZE 3
+
typedef struct String_tag
{
size_t length;
SSCHAR *chars;
+ SSCHAR line_end[LINE_END_BUFSIZE];
} String_placeholder;
static SSCHAR kLineEndChar = '\n';
@@ -45,6 +48,14 @@ StringGetBuffer( const String * s )
{
return s->chars;
}
+
+void
+StringCopyBuffer( const String * s, SSCHAR * buf, size_t bufSize )
+{
+ strncpy( buf, s->chars, bufSize );
+ buf[bufSize-1] = '\0';
+}
+
/*
* Returns 0 if index is not in the string
*/
@@ -83,6 +94,7 @@ String_Make( const SSCHAR * c_string )
}
else
BufferForThisManyChars( s, 0 );
+ s->line_end[0] = kLineEndChar;
}
else
String_HandleSeriousError( MAKE_NULL_ALLOC );
@@ -95,7 +107,11 @@ String_Make( const SSCHAR * c_string )
String *
String_Copy( const String * other )
{
- return StringSetToCString( String_New(), StringGetBuffer( other ) );
+ String *s = StringSetToCString( String_New(),
+ StringGetBuffer( other ) );
+ memcpy( s->line_end, other->line_end, LINE_END_BUFSIZE
+ * sizeof( SSCHAR ) );
+ return s;
}
void
@@ -118,6 +134,23 @@ StringTruncate( String * s, size_t n )
}
String *
+StringTrimLeading( String * s, size_t n )
+{
+ const size_t orig_len = StringLength( s );
+
+ if( orig_len > 0 && n > 0 )
+ {
+ const size_t position = MIN( orig_len, n ) - 1;
+ const size_t new_len = orig_len - position;
+
+ memmove( 0, s->chars + position, new_len );
+ s->chars[new_len] = '\0';
+ s->length = new_len;
+ }
+ return s;
+}
+
+String *
StringSetNthChar( String * s, size_t n, SSCHAR c )
{
if( n < s->length )
@@ -168,6 +201,31 @@ StringSetToCString( String * s, const SSCHAR *c_string )
return StringSetToBuffer( s, c_string, strlen( c_string ) );
}
+size_t
+StringSetNextToken( const String *s, String *token,
+ const SSCHAR *delim, size_t start )
+{
+ if( start < s->length )
+ {
+ const size_t ndelims = strlen( delim );
+ size_t next = s->length;
+ size_t d;
+
+ for( d = 0; d < ndelims; d++ )
+ {
+ size_t nextDelim = start;
+ if( StringFindCharFrom( s, delim[d], &nextDelim ) )
+ next = MIN( nextDelim, next );
+ }
+
+ StringSetRange( token, s, start, next - start );
+
+ return next < s->length ? next + 1 : next;
+ }
+ else
+ return 0;
+}
+
String *
StringConcatCString( String * s, const SSCHAR *c_string )
{
@@ -183,13 +241,11 @@ String *
StringSetToBuffer( String * s, const SSCHAR *buf, size_t len )
{
if( s != NULL && buf != NULL )
- {
if( BufferForThisManyChars( s, len ) )
{
strncpy( s->chars, buf, len );
s->chars[ len ] = '\0';
}
- }
return s;
}
@@ -198,17 +254,31 @@ StringSet( String * s, const String * other )
{
return StringSetToCString( s, StringGetBuffer( other ) );
}
-
+/*
+ * Take care! What if this String's buffer is the same as the other's?
+ * For now, this can happen only if the other String is the same as this
+ * String.
+ *
+ * This needs thought for every String that takes a String argument,
+ * and for the ones that take C strings as well.
+ */
String *
-StringSetSubString( String * s, const String * other,
- size_t first, size_t last )
+StringSetRange( String * s, const String * other,
+ size_t first, size_t length )
{
const size_t other_length = other->length;
- const size_t veryFirst = MIN( MIN( first, last ), other_length ),
- veryLast = MIN( MAX( first, last ), other_length ),
- length = ( veryLast + 1 ) - veryFirst;
+ const size_t veryFirst = MIN( first + 1, other_length ) - 1,
+ minLength = MIN( first + length, other_length ),
+ newLength = minLength - veryFirst;
- return StringSetToBuffer( s, other->chars + veryFirst, length );
+ return StringSetToBuffer( s, other->chars + veryFirst, newLength );
+}
+
+String *
+StringSetToPartAfter( String * s, const String * other, size_t position )
+{
+ return StringSetRange( s, other,
+ position + 1, StringLength( other ) - position );
}
/*
@@ -217,7 +287,7 @@ StringSetSubString( String * s, const String * other,
* On output, is position where char was found.
*/
SSBOOL
-StringFindChar( const String *s, SSCHAR theChar, size_t * position )
+StringFindCharFrom( const String *s, SSCHAR theChar, size_t * position )
{
SSCHAR * charPtr;
@@ -234,7 +304,7 @@ StringFindChar( const String *s, SSCHAR theChar, size_t * position )
}
SSBOOL
-StringFindSubString( const String * s, const String * other,
+StringFindStringFrom( const String * s, const String * other,
size_t * position )
{
SSCHAR * charPtr;
@@ -362,9 +432,10 @@ StringConcat( String * s, const String * other )
* On unix the default \n works; on the Mac, you might want \r
*/
void
-String_SetLineEndCharacter( SSCHAR c )
+String_SetLineEndCharacter( String * s, const SSCHAR *end )
{
- kLineEndChar = c;
+ strncpy( s->line_end, end, LINE_END_BUFSIZE );
+ s->line_end[LINE_END_BUFSIZE - 1] = '\0';
}
String *
@@ -425,12 +496,101 @@ StringConcatDouble( String * s, double d )
snprintf( buf, sizeof( buf ), "%f", d );
return StringConcatCString( s, buf );
}
+/*a
+ *
+ * 0) It's inappropritate to handle string and character convesions.
+ * And there are some very specific-use conversions, such as 't'
+ *
+ * 1) I'm not sure I completely understand all the conversions.
+ * specifically, I don't get G and g.
+ *
+ * 2) There are several standards, including C99 and SUSv2
+ *
+ * 3) I haven't done long long or long double
+ *
+ * 4) Mixed up notions of unsigned with hex and octal...wrong?
+ *
+ *
+ *
+ */
+static void
+addNumericMods( char * format, SSFORMAT f )
+{
+ strcat( format, "%" );
+ if( f & SFMT_LEFT_ALIGN )
+ strcat( format, "-" );
+ if( f & SFMT_PRINT_SIGN )
+ strcat( format, "+" );
+ if( f & SFMT_ADD_SIGN_SPACE )
+ strcat( format, " " );
+ if( f & SFMT_PAD_ZERO )
+ strcat( format, "0" );
+ if( f & SFMT_ALT )
+ strcat( format, "#" );
+}
+#define EMPTYSTRING { '\0' }
+String *
+StringConcatFormattedDecimal( String *s, long int d,
+ int width, int precision, SSINT_FORMAT f )
+{
+ char buf[DECIMALBUFSIZE] = EMPTYSTRING;
+ char format[16] = EMPTYSTRING;
+ addNumericMods( format, f );
+ strcat( format, "*.*ld" );
+ snprintf( buf, sizeof( buf ), format, width, precision, d );
+ return StringConcatCString( s, buf );
+}
String *
-StringConcatFormattedDouble( String * s, int ndigits, int ndec, double d )
-{
- char buf[DECIMALBUFSIZE] = { '\0' };
- snprintf( buf, sizeof( buf ), "%*.*f", ndigits, ndec, d );
+StringConcatFormattedUnsigned( String *s, unsigned long int n,
+ int width, int precision, SSINT_FORMAT f )
+{
+ char buf[DECIMALBUFSIZE] = EMPTYSTRING;
+ char format[16] = EMPTYSTRING;
+ addNumericMods( format, f );
+ strcat( format, "*.*l" );
+ if( f & SFMT_HEX )
+ {
+ if( f & SFMT_LOWERCASE )
+ strcat( format, "x" );
+ else
+ strcat( format, "X" );
+ }
+ else if( f & SFMT_OCTAL )
+ strcat( format, "o" );
+ else
+ strcat( format, "u" );
+ snprintf( buf, sizeof( buf ), format, width, precision, n );
+ return StringConcatCString( s, buf );
+}
+
+String *
+StringConcatFormattedDouble( String *s, double d,
+ int width, int precision, SSDOUBLE_FORMAT f )
+{
+ char buf[DECIMALBUFSIZE] = EMPTYSTRING;
+ char format[16] = EMPTYSTRING;
+ addNumericMods( format, f );
+ if( f & SFMT_ALWAYS_POINT )
+ strcat( format, "#" );
+ strcat( format, "*.*" );
+ if( f & SFMT_EXPONENTIAL )
+ {
+ if( f & SFMT_LOWERCASE )
+ strcat( format, "e" );
+ else
+ strcat( format, "E" );
+ }
+ if( f & SFMT_DISCRETIONARY_EXP )
+ {
+ if( f & SFMT_LOWERCASE )
+ strcat( format, "g" );
+ else
+ strcat( format, "G" );
+ }
+ else
+ strcat( format, "f" );
+ snprintf( buf, sizeof( buf ), format, width, precision, d );
return StringConcatCString( s, buf );
}
diff --git a/src/SString.h b/src/SString.h
index 4f93951..8be38ee 100644
--- a/src/SString.h
+++ b/src/SString.h
@@ -11,25 +11,32 @@
#include <stddef.h>
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+typedef struct String_tag String; /* The abstract type for a String */
+
+typedef char SSCHAR; /* but could be Unicode */
+
typedef enum { SSFALSE, SSTRUE } SSBOOL;
-typedef char SSCHAR;
-typedef struct String_tag String;
/* String creation and deletion */
String *String_New();
String *String_Copy( const String *other );
String *String_Make( const SSCHAR *other );
void String_Delete( String * );
- /* Copying */
-String * StringSet( String *dest, const String *source );
-String * StringSetSubString( String *dest, const String *source,
- size_t first, size_t last );
/* Number of characters in string */
size_t StringLength( const String * );
/* Accessors */
SSCHAR StringNthChar( const String *, size_t n );
String * StringSetNthChar( String *, size_t n, SSCHAR c );
-String * StringTruncate( String *, size_t n );
+ /* Copying */
+String * StringSet( String *dest, const String *source );
+String * StringSetRange( String *dest, const String *source,
+ size_t start, size_t length );
+String * StringSetToPartAfter( String *dest, const String *source,
+ size_t position );
/* Conversion to and from C string */
String * StringSetToCString( String *s, const SSCHAR *c_str );
String * StringConcatCString( String *s, const SSCHAR *c_str );
@@ -38,34 +45,73 @@ String * StringInsertCString( String * s, const char * c_str,
String * StringSetToBuffer( String *s, const SSCHAR *buf,
size_t len );
const SSCHAR * StringGetBuffer( const String * s );
+void StringCopyBuffer( const String * s, SSCHAR * buf,
+ size_t bufsize );
/* Searching */
-SSBOOL StringFindSubString( const String *s, const String *substr,
+SSBOOL StringFindStringFrom( const String *s, const String *toFind,
size_t *position );
-SSBOOL StringFindChar( const String *s, SSCHAR theChar,
+SSBOOL StringFindCharFrom( const String *s, SSCHAR theChar,
size_t *position );
+size_t StringSetNextToken( const String *s, String *token,
+ const SSCHAR *delim, size_t index );
/* Comparison */
SSBOOL StringEquals( const String *a, const String *b );
int StringCompare( const String *a, const String *b );
/* Insertion and Concatenation */
String * StringInsert( String * s, const String * other, size_t pos );
+String * StringConcat( String * s, const String * other);
String * StringInsertChar( String * s, SSCHAR c, size_t pos );
+ /* Deleting and Trimming */
String * StringDeleteChar( String * s, size_t pos );
String * StringDeleteRange( String * s, size_t begin, size_t end );
-String * StringConcat( String * s, const String * other);
- /* Trim */
-String * StringTrimHead( const String *s, size_t pos );
-String * StringTrimTail( const String *s, size_t pos );
+String * StringTruncate( String *, size_t n );
+String * StringTrimLeading( String *, size_t n );
+ /* For line reading and writing */
+void String_SetLineEndChars( String *str, const SSCHAR * );
/* Printing to stdout */
void StringPrint( const String *str );
void StringFormatPrint( const String *str, const SSCHAR *format );
- /* For line reading and writing */
-void String_SetLineEndCharacter( SSCHAR c );
- /* String conversions */
+ /* Numeric conversions */
+double StringAsDouble( const String *str );
+long StringAsLong( const String *str );
+unsigned long StringAsUnsignedLong( const String *str );
+
+typedef enum SSFORMAT_TAG
+{
+ SFMT_DEFAULT = 0,
+ SFMT_LEFT_ALIGN = 1,
+ SFMT_PAD_ZERO = 1<<1,
+ SFMT_LOWERCASE = 1<<2,
+ SFMT_ADD_SIGN_SPACE = 1<<3,
+ SFMT_PRINT_SIGN = 1<<4,
+ SFMT_ALT = 1<<5
+} SSFORMAT;
+
+typedef enum SSDOUBLE_FORMAT_TAG
+{
+ SFMT_EXPONENTIAL = 1<<6,
+ SFMT_DISCRETIONARY_EXP = 1<<7
+} SSDOUBLE_FORMAT;
+
+typedef enum SSINT_FORMAT_TAG
+{
+ SFMT_HEX = 1<<6,
+ SFMT_OCTAL = 1<<7
+} SSINT_FORMAT;
+#define SFMT_ALWAYS_POINT SFMT_ALT
+#define SFMT_DONT_TRIM_ZEROS SFMT_ALT
+
+String * StringConcatFormattedInt( String *s, long int d,
+ int width, int precision, SSINT_FORMAT f );
+String * StringConcatFormattedUnsigned( String *s, unsigned long int n,
+ int width, int precision, SSINT_FORMAT f );
+String * StringConcatFormattedDouble( String *s, double d,
+ int width, int precision, SSDOUBLE_FORMAT f );
String * StringConcatDecimal( String *str, long int d );
-String * StringConcatHex( String *str, long int d );
-String * StringConcatOctal( String *str, long int d );
String * StringConcatDouble( String *str, double d );
-String * StringConcatFormattedDouble( String *str, int ndigits,
- int ndecimals, double d );
+
+#ifdef __cplusplus
+}
+#endif
#endif
diff --git a/src/SStringHTML.c b/src/SStringHTML.c
index 5d4951a..42a317b 100644
--- a/src/SStringHTML.c
+++ b/src/SStringHTML.c
@@ -30,7 +30,7 @@ String *
StringReplaceCharWithCString( String * str, SSCHAR c, const SSCHAR *cstr )
{
size_t position = 0;
- while( StringFindChar( str, c, &position ) )
+ while( StringFindCharFrom( str, c, &position ) )
{
StringDeleteChar( str, position );
StringInsertCString( str, cstr, position );
diff --git a/src/SStringHTML.h b/src/SStringHTML.h
index 6fb220c..82c1687 100644
--- a/src/SStringHTML.h
+++ b/src/SStringHTML.h
@@ -25,6 +25,11 @@ String * StringSGMLEntity( SGMLEntityNum n );
*
* If move to bigger characters will have to encode more.
* */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
String * StringSetToEncodedURLCString( String * str, const char *c );
String * StringEncodeURL( String * str );
@@ -33,5 +38,8 @@ String * StringEncodeURL( String * str );
String * StringSetToEncodedHTMLCString( String * str, const char *c );
String * StringEncodeHTML( String * str );
+#ifdef __cplusplus
+}
+#endif
#endif
diff --git a/src/SStringIO.h b/src/SStringIO.h
index 7c84fb1..9924940 100644
--- a/src/SStringIO.h
+++ b/src/SStringIO.h
@@ -12,6 +12,10 @@
#include "SString.h"
#include <stdio.h>
+#ifdef __cplusplus
+extern "C"
+{
+#endif
/* File utilities */
String * StringReadToDelimiter( String *str, FILE * file, char delim );
String * StringReadToEndOfLine( String *str, FILE * is );
@@ -21,4 +25,8 @@ void StringPrintToFile( const String *str, FILE * is );
void StringFormatPrintToFile( const String *str, const char *format,
FILE * is );
+#ifdef __cplusplus
+}
+#endif
+
#endif
diff --git a/src/SStringIO_Namespace.h b/src/SStringIO_Namespace.h
index 274027b..d9833d0 100644
--- a/src/SStringIO_Namespace.h
+++ b/src/SStringIO_Namespace.h
@@ -11,15 +11,10 @@
#include "SStringIO.h"
-#define ReadToDelimiter( a, f, d ) \
- StringReadToDelimiter( a, f, d )
-#define ReadToEndOfLine( a, f ) \
- StringReadToEndOfLine( a, f )
-#define ReadLine( a, f ) \
- StringReadLine( a, f )
-#define PrintToFile( a, f ) \
- StringPrintToFile( a, f )
-#define FormatPrintToFile( a, s, f ) \
- StringFormatPrintToFile( a, s, f )
+#define ReadToDelimiter( a, f, d ) StringReadToDelimiter( a, f, d )
+#define ReadToEndOfLine( a, f ) StringReadToEndOfLine( a, f )
+#define ReadLine( a, f ) StringReadLine( a, f )
+#define PrintToFile( a, f ) StringPrintToFile( a, f )
+#define FormatPrintToFile( a, s, f ) StringFormatPrintToFile( a, s, f )
#endif
diff --git a/src/SString_Namespace.h b/src/SString_Namespace.h
index 4c40388..1ba9607 100644
--- a/src/SString_Namespace.h
+++ b/src/SString_Namespace.h
@@ -11,19 +11,22 @@
#include "SString.h"
-
/* A poor man's namespace for the String module */
#define Set( a, b ) \
StringSet( a, b )
+#define SetSubString( a, b, p, l ) \
+ StringSetSubString( a, b, p, l )
#define SetToCString( a, b ) \
StringSetToCString( a, b )
+#define SetToPartAfter( a, b, p ) \
+ StringSetToPartAfter( a, b, p )
#define InsertCString( a, b, c ) \
StringInsertCString( a, b, c )
#define ConcatCString( a, b ) \
StringConcatCString( a, b )
-#define SetToBuffer( a, b ) \
- StringSetToBuffer( a, b )
+#define SetToBuffer( a, b, l ) \
+ StringSetToBuffer( a, b, l )
#define GetBuffer( a ) \
StringGetBuffer( a )
#define Length( p ) \
@@ -34,10 +37,14 @@
StringSetNthChar( s, n, c )
#define Truncate( s, n ) \
StringTruncate( s, n )
-#define FindSubString( s, c, p ) \
- StringFindSubString( s, c, p )
-#define FindChar( s, c, p ) \
- StringFindChar( s, c, p )
+#define TrimLeading( s, n ) \
+ StringTrimLeading( s, n )
+#define FindStringFrom( s, c, p ) \
+ StringFindStringFrom( s, c, p )
+#define FindCharFrom( s, c, p ) \
+ StringFindCharFrom( s, c, p )
+#define SetNextToken( s, c, p, r ) \
+ StringSetNextToken( s, c, p, r )
#define Compare( a, b ) \
StringCompare( a, b )
#define AreEqual( a, b ) \
@@ -60,7 +67,7 @@
StringConcatOctal( a, s )
#define ConcatDouble( a, s ) \
StringConcatDouble( a, s )
-#define ConcatFormattedDouble( a, f, f2, s ) \
- StringConcatFormattedDouble( a, f, f2, s )
+#define ConcatFormattedDouble( a, d, s1, s2, f ) \
+ StringConcatFormattedDouble( a, d, s1, s2, f )
#endif
diff --git a/src/Server.c b/src/Server.c
index 9af9c55..dee7f10 100644
--- a/src/Server.c
+++ b/src/Server.c
@@ -25,8 +25,8 @@
#include "httpd.h"
-#include "http_Steer.h"
-#include "http_Expression.h"
+#include "Steer.h"
+#include "Expression.h"
#include "SString_Namespace.h"
@@ -49,7 +49,7 @@ typedef struct
********************************************************************/
static httpPage *CreatePageData(int (*function)(const cGH *,httpRequest *, void *), void *data);
-static httpPage *FindPage(char *path, char **residual);
+static httpPage *FindPage(const char *path, const char **residual);
static int StatusUntilIt (const cGH *cctkGH);
static int StatusUntilTime (const cGH *cctkGH);
@@ -100,20 +100,22 @@ static const char *notimplemented_page =
int HTTP_RequestGET(cGH *cctkGH, httpRequest *request)
{
int retval = -1;
- httpPage *pagedata;
+ const char *residual = NULL;
+ httpPage *pagedata = FindPage(HTTP_URI( request ), &residual );
+ HTTP_SetResidual( request, residual );
- if((pagedata = FindPage(request->uri, &(request->residual))))
+ if( pagedata )
{
retval = pagedata->function(cctkGH, request, pagedata->data);
}
if(retval < 0)
{
- Send_HTTP(request,"HTTP/1.0 404 Not Found\r\n");
+ HTTP_Send(request,"HTTP/1.0 404 Not Found\r\n");
- Send_HTTP(request,"Content-Type: text/html\r\n\r\n");
+ HTTP_Send(request,"Content-Type: text/html\r\n\r\n");
- Send_HTTP(request, notfound_page);
+ HTTP_Send(request, notfound_page);
}
return retval;
@@ -137,11 +139,11 @@ int HTTP_RequestUnsupported(cGH *cctkGH, httpRequest *request)
{
cctkGH = cctkGH; /* avoid compiler warning about unused parameter */
- Send_HTTP(request,"HTTP/1.0 501 Not Implemented\r\n");
+ HTTP_Send(request,"HTTP/1.0 501 Not Implemented\r\n");
- Send_HTTP(request,"Content-Type: text/html\r\n\r\n");
+ HTTP_Send(request,"Content-Type: text/html\r\n\r\n");
- Send_HTTP(request, notimplemented_page );
+ HTTP_Send(request, notimplemented_page );
return 0;
}
@@ -164,8 +166,6 @@ int HTTP_RegisterPage(const char *path, int (*function)(const cGH *, httpRequest
{
int retval = -1;
- httpPage *pagedata;
-
/* Create the hash table if it's not already been created */
if(! pages)
{
@@ -178,7 +178,7 @@ int HTTP_RegisterPage(const char *path, int (*function)(const cGH *, httpRequest
}
else
{
- pagedata = CreatePageData(function, data);
+ httpPage *pagedata = CreatePageData(function, data);
if(pagedata)
{
@@ -339,7 +339,7 @@ static httpPage *CreatePageData(int (*function)(const cGH *, httpRequest *, void
@endhistory
@@*/
-static httpPage *FindPage(char *path, char **residual)
+static httpPage *FindPage(const char *path, const char **residual)
{
httpPage *pagedata = NULL;
@@ -360,13 +360,10 @@ static httpPage *FindPage(char *path, char **residual)
ConcatCString( temp,"index.html");
pagedata = Util_HashData(pages, Length(temp), GetBuffer(temp), 0);
-
- *residual = NULL;
}
else if((pagedata = Util_HashData(pages, strlen(path), path, 0)))
{
/* Or exact path */
- *residual = NULL;
}
else
{
@@ -378,12 +375,12 @@ static httpPage *FindPage(char *path, char **residual)
pagedata = Util_HashData(pages, Length(temp), GetBuffer(temp), 0);
- *residual = NULL;
}
+ *residual = NULL;
if(!pagedata && strlen( path ) > 0)
{
- char *position;
+ const char *position;
/* Ok, now cycle through. Know it doesn't end with a slash */
for(position = path+strlen(path)-1; position >= path; position--)
{
@@ -473,8 +470,6 @@ static int StatusUntilExpression (cGH *cctkGH)
static char *parsed_expression = NULL;
static int times_set = -1;
int retval = 0;
- char *copy;
-
/* See if we need to parse the expression again. */
int new_times_set = CCTK_ParameterQueryTimesSet("until_expression",
@@ -493,7 +488,7 @@ static int StatusUntilExpression (cGH *cctkGH)
if(parsed_expression && strlen(parsed_expression) > 0 && cctkGH)
{
/* Make a copy */
- copy = Util_Strdup(parsed_expression);
+ char *copy = Util_Strdup(parsed_expression);
/* Evaluate the expression */
retval = HTTP_ExpressionEvaluate(copy, evaluator, cctkGH);
@@ -524,15 +519,12 @@ static double evaluator(const char *expression, void *data)
{
double retval = 0.0;
cGH *cctkGH = (cGH *)data;
- void *pointer;
- int vartype;
int varindex = CCTK_VarIndex(expression);
if(varindex > -1)
{
- vartype = CCTK_VarTypeI(varindex);
-
- pointer = CCTK_VarDataPtrI(cctkGH, 0, varindex);
+ int vartype = CCTK_VarTypeI(varindex);
+ int *pointer = CCTK_VarDataPtrI(cctkGH, 0, varindex);
switch(vartype)
{
diff --git a/src/Sockets.c b/src/Sockets.c
index 60aee22..b080ed0 100644
--- a/src/Sockets.c
+++ b/src/Sockets.c
@@ -61,13 +61,13 @@ CCTK_FILEVERSION(CactusConnect_HTTPD_Sockets_c)
typedef enum {closed, open} httpSocketState;
-typedef struct HTTPSocket
+typedef struct HTTPSocketTag
{
- struct HTTPSocket *prev;
- struct HTTPSocket *next;
+ httpSocket *prev;
+ httpSocket *next;
unsigned long filedes;
httpSocketState state;
-} httpSocket;
+} httpSocket_PLACEHOLDER;
/********************************************************************
********************* Local Routine Prototypes *********************
@@ -101,6 +101,26 @@ static unsigned long int httpport = 0;
********************* External Routines **********************
********************************************************************/
+ /*@@
+ @routine HTTP_Send
+ @date 10.04.2004
+ @author Steve White
+ @desc
+ Writes all of an HTTP reply.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+int
+HTTP_Send( httpRequest * request, const char * message )
+{
+ return HTTP_Write(request, message, strlen(message));
+}
+
/*@@
@routine HTTP_SetupServer
@date Wed Sep 13 20:39:15 2000
@@ -203,13 +223,7 @@ int HTTP_ShutdownServer(void)
@@*/
int HTTP_Poll(cGH *cctkGH, long sec, long usec)
{
-#ifdef HAVE_SOCKLEN_T
- socklen_t size;
-#else
- int size;
-#endif
- SOCKET new;
- fd_set read_fd_set;
+ fd_set read_fd_set = active_fd_set;
struct sockaddr_in clientname;
struct timeval timeout;
httpSocket *this, *next;
@@ -219,7 +233,6 @@ int HTTP_Poll(cGH *cctkGH, long sec, long usec)
timeout.tv_usec = usec;
/* Check if any input is available on one or more active sockets. */
- read_fd_set = active_fd_set;
if (select (FD_SETSIZE, &read_fd_set, NULL, NULL, sec >= 0 ? &timeout : NULL)
== SOCKET_ERROR)
@@ -232,8 +245,12 @@ int HTTP_Poll(cGH *cctkGH, long sec, long usec)
if (FD_ISSET (sock, &read_fd_set))
{
/* Connection request on original socket. */
- size = sizeof (clientname);
- new = accept (sock, (struct sockaddr *) &clientname, &size);
+#ifdef HAVE_SOCKLEN_T
+ socklen_t size = sizeof (clientname);
+#else
+ int size = sizeof (clientname);
+#endif
+ SOCKET new = accept (sock, (struct sockaddr *) &clientname, &size);
if (new == INVALID_SOCKET)
{
perror ("accept");
@@ -253,15 +270,17 @@ int HTTP_Poll(cGH *cctkGH, long sec, long usec)
}
}
- for(this = socklist; this; this = next)
+ this = socklist;
+ while( this )
{
- next = this->next;
+ httpSocket *next = this->next;
/* Data arriving on an already-connected socket. */
if (FD_ISSET (this->filedes, &read_fd_set) &&
HTTP_ReadFromClient (cctkGH, this) < 0)
{
SocketDestroy(this);
}
+ this = next;
}
return (0);
@@ -287,7 +306,7 @@ int HTTP_Write(httpRequest *request, const char *buffer, size_t count)
int retval = -1;
size_t bytes_sent = 0;
size_t halfcount;
- httpSocket *connection = (httpSocket *)request->connection;
+ httpSocket *connection = HTTP_Connection( request);
int done = 0;
int tmp;
fd_set this_set;
@@ -427,7 +446,7 @@ int HTTP_Read(httpRequest *request, char *buffer, size_t count)
{
int retval = -1;
- httpSocket *connection = (httpSocket *)request->connection;
+ httpSocket *connection = HTTP_Connection( request );
if(connection->state == open)
{
diff --git a/src/Startup.c b/src/Startup.c
index 6d88dc5..1ca6bef 100644
--- a/src/Startup.c
+++ b/src/Startup.c
@@ -22,8 +22,8 @@
#include "cctk_Parameters.h"
#include "httpd.h"
-#include "http_Steer.h"
-#include "http_Redirect.h"
+#include "Steer.h"
+#include "Redirect.h"
static const char *rcsid = "$Header$";
diff --git a/src/Steer.c b/src/Steer.c
index 8556777..4d2c379 100644
--- a/src/Steer.c
+++ b/src/Steer.c
@@ -29,7 +29,7 @@
#include "cctk_Parameter.h"
#endif
-#include "http_Steer.h"
+#include "Steer.h"
static const char *rcsid = "$Header$";
@@ -84,7 +84,7 @@ static pthread_mutex_t steer_mutex = PTHREAD_MUTEX_INITIALIZER;
@@*/
int HTTP_SteerQueue(const char *thorn, const char *parameter, const char *value)
{
- int retval = -1;
+ int retval = 0;
int buffer_length = 0;
int parameter_length = 0;
@@ -105,8 +105,9 @@ int HTTP_SteerQueue(const char *thorn, const char *parameter, const char *value)
{
queuebuffer = tmp;
queuebuffer_size = buffer_length+parameter_length+1;
- retval = 0;
}
+ else
+ retval = -1;
}
if(!retval)
diff --git a/src/http_Steer.h b/src/Steer.h
index 3c02842..3896e95 100644
--- a/src/http_Steer.h
+++ b/src/Steer.h
@@ -1,9 +1,10 @@
/*@@
- @header http_Steer.h
+ @header Steer.h
@date Fri Sep 15 11:31:04 2000
@author Tom Goodale
@desc
- Webserver parameter steering routines.
+ Webserver parameter steering routines. Was http_Steer.h; still exported
+ by that name
@enddesc
@version $Header$
@@*/
@@ -16,7 +17,8 @@ extern "C"
{
#endif
-int HTTP_SteerQueue(const char *thorn, const char *parameter, const char *value);
+int HTTP_SteerQueue(const char *thorn, const char *parameter,
+ const char *value);
int HTTP_SteerDispatch(void);
diff --git a/src/Thorns.c b/src/Thorns.c
index 5b10a8c..91a1a07 100644
--- a/src/Thorns.c
+++ b/src/Thorns.c
@@ -9,15 +9,13 @@
@@*/
#include <stdio.h>
-#include <string.h>
#include "cctk.h"
#include "util_String.h"
-#include "http_Request.h"
-#include "http_Content.h"
-#include "http_SString.h"
+#include "httpRequest.h"
+#include "Content.h"
#include "SString_Namespace.h"
#include "SStringHTML_Namespace.h"
@@ -69,9 +67,7 @@ int HTTPi_RegisterThornPages(void);
int HTTPi_RegisterThornPages(void)
{
int i;
- char pagename[THORN_NAME_MAXLENGTH];
- char *namecopy;
- const char *thorn;
+ char pagename[THORN_NAME_MAXLENGTH] = { '\0' };
/* Register the group info page. */
HTTP_RegisterPage("/Thorns", ThornMainPage, NULL);
@@ -82,11 +78,11 @@ int HTTPi_RegisterThornPages(void)
for (i = 0; i < CCTK_NumCompiledThorns (); i++)
{
- thorn = CCTK_CompiledThorn(i);
+ const char *thorn = CCTK_CompiledThorn(i);
sprintf(pagename,"/Thorns/%s", thorn);
- namecopy = Util_Strdup(thorn); /*SW isn't this a memory leak?*/
+ char *namecopy = Util_Strdup(thorn); /*SW isn't this a memory leak?*/
HTTP_RegisterPage(pagename, ThornPage, namecopy);
}
@@ -117,38 +113,36 @@ static int ThornMainPage(const cGH *cctkGH, httpRequest *request, void *data)
{
int i;
int retval = -1;
- int foundone;
+ int foundone = 0;
const char *thorn;
String *message = String_New();
/* avoid compiler warning about unused parameter */
data = data;
- SendHTTP_OK_Header( request );
+ HTTP_Send_OK_Header( request );
- SetHTML_Doctype( message );
- Send_HTTP_String(request, message);
+ HTTP_SetDoctype( message );
+ HTTP_SendString(request, message);
/* Start the page */
- Send_HTTP(request,"<html><head><title>Cactus Thorns</title>\n");
+ HTTP_Send(request, "<html><head><title>Cactus Thorns</title>\n");
- SetHTML_HeadHeader( message);
- Send_HTTP_String(request, message );
+ HTTP_SetHeadInfo( message);
+ HTTP_SendString(request, message );
- Send_HTTP(request,"</head>\n<body>\n");
+ HTTP_Send(request,"</head>\n<body>\n");
- /* Send_HTTP_String out the header part. */
+ /* HTTP_SendString out the header part. */
- SetHTML_ContentHeader(cctkGH,0,message,NULL);
+ HTTP_SetContentHeaderString(cctkGH,0,message,NULL);
- retval = Send_HTTP_String(request, message);
+ retval = HTTP_SendString(request, message);
- retval = Send_HTTP(request, "<h1>Thorns</h1>\n"
+ retval = HTTP_Send(request, "<h1>Thorns</h1>\n"
"<p>These pages describe the thorns used in this simulation.</p>\n");
+ retval = HTTP_Send(request, "<table><tr><td>\n");
- retval = Send_HTTP(request,"<table><tr><td>\n");
-
- foundone = 0;
for (i = 0; i < CCTK_NumCompiledThorns (); i++)
{
thorn = CCTK_CompiledThorn (i);
@@ -156,7 +150,7 @@ static int ThornMainPage(const cGH *cctkGH, httpRequest *request, void *data)
{
if (!foundone)
{
- Send_HTTP(request,
+ HTTP_Send(request,
"<h2>Active Thorns</h2>\n"
"<div class=\"center\">\n"
"<table class=\"thorns\" cellspacing=\"0\" cellpadding=\"5\">\n"
@@ -173,16 +167,16 @@ static int ThornMainPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message, "</a></td>\n<td>");
ConcatCString(message, CCTK_ThornImplementation(thorn));
ConcatCString(message, "</td>\n</tr>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
}
}
if (foundone)
{
- Send_HTTP(request,"</table></div>\n");
+ HTTP_Send(request,"</table></div>\n");
}
- retval = Send_HTTP(request,"</td><td>");
+ retval = HTTP_Send(request,"</td><td>");
foundone = 0;
for (i = 0; i < CCTK_NumCompiledThorns (); i++)
@@ -193,7 +187,7 @@ static int ThornMainPage(const cGH *cctkGH, httpRequest *request, void *data)
if (!foundone)
{
- Send_HTTP(request,
+ HTTP_Send(request,
"<h2>Dormant Thorns</h2>\n"
"<div class=\"centered\">\n"
"<table class=\"thorns\" cellspacing=\"0\" cellpadding=\"5\">\n"
@@ -209,22 +203,22 @@ static int ThornMainPage(const cGH *cctkGH, httpRequest *request, void *data)
ConcatCString(message, "</td>\n<td>");
ConcatCString(message, CCTK_ThornImplementation(thorn));
ConcatCString(message, "</td>\n</tr>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
}
}
if (foundone)
{
- Send_HTTP(request,"</table>\n</div>\n");
+ HTTP_Send(request,"</table>\n</div>\n");
}
- retval = Send_HTTP(request,"</td>\n</tr>\n</table>\n");
+ retval = HTTP_Send(request,"</td>\n</tr>\n</table>\n");
/* Write out the footer part. */
- SetHTML_ContentFooter(cctkGH,0,message);
- retval = Send_HTTP_String(request, message);
+ HTTP_SetContentFooterString(cctkGH,0,message);
+ retval = HTTP_SendString(request, message);
String_Delete( message );
return retval;
@@ -252,48 +246,49 @@ static int ThornPage(const cGH *cctkGH, httpRequest *request, void *data)
String *message = String_New();
const char *thorn = (const char *)data;
- SendHTTP_OK_Header(request);
+ HTTP_Send_OK_Header(request);
- SetHTML_Doctype( message );
- Send_HTTP_String(request, message);
+ HTTP_SetDoctype( message );
+ HTTP_SendString(request, message);
/* Start the page */
SetToCString(message, "<html>\n<head>\n<title>Thorn Page : ");
ConcatCString(message, thorn);
ConcatCString(message, "</title>\n");
- Send_HTTP_String(request, message);
- SetHTML_HeadHeader( message);
- Send_HTTP_String(request, message );
+ HTTP_SendString(request, message);
+ HTTP_SetHeadInfo( message);
+ HTTP_SendString(request, message );
- Send_HTTP(request,"</head>\n<body>\n");
+ HTTP_Send(request,"</head>\n<body>\n");
- SetHTML_ContentHeader(cctkGH,0,message,NULL);
+ HTTP_SetContentHeaderString(cctkGH,0,message,NULL);
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
SetToCString(message, "<h1>Thorn ");
ConcatCString(message, thorn);
ConcatCString(message, "</h1>\n");
- Send_HTTP_String(request, message);
+ HTTP_SendString(request, message);
- SetToCString(message,"<p>This page will include all the information about thorn \'");
+ SetToCString(message,"<p>This page will include all the information about "
+ "thorn \'");
ConcatCString(message, thorn);
- ConcatCString(message,
- "\'.\n For now, only information about the parameters is given.</p>\n");
+ ConcatCString(message, "\'.\n For now, only information about the parameters"
+ " is given.</p>\n");
ConcatCString(message, "<ul>\n"
- "<li><a href=\"/Parameters/");
+ "<li><a href=\"/Parameters/");
ConcatCString(message, thorn );
ConcatCString(message, "\">Parameters</a></li>\n"
- "</ul>\n");
- Send_HTTP_String(request, message);
+ "</ul>\n");
+ HTTP_SendString(request, message);
/* Write out the footer part. */
- SetHTML_ContentFooter(cctkGH, 0, message);
- retval = Send_HTTP_String(request, message);
+ HTTP_SetContentFooterString(cctkGH, 0, message);
+ retval = HTTP_SendString(request, message);
String_Delete( message );
return retval;
diff --git a/src/http.c b/src/http.c
index 4520d73..00989c5 100644
--- a/src/http.c
+++ b/src/http.c
@@ -12,7 +12,6 @@
#include "cctk_Parameters.h"
#include <stdio.h>
-#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_SYS_TIME_H
@@ -33,6 +32,8 @@
#include "util_String.h"
#include "httpd.h"
+#include "util_Hash.h"
+#include "SString_Namespace.h"
static const char *rcsid = "$Header$";
@@ -42,6 +43,115 @@ CCTK_FILEVERSION(CactusConnect_HTTPD_http_c)
********************* Local Data Types ***********************
********************************************************************/
+typedef struct HTTPArg
+{
+ /* Public data */
+ char *arg;
+ char *value;
+
+ /* Private data */
+ struct HTTPArg *next;
+ struct HTTPArg *all_next;
+} httpArg_PLACEHOLDER;
+
+/* This is the main structure for storing data about a request. */
+typedef struct httpRequestTag
+{
+ /* Public members of the structure. */
+ char *body; /* The body of the request */
+ int body_length; /* How long the body is */
+
+ const char *method; /* The HTTP method */
+ char *uri; /* The URI */
+ const char *residual; /* What's left of the URI after subtracting the found page */
+
+ /* HTTP version numbers */
+ int http_major_version;
+ int http_minor_version;
+
+ /* How many arguments there are */
+ int n_arguments;
+
+ /* These are all private members of this structure */
+
+ /* The connection data */
+ void *connection;
+
+ /* The request header lines */
+ uHash *headers;
+
+ /* Stuff for arguments */
+
+ /* First a hash table to look the data up quickly */
+ uHash *arguments;
+
+ /* Now a linked list to allow walking. */
+ httpArg *firstarg;
+ httpArg *lastarg;
+ httpArg *currentarg;
+
+} httpRequest_PLACEHOLDER;
+
+#define BLANK_HTTPREQUEST {NULL, 0, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
+ /* Accessors for the httpRequest structure */
+unsigned int HTTP_Major_Version( const httpRequest *request )
+{
+ return request->http_major_version;
+}
+
+unsigned int HTTP_Minor_Version( const httpRequest *request )
+{
+ return request->http_minor_version;
+}
+
+unsigned int HTTP_Num_Arguments( const httpRequest *request )
+{
+ return request->n_arguments;
+}
+
+const char * HTTP_URI( const httpRequest *request )
+{
+ return request->uri;
+}
+
+const char * HTTP_Residual( const httpRequest *request )
+{
+ return request->residual;
+}
+
+void HTTP_SetResidual( httpRequest *request, const char *residual )
+{
+ request->residual = residual;
+}
+
+const char * HTTP_Arg_Value( const httpArg *arg )
+{
+ return arg->value;
+}
+
+const char * HTTP_Arg_Name( const httpArg *arg )
+{
+ return arg->arg;
+}
+
+httpSocket * HTTP_Connection( const httpRequest *request )
+{
+ return request->connection;
+}
+
+SSBOOL HTTP_GetHeaderValueString(const httpRequest *request,
+ const String *header, String *value)
+{
+ const char * v = HTTP_HeaderValue(request, GetBuffer( header ) );
+ if( v )
+ {
+ SetToCString( value, v );
+ return SSTRUE;
+ }
+ else
+ return SSFALSE;
+}
+
struct httpHeader
{
char *line;
@@ -52,13 +162,14 @@ struct httpHeader
********************************************************************/
static char *NextLine(char *buffer, int *start, int size);
-static int DealWithRequest(cGH *cctkGH, httpRequest *request, char *buffer, int bufsize);
-static int AddHeader(httpRequest *request, const char *line);
+static int DealWithRequest(cGH *cctkGH, httpRequest *request, char *buffer,
+ int bufsize);
+static int AddHeader(httpRequest *request, const char *line);
-static int StripArgs(httpRequest *request, char *request_uri);
+static int StripArgs(httpRequest *request, char *request_uri);
static void Decode(char *string);
-static int InitialiseRequest(httpRequest *request);
-static int ClearRequest(httpRequest *request);
+static int InitialiseRequest(httpRequest *request);
+static int ClearRequest(httpRequest *request);
static void DestroyHeader(struct httpHeader *header);
static void DestroyArgument(httpArg *argument);
@@ -588,9 +699,6 @@ static int AddHeader(httpRequest *request, const char *line)
static int StripArgs(httpRequest *request, char *request_uri)
{
char *position;
- char *token;
- httpArg *argument;
- httpArg *stored;
/* Do we have arguments ? */
if((position = strchr(request_uri, '?')))
{
@@ -603,7 +711,7 @@ static int StripArgs(httpRequest *request, char *request_uri)
/* Parse the argument list */
position++;
- token = strtok(position, "&");
+ char *token = strtok(position, "&");
while(token)
{
@@ -619,11 +727,13 @@ static int StripArgs(httpRequest *request, char *request_uri)
Decode(token);
Decode(value);
- argument = (httpArg *)malloc(sizeof(httpArg));
+ httpArg *argument = (httpArg *)malloc(sizeof(httpArg));
if(argument)
{
httpArg *last = NULL;
+ httpArg *stored;
+
argument->next = NULL;
argument->all_next = NULL;
argument->arg = Util_Strdup(token);
diff --git a/src/httpRequest.h b/src/httpRequest.h
new file mode 100644
index 0000000..662040b
--- /dev/null
+++ b/src/httpRequest.h
@@ -0,0 +1,59 @@
+ /*@@
+ @header httpRequest.h
+ @date Wed Sep 13 23:49:30 2000
+ @author Tom Goodale
+ @desc
+ Was http_Request.h
+ @enddesc
+ @version $Header$
+ @@*/
+
+
+#ifndef __HTTP_REQUEST_H__
+#define __HTTP_REQUEST_H__ 1
+
+typedef struct HTTPSocketTag httpSocket;
+typedef struct HTTPArg httpArg;
+/* This is the main structure for storing data about a request. */
+typedef struct httpRequestTag httpRequest;
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+int HTTP_RegisterPage(const char *path,
+ int (*function)(const cGH *, httpRequest *, void *),
+ void *data);
+
+const char *HTTP_ArgumentValue(const httpRequest *request, const char *arg);
+const httpArg *HTTP_ArgumentWalk(httpRequest *request, int first);
+
+const char *HTTP_HeaderValue(const httpRequest *request, const char *header);
+
+int HTTP_Write(httpRequest *request, const char *buffer, size_t count);
+int HTTP_Read(httpRequest *request, char *buffer, size_t count);
+
+int HTTP_Send( httpRequest *request, const char * message );
+void HTTP_Send_OK_Header( httpRequest *request);
+
+unsigned long int HTTP_Port(void);
+
+unsigned int HTTP_Major_Version( const httpRequest *request );
+unsigned int HTTP_Minor_Version( const httpRequest *request );
+const char * HTTP_URI( const httpRequest *request );
+void HTTP_SetResidual( httpRequest *request, const char *residual );
+const char * HTTP_Residual( const httpRequest *request );
+unsigned int HTTP_Num_Arguments( const httpRequest *request );
+const char * HTTP_Get_Argument( const httpRequest *request, unsigned int index );
+httpSocket * HTTP_Connection( const httpRequest *request );
+const char * HTTP_Arg_Name( const httpArg *arg );
+const char * HTTP_Arg_Value( const httpArg *arg );
+#ifdef __cplusplus
+}
+
+#endif
+#include "httpSString.h"
+
+#endif /* __HTTP_REQUEST_H__ */
diff --git a/src/http_SString.h b/src/httpSString.h
index 091a1a6..170261d 100644
--- a/src/http_SString.h
+++ b/src/httpSString.h
@@ -20,10 +20,9 @@ extern "C"
{
#endif
-void SetHTML_Doctype( String *header);
-void SetHTML_HeadHeader( String *header);
-
-int Send_HTTP_String(httpRequest *request, const String* message);
+int HTTP_SendString(httpRequest *request, const String* message);
+SSBOOL HTTP_GetHeaderValueString(const httpRequest *request,
+ const String *header, String *value);
#ifdef __cplusplus
}
#endif
diff --git a/src/http_Content.h b/src/http_Content.h
deleted file mode 100644
index 307da99..0000000
--- a/src/http_Content.h
+++ /dev/null
@@ -1,43 +0,0 @@
- /*@@
- @header http_Content.h
- @date Sun Sep 17 14:19:23 2000
- @author Tom Goodale
- @desc
- Routines exported by the Content stuff.
- @enddesc
- @version $Header$
- @@*/
-
-#ifndef __HTTP_CONTENT_H__
-#define __HTTP_CONTENT_H__ 1
-
-#define HTTP_QUICKLINK 1
-
-#include "SString.h"
-
-#define EMPTYSTRING {'\0'}
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-int HTTP_ContentLink(const char *URL,
- const char *name,
- const char *description,
- int flags);
-
-int HTTP_ContentSendFromFile(httpRequest *request,
- int filedes);
-
-int SetHTML_ContentHeader(const cGH *cctkGH, int choice, String *mess,
- const String *menu);
-int SetHTML_ContentFooter(const cGH *cctkGH, int choice, String *mess);
-
-void SendHTTP_OK_Header(httpRequest *request);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __HTTP_CONENT_H__ */
diff --git a/src/http_Request.h b/src/http_Request.h
deleted file mode 100644
index e74e756..0000000
--- a/src/http_Request.h
+++ /dev/null
@@ -1,91 +0,0 @@
- /*@@
- @header http_Request.h
- @date Wed Sep 13 23:49:30 2000
- @author Tom Goodale
- @desc
-
- @enddesc
- @version $Header$
- @@*/
-
-#include "util_Hash.h"
-
-#ifndef __HTTP_REQUEST_H__
-#define __HTTP_REQUEST_H__ 1
-
-typedef struct HTTPArg
-{
- /* Public data */
- char *arg;
- char *value;
-
- /* Private data */
- struct HTTPArg *next;
- struct HTTPArg *all_next;
-} httpArg;
-
-/* This is the main structure for storing data about a request. */
-typedef struct
-{
- /* Public members of the structure. */
- char *body; /* The body of the request */
- int body_length; /* How long the body is */
-
- char *method; /* The HTTP method */
- char *uri; /* The URI */
- char *residual; /* What's left of the URI after subtracting the found page */
-
- /* HTTP version numbers */
- int http_major_version;
- int http_minor_version;
-
- /* How many arguments there are */
- int n_arguments;
-
- /* These are all private members of this structure */
-
- /* The connection data */
- void *connection;
-
- /* The request header lines */
- uHash *headers;
-
- /* Stuff for arguments */
-
- /* First a hash table to look the data up quickly */
- uHash *arguments;
-
- /* Now a linked list to allow walking. */
- httpArg *firstarg;
- httpArg *lastarg;
- httpArg *currentarg;
-
-} httpRequest;
-
-#define BLANK_HTTPREQUEST {NULL, 0, NULL, NULL, NULL, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-int HTTP_RegisterPage(const char *path, int (*function)(const cGH *, httpRequest *, void *), void *data);
-
-const char *HTTP_ArgumentValue(const httpRequest *request, const char *arg);
-
-const httpArg *HTTP_ArgumentWalk(httpRequest *request, int first);
-
-const char *HTTP_HeaderValue(const httpRequest *request, const char *header);
-
-int HTTP_Write(httpRequest *request, const char *buffer, size_t count);
-int HTTP_Read(httpRequest *request, char *buffer, size_t count);
-
-int Send_HTTP( httpRequest *request, const char * message );
-
-unsigned long int HTTP_Port(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __HTTP_REQUEST_H__ */
diff --git a/src/httpd.h b/src/httpd.h
index 5ddc4b8..0c3d42f 100644
--- a/src/httpd.h
+++ b/src/httpd.h
@@ -8,7 +8,7 @@
@version $Header$
@@*/
-#include "http_Request.h"
+#include "httpRequest.h"
#ifndef __HTTPD_H__
#define __HTTPD_H__ 1