Commit 45c0bb90 45c0bb9011bdfb74d77d6ca90481441844612692 by Sergey Poznyakoff

Remove mu_filter_iconv_create.

Callers should use mu_filter_create_args instead.

* examples/iconv.c: Rewrite using mu_filter_create_args.
* libmailutils/mime/mimehdr.c (mu_mimehdr_decode_param): Use mu_decode_filter.

* imap4d/imap4d.h: Include prog.h
* include/mailutils/filter.h (mu_filter_iconv_create): Mark as deprecated.
* include/mailutils/util.h (mu_decode_filter_args): New proto.
* libmailutils/base/msgid.c (mu_rfc2822_in_reply_to): Silence a
cast warning.
* libmailutils/tests/wicket.c (match_string): Likewise.
* libmailutils/filter/decode.c (mu_decode_filter_args): New function.
(mu_decode_filter): Rewrite as an alternative entry point to
mu_decode_filter_args.
* ibmailutils/filter/filter_iconv.c: Remove.
* libmailutils/filter/Makefile.am (libfilter_la_SOURCES): Remove
filter_iconv.c
* libmu_compat/filter_iconv.c: New file.
* libmu_compat/Makefile.am (libmu_compat_la_SOURCES): Add filter_iconv.c

* libmailutils/filter/iconvflt.c (_icvt_decoder): Set errcode
before returning failure.

* libmailutils/stream/fltstream.c (init_iobuf, filter_stream_init): Provide
a default value for io->errcode.
1 parent 1f1dca41
......@@ -28,35 +28,32 @@
int
main (int argc, char **argv)
{
int rc;
int i;
mu_stream_t in, out;
mu_stream_t cvt;
size_t size;
char buffer[80];
const char *args[5] = { "iconv" };
if (argc != 3)
if (argc < 3 || argc > 4)
{
fprintf (stderr, "usage: %s from-code to-code\n", argv[0]);
fprintf (stderr, "usage: %s from-code to-code [err]\n", argv[0]);
return 1;
}
MU_ASSERT (mu_stdio_stream_create (&in, MU_STDIN_FD, 0));
MU_ASSERT (mu_filter_iconv_create (&cvt, in, argv[1], argv[2],
0, mu_fallback_none));
args[1] = argv[1];
args[2] = argv[2];
i = 3;
if (argc == 4)
args[i++] = argv[3];
args[i] = NULL;
MU_ASSERT (mu_filter_create_args (&cvt, in, args[0], i, args,
MU_FILTER_DECODE,
MU_FILTER_READ));
mu_stream_unref (in);
MU_ASSERT (mu_stdio_stream_create (&out, MU_STDOUT_FD, 0));
while ((rc = mu_stream_read (cvt, buffer, sizeof (buffer), &size)) == 0
&& size > 0)
{
mu_stream_write (out, buffer, size, NULL);
}
MU_ASSERT (mu_stream_copy (out, cvt, 0, NULL));
mu_stream_unref (cvt);
mu_stream_flush (out);
if (rc)
{
fprintf (stderr, "error: %s / %s\n",
mu_stream_strerror (cvt, rc),
mu_strerror (rc));
}
return 0;
}
......
......@@ -104,6 +104,7 @@
#include <mailutils/cctype.h>
#include <mailutils/cstr.h>
#include <mailutils/io.h>
#include <mailutils/prog.h>
#include <mu_umaxtostr.h>
#include <muaux.h>
......
......@@ -132,8 +132,9 @@ enum mu_iconv_fallback_mode
extern int mu_filter_iconv_create (mu_stream_t *s, mu_stream_t transport,
const char *fromcode, const char *tocode,
int flags,
enum mu_iconv_fallback_mode fallback_mode);
enum mu_iconv_fallback_mode fallback_mode)
MU_DEPRECATED;
extern int mu_linelen_filter_create (mu_stream_t *pstream, mu_stream_t stream,
size_t limit, int flags);
......
......@@ -152,6 +152,10 @@ int mu_rfc2822_in_reply_to (mu_message_t msg, char **pstr);
int mu_decode_filter (mu_stream_t *pfilter, mu_stream_t input,
const char *filter_type,
const char *fromcode, const char *tocode);
int mu_decode_filter_args (mu_stream_t *pfilter, mu_stream_t input,
const char *filter_name,
int argc, const char **argv,
const char *fromcode, const char *tocode);
extern enum mu_iconv_fallback_mode mu_default_fallback_mode;
int mu_set_default_fallback (const char *str);
......
......@@ -202,7 +202,7 @@ mu_rfc2822_in_reply_to (mu_message_t msg, char **pstr)
}
if (idx > 1)
rc = mu_argcv_join (idx, argv, "", mu_argcv_escape_no, pstr);
rc = mu_argcv_join (idx, (char**) argv, "", mu_argcv_escape_no, pstr);
else
rc = MU_ERR_FAILURE;
return rc;
......
......@@ -25,7 +25,6 @@ libfilter_la_SOURCES =\
decode.c\
dot.c\
filter.c\
filter_iconv.c\
fltchain.c\
fromflt.c\
header.c\
......
......@@ -21,6 +21,7 @@
#endif
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <mailutils/stream.h>
......@@ -44,30 +45,46 @@ mu_set_default_fallback (const char *str)
}
int
mu_decode_filter (mu_stream_t *pfilter, mu_stream_t input,
const char *filter_type,
const char *fromcode, const char *tocode)
mu_decode_filter_args (mu_stream_t *pfilter, mu_stream_t input,
const char *filter_name, int argc, const char **argv,
const char *fromcode, const char *tocode)
{
mu_stream_t filter;
int xargc, i;
char **xargv;
int rc;
int status = mu_filter_create (&filter, input, filter_type,
MU_FILTER_DECODE, MU_STREAM_READ);
if (status)
return status;
xargc = argc + 5;
xargv = calloc (xargc + 1, sizeof (xargv[0]));
if (!xargv)
return ENOMEM;
if (fromcode && tocode && mu_c_strcasecmp (fromcode, tocode))
{
mu_stream_t cvt;
i = 0;
if (filter_name)
xargv[i++] = (char*) filter_name;
for (; i < argc; i++)
xargv[i] = (char*) argv[i];
status = mu_filter_iconv_create (&cvt, filter, fromcode, tocode,
0, mu_default_fallback_mode);
if (status == 0)
{
mu_stream_unref (filter);
filter = cvt;
}
}
*pfilter = filter;
return 0;
if (i)
xargv[i++] = "+";
xargv[i++] = "ICONV";
xargv[i++] = (char*) fromcode;
xargv[i++] = (char*) tocode;
xargv[i] = NULL;
rc = mu_filter_chain_create (pfilter, input,
MU_FILTER_DECODE, MU_STREAM_READ,
xargc, xargv);
free (xargv);
return rc;
}
int
mu_decode_filter (mu_stream_t *pfilter, mu_stream_t input,
const char *filter_name,
const char *fromcode, const char *tocode)
{
return mu_decode_filter_args (pfilter, input, filter_name, 0, NULL,
fromcode, tocode);
}
......
......@@ -147,6 +147,7 @@ _icvt_decoder (void *xd,
switch (_icvt->fallback_mode)
{
case mu_fallback_none:
iobuf->errcode = EILSEQ;
return mu_filter_failure;
case mu_fallback_copy_pass:
......@@ -181,6 +182,7 @@ _icvt_decoder (void *xd,
break;
default:
iobuf->errcode = errno;
return mu_filter_failure;
}
}
......
......@@ -514,10 +514,9 @@ mu_mimehdr_decode_param (const char *value, int flags,
rc = mu_memory_stream_create (&outstr, 0);
if (rc)
break;
rc = mu_filter_iconv_create (&cvt, instr, source_cs, charset,
0,
mu_default_fallback_mode);
rc = mu_decode_filter (&cvt, instr, NULL,
source_cs, charset);
if (rc)
break;
......
......@@ -49,7 +49,7 @@ init_iobuf (struct mu_filter_io *io, struct _mu_filter_stream *fs)
io->isize = MFB_RDBYTES (fs->inbuf);
io->output = MFB_ENDPTR (fs->outbuf);
io->osize = MFB_FREESIZE (fs->outbuf);
io->errcode = 0;
io->errcode = MU_ERR_FAILURE;
io->eof = 0;
}
......@@ -60,6 +60,7 @@ filter_stream_init (struct _mu_filter_stream *fs)
{
struct mu_filter_io iobuf;
memset (&iobuf, 0, sizeof (iobuf));
iobuf.errcode = MU_ERR_FAILURE;
if (fs->xcode (fs->xdata, mu_filter_init, &iobuf) == mu_filter_failure)
return iobuf.errcode;
}
......
......@@ -39,7 +39,7 @@ match_string (const char *str)
return;
}
MU_ASSERT (mu_stream_seek (stream, 0, MU_SEEK_SET, NULL));
loc.mu_file = name;
loc.mu_file = (char*)name;
loc.mu_line = 0;
loc.mu_col = 0;
rc = mu_wicket_stream_match_url (stream, &loc, u, MU_URL_PARSE_ALL, &url);
......
......@@ -19,6 +19,7 @@ lib_LTLIBRARIES = libmu_compat.la
libmu_compat_la_SOURCES = \
argcv.c\
filter_iconv.c\
vartab.c
INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2010 Free Software Foundation, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library. If not, see
<http://www.gnu.org/licenses/>. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <mailutils/types.h>
#include <mailutils/stream.h>
#include <mailutils/filter.h>
int
mu_filter_iconv_create (mu_stream_t *s, mu_stream_t transport,
const char *fromcode, const char *tocode, int flags,
enum mu_iconv_fallback_mode fallback_mode)
{
const char *argv[] = { "iconv", fromcode, tocode, NULL, NULL };
switch (fallback_mode)
{
case mu_fallback_none:
argv[3] = "none";
break;
case mu_fallback_copy_pass:
argv[3] = "copy-pass";
break;
case mu_fallback_copy_octal:
argv[3] = "copy-octal";
}
return mu_filter_create_args (s, transport, "iconv", 4, argv,
MU_FILTER_DECODE, MU_FILTER_READ);
}
......@@ -135,8 +135,6 @@ libmailutils/stream/file_stream.c
libmailutils/stream/prog_stream.c
libmailutils/stream/logstream.c
libmailutils/filter/filter_iconv.c
libmailutils/server/ipsrv.c
libmailutils/server/msrv.c
......