aboutsummaryrefslogtreecommitdiff
path: root/src/Redirect.c
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/Redirect.c
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/Redirect.c')
-rw-r--r--src/Redirect.c320
1 files changed, 320 insertions, 0 deletions
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;
+}
+
+
+
+