1 //
2 // aegis - project change supervisor
3 // Copyright (C) 2003-2006, 2008, 2012 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or (at
8 // your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #include <common/ac/string.h>
20 
21 #include <common/sizeof.h>
22 #include <libaegis/http.h>
23 
24 #include <aeget/cgi.h>
25 #include <aeget/forkandwatch.h>
26 #include <aeget/get.h>
27 
28 
29 struct table_t
30 {
31     const char      *name;
32     void            (*action)(void);
33 };
34 
35 
36 static table_t table[] =
37 {
38     { "GET", get },
39 };
40 
41 
42 void
cgi(void)43 cgi(void)
44 {
45     const char      *request_method;
46     table_t         *tp;
47 
48     fork_and_watch();
49     request_method = http_getenv("REQUEST_METHOD");
50     for (tp = table; tp < ENDOF(table); ++tp)
51     {
52         if (0 == strcasecmp(request_method, tp->name))
53         {
54             tp->action();
55             return;
56         }
57     }
58     http_fatal
59     (
60         http_error_method_not_allowed,
61         "The \"%s\" method is not supported.",
62         request_method
63     );
64 }
65 
66 
67 // vim: set ts=8 sw=4 et :
68