summaryrefslogtreecommitdiff
path: root/include
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 /include
parentf50de094ab26e6e81438d056e31236e776e4dc65 (diff)
downloadmailutils-ff2d2fa501b16e9f3e4882caa6e920da5c71e535.tar.gz
mailutils-ff2d2fa501b16e9f3e4882caa6e920da5c71e535.tar.bz2
nntp.h sys/nntp.h
Framework for NNTP.
Diffstat (limited to 'include')
-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 @@
1/* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2004 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
18#ifndef _MAILUTILS_NNTP_H
19#define _MAILUTILS_NNTP_H
20
21#include <mailutils/debug.h>
22#include <mailutils/stream.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28struct _mu_nntp;
29typedef struct _mu_nntp* mu_nntp_t;
30
31extern int mu_nntp_create (mu_nntp_t *nntp);
32extern void mu_nntp_destroy (mu_nntp_t *nntp);
33
34extern int mu_nntp_set_carrier (mu_nntp_t nntp, stream_t carrier);
35extern int mu_nntp_get_carrier (mu_nntp_t nntp, stream_t *pcarrier);
36
37extern int mu_nntp_connect (mu_nntp_t nntp);
38extern int mu_nntp_disconnect (mu_nntp_t nntp);
39
40extern int mu_nntp_set_timeout (mu_nntp_t nntp, int timeout);
41extern int mu_nntp_get_timeout (mu_nntp_t nntp, int *timeout);
42
43extern int mu_nntp_set_debug (mu_nntp_t nntp, mu_debug_t debug);
44
45extern int mu_nntp_stls (mu_nntp_t nntp);
46
47
48extern int mu_nntp_article (mu_nntp_t nntp, long num, stream_t *stream);
49extern int mu_nntp_article_id (mu_nntp_t nntp, const char *id, stream_t *stream);
50
51extern int mu_nntp_header (mu_nntp_t nntp, long num, stream_t *stream);
52extern int mu_nntp_header_id (mu_nntp_t nntp, const char *name, stream_t *stream);
53
54extern int mu_nntp_body (mu_nntp_t nntp, long num, stream_t *stream);
55extern int mu_nntp_body_id (mu_nntp_t nntp, const char *name, stream_t *stream);
56
57extern int mu_nntp_stat (mu_nntp_t nntp, long num, char **id);
58extern int mu_nntp_stat_id (mu_nntp_t nntp, const char *name, char **id);
59
60extern int mu_nntp_group (mu_nntp_t nntp, const char *group, long *total, long *first, long *last, char **name);
61
62
63/* Reads the multi-line response of the server, nread will be 0 when the termination octets
64 are detected. Clients should not use this function unless they are sending direct command. */
65extern int mu_nntp_readline (mu_nntp_t nntp, char *buffer, size_t buflen, size_t *nread);
66
67/* Returns the last command acknowledge. If the server supports RESP-CODE, the message
68 could be retrieve, but it is up the caller to do the parsing. */
69extern int mu_nntp_response (mu_nntp_t nntp, char *buffer, size_t buflen, size_t *nread);
70
71/* pop3_writeline copies the line in the internal buffer, a mu_pop3_send() is
72 needed to do the actual transmission. */
73extern int mu_nntp_writeline (mu_nntp_t nntp, const char *format, ...);
74
75/* mu_pop3_sendline() is equivalent to:
76 mu_pop3_writeline (pop3, line);
77 mu_pop3_send (pop3);
78 */
79extern int mu_nntp_sendline (mu_nntp_t nntp, const char *line);
80
81/* Transmit via the carrier the internal buffer data. */
82extern int mu_nntp_send (mu_nntp_t nntp);
83
84#ifdef __cplusplus
85}
86#endif
87
88#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 @@
1/* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 2004 Free Software Foundation, Inc.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
18#ifndef _MAILUTILS_SYS_NNTP_H
19#define _MAILUTILS_SYS_NNTP_H
20
21#include <sys/types.h>
22#include <mailutils/nntp.h>
23#include <mailutils/errno.h>
24
25#ifdef DMALLOC
26# include <dmalloc.h>
27#endif
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33enum mu_nntp_state
34 {
35 MU_NNTP_NO_STATE,
36 MU_NNTP_CONNECT, MU_NNTP_GREETINGS,
37 MU_NNTP_ARTICLE, MU_NNTP_ARTICLE_ACK, MU_NNTP_ARTICLE_RX,
38 MU_NNTP_HEADER, MU_NNTP_HEADER_ACK, MU_NNTP_HEADER_RX,
39 MU_NNTP_BODY, MU_NNTP_BODY_ACK, MU_NNTP_BODY_RX,
40 MU_NNTP_STAT, MU_NNTP_STAT_ACK,
41 MU_NNTP_STLS, MU_NNTP_STLS_ACK, MU_NNTP_STLS_CONNECT,
42 MU_NNTP_DONE, MU_NNTP_UNKNOWN, MU_NNTP_ERROR
43 };
44
45/* Structure holding the data necessary to do proper buffering. */
46struct mu_nntp_work_buf
47 {
48 char *buf;
49 char *ptr;
50 char *nl;
51 size_t len;
52 };
53
54/* Structure to hold things general to nntp connection, like its state, etc ... */
55struct _mu_nntp
56 {
57 /* Working I/O buffer.
58 io.buf: Working io buffer
59 io.ptr: Points to the end of the buffer, the non consumed chars
60 io.nl: Points to the '\n' char in the string
61 io.len: Len of io_buf. */
62 struct mu_nntp_work_buf io;
63
64 /* Holds the first line response of the last command, i.e the ACK:
65 ack.buf: Buffer for the ack
66 ack.ptr: Working pointer, indicate the start of the non consumed chars
67 ack.len: Size 512 according to RFC2449. */
68 struct mu_nntp_work_buf ack;
69 int acknowledge;
70
71 unsigned timeout; /* Default is 10 minutes. */
72
73 mu_debug_t debug; /* debugging trace. */
74
75 enum mu_nntp_state state; /* Indicate the state of the running command. */
76
77 stream_t carrier; /* TCP Connection. */
78 };
79
80extern int mu_nntp_debug_cmd (mu_nntp_t);
81extern int mu_nntp_debug_ack (mu_nntp_t);
82extern int mu_nntp_stream_create (mu_nntp_t pop3, stream_t *pstream);
83extern int mu_nntp_carrier_is_ready (stream_t carrier, int flag, int timeout);
84
85/* Check for non recoverable error.
86 The error is consider not recoverable if not part of the signal set:
87 EAGAIN, EINPROGRESS, EINTR.
88 For unrecoverable error we reset, by moving the working ptr
89 to the begining of the buffer and setting the state to error.
90 */
91#define MU_NNTP_CHECK_EAGAIN(nntp, status) \
92do \
93 { \
94 if (status != 0) \
95 { \
96 if (status != EAGAIN && status != EINPROGRESS && status != EINTR) \
97 { \
98 nntp->io.ptr = nntp->io.buf; \
99 nntp->state = MU_NNTP_ERROR; \
100 } \
101 return status; \
102 } \
103 } \
104while (0)
105
106/* If error return.
107 Check status an reset(see MU_NNTP_CHECK_EAGAIN) the buffer.
108 */
109#define MU_NNTP_CHECK_ERROR(nntp, status) \
110do \
111 { \
112 if (status != 0) \
113 { \
114 nntp->io.ptr = nntp->io.buf; \
115 nntp->state = MU_NNTP_ERROR; \
116 return status; \
117 } \
118 } \
119while (0)
120
121/* Check if we got "2xx". In NNTP protocol and ack of "2xx" means the command was successfull.
122 */
123#define MU_NNTP_CHECK_COMPLETE(nntp) \
124do \
125 { \
126 if (nntp->ack.buf[0] == '2') != 0) \
127 { \
128 nntp->state = MU_NNTP_NO_STATE; \
129 return EACCES; \
130 } \
131 } \