1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-25 20:02:37 +03:00

added mime option to axhttpd. Improved cygwin library build

git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@52 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
cameronrich 2006-12-06 02:20:00 +00:00
parent 8213b750a1
commit dabdec8fcc
12 changed files with 357 additions and 386 deletions

View File

@ -69,9 +69,10 @@ win32_demo:
install: $(PREFIX) all
cp --no-dereference $(STAGE)/libax* $(PREFIX)/lib
chmod 755 $(PREFIX)/lib/libax*
-@install -m 755 $(STAGE)/ax* $(PREFIX)/bin > /dev/null 2>&1
-@install -m 755 $(STAGE)/axtlsp.pm `perl -e 'use Config; print $$Config{installarchlib};'` > /dev/null 2>&1
-@install -m 755 $(STAGE)/axhttpd* $(PREFIX)/bin > /dev/null 2>&1
-install -m 755 $(STAGE)/ax* $(PREFIX)/bin > /dev/null 2>&1
ifdef CONFIG_PERL_BINDINGS
-install -m 755 $(STAGE)/axtlsp.pm `perl -e 'use Config; print $$Config{installarchlib};'` > /dev/null 2>&1
endif
installclean:
-@rm $(PREFIX)/lib/libax* > /dev/null 2>&1

View File

@ -55,6 +55,7 @@ CONFIG_HTTP_CGI_EXTENSION=""
# CONFIG_HTTP_DIRECTORIES is not set
# CONFIG_HTTP_PERM_CHECK is not set
# CONFIG_HTTP_HAS_IPV6 is not set
CONFIG_HTTP_ALL_MIME_TYPES=y
# CONFIG_HTTP_VERBOSE is not set
# CONFIG_HTTP_IS_DAEMON is not set

View File

@ -62,6 +62,7 @@ CONFIG_HTTP_CGI_EXTENSION=""
CONFIG_HTTP_DIRECTORIES=y
# CONFIG_HTTP_PERM_CHECK is not set
# CONFIG_HTTP_HAS_IPV6 is not set
CONFIG_HTTP_ALL_MIME_TYPES=y
CONFIG_HTTP_VERBOSE=y
# CONFIG_HTTP_IS_DAEMON is not set

View File

@ -88,6 +88,17 @@ config CONFIG_HTTP_HAS_IPV6
Does not work under Win32
config CONFIG_HTTP_ALL_MIME_TYPES
bool "Use all mime types"
default y if CONFIG_SSL_FULL_MODE
default n if !CONFIG_SSL_FULL_MODE
help
Use the full list of supported mime types.
Use this option if a "generic" webserver is used. However if it is
using only web pages (html, jpg, gif, png, css) then select this
option.
config CONFIG_HTTP_VERBOSE
bool "Verbose Mode"
default y if CONFIG_SSL_FULL_MODE

View File

@ -47,7 +47,7 @@ LIBS=../$(STAGE)/axtls.lib ..\\config\\axtls.res
endif
endif
ifndef CONFIG_AWHTTPD
ifndef CONFIG_AXHTTPD
web_server:
else
@ -56,18 +56,13 @@ web_server : $(TARGET)
OBJ= \
conn.o \
main.o \
net.o \
proc.o \
socket.o \
misc.o \
mime_types.o
ifndef CONFIG_PLATFORM_WIN32
$(TARGET): $(OBJ)
ifdef CONFIG_HTTP_NO_SSL
$(LD) $(LDFLAGS) -o $@ $(OBJ)
endif
$(TARGET): $(OBJ) ../$(STAGE)/libaxtls.a
$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
ifndef CONFIG_DEBUG
ifndef CONFIG_PLATFORM_SOLARIS
@ -77,13 +72,10 @@ endif
else # Win32
$(TARGET): $(OBJ)
ifdef CONFIG_HTTP_NO_SSL
$(LD) $(LDFLAGS) /out:$@ $(OBJ)
endif
$(LD) $(LDFLAGS) $(LIBS) /out:$@ $(OBJ)
endif
endif # CONFIG_AWHTTPD
endif # CONFIG_AXHTTPD
clean::
-@rm -f $(TARGET)*

View File

@ -20,7 +20,7 @@
#include "ssl.h"
#define BACKLOG 15
#define VERSION "3.0.7"
#define VERSION "1.0.0"
#ifdef CONFIG_HTTP_HAS_IPV6
#define HAVE_IPV6
#endif
@ -47,10 +47,8 @@
struct connstruct
{
struct connstruct *next;
int state;
int reqtype;
int networkdesc;
int filedesc;
@ -73,7 +71,6 @@ struct connstruct
char cgipathinfo[MAXREQUESTLENGTH];
#endif
char virtualhostreq[MAXREQUESTLENGTH];
int numbytes;
char databuf[BLOCKSIZE];
@ -90,11 +87,13 @@ struct serverstruct
SSLCTX *ssl_ctx;
};
#if defined(CONFIG_HTTP_HAS_CGI)
struct cgiextstruct
{
struct cgiextstruct *next;
char *ext;
};
#endif
struct indexstruct
{
@ -106,7 +105,9 @@ struct indexstruct
extern struct serverstruct *servers;
extern struct connstruct *usedconns;
extern struct connstruct *freeconns;
#if defined(CONFIG_HTTP_HAS_CGI)
extern struct cgiextstruct *cgiexts;
#endif
extern struct indexstruct *indexlist;
// Conf global prototypes
@ -129,15 +130,6 @@ void procreadfile(struct connstruct *cn);
void procsendfile(struct connstruct *cn);
int special_write(struct connstruct *cn, const uint8_t *buf, size_t count);
// net.c prototypes
void addtoservers(int sd);
void selectloop(void);
// socket.c prototypes
void handlenewconnection(int listenfd, int is_ssl);
int openlistener(int port);
int openlistener6(int port);
// misc.c prototypes
void nada(int sigtype);
void die(int sigtype);

View File

@ -33,7 +33,12 @@ struct cgiextstruct *cgiexts;
struct indexstruct *indexlist;
char *webroot = CONFIG_HTTP_WEBROOT;
static void addindex(char *tp);
static void addtoservers(int sd);
static void selectloop(void);
static int openlistener(int port);
static void handlenewconnection(int listenfd, int is_ssl);
#if defined(CONFIG_HTTP_PERM_CHECK)
static void procpermcheck(char *pathtocheck);
#endif
@ -123,7 +128,7 @@ int main(int argc, char *argv[])
exit(1);
}
if ((tp=openlistener(CONFIG_HTTP_PORT)) == -1)
if ((tp = openlistener(CONFIG_HTTP_PORT)) == -1)
{
#ifdef CONFIG_HTTP_VERBOSE
fprintf(stderr, "ERR: Couldn't bind to port %d (IPv4)\n",
@ -143,7 +148,7 @@ int main(int argc, char *argv[])
}
#endif
if ((tp=openlistener(CONFIG_HTTP_HTTPS_PORT)) == -1)
if ((tp = openlistener(CONFIG_HTTP_HTTPS_PORT)) == -1)
{
#ifdef CONFIG_HTTP_VERBOSE
fprintf(stderr, "ERR: Couldn't bind to port %d (IPv4)\n",
@ -321,3 +326,260 @@ static void addcgiext(char *tp)
}
#endif
static void addtoservers(int sd)
{
struct serverstruct *tp = (struct serverstruct *)
calloc(1, sizeof(struct serverstruct));
tp->next = servers;
tp->sd = sd;
servers = tp;
}
static void selectloop(void)
{
fd_set rfds, wfds;
struct connstruct *tp, *to;
struct serverstruct *sp;
int rnum, wnum, active;
int currtime;
while (1)
{
// MAIN SELECT LOOP
FD_ZERO(&rfds);
FD_ZERO(&wfds);
rnum = wnum = -1;
// Add the listening sockets
sp = servers;
while (sp != NULL)
{
FD_SET(sp->sd, &rfds);
if (sp->sd > rnum) rnum = sp->sd;
sp = sp->next;
}
// Add the established sockets
tp = usedconns;
currtime = time(NULL);
while (tp != NULL)
{
if (currtime > tp->timeout)
{
to = tp;
tp = tp->next;
removeconnection(to);
continue;
}
if (tp->state == STATE_WANT_TO_READ_HEAD)
{
FD_SET(tp->networkdesc, &rfds);
if (tp->networkdesc > rnum)
rnum = tp->networkdesc;
}
if (tp->state == STATE_WANT_TO_SEND_HEAD)
{
FD_SET(tp->networkdesc, &wfds);
if (tp->networkdesc > wnum)
wnum = tp->networkdesc;
}
if (tp->state == STATE_WANT_TO_READ_FILE)
{
FD_SET(tp->filedesc, &rfds);
if (tp->filedesc > rnum)
rnum = tp->filedesc;
}
if (tp->state == STATE_WANT_TO_SEND_FILE)
{
FD_SET(tp->networkdesc, &wfds);
if (tp->networkdesc > wnum)
wnum = tp->networkdesc;
}
#if defined(CONFIG_HTTP_DIRECTORIES)
if (tp->state == STATE_DOING_DIR)
{
FD_SET(tp->networkdesc, &wfds);
if (tp->networkdesc > wnum)
wnum = tp->networkdesc;
}
#endif
tp = tp->next;
}
active = select(wnum > rnum ? wnum+1 : rnum+1,
rnum != -1 ? &rfds : NULL,
wnum != -1 ? &wfds : NULL,
NULL, NULL);
// Handle the listening sockets
sp = servers;
while (active > 0 && sp != NULL)
{
if (FD_ISSET(sp->sd, &rfds))
{
handlenewconnection(sp->sd, sp->is_ssl);
active--;
}
sp = sp->next;
}
// Handle the established sockets
tp = usedconns;
while (active > 0 && tp != NULL)
{
to = tp;
tp = tp->next;
if (to->state == STATE_WANT_TO_READ_HEAD)
if (FD_ISSET(to->networkdesc, &rfds))
{
active--;
procreadhead(to);
}
if (to->state == STATE_WANT_TO_SEND_HEAD)
if (FD_ISSET(to->networkdesc, &wfds))
{
active--;
procsendhead(to);
}
if (to->state == STATE_WANT_TO_READ_FILE)
if (FD_ISSET(to->filedesc, &rfds))
{
active--;
procreadfile(to);
}
if (to->state == STATE_WANT_TO_SEND_FILE)
if (FD_ISSET(to->networkdesc, &wfds))
{
active--;
procsendfile(to);
}
#if defined(CONFIG_HTTP_DIRECTORIES)
if (to->state == STATE_DOING_DIR)
if (FD_ISSET(to->networkdesc, &wfds))
{
active--;
procdodir(to);
}
#endif
}
} // MAIN SELECT LOOP
}
#ifdef HAVE_IPV6
static void handlenewconnection(int listenfd, int is_ssl)
{
struct sockaddr_in6 their_addr;
int tp = sizeof(their_addr);
char ipbuf[100];
int connfd = accept(listenfd, (struct sockaddr *)&their_addr, &tp);
if (connfd == -1)
return;
if (tp == sizeof(struct sockaddr_in6))
{
inet_ntop(AF_INET6, &their_addr.sin6_addr, ipbuf, sizeof(ipbuf));
}
else if (tp == sizeof(struct sockaddr_in))
{
inet_ntop(AF_INET, &(((struct sockaddr_in *)&their_addr)->sin_addr),
ipbuf, sizeof(ipbuf));
}
else
{
*ipbuf = '\0';
}
addconnection(connfd, ipbuf, is_ssl);
}
#else
static void handlenewconnection(int listenfd, int is_ssl)
{
struct sockaddr_in their_addr;
int tp = sizeof(struct sockaddr_in);
int connfd = accept(listenfd, (struct sockaddr *)&their_addr, &tp);
if (connfd == -1)
return;
addconnection(connfd, inet_ntoa(their_addr.sin_addr), is_ssl);
}
#endif
static int openlistener(int port)
{
int sd;
#ifdef WIN32
char tp=1;
#else
int tp=1;
#endif
struct sockaddr_in my_addr;
if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
return -1;
setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &tp, sizeof(tp));
my_addr.sin_family = AF_INET; // host byte order
my_addr.sin_port = htons((short)port); // short, network byte order
my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP
memset(&(my_addr.sin_zero), 0, 8); // zero the rest of the struct
if (bind(sd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1)
{
close(sd);
return -1;
}
if (listen(sd, BACKLOG) == -1)
{
close(sd);
return -1;
}
return sd;
}
#ifdef HAVE_IPV6
static int openlistener6(int port)
{
int sd,tp;
struct sockaddr_in6 my_addr;
if ((sd = socket(AF_INET6, SOCK_STREAM, 0)) == -1)
return -1;
setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &tp, sizeof(tp));
memset(&my_addr, 0, sizeof(my_addr));
my_addr.sin6_family = AF_INET6;
my_addr.sin6_port = htons(port);
if (bind(sd, (struct sockaddr *)&my_addr, sizeof(my_addr)) == -1)
{
close(sd);
return -1;
}
if (listen(sd, BACKLOG) == -1)
{
close(sd);
return -1;
}
return sd;
}
#endif

View File

@ -35,19 +35,23 @@ static mime_table_t mime_table[] =
// Fundamentals
{ ".html", "text/html" },
{ ".htm", "text/html" },
{ ".txt", "text/plain" },
{ ".css", "text/css" },
// Others
// Basic graphics
{ ".jpg", "image/jpeg" },
{ ".gif", "image/gif" },
{ ".png", "image/png" },
#ifdef CONFIG_HTTP_ALL_MIME_TYPES
// This list is a bit expensive to maintain normally, so it's an option.
{ ".txt", "text/plain" },
{ ".rtx", "text/richtext" },
{ ".etx", "text/x-setext" },
{ ".tsv", "text/tab-separated-values" },
{ ".css", "text/css" },
{ ".xml", "text/xml" },
{ ".dtd", "text/xml" },
{ ".gif", "image/gif" },
{ ".jpg", "image/jpeg" },
{ ".jpeg", "image/jpeg" },
{ ".jpe", "image/jpeg" },
{ ".jpeg", "image/jpeg" },
{ ".jfif", "image/jpeg" },
{ ".tif", "image/tiff" },
{ ".tiff", "image/tiff" },
@ -59,7 +63,6 @@ static mime_table_t mime_table[] =
{ ".xpm", "image/x-xpixmap" },
{ ".xwd", "image/x-xwindowdump" },
{ ".ief", "image/ief" },
{ ".png", "image/png" },
{ ".au", "audio/basic" },
{ ".snd", "audio/basic" },
{ ".aif", "audio/x-aiff" },
@ -159,6 +162,7 @@ static mime_table_t mime_table[] =
{ ".tar.gz", "application/x-gzip" },
{ ".bz2", "application/x-bzip2" },
{ ".zip", "application/zip" }
#endif
};
static int mime_cmp(const mime_table_t *t1, const mime_table_t *t2)

View File

@ -1,176 +0,0 @@
/*
* Copyright(C) 2006 Cameron Rich
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include "axhttp.h"
void addtoservers(int sd)
{
struct serverstruct *tp = (struct serverstruct *)
calloc(1, sizeof(struct serverstruct));
tp->next = servers;
tp->sd = sd;
servers = tp;
}
void selectloop()
{
fd_set rfds, wfds;
struct connstruct *tp, *to;
struct serverstruct *sp;
int rnum, wnum, active;
int currtime;
while (1)
{
// MAIN SELECT LOOP
FD_ZERO(&rfds);
FD_ZERO(&wfds);
rnum = wnum = -1;
// Add the listening sockets
sp = servers;
while (sp != NULL)
{
FD_SET(sp->sd, &rfds);
if (sp->sd > rnum) rnum = sp->sd;
sp = sp->next;
}
// Add the established sockets
tp = usedconns;
currtime = time(NULL);
while (tp != NULL)
{
if (currtime > tp->timeout)
{
to = tp;
tp = tp->next;
removeconnection(to);
continue;
}
if (tp->state == STATE_WANT_TO_READ_HEAD)
{
FD_SET(tp->networkdesc, &rfds);
if (tp->networkdesc > rnum)
rnum = tp->networkdesc;
}
if (tp->state == STATE_WANT_TO_SEND_HEAD)
{
FD_SET(tp->networkdesc, &wfds);
if (tp->networkdesc > wnum)
wnum = tp->networkdesc;
}
if (tp->state == STATE_WANT_TO_READ_FILE)
{
FD_SET(tp->filedesc, &rfds);
if (tp->filedesc > rnum)
rnum = tp->filedesc;
}
if (tp->state == STATE_WANT_TO_SEND_FILE)
{
FD_SET(tp->networkdesc, &wfds);
if (tp->networkdesc > wnum)
wnum = tp->networkdesc;
}
#if defined(CONFIG_HTTP_DIRECTORIES)
if (tp->state == STATE_DOING_DIR)
{
FD_SET(tp->networkdesc, &wfds);
if (tp->networkdesc > wnum)
wnum = tp->networkdesc;
}
#endif
tp = tp->next;
}
active = select(wnum > rnum ? wnum+1 : rnum+1,
rnum != -1 ? &rfds : NULL,
wnum != -1 ? &wfds : NULL,
NULL, NULL);
// Handle the listening sockets
sp = servers;
while (active > 0 && sp != NULL)
{
if (FD_ISSET(sp->sd, &rfds))
{
handlenewconnection(sp->sd, sp->is_ssl);
active--;
}
sp = sp->next;
}
// Handle the established sockets
tp = usedconns;
while (active > 0 && tp != NULL)
{
to = tp;
tp = tp->next;
if (to->state == STATE_WANT_TO_READ_HEAD)
if (FD_ISSET(to->networkdesc, &rfds))
{
active--;
procreadhead(to);
}
if (to->state == STATE_WANT_TO_SEND_HEAD)
if (FD_ISSET(to->networkdesc, &wfds))
{
active--;
procsendhead(to);
}
if (to->state == STATE_WANT_TO_READ_FILE)
if (FD_ISSET(to->filedesc, &rfds))
{
active--;
procreadfile(to);
}
if (to->state == STATE_WANT_TO_SEND_FILE)
if (FD_ISSET(to->networkdesc, &wfds))
{
active--;
procsendfile(to);
}
#if defined(CONFIG_HTTP_DIRECTORIES)
if (to->state == STATE_DOING_DIR)
if (FD_ISSET(to->networkdesc, &wfds))
{
active--;
procdodir(to);
}
#endif
}
} // MAIN SELECT LOOP
}

View File

@ -31,9 +31,11 @@ static void send301(struct connstruct *cn);
static void send404(struct connstruct *cn);
static int procindex(struct connstruct *cn, struct stat *stp);
static int hexit(char c);
static void urlencode(unsigned char *s, unsigned char *t);
static void urldecode(char *buf);
#if defined(CONFIG_HTTP_DIRECTORIES)
static void urlencode(unsigned char *s, unsigned char *t);
#endif
#if defined(CONFIG_HTTP_HAS_CGI)
static void proccgi(struct connstruct *cn, int has_pathinfo);
#endif
@ -206,6 +208,35 @@ void procdodir(struct connstruct *cn)
}
while (issockwriteable(cn->networkdesc));
}
/* Encode funny chars -> %xx in newly allocated storage */
/* (preserves '/' !) */
static void urlencode(unsigned char *s, unsigned char *t)
{
uint8_t *p, *tp;
tp =t ;
for (p=s; *p; p++)
{
if ((*p > 0x00 && *p < ',') ||
(*p > '9' && *p < 'A') ||
(*p > 'Z' && *p < '_') ||
(*p > '_' && *p < 'a') ||
(*p > 'z' && *p < 0xA1)) {
sprintf((char *)tp, "%%%02X", *p);
tp += 3;
}
else
{
*tp = *p;
tp++;
}
}
*tp='\0';
}
#endif
void procreadhead(struct connstruct *cn)
@ -529,20 +560,6 @@ static int special_read(struct connstruct *cn, void *buf, size_t count)
return res;
}
static void send301(struct connstruct *cn)
{
char buf[2048];
sprintf(buf, "HTTP/1.1 301 Moved Permanently\nLocation: %s/\n\n<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<HTML><HEAD>\n<TITLE>301 Moved Permanently</TITLE>\n</HEAD><BODY>\n<H1>Moved Permanently</H1>\nThe document has moved <A HREF=\"%s/\">here</A>.<P>\n<HR>\n</BODY></HTML>\n", cn->filereq, cn->filereq);
special_write(cn, buf, strlen(buf));
}
static void send404(struct connstruct *cn)
{
char buf[1024];
sprintf(buf, "HTTP/1.0 404 Not Found\nContent-Type: text/html\n\n<HTML><BODY>\n<TITLE>404 Not Found</TITLE><H1>It ain't there my friend. (404 Not Found)</H1>\n</BODY></HTML>\n");
special_write(cn, buf, strlen(buf));
}
// Returns 0 if no index was found and doesn't modify cn->actualfile
// Returns 1 if an index was found and puts the index in cn->actualfile
// and puts its stat info into stp
@ -701,34 +718,6 @@ static void proccgi(struct connstruct *cn, int has_pathinfo)
}
#endif /* CONFIG_HTTP_HAS_CGI */
/* Encode funny chars -> %xx in newly allocated storage */
/* (preserves '/' !) */
static void urlencode(unsigned char *s, unsigned char *t)
{
uint8_t *p, *tp;
tp =t ;
for (p=s; *p; p++)
{
if ((*p > 0x00 && *p < ',') ||
(*p > '9' && *p < 'A') ||
(*p > 'Z' && *p < '_') ||
(*p > '_' && *p < 'a') ||
(*p > 'z' && *p < 0xA1)) {
sprintf((char *)tp, "%%%02X", *p);
tp += 3;
}
else
{
*tp = *p;
tp++;
}
}
*tp='\0';
}
/* Decode string %xx -> char (in place) */
static void urldecode(char *buf)
{
@ -778,3 +767,17 @@ static int hexit(char c)
return 0;
}
static void send301(struct connstruct *cn)
{
char buf[2048];
snprintf(buf, sizeof(buf), "HTTP/1.1 301 Moved Permanently\nLocation: %s/\n\n<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<HTML><HEAD>\n<TITLE>301 Moved Permanently</TITLE>\n</HEAD><BODY>\n<H1>Moved Permanently</H1>\nThe document has moved <A HREF=\"%s/\">here</A>.<P>\n<HR>\n</BODY></HTML>\n", cn->filereq, cn->filereq);
special_write(cn, buf, strlen(buf));
}
static void send404(struct connstruct *cn)
{
char buf[1024];
sprintf(buf, "HTTP/1.0 404 Not Found\nContent-Type: text/html\n\n<HTML><BODY>\n<TITLE>404 Not Found</TITLE><H1>It ain't there my friend. (404 Not Found)</H1>\n</BODY></HTML>\n");
special_write(cn, buf, strlen(buf));
}

View File

@ -1,129 +0,0 @@
/*
* Copyright(C) 2006 Cameron Rich
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include "axhttp.h"
#ifdef HAVE_IPV6
void handlenewconnection(int listenfd, int is_ssl)
{
struct sockaddr_in6 their_addr;
int tp = sizeof(their_addr);
char ipbuf[100];
int connfd = accept(listenfd, (struct sockaddr *)&their_addr, &tp);
if (connfd == -1)
return;
if (tp == sizeof(struct sockaddr_in6))
{
inet_ntop(AF_INET6, &their_addr.sin6_addr, ipbuf, sizeof(ipbuf));
}
else if (tp == sizeof(struct sockaddr_in))
{
inet_ntop(AF_INET, &(((struct sockaddr_in *)&their_addr)->sin_addr),
ipbuf, sizeof(ipbuf));
}
else
{
*ipbuf = '\0';
}
addconnection(connfd, ipbuf, is_ssl);
}
#else
void handlenewconnection(int listenfd, int is_ssl)
{
struct sockaddr_in their_addr;
int tp = sizeof(struct sockaddr_in);
int connfd = accept(listenfd, (struct sockaddr *)&their_addr, &tp);
if (connfd == -1)
return;
addconnection(connfd, inet_ntoa(their_addr.sin_addr), is_ssl);
}
#endif
int openlistener(int port)
{
int sd;
#ifdef WIN32
char tp=1;
#else
int tp=1;
#endif
struct sockaddr_in my_addr;
if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
return -1;
setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &tp, sizeof(tp));
my_addr.sin_family = AF_INET; // host byte order
my_addr.sin_port = htons((short)port); // short, network byte order
my_addr.sin_addr.s_addr = INADDR_ANY; // automatically fill with my IP
memset(&(my_addr.sin_zero), 0, 8); // zero the rest of the struct
if (bind(sd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1)
{
close(sd);
return -1;
}
if (listen(sd, BACKLOG) == -1)
{
close(sd);
return -1;
}
return sd;
}
#ifdef HAVE_IPV6
int openlistener6(int port)
{
int sd,tp;
struct sockaddr_in6 my_addr;
if ((sd = socket(AF_INET6, SOCK_STREAM, 0)) == -1)
return -1;
setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &tp, sizeof(tp));
memset(&my_addr, 0, sizeof(my_addr));
my_addr.sin6_family = AF_INET6;
my_addr.sin6_port = htons(port);
if (bind(sd, (struct sockaddr *)&my_addr, sizeof(my_addr)) == -1)
{
close(sd);
return -1;
}
if (listen(sd, BACKLOG) == -1)
{
close(sd);
return -1;
}
return sd;
}
#endif

View File

@ -31,7 +31,9 @@ endif
ifndef CONFIG_PLATFORM_WIN32
TARGET1=../$(STAGE)/libaxtls.a
BASETARGET=libaxtls.so
TARGET2=../$(STAGE)/$(BASETARGET)
ifdef CONFIG_PLATFORM_CYGWIN
TARGET2=../$(STAGE)/libaxtls.dll.a
endif
# shared library major/minor numbers
LIBMAJOR=$(BASETARGET).1
@ -72,8 +74,15 @@ $(TARGET1) : $(OBJ)
$(AR) -r $@ $(OBJ)
$(TARGET2) : $(OBJ)
$(LD) $(LDFLAGS) -Wl,-soname,$(LIBMAJOR) $(LDSHARED) -o ../$(STAGE)/$(LIBMINOR) $(OBJ)
ifndef CONFIG_PLATFORM_CYGWIN
$(LD) $(LDFLAGS) $(LDSHARED) -Wl,-soname,$(LIBMAJOR) -o ../$(STAGE)/$(LIBMINOR) $(OBJ)
cd ../$(STAGE); ln -sf $(LIBMINOR) $(LIBMAJOR); ln -sf $(LIBMAJOR) $(BASETARGET); cd -
else
$(LD) $(LDFLAGS) $(LDSHARED) -o ../$(STAGE)/cygaxtls.dll \
-Wl,--out-implib=../$(STAGE)/libaxtls.dll.a \
-Wl,--export-all-symbols \
-Wl,--enable-auto-import $(OBJ)
endif
else # Win32