src/server/daemon/event.c

Sun, 30 Dec 2012 15:49:44 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 30 Dec 2012 15:49:44 +0100
changeset 39
de4bc3cd2d36
parent 35
4417619a9bbd
child 44
3da1f7b6847f
permissions
-rw-r--r--

added mime type configuration file

30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2011 Olaf Wintermann. All rights reserved.
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "../ucx/map.h"
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include "event.h"
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 UcxMap *event_handler_map = NULL;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 int numevhandlers = 0;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 event_handler_t *default_event_handler = NULL;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 event_handler_t *last_handler_c = NULL;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 int create_event_handler(EventHandlerConfig *cfg) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 if(event_handler_map == NULL) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 event_handler_map = ucx_map_new(16);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 /* if the event handler already exists, we don't modify it */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 if(ucx_map_sstr_get(event_handler_map, cfg->name)) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 /* TODO: log message */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 /* TODO: set reload status */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 return 1;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 /* create new handler */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 event_handler_t *e = evhandler_create(cfg->nthreads);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 if(e == NULL) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 return 1;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 if(cfg->isdefault) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 if(default_event_handler) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 /* there can be only one default event handler */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 /* TODO: log warning */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 default_event_handler = e;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 int ret = ucx_map_sstr_put(event_handler_map, cfg->name, e);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 if(ret == 0) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 last_handler_c = e;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 numevhandlers++;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 return ret;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 /*
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 * checks if there is at least one event handler and a default handler
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 * if necessary, check_event_handler_cfg() creates a default event handler
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 */
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 int check_event_handler_cfg() {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 if(numevhandlers > 0 ) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 if(default_event_handler) {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 return 0;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 } else {
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 default_event_handler = last_handler_c;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 return 0;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 EventHandlerConfig cfg;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 cfg.name = sstr("default");
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 cfg.nthreads = 1;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 cfg.isdefault = 1;
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 return create_event_handler(&cfg);
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 }
27c7511c0e34 new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
35
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
97
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
98 event_handler_t* get_default_event_handler() {
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
99 return default_event_handler;
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
100 }
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
101
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
102 event_handler_t* get_event_handler(char *name) {
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
103 return ucx_map_cstr_get(event_handler_map, name);
4417619a9bbd using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 30
diff changeset
104 }

mercurial