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 @@ ...@@ -3,6 +3,8 @@
3 *.la 3 *.la
4 *.lo 4 *.lo
5 *.o 5 *.o
6 *.pyc
7 *.pyo
6 *.so 8 *.so
7 *~ 9 *~
8 .bootstrap 10 .bootstrap
......
...@@ -221,9 +221,10 @@ shell (List& lst) ...@@ -221,9 +221,10 @@ shell (List& lst)
221 { 221 {
222 char *text; 222 char *text;
223 char buf[80]; 223 char buf[80];
224 int argc; 224 int wsflags = MU_WRDSF_DEFFLAGS | MU_WRDSF_COMMENT;
225 char **argv; 225 struct mu_wordsplit ws;
226 226 ws.ws_comment = "#";
227
227 try { 228 try {
228 itr[num]->current ((void**) &text); 229 itr[num]->current ((void**) &text);
229 } 230 }
...@@ -235,40 +236,43 @@ shell (List& lst) ...@@ -235,40 +236,43 @@ shell (List& lst)
235 if (cin.getline (buf, sizeof (buf)).eof ()) 236 if (cin.getline (buf, sizeof (buf)).eof ())
236 return; 237 return;
237 238
238 rc = mu_argcv_get (buf, "", "#", &argc, &argv); 239 if (mu_wordsplit (buf, &ws, wsflags))
239 if (rc) 240 {
240 cerr << "mu_argcv_get: " << rc << endl; 241 mu_error ("cannot split line `%s': %s", buf,
242 mu_wordsplit_strerror (&ws));
243 continue;
244 }
241 245
242 if (argc > 0) 246 if (ws.ws_wordc > 0)
243 { 247 {
244 string cmd (argv[0]); 248 string cmd (ws.ws_wordv[0]);
245 249
246 if (cmd == "next") 250 if (cmd == "next")
247 next (itr[num], argv[1]); 251 next (itr[num], ws.ws_wordv[1]);
248 else if (cmd == "first") 252 else if (cmd == "first")
249 itr[num]->first (); 253 itr[num]->first ();
250 else if (cmd == "del") 254 else if (cmd == "del")
251 del (lst, argc, argv); 255 del (lst, ws.ws_wordc, ws.ws_wordv);
252 else if (cmd == "add") 256 else if (cmd == "add")
253 add (lst, argc, argv); 257 add (lst, ws.ws_wordc, ws.ws_wordv);
254 else if (cmd == "prep") 258 else if (cmd == "prep")
255 prep (lst, argc, argv); 259 prep (lst, ws.ws_wordc, ws.ws_wordv);
256 else if (cmd == "repl") 260 else if (cmd == "repl")
257 repl (lst, argc, argv); 261 repl (lst, ws.ws_wordc, ws.ws_wordv);
258 else if (cmd == "print") 262 else if (cmd == "print")
259 print (lst); 263 print (lst);
260 else if (cmd == "quit") 264 else if (cmd == "quit")
261 return; 265 return;
262 else if (cmd == "iter") 266 else if (cmd == "iter")
263 iter (&num, argc, argv); 267 iter (&num, ws.ws_wordc, ws.ws_wordv);
264 else if (cmd == "find") 268 else if (cmd == "find")
265 find (itr[num], argv[1]); 269 find (itr[num], ws.ws_wordv[1]);
266 else if (cmd == "help") 270 else if (cmd == "help")
267 help (); 271 help ();
268 else if (argc == 1) 272 else if (ws.ws_wordc == 1)
269 { 273 {
270 char* p; 274 char* p;
271 size_t n = strtoul (argv[0], &p, 0); 275 size_t n = strtoul (ws.ws_wordv[0], &p, 0);
272 if (*p != 0) 276 if (*p != 0)
273 cerr << "?" << endl; 277 cerr << "?" << endl;
274 else 278 else
...@@ -287,7 +291,7 @@ shell (List& lst) ...@@ -287,7 +291,7 @@ shell (List& lst)
287 else 291 else
288 cerr << "?" << endl; 292 cerr << "?" << endl;
289 } 293 }
290 mu_argcv_free (argc, argv); 294 mu_wordsplit_free (&ws);
291 } 295 }
292 } 296 }
293 297
......
...@@ -75,8 +75,8 @@ main (int argc, char **argv) ...@@ -75,8 +75,8 @@ main (int argc, char **argv)
75 /* Debugging trace. */ 75 /* Debugging trace. */
76 if (debug) 76 if (debug)
77 { 77 {
78 Debug debug = mbox.get_debug (); 78 mu_debug_set_category_level (MU_DEBCAT_MAILBOX,
79 debug.set_level (MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT)); 79 MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
80 } 80 }
81 81
82 /* Open the mailbox for reading only. */ 82 /* Open the mailbox for reading only. */
......
...@@ -95,8 +95,8 @@ main (int argc, char *argv[]) ...@@ -95,8 +95,8 @@ main (int argc, char *argv[])
95 Mailer mailer (optmailer); 95 Mailer mailer (optmailer);
96 if (optdebug) 96 if (optdebug)
97 { 97 {
98 Debug debug = mailer.get_debug (); 98 mu_debug_set_category_level (MU_DEBCAT_MAILER,
99 debug.set_level (MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT)); 99 MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
100 } 100 }
101 mailer.open (); 101 mailer.open ();
102 mailer.send_message (msg, from, to); 102 mailer.send_message (msg, from, to);
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
25 #include <mailutils/cpp/error.h> 25 #include <mailutils/cpp/error.h>
26 #include <mailutils/cpp/iterator.h> 26 #include <mailutils/cpp/iterator.h>
27 27
28 typedef int mu_list_action_t (void*, void*);
29 typedef int (*mu_list_comparator_t) (const void*, const void*); 28 typedef int (*mu_list_comparator_t) (const void*, const void*);
30 29
31 namespace mailutils 30 namespace mailutils
...@@ -64,7 +63,7 @@ class List ...@@ -64,7 +63,7 @@ class List
64 void to_array (void** array, size_t count, size_t* pcount); 63 void to_array (void** array, size_t count, size_t* pcount);
65 void locate (void* item, void** ret_item); 64 void locate (void* item, void** ret_item);
66 65
67 void apply (mu_list_action_t* action, void* cbdata); 66 void apply (mu_list_action_t action, void* cbdata);
68 mu_list_comparator_t set_comparator (mu_list_comparator_t comp); 67 mu_list_comparator_t set_comparator (mu_list_comparator_t comp);
69 mu_list_destroy_item_t set_destroy_item (mu_list_destroy_item_t mu_destroy_item); 68 mu_list_destroy_item_t set_destroy_item (mu_list_destroy_item_t mu_destroy_item);
70 69
......
...@@ -21,6 +21,10 @@ ...@@ -21,6 +21,10 @@
21 #include <sys/resource.h> 21 #include <sys/resource.h>
22 #include <mailutils/types.h> 22 #include <mailutils/types.h>
23 23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
24 #define MU_PROG_LIMIT_AS 0 28 #define MU_PROG_LIMIT_AS 0
25 #define MU_PROG_LIMIT_CPU 1 29 #define MU_PROG_LIMIT_CPU 1
26 #define MU_PROG_LIMIT_DATA 2 30 #define MU_PROG_LIMIT_DATA 2
...@@ -66,5 +70,9 @@ int mu_prog_stream_create (mu_stream_t *pstream, ...@@ -66,5 +70,9 @@ int mu_prog_stream_create (mu_stream_t *pstream,
66 int mu_command_stream_create (mu_stream_t *pstream, const char *command, 70 int mu_command_stream_create (mu_stream_t *pstream, const char *command,
67 int flags); 71 int flags);
68 72
73 #ifdef __cplusplus
74 }
75 #endif
76
69 #endif 77 #endif
70 78
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
19 19
20 #include <stddef.h> 20 #include <stddef.h>
21 21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
22 struct mu_wordsplit 26 struct mu_wordsplit
23 { 27 {
24 size_t ws_wordc; 28 size_t ws_wordc;
...@@ -155,5 +159,8 @@ void mu_wordsplit_c_quote_copy (char *dst, const char *src, int quote_hex); ...@@ -155,5 +159,8 @@ void mu_wordsplit_c_quote_copy (char *dst, const char *src, int quote_hex);
155 void mu_wordsplit_perror (struct mu_wordsplit *ws); 159 void mu_wordsplit_perror (struct mu_wordsplit *ws);
156 const char *mu_wordsplit_strerror (struct mu_wordsplit *ws); 160 const char *mu_wordsplit_strerror (struct mu_wordsplit *ws);
157 161
162 #ifdef __cplusplus
163 }
164 #endif
158 165
159 #endif 166 #endif
......
...@@ -172,12 +172,13 @@ std::string ...@@ -172,12 +172,13 @@ std::string
172 Address :: to_string () 172 Address :: to_string ()
173 { 173 {
174 size_t n; 174 size_t n;
175 char buf[1024]; 175 char const *sptr;
176 int status = mu_address_to_string (addr, buf, sizeof (buf), &n); 176
177 int status = mu_address_sget_printable (addr, &sptr);
177 if (status) 178 if (status)
178 throw Exception ("Address::to_string", status); 179 throw Exception ("Address::to_string", status);
179 180
180 return std::string (buf); 181 return std::string (sptr);
181 } 182 }
182 183
183 namespace mailutils 184 namespace mailutils
......
...@@ -47,10 +47,12 @@ FilterIconvStream :: FilterIconvStream (Stream& transport, ...@@ -47,10 +47,12 @@ FilterIconvStream :: FilterIconvStream (Stream& transport,
47 int flags, 47 int flags,
48 enum mu_iconv_fallback_mode fm) 48 enum mu_iconv_fallback_mode fm)
49 { 49 {
50 int status = mu_filter_iconv_create (&this->stm, transport.stm, 50 const char *argv[4] = { "iconv", NULL, NULL, NULL };
51 fromcode.c_str (), 51 argv[1] = fromcode.c_str ();
52 tocode.c_str (), 52 argv[2] = tocode.c_str ();
53 flags, fm); 53
54 int status = mu_filter_create_args (&this->stm, transport.stm, argv[0], 3,
55 argv, MU_FILTER_DECODE, flags);
54 if (status) 56 if (status)
55 throw Exception ("FilterIconvStream::FilterIconvStream", status); 57 throw Exception ("FilterIconvStream::FilterIconvStream", status);
56 this->input = new Stream (transport); 58 this->input = new Stream (transport);
......
...@@ -199,7 +199,7 @@ List :: size () ...@@ -199,7 +199,7 @@ List :: size ()
199 } 199 }
200 200
201 void 201 void
202 List :: apply (mu_list_action_t* action, void* cbdata) 202 List :: apply (mu_list_action_t action, void* cbdata)
203 { 203 {
204 int status = mu_list_foreach (mu_list, action, cbdata); 204 int status = mu_list_foreach (mu_list, action, cbdata);
205 if (status) 205 if (status)
......
...@@ -49,17 +49,6 @@ class Folder: ...@@ -49,17 +49,6 @@ class Folder:
49 if status: 49 if status:
50 raise FolderError (status) 50 raise FolderError (status)
51 51
52 def get_stream (self):
53 status, stream = folder.get_stream (self.folder)
54 if status:
55 raise FolderError (status)
56 return stream.Stream (stm)
57
58 def set_stream (self, stream):
59 status = folder.set_stream (self.folder, stream.stm)
60 if status:
61 raise FolderError (status)
62
63 def get_authority (self): 52 def get_authority (self):
64 status, authority = folder.get_authority (self.folder) 53 status, authority = folder.get_authority (self.folder)
65 if status: 54 if status:
......