summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlain Magloire <alainm@gnu.org>2004-06-13 03:14:17 +0000
committerAlain Magloire <alainm@gnu.org>2004-06-13 03:14:17 +0000
commitff2d2fa501b16e9f3e4882caa6e920da5c71e535 (patch)
tree597616a7666a49827ea3a0ca628b6957e565a787
parentf50de094ab26e6e81438d056e31236e776e4dc65 (diff)
downloadmailutils-ff2d2fa501b16e9f3e4882caa6e920da5c71e535.tar.gz
mailutils-ff2d2fa501b16e9f3e4882caa6e920da5c71e535.tar.bz2
nntp.h sys/nntp.h
Framework for NNTP.
-rw-r--r--include/mailutils/nntp.h88
-rw-r--r--include/mailutils/sys/nntp.h138
2 files changed, 226 insertions, 0 deletions
diff --git a/include/mailutils/nntp.h b/include/mailutils/nntp.h
new file mode 100644
index 000000000..b617dde28
--- /dev/null
+++ b/include/mailutils/nntp.h
@@ -0,0 +1,88 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2004 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef _MAILUTILS_NNTP_H
+#define _MAILUTILS_NNTP_H
+
+#include <mailutils/debug.h>
+#include <mailutils/stream.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct _mu_nntp;
+typedef struct _mu_nntp* mu_nntp_t;
+
+extern int mu_nntp_create (mu_nntp_t *nntp);
+extern void mu_nntp_destroy (mu_nntp_t *nntp);
+
+extern int mu_nntp_set_carrier (mu_nntp_t nntp, stream_t carrier);
+extern int mu_nntp_get_carrier (mu_nntp_t nntp, stream_t *pcarrier);
+
+extern int mu_nntp_connect (mu_nntp_t nntp);
+extern int mu_nntp_disconnect (mu_nntp_t nntp);
+
+extern int mu_nntp_set_timeout (mu_nntp_t nntp, int timeout);
+extern int mu_nntp_get_timeout (mu_nntp_t nntp, int *timeout);
+
+extern int mu_nntp_set_debug (mu_nntp_t nntp, mu_debug_t debug);
+
+extern int mu_nntp_stls (mu_nntp_t nntp);
+
+
+extern int mu_nntp_article (mu_nntp_t nntp, long num, stream_t *stream);
+extern int mu_nntp_article_id (mu_nntp_t nntp, const char *id, stream_t *stream);
+
+extern int mu_nntp_header (mu_nntp_t nntp, long num, stream_t *stream);
+extern int mu_nntp_header_id (mu_nntp_t nntp, const char *name, stream_t *stream);
+
+extern int mu_nntp_body (mu_nntp_t nntp, long num, stream_t *stream);
+extern int mu_nntp_body_id (mu_nntp_t nntp, const char *name, stream_t *stream);
+
+extern int mu_nntp_stat (mu_nntp_t nntp, long num, char **id);
+extern int mu_nntp_stat_id (mu_nntp_t nntp, const char *name, char **id);
+
+extern int mu_nntp_group (mu_nntp_t nntp, const char *group, long *total, long *first, long *last, char **name);
+
+
+/* Reads the multi-line response of the server, nread will be 0 when the termination octets
+ are detected. Clients should not use this function unless they are sending direct command. */
+extern int mu_nntp_readline (mu_nntp_t nntp, char *buffer, size_t buflen, size_t *nread);
+
+/* Returns the last command acknowledge. If the server supports RESP-CODE, the message
+ could be retrieve, but it is up the caller to do the parsing. */
+extern int mu_nntp_response (mu_nntp_t nntp, char *buffer, size_t buflen, size_t *nread);
+
+/* pop3_writeline copies the line in the internal buffer, a mu_pop3_send() is
+ needed to do the actual transmission. */
+extern int mu_nntp_writeline (mu_nntp_t nntp, const char *format, ...);
+
+/* mu_pop3_sendline() is equivalent to:
+ mu_pop3_writeline (pop3, line);
+ mu_pop3_send (pop3);
+ */
+extern int mu_nntp_sendline (mu_nntp_t nntp, const char *line);
+
+/* Transmit via the carrier the internal buffer data. */
+extern int mu_nntp_send (mu_nntp_t nntp);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MAILUTILS_POP3_H */
diff --git a/include/mailutils/sys/nntp.h b/include/mailutils/sys/nntp.h
new file mode 100644
index 000000000..6f200d9f5
--- /dev/null
+++ b/include/mailutils/sys/nntp.h
@@ -0,0 +1,138 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2004 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef _MAILUTILS_SYS_NNTP_H
+#define _MAILUTILS_SYS_NNTP_H
+
+#include <sys/types.h>
+#include <mailutils/nntp.h>
+#include <mailutils/errno.h>
+
+#ifdef DMALLOC
+# include <dmalloc.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum mu_nntp_state
+ {
+ MU_NNTP_NO_STATE,
+ MU_NNTP_CONNECT, MU_NNTP_GREETINGS,
+ MU_NNTP_ARTICLE, MU_NNTP_ARTICLE_ACK, MU_NNTP_ARTICLE_RX,
+ MU_NNTP_HEADER, MU_NNTP_HEADER_ACK, MU_NNTP_HEADER_RX,
+ MU_NNTP_BODY, MU_NNTP_BODY_ACK, MU_NNTP_BODY_RX,
+ MU_NNTP_STAT, MU_NNTP_STAT_ACK,
+ MU_NNTP_STLS, MU_NNTP_STLS_ACK, MU_NNTP_STLS_CONNECT,
+ MU_NNTP_DONE, MU_NNTP_UNKNOWN, MU_NNTP_ERROR
+ };
+
+/* Structure holding the data necessary to do proper buffering. */
+struct mu_nntp_work_buf
+ {
+ char *buf;
+ char *ptr;
+ char *nl;
+ size_t len;
+ };
+
+/* Structure to hold things general to nntp connection, like its state, etc ... */
+struct _mu_nntp
+ {
+ /* Working I/O buffer.
+ io.buf: Working io buffer
+ io.ptr: Points to the end of the buffer, the non consumed chars
+ io.nl: Points to the '\n' char in the string
+ io.len: Len of io_buf. */
+ struct mu_nntp_work_buf io;
+
+ /* Holds the first line response of the last command, i.e the ACK:
+ ack.buf: Buffer for the ack
+ ack.ptr: Working pointer, indicate the start of the non consumed chars
+ ack.len: Size 512 according to RFC2449. */
+ struct mu_nntp_work_buf ack;
+ int acknowledge;
+
+ unsigned timeout; /* Default is 10 minutes. */
+
+ mu_debug_t debug; /* debugging trace. */
+
+ enum mu_nntp_state state; /* Indicate the state of the running command. */
+
+ stream_t carrier; /* TCP Connection. */
+ };
+
+extern int mu_nntp_debug_cmd (mu_nntp_t);
+extern int mu_nntp_debug_ack (mu_nntp_t);
+extern int mu_nntp_stream_create (mu_nntp_t pop3, stream_t *pstream);
+extern int mu_nntp_carrier_is_ready (stream_t carrier, int flag, int timeout);
+
+/* Check for non recoverable error.
+ The error is consider not recoverable if not part of the signal set:
+ EAGAIN, EINPROGRESS, EINTR.
+ For unrecoverable error we reset, by moving the working ptr
+ to the begining of the buffer and setting the state to error.
+ */
+#define MU_NNTP_CHECK_EAGAIN(nntp, status) \
+do \
+ { \
+ if (status != 0) \
+ { \
+ if (status != EAGAIN && status != EINPROGRESS && status != EINTR) \
+ { \
+ nntp->io.ptr = nntp->io.buf; \
+ nntp->state = MU_NNTP_ERROR; \
+ } \
+ return status; \
+ } \
+ } \
+while (0)
+
+/* If error return.
+ Check status an reset(see MU_NNTP_CHECK_EAGAIN) the buffer.
+ */
+#define MU_NNTP_CHECK_ERROR(nntp, status) \
+do \
+ { \
+ if (status != 0) \
+ { \
+ nntp->io.ptr = nntp->io.buf; \
+ nntp->state = MU_NNTP_ERROR; \
+ return status; \
+ } \
+ } \
+while (0)
+
+/* Check if we got "2xx". In NNTP protocol and ack of "2xx" means the command was successfull.
+ */
+#define MU_NNTP_CHECK_COMPLETE(nntp) \
+do \
+ { \
+ if (nntp->ack.buf[0] == '2') != 0) \
+ { \
+ nntp->state = MU_NNTP_NO_STATE; \
+ return EACCES; \
+ } \
+ } \
+while (0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MAILUTILS_SYS_NNTP_H */

Return to:

Send suggestions and report system problems to the System administrator.