Fri, 01 Nov 2024 12:25:52 +0100
fix pgext uses a wrong field number, if the column has the same name as a resource or property column
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 | * |
44
3da1f7b6847f
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
35
diff
changeset
|
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
30
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 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
29 | #include <cx/hash_map.h> |
541
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
30 | #include <cx/linked_list.h> |
159
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
31 | #include "../util/atomic.h" |
30
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 | #include "event.h" |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | |
555
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
35 | static CxMap *event_handler_map = NULL; |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | int numevhandlers = 0; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
159
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
38 | EVHandler *default_event_handler = NULL; |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
159
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
40 | EVHandler *last_handler_c = NULL; |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | int create_event_handler(EventHandlerConfig *cfg) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | if(event_handler_map == NULL) { |
490 | 44 | event_handler_map = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
47 | CxHashKey key = cx_hash_key_bytes((const unsigned char*)cfg->name.ptr, cfg->name.length); |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
48 | |
443
ef3c8a0e1fee
improve daemon startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
49 | // if the event handler already exists, we don't modify it |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
50 | if(cxMapGet(event_handler_map, key)) { |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | /* TODO: log message */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | /* TODO: set reload status */ |
443
ef3c8a0e1fee
improve daemon startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
53 | log_ereport(LOG_DEBUG, "event handler %s already exists", cfg->name.ptr); |
440
d77b8f3e14e2
implement successor listener, fix webserver_reconfig
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
54 | return 0; |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | |
443
ef3c8a0e1fee
improve daemon startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
57 | // create new handler |
159
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
58 | EVHandler *e = evhandler_create(cfg); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | if(e == NULL) { |
443
ef3c8a0e1fee
improve daemon startup
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
440
diff
changeset
|
60 | log_ereport(LOG_FAILURE, "evhandler_create failed"); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | return 1; |
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 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | if(cfg->isdefault) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | if(default_event_handler) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | /* there can be only one default event handler */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | /* TODO: log warning */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | default_event_handler = e; |
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 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
72 | int ret = cxMapPut(event_handler_map, key, e); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | if(ret == 0) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | last_handler_c = e; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | numevhandlers++; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | return ret; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | |
555
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
81 | void shutdown_eventhandlers_wait(void) { |
556
b036ccad4b49
improve webserver shutdown and free some stuff to make the valgrind output cleaner
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
555
diff
changeset
|
82 | log_ereport(LOG_INFORM, "shutdown eventhandlers"); |
b036ccad4b49
improve webserver shutdown and free some stuff to make the valgrind output cleaner
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
555
diff
changeset
|
83 | |
555
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
84 | CxIterator i = cxMapIteratorValues(event_handler_map); |
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
85 | cx_foreach(EVHandler *, e, i) { |
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
86 | evhandler_shutdown(e); |
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
87 | } |
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
88 | |
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
89 | i = cxMapIteratorValues(event_handler_map); |
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
90 | cx_foreach(EVHandler *, e, i) { |
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
91 | evhandler_wait_and_destroy(e); |
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
92 | } |
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
93 | |
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
94 | cxMapDestroy(event_handler_map); |
556
b036ccad4b49
improve webserver shutdown and free some stuff to make the valgrind output cleaner
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
555
diff
changeset
|
95 | |
b036ccad4b49
improve webserver shutdown and free some stuff to make the valgrind output cleaner
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
555
diff
changeset
|
96 | log_ereport(LOG_INFORM, "all eventhandlers closed"); |
555
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
97 | } |
66b0accda0a8
move first request poll to the event handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
552
diff
changeset
|
98 | |
552
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
99 | void evhandler_shutdown(EVHandler *h) { |
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
100 | for(int i=0;i<h->numins;i++) { |
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
101 | ev_instance_shutdown(h->instances[i]); |
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
102 | } |
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
103 | } |
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
104 | |
547
280bf87c8689
add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
105 | void evhandler_close(EVHandler *h) { |
280bf87c8689
add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
106 | for(int i=0;i<h->numins;i++) { |
280bf87c8689
add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
107 | ev_instance_close(h->instances[i]); |
280bf87c8689
add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
108 | } |
552
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
109 | } |
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
110 | |
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
111 | void evhandler_wait_and_destroy(EVHandler *h) { |
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
112 | for(int i=0;i<h->numins;i++) { |
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
113 | ev_instance_wait(h->instances[i]); |
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
114 | } |
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
115 | |
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
116 | free(h->instances); |
4ed0e46aa9dc
add test for sending multiple events to an eventhandler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
547
diff
changeset
|
117 | free(h); |
547
280bf87c8689
add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
118 | } |
280bf87c8689
add functions to stop event handlers
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
543
diff
changeset
|
119 | |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | /* |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | * 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
|
122 | * 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
|
123 | */ |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | int check_event_handler_cfg() { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | if(numevhandlers > 0 ) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | if(default_event_handler) { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | return 0; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | } else { |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | default_event_handler = last_handler_c; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | return 0; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | EventHandlerConfig cfg; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
135 | cfg.name = cx_str("default"); |
30
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | cfg.nthreads = 1; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | cfg.isdefault = 1; |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | return create_event_handler(&cfg); |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | } |
27c7511c0e34
new proppatch, mkcol and delete method
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | |
35
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
142 | |
159
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
143 | EVHandler* get_default_event_handler() { |
35
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
144 | return default_event_handler; |
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
145 | } |
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
146 | |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
147 | EVHandler* get_event_handler(const char *name) { |
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
256
diff
changeset
|
148 | return cxMapGet(event_handler_map, cx_hash_key_str(name)); |
35
4417619a9bbd
using non blocking IO for request input
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
30
diff
changeset
|
149 | } |
159
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
150 | |
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
151 | EventHandler* ev_instance(EVHandler *ev) { |
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
152 | int nev = ev->numins; |
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
153 | if(nev == 1) { |
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
154 | return ev->instances[0]; |
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
155 | } |
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
156 | |
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
157 | int ins = ev->current & nev; |
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
158 | ws_atomic_inc32(&ev->current); |
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
159 | return ev->instances[ins]; |
9ba9f8befa80
makes EventHandler public
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
92
diff
changeset
|
160 | } |
541
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
161 | |
542
1327febf99c4
refactore keep alive handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
162 | int ev_free_event(EventHandler *h, Event *event) { |
1327febf99c4
refactore keep alive handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
163 | free(event); |
1327febf99c4
refactore keep alive handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
164 | return 0; |
1327febf99c4
refactore keep alive handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
165 | } |
1327febf99c4
refactore keep alive handler
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
541
diff
changeset
|
166 | |
541
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
167 | |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
168 | void ev_watchlist_add(EventHandler *h, EVWatchList *elm) { |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
169 | watchlist_add(&h->watchlist_begin, &h->watchlist_end, elm); |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
170 | } |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
171 | |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
172 | void ev_watchlist_remove(EventHandler *h, EVWatchList *elm) { |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
173 | watchlist_remove(&h->watchlist_begin, &h->watchlist_end, elm); |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
174 | } |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
175 | |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
176 | void ev_saf_return(EventHandler *h, Session *sn, Request *rq, int ret) { |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
177 | h->fnreturn[h->numret++] = (EVReturn){ sn, rq, ret }; |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
178 | } |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
179 | |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
180 | void watchlist_add(EVWatchList **begin, EVWatchList **end, EVWatchList *elm) { |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
181 | cx_linked_list_add( |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
182 | (void**)begin, |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
183 | (void**)end, |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
184 | offsetof(EVWatchList, prev), |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
185 | offsetof(EVWatchList, next), |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
186 | elm); |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
187 | } |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
188 | |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
189 | void watchlist_remove(EVWatchList **begin, EVWatchList **end, EVWatchList *elm) { |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
190 | cx_linked_list_remove( |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
191 | (void**)begin, |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
192 | (void**)end, |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
193 | offsetof(EVWatchList, prev), |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
194 | offsetof(EVWatchList, next), |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
195 | elm); |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
196 | } |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
197 | |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
198 | void watchlist_check(EventHandler *h, time_t t) { |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
199 | if(t == 0) { |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
200 | t = time(NULL); |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
201 | } |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
202 | |
543
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
203 | log_ereport(LOG_DEBUG, "eventhandler: check watchlist"); |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
204 | |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
205 | EVWatchList *elm = h->watchlist_begin; |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
206 | while(elm) { |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
207 | EVWatchList *next = elm->next; |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
208 | |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
209 | if(elm->expire < t) { |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
210 | ev_watchlist_remove(h, elm); |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
211 | |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
212 | if(elm->destroy) { |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
213 | elm->destroy(h, elm); |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
214 | } |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
215 | } |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
216 | |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
217 | elm = next; |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
218 | } |
3335f431a91b
implement keep-alive timeout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
542
diff
changeset
|
219 | |
541
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
220 | |
1e1fca11aaff
refactore EventHandler: add common fields to base struct
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
490
diff
changeset
|
221 | } |