]> git.mikk.net Git - liburl/commitdiff
Added callbacks with data to msgproc structure, and called them from
authorchris mikkelson <chris@mikk.net>
Thu, 11 Mar 2010 20:12:42 +0000 (14:12 -0600)
committerchris mikkelson <chris@mikk.net>
Thu, 11 Mar 2010 20:12:42 +0000 (14:12 -0600)
text and html modules.

html.c
msgproc.c
msgproc.h
text.c

diff --git a/html.c b/html.c
index ca4a9111665f137f7b98165d94c4c88d258b3cba..e1aea3c6c5e5358dec1eb171b089d97e07b81628 100644 (file)
--- a/html.c
+++ b/html.c
@@ -37,7 +37,9 @@ html_process(msgproc *m, char *buf, size_t size)
        while (size > 0) {
                n = re_stream_exec(sr, buf, size);
                if (re_stream_result(sr) == 1) {
-                       /* TODO: callback (module param) or next stage */
+                       char *url = re_stream_getresult(sr);
+                       if (m->callback)
+                               m->callback(m, url, m->call_data);
                }
                size -= n;
                buf += n;
index 3e8df723a2d0d61b54d804243101081858fe7d12..2c1f1cc70ff0cf95d788b86291a847c0984bd665 100644 (file)
--- a/msgproc.c
+++ b/msgproc.c
@@ -15,7 +15,11 @@ msgproc_create(msgproc *parent, msgproc_module *mod)
                m->mp_mod = mod;
                m->mp_prev = parent;
                m->mp_next = NULL;
-               if (parent) parent->mp_next = m;
+               if (parent) {
+                       parent->mp_next = m;
+                       m->callback = parent->callback;
+                       m->call_data = parent->call_data;
+               }
        }
        return m;
 }
@@ -29,6 +33,15 @@ msgproc_free(msgproc *m)
        }
 }
 
+void
+msgproc_setcallback(msgproc *m, msgproc_callback cb, void *call_data)
+{
+       if (m) {
+               m->callback = cb;
+               m->call_data = call_data;
+       }
+}
+
 void
 msgproc_setpriv(msgproc *m, void *data)
 {
index 7c2945a2862c5f7c08d655179ffe0643d8d07ddb..722b6fe28933764c309dc4bfb8c78e87c9b458f8 100644 (file)
--- a/msgproc.h
+++ b/msgproc.h
@@ -29,15 +29,19 @@ typedef struct {
        void (*mpm_shutdown)(void);
 } msgproc_module;
 
+typedef void (*msgproc_callback)(msgproc *, char *, void *);
 struct _msgproc_s {
        void *mp_priv;
        msgproc_module *mp_mod;
        msgproc *mp_prev, *mp_next;
+       msgproc_callback callback;
+       void *call_data;
 };
 
 msgproc *msgproc_create(msgproc *, msgproc_module *);
 void msgproc_free(msgproc *);
 
+void msgproc_setcallback(msgproc *, msgproc_callback, void *);
 void msgproc_setpriv(msgproc *, void *);
 void *msgproc_getpriv(msgproc *);
 msgproc *msgproc_next(msgproc *);
diff --git a/text.c b/text.c
index a61bd2653eb52b7aeae346c048c664d6c208e448..01d97182a2743dafd3a1d39161697a780d367cb9 100644 (file)
--- a/text.c
+++ b/text.c
@@ -37,8 +37,11 @@ text_process(msgproc *m, char *buf, size_t size)
        while (size > 0) {
                n = re_stream_exec(sr, buf, size);
                if (re_stream_result(sr) == 1) {
-                       /* TODO: callback (supplied by set module param?)
-                               or next stage */
+                       char *url = re_stream_getresult(sr);
+                       if (m->callback) {
+                               m->callback(m, url, m->call_data);
+                       }
+               
                }
                size -= n;
                buf += n;