Created
March 15, 2015 15:38
-
-
Save acv/22ff3b4a64c8b10dc938 to your computer and use it in GitHub Desktop.
Difference between libhttpd 1.3 and 1.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -u -r libhttpd-1.3/HISTORY libhttpd-1.4/HISTORY | |
--- libhttpd-1.3/HISTORY 2002-11-24 21:30:05.000000000 -0500 | |
+++ libhttpd-1.4/HISTORY 2005-02-02 16:27:42.000000000 -0500 | |
@@ -1,4 +1,24 @@ | |
-Version 1.3 25 Nov 2002 | |
+Version 1.4 2 JFeb 2005 | |
+-------------------------- | |
+ | |
+* Fixed problem with the authentication routine prototypes | |
+ and return values from httpdAuthenticate | |
+ | |
+* Added support for custom error pages via the | |
+ httpdSetErrorFunction() api entry. | |
+ | |
+* Added support for Ember callbacks for generation of dynamic | |
+ content | |
+ | |
+* Added variable expansion in all text/* content type pages. | |
+ | |
+* Added httpdSetVariableValue() api entry | |
+ | |
+* Added host header info to the request structure | |
+ | |
+ | |
+ | |
+Version 1.3 25 Oct 2002 | |
-------------------------- | |
* Fixed possible buffer overrun vulnerabilities | |
diff -u -r libhttpd-1.3/README libhttpd-1.4/README | |
--- libhttpd-1.3/README 2002-10-15 20:39:11.000000000 -0400 | |
+++ libhttpd-1.4/README 2005-02-01 16:54:31.000000000 -0500 | |
@@ -20,4 +20,8 @@ | |
This software is released under the GPL. If you wish to incorporate | |
this code in a commercial application then OEM licenses are available | |
-from Hughes Technology. Please email [email protected] for details. | |
+from Hughes Technologies. Royalty free OEM licenses can be purchased | |
+from the Hughes Technologies web site at | |
+ | |
+ http://www.Hughes.com.au/products/libhttpd/ | |
+ | |
diff -u -r libhttpd-1.3/Site.mm.in libhttpd-1.4/Site.mm.in | |
--- libhttpd-1.3/Site.mm.in 2002-02-26 00:41:18.000000000 -0500 | |
+++ libhttpd-1.4/Site.mm.in 2004-05-09 14:06:24.000000000 -0400 | |
@@ -34,8 +34,13 @@ | |
# Extra libraries if required | |
EXTRA_LIBS= | |
+EMBER_LIB= @EMBER_LIB@ | |
+ | |
# Any other CFlags required | |
EXTRA_CFLAGS= | |
-CFLAGS= -g -I$(TOP)/ -I/usr/local/include $(EXTRA_CFLAGS) -D$(OS_TYPE) | |
+# | |
+EMBER_INST_DIR= @EMBER_INSTALL_DIR@ | |
+ | |
+CFLAGS= -g -I$(TOP)/ -I/usr/local/include $(EXTRA_CFLAGS) -D$(OS_TYPE) -I$(EMBER_INST_DIR)/include | |
LDLIBS= -L/usr/local/lib -L$(TOP)/lib @LIBS@ $(EXTRA_LIBS) | |
diff -u -r libhttpd-1.3/configure.in libhttpd-1.4/configure.in | |
--- libhttpd-1.3/configure.in 2002-02-26 00:41:18.000000000 -0500 | |
+++ libhttpd-1.4/configure.in 2005-02-02 16:19:35.000000000 -0500 | |
@@ -8,8 +8,53 @@ | |
AC_DEFINE_UNQUOTED(VERSION, "$VERSION") | |
AC_SUBST(VERSION) | |
+ | |
echo "Configuring libhttpd" | |
+echo $ECHO_N "Do you want to include support for Ember scripts (n) : $ECHO_C" | |
+read EMBER | |
+if test "$EMBER." = "y." -o "$EMBER." = "Y." | |
+then | |
+ HAVE_EMBER="#define HAVE_EMBER" | |
+ echo "Ember support included" | |
+ echo $ECHO_N "checking for Ember... $ECHO_C" | |
+ if test -d /usr/local/ember | |
+ then | |
+ INST_DIR="/usr/local/ember" | |
+ fi | |
+ if test -d /usr/ember | |
+ then | |
+ INST_DIR="/usr/ember" | |
+ fi | |
+ if test -d /opt/ember | |
+ then | |
+ INST_DIR="/opt/ember" | |
+ fi | |
+ if test -d /usr/local/nk/ember | |
+ then | |
+ INST_DIR="/usr/local/nk/ember" | |
+ fi | |
+ if test -d /opt/nk/ember | |
+ then | |
+ INST_DIR="/opt/nk/ember" | |
+ fi | |
+ if test "$INST_DIR." = "." | |
+ then | |
+ echo "UNKNOWN" | |
+ echo "Can't find the installation directory" | |
+ $ECHO_N "Where is Ember installed? $ECHO_C" | |
+ read INST_DIR | |
+ fi | |
+ echo "found in $INST_DIR" | |
+ AC_DEFINE_UNQUOTED(HAVE_EMBER) | |
+ EMBER_LIB="-lember"; | |
+fi | |
+EMBER_INSTALL_DIR="$INST_DIR" | |
+AC_DEFINE_UNQUOTED(EMBER_INSTALL_DIR,$EMBER_INSTALL_DIR) | |
+AC_SUBST(HAVE_EMBER) | |
+AC_SUBST(EMBER_LIB) | |
+AC_SUBST(EMBER_INSTALL_DIR) | |
+ | |
AC_PROG_CC | |
if test "$ac_cv_prog_CC" = "gcc"; | |
then | |
diff -u -r libhttpd-1.3/src/Makefile.tmpl libhttpd-1.4/src/Makefile.tmpl | |
--- libhttpd-1.3/src/Makefile.tmpl 2002-10-10 01:04:10.000000000 -0400 | |
+++ libhttpd-1.4/src/Makefile.tmpl 2004-05-09 14:06:24.000000000 -0400 | |
@@ -1,3 +1,3 @@ | |
-!library_unix libhttpd.a protocol.c,api.c,version.c,ip_acl.c | |
+!library_unix libhttpd.a protocol.c,api.c,version.c,ip_acl.c,ember.c | |
!libinstall libhttpd.a /usr/local/lib/libhttpd.a 744 $(ROOT) | |
!install httpd.h /usr/local/include/httpd.h 744 $(ROOT) | |
diff -u -r libhttpd-1.3/src/api.c libhttpd-1.4/src/api.c | |
--- libhttpd-1.3/src/api.c 2002-11-24 21:15:51.000000000 -0500 | |
+++ libhttpd-1.4/src/api.c 2005-01-25 23:48:28.000000000 -0500 | |
@@ -14,7 +14,7 @@ | |
** connection with the use or performance of this software. | |
** | |
** | |
-** $Id: api.c,v 1.16 2002/11/25 02:15:51 bambi Exp $ | |
+** $Id: api.c,v 1.22 2005/01/26 04:48:28 bambi Exp $ | |
** | |
*/ | |
@@ -205,6 +205,29 @@ | |
return(0); | |
} | |
+ | |
+int httpdSetVariableValue(server, name, value) | |
+ httpd *server; | |
+ char *name, | |
+ *value; | |
+{ | |
+ httpVar *var; | |
+ | |
+ var = httpdGetVariableByName(server, name); | |
+ if (var) | |
+ { | |
+ if (var->value) | |
+ free(var->value); | |
+ var->value = strdup(value); | |
+ return(0); | |
+ } | |
+ else | |
+ { | |
+ return(httpdAddVariable(server,name,value)); | |
+ } | |
+} | |
+ | |
+ | |
httpd *httpdCreate(host, port) | |
char *host; | |
int port; | |
@@ -322,7 +345,7 @@ | |
int result; | |
fd_set fds; | |
struct sockaddr_in addr; | |
- size_t addrLen; | |
+ int addrLen; | |
char *ipaddr; | |
FD_ZERO(&fds); | |
@@ -504,6 +527,15 @@ | |
authBuf, HTTP_MAX_AUTH); | |
} | |
} | |
+ if (strncasecmp(buf,"Host: ",6) == 0) | |
+ { | |
+ cp = index(buf,':') + 2; | |
+ if(cp) | |
+ { | |
+ strncpy(server->request.host,cp, | |
+ HTTP_MAX_URL); | |
+ } | |
+ } | |
if (strncasecmp(buf,"Referer: ",9) == 0) | |
{ | |
cp = index(buf,':') + 2; | |
@@ -771,6 +803,31 @@ | |
return(0); | |
} | |
+int httpdAddEmberContect(server, dir, name, indexFlag, preload, script) | |
+ httpd *server; | |
+ char *dir; | |
+ char *name; | |
+ int (*preload)(); | |
+ char *script; | |
+{ | |
+ httpDir *dirPtr; | |
+ httpContent *newEntry; | |
+ | |
+ dirPtr = _httpd_findContentDir(server, dir, HTTP_TRUE); | |
+ newEntry = malloc(sizeof(httpContent)); | |
+ if (newEntry == NULL) | |
+ return(-1); | |
+ bzero(newEntry,sizeof(httpContent)); | |
+ newEntry->name = strdup(name); | |
+ newEntry->type = HTTP_EMBER_FUNCT; | |
+ newEntry->indexFlag = indexFlag; | |
+ newEntry->data = script; | |
+ newEntry->preload = preload; | |
+ newEntry->next = dirPtr->entries; | |
+ dirPtr->entries = newEntry; | |
+ return(0); | |
+} | |
+ | |
void httpdSendHeaders(server) | |
httpd *server; | |
{ | |
@@ -953,12 +1010,19 @@ | |
(entry->function)(server); | |
break; | |
+#ifdef HAVE_EMBER | |
+ case HTTP_EMBER_FUNCT: | |
+ case HTTP_EMBER_WILDCARD: | |
+ _httpd_executeEmber(server, entry->data); | |
+ break; | |
+#endif | |
+ | |
case HTTP_STATIC: | |
_httpd_sendStatic(server, entry->data); | |
break; | |
case HTTP_FILE: | |
- _httpd_sendFile(server, entry->path); | |
+ httpdSendFile(server, entry->path); | |
break; | |
case HTTP_WILDCARD: | |
@@ -985,7 +1049,7 @@ | |
server->errorLog = fp; | |
} | |
-void httpdAuthenticate(server, realm) | |
+int httpdAuthenticate(server, realm) | |
httpd *server; | |
char *realm; | |
{ | |
@@ -998,7 +1062,9 @@ | |
"WWW-Authenticate: Basic realm=\"%s\"\n", realm); | |
httpdAddHeader(server, buffer); | |
httpdOutput(server,"\n"); | |
+ return(0); | |
} | |
+ return(1); | |
} | |
@@ -1014,3 +1080,78 @@ | |
httpdAddHeader(server, buffer); | |
httpdOutput(server,"\n"); | |
} | |
+ | |
+ | |
+ | |
+int httpdSetErrorFunction(server, error, function) | |
+ httpd *server; | |
+ int error; | |
+ void (*function)(); | |
+{ | |
+ static char errBuf[80]; | |
+ | |
+ switch(error) | |
+ { | |
+ case 304: | |
+ server->errorFunction304 = function; | |
+ break; | |
+ case 403: | |
+ server->errorFunction403 = function; | |
+ break; | |
+ case 404: | |
+ server->errorFunction404 = function; | |
+ break; | |
+ default: | |
+ snprintf(errBuf, 80, | |
+ "Invalid error code (%d) for custom callback", | |
+ error); | |
+ _httpd_writeErrorLog(server,LEVEL_ERROR, errBuf); | |
+ return(-1); | |
+ break; | |
+ } | |
+ return(0); | |
+} | |
+ | |
+ | |
+ | |
+void httpdSendFile(server, path) | |
+ httpd *server; | |
+ char *path; | |
+{ | |
+ char *suffix; | |
+ struct stat sbuf; | |
+ | |
+ suffix = rindex(path, '.'); | |
+ if (suffix != NULL) | |
+ { | |
+ if (strcasecmp(suffix,".gif") == 0) | |
+ strcpy(server->response.contentType,"image/gif"); | |
+ if (strcasecmp(suffix,".jpg") == 0) | |
+ strcpy(server->response.contentType,"image/jpeg"); | |
+ if (strcasecmp(suffix,".xbm") == 0) | |
+ strcpy(server->response.contentType,"image/xbm"); | |
+ if (strcasecmp(suffix,".png") == 0) | |
+ strcpy(server->response.contentType,"image/png"); | |
+ if (strcasecmp(suffix,".css") == 0) | |
+ strcpy(server->response.contentType,"text/css"); | |
+ } | |
+ if (stat(path, &sbuf) < 0) | |
+ { | |
+ _httpd_send404(server); | |
+ return; | |
+ } | |
+ if (_httpd_checkLastModified(server,sbuf.st_mtime) == 0) | |
+ { | |
+ _httpd_send304(server); | |
+ } | |
+ else | |
+ { | |
+ _httpd_sendHeaders(server, sbuf.st_size, sbuf.st_mtime); | |
+ | |
+ if (strncmp(server->response.contentType,"text/",5) == 0) | |
+ _httpd_catFile(server, path, HTTP_EXPAND_TEXT); | |
+ else | |
+ _httpd_catFile(server, path, HTTP_RAW_DATA); | |
+ } | |
+} | |
+ | |
diff -u -r libhttpd-1.3/src/config.h.in libhttpd-1.4/src/config.h.in | |
--- libhttpd-1.3/src/config.h.in 2002-02-26 00:41:18.000000000 -0500 | |
+++ libhttpd-1.4/src/config.h.in 2004-05-09 14:06:24.000000000 -0400 | |
@@ -17,3 +17,6 @@ | |
/* Define if you have the socket library (-lsocket). */ | |
#undef HAVE_LIBSOCKET | |
+ | |
+/* Define if you have the socket library (-lsocket). */ | |
+#undef HAVE_EMBER | |
Only in libhttpd-1.4/src: ember.c | |
diff -u -r libhttpd-1.3/src/httpd.h libhttpd-1.4/src/httpd.h | |
--- libhttpd-1.3/src/httpd.h 2002-11-24 21:15:51.000000000 -0500 | |
+++ libhttpd-1.4/src/httpd.h 2005-01-25 23:48:28.000000000 -0500 | |
@@ -14,7 +14,7 @@ | |
** connection with the use or performance of this software. | |
** | |
** | |
-** $Id: httpd.h,v 1.10 2002/11/25 02:15:51 bambi Exp $ | |
+** $Id: httpd.h,v 1.16 2005/01/26 04:48:28 bambi Exp $ | |
** | |
*/ | |
@@ -60,6 +60,7 @@ | |
#define HTTP_TIME_STRING_LEN 40 | |
#define HTTP_READ_BUF_LEN 4096 | |
#define HTTP_ANY_ADDR NULL | |
+#define HTTP_MAX_VAR_NAME_LEN 48 | |
#define HTTP_GET 1 | |
#define HTTP_POST 2 | |
@@ -73,6 +74,7 @@ | |
#define HTTP_STATIC 4 | |
#define HTTP_WILDCARD 5 | |
#define HTTP_C_WILDCARD 6 | |
+#define HTTP_EMBER_WILDCARD 7 | |
#define HTTP_METHOD_ERROR "\n<B>ERROR : Method Not Implemented</B>\n\n" | |
@@ -98,6 +100,7 @@ | |
contentLength, | |
authLength; | |
char path[HTTP_MAX_URL], | |
+ host[HTTP_MAX_URL], | |
userAgent[HTTP_MAX_URL], | |
referer[HTTP_MAX_URL], | |
ifModified[HTTP_MAX_URL], | |
@@ -169,6 +172,9 @@ | |
httpAcl *defaultAcl; | |
FILE *accessLog, | |
*errorLog; | |
+ void (*errorFunction304)(), | |
+ (*errorFunction403)(), | |
+ (*errorFunction404)(); | |
} httpd; | |
@@ -180,6 +186,7 @@ | |
int httpdAddCContent __ANSI_PROTO((httpd*,char*,char*,int,int(*)(),void(*)())); | |
int httpdAddFileContent __ANSI_PROTO((httpd*,char*,char*,int,int(*)(),char*)); | |
+int httpdAddEmberContent __ANSI_PROTO((httpd*,char*,char*,int,int(*)(),char*)); | |
int httpdAddStaticContent __ANSI_PROTO((httpd*,char*,char*,int,int(*)(),char*)); | |
int httpdAddWildcardContent __ANSI_PROTO((httpd*,char*,int(*)(),char*)); | |
int httpdAddCWildcardContent __ANSI_PROTO((httpd*,char*,int(*)(),void(*)())); | |
@@ -187,6 +194,8 @@ | |
int httpdGetConnection __ANSI_PROTO((httpd*, struct timeval*)); | |
int httpdReadRequest __ANSI_PROTO((httpd*)); | |
int httpdCheckAcl __ANSI_PROTO((httpd*, httpAcl*)); | |
+int httpdAuthenticate __ANSI_PROTO((httpd*, char*)); | |
+int httpdSetErrorFunction __ANSI_PROTO((httpd*,int,void(*)())); | |
char *httpdRequestMethodName __ANSI_PROTO((httpd*)); | |
char *httpdUrlEncode __ANSI_PROTO((char *)); | |
@@ -195,6 +204,7 @@ | |
void httpdSetContentType __ANSI_PROTO((httpd*, char*)); | |
void httpdSetResponse __ANSI_PROTO((httpd*, char*)); | |
void httpdEndRequest __ANSI_PROTO((httpd*)); | |
+void httpdForceAuthenticate __ANSI_PROTO((httpd*, char*)); | |
httpd *httpdCreate __ANSI_PROTO(()); | |
void httpdFreeVariables __ANSI_PROTO((httpd*)); | |
@@ -205,6 +215,7 @@ | |
void httpdSendHeaders __ANSI_PROTO((httpd*)); | |
void httpdSetFileBase __ANSI_PROTO((httpd*, char*)); | |
void httpdSetCookie __ANSI_PROTO((httpd*, char*, char*)); | |
+void httpdSendFile __ANSI_PROTO((httpd*, char*)); | |
void httpdSetErrorLog __ANSI_PROTO((httpd*, FILE*)); | |
void httpdSetAccessLog __ANSI_PROTO((httpd*, FILE*)); | |
diff -u -r libhttpd-1.3/src/httpd_priv.h libhttpd-1.4/src/httpd_priv.h | |
--- libhttpd-1.3/src/httpd_priv.h 2002-11-24 21:15:51.000000000 -0500 | |
+++ libhttpd-1.4/src/httpd_priv.h 2004-09-24 02:24:50.000000000 -0400 | |
@@ -14,7 +14,7 @@ | |
** connection with the use or performance of this software. | |
** | |
** | |
-** $Id: httpd_priv.h,v 1.5 2002/11/25 02:15:51 bambi Exp $ | |
+** $Id: httpd_priv.h,v 1.8 2004/09/24 06:24:50 bambi Exp $ | |
** | |
*/ | |
@@ -48,13 +48,17 @@ | |
#define LEVEL_NOTICE "notice" | |
#define LEVEL_ERROR "error" | |
+#define HTTP_EXPAND_TEXT 1 | |
+#define HTTP_RAW_DATA 2 | |
+ | |
char * _httpd_unescape __ANSI_PROTO((char*)); | |
char *_httpd_escape __ANSI_PROTO((char*)); | |
char _httpd_from_hex __ANSI_PROTO((char)); | |
-void _httpd_catFile __ANSI_PROTO((httpd*, char*)); | |
+void _httpd_catFile __ANSI_PROTO((httpd*, char*, int)); | |
void _httpd_send403 __ANSI_PROTO((httpd*)); | |
+void _httpd_send304 __ANSI_PROTO((httpd*)); | |
void _httpd_send404 __ANSI_PROTO((httpd*)); | |
void _httpd_sendText __ANSI_PROTO((httpd*, char*)); | |
void _httpd_sendFile __ANSI_PROTO((httpd*, char*)); | |
@@ -75,6 +79,7 @@ | |
int _httpd_readLine __ANSI_PROTO((httpd*, char*, int)); | |
int _httpd_checkLastModified __ANSI_PROTO((httpd*, int)); | |
int _httpd_sendDirectoryEntry __ANSI_PROTO((httpd*, httpContent*, char*)); | |
+int _httpd_executeEmber __ANSI_PROTO((httpd*, char*)); | |
httpContent *_httpd_findContentEntry __ANSI_PROTO((httpd*, httpDir*, char*)); | |
httpDir *_httpd_findContentDir __ANSI_PROTO((httpd*, char*, int)); | |
diff -u -r libhttpd-1.3/src/protocol.c libhttpd-1.4/src/protocol.c | |
--- libhttpd-1.3/src/protocol.c 2002-11-24 21:15:51.000000000 -0500 | |
+++ libhttpd-1.4/src/protocol.c 2004-09-24 02:24:50.000000000 -0400 | |
@@ -14,7 +14,7 @@ | |
** connection with the use or performance of this software. | |
** | |
** | |
-** $Id: protocol.c,v 1.9 2002/11/25 02:15:51 bambi Exp $ | |
+** $Id: protocol.c,v 1.14 2004/09/24 06:24:50 bambi Exp $ | |
** | |
*/ | |
@@ -140,6 +140,106 @@ | |
return(1); | |
} | |
+int _httpd_sendExpandedText(server, buf, bufLen) | |
+ httpd *server; | |
+ char *buf; | |
+ int bufLen; | |
+{ | |
+ char *textStart, | |
+ *textEnd, | |
+ *varStart, | |
+ *varEnd, | |
+ varName[HTTP_MAX_VAR_NAME_LEN + 1]; | |
+ int length, | |
+ offset; | |
+ httpVar *var; | |
+ | |
+ length = offset = 0; | |
+ textStart = buf; | |
+ while(offset < bufLen) | |
+ { | |
+ /* | |
+ ** Look for the start of a variable name | |
+ */ | |
+ textEnd = index(textStart,'$'); | |
+ if (!textEnd) | |
+ { | |
+ /* | |
+ ** Nope. Write the remainder and bail | |
+ */ | |
+ _httpd_net_write(server->clientSock, | |
+ textStart, bufLen - offset); | |
+ length += bufLen - offset; | |
+ offset += bufLen - offset; | |
+ break; | |
+ } | |
+ | |
+ /* | |
+ ** Looks like there could be a variable. Send the | |
+ ** preceeding text and check it out | |
+ */ | |
+ _httpd_net_write(server->clientSock, textStart, | |
+ textEnd - textStart); | |
+ length += textEnd - textStart; | |
+ offset += textEnd - textStart; | |
+ varEnd = index(textEnd, '}'); | |
+ if (*(textEnd + 1) != '{' || varEnd == NULL) | |
+ { | |
+ /* | |
+ ** Nope, false alarm. | |
+ */ | |
+ _httpd_net_write(server->clientSock, "$",1 ); | |
+ length += 1; | |
+ offset += 1; | |
+ textStart = textEnd + 1; | |
+ continue; | |
+ } | |
+ | |
+ /* | |
+ ** OK, looks like an embedded variable | |
+ */ | |
+ varStart = textEnd + 2; | |
+ varEnd = varEnd - 1; | |
+ if (varEnd - varStart > HTTP_MAX_VAR_NAME_LEN) | |
+ { | |
+ /* | |
+ ** Variable name is too long | |
+ */ | |
+ _httpd_net_write(server->clientSock, "$", 1); | |
+ length += 1; | |
+ offset += 1; | |
+ textStart = textEnd + 1; | |
+ continue; | |
+ } | |
+ | |
+ /* | |
+ ** Is this a known variable? | |
+ */ | |
+ bzero(varName, HTTP_MAX_VAR_NAME_LEN); | |
+ strncpy(varName, varStart, varEnd - varStart + 1); | |
+ offset += strlen(varName) + 3; | |
+ var = httpdGetVariableByName(server, varName); | |
+ if (!var) | |
+ { | |
+ /* | |
+ ** Nope. It's undefined. Ignore it | |
+ */ | |
+ textStart = varEnd + 2; | |
+ continue; | |
+ } | |
+ | |
+ /* | |
+ ** Write the variables value and continue | |
+ */ | |
+ _httpd_net_write(server->clientSock, var->value, | |
+ strlen(var->value)); | |
+ length += strlen(var->value); | |
+ textStart = varEnd + 2; | |
+ } | |
+ return(length); | |
+} | |
+ | |
+ | |
void _httpd_writeAccessLog(server) | |
httpd *server; | |
{ | |
@@ -521,7 +621,14 @@ | |
httpd *server; | |
{ | |
httpdSetResponse(server, "304 Not Modified\n"); | |
- _httpd_sendHeaders(server,0,0); | |
+ if (server->errorFunction304) | |
+ { | |
+ (server->errorFunction304)(server,304); | |
+ } | |
+ else | |
+ { | |
+ _httpd_sendHeaders(server,0,0); | |
+ } | |
} | |
@@ -529,11 +636,18 @@ | |
httpd *server; | |
{ | |
httpdSetResponse(server, "403 Permission Denied\n"); | |
- _httpd_sendHeaders(server,0,0); | |
- _httpd_sendText(server, | |
+ if (server->errorFunction403) | |
+ { | |
+ (server->errorFunction403)(server,403); | |
+ } | |
+ else | |
+ { | |
+ _httpd_sendHeaders(server,0,0); | |
+ _httpd_sendText(server, | |
"<HTML><HEAD><TITLE>403 Permission Denied</TITLE></HEAD>\n"); | |
- _httpd_sendText(server, | |
+ _httpd_sendText(server, | |
"<BODY><H1>Access to the request URL was denied!</H1>\n"); | |
+ } | |
} | |
@@ -542,36 +656,55 @@ | |
{ | |
char msg[HTTP_MAX_URL]; | |
+ | |
snprintf(msg, HTTP_MAX_URL, | |
"File does not exist: %s", server->request.path); | |
_httpd_writeErrorLog(server,LEVEL_ERROR, msg); | |
httpdSetResponse(server, "404 Not Found\n"); | |
- _httpd_sendHeaders(server,0,0); | |
- _httpd_sendText(server, | |
- "<HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD>\n"); | |
- _httpd_sendText(server, | |
- "<BODY><H1>The request URL was not found!</H1>\n"); | |
- _httpd_sendText(server, "</BODY></HTML>\n"); | |
+ if (server->errorFunction404) | |
+ { | |
+ (server->errorFunction404)(server,404); | |
+ } | |
+ else | |
+ { | |
+ _httpd_sendHeaders(server,0,0); | |
+ _httpd_sendText(server, | |
+ "<HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD>\n"); | |
+ _httpd_sendText(server, | |
+ "<BODY><H1>The request URL was not found!</H1>\n"); | |
+ _httpd_sendText(server, "</BODY></HTML>\n"); | |
+ } | |
} | |
-void _httpd_catFile(server, path) | |
+void _httpd_catFile(server, path, mode) | |
httpd *server; | |
char *path; | |
+ int mode; | |
{ | |
int fd, | |
- len; | |
+ readLen, | |
+ writeLen; | |
char buf[HTTP_MAX_LEN]; | |
fd = open(path,O_RDONLY); | |
if (fd < 0) | |
return; | |
- len = read(fd, buf, HTTP_MAX_LEN); | |
- while(len > 0) | |
+ readLen = read(fd, buf, HTTP_MAX_LEN - 1); | |
+ while(readLen > 0) | |
{ | |
- server->response.responseLength += len; | |
- _httpd_net_write(server->clientSock, buf, len); | |
- len = read(fd, buf, HTTP_MAX_LEN); | |
+ if (mode == HTTP_RAW_DATA) | |
+ { | |
+ server->response.responseLength += readLen; | |
+ _httpd_net_write(server->clientSock, buf, readLen); | |
+ } | |
+ else | |
+ { | |
+ buf[readLen] = 0; | |
+ writeLen = _httpd_sendExpandedText(server,buf,readLen); | |
+ server->response.responseLength += writeLen; | |
+ } | |
+ readLen = read(fd, buf, HTTP_MAX_LEN - 1); | |
} | |
close(fd); | |
} | |
@@ -609,6 +742,8 @@ | |
strcpy(server->response.contentType,"image/xbm"); | |
if (strcasecmp(suffix,".png") == 0) | |
strcpy(server->response.contentType,"image/png"); | |
+ if (strcasecmp(suffix,".css") == 0) | |
+ strcpy(server->response.contentType,"text/css"); | |
} | |
if (stat(path, &sbuf) < 0) | |
{ | |
@@ -622,7 +757,11 @@ | |
else | |
{ | |
_httpd_sendHeaders(server, sbuf.st_size, sbuf.st_mtime); | |
- _httpd_catFile(server, path); | |
+ | |
+ if (strncmp(server->response.contentType,"text/",5) == 0) | |
+ _httpd_catFile(server, path, HTTP_EXPAND_TEXT); | |
+ else | |
+ _httpd_catFile(server, path, HTTP_RAW_DATA); | |
} | |
} | |
diff -u -r libhttpd-1.3/test/Makefile.tmpl libhttpd-1.4/test/Makefile.tmpl | |
--- libhttpd-1.3/test/Makefile.tmpl 2002-10-09 18:31:50.000000000 -0400 | |
+++ libhttpd-1.4/test/Makefile.tmpl 2005-02-02 16:38:09.000000000 -0500 | |
@@ -1,5 +1,5 @@ | |
CFLAGS= -g -I../src | |
-EXTRA_LIBS= ../src/libhttpd.a | |
+EXTRA_LIBS= ../src/libhttpd.a -L$(EMBER_INST_DIR)/lib $(EMBER_LIB) | |
!program test_httpd test_httpd.c | |
diff -u -r libhttpd-1.3/test/test_httpd.c libhttpd-1.4/test/test_httpd.c | |
--- libhttpd-1.3/test/test_httpd.c 2002-11-24 21:26:58.000000000 -0500 | |
+++ libhttpd-1.4/test/test_httpd.c 2004-05-09 14:06:24.000000000 -0400 | |
@@ -14,7 +14,7 @@ | |
** connection with the use or performance of this software. | |
** | |
** | |
-** $Id: test_httpd.c,v 1.10 2002/11/25 02:26:58 bambi Exp $ | |
+** $Id: test_httpd.c,v 1.13 2004/05/09 18:06:24 bambi Exp $ | |
** | |
*/ | |
@@ -22,6 +22,7 @@ | |
#include <stdio.h> | |
#include <unistd.h> | |
+#include <signal.h> | |
#ifdef _WIN32 | |
# include <getopt.h> | |
@@ -37,6 +38,8 @@ | |
*/ | |
#define test1_html "<HTML><BODY>This is just a test</BODY>" | |
+#define ember_code1 "printf(\"This is from ember in process %d\n\",getpid());" | |
+#define ember_code "load \"/usr/local/nk/www/content.lib\"; dispatchWebPage(\"/index.html\");" | |
/* | |
** Below are 2 dynamic pages, each generated by a C function. The first | |
@@ -100,7 +103,6 @@ | |
} | |
- | |
void login_html(server) | |
httpd *server; | |
{ | |
@@ -136,6 +138,15 @@ | |
} | |
+void myError404Handler(server, error) | |
+ httpd *server; | |
+ int error; | |
+{ | |
+ httpdOutput(server,"Whoa there. You hit a page that doesn't exist! <P><BR><BR>\n"); | |
+ httpdOutput(server,"Or in other words : <B>Error 404</B>\n\n"); | |
+} | |
+ | |
+ | |
int main(argc, argv) | |
int argc; | |
char *argv[]; | |
@@ -177,6 +188,15 @@ | |
/* | |
+ ** Ensure that PIPE signals are either handled or ignored. | |
+ ** If a client connection breaks while the server is using | |
+ ** it then the application will be sent a SIGPIPE. If you | |
+ ** don't handle it then it'll terminate your application. | |
+ */ | |
+ signal(SIGPIPE, SIG_IGN); | |
+ | |
+ | |
+ /* | |
** Create a server and setup our logging | |
*/ | |
server = httpdCreate(host,port); | |
@@ -189,6 +209,12 @@ | |
httpdSetErrorLog(server, stdout); | |
/* | |
+ ** We are fussy and don't want the default Error 404 page | |
+ */ | |
+ httpdSetErrorFunction(server,404, myError404Handler); | |
+ | |
+ | |
+ /* | |
** Setup some content for the server | |
*/ | |
httpdAddCContent(server,"/", "index.html", HTTP_TRUE, | |
@@ -202,15 +228,23 @@ | |
httpdAddCWildcardContent(server,"/wildcard", NULL, test3_html); | |
httpdAddStaticContent(server, "/", "test1.html", HTTP_FALSE, | |
NULL, test1_html); | |
+ httpdAddEmberContect(server,"/","ember.html", HTTP_FALSE, | |
+ NULL, ember_code); | |
/* | |
** Go into our service loop | |
*/ | |
- timeout.tv_sec = 5; | |
- timeout.tv_usec = 0; | |
while(1 == 1) | |
{ | |
+ /* | |
+ ** Linux modifies the timouet value during the | |
+ ** select call so we must set it everyt ime. Most | |
+ ** other UNIX implementations do not modify timeout | |
+ ** but it doesn't hurt to set it each time anyway | |
+ */ | |
+ timeout.tv_sec = 5; | |
+ timeout.tv_usec = 0; | |
result = httpdGetConnection(server, &timeout); | |
if (result == 0) | |
{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment