-
Notifications
You must be signed in to change notification settings - Fork 32
/
cicapcalls.c
242 lines (213 loc) · 7.89 KB
/
cicapcalls.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
* Copyright (C) 2004-2008 Christos Tsantilas
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*/
#include "common.h"
#include "c-icap.h"
#include "proc_threads_queues.h"
#include "request.h"
#include "module.h"
#include <w32api/windows.h>
char *logformat_fmt(const char *name)
{
typedef char* (*LF_FMT)(const char *);
LF_FMT fn;
fn = (LF_FMT)GetProcAddress(GetModuleHandle(NULL), "logformat_fmt");
if (fn)
return (*fn)(name);
fprintf(stderr, "Can not execute logformat_fmt\n");
return NULL;
}
void ci_command_register_action(const char *name, int type, void *data,
void (*command_action) (const char *name, int type, void *data))
{
typedef void (*RA)(const char *, int, void *, void(*)(const char *, int, void *));
RA fn;
fn = (RA)GetProcAddress(GetModuleHandle(NULL), "ci_command_register_action");
if (fn)
(*fn)(name, type, data, command_action);
else
fprintf(stderr, "Can not execute ci_command_register_action\n");
}
void ci_command_register_ctl_cmd(const char *name, int type, void (*command_action)(const char *name,int type, const char **argv))
{
typedef void (*RC)(const char *, int, void(*)(const char *, int, const char **));
RC fn;
fn = (RC)GetProcAddress(GetModuleHandle(NULL), "ci_command_register_ctl_cmd");
if (fn)
(*fn)(name, type, command_action);
else
fprintf(stderr, "Can not execute ci_command_register_ctl_cmd\n");
}
void ci_command_schedule_on(const char *name, void *data, time_t time)
{
typedef void (*CS)(const char *, void *, time_t);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_command_schedule_on");
if (fn)
(*fn)(name, data, time);
else
fprintf(stderr, "Can not execute ci_command_schedule_on\n");
}
void ci_command_schedule(const char *name, void *data, time_t time)
{
typedef void (*CS)(const char *, void *, time_t);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_command_schedule");
if (fn)
(*fn)(name, data, time);
else
fprintf(stderr, "Can not execute ci_command_schedule\n");
}
void ci_command_register_child_cleanup(const char *name, void *data, void (*child_cleanup_handler) (const char *name, HANDLE pid, int reason, void *data))
{
typedef void (*RC)(const char *, void *, void(*)(const char *, HANDLE, int, void *));
RC fn;
fn = (RC)GetProcAddress(GetModuleHandle(NULL), "ci_command_register_child_cleanup");
if (fn)
(*fn)(name, data, child_cleanup_handler);
else
fprintf(stderr, "Can not execute ci_command_register_child_cleanup\n");
}
ci_kbs_t ci_server_stat_kbs_get_running(int id)
{
typedef ci_kbs_t (*CS)(int id);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_server_stat_kbs_get_running");
if (fn)
return (*fn)(id);
fprintf(stderr, "Can not execute ci_server_stat_kbs_get_running\n");
return ci_kbs_zero();
}
uint64_t ci_server_stat_uint64_get_running(int id)
{
typedef uint64_t (*CS)(int id);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_server_stat_uint64_get_running");
if (fn)
return (*fn)(id);
fprintf(stderr, "Can not execute ci_server_stat_uint64_get_running\n");
return 0;
}
ci_kbs_t ci_server_stat_kbs_get_global(int id)
{
typedef ci_kbs_t (*CS)(int id);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_server_stat_kbs_get_global");
if (fn)
return (*fn)(id);
fprintf(stderr, "Can not execute ci_server_stat_kbs_get_global\n");
return ci_kbs_zero();
}
uint64_t ci_server_stat_uint64_get_global(int id)
{
typedef uint64_t (*CS)(int id);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_server_stat_uint64_get_global");
if (fn)
return (*fn)(id);
fprintf(stderr, "Can not execute ci_server_stat_uint64_get_global\n");
return 0;
}
ci_stat_memblock_t *ci_server_stat_get_all_stats(uint32_t flags)
{
typedef ci_stat_memblock_t *(*CS)(uint32_t);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_server_stat_get_all_stats");
if (fn)
return (*fn)(flags);
fprintf(stderr, "Can not execute ci_server_stat_get_all_stats\n");
return NULL;
}
void ci_server_stat_free_all_stats(ci_stat_memblock_t *blk)
{
typedef void (*CS)(ci_stat_memblock_t *);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_server_stat_free_all_stats");
if (fn)
(*fn)(blk);
fprintf(stderr, "Can not execute ci_server_stat_free_all_stats\n");
}
const ci_stat_memblock_t *ci_server_stat_get_child_stats(process_pid_t pid, uint32_t flags)
{
typedef const ci_stat_memblock_t *(*CS)(process_pid_t, uint32_t);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_server_stat_get_child_stats");
if (fn)
return (*fn)(pid, flags);
fprintf(stderr, "Can not execute ci_server_stat_get_child_stats\n");
return NULL;
}
const ci_stat_memblock_t *ci_server_stat_get_history_stats(uint32_t flags)
{
typedef const ci_stat_memblock_t *(*CS)(uint32_t);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_server_stat_get_history_stats");
if (fn)
return (*fn)(flags);
fprintf(stderr, "Can not execute ci_server_stat_get_history_stats\n");
return NULL;
}
int ci_server_shared_memblob_register(const char *name, size_t size)
{
typedef int (*CS)(const char *, size_t);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_server_shared_memblob_register");
if (fn)
return (*fn)(name, size);
fprintf(stderr, "Can not execute ci_server_shared_memblob_register\n");
return -1;
}
void *ci_server_shared_memblob(int ID)
{
typedef void * (*CS)(int ID);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_server_shared_memblob");
if (fn)
return (*fn)(ID);
fprintf(stderr, "Can not execute ci_server_shared_memblob\n");
return NULL;
}
void * ci_server_shared_memblob_byname(const char *name)
{
typedef void * (*CS)(const char *);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_server_shared_memblob_byname");
if (fn)
return (*fn)(name);
fprintf(stderr, "Can not execute ci_server_shared_memblob_byname\n");
return NULL;
}
void ci_http_server_register_service(const char *path, const char *descr, int (*handler)(ci_request_t *req), unsigned flags)
{
typedef void (*CS)(const char *, const char *, int (*)(ci_request_t *req), unsigned);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_http_server_register_service");
if (fn)
return (*fn)(path, descr, handler, flags);
fprintf(stderr, "Can not execute ci_http_server_register_service\n");
}
common_module_t * ci_common_module_build(const char *name, int (*init_module)(struct ci_server_conf *server_conf), int (*post_init_module)(struct ci_server_conf *server_conf), void (*close_module)(), struct ci_conf_entry *conf_table)
{
typedef common_module_t * (*CS)(const char *, int (*)(struct ci_server_conf *), int (*)(struct ci_server_conf *), void (*)(), struct ci_conf_entry *);
CS fn;
fn = (CS)GetProcAddress(GetModuleHandle(NULL), "ci_common_module_build");
if (fn)
return (*fn)(name, init_module, post_init_module, close_module, conf_table);
fprintf(stderr, "Can not execute ci_common_module_build\n");
return NULL;
}