diff options
Diffstat (limited to 'src/Parameters.c')
-rw-r--r-- | src/Parameters.c | 231 |
1 files changed, 110 insertions, 121 deletions
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,¶m_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,¶m_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 ); |