Update C++ API and the examples.
* include/mailutils/cpp/pop3.h (capa): Add reread parameter. (getline): Add new prototype. (send, readline): Remove. (response, stat): Change prototype. * libmu_cpp/pop3.cc: Likewise. * include/mailutils/cpp/stream.h (read, write, readline): Change prototype. (sequential_readline, sequential_write): Remove. * libmu_cpp/stream.cc: Likewise.
Showing
8 changed files
with
51 additions
and
73 deletions
... | @@ -39,7 +39,7 @@ main (int argc, char **argv) | ... | @@ -39,7 +39,7 @@ main (int argc, char **argv) |
39 | } | 39 | } |
40 | 40 | ||
41 | try { | 41 | try { |
42 | StdioStream *in = new StdioStream (stdin, 0); | 42 | StdioStream *in = new StdioStream (MU_STDIN_FD, 0); |
43 | in->open (); | 43 | in->open (); |
44 | 44 | ||
45 | FilterIconvStream cvt (*in, (string)argv[1], (string)argv[2], 0, | 45 | FilterIconvStream cvt (*in, (string)argv[1], (string)argv[2], 0, |
... | @@ -47,12 +47,12 @@ main (int argc, char **argv) | ... | @@ -47,12 +47,12 @@ main (int argc, char **argv) |
47 | cvt.open (); | 47 | cvt.open (); |
48 | delete in; | 48 | delete in; |
49 | 49 | ||
50 | StdioStream out (stdout, 0); | 50 | StdioStream out (MU_STDOUT_FD, 0); |
51 | out.open (); | 51 | out.open (); |
52 | 52 | ||
53 | do { | 53 | do { |
54 | cvt.read (buffer, sizeof (buffer), total); | 54 | cvt.read (buffer, sizeof (buffer)); |
55 | out.sequential_write (buffer, cvt.get_read_count ()); | 55 | out.write (buffer, cvt.get_read_count ()); |
56 | total += cvt.get_read_count (); | 56 | total += cvt.get_read_count (); |
57 | } while (cvt.get_read_count ()); | 57 | } while (cvt.get_read_count ()); |
58 | 58 | ... | ... |
... | @@ -187,14 +187,12 @@ message_display_parts (Message& msg, int indent) | ... | @@ -187,14 +187,12 @@ message_display_parts (Message& msg, int indent) |
187 | Stream stream = body.get_stream (); | 187 | Stream stream = body.get_stream (); |
188 | 188 | ||
189 | FilterStream filter (stream, encoding, 0, 0); | 189 | FilterStream filter (stream, encoding, 0, 0); |
190 | int offset = 0; | ||
191 | char buf[2048]; | 190 | char buf[2048]; |
192 | 191 | ||
193 | while (filter.readline (buf, sizeof (buf), offset) == 0 && | 192 | while (filter.readline (buf, sizeof (buf)) == 0 && |
194 | filter.get_read_count ()) | 193 | filter.get_read_count ()) |
195 | { | 194 | { |
196 | cout << setw (indent) << setfill (' ') << buf; | 195 | cout << setw (indent) << setfill (' ') << buf; |
197 | offset += filter.get_read_count (); | ||
198 | } | 196 | } |
199 | } | 197 | } |
200 | else | 198 | else | ... | ... |
... | @@ -88,7 +88,7 @@ main (int argc, char *argv[]) | ... | @@ -88,7 +88,7 @@ main (int argc, char *argv[]) |
88 | } | 88 | } |
89 | 89 | ||
90 | try { | 90 | try { |
91 | StdioStream in (stdin, MU_STREAM_SEEK); | 91 | StdioStream in (MU_STDIN_FD, MU_STREAM_SEEK); |
92 | in.open (); | 92 | in.open (); |
93 | 93 | ||
94 | Message msg; | 94 | Message msg; | ... | ... |
... | @@ -33,11 +33,11 @@ read_and_print (Stream *in, Stream& out) | ... | @@ -33,11 +33,11 @@ read_and_print (Stream *in, Stream& out) |
33 | { | 33 | { |
34 | char buffer[128]; | 34 | char buffer[128]; |
35 | 35 | ||
36 | in->sequential_readline (buffer, sizeof (buffer)); | 36 | in->readline (buffer, sizeof (buffer)); |
37 | while (in->get_read_count ()) | 37 | while (in->get_read_count ()) |
38 | { | 38 | { |
39 | out.sequential_write (buffer, in->get_read_count ()); | 39 | out.write (buffer, in->get_read_count ()); |
40 | in->sequential_readline (buffer, sizeof (buffer)); | 40 | in->readline (buffer, sizeof (buffer)); |
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
... | @@ -47,7 +47,7 @@ create_filter (bool read_stdin, char *cmdline, int flags) | ... | @@ -47,7 +47,7 @@ create_filter (bool read_stdin, char *cmdline, int flags) |
47 | try { | 47 | try { |
48 | if (read_stdin) | 48 | if (read_stdin) |
49 | { | 49 | { |
50 | StdioStream *in = new StdioStream (stdin, 0); | 50 | StdioStream *in = new StdioStream (MU_STDIN_FD, 0); |
51 | in->open (); | 51 | in->open (); |
52 | FilterProgStream *stream = new FilterProgStream (cmdline, in); | 52 | FilterProgStream *stream = new FilterProgStream (cmdline, in); |
53 | stream->open (); | 53 | stream->open (); |
... | @@ -96,7 +96,7 @@ main (int argc, char *argv[]) | ... | @@ -96,7 +96,7 @@ main (int argc, char *argv[]) |
96 | stream = create_filter (read_stdin, cmdline, flags); | 96 | stream = create_filter (read_stdin, cmdline, flags); |
97 | 97 | ||
98 | try { | 98 | try { |
99 | StdioStream out (stdout, 0); | 99 | StdioStream out (MU_STDOUT_FD, 0); |
100 | out.open (); | 100 | out.open (); |
101 | 101 | ||
102 | read_and_print (stream, out); | 102 | read_and_print (stream, out); | ... | ... |
... | @@ -51,7 +51,7 @@ class Pop3 | ... | @@ -51,7 +51,7 @@ class Pop3 |
51 | 51 | ||
52 | void apop (const char* name, const char* digest); | 52 | void apop (const char* name, const char* digest); |
53 | void stls (); | 53 | void stls (); |
54 | Iterator& capa (); | 54 | Iterator& capa (bool reread); |
55 | void dele (unsigned int msgno); | 55 | void dele (unsigned int msgno); |
56 | size_t list (unsigned int msgno); | 56 | size_t list (unsigned int msgno); |
57 | Iterator& list_all (); | 57 | Iterator& list_all (); |
... | @@ -60,16 +60,15 @@ class Pop3 | ... | @@ -60,16 +60,15 @@ class Pop3 |
60 | void quit (); | 60 | void quit (); |
61 | Stream& retr (unsigned int msgno); | 61 | Stream& retr (unsigned int msgno); |
62 | void rset (); | 62 | void rset (); |
63 | void stat (unsigned int* count, size_t* octets); | 63 | void stat (unsigned int* count, mu_off_t* octets); |
64 | Stream& top (unsigned int msgno, unsigned int lines); | 64 | Stream& top (unsigned int msgno, unsigned int lines); |
65 | std::string uidl (unsigned int msgno); | 65 | std::string uidl (unsigned int msgno); |
66 | Iterator& uidl_all (); | 66 | Iterator& uidl_all (); |
67 | void user (const char* user); | 67 | void user (const char* user); |
68 | 68 | ||
69 | size_t readline (char* buf, size_t buflen); | 69 | void getline (); |
70 | size_t response (char* buf, size_t buflen); | 70 | void response (size_t* nread); |
71 | void sendline (const char* line); | 71 | void sendline (const char* line); |
72 | void send (); | ||
73 | }; | 72 | }; |
74 | 73 | ||
75 | } | 74 | } | ... | ... |
... | @@ -68,11 +68,10 @@ class Stream | ... | @@ -68,11 +68,10 @@ class Stream |
68 | void set_waitflags (int flags); | 68 | void set_waitflags (int flags); |
69 | void wait (); // timeval is missing | 69 | void wait (); // timeval is missing |
70 | void wait (int flags); // timeval is missing | 70 | void wait (int flags); // timeval is missing |
71 | int read (char* rbuf, size_t size, off_t offset); | 71 | int read (void* rbuf, size_t size); |
72 | int write (const std::string& wbuf, size_t size, off_t offset); | 72 | int write (void* wbuf, size_t size); |
73 | int readline (char* rbuf, size_t size, off_t offset); | 73 | int write (const std::string& wbuf, size_t size); |
74 | void sequential_readline (char* rbuf, size_t size); | 74 | int readline (char* rbuf, size_t size); |
75 | void sequential_write (const std::string& wbuf, size_t size); | ||
76 | void flush (); | 75 | void flush (); |
77 | 76 | ||
78 | // Inlines | 77 | // Inlines |
... | @@ -108,7 +107,7 @@ class FileStream : public Stream | ... | @@ -108,7 +107,7 @@ class FileStream : public Stream |
108 | class StdioStream : public Stream | 107 | class StdioStream : public Stream |
109 | { | 108 | { |
110 | public: | 109 | public: |
111 | StdioStream (FILE*, int); | 110 | StdioStream (int fd, int flags); |
112 | }; | 111 | }; |
113 | 112 | ||
114 | class ProgStream : public Stream | 113 | class ProgStream : public Stream | ... | ... |
... | @@ -120,11 +120,11 @@ Pop3 :: stls () | ... | @@ -120,11 +120,11 @@ Pop3 :: stls () |
120 | } | 120 | } |
121 | 121 | ||
122 | Iterator& | 122 | Iterator& |
123 | Pop3 :: capa () | 123 | Pop3 :: capa (bool reread = false) |
124 | { | 124 | { |
125 | mu_iterator_t mu_itr; | 125 | mu_iterator_t mu_itr; |
126 | 126 | ||
127 | int status = mu_pop3_capa (pop3, &mu_itr); | 127 | int status = mu_pop3_capa (pop3, reread, &mu_itr); |
128 | if (status) | 128 | if (status) |
129 | throw Exception ("Pop3::capa", status); | 129 | throw Exception ("Pop3::capa", status); |
130 | 130 | ||
... | @@ -208,7 +208,7 @@ Pop3 :: rset () | ... | @@ -208,7 +208,7 @@ Pop3 :: rset () |
208 | } | 208 | } |
209 | 209 | ||
210 | void | 210 | void |
211 | Pop3 :: stat (unsigned int* count, size_t* octets) | 211 | Pop3 :: stat (unsigned int* count, mu_off_t* octets) |
212 | { | 212 | { |
213 | int status = mu_pop3_stat (pop3, count, octets); | 213 | int status = mu_pop3_stat (pop3, count, octets); |
214 | if (status) | 214 | if (status) |
... | @@ -264,22 +264,18 @@ Pop3 :: user (const char* user) | ... | @@ -264,22 +264,18 @@ Pop3 :: user (const char* user) |
264 | throw Exception ("Pop3::user", status); | 264 | throw Exception ("Pop3::user", status); |
265 | } | 265 | } |
266 | 266 | ||
267 | size_t | 267 | void |
268 | Pop3 :: readline (char* buf, size_t buflen) | 268 | Pop3 :: getline () |
269 | { | 269 | { |
270 | size_t nread; | 270 | int status = mu_pop3_getline (pop3); |
271 | |||
272 | int status = mu_pop3_readline (pop3, buf, buflen, &nread); | ||
273 | if (status) | 271 | if (status) |
274 | throw Exception ("Pop3::readline", status); | 272 | throw Exception ("Pop3::getline", status); |
275 | } | 273 | } |
276 | 274 | ||
277 | size_t | 275 | void |
278 | Pop3 :: response (char* buf, size_t buflen) | 276 | Pop3 :: response (size_t* nread) |
279 | { | 277 | { |
280 | size_t nread; | 278 | int status = mu_pop3_response (pop3, nread); |
281 | |||
282 | int status = mu_pop3_response (pop3, buf, buflen, &nread); | ||
283 | if (status) | 279 | if (status) |
284 | throw Exception ("Pop3::response", status); | 280 | throw Exception ("Pop3::response", status); |
285 | } | 281 | } |
... | @@ -292,11 +288,3 @@ Pop3 :: sendline (const char* line) | ... | @@ -292,11 +288,3 @@ Pop3 :: sendline (const char* line) |
292 | throw Exception ("Pop3::sendline", status); | 288 | throw Exception ("Pop3::sendline", status); |
293 | } | 289 | } |
294 | 290 | ||
295 | void | ||
296 | Pop3 :: send () | ||
297 | { | ||
298 | int status = mu_pop3_send (pop3); | ||
299 | if (status) | ||
300 | throw Exception ("Pop3::send", status); | ||
301 | } | ||
302 | ... | ... |
... | @@ -56,7 +56,7 @@ Stream :: ~Stream () | ... | @@ -56,7 +56,7 @@ Stream :: ~Stream () |
56 | { | 56 | { |
57 | close (); | 57 | close (); |
58 | if (this->stm) | 58 | if (this->stm) |
59 | mu_stream_destroy (&stm, NULL); | 59 | mu_stream_destroy (&stm); |
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
... | @@ -109,9 +109,9 @@ Stream :: wait (int flags) | ... | @@ -109,9 +109,9 @@ Stream :: wait (int flags) |
109 | } | 109 | } |
110 | 110 | ||
111 | int | 111 | int |
112 | Stream :: read (char* rbuf, size_t size, off_t offset) | 112 | Stream :: read (void* rbuf, size_t size) |
113 | { | 113 | { |
114 | int status = mu_stream_read (stm, rbuf, size, offset, &read_count); | 114 | int status = mu_stream_read (stm, rbuf, size, &read_count); |
115 | if (status == EAGAIN) | 115 | if (status == EAGAIN) |
116 | throw Stream::EAgain ("Stream::read", status); | 116 | throw Stream::EAgain ("Stream::read", status); |
117 | else if (status) | 117 | else if (status) |
... | @@ -120,10 +120,9 @@ Stream :: read (char* rbuf, size_t size, off_t offset) | ... | @@ -120,10 +120,9 @@ Stream :: read (char* rbuf, size_t size, off_t offset) |
120 | } | 120 | } |
121 | 121 | ||
122 | int | 122 | int |
123 | Stream :: write (const std::string& wbuf, size_t size, off_t offset) | 123 | Stream :: write (void* wbuf, size_t size) |
124 | { | 124 | { |
125 | int status = mu_stream_write (stm, wbuf.c_str (), size, offset, | 125 | int status = mu_stream_write (stm, wbuf, size, &write_count); |
126 | &write_count); | ||
127 | if (status == EAGAIN) | 126 | if (status == EAGAIN) |
128 | throw Stream::EAgain ("Stream::write", status); | 127 | throw Stream::EAgain ("Stream::write", status); |
129 | else if (status) | 128 | else if (status) |
... | @@ -132,30 +131,25 @@ Stream :: write (const std::string& wbuf, size_t size, off_t offset) | ... | @@ -132,30 +131,25 @@ Stream :: write (const std::string& wbuf, size_t size, off_t offset) |
132 | } | 131 | } |
133 | 132 | ||
134 | int | 133 | int |
135 | Stream :: readline (char* rbuf, size_t size, off_t offset) | 134 | Stream :: write (const std::string& wbuf, size_t size) |
136 | { | 135 | { |
137 | int status = mu_stream_readline (stm, rbuf, size, offset, &read_count); | 136 | int status = mu_stream_write (stm, wbuf.c_str (), size, &write_count); |
138 | if (status == EAGAIN) | 137 | if (status == EAGAIN) |
139 | throw Stream::EAgain ("Stream::readline", status); | 138 | throw Stream::EAgain ("Stream::write", status); |
140 | else if (status) | 139 | else if (status) |
141 | throw Exception ("Stream::readline", status); | 140 | throw Exception ("Stream::write", status); |
142 | return status; | 141 | return status; |
143 | } | 142 | } |
144 | 143 | ||
145 | void | 144 | int |
146 | Stream :: sequential_readline (char* rbuf, size_t size) | 145 | Stream :: readline (char* rbuf, size_t size) |
147 | { | ||
148 | int status = mu_stream_sequential_readline (stm, rbuf, size, &read_count); | ||
149 | if (status) | ||
150 | throw Exception ("Stream::sequential_readline", status); | ||
151 | } | ||
152 | |||
153 | void | ||
154 | Stream :: sequential_write (const std::string& wbuf, size_t size) | ||
155 | { | 146 | { |
156 | int status = mu_stream_sequential_write (stm, wbuf.c_str (), size); | 147 | int status = mu_stream_readline (stm, rbuf, size, &read_count); |
157 | if (status) | 148 | if (status == EAGAIN) |
158 | throw Exception ("Stream::sequential_write", status); | 149 | throw Stream::EAgain ("Stream::readline", status); |
150 | else if (status) | ||
151 | throw Exception ("Stream::readline", status); | ||
152 | return status; | ||
159 | } | 153 | } |
160 | 154 | ||
161 | void | 155 | void |
... | @@ -171,7 +165,7 @@ namespace mailutils | ... | @@ -171,7 +165,7 @@ namespace mailutils |
171 | Stream& | 165 | Stream& |
172 | operator << (Stream& stm, const std::string& wbuf) | 166 | operator << (Stream& stm, const std::string& wbuf) |
173 | { | 167 | { |
174 | stm.write (wbuf, wbuf.length (), 0); | 168 | stm.write (wbuf, wbuf.length ()); |
175 | return stm; | 169 | return stm; |
176 | } | 170 | } |
177 | 171 | ||
... | @@ -179,7 +173,7 @@ namespace mailutils | ... | @@ -179,7 +173,7 @@ namespace mailutils |
179 | operator >> (Stream& stm, std::string& rbuf) | 173 | operator >> (Stream& stm, std::string& rbuf) |
180 | { | 174 | { |
181 | char tmp[1024]; | 175 | char tmp[1024]; |
182 | stm.read (tmp, sizeof (tmp), 0); | 176 | stm.read (tmp, sizeof (tmp)); |
183 | rbuf = std::string (tmp); | 177 | rbuf = std::string (tmp); |
184 | return stm; | 178 | return stm; |
185 | } | 179 | } |
... | @@ -211,9 +205,9 @@ FileStream :: FileStream (const std::string& filename, int flags) | ... | @@ -211,9 +205,9 @@ FileStream :: FileStream (const std::string& filename, int flags) |
211 | // StdioStream | 205 | // StdioStream |
212 | // | 206 | // |
213 | 207 | ||
214 | StdioStream :: StdioStream (FILE* fp, int flags) | 208 | StdioStream :: StdioStream (int fd, int flags) |
215 | { | 209 | { |
216 | int status = mu_stdio_stream_create (&stm, fp, flags); | 210 | int status = mu_stdio_stream_create (&stm, fd, flags); |
217 | if (status) | 211 | if (status) |
218 | throw Exception ("StdioStream::StdioStream", status); | 212 | throw Exception ("StdioStream::StdioStream", status); |
219 | } | 213 | } | ... | ... |
-
Please register or sign in to post a comment