]> jfr.im git - irc/blitzed-org/libopm.git/commitdiff
patch to add data as param for callbacks..
authordgl <redacted>
Sat, 26 Oct 2002 18:51:03 +0000 (18:51 +0000)
committerdgl <redacted>
Sat, 26 Oct 2002 18:51:03 +0000 (18:51 +0000)
src/libopm.c
src/opm.h
src/test.c

index 72bf98742d42f787249304d78c7111c806ec0d00..56103e17ce0b901848f86a728f456d7f8d12b917 100644 (file)
@@ -119,9 +119,12 @@ OPM_T *opm_create()
    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;
 }
@@ -157,10 +160,13 @@ OPM_REMOTE_T *opm_remote_create(char *ip)
    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;
@@ -207,12 +213,14 @@ void opm_remote_free(OPM_REMOTE_T *remote)
  *    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;
 }
@@ -229,12 +237,13 @@ OPM_ERR_T opm_remote_callback(OPM_REMOTE_T *remote, int type, OPM_CALLBACK_T *fu
  *    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;
 }
@@ -1228,10 +1237,10 @@ static void libopm_do_callback(OPM_T *scanner, OPM_REMOTE_T *remote, int type, i
    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);
 }
 
 
index eca6119dff74c6381f4f98e54c43b712f18d547e..8507a5df671aac0e4804ed4ad0852f9409a13b54 100644 (file)
--- a/src/opm.h
+++ b/src/opm.h
 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;
@@ -29,7 +35,7 @@ struct _OPM {
    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 {
@@ -40,7 +46,7 @@ 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();
@@ -55,8 +61,8 @@ OPM_ERR_T opm_scan(OPM_T *, OPM_REMOTE_T *);
 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 *);
 
index c7a09d0cd7f3ce491ba5160ba5da823243f785a5..8dbce508c0015808bb8de2d388a252a7aaf5d1be 100644 (file)
 
 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)
@@ -58,11 +58,11 @@ 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");
@@ -104,29 +104,29 @@ int main(int argc, char **argv)
    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)
    {