From 2985e4a0702f0e2b67a18be4d214ac8d2ad9be8a Mon Sep 17 00:00:00 2001 From: swhite Date: Fri, 16 Apr 2004 11:42:08 +0000 Subject: Addresses Cactus bug 907 Added ability to send HTTP Refresh header: HTTP_Send_OK_Refresh_Header Added parameter HTTP::refresh_seconds Made main content window to respond to refresh parameter setting Also Minor improvements to String module Fixed variable decarations after executable code in a block. git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPD/trunk@193 1faa4e14-9dd3-4be0-9f0e-ffe519881164 --- param.ccl | 5 +++++ src/Content.c | 20 +++++++++++++++++--- src/Expression.c | 5 +++-- src/Parameters.c | 3 ++- src/SString.c | 20 +++++++++++++------- src/SString.h | 7 ++++--- src/SString_Namespace.h | 10 ++++++++-- src/Thorns.c | 3 ++- src/http.c | 3 ++- src/httpRequest.h | 1 + 10 files changed, 57 insertions(+), 20 deletions(-) diff --git a/param.ccl b/param.ccl index 7e495b6..abb0d14 100644 --- a/param.ccl +++ b/param.ccl @@ -82,6 +82,11 @@ INT queue_length "Listen queue length" 1: :: "Any positive number" } 4 +INT refresh_seconds "Page refresh time seconds" STEERABLE = ALWAYS +{ + -1: :: "-1 for no refresh, 0 for immediate refresh" +} -1 + ################################################################### # You probably don't want to set this in a parameter file diff --git a/src/Content.c b/src/Content.c index 357c04d..b32c516 100644 --- a/src/Content.c +++ b/src/Content.c @@ -122,13 +122,27 @@ HTTP_SendString( httpRequest *request, const String * message ) void HTTP_Send_OK_Header( httpRequest *request ) +{ + HTTP_Send_OK_Refresh_Header( request, -1 ); +} + +void +HTTP_Send_OK_Refresh_Header( httpRequest *request, int secs ) { /* 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"); + + if( secs >= 0 ) + { + String * timeString = String_Make( "Refresh: " ); + ConcatDecimal( timeString, secs ); + ConcatCString( timeString, "\r\n" ); + HTTP_SendString( request, timeString ); + String_Delete( timeString ); + } + HTTP_Send( request, "\r\n" ); } void @@ -375,7 +389,7 @@ static int MainPage(const cGH *cctkGH, httpRequest *request, void *data) /* avoid compiler warning about unused parameter */ data = data; - HTTP_Send_OK_Header( request ); + HTTP_Send_OK_Refresh_Header( request, refresh_seconds ); HTTP_SetDoctype( message ); HTTP_SendString(request, message); diff --git a/src/Expression.c b/src/Expression.c index 174698e..883efb2 100644 --- a/src/Expression.c +++ b/src/Expression.c @@ -194,11 +194,12 @@ static pToken *Tokenise(const char *expression) while(*tokenstart) { + const char *tokenend = NULL; + const char *position; /* Remove leading whitespace */ for(; *tokenstart == ' ' || *tokenstart == '\t'; tokenstart++); - const char *tokenend = NULL; - const char *position = tokenstart; + position = tokenstart; for(position=tokenstart; *position && *(position+1); position++) { diff --git a/src/Parameters.c b/src/Parameters.c index 020e538..084a27e 100644 --- a/src/Parameters.c +++ b/src/Parameters.c @@ -604,10 +604,11 @@ static int ThornParameterPage(const cGH *cctkGH, httpRequest *request, void *dat while(CCTK_ParameterWalk(first, thorn, NULL, &pData) == 0) { + char *value; first = 0; Truncate(message,0); - char *value = CCTK_ParameterValString (pData->name, pData->thorn); + value = CCTK_ParameterValString (pData->name, pData->thorn); if(value) { if (!(pData->steerable == CCTK_STEERABLE_ALWAYS)) diff --git a/src/SString.c b/src/SString.c index b0b1477..a72a576 100644 --- a/src/SString.c +++ b/src/SString.c @@ -337,14 +337,20 @@ StringEquals( const String * a, const String * b ) int StringCompare( const String * a, const String * b ) { - const size_t length = MIN( a->length, b->length ); + return StringCompareCString( a, b->chars ); +} - if( length > 0 ) - return strncmp( a->chars, b->chars, length ) <= 0; - else if( b->chars == 0 ) - return SSTRUE; +int +StringCompareCString( const String * a, const char * b ) +{ + const size_t length = MIN( a->length, strlen( b ) ); - return SSFALSE; + if( length > 0 ) + return strncmp( a->chars, b, length ); + else if( strlen( b ) == 0 ) + return 0; + else /* b is empty but a isn't */ + return 1; } String * @@ -432,7 +438,7 @@ StringConcat( String * s, const String * other ) * On unix the default \n works; on the Mac, you might want \r */ void -String_SetLineEndCharacter( String * s, const SSCHAR *end ) +StringSetLineEndCharacter( String * s, const SSCHAR *end ) { strncpy( s->line_end, end, LINE_END_BUFSIZE ); s->line_end[LINE_END_BUFSIZE - 1] = '\0'; diff --git a/src/SString.h b/src/SString.h index 8be38ee..81c6c85 100644 --- a/src/SString.h +++ b/src/SString.h @@ -22,7 +22,7 @@ typedef char SSCHAR; /* but could be Unicode */ typedef enum { SSFALSE, SSTRUE } SSBOOL; /* String creation and deletion */ -String *String_New(); +String *String_New( void ); String *String_Copy( const String *other ); String *String_Make( const SSCHAR *other ); void String_Delete( String * ); @@ -40,6 +40,7 @@ String * StringSetToPartAfter( String *dest, const String *source, /* Conversion to and from C string */ String * StringSetToCString( String *s, const SSCHAR *c_str ); String * StringConcatCString( String *s, const SSCHAR *c_str ); +int StringCompareCString( const String *s, const SSCHAR *c_str ); String * StringInsertCString( String * s, const char * c_str, size_t position ); String * StringSetToBuffer( String *s, const SSCHAR *buf, @@ -67,7 +68,7 @@ String * StringDeleteRange( String * s, size_t begin, size_t end ); String * StringTruncate( String *, size_t n ); String * StringTrimLeading( String *, size_t n ); /* For line reading and writing */ -void String_SetLineEndChars( String *str, const SSCHAR * ); +void StringSetLineEndChars( String *str, const SSCHAR * ); /* Printing to stdout */ void StringPrint( const String *str ); void StringFormatPrint( const String *str, const SSCHAR *format ); @@ -101,7 +102,7 @@ typedef enum SSINT_FORMAT_TAG #define SFMT_ALWAYS_POINT SFMT_ALT #define SFMT_DONT_TRIM_ZEROS SFMT_ALT -String * StringConcatFormattedInt( String *s, long int d, +String * StringConcatFormattedDecimal( 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 ); diff --git a/src/SString_Namespace.h b/src/SString_Namespace.h index 1ba9607..742d03f 100644 --- a/src/SString_Namespace.h +++ b/src/SString_Namespace.h @@ -25,6 +25,8 @@ StringInsertCString( a, b, c ) #define ConcatCString( a, b ) \ StringConcatCString( a, b ) +#define CompareCString( a, b ) \ + StringCompareCString( a, b ) #define SetToBuffer( a, b, l ) \ StringSetToBuffer( a, b, l ) #define GetBuffer( a ) \ @@ -47,8 +49,8 @@ StringSetNextToken( s, c, p, r ) #define Compare( a, b ) \ StringCompare( a, b ) -#define AreEqual( a, b ) \ - StringsAreEqual( a, b ) +#define Equals( a, b ) \ + StringEquals( a, b ) #define Insert( a, b, p ) \ StringInsert( a, b, p ) #define InsertChar( a, b, p ) \ @@ -67,6 +69,10 @@ StringConcatOctal( a, s ) #define ConcatDouble( a, s ) \ StringConcatDouble( a, s ) +#define ConcatFormattedDecimal( a, d, s1, s2, f ) \ + StringConcatFormattedDecimal( a, d, s1, s2, f ) +#define ConcatFormattedUnsigned( a, d, s1, s2, f ) \ + StringConcatFormattedUnsigned( a, d, s1, s2, f ) #define ConcatFormattedDouble( a, d, s1, s2, f ) \ StringConcatFormattedDouble( a, d, s1, s2, f ) diff --git a/src/Thorns.c b/src/Thorns.c index 91a1a07..b7c8463 100644 --- a/src/Thorns.c +++ b/src/Thorns.c @@ -79,10 +79,11 @@ int HTTPi_RegisterThornPages(void) for (i = 0; i < CCTK_NumCompiledThorns (); i++) { const char *thorn = CCTK_CompiledThorn(i); + char *namecopy; sprintf(pagename,"/Thorns/%s", thorn); - char *namecopy = Util_Strdup(thorn); /*SW isn't this a memory leak?*/ + namecopy = Util_Strdup(thorn); /*SW isn't this a memory leak?*/ HTTP_RegisterPage(pagename, ThornPage, namecopy); } diff --git a/src/http.c b/src/http.c index 00989c5..0aea4d5 100644 --- a/src/http.c +++ b/src/http.c @@ -702,6 +702,7 @@ static int StripArgs(httpRequest *request, char *request_uri) /* Do we have arguments ? */ if((position = strchr(request_uri, '?'))) { + char *token; /* Mark the end of the URI */ *position = 0; @@ -711,7 +712,7 @@ static int StripArgs(httpRequest *request, char *request_uri) /* Parse the argument list */ position++; - char *token = strtok(position, "&"); + token = strtok(position, "&"); while(token) { diff --git a/src/httpRequest.h b/src/httpRequest.h index 662040b..ebfa9d9 100644 --- a/src/httpRequest.h +++ b/src/httpRequest.h @@ -37,6 +37,7 @@ 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); +void HTTP_Send_OK_Refresh_Header( httpRequest *request, int secs ); unsigned long int HTTP_Port(void); -- cgit v1.2.3