ret->fd_use = 0;
/* Setup callbacks */
- ret->callbacks = MyMalloc(sizeof(OPM_CALLBACK_T *) * CBLEN);
+ ret->callbacks = MyMalloc(sizeof(OPM_CALLBACK_T) * CBLEN);
for(i = 0; i < CBLEN; i++)
- ret->callbacks[i] = NULL;
+ {
+ ret->callbacks[i].func = NULL;
+ ret->callbacks[i].data = NULL;
+ }
return ret;
}
ret->ip = (char*) strdup(ip); /* replace with custom strdup function */
/* Setup callbacks */
- ret->callbacks = MyMalloc(sizeof(OPM_CALLBACK_T *) * CBLEN);
+ ret->callbacks = MyMalloc(sizeof(OPM_CALLBACK_T) * CBLEN);
for(i = 0; i < CBLEN; i++)
- ret->callbacks[i] = NULL;
+ {
+ ret->callbacks[i].func = NULL;
+ ret->callbacks[i].data = NULL;
+ }
ret->port = 0;
ret->protocol = 0;
* Error code
*/
-OPM_ERR_T opm_remote_callback(OPM_REMOTE_T *remote, int type, OPM_CALLBACK_T *function)
+OPM_ERR_T opm_remote_callback(OPM_REMOTE_T *remote, int type, OPM_CALLBACK_FUNC *function,
+ void *data)
{
if(type < 0 || type >= (CBLEN + 1))
return OPM_ERR_CBNOTFOUND;
- remote->callbacks[type] = function;
+ remote->callbacks[type].func = function;
+ remote->callbacks[type].data = data;
return OPM_SUCCESS;
}
* Error code
*/
-OPM_ERR_T opm_callback(OPM_T *scanner, int type, OPM_CALLBACK_T *function)
+OPM_ERR_T opm_callback(OPM_T *scanner, int type, OPM_CALLBACK_FUNC *function, void *data)
{
if(type < 0 || type >= (CBLEN + 1))
return OPM_ERR_CBNOTFOUND;
- scanner->callbacks[type] = function;
+ scanner->callbacks[type].func = function;
+ scanner->callbacks[type].data = data;
return OPM_SUCCESS;
}
if(type < 0 || type >= (CBLEN + 1))
return;
- if(scanner->callbacks[type])
- (scanner->callbacks[type]) (scanner, remote, var);
- if(remote->callbacks[type])
- (remote->callbacks[type]) (scanner, remote, var);
+ if(scanner->callbacks[type].func)
+ (scanner->callbacks[type].func) (scanner, remote, var, scanner->callbacks[type].data);
+ if(remote->callbacks[type].func)
+ (remote->callbacks[type].func) (scanner, remote, var, remote->callbacks[type].data);
}
typedef struct _OPM_CONFIG OPM_CONFIG_T;
typedef struct _OPM OPM_T;
typedef struct _OPM_REMOTE OPM_REMOTE_T;
+typedef struct _OPM_CALLBACK OPM_CALLBACK_T;
typedef int OPM_ERR_T;
-typedef void OPM_CALLBACK_T (OPM_T *, OPM_REMOTE_T *, int);
+typedef void OPM_CALLBACK_FUNC (OPM_T *, OPM_REMOTE_T *, int, void *);
+
+struct _OPM_CALLBACK {
+ OPM_CALLBACK_FUNC *func;
+ void *data;
+};
struct _OPM_CONFIG {
void **vars;
OPM_LIST_T *protocols; /* List of protocols this scanner handles */
unsigned int fd_use; /* Number of file descriptors in use */
- OPM_CALLBACK_T **callbacks; /* Scanner wide callbacks */
+ OPM_CALLBACK_T *callbacks; /* Scanner wide callbacks */
};
struct _OPM_REMOTE {
unsigned short int protocol; /* Protocol passed back on certain callbacks */
unsigned short int bytes_read; /* Bytes read passed back on certain callbacks */
- OPM_CALLBACK_T **callbacks; /* Callback configuration */
+ OPM_CALLBACK_T *callbacks; /* Callback configuration */
};
OPM_T *opm_create();
OPM_ERR_T opm_addtype(OPM_T *, int, unsigned short int);
OPM_ERR_T opm_addcustom(OPM_T *, char *, char *, unsigned short int);
-OPM_ERR_T opm_remote_callback(OPM_REMOTE_T *, int, OPM_CALLBACK_T *);
-OPM_ERR_T opm_callback(OPM_T *, int, OPM_CALLBACK_T *);
+OPM_ERR_T opm_remote_callback(OPM_REMOTE_T *, int, OPM_CALLBACK_FUNC *, void *);
+OPM_ERR_T opm_callback(OPM_T *, int, OPM_CALLBACK_FUNC *, void *);
void opm_cycle(OPM_T *);
RCSID("$Id$");
-void open_proxy(OPM_T *, OPM_REMOTE_T *, int);
-void negotiation_failed(OPM_T *, OPM_REMOTE_T *, int);
-void timeout(OPM_T *, OPM_REMOTE_T *, int);
-void end(OPM_T *, OPM_REMOTE_T *, int);
-void handle_error(OPM_T *, OPM_REMOTE_T *, int);
+void open_proxy(OPM_T *, OPM_REMOTE_T *, int, void *);
+void negotiation_failed(OPM_T *, OPM_REMOTE_T *, int, void *);
+void timeout(OPM_T *, OPM_REMOTE_T *, int, void *);
+void end(OPM_T *, OPM_REMOTE_T *, int, void *);
+void handle_error(OPM_T *, OPM_REMOTE_T *, int, void *);
int complete = 0;
int main(int argc, char **argv)
remote = opm_remote_create("208.245.162.250");
/* Setup callbacks */
- opm_callback(scanner, OPM_CALLBACK_OPENPROXY, &open_proxy);
- opm_callback(scanner, OPM_CALLBACK_NEGFAIL, &negotiation_failed);
- opm_callback(scanner, OPM_CALLBACK_TIMEOUT, &timeout);
- opm_callback(scanner, OPM_CALLBACK_END, &end);
- opm_callback(scanner, OPM_CALLBACK_ERROR, &handle_error);
+ opm_callback(scanner, OPM_CALLBACK_OPENPROXY, &open_proxy, 0);
+ opm_callback(scanner, OPM_CALLBACK_NEGFAIL, &negotiation_failed, 0);
+ opm_callback(scanner, OPM_CALLBACK_TIMEOUT, &timeout, 0);
+ opm_callback(scanner, OPM_CALLBACK_END, &end, 0);
+ opm_callback(scanner, OPM_CALLBACK_ERROR, &handle_error, 0);
opm_config(scanner, OPM_CONFIG_FD_LIMIT, &fdlimit);
opm_config(scanner, OPM_CONFIG_SCAN_IP, "203.56.139.100");
return 0;
}
-void open_proxy(OPM_T *scanner, OPM_REMOTE_T *remote, int notused)
+void open_proxy(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *data)
{
printf("Open proxy on %s:%d [%d bytes read]\n", remote->ip, remote->port, remote->bytes_read);
}
-void negotiation_failed(OPM_T *scanner, OPM_REMOTE_T *remote, int notused)
+void negotiation_failed(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *data)
{
printf("Negotiation on %s:%d failed [%d bytes read]\n", remote->ip, remote->port, remote->bytes_read);
}
-void timeout(OPM_T *scanner, OPM_REMOTE_T *remote, int notused)
+void timeout(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *data)
{
printf("Negotiation timed out on %s:%d\n", remote->ip, remote->port);
}
-void end(OPM_T *scanner, OPM_REMOTE_T *remote, int notused)
+void end(OPM_T *scanner, OPM_REMOTE_T *remote, int notused, void *data)
{
printf("Scan on %s has ended\n", remote->ip);
opm_remote_free(remote);
complete = 1;
}
-void handle_error(OPM_T *scanner, OPM_REMOTE_T *remote, int err)
+void handle_error(OPM_T *scanner, OPM_REMOTE_T *remote, int err, void *data)
{
switch(err)
{