aboutsummaryrefslogtreecommitdiff
path: root/src/gethandler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gethandler.c')
-rw-r--r--src/gethandler.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/gethandler.c b/src/gethandler.c
new file mode 100644
index 00000000..297d53a6
--- /dev/null
+++ b/src/gethandler.c
@@ -0,0 +1,96 @@
1/* Copyrights 2002 Luis Figueiredo (stdio@netc.pt) All rights reserved.
2 *
3 * See the LICENSE file
4 *
5 * The origin of this software must not be misrepresented, either by
6 * explicit claim or by omission. Since few users ever read sources,
7 * credits must appear in the documentation.
8 *
9 * date: Sat Mar 30 14:44:42 GMT 2002
10 *
11 * -- handlers functions
12 *
13 */
14
15
16
17#include "gethandler.h"
18
19
20/*********************************************************************************************************/
21/*
22 * initializate (allocate) handler list
23 */
24struct gethandler *__ILWS_init_handler_list() {
25 struct gethandler *ret;
26
27 ret=__ILWS_malloc(sizeof(struct gethandler));
28 if(ret==NULL) {
29 LWSERR(LE_MEMORY);
30 return NULL;
31 };
32 ret->next=NULL;
33 ret->hdl.func=NULL; // or path
34 ret->flag=0;
35 ret->str=NULL;
36 return ret;
37}
38
39/*********************************************************************************************************/
40/*
41 * add an handler to list
42 */
43int __ILWS_add_handler(struct gethandler *handler, const char *mstr, void (*func)(), char *path, int flag, int type) {
44 struct gethandler *temp=handler;
45 while(temp->next!=NULL)temp=temp->next;
46
47 temp->next=__ILWS_malloc(sizeof(struct gethandler));
48 if(temp->next==NULL) {
49 LWSERR(LE_MEMORY);
50 return 0;
51 };
52
53 temp->next->str=__ILWS_malloc(strlen(mstr)+1);
54 if(temp->next->str==NULL) {
55 __ILWS_free(temp->next); // free last malloced
56 LWSERR(LE_MEMORY);
57 return 0;
58 };
59 memcpy(temp->next->str,mstr,strlen(mstr));
60 temp->next->str[strlen(mstr)]='\0';
61
62 temp->next->type=type;
63 switch (temp->next->type) {
64 case 0:
65 temp->next->hdl.func=func; // for function
66 break;
67 case 1: // new on 0.5.2 // directory or cgi
68 case 2:
69 if(!(temp->next->hdl.path=strdup(path))) {
70 __ILWS_free(temp->next->str);
71 __ILWS_free(temp->next);
72 LWSERR(LE_MEMORY);
73 return 0;
74 };
75
76 break;
77 };
78
79 temp->next->flag=flag;
80 temp->next->next=NULL;
81 return 1;
82}
83
84/*********************************************************************************************************/
85/*
86 * Deletes the entire handler list
87 */
88void __ILWS_delete_handler_list(struct gethandler *handler) {
89 struct gethandler *next;
90
91 while(handler) {
92 next = handler->next;
93 __ILWS_free(handler);
94 handler = next;
95 }
96}