70 |
|
static void libopm_do_hup(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); |
71 |
|
static void libopm_do_read(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); |
72 |
|
static void libopm_do_openproxy(OPM_T *, OPM_SCAN_T *, OPM_CONNECTION_T *); |
73 |
– |
|
73 |
|
static void libopm_do_callback(OPM_T *, OPM_REMOTE_T *, int, int); |
74 |
|
|
75 |
|
static OPM_REMOTE_T *libopm_setup_remote(OPM_REMOTE_T *, OPM_CONNECTION_T *); |
82 |
|
* data). |
83 |
|
* |
84 |
|
*/ |
85 |
< |
|
86 |
< |
static OPM_PROTOCOL_T OPM_PROTOCOLS[] = { |
87 |
< |
{OPM_TYPE_HTTP, libopm_proxy_http_write, NULL}, |
88 |
< |
{OPM_TYPE_SOCKS4, libopm_proxy_socks4_write, NULL}, |
89 |
< |
{OPM_TYPE_SOCKS5, libopm_proxy_socks5_write, NULL}, |
90 |
< |
{OPM_TYPE_ROUTER, libopm_proxy_router_write, NULL}, |
91 |
< |
{OPM_TYPE_WINGATE, libopm_proxy_wingate_write, NULL}, |
92 |
< |
{OPM_TYPE_HTTPPOST, libopm_proxy_httppost_write, NULL} |
85 |
> |
static OPM_PROTOCOL_T OPM_PROTOCOLS[] = |
86 |
> |
{ |
87 |
> |
{ OPM_TYPE_HTTP, libopm_proxy_http_write, NULL }, |
88 |
> |
{ OPM_TYPE_SOCKS4, libopm_proxy_socks4_write, NULL }, |
89 |
> |
{ OPM_TYPE_SOCKS5, libopm_proxy_socks5_write, NULL }, |
90 |
> |
{ OPM_TYPE_ROUTER, libopm_proxy_router_write, NULL }, |
91 |
> |
{ OPM_TYPE_WINGATE, libopm_proxy_wingate_write, NULL }, |
92 |
> |
{ OPM_TYPE_HTTPPOST, libopm_proxy_httppost_write, NULL } |
93 |
|
}; |
94 |
|
|
96 |
– |
|
97 |
– |
|
98 |
– |
|
95 |
|
/* opm_create |
96 |
|
* |
97 |
|
* Initialize a new scanner and return a pointer to it. |
98 |
|
* |
99 |
|
* Parameters: |
100 |
|
* None |
101 |
< |
* |
102 |
< |
* Return |
101 |
> |
* |
102 |
> |
* Return |
103 |
|
* Pointer to new OPM_T (scanner) |
104 |
|
*/ |
105 |
< |
|
106 |
< |
OPM_T *opm_create() |
105 |
> |
OPM_T * |
106 |
> |
opm_create(void) |
107 |
|
{ |
108 |
< |
int i; |
109 |
< |
OPM_T *ret; |
108 |
> |
int i; |
109 |
> |
OPM_T *ret; |
110 |
|
|
111 |
< |
ret = xcalloc(sizeof *ret); |
111 |
> |
ret = xcalloc(sizeof *ret); |
112 |
|
|
113 |
< |
ret->config = libopm_config_create(); |
114 |
< |
ret->scans = libopm_list_create(); |
115 |
< |
ret->queue = libopm_list_create(); |
116 |
< |
ret->protocols = libopm_list_create(); |
117 |
< |
ret->fd_use = 0; |
118 |
< |
|
119 |
< |
/* Setup callbacks */ |
120 |
< |
ret->callbacks = xcalloc(sizeof(OPM_CALLBACK_T) * CBLEN); |
121 |
< |
for(i = 0; i < CBLEN; i++) |
122 |
< |
{ |
123 |
< |
ret->callbacks[i].func = NULL; |
124 |
< |
ret->callbacks[i].data = NULL; |
125 |
< |
} |
113 |
> |
ret->config = libopm_config_create(); |
114 |
> |
ret->scans = libopm_list_create(); |
115 |
> |
ret->queue = libopm_list_create(); |
116 |
> |
ret->protocols = libopm_list_create(); |
117 |
> |
ret->fd_use = 0; |
118 |
> |
|
119 |
> |
/* Setup callbacks */ |
120 |
> |
ret->callbacks = xcalloc(sizeof(OPM_CALLBACK_T) * CBLEN); |
121 |
> |
|
122 |
> |
for (i = 0; i < CBLEN; i++) |
123 |
> |
{ |
124 |
> |
ret->callbacks[i].func = NULL; |
125 |
> |
ret->callbacks[i].data = NULL; |
126 |
> |
} |
127 |
|
|
128 |
< |
return ret; |
128 |
> |
return ret; |
129 |
|
} |
130 |
|
|
134 |
– |
|
135 |
– |
|
136 |
– |
|
131 |
|
/* opm_remote_create |
132 |
|
* |
133 |
|
* Create OPM_REMOTE_T struct, fill it with neccessary |
140 |
|
* Address of OPM_REMOTE_T created |
141 |
|
* |
142 |
|
*/ |
143 |
+ |
OPM_REMOTE_T * |
144 |
+ |
opm_remote_create(const char *ip) |
145 |
+ |
{ |
146 |
+ |
OPM_REMOTE_T *ret; |
147 |
|
|
148 |
< |
OPM_REMOTE_T *opm_remote_create(const char *ip) |
151 |
< |
{ |
152 |
< |
OPM_REMOTE_T *ret; |
153 |
< |
|
154 |
< |
|
155 |
< |
ret = xcalloc(sizeof *ret); |
156 |
< |
|
157 |
< |
/* Do initializations */ |
158 |
< |
if(ip == NULL) |
159 |
< |
return NULL; |
148 |
> |
ret = xcalloc(sizeof *ret); |
149 |
|
|
150 |
< |
ret->ip = libopm_xstrdup(ip); |
150 |
> |
/* Do initializations */ |
151 |
> |
if (ip == NULL) |
152 |
> |
return NULL; |
153 |
|
|
154 |
< |
ret->port = 0; |
164 |
< |
ret->protocol = 0; |
165 |
< |
ret->bytes_read = 0; |
154 |
> |
ret->ip = libopm_xstrdup(ip); |
155 |
|
|
156 |
< |
ret->data = NULL; |
156 |
> |
ret->port = 0; |
157 |
> |
ret->protocol = 0; |
158 |
> |
ret->bytes_read = 0; |
159 |
> |
ret->data = NULL; |
160 |
|
|
161 |
< |
ret->protocols = libopm_list_create(); /* setup protocol list */ |
161 |
> |
ret->protocols = libopm_list_create(); /* Setup protocol list */ |
162 |
|
|
163 |
< |
return ret; |
163 |
> |
return ret; |
164 |
|
} |
165 |
|
|
174 |
– |
|
175 |
– |
|
166 |
|
/* opm_remote_free |
167 |
|
* |
168 |
|
* Free OPM_REMOTE_T struct and cleanup |
173 |
|
* Return: |
174 |
|
* None |
175 |
|
*/ |
176 |
< |
|
177 |
< |
void opm_remote_free(OPM_REMOTE_T *remote) |
176 |
> |
void |
177 |
> |
opm_remote_free(OPM_REMOTE_T *remote) |
178 |
|
{ |
179 |
+ |
OPM_NODE_T *p, *next; |
180 |
+ |
OPM_PROTOCOL_CONFIG_T *ppc; |
181 |
|
|
182 |
< |
OPM_NODE_T *p, *next; |
191 |
< |
OPM_PROTOCOL_CONFIG_T *ppc; |
182 |
> |
MyFree(remote->ip); |
183 |
|
|
184 |
< |
MyFree(remote->ip); |
184 |
> |
LIST_FOREACH_SAFE(p, next, remote->protocols->head) |
185 |
> |
{ |
186 |
> |
ppc = p->data; |
187 |
|
|
188 |
< |
LIST_FOREACH_SAFE(p, next, remote->protocols->head) |
189 |
< |
{ |
190 |
< |
ppc = p->data; |
191 |
< |
|
199 |
< |
libopm_protocol_config_free(ppc); |
200 |
< |
libopm_list_remove(remote->protocols, p); |
201 |
< |
libopm_node_free(p); |
202 |
< |
} |
188 |
> |
libopm_protocol_config_free(ppc); |
189 |
> |
libopm_list_remove(remote->protocols, p); |
190 |
> |
libopm_node_free(p); |
191 |
> |
} |
192 |
|
|
193 |
< |
libopm_list_free(remote->protocols); |
193 |
> |
libopm_list_free(remote->protocols); |
194 |
|
|
195 |
< |
MyFree(remote); |
195 |
> |
MyFree(remote); |
196 |
|
} |
197 |
|
|
209 |
– |
|
210 |
– |
|
211 |
– |
|
198 |
|
/* opm_callback |
199 |
|
* Register scanner level callback |
200 |
|
* |
205 |
|
* Error code |
206 |
|
*/ |
207 |
|
|
208 |
< |
OPM_ERR_T opm_callback(OPM_T *scanner, int type, OPM_CALLBACK_FUNC *function, void *data) |
208 |
> |
OPM_ERR_T |
209 |
> |
opm_callback(OPM_T *scanner, int type, OPM_CALLBACK_FUNC *function, void *data) |
210 |
|
{ |
211 |
< |
if(type < 0 || type >= (CBLEN + 1)) |
212 |
< |
return OPM_ERR_CBNOTFOUND; |
211 |
> |
if (type < 0 || type >= (CBLEN + 1)) |
212 |
> |
return OPM_ERR_CBNOTFOUND; |
213 |
|
|
214 |
< |
scanner->callbacks[type].func = function; |
215 |
< |
scanner->callbacks[type].data = data; |
214 |
> |
scanner->callbacks[type].func = function; |
215 |
> |
scanner->callbacks[type].data = data; |
216 |
|
|
217 |
< |
return OPM_SUCCESS; |
217 |
> |
return OPM_SUCCESS; |
218 |
|
} |
219 |
|
|
233 |
– |
|
234 |
– |
|
235 |
– |
|
220 |
|
/* opm_free |
221 |
|
* |
222 |
|
* Free OPM_T (scanner) and cleanup |
227 |
|
* Return: |
228 |
|
* None |
229 |
|
*/ |
230 |
< |
|
231 |
< |
void opm_free(OPM_T *scanner) |
230 |
> |
void |
231 |
> |
opm_free(OPM_T *scanner) |
232 |
|
{ |
233 |
< |
OPM_NODE_T *p, *next; |
234 |
< |
OPM_PROTOCOL_CONFIG_T *ppc; |
235 |
< |
OPM_SCAN_T *scan; |
236 |
< |
|
237 |
< |
libopm_config_free(scanner->config); |
233 |
> |
OPM_NODE_T *p, *next; |
234 |
> |
OPM_PROTOCOL_CONFIG_T *ppc; |
235 |
> |
OPM_SCAN_T *scan; |
236 |
> |
|
237 |
> |
libopm_config_free(scanner->config); |
238 |
> |
|
239 |
> |
LIST_FOREACH_SAFE(p, next, scanner->protocols->head) |
240 |
> |
{ |
241 |
> |
ppc = p->data; |
242 |
> |
|
243 |
> |
libopm_protocol_config_free(ppc); |
244 |
> |
libopm_list_remove(scanner->protocols, p); |
245 |
> |
libopm_node_free(p); |
246 |
> |
} |
247 |
> |
|
248 |
> |
LIST_FOREACH_SAFE(p, next, scanner->scans->head) |
249 |
> |
{ |
250 |
> |
scan = p->data; |
251 |
> |
|
252 |
> |
libopm_scan_free(scan); |
253 |
> |
libopm_list_remove(scanner->scans, p); |
254 |
> |
libopm_node_free(p); |
255 |
> |
} |
256 |
> |
|
257 |
> |
LIST_FOREACH_SAFE(p, next, scanner->queue->head) |
258 |
> |
{ |
259 |
> |
scan = p->data; |
260 |
> |
|
261 |
> |
libopm_scan_free(scan); |
262 |
> |
libopm_list_remove(scanner->queue, p); |
263 |
> |
libopm_node_free(p); |
264 |
> |
} |
265 |
> |
|
266 |
> |
libopm_list_free(scanner->protocols); |
267 |
> |
libopm_list_free(scanner->scans); |
268 |
> |
libopm_list_free(scanner->queue); |
269 |
|
|
270 |
< |
LIST_FOREACH_SAFE(p, next, scanner->protocols->head) |
271 |
< |
{ |
257 |
< |
ppc = p->data; |
258 |
< |
|
259 |
< |
libopm_protocol_config_free(ppc); |
260 |
< |
libopm_list_remove(scanner->protocols, p); |
261 |
< |
libopm_node_free(p); |
262 |
< |
} |
263 |
< |
|
264 |
< |
LIST_FOREACH_SAFE(p, next, scanner->scans->head) |
265 |
< |
{ |
266 |
< |
scan = p->data; |
267 |
< |
libopm_scan_free(scan); |
268 |
< |
libopm_list_remove(scanner->scans, p); |
269 |
< |
libopm_node_free(p); |
270 |
< |
} |
271 |
< |
|
272 |
< |
LIST_FOREACH_SAFE(p, next, scanner->queue->head) |
273 |
< |
{ |
274 |
< |
scan = p->data; |
275 |
< |
libopm_scan_free(scan); |
276 |
< |
libopm_list_remove(scanner->queue, p); |
277 |
< |
libopm_node_free(p); |
278 |
< |
} |
279 |
< |
|
280 |
< |
libopm_list_free(scanner->protocols); |
281 |
< |
libopm_list_free(scanner->scans); |
282 |
< |
libopm_list_free(scanner->queue); |
283 |
< |
|
284 |
< |
MyFree(scanner->callbacks); |
285 |
< |
MyFree(scanner); |
270 |
> |
MyFree(scanner->callbacks); |
271 |
> |
MyFree(scanner); |
272 |
|
} |
273 |
|
|
288 |
– |
|
289 |
– |
|
290 |
– |
|
274 |
|
/* opm_config |
275 |
|
* |
276 |
|
* Wrapper to config_set. Set configuration variables |
284 |
|
* Return: |
285 |
|
* OPM_ERR_T containing error code |
286 |
|
*/ |
287 |
< |
|
288 |
< |
OPM_ERR_T opm_config(OPM_T *scanner, int key, const void *value) |
287 |
> |
OPM_ERR_T |
288 |
> |
opm_config(OPM_T *scanner, int key, const void *value) |
289 |
|
{ |
290 |
< |
return libopm_config_set((scanner->config), key, value); |
290 |
> |
return libopm_config_set((scanner->config), key, value); |
291 |
|
} |
292 |
|
|
310 |
– |
|
311 |
– |
|
312 |
– |
|
293 |
|
/* opm_addtype |
294 |
|
* |
295 |
< |
* Add a proxy type and port to the list of protocols |
295 |
> |
* Add a proxy type and port to the list of protocols |
296 |
|
* a scanner will use. |
297 |
< |
* |
297 |
> |
* |
298 |
|
* Parameters: |
299 |
|
* scanner: pointer to scanner struct |
300 |
|
* type: type of proxy to scan (used in hashing to the functions) |
303 |
|
* OPM_SUCCESS: Successful protocol add |
304 |
|
* OPM_ERR_BADPROTOCOL: Protocol is unknown |
305 |
|
*/ |
306 |
< |
|
307 |
< |
OPM_ERR_T opm_addtype(OPM_T *scanner, int type, unsigned short int port) |
306 |
> |
OPM_ERR_T |
307 |
> |
opm_addtype(OPM_T *scanner, int type, unsigned short int port) |
308 |
|
{ |
309 |
< |
unsigned int i; |
330 |
< |
|
331 |
< |
OPM_NODE_T *node; |
332 |
< |
OPM_PROTOCOL_CONFIG_T *protocol_config; |
333 |
< |
|
334 |
< |
for(i = 0; i < sizeof(OPM_PROTOCOLS) / sizeof(OPM_PROTOCOL_T); i++) |
335 |
< |
{ |
336 |
< |
if(type == OPM_PROTOCOLS[i].type) |
337 |
< |
{ |
338 |
< |
protocol_config = libopm_protocol_config_create(); |
309 |
> |
unsigned int i; |
310 |
|
|
311 |
< |
protocol_config->type = &OPM_PROTOCOLS[i]; |
312 |
< |
protocol_config->port = port; |
342 |
< |
|
343 |
< |
node = libopm_node_create(protocol_config); |
344 |
< |
libopm_list_add(scanner->protocols, node); |
311 |
> |
OPM_NODE_T *node; |
312 |
> |
OPM_PROTOCOL_CONFIG_T *protocol_config; |
313 |
|
|
314 |
< |
return OPM_SUCCESS; |
314 |
> |
for (i = 0; i < sizeof(OPM_PROTOCOLS) / sizeof(OPM_PROTOCOL_T); i++) |
315 |
> |
{ |
316 |
> |
if (type == OPM_PROTOCOLS[i].type) |
317 |
> |
{ |
318 |
> |
protocol_config = libopm_protocol_config_create(); |
319 |
> |
protocol_config->type = &OPM_PROTOCOLS[i]; |
320 |
> |
protocol_config->port = port; |
321 |
> |
|
322 |
> |
node = libopm_node_create(protocol_config); |
323 |
> |
libopm_list_add(scanner->protocols, node); |
324 |
> |
|
325 |
> |
return OPM_SUCCESS; |
326 |
> |
} |
327 |
> |
} |
328 |
|
|
329 |
< |
} |
349 |
< |
} |
350 |
< |
return OPM_ERR_BADPROTOCOL; |
329 |
> |
return OPM_ERR_BADPROTOCOL; |
330 |
|
} |
331 |
|
|
353 |
– |
|
354 |
– |
|
332 |
|
/* opm_remote_addtype |
333 |
|
* |
334 |
|
* Add a proxy type and port to the list of protocols |
342 |
|
* OPM_SUCCESS: Successful protocol add |
343 |
|
* OPM_ERR_BADPROTOCOL: Protocol is unknown |
344 |
|
*/ |
368 |
– |
|
345 |
|
OPM_ERR_T opm_remote_addtype(OPM_REMOTE_T *remote, int type, unsigned short int port) |
346 |
|
{ |
347 |
< |
unsigned int i; |
372 |
< |
|
373 |
< |
OPM_NODE_T *node; |
374 |
< |
OPM_PROTOCOL_CONFIG_T *protocol_config; |
347 |
> |
unsigned int i; |
348 |
|
|
349 |
< |
for(i = 0; i < sizeof(OPM_PROTOCOLS) / sizeof(OPM_PROTOCOL_T); i++) |
350 |
< |
{ |
378 |
< |
if(type == OPM_PROTOCOLS[i].type) |
379 |
< |
{ |
380 |
< |
protocol_config = libopm_protocol_config_create(); |
349 |
> |
OPM_NODE_T *node; |
350 |
> |
OPM_PROTOCOL_CONFIG_T *protocol_config; |
351 |
|
|
352 |
< |
protocol_config->type = &OPM_PROTOCOLS[i]; |
353 |
< |
protocol_config->port = port; |
352 |
> |
for (i = 0; i < sizeof(OPM_PROTOCOLS) / sizeof(OPM_PROTOCOL_T); i++) |
353 |
> |
{ |
354 |
> |
if (type == OPM_PROTOCOLS[i].type) |
355 |
> |
{ |
356 |
> |
protocol_config = libopm_protocol_config_create(); |
357 |
> |
protocol_config->type = &OPM_PROTOCOLS[i]; |
358 |
> |
protocol_config->port = port; |
359 |
> |
|
360 |
> |
node = libopm_node_create(protocol_config); |
361 |
> |
libopm_list_add(remote->protocols, node); |
362 |
> |
|
363 |
> |
return OPM_SUCCESS; |
364 |
> |
} |
365 |
> |
} |
366 |
|
|
367 |
< |
node = libopm_node_create(protocol_config); |
386 |
< |
libopm_list_add(remote->protocols, node); |
387 |
< |
|
388 |
< |
return OPM_SUCCESS; |
389 |
< |
} |
390 |
< |
} |
391 |
< |
return OPM_ERR_BADPROTOCOL; |
367 |
> |
return OPM_ERR_BADPROTOCOL; |
368 |
|
} |
369 |
|
|
394 |
– |
|
395 |
– |
|
396 |
– |
|
370 |
|
/* libopm_protocol_create |
371 |
|
* |
372 |
|
* Create OPM_PROTOCOL_T struct. |
379 |
|
* XXX - does not appear to be used anywhere? |
380 |
|
* -grifferz |
381 |
|
*/ |
409 |
– |
|
382 |
|
#if 0 |
383 |
|
static OPM_PROTOCOL_T *libopm_protocol_create(void) |
384 |
|
{ |
385 |
< |
OPM_PROTOCOL_T *ret; |
386 |
< |
ret = xcalloc(sizeof(OPM_PROTOCOL_T)); |
385 |
> |
OPM_PROTOCOL_T *ret; |
386 |
> |
ret = xcalloc(sizeof(OPM_PROTOCOL_T)); |
387 |
> |
|
388 |
> |
ret->type = 0; |
389 |
> |
ret->write_function = NULL; |
390 |
> |
ret->read_function = NULL; |
391 |
|
|
392 |
< |
ret->type = 0; |
417 |
< |
ret->write_function = NULL; |
418 |
< |
ret->read_function = NULL; |
419 |
< |
|
420 |
< |
return ret; |
392 |
> |
return ret; |
393 |
|
} |
394 |
|
#endif |
395 |
|
|
424 |
– |
|
396 |
|
/* libopm_protocol_free |
397 |
|
* |
398 |
< |
* Free an OPM_PROTOCOL_T struct. Assume that if |
399 |
< |
* format is not NULL, it is pointed to dynamically |
398 |
> |
* Free an OPM_PROTOCOL_T struct. Assume that if |
399 |
> |
* format is not NULL, it is pointed to dynamically |
400 |
|
* allocated memory and free it. |
401 |
< |
* |
401 |
> |
* |
402 |
|
* Parameters: |
403 |
|
* protocol: struct to free |
404 |
< |
* |
404 |
> |
* |
405 |
|
* Return: |
406 |
|
* None |
407 |
|
* |
408 |
|
* XXX - apparently no longer used? |
409 |
|
* -grifferz |
410 |
|
*/ |
440 |
– |
|
411 |
|
#if 0 |
412 |
< |
static void libopm_protocol_free(OPM_PROTOCOL_T *protocol) |
412 |
> |
static void |
413 |
> |
libopm_protocol_free(OPM_PROTOCOL_T *protocol) |
414 |
|
{ |
415 |
< |
MyFree(protocol); |
415 |
> |
MyFree(protocol); |
416 |
|
} |
417 |
|
#endif |
418 |
|
|
448 |
– |
|
449 |
– |
|
419 |
|
/* libopm_protocol_config_create |
420 |
|
* |
421 |
|
* Allocate and return address of a new OPM_PROTOCOL_CONFIG_T |
426 |
|
* Return: |
427 |
|
* Address of new OPM_PROTOCOL_CONFIG_T |
428 |
|
*/ |
429 |
< |
|
430 |
< |
static OPM_PROTOCOL_CONFIG_T *libopm_protocol_config_create(void) |
429 |
> |
static OPM_PROTOCOL_CONFIG_T * |
430 |
> |
libopm_protocol_config_create(void) |
431 |
|
{ |
432 |
< |
OPM_PROTOCOL_CONFIG_T *ret; |
433 |
< |
ret = xcalloc(sizeof *ret); |
432 |
> |
OPM_PROTOCOL_CONFIG_T *ret; |
433 |
> |
ret = xcalloc(sizeof *ret); |
434 |
|
|
435 |
< |
return ret; |
435 |
> |
return ret; |
436 |
|
} |
437 |
|
|
469 |
– |
|
470 |
– |
|
471 |
– |
|
438 |
|
/* protocol_config_free |
439 |
|
* |
440 |
|
* Free OPM_PROTOCOL_CONFIG_T struct |
445 |
|
* Return: |
446 |
|
* None |
447 |
|
*/ |
448 |
< |
|
449 |
< |
static void libopm_protocol_config_free(OPM_PROTOCOL_CONFIG_T *protocol) |
448 |
> |
static void |
449 |
> |
libopm_protocol_config_free(OPM_PROTOCOL_CONFIG_T *protocol) |
450 |
|
{ |
451 |
< |
MyFree(protocol); |
451 |
> |
MyFree(protocol); |
452 |
|
} |
453 |
|
|
488 |
– |
|
489 |
– |
|
490 |
– |
|
454 |
|
/* opm_scan |
455 |
|
* |
456 |
|
* Scan remote host. The opm_scan function takes an OPM_REMOTE_T |
460 |
|
* Parameters: |
461 |
|
* scanner: Scanner to scan host on |
462 |
|
* remote: OPM_REMOTE_T defining remote host |
463 |
< |
* |
463 |
> |
* |
464 |
|
* Return: |
465 |
|
* (to be written) |
466 |
|
*/ |
467 |
< |
|
468 |
< |
OPM_ERR_T opm_scan(OPM_T *scanner, OPM_REMOTE_T *remote) |
467 |
> |
OPM_ERR_T |
468 |
> |
opm_scan(OPM_T *scanner, OPM_REMOTE_T *remote) |
469 |
|
{ |
470 |
< |
OPM_SCAN_T *scan; /* New scan for OPM_T */ |
471 |
< |
OPM_NODE_T *node; /* Node we'll add scan to |
472 |
< |
when we link it to scans */ |
510 |
< |
unsigned int fd_limit; |
470 |
> |
OPM_SCAN_T *scan; /* New scan for OPM_T */ |
471 |
> |
OPM_NODE_T *node; /* Node we'll add scan to when we link it to scans */ |
472 |
> |
unsigned int fd_limit; |
473 |
|
|
474 |
< |
fd_limit = *(int *) libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT); |
474 |
> |
fd_limit = *(int *)libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT); |
475 |
|
|
476 |
< |
if(LIST_SIZE(scanner->protocols) == 0 && |
476 |
> |
if (LIST_SIZE(scanner->protocols) == 0 && |
477 |
|
LIST_SIZE(remote->protocols) == 0) |
478 |
< |
{ |
517 |
< |
return OPM_ERR_NOPROTOCOLS; |
518 |
< |
} |
478 |
> |
return OPM_ERR_NOPROTOCOLS; |
479 |
|
|
480 |
< |
scan = libopm_scan_create(scanner, remote); |
480 |
> |
scan = libopm_scan_create(scanner, remote); |
481 |
|
|
482 |
< |
if(inet_pton(AF_INET, remote->ip, &(scan->addr.sa4.sin_addr) ) <= 0) |
483 |
< |
{ |
484 |
< |
libopm_scan_free(scan); |
485 |
< |
return OPM_ERR_BADADDR; |
486 |
< |
} |
482 |
> |
if (inet_pton(AF_INET, remote->ip, &(scan->addr.sa4.sin_addr) ) <= 0) |
483 |
> |
{ |
484 |
> |
libopm_scan_free(scan); |
485 |
> |
return OPM_ERR_BADADDR; |
486 |
> |
} |
487 |
|
|
488 |
< |
node = libopm_node_create(scan); |
489 |
< |
libopm_list_add(scanner->queue, node); |
488 |
> |
node = libopm_node_create(scan); |
489 |
> |
libopm_list_add(scanner->queue, node); |
490 |
|
|
491 |
< |
return OPM_SUCCESS; |
491 |
> |
return OPM_SUCCESS; |
492 |
|
} |
493 |
|
|
534 |
– |
|
535 |
– |
|
536 |
– |
|
494 |
|
/* opm_end |
495 |
|
* |
496 |
|
* End a scan prematurely. |
499 |
|
* scanner: Scanner to end scan on |
500 |
|
* remote: Pointer to remote struct to search for and end |
501 |
|
* |
502 |
< |
* Return: |
502 |
> |
* Return: |
503 |
|
* No return. OPM_CALLBACK_END will still be called as normal. |
504 |
|
*/ |
505 |
< |
|
506 |
< |
void opm_end(OPM_T *scanner, OPM_REMOTE_T *remote) |
505 |
> |
void |
506 |
> |
opm_end(OPM_T *scanner, OPM_REMOTE_T *remote) |
507 |
|
{ |
508 |
< |
OPM_NODE_T *node1, *node2, *next1, *next2; |
509 |
< |
|
510 |
< |
OPM_SCAN_T *scan; |
511 |
< |
OPM_CONNECTION_T *conn; |
512 |
< |
|
513 |
< |
/* End active scans */ |
514 |
< |
opm_endscan(scanner, remote); |
515 |
< |
|
516 |
< |
/* Secondly remove all traces of it in the queue. Once removed we have to call |
517 |
< |
OPM_CALLBACK_END */ |
518 |
< |
|
519 |
< |
LIST_FOREACH_SAFE(node1, next1, scanner->queue->head) |
520 |
< |
{ |
521 |
< |
scan = node1->data; |
522 |
< |
if(scan->remote == remote) |
508 |
> |
OPM_NODE_T *node1, *node2, *next1, *next2; |
509 |
> |
OPM_SCAN_T *scan; |
510 |
> |
OPM_CONNECTION_T *conn; |
511 |
> |
|
512 |
> |
/* End active scans */ |
513 |
> |
opm_endscan(scanner, remote); |
514 |
> |
|
515 |
> |
/* |
516 |
> |
* Secondly remove all traces of it in the queue. Once removed we have to call |
517 |
> |
* OPM_CALLBACK_END |
518 |
> |
*/ |
519 |
> |
LIST_FOREACH_SAFE(node1, next1, scanner->queue->head) |
520 |
> |
{ |
521 |
> |
scan = node1->data; |
522 |
> |
|
523 |
> |
if (scan->remote == remote) |
524 |
> |
{ |
525 |
> |
/* Free all connections */ |
526 |
> |
LIST_FOREACH_SAFE(node2, next2, scan->connections->head) |
527 |
|
{ |
528 |
< |
/* Free all connections */ |
568 |
< |
LIST_FOREACH_SAFE(node2, next2, scan->connections->head) |
569 |
< |
{ |
570 |
< |
|
571 |
< |
conn = node2->data; |
572 |
< |
|
573 |
< |
libopm_list_remove(scan->connections, node2); |
574 |
< |
libopm_connection_free(conn); |
575 |
< |
libopm_node_free(node2); |
576 |
< |
continue; |
577 |
< |
} |
578 |
< |
|
579 |
< |
/* OPM_CALLBACK_END because check_closed normally handles this */ |
580 |
< |
libopm_do_callback(scanner, scan->remote, OPM_CALLBACK_END, 0); |
528 |
> |
conn = node2->data; |
529 |
|
|
530 |
< |
/* Free up the scan */ |
531 |
< |
libopm_list_remove(scanner->queue, node1); |
532 |
< |
libopm_scan_free(scan); |
533 |
< |
libopm_node_free(node1); |
530 |
> |
libopm_list_remove(scan->connections, node2); |
531 |
> |
libopm_connection_free(conn); |
532 |
> |
libopm_node_free(node2); |
533 |
> |
continue; |
534 |
|
} |
587 |
– |
} |
588 |
– |
} |
589 |
– |
|
535 |
|
|
536 |
+ |
/* OPM_CALLBACK_END because check_closed normally handles this */ |
537 |
+ |
libopm_do_callback(scanner, scan->remote, OPM_CALLBACK_END, 0); |
538 |
|
|
539 |
+ |
/* Free up the scan */ |
540 |
+ |
libopm_list_remove(scanner->queue, node1); |
541 |
+ |
libopm_scan_free(scan); |
542 |
+ |
libopm_node_free(node1); |
543 |
+ |
} |
544 |
+ |
} |
545 |
+ |
} |
546 |
|
|
547 |
|
/* opm_endscan |
548 |
|
* |
557 |
|
* Return: |
558 |
|
* No return. OPM_CALLBACK_END will still be called as normal. |
559 |
|
*/ |
560 |
< |
|
561 |
< |
void opm_endscan(OPM_T *scanner, OPM_REMOTE_T *remote) |
560 |
> |
void |
561 |
> |
opm_endscan(OPM_T *scanner, OPM_REMOTE_T *remote) |
562 |
|
{ |
563 |
< |
OPM_NODE_T *node1, *node2; |
564 |
< |
|
565 |
< |
OPM_SCAN_T *scan; |
566 |
< |
OPM_CONNECTION_T *conn; |
567 |
< |
|
568 |
< |
/* |
569 |
< |
First check to see if it's in the queue, if it is set all connections closed |
570 |
< |
Next cycle of libopm_check_closed will take care of the garbage and handle |
617 |
< |
OPM_CALLBACK_END |
563 |
> |
OPM_NODE_T *node1, *node2; |
564 |
> |
OPM_SCAN_T *scan; |
565 |
> |
OPM_CONNECTION_T *conn; |
566 |
> |
|
567 |
> |
/* |
568 |
> |
* First check to see if it's in the queue, if it is set all connections closed |
569 |
> |
* Next cycle of libopm_check_closed will take care of the garbage and handle |
570 |
> |
* OPM_CALLBACK_END |
571 |
|
*/ |
572 |
< |
LIST_FOREACH(node1, scanner->scans->head) |
573 |
< |
{ |
574 |
< |
scan = node1->data; |
572 |
> |
LIST_FOREACH(node1, scanner->scans->head) |
573 |
> |
{ |
574 |
> |
scan = node1->data; |
575 |
|
|
576 |
< |
if(scan->remote == remote) |
576 |
> |
if (scan->remote == remote) |
577 |
> |
{ |
578 |
> |
LIST_FOREACH(node2, scan->connections->head) |
579 |
|
{ |
580 |
< |
LIST_FOREACH(node2, scan->connections->head) |
581 |
< |
{ |
627 |
< |
conn = (OPM_CONNECTION_T *) node2->data; |
628 |
< |
conn->state = OPM_STATE_CLOSED; |
629 |
< |
} |
580 |
> |
conn = (OPM_CONNECTION_T *) node2->data; |
581 |
> |
conn->state = OPM_STATE_CLOSED; |
582 |
|
} |
583 |
< |
} |
583 |
> |
} |
584 |
> |
} |
585 |
|
} |
586 |
|
|
587 |
< |
|
635 |
< |
|
636 |
< |
|
637 |
< |
/* opm_active |
587 |
> |
/* opm_active |
588 |
|
|
589 |
|
Return number of scans in a scanner left. |
590 |
|
|
594 |
|
Return: |
595 |
|
Number of active scans, both queued and active. |
596 |
|
*/ |
597 |
< |
|
598 |
< |
size_t opm_active(OPM_T *scanner) |
597 |
> |
size_t |
598 |
> |
opm_active(OPM_T *scanner) |
599 |
|
{ |
600 |
< |
return LIST_SIZE(scanner->queue) + LIST_SIZE(scanner->scans); |
600 |
> |
return LIST_SIZE(scanner->queue) + LIST_SIZE(scanner->scans); |
601 |
|
} |
602 |
|
|
653 |
– |
|
654 |
– |
|
603 |
|
/* scan_create |
604 |
|
* |
605 |
|
* Create new OPM_SCAN_T struct |
606 |
|
* |
607 |
< |
* Parameters: |
607 |
> |
* Parameters: |
608 |
|
* scanner: Scanner the scan is being created for. This |
609 |
|
* is needed to get information on currently set |
610 |
|
* protocols/config. |
614 |
|
* Return |
615 |
|
* Address of new struct |
616 |
|
*/ |
617 |
< |
static OPM_SCAN_T *libopm_scan_create(OPM_T *scanner, OPM_REMOTE_T *remote) |
617 |
> |
static OPM_SCAN_T * |
618 |
> |
libopm_scan_create(OPM_T *scanner, OPM_REMOTE_T *remote) |
619 |
|
{ |
620 |
< |
OPM_SCAN_T *ret; |
621 |
< |
OPM_CONNECTION_T *conn; |
622 |
< |
OPM_NODE_T *node, *p; |
674 |
< |
|
675 |
< |
ret = xcalloc(sizeof *ret); |
620 |
> |
OPM_SCAN_T *ret; |
621 |
> |
OPM_CONNECTION_T *conn; |
622 |
> |
OPM_NODE_T *node, *p; |
623 |
|
|
624 |
< |
ret->remote = remote; |
678 |
< |
ret->connections = libopm_list_create(); |
679 |
< |
|
680 |
< |
/* Setup list of connections, one for each protocol */ |
681 |
< |
LIST_FOREACH(p, scanner->protocols->head) |
682 |
< |
{ |
683 |
< |
conn = libopm_connection_create(); |
684 |
< |
|
685 |
< |
conn->protocol = ((OPM_PROTOCOL_CONFIG_T *) p->data)->type; |
686 |
< |
conn->port = ((OPM_PROTOCOL_CONFIG_T *) p->data)->port; |
687 |
< |
|
688 |
< |
node = libopm_node_create(conn); |
624 |
> |
ret = xcalloc(sizeof *ret); |
625 |
|
|
626 |
< |
libopm_list_add(ret->connections, node); |
627 |
< |
} |
692 |
< |
|
693 |
< |
/* Do the same for any specific protocols the remote struct might be configured |
694 |
< |
with */ |
626 |
> |
ret->remote = remote; |
627 |
> |
ret->connections = libopm_list_create(); |
628 |
|
|
629 |
< |
LIST_FOREACH(p, remote->protocols->head) |
630 |
< |
{ |
631 |
< |
conn = libopm_connection_create(); |
629 |
> |
/* Setup list of connections, one for each protocol */ |
630 |
> |
LIST_FOREACH(p, scanner->protocols->head) |
631 |
> |
{ |
632 |
> |
conn = libopm_connection_create(); |
633 |
|
|
634 |
< |
conn->protocol = ((OPM_PROTOCOL_CONFIG_T *) p->data)->type; |
635 |
< |
conn->port = ((OPM_PROTOCOL_CONFIG_T *) p->data)->port; |
634 |
> |
conn->protocol = ((OPM_PROTOCOL_CONFIG_T *) p->data)->type; |
635 |
> |
conn->port = ((OPM_PROTOCOL_CONFIG_T *) p->data)->port; |
636 |
|
|
637 |
< |
node = libopm_node_create(conn); |
637 |
> |
node = libopm_node_create(conn); |
638 |
|
|
639 |
< |
libopm_list_add(ret->connections, node); |
640 |
< |
} |
639 |
> |
libopm_list_add(ret->connections, node); |
640 |
> |
} |
641 |
|
|
642 |
< |
memset(&(ret->addr), 0, sizeof(opm_sockaddr)); |
642 |
> |
/* |
643 |
> |
* Do the same for any specific protocols the remote struct might be configured with |
644 |
> |
*/ |
645 |
> |
LIST_FOREACH(p, remote->protocols->head) |
646 |
> |
{ |
647 |
> |
conn = libopm_connection_create(); |
648 |
> |
|
649 |
> |
conn->protocol = ((OPM_PROTOCOL_CONFIG_T *) p->data)->type; |
650 |
> |
conn->port = ((OPM_PROTOCOL_CONFIG_T *) p->data)->port; |
651 |
> |
|
652 |
> |
node = libopm_node_create(conn); |
653 |
> |
libopm_list_add(ret->connections, node); |
654 |
> |
} |
655 |
|
|
656 |
< |
return ret; |
656 |
> |
memset(&(ret->addr), 0, sizeof(opm_sockaddr)); |
657 |
> |
return ret; |
658 |
|
} |
659 |
|
|
713 |
– |
|
714 |
– |
|
715 |
– |
|
660 |
|
/* scan_free |
661 |
|
* |
662 |
|
* Free and cleanup OPM_SCAN_T struct |
667 |
|
* Return: |
668 |
|
* None |
669 |
|
*/ |
670 |
< |
|
671 |
< |
static void libopm_scan_free(OPM_SCAN_T *scan) |
670 |
> |
static void |
671 |
> |
libopm_scan_free(OPM_SCAN_T *scan) |
672 |
|
{ |
673 |
< |
OPM_NODE_T *p, *next; |
674 |
< |
OPM_CONNECTION_T *conn; |
673 |
> |
OPM_NODE_T *p, *next; |
674 |
> |
OPM_CONNECTION_T *conn; |
675 |
|
|
676 |
< |
LIST_FOREACH_SAFE(p, next, scan->connections->head) |
677 |
< |
{ |
678 |
< |
conn = p->data; |
735 |
< |
libopm_connection_free(conn); |
736 |
< |
|
737 |
< |
libopm_list_remove(scan->connections, p); |
738 |
< |
libopm_node_free(p); |
739 |
< |
} |
740 |
< |
libopm_list_free(scan->connections); |
741 |
< |
|
742 |
< |
MyFree(scan); |
743 |
< |
} |
676 |
> |
LIST_FOREACH_SAFE(p, next, scan->connections->head) |
677 |
> |
{ |
678 |
> |
conn = p->data; |
679 |
|
|
680 |
+ |
libopm_connection_free(conn); |
681 |
+ |
libopm_list_remove(scan->connections, p); |
682 |
+ |
libopm_node_free(p); |
683 |
+ |
} |
684 |
|
|
685 |
+ |
libopm_list_free(scan->connections); |
686 |
|
|
687 |
+ |
MyFree(scan); |
688 |
+ |
} |
689 |
|
|
690 |
|
/* connection_create |
691 |
|
* |
697 |
|
* Return: |
698 |
|
* Address of new OPM_CONNECTION_T |
699 |
|
*/ |
700 |
< |
|
701 |
< |
static OPM_CONNECTION_T *libopm_connection_create(void) |
700 |
> |
static OPM_CONNECTION_T * |
701 |
> |
libopm_connection_create(void) |
702 |
|
{ |
703 |
< |
OPM_CONNECTION_T *ret; |
762 |
< |
ret = xcalloc(sizeof *ret); |
703 |
> |
OPM_CONNECTION_T *ret; |
704 |
|
|
705 |
< |
ret->fd = 0; |
765 |
< |
ret->bytes_read = 0; |
766 |
< |
ret->readlen = 0; |
767 |
< |
ret->protocol = 0; |
768 |
< |
ret->port = 0; |
769 |
< |
|
770 |
< |
ret->state = OPM_STATE_UNESTABLISHED; |
771 |
< |
|
772 |
< |
return ret; |
773 |
< |
} |
705 |
> |
ret = xcalloc(sizeof *ret); |
706 |
|
|
707 |
+ |
ret->fd = 0; |
708 |
+ |
ret->bytes_read = 0; |
709 |
+ |
ret->readlen = 0; |
710 |
+ |
ret->protocol = 0; |
711 |
+ |
ret->port = 0; |
712 |
|
|
713 |
+ |
ret->state = OPM_STATE_UNESTABLISHED; |
714 |
|
|
715 |
+ |
return ret; |
716 |
+ |
} |
717 |
|
|
718 |
|
/* connection_free |
719 |
|
* |
725 |
|
* Return: |
726 |
|
* None |
727 |
|
*/ |
728 |
< |
|
729 |
< |
static void libopm_connection_free(OPM_CONNECTION_T *conn) |
728 |
> |
static void |
729 |
> |
libopm_connection_free(OPM_CONNECTION_T *conn) |
730 |
|
{ |
731 |
< |
MyFree(conn); |
731 |
> |
MyFree(conn); |
732 |
|
} |
733 |
|
|
794 |
– |
|
734 |
|
/* opm_cycle |
735 |
|
* |
736 |
|
* Perform tasks (called by client's loop) |
740 |
|
* Return: |
741 |
|
* None |
742 |
|
*/ |
743 |
< |
|
744 |
< |
void opm_cycle(OPM_T *scanner) |
743 |
> |
void |
744 |
> |
opm_cycle(OPM_T *scanner) |
745 |
|
{ |
746 |
< |
libopm_check_queue(scanner); /* Move scans from the queue to the live scan list */ |
747 |
< |
libopm_check_establish(scanner); /* Make new connections if possible */ |
748 |
< |
libopm_check_poll(scanner); /* Poll connections for IO and proxy test */ |
749 |
< |
libopm_check_closed(scanner); /* Check for closed or timed out connections */ |
746 |
> |
libopm_check_queue(scanner); /* Move scans from the queue to the live scan list */ |
747 |
> |
libopm_check_establish(scanner); /* Make new connections if possible */ |
748 |
> |
libopm_check_poll(scanner); /* Poll connections for IO and proxy test */ |
749 |
> |
libopm_check_closed(scanner); /* Check for closed or timed out connections */ |
750 |
|
} |
751 |
|
|
813 |
– |
|
814 |
– |
|
815 |
– |
|
752 |
|
/* check_queue |
753 |
|
* |
754 |
|
* Move scans from the queue to the live scan list as long as there is |
760 |
|
* Return: |
761 |
|
* None |
762 |
|
*/ |
763 |
< |
|
764 |
< |
static void libopm_check_queue(OPM_T *scanner) |
763 |
> |
static void |
764 |
> |
libopm_check_queue(OPM_T *scanner) |
765 |
|
{ |
766 |
|
OPM_NODE_T *node; |
767 |
|
OPM_SCAN_T *scan; |
797 |
|
|
798 |
|
} |
799 |
|
|
864 |
– |
|
865 |
– |
|
866 |
– |
|
800 |
|
/* check_establish |
801 |
|
* |
802 |
|
* Make new connections if there are free file descriptors and connections |
807 |
|
* Return: |
808 |
|
* None |
809 |
|
*/ |
810 |
< |
|
811 |
< |
static void libopm_check_establish(OPM_T *scanner) |
810 |
> |
static void |
811 |
> |
libopm_check_establish(OPM_T *scanner) |
812 |
|
{ |
813 |
< |
OPM_NODE_T *node1, *node2; |
814 |
< |
OPM_SCAN_T *scan; |
815 |
< |
OPM_CONNECTION_T *conn; |
816 |
< |
|
817 |
< |
unsigned int fd_limit; |
818 |
< |
|
819 |
< |
if(LIST_SIZE(scanner->scans) == 0) |
820 |
< |
return; |
821 |
< |
|
822 |
< |
fd_limit = *(int *) libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT); |
823 |
< |
|
824 |
< |
if(scanner->fd_use >= fd_limit) |
825 |
< |
return; |
826 |
< |
|
827 |
< |
LIST_FOREACH(node1, scanner->scans->head) |
828 |
< |
{ |
829 |
< |
scan = node1->data; |
830 |
< |
LIST_FOREACH(node2, scan->connections->head) |
831 |
< |
{ |
832 |
< |
/* Only scan if we have free file descriptors */ |
833 |
< |
if(scanner->fd_use >= fd_limit) |
834 |
< |
return; |
835 |
< |
|
836 |
< |
conn = node2->data; |
837 |
< |
if(conn->state == OPM_STATE_UNESTABLISHED) |
838 |
< |
libopm_do_connect(scanner, scan, conn); |
839 |
< |
} |
840 |
< |
} |
813 |
> |
OPM_NODE_T *node1, *node2; |
814 |
> |
OPM_SCAN_T *scan; |
815 |
> |
OPM_CONNECTION_T *conn; |
816 |
> |
unsigned int fd_limit; |
817 |
> |
|
818 |
> |
if (LIST_SIZE(scanner->scans) == 0) |
819 |
> |
return; |
820 |
> |
|
821 |
> |
fd_limit = *(int *)libopm_config(scanner->config, OPM_CONFIG_FD_LIMIT); |
822 |
> |
|
823 |
> |
if (scanner->fd_use >= fd_limit) |
824 |
> |
return; |
825 |
> |
|
826 |
> |
LIST_FOREACH(node1, scanner->scans->head) |
827 |
> |
{ |
828 |
> |
scan = node1->data; |
829 |
> |
|
830 |
> |
LIST_FOREACH(node2, scan->connections->head) |
831 |
> |
{ |
832 |
> |
/* Only scan if we have free file descriptors */ |
833 |
> |
if (scanner->fd_use >= fd_limit) |
834 |
> |
return; |
835 |
> |
|
836 |
> |
conn = node2->data; |
837 |
> |
|
838 |
> |
if (conn->state == OPM_STATE_UNESTABLISHED) |
839 |
> |
libopm_do_connect(scanner, scan, conn); |
840 |
> |
} |
841 |
> |
} |
842 |
|
} |
843 |
|
|
910 |
– |
|
911 |
– |
|
912 |
– |
|
844 |
|
/* check_closed |
845 |
|
* |
846 |
|
* Check for connections which have timed out or are |
856 |
|
* Return: |
857 |
|
* None |
858 |
|
*/ |
859 |
< |
|
860 |
< |
static void libopm_check_closed(OPM_T *scanner) |
859 |
> |
static void |
860 |
> |
libopm_check_closed(OPM_T *scanner) |
861 |
|
{ |
862 |
|
|
863 |
|
time_t present; |
926 |
|
} |
927 |
|
} |
928 |
|
|
998 |
– |
|
999 |
– |
|
1000 |
– |
|
929 |
|
/* do_connect |
930 |
|
* |
931 |
|
* Call socket() and connect() to start a scan. |
936 |
|
* Return: |
937 |
|
* None |
938 |
|
*/ |
939 |
< |
|
940 |
< |
static void libopm_do_connect(OPM_T * scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
939 |
> |
static void |
940 |
> |
libopm_do_connect(OPM_T * scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
941 |
|
{ |
942 |
|
opm_sockaddr *bind_ip; |
943 |
|
|
986 |
|
time(&(conn->creation)); /* Stamp creation time, for timeout */ |
987 |
|
} |
988 |
|
|
1061 |
– |
|
989 |
|
/* check_poll |
990 |
|
* |
991 |
|
* Check sockets for ready read/write |
995 |
|
* Return: |
996 |
|
* None |
997 |
|
*/ |
998 |
< |
|
999 |
< |
static void libopm_check_poll(OPM_T *scanner) |
998 |
> |
static void |
999 |
> |
libopm_check_poll(OPM_T *scanner) |
1000 |
|
{ |
1001 |
|
OPM_NODE_T *node1, *node2; |
1002 |
|
OPM_SCAN_T *scan; |
1091 |
|
} |
1092 |
|
} |
1093 |
|
|
1167 |
– |
|
1168 |
– |
|
1169 |
– |
|
1094 |
|
/* do_readready |
1095 |
|
* |
1096 |
|
* Remote connection is read ready, read the data into a buffer and check it against |
1104 |
|
* Return: |
1105 |
|
* None |
1106 |
|
*/ |
1107 |
< |
|
1108 |
< |
static void libopm_do_readready(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
1107 |
> |
static void |
1108 |
> |
libopm_do_readready(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
1109 |
|
{ |
1110 |
|
|
1111 |
|
int max_read; |
1168 |
|
} |
1169 |
|
} |
1170 |
|
|
1247 |
– |
|
1248 |
– |
|
1249 |
– |
|
1171 |
|
/* do_read |
1172 |
|
* |
1173 |
|
* A line of data has been read from the socket, check it against |
1174 |
|
* target string. |
1175 |
|
* |
1176 |
< |
* |
1176 |
> |
* |
1177 |
|
* |
1178 |
|
* Parameters: |
1179 |
|
* scanner: Scanner doing the scan |
1183 |
|
* Return: |
1184 |
|
* None |
1185 |
|
*/ |
1186 |
< |
|
1187 |
< |
static void libopm_do_read(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
1186 |
> |
static void |
1187 |
> |
libopm_do_read(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
1188 |
|
{ |
1189 |
< |
OPM_LIST_T *list; |
1190 |
< |
OPM_NODE_T *node; |
1191 |
< |
char *target_string; |
1192 |
< |
|
1193 |
< |
/* Check readbuf against target strings */ |
1194 |
< |
list = (OPM_LIST_T *) libopm_config(scanner->config, OPM_CONFIG_TARGET_STRING); |
1195 |
< |
LIST_FOREACH(node, list->head) |
1196 |
< |
{ |
1197 |
< |
target_string = node->data; |
1198 |
< |
if(strstr(conn->readbuf, target_string)) |
1199 |
< |
{ |
1200 |
< |
libopm_do_openproxy(scanner, scan, conn); |
1201 |
< |
break; |
1202 |
< |
} |
1203 |
< |
} |
1189 |
> |
OPM_LIST_T *list; |
1190 |
> |
OPM_NODE_T *node; |
1191 |
> |
char *target_string; |
1192 |
> |
|
1193 |
> |
/* Check readbuf against target strings */ |
1194 |
> |
list = (OPM_LIST_T *)libopm_config(scanner->config, OPM_CONFIG_TARGET_STRING); |
1195 |
> |
|
1196 |
> |
LIST_FOREACH(node, list->head) |
1197 |
> |
{ |
1198 |
> |
target_string = node->data; |
1199 |
> |
|
1200 |
> |
if (strstr(conn->readbuf, target_string)) |
1201 |
> |
{ |
1202 |
> |
libopm_do_openproxy(scanner, scan, conn); |
1203 |
> |
break; |
1204 |
> |
} |
1205 |
> |
} |
1206 |
|
} |
1207 |
|
|
1285 |
– |
|
1208 |
|
/* do_openproxy |
1209 |
|
* |
1210 |
|
* An open proxy was found on connection conn. Cleanup the connection and |
1218 |
|
* Return: |
1219 |
|
* None |
1220 |
|
*/ |
1221 |
< |
|
1222 |
< |
static void libopm_do_openproxy(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
1221 |
> |
static void |
1222 |
> |
libopm_do_openproxy(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
1223 |
|
{ |
1224 |
< |
OPM_REMOTE_T *remote; |
1224 |
> |
OPM_REMOTE_T *remote; |
1225 |
|
|
1226 |
< |
remote = scan->remote; |
1226 |
> |
remote = scan->remote; |
1227 |
|
|
1228 |
< |
/* Mark the connection for close */ |
1229 |
< |
conn->state = OPM_STATE_CLOSED; |
1228 |
> |
/* Mark the connection for close */ |
1229 |
> |
conn->state = OPM_STATE_CLOSED; |
1230 |
|
|
1231 |
< |
/* Call client's open proxy callback */ |
1232 |
< |
libopm_do_callback(scanner, libopm_setup_remote(scan->remote, conn), OPM_CALLBACK_OPENPROXY, 0); |
1231 |
> |
/* Call client's open proxy callback */ |
1232 |
> |
libopm_do_callback(scanner, libopm_setup_remote(scan->remote, conn), OPM_CALLBACK_OPENPROXY, 0); |
1233 |
|
} |
1234 |
|
|
1313 |
– |
|
1314 |
– |
|
1315 |
– |
|
1235 |
|
/* do_writeready |
1236 |
|
* |
1237 |
|
* Remote connection is write ready, call the specific protocol |
1245 |
|
* Return: |
1246 |
|
* None |
1247 |
|
*/ |
1248 |
< |
|
1249 |
< |
static void libopm_do_writeready(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
1248 |
> |
static void |
1249 |
> |
libopm_do_writeready(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
1250 |
|
{ |
1251 |
< |
OPM_PROTOCOL_T *protocol; |
1251 |
> |
OPM_PROTOCOL_T *protocol; |
1252 |
|
|
1253 |
< |
protocol = conn->protocol; |
1253 |
> |
protocol = conn->protocol; |
1254 |
|
|
1255 |
< |
/* Call write function for specific protocol */ |
1256 |
< |
if(protocol->write_function) |
1257 |
< |
protocol->write_function(scanner, scan, conn); |
1255 |
> |
/* Call write function for specific protocol */ |
1256 |
> |
if (protocol->write_function) |
1257 |
> |
protocol->write_function(scanner, scan, conn); |
1258 |
|
|
1259 |
< |
/* Flag as NEGSENT so we don't have to send data again*/ |
1260 |
< |
conn->state = OPM_STATE_NEGSENT; |
1259 |
> |
/* Flag as NEGSENT so we don't have to send data again*/ |
1260 |
> |
conn->state = OPM_STATE_NEGSENT; |
1261 |
|
} |
1262 |
|
|
1344 |
– |
|
1345 |
– |
|
1346 |
– |
|
1263 |
|
/* do_hup |
1264 |
|
* |
1265 |
|
* Connection ended prematurely |
1272 |
|
* Return: |
1273 |
|
* None |
1274 |
|
*/ |
1275 |
< |
|
1276 |
< |
static void libopm_do_hup(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
1275 |
> |
static void |
1276 |
> |
libopm_do_hup(OPM_T *scanner, OPM_SCAN_T *scan, OPM_CONNECTION_T *conn) |
1277 |
|
{ |
1278 |
< |
OPM_REMOTE_T *remote; |
1278 |
> |
OPM_REMOTE_T *remote; |
1279 |
|
|
1280 |
< |
remote = scan->remote; |
1280 |
> |
remote = scan->remote; |
1281 |
|
|
1282 |
|
/* Mark the connection for close */ |
1283 |
< |
conn->state = OPM_STATE_CLOSED; |
1283 |
> |
conn->state = OPM_STATE_CLOSED; |
1284 |
|
|
1285 |
< |
libopm_do_callback(scanner, libopm_setup_remote(scan->remote, conn), OPM_CALLBACK_NEGFAIL, 0); |
1285 |
> |
libopm_do_callback(scanner, libopm_setup_remote(scan->remote, conn), OPM_CALLBACK_NEGFAIL, 0); |
1286 |
|
} |
1287 |
|
|
1372 |
– |
|
1373 |
– |
|
1374 |
– |
|
1288 |
|
/* do_callback |
1289 |
|
* |
1290 |
|
* Call callback |
1297 |
|
* Return: |
1298 |
|
* None |
1299 |
|
*/ |
1300 |
< |
|
1301 |
< |
static void libopm_do_callback(OPM_T *scanner, OPM_REMOTE_T *remote, int type, int var) |
1300 |
> |
static void |
1301 |
> |
libopm_do_callback(OPM_T *scanner, OPM_REMOTE_T *remote, int type, int var) |
1302 |
|
{ |
1303 |
< |
/* Callback is out of range */ |
1304 |
< |
if(type < 0 || type >= (CBLEN + 1)) |
1305 |
< |
return; |
1303 |
> |
/* Callback is out of range */ |
1304 |
> |
if (type < 0 || type >= (CBLEN + 1)) |
1305 |
> |
return; |
1306 |
|
|
1307 |
< |
if(scanner->callbacks[type].func) |
1308 |
< |
(scanner->callbacks[type].func) (scanner, remote, var, scanner->callbacks[type].data); |
1307 |
> |
if (scanner->callbacks[type].func) |
1308 |
> |
(scanner->callbacks[type].func)(scanner, remote, var, scanner->callbacks[type].data); |
1309 |
|
} |
1310 |
|
|
1398 |
– |
|
1399 |
– |
|
1400 |
– |
|
1311 |
|
/* setup_remote |
1312 |
|
* |
1313 |
|
* Setup an OPM_REMOTE_T with information from an OPM_CONNECTION_T |
1315 |
|
* |
1316 |
|
* Parameters: |
1317 |
|
* remote, conn |
1318 |
< |
* |
1318 |
> |
* |
1319 |
|
* Return: |
1320 |
|
* remote |
1321 |
|
*/ |
1322 |
< |
|
1323 |
< |
static OPM_REMOTE_T *libopm_setup_remote(OPM_REMOTE_T *remote, OPM_CONNECTION_T *conn) |
1322 |
> |
static OPM_REMOTE_T * |
1323 |
> |
libopm_setup_remote(OPM_REMOTE_T *remote, OPM_CONNECTION_T *conn) |
1324 |
|
{ |
1325 |
< |
remote->port = conn->port; |
1326 |
< |
remote->bytes_read = conn->bytes_read; |
1327 |
< |
remote->protocol = conn->protocol->type; |
1325 |
> |
remote->port = conn->port; |
1326 |
> |
remote->bytes_read = conn->bytes_read; |
1327 |
> |
remote->protocol = conn->protocol->type; |
1328 |
|
|
1329 |
< |
return remote; |
1329 |
> |
return remote; |
1330 |
|
} |