1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3
* Copyright (C) 2001 Ximian Inc.
5
* Authors: Michael Zucchi <notzed@ximian.com>
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of version 2 of the GNU Lesser General Public
9
* License as published by the Free Software Foundation.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this program; if not, write to the
18
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
29
#include <sys/types.h>
31
#include "camel-html-parser.h"
32
#include "camel-mime-filter-html.h"
36
static void camel_mime_filter_html_class_init (CamelMimeFilterHTMLClass *klass);
37
static void camel_mime_filter_html_init (CamelObject *o);
38
static void camel_mime_filter_html_finalize (CamelObject *o);
40
static CamelMimeFilterClass *camel_mime_filter_html_parent;
42
struct _CamelMimeFilterHTMLPrivate {
43
CamelHTMLParser *ctxt;
46
/* ********************************************************************** */
50
/* well we odnt use this stuff yet */
52
#define ARRAY_LEN(x) (sizeof(x)/sizeof((x)[0]))
60
{ "h1", "\n" }, { "h2", "\n" }, { "h3", "\n" }, { "h4", "\n" }, { "h5", "\n" }, { "h6", "\n" },
68
{ "h1", "\n" }, { "h2", "\n" }, { "h3", "\n" }, { "h4", "\n" }, { "h5", "\n" }, { "h6", "\n" },
73
/* ********************************************************************** */
77
camel_mime_filter_html_get_type (void)
79
static CamelType type = CAMEL_INVALID_TYPE;
81
if (type == CAMEL_INVALID_TYPE) {
82
type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterHTML",
83
sizeof (CamelMimeFilterHTML),
84
sizeof (CamelMimeFilterHTMLClass),
85
(CamelObjectClassInitFunc) camel_mime_filter_html_class_init,
87
(CamelObjectInitFunc) camel_mime_filter_html_init,
88
(CamelObjectFinalizeFunc) camel_mime_filter_html_finalize);
95
camel_mime_filter_html_finalize(CamelObject *o)
97
CamelMimeFilterHTML *f = (CamelMimeFilterHTML *)o;
99
camel_object_unref((CamelObject *)f->priv->ctxt);
104
camel_mime_filter_html_init (CamelObject *o)
106
CamelMimeFilterHTML *f = (CamelMimeFilterHTML *)o;
108
f->priv = g_malloc0(sizeof(*f->priv));
109
f->priv->ctxt = camel_html_parser_new();
113
run(CamelMimeFilter *mf, char *in, size_t inlen, size_t prespace, char **out, size_t *outlenptr, size_t *outprespace, int last)
115
CamelMimeFilterHTML *f = (CamelMimeFilterHTML *) mf;
116
camel_html_parser_t state;
119
d(printf("converting html:\n%.*s\n", (int)inlen, in));
121
/* We should generally shrink the data, but this'll do */
122
camel_mime_filter_set_size (mf, inlen * 2 + 256, FALSE);
125
camel_html_parser_set_data (f->priv->ctxt, in, inlen, last);
130
state = camel_html_parser_step(f->priv->ctxt, &data, &len);
133
case CAMEL_HTML_PARSER_DATA:
134
case CAMEL_HTML_PARSER_ENT:
135
memcpy(outp, data, len);
138
case CAMEL_HTML_PARSER_ELEMENT:
139
/* FIXME: do some whitespace processing here */
142
/* ignore everything else */
145
} while (state != CAMEL_HTML_PARSER_EOF && state != CAMEL_HTML_PARSER_EOD);
148
*outlenptr = outp - mf->outbuf;
149
*outprespace = mf->outbuf - mf->outreal;
151
d(printf("converted html end:\n%.*s\n", (int)*outlenptr, *out));
155
complete(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, size_t *outlenptr, size_t *outprespace)
157
run(mf, in, len, prespace, out, outlenptr, outprespace, TRUE);
161
filter(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, size_t *outlenptr, size_t *outprespace)
163
run(mf, in, len, prespace, out, outlenptr, outprespace, FALSE);
167
reset(CamelMimeFilter *mf)
169
CamelMimeFilterHTML *f = (CamelMimeFilterHTML *)mf;
171
camel_object_unref((CamelObject *)f->priv->ctxt);
172
f->priv->ctxt = camel_html_parser_new();
176
camel_mime_filter_html_class_init (CamelMimeFilterHTMLClass *klass)
178
CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
180
camel_mime_filter_html_parent = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
182
filter_class->reset = reset;
183
filter_class->filter = filter;
184
filter_class->complete = complete;
189
* camel_mime_filter_html_new:
191
* Create a new #CamelMimeFilterHTML object.
193
* Returns a new #CamelMimeFilterHTML object
195
CamelMimeFilterHTML *
196
camel_mime_filter_html_new (void)
198
CamelMimeFilterHTML *new = CAMEL_MIME_FILTER_HTML ( camel_object_new (camel_mime_filter_html_get_type ()));