From: chris mikkelson Date: Thu, 11 Mar 2010 20:12:42 +0000 (-0600) Subject: Added callbacks with data to msgproc structure, and called them from X-Git-Url: https://git.mikk.net/?a=commitdiff_plain;h=c74072bdc8d5e826a559770a054da8df8d583ab2;p=liburl Added callbacks with data to msgproc structure, and called them from text and html modules. --- diff --git a/html.c b/html.c index ca4a911..e1aea3c 100644 --- 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; diff --git a/msgproc.c b/msgproc.c index 3e8df72..2c1f1cc 100644 --- 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) { diff --git a/msgproc.h b/msgproc.h index 7c2945a..722b6fe 100644 --- 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 a61bd26..01d9718 100644 --- 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;