Commit 074a1485 074a14853c501529630b5b7c762cbb49711b5e73 by Sergey Poznyakoff

Remove the leftovers of mu_debug_t and obsoleted sieve interfaces.

* include/mailutils/cpp/debug.h: Remove.
* include/mailutils/cpp/Makefile.am (cppinclude_HEADERS): Remove debug.h
* libmu_cpp/debug.cc: Remove
* libmu_cpp/Makefile.am (libmu_cpp_la_SOURCES): Remove debug.cc.
* python/libmu_py/debug.c: Remove.
* python/libmu_py/Makefile.am (libmu_py_la_SOURCES): Remove debug.c
* include/mailutils/cpp/mailbox.h: Remove objects and methods derived
from mu_debug_t.
* include/mailutils/cpp/mailer.h: Likewise.
* include/mailutils/cpp/stream.h: Likewise.
* libmu_cpp/mailbox.cc: Likewise.
* libmu_cpp/mailer.cc: Likewise.
* libmu_cpp/sieve.cc: Likewise.  Ditto for mu_sieve_printf_t,
mu_sieve_parse_error_t.
* include/mailutils/cpp/sieve.h: Likewise.

* libmu_cpp/stream.cc: Remove objects and methods derived
from mu_debug_t.
(ProgStream::ProgStream): Use mu_command_stream_create (see FIXME).
(FilterProgStream::FilterProgStream): Rewrite.

* include/mailutils/python.h: Remove objects and methods derived
from mu_debug_t.
* python/libmu_py/filter.c (api_filter_iconv_create): Rewrite using
mu_filter_create_args.

* python/libmu_py/libmu_py.c: Likewise.
* python/libmu_py/libmu_py.h: Likewise.
* python/libmu_py/mailbox.c: Likewise.
* python/libmu_py/mailer.c: Likewise.
* python/libmu_py/stream.c: Likewise.
* python/libmu_py/url.c: Likewise.
* python/libmu_py/sieve.c: Likewise.  Same for mu_sieve_printf_t,
mu_sieve_parse_error_t.
1 parent 45c0bb90
......@@ -19,7 +19,6 @@ cppinclude_HEADERS = \
address.h\
attribute.h\
body.h\
debug.h\
envelope.h\
error.h\
filter.h\
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009, 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/>. */
#ifndef _MUCPP_DEBUG_H
#define _MUCPP_DEBUG_H
#include <string>
#include <errno.h>
#include <mailutils/debug.h>
#include <mailutils/cpp/error.h>
namespace mailutils
{
class Debug
{
protected:
mu_debug_t debug;
public:
Debug ();
Debug (const mu_debug_t);
void set_level (const mu_log_level_t level);
};
}
#endif // not _MUCPP_DEBUG_H
......@@ -22,7 +22,6 @@
#include <errno.h>
#include <mailutils/mailbox.h>
#include <mailutils/cpp/error.h>
#include <mailutils/cpp/debug.h>
#include <mailutils/cpp/folder.h>
#include <mailutils/cpp/message.h>
#include <mailutils/cpp/url.h>
......@@ -54,7 +53,6 @@ class MailboxBase
void unlock ();
mu_off_t get_size ();
Debug& get_debug ();
Folder& get_folder ();
Url& get_url ();
......
......@@ -22,7 +22,6 @@
#include <string>
#include <errno.h>
#include <mailutils/mailer.h>
#include <mailutils/cpp/debug.h>
#include <mailutils/cpp/message.h>
#include <mailutils/cpp/address.h>
......@@ -45,7 +44,6 @@ class Mailer
void send_message (const Message& msg, const Address& from,
const Address& to);
Debug& get_debug ();
};
}
......
......@@ -44,9 +44,6 @@ class SieveMachine
void disass ();
void mailbox (const Mailbox& mbox);
void message (const Message& msg);
void set_debug (mu_sieve_printf_t printer);
void set_error (mu_sieve_printf_t printer);
void set_parse_error (mu_sieve_parse_error_t printer);
void set_logger (mu_sieve_action_log_t printer);
};
......
......@@ -22,6 +22,8 @@
#include <string>
#include <errno.h>
#include <mailutils/stream.h>
#include <mailutils/prog.h>
#include <mailutils/wordsplit.h>
#include <mailutils/cpp/error.h>
namespace mailutils
......
......@@ -69,12 +69,6 @@ typedef struct
typedef struct
{
PyObject_HEAD;
mu_debug_t dbg;
} PyDebug;
typedef struct
{
PyObject_HEAD;
mu_envelope_t env;
} PyEnvelope;
......@@ -158,7 +152,6 @@ extern int mu_py_init_address (void);
extern int mu_py_init_attribute (void);
extern int mu_py_init_auth (void);
extern int mu_py_init_body (void);
extern int mu_py_init_debug (void);
extern int mu_py_init_envelope (void);
extern int mu_py_init_header (void);
extern int mu_py_init_folder (void);
......@@ -182,7 +175,6 @@ extern PyTicket * PyTicket_NEW ();
extern PyWicket * PyWicket_NEW ();
extern PyAuthData * PyAuthData_NEW ();
extern PyBody * PyBody_NEW ();
extern PyDebug * PyDebug_NEW ();
extern PyEnvelope * PyEnvelope_NEW ();
extern PyFolder * PyFolder_NEW ();
extern PyHeader * PyHeader_NEW ();
......@@ -223,9 +215,6 @@ extern void mu_py_script_finish (void);
extern int mu_py_script_run (const char *filename,
mu_py_script_data *data);
extern void mu_py_capture_stdout (mu_debug_t debug);
extern void mu_py_capture_stderr (mu_debug_t debug);
extern int mu_py_script_process_mailbox (int argc, char *argv[],
const char *python_filename,
const char *module_name,
......
......@@ -23,7 +23,6 @@ libmu_cpp_la_SOURCES = \
address.cc\
attribute.cc\
body.cc\
debug.cc\
envelope.cc\
filter.cc\
folder.cc\
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009, 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/>. */
#include <mailutils/cpp/debug.h>
using namespace mailutils;
//
// Debug
//
Debug :: Debug ()
{
this->debug = NULL;
}
Debug :: Debug (const mu_debug_t debug)
{
if (debug == 0)
throw Exception ("Debug::Debug", EINVAL);
this->debug = debug;
}
void
Debug :: set_level (const mu_log_level_t level)
{
int status = mu_debug_set_level (debug, level);
if (status)
throw Exception ("Debug::set_level", status);
}
......@@ -160,18 +160,6 @@ MailboxBase :: get_size ()
return size;
}
Debug&
MailboxBase :: get_debug ()
{
mu_debug_t c_dbg;
int status = mu_mailbox_get_debug (mbox, &c_dbg);
if (status)
throw Exception ("MailboxBase::get_debug", status);
return *new Debug (c_dbg);
}
Folder&
MailboxBase :: get_folder ()
{
......
......@@ -78,15 +78,3 @@ Mailer :: send_message (const Message& msg, const Address& from,
throw Exception ("Mailer::send_message", status);
}
Debug&
Mailer :: get_debug ()
{
mu_debug_t c_dbg;
int status = mu_mailer_get_debug (mailer, &c_dbg);
if (status)
throw Exception ("Mailer::get_debug", status);
return *new Debug (c_dbg);
}
......
......@@ -25,7 +25,7 @@ using namespace mailutils;
SieveMachine :: SieveMachine ()
{
int status = mu_sieve_machine_init (&mach, NULL);
int status = mu_sieve_machine_init (&mach);
if (status)
throw Exception ("SieveMachine::SieveMachine", status);
}
......@@ -88,27 +88,4 @@ SieveMachine :: message (const Message& msg)
throw Exception ("SieveMachine::message", status);
}
void
SieveMachine :: set_debug (mu_sieve_printf_t printer)
{
mu_sieve_set_debug (mach, printer);
}
void
SieveMachine :: set_error (mu_sieve_printf_t printer)
{
mu_sieve_set_error (mach, printer);
}
void
SieveMachine :: set_parse_error (mu_sieve_parse_error_t printer)
{
mu_sieve_set_parse_error (mach, printer);
}
void
SieveMachine :: set_logger (mu_sieve_action_log_t printer)
{
mu_sieve_set_logger (mach, printer);
}
......
......@@ -211,11 +211,13 @@ StdioStream :: StdioStream (int fd, int flags)
//
// ProgStream
//
/* FIXME: This must be revised using the real prog_stream interface, instead
of the command_stream
*/
ProgStream :: ProgStream (const std::string& progname, int flags)
{
int status = mu_prog_stream_create (&stm, progname.c_str (), flags);
int status = mu_command_stream_create (&stm, progname.c_str (), flags);
if (status)
throw Exception ("ProgStream::ProgStream", status);
}
......@@ -227,20 +229,28 @@ ProgStream :: ProgStream (const std::string& progname, int flags)
FilterProgStream :: FilterProgStream (const std::string& progname,
Stream& input)
{
int status = mu_filter_prog_stream_create (&stm, progname.c_str (),
input.stm);
this->input = new Stream (input);
struct mu_prog_hints hints;
struct mu_wordsplit ws;
int status;
if (mu_wordsplit (progname.c_str (), &ws, MU_WRDSF_DEFFLAGS))
throw Exception ("FilterProgStream::FilterProgStream", errno);
hints.mu_prog_input = input.stm;
status = mu_prog_stream_create (&stm, ws.ws_wordv[0],
ws.ws_wordc, ws.ws_wordv,
MU_PROG_HINT_INPUT,
&hints,
MU_STREAM_READ);
mu_wordsplit_free (&ws);
if (status)
throw Exception ("FilterProgStream::FilterProgStream", status);
this->input = new Stream (input);
}
FilterProgStream :: FilterProgStream (const std::string& progname,
Stream* input)
{
int status = mu_filter_prog_stream_create (&stm, progname.c_str (),
input->stm);
this->input = new Stream (*input);
if (status)
throw Exception ("FilterProgStream::FilterProgStream", status);
FilterProgStream (progname, input);
}
......
......@@ -23,7 +23,6 @@ libmu_py_la_SOURCES = \
attribute.c \
auth.c \
body.c \
debug.c \
envelope.c \
filter.c \
folder.c \
......
/* GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 2009, 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/>. */
#include "libmu_py.h"
#define PY_MODULE "debug"
#define PY_CSNAME "DebugType"
static PyObject *
_repr (PyObject *self)
{
char buf[80];
sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
return PyString_FromString (buf);
}
static PyTypeObject PyDebugType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
PY_MODULE "." PY_CSNAME, /* tp_name */
sizeof (PyDebug), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)_py_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr; __getattr__ */
0, /* tp_setattr; __setattr__ */
0, /* tp_compare; __cmp__ */
_repr, /* tp_repr; __repr__ */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash; __hash__ */
0, /* tp_call; __call__ */
_repr, /* tp_str; __str__ */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
0, /* tp_new */
};
PyDebug *
PyDebug_NEW ()
{
return (PyDebug *)PyObject_NEW (PyDebug, &PyDebugType);
}
static PyObject *
api_debug_set_level (PyObject *self, PyObject *args)
{
int status, level;
PyDebug *py_dbg;
if (!PyArg_ParseTuple (args, "O!i", &PyDebugType, &py_dbg, &level))
return NULL;
status = mu_debug_set_level (py_dbg->dbg,
MU_DEBUG_LEVEL_UPTO (level));
return _ro (PyInt_FromLong (status));
}
static PyMethodDef methods[] = {
{ "set_level", (PyCFunction) api_debug_set_level, METH_VARARGS,
"" },
{ NULL, NULL, 0, NULL }
};
static mu_debug_t _mu_prog_debug_stdout;
static mu_debug_t _mu_prog_debug_stderr;
static PyObject *
_capture_stdout (PyObject *self, PyObject *args)
{
char *buf = "";
if (!PyArg_ParseTuple (args, "s", &buf))
return NULL;
if (_mu_prog_debug_stdout)
mu_debug_printf (_mu_prog_debug_stdout, MU_DIAG_INFO, "%.*s",
(int) strlen (buf), buf);
return _ro (Py_None);
}
static PyObject *
_capture_stderr (PyObject *self, PyObject *args)
{
char *buf = "";
if (!PyArg_ParseTuple (args, "s", &buf))
return NULL;
if (_mu_prog_debug_stderr)
mu_debug_printf (_mu_prog_debug_stderr, MU_DIAG_ERROR, "%.*s",
(int) strlen (buf), buf);
return _ro (Py_None);
}
static PyMethodDef capture_stdout_method[] =
{
{ "write", _capture_stdout, 1 },
{ NULL, NULL, 0, NULL }
};
static PyMethodDef capture_stderr_method[] =
{
{ "write", _capture_stderr, 1 },
{ NULL, NULL, 0, NULL }
};
void
mu_py_capture_stdout (mu_debug_t debug)
{
PyObject *py_out;
_mu_prog_debug_stdout = debug;
py_out = Py_InitModule ("stdout", capture_stdout_method);
if (py_out)
PySys_SetObject ("stdout", py_out);
}
void
mu_py_capture_stderr (mu_debug_t debug)
{
PyObject *py_err;
_mu_prog_debug_stderr = debug;
py_err = Py_InitModule ("stderr", capture_stderr_method);
if (py_err)
PySys_SetObject ("stderr", py_err);
}
int
mu_py_init_debug (void)
{
PyDebugType.tp_new = PyType_GenericNew;
return PyType_Ready (&PyDebugType);
}
void
_mu_py_attach_debug (void)
{
PyObject *m;
if ((m = _mu_py_attach_module (PY_MODULE, methods)))
{
Py_INCREF (&PyDebugType);
PyModule_AddObject (m, PY_CSNAME, (PyObject *)&PyDebugType);
}
}
......@@ -50,7 +50,8 @@ api_filter_iconv_create (PyObject *self, PyObject *args)
char *fromcode = NULL;
char *tocode = NULL;
PyStream *py_stm, *py_transport;
const char *argv[4] = { "iconv", NULL, NULL, NULL };
if (!PyArg_ParseTuple (args, "OOssi",
&py_stm, &py_transport,
&fromcode, &tocode, &flags))
......@@ -63,9 +64,10 @@ api_filter_iconv_create (PyObject *self, PyObject *args)
return NULL;
}
status = mu_filter_iconv_create (&py_stm->stm, py_transport->stm,
fromcode, tocode, flags,
mu_fallback_none);
argv[1] = fromcode;
argv[2] = tocode;
mu_filter_create_args (&py_stm->stm, py_transport->stm, argv[0], 3, argv,
MU_FILTER_DECODE, flags);
return _ro (PyInt_FromLong (status));
}
......
......@@ -72,7 +72,6 @@ mu_py_init (void)
mu_py_init_attribute ();
mu_py_init_auth ();
mu_py_init_body ();
mu_py_init_debug ();
mu_py_init_envelope ();
mu_py_init_header ();
mu_py_init_folder ();
......
......@@ -45,6 +45,8 @@
#include <mailutils/stream.h>
#include <mailutils/url.h>
#include <mailutils/python.h>
#include <mailutils/wordsplit.h>
#include <mailutils/prog.h>
#define PY_PACKAGE_NAME "mailutils"
#define PY_ROOT_NAME "c_api"
......
......@@ -340,22 +340,6 @@ api_mailbox_get_size (PyObject *self, PyObject *args)
}
static PyObject *
api_mailbox_get_debug (PyObject *self, PyObject *args)
{
int status;
PyMailbox *py_mbox;
PyDebug *py_dbg = PyDebug_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
status = mu_mailbox_get_debug (py_mbox->mbox, &py_dbg->dbg);
Py_INCREF (py_dbg);
return status_object (status, (PyObject *)py_dbg);
}
static PyObject *
api_mailbox_get_folder (PyObject *self, PyObject *args)
{
int status;
......@@ -444,9 +428,6 @@ static PyMethodDef methods[] = {
{ "get_size", (PyCFunction) api_mailbox_get_size, METH_VARARGS,
"" },
{ "get_debug", (PyCFunction) api_mailbox_get_debug, METH_VARARGS,
"" },
{ "get_folder", (PyCFunction) api_mailbox_get_folder, METH_VARARGS,
"" },
......
......@@ -168,22 +168,6 @@ api_mailer_send_message (PyObject *self, PyObject *args)
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_mailer_get_debug (PyObject *self, PyObject *args)
{
int status;
PyMailer *py_mlr;
PyDebug *py_dbg = PyDebug_NEW ();
if (!PyArg_ParseTuple (args, "O!", &PyMailerType, &py_mlr))
return NULL;
status = mu_mailer_get_debug (py_mlr->mlr, &py_dbg->dbg);
Py_INCREF (py_dbg);
return status_object (status, (PyObject *)py_dbg);
}
static PyMethodDef methods[] = {
{ "create", (PyCFunction) api_mailer_create, METH_VARARGS,
"Create mailer." },
......@@ -200,9 +184,6 @@ static PyMethodDef methods[] = {
{ "send_message", (PyCFunction) api_mailer_send_message, METH_VARARGS,
"" },
{ "get_debug", (PyCFunction) api_mailer_get_debug, METH_VARARGS,
"" },
{ NULL, NULL, 0, NULL }
};
......
......@@ -94,15 +94,11 @@ api_sieve_machine_init (PyObject *self, PyObject *args)
{
int status;
PySieveMachine *py_mach;
struct _mu_py_sieve_logger *s;
if (!PyArg_ParseTuple (args, "O!", &PySieveMachineType, &py_mach))
return NULL;
if (!(s = calloc (1, sizeof (*s))))
return NULL;
status = mu_sieve_machine_init (&py_mach->mach, s);
status = mu_sieve_machine_init (&py_mach->mach);
return _ro (PyInt_FromLong (status));
}
......@@ -190,224 +186,71 @@ api_sieve_message (PyObject *self, PyObject *args)
return _ro (PyInt_FromLong (status));
}
static int
_sieve_error_printer (void *data, const char *fmt, va_list ap)
{
char *buf = NULL;
size_t buflen = 0;
PyObject *py_args = PyTuple_New (1);
if (py_args)
{
struct _mu_py_sieve_logger *s = data;
PyObject *py_fnc = s->py_error_printer;
if (mu_vasnprintf (&buf, &buflen, fmt, ap))
return 0;
PyTuple_SetItem (py_args, 0, PyString_FromString (buf ? buf : ""));
if (buf)
free (buf);
if (py_fnc && PyCallable_Check (py_fnc))
PyObject_CallObject (py_fnc, py_args);
Py_DECREF (py_args);
}
return 0;
}
static int
_sieve_parse_error_printer (void *data, const char *filename, int lineno,
const char *fmt, va_list ap)
{
PyObject *py_args;
PyObject *py_dict;
py_dict = PyDict_New ();
if (py_dict)
{
char *buf = NULL;
size_t buflen = 0;
PyDict_SetItemString (py_dict, "filename",
PyString_FromString (filename));
PyDict_SetItemString (py_dict, "lineno", PyInt_FromLong (lineno));
if (mu_vasnprintf (&buf, &buflen, fmt, ap))
return 0;
PyDict_SetItemString (py_dict, "text",
PyString_FromString (buf ? buf : ""));
if (buf)
free (buf);
py_args = PyTuple_New (1);
if (py_args)
{
struct _mu_py_sieve_logger *s = data;
PyObject *py_fnc = s->py_parse_error_printer;
Py_INCREF (py_dict);
PyTuple_SetItem (py_args, 0, py_dict);
if (py_fnc && PyCallable_Check (py_fnc))
PyObject_CallObject (py_fnc, py_args);
Py_DECREF (py_dict);
Py_DECREF (py_args);
}
}
return 0;
}
static int
_sieve_debug_printer (void *data, const char *fmt, va_list ap)
{
char *buf = NULL;
size_t buflen = 0;
PyObject *py_args = PyTuple_New (1);
if (py_args)
{
struct _mu_py_sieve_logger *s = data;
PyObject *py_fnc = s->py_debug_printer;
if (mu_vasnprintf (&buf, &buflen, fmt, ap))
return 0;
PyTuple_SetItem (py_args, 0, PyString_FromString (buf ? buf : ""));
if (buf)
free (buf);
if (py_fnc && PyCallable_Check (py_fnc))
PyObject_CallObject (py_fnc, py_args);
Py_DECREF (py_args);
}
return 0;
}
static void
_sieve_action_printer (void *data, const struct mu_locus *locus,
_sieve_action_printer (void *data, mu_stream_t stream,
size_t msgno, mu_message_t msg,
const char *action, const char *fmt, va_list ap)
{
PyObject *py_args;
PyObject *py_dict;
PyObject *py_dict = PyDict_New ();
PyStream *py_stm;
py_dict = PyDict_New ();
if (py_dict)
if (!py_dict)
return;
py_stm = PyStream_NEW ();
if (py_stm)
{
PyMessage *py_msg = PyMessage_NEW ();
char *buf = NULL;
size_t buflen = 0;
PyMessage *py_msg = PyMessage_NEW ();
py_msg->msg = msg;
Py_INCREF (py_msg);
PyDict_SetItemString (py_dict, "source_file",
PyString_FromString (locus->source_file));
PyDict_SetItemString (py_dict, "source_line",
PyInt_FromLong (locus->source_line));
PyDict_SetItemString (py_dict, "msgno",
PyInt_FromLong (msgno));
PyDict_SetItemString (py_dict, "msg", (PyObject *)py_msg);
PyDict_SetItemString (py_dict, "action",
PyString_FromString (action ? action : ""));
if (mu_vasnprintf (&buf, &buflen, fmt, ap))
return;
PyDict_SetItemString (py_dict, "text",
PyString_FromString (buf ? buf : ""));
if (buf)
free (buf);
py_args = PyTuple_New (1);
if (py_args)
if (py_msg)
{
struct _mu_py_sieve_logger *s = data;
PyObject *py_fnc = s->py_action_printer;
Py_INCREF (py_dict);
PyTuple_SetItem (py_args, 0, py_dict);
if (py_fnc && PyCallable_Check (py_fnc))
PyObject_CallObject (py_fnc, py_args);
Py_DECREF (py_dict);
Py_DECREF (py_args);
PyStream *py_stm = PyStream_NEW ();
if (py_stm)
{
py_stm->stm = stream;
mu_stream_ref (stream);
py_msg->msg = msg;
Py_INCREF (py_msg);
PyDict_SetItemString (py_dict, "msgno",
PyInt_FromLong (msgno));
PyDict_SetItemString (py_dict, "msg", (PyObject *)py_msg);
PyDict_SetItemString (py_dict, "action",
PyString_FromString (action ? action : ""));
if (mu_vasnprintf (&buf, &buflen, fmt, ap))
{
mu_stream_unref (stream);
return;
}
PyDict_SetItemString (py_dict, "text",
PyString_FromString (buf ? buf : ""));
free (buf);
py_args = PyTuple_New (1);
if (py_args)
{
struct _mu_py_sieve_logger *s = data;
PyObject *py_fnc = s->py_action_printer;
Py_INCREF (py_dict);
PyTuple_SetItem (py_args, 0, py_dict);
if (py_fnc && PyCallable_Check (py_fnc))
PyObject_CallObject (py_fnc, py_args);
Py_DECREF (py_dict);
Py_DECREF (py_args);
}
}
}
}
}
static PyObject *
api_sieve_set_error (PyObject *self, PyObject *args)
{
PySieveMachine *py_mach;
PyObject *py_fnc;
if (!PyArg_ParseTuple (args, "O!O", &PySieveMachineType, &py_mach, &py_fnc))
return NULL;
if (py_fnc && PyCallable_Check (py_fnc)) {
mu_sieve_machine_t mach = py_mach->mach;
struct _mu_py_sieve_logger *s = mu_sieve_get_data (mach);
s->py_error_printer = py_fnc;
Py_INCREF (py_fnc);
mu_sieve_set_error (py_mach->mach, _sieve_error_printer);
}
else {
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
return _ro (Py_None);
}
static PyObject *
api_sieve_set_parse_error (PyObject *self, PyObject *args)
{
PySieveMachine *py_mach;
PyObject *py_fnc;
if (!PyArg_ParseTuple (args, "O!O", &PySieveMachineType, &py_mach, &py_fnc))
return NULL;
if (py_fnc && PyCallable_Check (py_fnc)) {
mu_sieve_machine_t mach = py_mach->mach;
struct _mu_py_sieve_logger *s = mu_sieve_get_data (mach);
s->py_parse_error_printer = py_fnc;
Py_INCREF (py_fnc);
mu_sieve_set_parse_error (py_mach->mach, _sieve_parse_error_printer);
}
else {
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
return _ro (Py_None);
}
static PyObject *
api_sieve_set_debug (PyObject *self, PyObject *args)
{
PySieveMachine *py_mach;
PyObject *py_fnc;
if (!PyArg_ParseTuple (args, "O!O", &PySieveMachineType, &py_mach, &py_fnc))
return NULL;
if (py_fnc && PyCallable_Check (py_fnc)) {
mu_sieve_machine_t mach = py_mach->mach;
struct _mu_py_sieve_logger *s = mu_sieve_get_data (mach);
s->py_debug_printer = py_fnc;
Py_INCREF (py_fnc);
mu_sieve_set_debug (py_mach->mach, _sieve_debug_printer);
}
else {
PyErr_SetString (PyExc_TypeError, "");
return NULL;
}
return _ro (Py_None);
}
static PyObject *
api_sieve_set_logger (PyObject *self, PyObject *args)
{
PySieveMachine *py_mach;
......@@ -451,15 +294,6 @@ static PyMethodDef methods[] = {
"Execute the code from the given instance of sieve machine "
"'mach' over the 'message'. " },
{ "set_debug", (PyCFunction) api_sieve_set_debug, METH_VARARGS,
"" },
{ "set_error", (PyCFunction) api_sieve_set_error, METH_VARARGS,
"" },
{ "set_parse_error", (PyCFunction) api_sieve_set_parse_error, METH_VARARGS,
"" },
{ "set_logger", (PyCFunction) api_sieve_set_logger, METH_VARARGS,
"" },
......
......@@ -136,7 +136,7 @@ api_prog_stream_create (PyObject *self, PyObject *args)
&progname, &flags))
return NULL;
status = mu_prog_stream_create (&py_stm->stm, progname, flags);
status = mu_command_stream_create (&py_stm->stm, progname, flags);
return _ro (PyInt_FromLong (status));
}
......@@ -146,6 +146,8 @@ api_filter_prog_stream_create (PyObject *self, PyObject *args)
int status;
char *progname;
PyStream *py_stm, *py_input;
struct mu_prog_hints hints;
struct mu_wordsplit ws;
if (!PyArg_ParseTuple (args, "O!sO!",
&PyStreamType, &py_stm,
......@@ -153,8 +155,16 @@ api_filter_prog_stream_create (PyObject *self, PyObject *args)
&PyStreamType, &py_input))
return NULL;
status = mu_filter_prog_stream_create (&py_stm->stm, progname,
py_input->stm);
if (mu_wordsplit (progname, &ws, MU_WRDSF_DEFFLAGS))
return _ro (PyInt_FromLong (errno));
hints.mu_prog_input = py_input->stm;
status = mu_prog_stream_create (&py_stm->stm, ws.ws_wordv[0],
ws.ws_wordc, ws.ws_wordv,
MU_PROG_HINT_INPUT,
&hints,
MU_STREAM_READ);
mu_wordsplit_free (&ws);
return _ro (PyInt_FromLong (status));
}
......
......@@ -106,7 +106,6 @@ api_url_destroy (PyObject *self, PyObject *args)
static PyObject *
api_url_parse (PyObject *self, PyObject *args)
{
int status;
PyUrl *py_url;
if (!PyArg_ParseTuple (args, "O!", &PyUrlType, &py_url))
......