00001 /* 00002 Copyright 2007 Erez Bibi (erezbibi@users.sourceforge.net) 00003 This file is part of Beesnest. 00004 00005 Beesnest is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 Beesnest is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with Beesnest; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 #ifndef __CDC_GLOBALS 00021 #define __CDC_GLOBALS 00022 00023 /* Here you define which Operating System you are going to use. */ 00024 #define OS_NAME Windows 00025 00026 /* This macros will return include path of the current OS. 00027 Yes this is unnecessary complicate...*/ 00028 #define _INCLUDE_PATH(file_name) OS_NAME/file_name 00029 #define _CALL_QUOTE_PATH(path) _QUOTE_PATH(path) 00030 #define _QUOTE_PATH(path) #path 00031 #define _GET_INCLUDE_PATH(file_name) _CALL_QUOTE_PATH(_INCLUDE_PATH(file_name)) 00032 00033 /* Includes. */ 00034 #include <stdlib.h> 00035 #include <time.h> 00036 /* Specific includes for the system */ 00037 #include _GET_INCLUDE_PATH (DcOS.h) 00038 /* STL */ 00039 #include <fstream> 00040 #include <iostream> 00041 #include <map> 00042 #include <list> 00043 #include <vector> 00044 #include <set> 00045 #include <string> 00046 using namespace std; 00047 /* CdcString is for everyone... */ 00048 #include "DcString.h" 00049 00050 /** Map to store header fields values, variables and parameters. */ 00051 typedef map<string, string> t_map; 00052 typedef t_map::iterator t_itr; 00053 typedef t_map::const_iterator t_const_itr; 00054 00055 typedef unsigned int uint; 00056 00057 /* These defines are parameters I don't want to put in the configuration file. */ 00058 #define BUFF_LEN 256 00059 #define CRLF "\r\n" 00060 #define CRLF_SIZE 2 00061 #define CRLFCRLF "\r\n\r\n" 00062 #define CRLFCRLF_SIZE 4 00063 #define POST "POST" 00064 #define GET "GET" 00065 #define HEAD "HEAD" 00066 #define SERVER_NAME "Beesnest HTTP 1.1 Server/1.0" 00067 #define PROTOCOL11_VRS "HTTP/1.1" 00068 #define PROTOCOL10_VRS "HTTP/1.0" 00069 #define CONTINUE_MSG "HTTP/1.1 100 Continue" 00070 #define OVRLOAD_MSG "HTTP/1.1 503 Service Unavailable\r\n\r\n" 00071 #define OVRLOAD_MSG_LEN 40 00072 #define TIME_FORMAT "%a, %d %b %Y %H:%M:%S GMT" 00073 #define PARM_SEP "->" 00074 #define PARM_SEP_LEN 2 00075 #define PARM_FILE_EXT "bnc" 00076 00077 #define SCRIPT_STR "<bnscript" 00078 #define SCRIPT_STR_LEN 9 00079 #define SCRIPT_END "</bnscript" 00080 #define SCRIPT_END_LEN 10 00081 #define SCRIPT_TRM '>' 00082 #define DEL_CMD "delete" 00083 #define DEL_CMD_LEN 6 00084 00085 /* Logging Levels. */ 00086 #define PS_GEN 1 00087 #define PS_LOG 2 00088 #define PS_SEC 3 00089 #define PS_TRD 4 00090 #define PS_DBG 5 00091 00092 const CdcString EMPTY_STR (""); 00093 00094 /* Header fields that the user allow to change from a page. - Not in use. */ 00095 const CdcString CONTROLED_HEADERS = "Cache-Control, Connection, Server"; 00096 00097 /* Global Functions headers. */ 00098 /** 00099 * This is the real main function of the server. it creates a CdcSocketServer 00100 * object by calling the static function <b>CdcSocketserver::GetSocketServer</b>. 00101 * Then it inserts a loop and listens to the selected port for incoming 00102 * connections. When a new request is available <b>Listen</b> returns with a 00103 * pointer to a <b>CdcSocket</b> object. Then the function will create a new 00104 * <b>CdcConnectionThread</b> with the new socket, and call 00105 * <b>CdcConnectionThread::Start</b>. The new thread will do the work while Main 00106 * will return to listen on the port. 00107 * <p> 00108 * @return (int) -1 if exit because of an error, otherwise it returns 0. 00109 */ 00110 int ProgramMain (); 00111 00112 /** 00113 * Initialize classes of the server by calling some class static functions. 00114 * <p> 00115 * @throw (CdcException) from the initialization functions. 00116 */ 00117 void InitProgram (); 00118 00119 /** 00120 * Add, Change password and Remove users from the users database. 00121 * <p> 00122 * usage: <br> 00123 * logins add 'username' 'password'. <br> 00124 * logins change 'username' 'old_password' 'new_password'. <br> 00125 * logins remove 'username' 'password'. <br> 00126 */ 00127 void ControlUsers (int argc, char* argv[]); 00128 00129 /** 00130 * Thread safe function to print a messages to the console and/or log file. 00131 * This is just a wrapper to CdcLogger::PrintString 00132 * <p> 00133 * @param str The message to print. 00134 * @param level Optional logging level (default is zero - always print). 00135 */ 00136 void PrintString (CdcString str, int level=0); 00137 00138 /** 00139 * The Main function. It checks the command line arguments. <br> 00140 * <b>install</b> - will register this program as a demon/service. <br> 00141 * <b>uninstall</b> - will unregister this program. <br> 00142 * <b>run</b> - will run the program as regular console application. <br> 00143 * <b>logins</b> - will add, remove and change password of users. <br> 00144 * if no argument exists, it start the program as a demon/service. 00145 * @return Zero on successful exit, or none zero if failed. 00146 */ 00147 void main (int argc, char* argv[]); 00148 00149 00150 #endif /* __CDC_GLOBALS. */ 00151