trunk 20080912
[gitenigma.git] / boot / chttpd / chttpd.cpp
blob0c630b0a8f5c4c9d5ddcf446db4430d9666e02f0
1 /*
2 * $Id: chttpd.cpp,v 1.3 2005/10/18 11:30:19 digi_casi Exp $
4 * (C) 2005 by digi_casi <digi_casi@tuxbox.org>
5 * based on nhttpd (C) 2001/2002 Dirk Szymanski
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #ifdef ENABLE_EXPERT_WEBIF
24 #define CHTTPD_VERSION "0.1"
26 #include <signal.h>
27 #include <sys/types.h>
28 #include <stdio.h>
29 #include <config.h>
30 #include "webserver.h"
31 #include "debug.h"
32 #include <chttpd/chttpdconfig.h>
34 using namespace std;
36 CWebserver *webserver;
37 chttpdConfig cfg;
39 void sig_catch(int msignal)
41 switch (msignal)
43 case SIGHUP:
44 aprintf("got signal HUP, reading config\n");
45 cfg.load();
46 break;
47 default:
48 aprintf("stop requested...\n");
49 webserver->Stop();
50 delete(webserver);
51 exit(0);
55 int main(int argc, char **argv)
57 bool debug = false;
58 bool do_fork = true;
60 int i;
62 if (argc > 1)
64 for (i = 1; i < argc; i++)
67 if (strncmp(argv[i], "-d", 2) == 0)
69 CDEBUG::getInstance()->Debug = true;
70 do_fork = false;
72 else
74 if (strncmp(argv[i], "-f", 2) == 0)
76 do_fork = false;
78 else if (strncmp(argv[i],"--version", 9) == 0)
80 printf("chttp - Webserver\n");
81 printf("Version: %s\n", CHTTPD_VERSION);
82 return 0;
84 else if ((strncmp(argv[i], "--help", 6) == 0) || (strncmp(argv[i], "-h", 2) == 0))
86 printf("chttpd parameters:\n");
87 printf("-d\t\tdebug\n");
88 printf("-f\t\tdo not fork\n");
89 printf("--version\tversion\n");
90 printf("--help\t\tthis text\n\n");
91 return 0;
96 signal(SIGINT,sig_catch);
97 signal(SIGHUP,sig_catch);
98 signal(SIGTERM,sig_catch);
100 aprintf("HTTP-Server starting..\n");
102 if (do_fork)
104 switch (fork())
106 case -1:
107 dperror("fork");
108 return -1;
109 case 0:
110 break;
111 default:
112 return 0;
115 if (setsid() == -1)
117 dperror("[chttpd] Error setsid");
118 return -1;
122 if ((webserver = new CWebserver(debug)) != NULL)
124 if (webserver->Start())
126 webserver->DoLoop();
127 webserver->Stop();
130 else
132 aprintf("Error initializing chttpd\n");
133 return -1;
136 return 0;
138 #else
139 int main(int argc, char **argv)
141 return 0;
143 #endif