aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgoodale <goodale@1faa4e14-9dd3-4be0-9f0e-ffe519881164>2001-05-18 09:35:49 +0000
committergoodale <goodale@1faa4e14-9dd3-4be0-9f0e-ffe519881164>2001-05-18 09:35:49 +0000
commitd8f1697495666e3a90f1a6e438ad7111469e2f6a (patch)
tree7cfa1a8a4b76a9602aed683fbe087597def3aaa0 /src
parent8b12a1b456d296db9c305a1f008dbf93f515301c (diff)
Moving John's redirection stuff into a file of its own as it is a logically
independent system. All files except Startup.c and make.code.defn should be pretty much back at their beta10 state if you're trying to track this change back in time. Redirect stuff is now in Redirect.c and http_Redirect.h. Tom git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPD/trunk@129 1faa4e14-9dd3-4be0-9f0e-ffe519881164
Diffstat (limited to 'src')
-rw-r--r--src/Content.c89
-rw-r--r--src/Redirect.c320
-rw-r--r--src/Sockets.c149
-rw-r--r--src/Startup.c19
-rw-r--r--src/http_Redirect.h34
-rw-r--r--src/http_Request.h4
-rw-r--r--src/httpd.h6
-rw-r--r--src/make.code.defn5
8 files changed, 369 insertions, 257 deletions
diff --git a/src/Content.c b/src/Content.c
index 2f2ffba..517202f 100644
--- a/src/Content.c
+++ b/src/Content.c
@@ -69,7 +69,6 @@ struct httpLink
static int RegisterImages(void);
-static int RedirectPage(cGH *cctkGH, httpRequest *request, void *data);
static int MainPage(cGH *cctkGH, httpRequest *request, void *data);
static int AboutPage(cGH *cctkGH, httpRequest *request, void *data);
@@ -88,7 +87,6 @@ static int CookieTestPage(cGH *cctkGH, httpRequest *request, void *data);
********************************************************************/
void HTTP_ContentWork(cGH *GH);
-int HTTP_RegisterRedirect(void);
int HTTP_RegisterPages(void);
int HTTPi_RegisterGroupsPages(void);
int HTTPi_RegisterThornPages(void);
@@ -193,29 +191,6 @@ int HTTP_RegisterPages(void)
}
/*@@
- @routine HTTP_RegisterRedirect
- @date Fri April 20 23:47:43 2001
- @author John Shalf
- @desc
- Redirection Page Registration.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
-@@*/
-int HTTP_RegisterRedirect(void){
- DECLARE_CCTK_PARAMETERS
-#ifdef HTTP_DEBUG
- printf("Registering Redirection Page");
-#endif
- HTTP_RegisterPage("/index.html",RedirectPage,NULL);
- RegisterImages();
-}
-
- /*@@
@routine HTTP_ContentLink
@date Sun Sep 17 13:17:56 2000
@author Tom Goodale
@@ -302,70 +277,6 @@ static int CompareStrings(const void *string1, const void *string2)
/*@@
- @routine RedirectPage
- @date Fri April 20 23:47:43 2001
- @author John Shalf
- @desc
- Redirects the webbrowser to the main server page
- @enddesc
- @calls
- @calledby
- @history
- @hdate Thu Sep 14 10:54:22 2000 @hauthor John Shalf
- @hdesc For clusters where its difficult to know which node is going to
- have the webserver process, this opens a port on *all* distinct nodes
- and redirects all web connection attempts to the root node for processing.
- @endhistory
-
-@@*/
-
-static int RedirectPage(cGH *cctkGH, httpRequest *request, void *data)
-{
-
- DECLARE_CCTK_PARAMETERS
-
- int retval;
- char message[10098];
- char title[4098];
- char menu[4098];
- char *dir;
- char *file;
- struct httpLink *hlink;
-
- /* avoid compiler warning about unused parameter */
- data = data;
-
- /* Status message */
- strcpy(message,"HTTP/1.0 200 OK\r\n");
-
- HTTP_Write(request, message, strlen(message));
-
- /* Content-Type */
- strcpy(message,"Content-Type: text/html\r\n\r\n");
-
- HTTP_Write(request, message, strlen(message));
-
- /* Start the page */
- strcpy(message,"<HTML><HEAD><TITLE>Server Redirect</TITLE>\n");
- /* Write out the main header part */
- HTTP_Write(request, message, strlen(message));
- sprintf(message,"<META http-equiv=\"refresh\" content=\"1; URL=http://%s:%u\"></HEAD><body>\n",
- HTTP_Master(),HTTP_Port());
- HTTP_Write(request,message,strlen(message));
- /* ********** Server Redirect To Master ************* */
- sprintf(message,"<p><h1>Redirect to master host=%s:%u</h1><p>\n",
- HTTP_Master(),HTTP_Port());
- HTTP_Write(request,message,strlen(message));
-
- HTTP_ContentFooter(cctkGH, 0, 4096, message);
- retval = HTTP_Write(request, message, strlen(message));
-
- /* retval = HTTP_Write(request, base_page, strlen(base_page)); */
-
- return retval;
-}
-
- /*@@
@routine MainPage
@date Wed Sep 13 23:47:43 2000
@author Tom Goodale
diff --git a/src/Redirect.c b/src/Redirect.c
new file mode 100644
index 0000000..ba04559
--- /dev/null
+++ b/src/Redirect.c
@@ -0,0 +1,320 @@
+ /*@@
+ @file Redirect.c
+ @date Fri May 18 10:03:15 2001
+ @author Tom Goodale
+ @desc
+ File to contain John Shalf's HTTP redirect stuff.
+ @enddesc
+ @version $Header$
+ @@*/
+
+#include "cctk.h"
+
+#include <stdio.h>
+
+#ifdef CCTK_MPI
+#include "mpi.h"
+#endif /* CCTK_MPI */
+
+#include "httpd.h"
+
+#include "http_Request.h"
+#include "http_Content.h"
+
+#include "http_Redirect.h"
+
+static const char *rcsid = "$Header$";
+
+CCTK_FILEVERSION(CactusConnect_HTTPD_Redirect_c)
+
+/********************************************************************
+ ********************* Local Data Types ***********************
+ ********************************************************************/
+
+/********************************************************************
+ ********************* Local Routine Prototypes *********************
+ ********************************************************************/
+
+static int RegisterRedirect(void);
+static int RedirectPage(cGH *cctkGH, httpRequest *request, void *data);
+
+/********************************************************************
+ ********************* Other Routine Prototypes *********************
+ ********************************************************************/
+
+/********************************************************************
+ ********************* Local Data *****************************
+ ********************************************************************/
+
+static char httpredirect=0;
+static char httpmaster[1024];
+
+/********************************************************************
+ ********************* External Routines **********************
+ ********************************************************************/
+
+ /*@@
+ @routine HTTP_SetupRedirect
+ @date Wed April 20 20:39:15 2001
+ @author John Shalf
+ @desc
+ Creates a socket to listen on purely for server redirect to the root node.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+
+int HTTP_SetupRedirect(int port,
+ int queue_size,
+ int hunt)
+{
+ int retval;
+ /* should not hunt */
+ int i;
+ char hostnm[1024];
+ char *alladdr;
+ int addrlen;
+ int nprocs;
+ int proc;
+
+ addrlen = 1024;
+ nprocs = CCTK_nProcs(NULL);
+ proc = CCTK_MyProc(NULL);
+
+ retval = 0;
+
+ CCTK_INFO("enter setup redirect------------");
+ memset(hostnm,0,addrlen);
+ Util_GetHostName(hostnm, addrlen);
+ alladdr=(char*)malloc(addrlen * nprocs);
+ memset(alladdr,0,addrlen*nprocs); /* zero it */
+
+#ifdef CCTK_MPI
+ { /* push stack */
+ CCTK_INFO("all gather");
+
+ MPI_Allgather(hostnm,addrlen,MPI_CHAR,
+ alladdr,addrlen,MPI_CHAR,
+ MPI_COMM_WORLD);
+ CCTK_INFO("collected");
+ }
+#endif
+
+ /* set our master */
+ printf("alladdr is %s\n", alladdr);
+ strcpy(httpmaster,alladdr); /* the 0th element is the master hostname */
+
+ /* so compare my addr to the list sequentially */
+ for(i=0;i<nprocs;i++)
+ {
+ printf("Cycle through %u\n",i);
+ if(!strcmp(alladdr+i*addrlen,hostnm))
+ {
+ /* we matched addresses */
+ if(i<proc || i==0)
+ {
+ break; /* I'm not the lowest order */
+ }
+ else
+ {
+ /* otherwise, I am the lowest ranked processor with this
+ address that isn't the primary webserver. So
+ I should do a server redirect */
+ httpredirect=1; /* this has a redirect socket */
+ HTTP_SetupServer(port,queue_size,hunt);
+
+ RegisterRedirect();
+ retval = 1;
+ }
+ }
+ }
+ if(! retval)
+ {
+ CCTK_INFO("No Redirect**************\n");
+ httpredirect=0;
+ }
+
+ return retval;
+}
+
+ /*@@
+ @routine HTTP_Master
+ @date Friday April 20 11:24:40 2001
+ @author John Shalf
+ @desc
+ Reports the hostname of the node the HTTP server is listening on.
+ The returns the hostname of the master as a string.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+@@*/
+const char *HTTP_Master(void)
+{
+ return httpmaster;
+}
+
+ /*@@
+ @routine HTTP_IsServer
+ @date Friday April 20 11:24:40 2001
+ @author John Shalf
+ @desc
+ True if this node has a server socket open.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+@@*/
+int HTTP_IsServer(void)
+{
+ int retcode;
+
+ if(CCTK_MyProc(NULL)==0 || httpredirect)
+ {
+ retcode = 1;
+ }
+ else
+ {
+ retcode = 0;
+ }
+}
+
+ /*@@
+ @routine HTTP_IsRedirect
+ @date Friday April 20 11:24:40 2001
+ @author John Shalf
+ @desc
+ True only if this node has a server open and that server
+ is exclusively used to redirect web traffic back to the root
+ node.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+@@*/
+int HTTP_IsRedirect(void)
+{
+ return httpredirect;
+}
+
+
+#if 0 /* this would be more efficient, but PUGH doesn't define
+ a datatype for 8-byte integers. So instead,
+ setupRedirect will use the actual hostname. */
+CCTK_INT8 Util_GetHostAddr(char *hostname)
+{
+ hostent *he;
+ char hostname[1025];
+ int addrlen;
+ CCTK_INT8 addr;
+
+ Util_GetHostName(hostname, 1024);
+ he=gethostbyname(hostname);
+ addrlen=he->h_length;
+ if(addrlen>sizeof(CCTK_INT8)) addrlen=CCTK_INT8;
+ addr=0;
+ memcpy(&addr,he->h_addr,addrlen);
+ return addr;
+}
+#endif
+
+
+
+/********************************************************************
+ ********************* Local Routines *************************
+ ********************************************************************/
+
+ /*@@
+ @routine RegisterRedirect
+ @date Fri April 20 23:47:43 2001
+ @author John Shalf
+ @desc
+ Redirection Page Registration.
+ @enddesc
+ @calls
+ @calledby
+ @history
+
+ @endhistory
+
+@@*/
+static int RegisterRedirect(void)
+{
+#ifdef HTTP_DEBUG
+ printf("Registering Redirection Page");
+#endif
+ HTTP_RegisterPage("/index.html",RedirectPage,NULL);
+}
+
+ /*@@
+ @routine RedirectPage
+ @date Fri April 20 23:47:43 2001
+ @author John Shalf
+ @desc
+ Redirects the webbrowser to the main server page
+ @enddesc
+ @calls
+ @calledby
+ @history
+ @hdate Thu Sep 14 10:54:22 2000 @hauthor John Shalf
+ @hdesc For clusters where its difficult to know which node is going to
+ have the webserver process, this opens a port on *all* distinct nodes
+ and redirects all web connection attempts to the root node for processing.
+ @endhistory
+
+@@*/
+
+static int RedirectPage(cGH *cctkGH, httpRequest *request, void *data)
+{
+ int retval;
+ char message[10098];
+ char title[4098];
+ char menu[4098];
+ char *dir;
+ char *file;
+ struct httpLink *hlink;
+
+ /* avoid compiler warning about unused parameter */
+ data = data;
+
+ /* Status message */
+ strcpy(message,"HTTP/1.0 200 OK\r\n");
+
+ HTTP_Write(request, message, strlen(message));
+
+ /* Content-Type */
+ strcpy(message,"Content-Type: text/html\r\n\r\n");
+
+ HTTP_Write(request, message, strlen(message));
+
+ /* Start the page */
+ strcpy(message,"<HTML><HEAD><TITLE>Server Redirect</TITLE>\n");
+ /* Write out the main header part */
+ HTTP_Write(request, message, strlen(message));
+ sprintf(message,"<META http-equiv=\"refresh\" content=\"1; URL=http://%s:%u\"></HEAD><body>\n",
+ HTTP_Master(),HTTP_Port());
+ HTTP_Write(request,message,strlen(message));
+ /* ********** Server Redirect To Master ************* */
+ sprintf(message,"<p><h1>Redirect to master host=%s:%u</h1><p>\n",
+ HTTP_Master(),HTTP_Port());
+ HTTP_Write(request,message,strlen(message));
+
+ HTTP_ContentFooter(cctkGH, 0, 4096, message);
+ retval = HTTP_Write(request, message, strlen(message));
+
+ return retval;
+}
+
+
+
+
diff --git a/src/Sockets.c b/src/Sockets.c
index 93e8c8e..38a5ced 100644
--- a/src/Sockets.c
+++ b/src/Sockets.c
@@ -48,16 +48,9 @@
#include "httpd.h"
-#include "cctk.h"
-#include "cctk_DefineThorn.h"
-#include "cctk_Parameters.h"
-#ifdef CACTUSPUGH_PUGH
-#include "CactusPUGH/PUGH/src/include/pugh.h"
-#endif
-
static const char *rcsid = "$Header$";
-CCTK_FILEVERSION(CactusConnect_HTTPD_Socket_c)
+CCTK_FILEVERSION(CactusConnect_HTTPD_Sockets_c)
/********************************************************************
********************* Local Data Types ***********************
@@ -120,9 +113,8 @@ static fd_set active_fd_set;
static SOCKET sock;
static SOCKET minsock;
static SOCKET maxsock;
-static char httpredirect=0;
+
static httpSocket *socklist = NULL;
-static char httpmaster[1024];
static unsigned long int httpport = 0;
@@ -130,88 +122,6 @@ static unsigned long int httpport = 0;
********************* External Routines **********************
********************************************************************/
-#if 0 /* this would be more efficient, but PUGH doesn't define
- a datatype for 8-byte integers. So instead,
- setupRedirect will use the actual hostname. */
-CCTK_INT8 Util_GetHostAddr(char *hostname){
- hostent *he;
- char hostname[1025];
- int addrlen;
- CCTK_INT8 addr;
-
- Util_GetHostName(hostname, 1024);
- he=gethostbyname(hostname);
- addrlen=he->h_length;
- if(addrlen>sizeof(CCTK_INT8)) addrlen=CCTK_INT8;
- addr=0;
- memcpy(&addr,he->h_addr,addrlen);
- return addr;
-}
-#endif
-
- /*@@
- @routine HTTP_SetupRedirect
- @date Wed April 20 20:39:15 2001
- @author John Shalf
- @desc
- Creates a socket to listen on purely for server redirect to the root node.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-
-@@*/
-int HTTP_SetupRedirect(cGH *cctkGH,int port, int queue_size,int hunt){
- /* should not hunt */
- int i;
- char hostnm[1024];
- char *alladdr;
- int addrlen=1024;
- int nprocs=CCTK_nProcs(NULL);
- int proc=CCTK_MyProc(NULL);
-
- puts("enter setup redirect------------");
- memset(hostnm,0,addrlen);
- Util_GetHostName(hostnm, addrlen);
- alladdr=(char*)malloc(addrlen * nprocs);
- memset(alladdr,0,addrlen*nprocs); /* zero it */
-#ifdef CCTK_MPI
- { /* push stack */
- pGH *pughGH = PUGH_pGH(cctkGH);
- puts("all gather");
- if(!pughGH) puts("********would fail");
- MPI_Allgather(hostnm,addrlen,PUGH_MPI_CHAR,
- alladdr,addrlen,PUGH_MPI_CHAR,
- MPI_COMM_WORLD);
- /* pughGH->PUGH_COMM_WORLD); fails if I use PUGH_COMM_WORLD */
- puts("collected");
- }
-#endif
- /* set our master */
- printf("alladdr is %s\n", alladdr);
- strcpy(httpmaster,alladdr); /* the 0th element is the master hostname */
- /* so compare my addr to the list sequentially */
- for(i=0;i<nprocs;i++){
- printf("Cycle through %u\n",i);
- if(!strcmp(alladdr+i*addrlen,hostnm)){
- /* we matched addresses */
- if(i<proc || i==0) break; /* I'm not the lowest order */
- /* otherwise, I am the lowest ranked processor with this
- address that isn't the primary webserver. So
- I should do a server redirect */
- httpredirect=1; /* this has a redirect socket */
- HTTP_SetupServer(port,queue_size,hunt);
- HTTP_RegisterRedirect();
- return 1;
- }
- }
- printf("No Redirect**************\n");
- httpredirect=0;
- return 0; /* no registration performed */
-}
-
/*@@
@routine HTTP_SetupServer
@date Wed Sep 13 20:39:15 2000
@@ -598,61 +508,6 @@ unsigned long int HTTP_Port(void)
return httpport;
}
- /*@@
- @routine HTTP_Master
- @date Friday April 20 11:24:40 2001
- @author John Shalf
- @desc
- Reports the hostname of the node the HTTP server is listening on.
- The returns the hostname of the master as a string.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-@@*/
-char *HTTP_Master(void)
-{
- return httpmaster;
-}
-
- /*@@
- @routine HTTP_IsServer
- @date Friday April 20 11:24:40 2001
- @author John Shalf
- @desc
- True if this node has a server socket open.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-@@*/
-char HTTP_IsServer(void){
- if(CCTK_MyProc(NULL)==0 || httpredirect) return 1;
- else return 0;
-}
-
- /*@@
- @routine HTTP_IsRedirect
- @date Friday April 20 11:24:40 2001
- @author John Shalf
- @desc
- True only if this node has a server open and that server
- is exclusively used to redirect web traffic back to the root
- node.
- @enddesc
- @calls
- @calledby
- @history
-
- @endhistory
-@@*/
-char HTTP_IsRedirect(void){
- return httpredirect;
-}
/********************************************************************
********************* Local Routines *************************
********************************************************************/
diff --git a/src/Startup.c b/src/Startup.c
index a44c540..d87805e 100644
--- a/src/Startup.c
+++ b/src/Startup.c
@@ -23,6 +23,7 @@
#include "httpd.h"
#include "http_Steer.h"
+#include "http_Redirect.h"
static const char *rcsid = "$Header$";
@@ -45,7 +46,7 @@ static void HTTP_SetupPollingThread(cGH *cctkGH);
***************** Scheduled Routine Prototypes *********************
********************************************************************/
-int HTTP_Startup(CCTK_ARGUMENTS);
+int HTTP_Startup(void);
void HTTP_Work(CCTK_ARGUMENTS);
int HTTP_Shutdown(void);
@@ -82,13 +83,13 @@ static int thread_started = 0;
@endhistory
@@*/
-int HTTP_Startup(CCTK_ARGUMENTS)
+int HTTP_Startup(void)
{
DECLARE_CCTK_PARAMETERS
httpState state;
- if(CCTK_MyProc(NULL)==0)
+ if(CCTK_MyProc(NULL) == 0)
{
/* Does the server provide any pages by default ? */
if(provide_pages)
@@ -98,9 +99,9 @@ int HTTP_Startup(CCTK_ARGUMENTS)
HTTP_SetupServer(port, queue_length, hunt);
}
- else
- HTTP_RegisterRedirect();
- HTTP_SetupRedirect(cctkGH,port,queue_length,hunt);
+
+ /* Do we need to redirect to a master server ? */
+ HTTP_SetupRedirect(port,queue_length,hunt);
HTTP_UpdateState(NULL, &state);
@@ -207,14 +208,8 @@ int HTTP_Shutdown(void)
{
DECLARE_CCTK_PARAMETERS
#ifdef CCTK_PTHREADS
-<<<<<<< Startup.c
/* Wait for the polling thread to exit */
if(HTTP_IsServer() && use_pthreads && thread_started)
-=======
- /* Set the "HTTPD::terminate" parameter to flag termination
- to the polling thread and wait for it to exit */
- if(CCTK_MyProc(NULL) == 0 && use_pthreads && thread_started)
->>>>>>> 1.15
{
CCTK_ParameterSet("terminate", CCTK_THORNSTRING, "yes");
pthread_join(polling_thread, NULL);
diff --git a/src/http_Redirect.h b/src/http_Redirect.h
new file mode 100644
index 0000000..0cfad1a
--- /dev/null
+++ b/src/http_Redirect.h
@@ -0,0 +1,34 @@
+ /*@@
+ @header http_Redirect.h
+ @date Fri May 18 11:08:25 2001
+ @author Tom Goodale
+ @desc
+ Rdirection stuff.
+ @enddesc
+ @version
+ @@*/
+#ifndef _HTTP_REDIRECT_H_
+#define _HTTP_REDIRECT_H_ 1
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+int HTTP_SetupRedirect(int port,
+ int queue_size,
+ int hunt);
+
+int HTTP_RegisterRedirect(void);
+
+const char *HTTP_Master(void);
+int HTTP_IsServer(void);
+int HTTP_IsRedirect(void);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _HTTP_REDIRECT_H_ */
diff --git a/src/http_Request.h b/src/http_Request.h
index 6974e7f..cb2a4f5 100644
--- a/src/http_Request.h
+++ b/src/http_Request.h
@@ -79,10 +79,6 @@ int HTTP_Write(httpRequest *request, const char *buffer, size_t count);
int HTTP_Read(httpRequest *request, char *buffer, size_t count);
unsigned long int HTTP_Port(void);
-char* HTTP_Master(void);
- char HTTP_IsServer(void);
- char HTTP_IsRedirect(void);
- /* char HTTP_IsMaster(void); */
#ifdef __cplusplus
}
diff --git a/src/httpd.h b/src/httpd.h
index ef55686..ccdb967 100644
--- a/src/httpd.h
+++ b/src/httpd.h
@@ -10,8 +10,8 @@
#include "http_Request.h"
-#ifndef __HTTP_H__
-#define __HTTP_H__ 1
+#ifndef __HTTPD_H__
+#define __HTTPD_H__ 1
typedef struct
{
@@ -29,7 +29,6 @@ extern "C"
int HTTP_ReadFromClient (cGH *cctkGH, void *connection);
-
int HTTP_SetupServer(int port, int queue_size, int hunt);
int HTTP_ShutdownServer(void);
@@ -45,7 +44,6 @@ int HTTP_Terminate(cGH *cctkGH);
/* Content stuff */
int HTTP_RegisterPages(void);
-int HTTP_RegisterRedirect(void);
#ifdef __cplusplus
}
diff --git a/src/make.code.defn b/src/make.code.defn
index d18d185..869a536 100644
--- a/src/make.code.defn
+++ b/src/make.code.defn
@@ -15,12 +15,15 @@ AUTHENTICATION_SRC = Authorisation.c base64.c
COOKIES_SRC = Cookies.c
+REDIRECTION_SRC = Redirect.c
+
SRCS = $(MISC_SRC) \
$(SERVER_SRC) \
$(CONTENT_SRC) \
$(STEERING_SRC) \
$(AUTHENTICATION_SRC) \
- $(COOKIES_SRC)
+ $(COOKIES_SRC) \
+ $(REDIRECTION_SRC)
# set the _LIBC flag to prevent gcc warnings in base64.c
CFLAGS += -D_LIBC