From faaf88b24c6edd2b48234eec7c4a8a897b2dca50 Mon Sep 17 00:00:00 2001 From: chris mikkelson Date: Thu, 11 Mar 2010 14:29:26 -0600 Subject: [PATCH] Merged html.c into text.c -- almost all code overlapped. --- Makefile | 4 ++-- html.c | 69 -------------------------------------------------------- text.c | 38 +++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 75 deletions(-) delete mode 100644 html.c diff --git a/Makefile b/Makefile index fa99451..0377f26 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,9 @@ CFLAGS=-g -Wall -Werror -I/usr/local/include .c.o: $(CC) $(CFLAGS) -c $> -SRCS=msgproc.c base64.c quoted-printable.c re_stream.c html.c text.c \ +SRCS=msgproc.c base64.c quoted-printable.c re_stream.c text.c \ multipart.c message.c -OBJS=msgproc.o base64.o quoted-printable.o re_stream.o html.o text.o \ +OBJS=msgproc.o base64.o quoted-printable.o re_stream.o text.o \ multipart.o message.o default: liburl.a diff --git a/html.c b/html.c deleted file mode 100644 index e1aea3c..0000000 --- a/html.c +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2009 Christopher L. Mikkelson - * All Rights Reserved, for now. - */ - -#include -#include "re_stream.h" - -#include "msgproc.h" - -static const char *html_url_pattern = "<(a href|img src)=\"https?://[^\"]+"; -static pcre *html_url_re; - -static void -html_init(void) { - const char *etxt; int epos; - html_url_re = pcre_compile(html_url_pattern, 0, &etxt, &epos, 0); - if (!html_url_re) { - /* die */ - } -} - -static void -html_start(msgproc *m) -{ - struct stream_re *s = malloc(sizeof(struct stream_re)); - re_stream_start(s, html_url_re, 0); - msgproc_setpriv(m, (void *)s); -} - -static void -html_process(msgproc *m, char *buf, size_t size) -{ - struct stream_re *sr = (struct stream_re *)msgproc_getpriv(m); - int n; - - while (size > 0) { - n = re_stream_exec(sr, buf, size); - if (re_stream_result(sr) == 1) { - char *url = re_stream_getresult(sr); - if (m->callback) - m->callback(m, url, m->call_data); - } - size -= n; - buf += n; - } -} - -static void -html_finish(msgproc *m) -{ - struct stream_re *sr = (struct stream_re *)msgproc_getpriv(m); - if (sr) { - re_stream_stop(sr); - free(sr); - } - msgproc_free(m); -} - -msgproc_module msgproc_html = { - MSGPROC_HTML, /* type */ - html_init, /* module init */ - NULL, /* set module parameter */ - html_start, /* start module instance */ - NULL, /* set module instance parameter */ - html_process, /* process data */ - html_finish, /* shut down, free module instance */ - NULL /* shut down, free module */ -}; diff --git a/text.c b/text.c index 01d9718..19f39d6 100644 --- a/text.c +++ b/text.c @@ -10,9 +10,11 @@ static const char *text_url_pattern = "https?://\\S+"; static pcre *text_url_re; +static const char *html_url_pattern = "<(a href|img src)=\"https?://[^\"]+"; +static pcre *html_url_re; static void -text_init(void) { +text_plain_init(void) { const char *etxt; int epos; text_url_re = pcre_compile(text_url_pattern, 0, &etxt, &epos, 0); if (!text_url_re) { @@ -21,7 +23,24 @@ text_init(void) { } static void -text_start(msgproc *m) +text_html_init(void) { + const char *etxt; int epos; + html_url_re = pcre_compile(html_url_pattern, 0, &etxt, &epos, 0); + if (!html_url_re) { + /* die */ + } +} + +static void +text_plain_start(msgproc *m) +{ + struct stream_re *s = malloc(sizeof(struct stream_re)); + re_stream_start(s, text_url_re, 0); + msgproc_setpriv(m, (void *)s); +} + +static void +text_html_start(msgproc *m) { struct stream_re *s = malloc(sizeof(struct stream_re)); re_stream_start(s, text_url_re, 0); @@ -61,9 +80,20 @@ text_finish(msgproc *m) msgproc_module msgproc_text = { MSGPROC_TEXT, /* type */ - text_init, /* module init */ + text_plain_init, /* module init */ + NULL, /* set module parameter */ + text_plain_start, /* start module instance */ + NULL, /* set module instance parameter */ + text_process, /* process data */ + text_finish, /* shut down, free module instance */ + NULL /* shut down, free module */ +}; + +msgproc_module msgproc_html = { + MSGPROC_HTML, /* type */ + text_html_init, /* module init */ NULL, /* set module parameter */ - text_start, /* start module instance */ + text_html_start, /* start module instance */ NULL, /* set module instance parameter */ text_process, /* process data */ text_finish, /* shut down, free module instance */ -- 2.50.1