Commit ca45a7aa ca45a7aad841db4231bdd598e9a977a36dbf90c3 by Wojciech Polak

Update C++ and Python interfaces.

* include/mailutils/prog.h: Add extern "C".
* include/mailutils/wordsplit.h: Likewise.
* libmu_cpp/address.cc (Address::to_string): Use mu_address_sget_printable.
* libmu_cpp/filter.cc (FilterIconvStream): Use mu_filter_create_args.
* python/mailutils/folder.py (get_stream, set_stream): Remove.
1 parent 240e03b9
......@@ -3,6 +3,8 @@
*.la
*.lo
*.o
*.pyc
*.pyo
*.so
*~
.bootstrap
......
......@@ -221,8 +221,9 @@ shell (List& lst)
{
char *text;
char buf[80];
int argc;
char **argv;
int wsflags = MU_WRDSF_DEFFLAGS | MU_WRDSF_COMMENT;
struct mu_wordsplit ws;
ws.ws_comment = "#";
try {
itr[num]->current ((void**) &text);
......@@ -235,40 +236,43 @@ shell (List& lst)
if (cin.getline (buf, sizeof (buf)).eof ())
return;
rc = mu_argcv_get (buf, "", "#", &argc, &argv);
if (rc)
cerr << "mu_argcv_get: " << rc << endl;
if (mu_wordsplit (buf, &ws, wsflags))
{
mu_error ("cannot split line `%s': %s", buf,
mu_wordsplit_strerror (&ws));
continue;
}
if (argc > 0)
if (ws.ws_wordc > 0)
{
string cmd (argv[0]);
string cmd (ws.ws_wordv[0]);
if (cmd == "next")
next (itr[num], argv[1]);
next (itr[num], ws.ws_wordv[1]);
else if (cmd == "first")
itr[num]->first ();
else if (cmd == "del")
del (lst, argc, argv);
del (lst, ws.ws_wordc, ws.ws_wordv);
else if (cmd == "add")
add (lst, argc, argv);
add (lst, ws.ws_wordc, ws.ws_wordv);
else if (cmd == "prep")
prep (lst, argc, argv);
prep (lst, ws.ws_wordc, ws.ws_wordv);
else if (cmd == "repl")
repl (lst, argc, argv);
repl (lst, ws.ws_wordc, ws.ws_wordv);
else if (cmd == "print")
print (lst);
else if (cmd == "quit")
return;
else if (cmd == "iter")
iter (&num, argc, argv);
iter (&num, ws.ws_wordc, ws.ws_wordv);
else if (cmd == "find")
find (itr[num], argv[1]);
find (itr[num], ws.ws_wordv[1]);
else if (cmd == "help")
help ();
else if (argc == 1)
else if (ws.ws_wordc == 1)
{
char* p;
size_t n = strtoul (argv[0], &p, 0);
size_t n = strtoul (ws.ws_wordv[0], &p, 0);
if (*p != 0)
cerr << "?" << endl;
else
......@@ -287,7 +291,7 @@ shell (List& lst)
else
cerr << "?" << endl;
}
mu_argcv_free (argc, argv);
mu_wordsplit_free (&ws);
}
}
......
......@@ -75,8 +75,8 @@ main (int argc, char **argv)
/* Debugging trace. */
if (debug)
{
Debug debug = mbox.get_debug ();
debug.set_level (MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
mu_debug_set_category_level (MU_DEBCAT_MAILBOX,
MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
}
/* Open the mailbox for reading only. */
......
......@@ -95,8 +95,8 @@ main (int argc, char *argv[])
Mailer mailer (optmailer);
if (optdebug)
{
Debug debug = mailer.get_debug ();
debug.set_level (MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
mu_debug_set_category_level (MU_DEBCAT_MAILER,
MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
}
mailer.open ();
mailer.send_message (msg, from, to);
......
......@@ -25,7 +25,6 @@
#include <mailutils/cpp/error.h>
#include <mailutils/cpp/iterator.h>
typedef int mu_list_action_t (void*, void*);
typedef int (*mu_list_comparator_t) (const void*, const void*);
namespace mailutils
......@@ -64,7 +63,7 @@ class List
void to_array (void** array, size_t count, size_t* pcount);
void locate (void* item, void** ret_item);
void apply (mu_list_action_t* action, void* cbdata);
void apply (mu_list_action_t action, void* cbdata);
mu_list_comparator_t set_comparator (mu_list_comparator_t comp);
mu_list_destroy_item_t set_destroy_item (mu_list_destroy_item_t mu_destroy_item);
......
......@@ -21,6 +21,10 @@
#include <sys/resource.h>
#include <mailutils/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MU_PROG_LIMIT_AS 0
#define MU_PROG_LIMIT_CPU 1
#define MU_PROG_LIMIT_DATA 2
......@@ -66,5 +70,9 @@ int mu_prog_stream_create (mu_stream_t *pstream,
int mu_command_stream_create (mu_stream_t *pstream, const char *command,
int flags);
#ifdef __cplusplus
}
#endif
#endif
......
......@@ -19,6 +19,10 @@
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
struct mu_wordsplit
{
size_t ws_wordc;
......@@ -155,5 +159,8 @@ void mu_wordsplit_c_quote_copy (char *dst, const char *src, int quote_hex);
void mu_wordsplit_perror (struct mu_wordsplit *ws);
const char *mu_wordsplit_strerror (struct mu_wordsplit *ws);
#ifdef __cplusplus
}
#endif
#endif
......
......@@ -172,12 +172,13 @@ std::string
Address :: to_string ()
{
size_t n;
char buf[1024];
int status = mu_address_to_string (addr, buf, sizeof (buf), &n);
char const *sptr;
int status = mu_address_sget_printable (addr, &sptr);
if (status)
throw Exception ("Address::to_string", status);
return std::string (buf);
return std::string (sptr);
}
namespace mailutils
......
......@@ -47,10 +47,12 @@ FilterIconvStream :: FilterIconvStream (Stream& transport,
int flags,
enum mu_iconv_fallback_mode fm)
{
int status = mu_filter_iconv_create (&this->stm, transport.stm,
fromcode.c_str (),
tocode.c_str (),
flags, fm);
const char *argv[4] = { "iconv", NULL, NULL, NULL };
argv[1] = fromcode.c_str ();
argv[2] = tocode.c_str ();
int status = mu_filter_create_args (&this->stm, transport.stm, argv[0], 3,
argv, MU_FILTER_DECODE, flags);
if (status)
throw Exception ("FilterIconvStream::FilterIconvStream", status);
this->input = new Stream (transport);
......
......@@ -199,7 +199,7 @@ List :: size ()
}
void
List :: apply (mu_list_action_t* action, void* cbdata)
List :: apply (mu_list_action_t action, void* cbdata)
{
int status = mu_list_foreach (mu_list, action, cbdata);
if (status)
......
......@@ -49,17 +49,6 @@ class Folder:
if status:
raise FolderError (status)
def get_stream (self):
status, stream = folder.get_stream (self.folder)
if status:
raise FolderError (status)
return stream.Stream (stm)
def set_stream (self, stream):
status = folder.set_stream (self.folder, stream.stm)
if status:
raise FolderError (status)
def get_authority (self):
status, authority = folder.get_authority (self.folder)
if status:
......