00001 #ifndef W3SERVER_H 00002 #define W3SERVER_H 00003 00004 /* 00005 Copyright (C) by Christian Gosch. 00006 00007 This file is part of w3server, a very small HTTP(-subset) server. 00008 00009 w3server is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation; either version 2 of the License, or 00012 (at your option) any later version. 00013 00014 Foobar is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 You should have received a copy of the GNU General Public License 00020 along with Foobar; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 */ 00030 #include <w3types.h> 00031 #include <w3comm.h> 00032 #include <netinet/in.h> 00033 #include <sys/socket.h> 00034 #include <unistd.h> 00035 #include <stdlib.h> 00036 00041 typedef struct { 00042 int socket; 00043 int port; 00044 char *hostname; 00045 struct sockaddr_in sock_addr; 00046 struct hostent *host; 00047 } w3Server; 00048 00049 typedef struct { 00050 w3Server *server; 00051 struct sockaddr_in sock_addr; 00052 socklen_t addrlen; 00053 int socket; 00054 } w3ServerConnection; 00055 00059 w3ServerConnection* w3ServerAccept (w3Server *server); 00060 00064 boolean w3ServerInit (w3Server *server); 00065 00069 boolean w3ServerClose (w3Server *server); 00070 00074 boolean w3ServerDisconnect (w3ServerConnection* con); 00075 00076 00077 00082 char* w3ServerGetToken (char *str, int *idx); 00083 00089 char* w3ServerGetPath (char *str); 00090 00098 boolean w3ServerSendFile (char *path, w3ServerConnection *con); 00099 00104 boolean w3ServerSendError (int errorcode, w3ServerConnection *con); 00105 00110 boolean w3ServerServeClient (w3Server *server, w3ServerConnection *con); 00111 00115 boolean w3StartServer (int port); 00116 00120 void w3ServerMessage (const char* msg); 00121 00124 #endif