Commit 5984fc0c 5984fc0cd9f8841e574991ba8155cb1448389af3 by Wojciech Polak

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.
1 parent 89ea7423
......@@ -39,7 +39,7 @@ main (int argc, char **argv)
}
try {
StdioStream *in = new StdioStream (stdin, 0);
StdioStream *in = new StdioStream (MU_STDIN_FD, 0);
in->open ();
FilterIconvStream cvt (*in, (string)argv[1], (string)argv[2], 0,
......@@ -47,12 +47,12 @@ main (int argc, char **argv)
cvt.open ();
delete in;
StdioStream out (stdout, 0);
StdioStream out (MU_STDOUT_FD, 0);
out.open ();
do {
cvt.read (buffer, sizeof (buffer), total);
out.sequential_write (buffer, cvt.get_read_count ());
cvt.read (buffer, sizeof (buffer));
out.write (buffer, cvt.get_read_count ());
total += cvt.get_read_count ();
} while (cvt.get_read_count ());
......
......@@ -187,14 +187,12 @@ message_display_parts (Message& msg, int indent)
Stream stream = body.get_stream ();
FilterStream filter (stream, encoding, 0, 0);
int offset = 0;
char buf[2048];
while (filter.readline (buf, sizeof (buf), offset) == 0 &&
while (filter.readline (buf, sizeof (buf)) == 0 &&
filter.get_read_count ())
{
cout << setw (indent) << setfill (' ') << buf;
offset += filter.get_read_count ();
}
}
else
......
......@@ -88,7 +88,7 @@ main (int argc, char *argv[])
}
try {
StdioStream in (stdin, MU_STREAM_SEEK);
StdioStream in (MU_STDIN_FD, MU_STREAM_SEEK);
in.open ();
Message msg;
......
......@@ -33,11 +33,11 @@ read_and_print (Stream *in, Stream& out)
{
char buffer[128];
in->sequential_readline (buffer, sizeof (buffer));
in->readline (buffer, sizeof (buffer));
while (in->get_read_count ())
{
out.sequential_write (buffer, in->get_read_count ());
in->sequential_readline (buffer, sizeof (buffer));
out.write (buffer, in->get_read_count ());
in->readline (buffer, sizeof (buffer));
}
}
......@@ -47,7 +47,7 @@ create_filter (bool read_stdin, char *cmdline, int flags)
try {
if (read_stdin)
{
StdioStream *in = new StdioStream (stdin, 0);
StdioStream *in = new StdioStream (MU_STDIN_FD, 0);
in->open ();
FilterProgStream *stream = new FilterProgStream (cmdline, in);
stream->open ();
......@@ -96,7 +96,7 @@ main (int argc, char *argv[])
stream = create_filter (read_stdin, cmdline, flags);
try {
StdioStream out (stdout, 0);
StdioStream out (MU_STDOUT_FD, 0);
out.open ();
read_and_print (stream, out);
......
......@@ -51,7 +51,7 @@ class Pop3
void apop (const char* name, const char* digest);
void stls ();
Iterator& capa ();
Iterator& capa (bool reread);
void dele (unsigned int msgno);
size_t list (unsigned int msgno);
Iterator& list_all ();
......@@ -60,16 +60,15 @@ class Pop3
void quit ();
Stream& retr (unsigned int msgno);
void rset ();
void stat (unsigned int* count, size_t* octets);
void stat (unsigned int* count, mu_off_t* octets);
Stream& top (unsigned int msgno, unsigned int lines);
std::string uidl (unsigned int msgno);
Iterator& uidl_all ();
void user (const char* user);
size_t readline (char* buf, size_t buflen);
size_t response (char* buf, size_t buflen);
void getline ();
void response (size_t* nread);
void sendline (const char* line);
void send ();
};
}
......
......@@ -68,11 +68,10 @@ class Stream
void set_waitflags (int flags);
void wait (); // timeval is missing
void wait (int flags); // timeval is missing
int read (char* rbuf, size_t size, off_t offset);
int write (const std::string& wbuf, size_t size, off_t offset);
int readline (char* rbuf, size_t size, off_t offset);
void sequential_readline (char* rbuf, size_t size);
void sequential_write (const std::string& wbuf, size_t size);
int read (void* rbuf, size_t size);
int write (void* wbuf, size_t size);
int write (const std::string& wbuf, size_t size);
int readline (char* rbuf, size_t size);
void flush ();
// Inlines
......@@ -108,7 +107,7 @@ class FileStream : public Stream
class StdioStream : public Stream
{
public:
StdioStream (FILE*, int);
StdioStream (int fd, int flags);
};
class ProgStream : public Stream
......
......@@ -120,11 +120,11 @@ Pop3 :: stls ()
}
Iterator&
Pop3 :: capa ()
Pop3 :: capa (bool reread = false)
{
mu_iterator_t mu_itr;
int status = mu_pop3_capa (pop3, &mu_itr);
int status = mu_pop3_capa (pop3, reread, &mu_itr);
if (status)
throw Exception ("Pop3::capa", status);
......@@ -208,7 +208,7 @@ Pop3 :: rset ()
}
void
Pop3 :: stat (unsigned int* count, size_t* octets)
Pop3 :: stat (unsigned int* count, mu_off_t* octets)
{
int status = mu_pop3_stat (pop3, count, octets);
if (status)
......@@ -264,22 +264,18 @@ Pop3 :: user (const char* user)
throw Exception ("Pop3::user", status);
}
size_t
Pop3 :: readline (char* buf, size_t buflen)
void
Pop3 :: getline ()
{
size_t nread;
int status = mu_pop3_readline (pop3, buf, buflen, &nread);
int status = mu_pop3_getline (pop3);
if (status)
throw Exception ("Pop3::readline", status);
throw Exception ("Pop3::getline", status);
}
size_t
Pop3 :: response (char* buf, size_t buflen)
void
Pop3 :: response (size_t* nread)
{
size_t nread;
int status = mu_pop3_response (pop3, buf, buflen, &nread);
int status = mu_pop3_response (pop3, nread);
if (status)
throw Exception ("Pop3::response", status);
}
......@@ -292,11 +288,3 @@ Pop3 :: sendline (const char* line)
throw Exception ("Pop3::sendline", status);
}
void
Pop3 :: send ()
{
int status = mu_pop3_send (pop3);
if (status)
throw Exception ("Pop3::send", status);
}
......
......@@ -56,7 +56,7 @@ Stream :: ~Stream ()
{
close ();
if (this->stm)
mu_stream_destroy (&stm, NULL);
mu_stream_destroy (&stm);
}
}
......@@ -109,9 +109,9 @@ Stream :: wait (int flags)
}
int
Stream :: read (char* rbuf, size_t size, off_t offset)
Stream :: read (void* rbuf, size_t size)
{
int status = mu_stream_read (stm, rbuf, size, offset, &read_count);
int status = mu_stream_read (stm, rbuf, size, &read_count);
if (status == EAGAIN)
throw Stream::EAgain ("Stream::read", status);
else if (status)
......@@ -120,10 +120,9 @@ Stream :: read (char* rbuf, size_t size, off_t offset)
}
int
Stream :: write (const std::string& wbuf, size_t size, off_t offset)
Stream :: write (void* wbuf, size_t size)
{
int status = mu_stream_write (stm, wbuf.c_str (), size, offset,
&write_count);
int status = mu_stream_write (stm, wbuf, size, &write_count);
if (status == EAGAIN)
throw Stream::EAgain ("Stream::write", status);
else if (status)
......@@ -132,30 +131,25 @@ Stream :: write (const std::string& wbuf, size_t size, off_t offset)
}
int
Stream :: readline (char* rbuf, size_t size, off_t offset)
Stream :: write (const std::string& wbuf, size_t size)
{
int status = mu_stream_readline (stm, rbuf, size, offset, &read_count);
int status = mu_stream_write (stm, wbuf.c_str (), size, &write_count);
if (status == EAGAIN)
throw Stream::EAgain ("Stream::readline", status);
throw Stream::EAgain ("Stream::write", status);
else if (status)
throw Exception ("Stream::readline", status);
throw Exception ("Stream::write", status);
return status;
}
void
Stream :: sequential_readline (char* rbuf, size_t size)
{
int status = mu_stream_sequential_readline (stm, rbuf, size, &read_count);
if (status)
throw Exception ("Stream::sequential_readline", status);
}
void
Stream :: sequential_write (const std::string& wbuf, size_t size)
int
Stream :: readline (char* rbuf, size_t size)
{
int status = mu_stream_sequential_write (stm, wbuf.c_str (), size);
if (status)
throw Exception ("Stream::sequential_write", status);
int status = mu_stream_readline (stm, rbuf, size, &read_count);
if (status == EAGAIN)
throw Stream::EAgain ("Stream::readline", status);
else if (status)
throw Exception ("Stream::readline", status);
return status;
}
void
......@@ -171,7 +165,7 @@ namespace mailutils
Stream&
operator << (Stream& stm, const std::string& wbuf)
{
stm.write (wbuf, wbuf.length (), 0);
stm.write (wbuf, wbuf.length ());
return stm;
}
......@@ -179,7 +173,7 @@ namespace mailutils
operator >> (Stream& stm, std::string& rbuf)
{
char tmp[1024];
stm.read (tmp, sizeof (tmp), 0);
stm.read (tmp, sizeof (tmp));
rbuf = std::string (tmp);
return stm;
}
......@@ -211,9 +205,9 @@ FileStream :: FileStream (const std::string& filename, int flags)
// StdioStream
//
StdioStream :: StdioStream (FILE* fp, int flags)
StdioStream :: StdioStream (int fd, int flags)
{
int status = mu_stdio_stream_create (&stm, fp, flags);
int status = mu_stdio_stream_create (&stm, fd, flags);
if (status)
throw Exception ("StdioStream::StdioStream", status);
}
......