Commit beee5d8f beee5d8f2df6c274f7cc88c29ff47290282c2499 by Alain Magloire

Makefile.am nntp_head.c nntp_article.c nntp_body.c

added ARTICLE HEAD and BODY
1 parent 51cb98a7
1 ## Process this file with GNU Automake to create Makefile.in
2
3 ## Copyright (C) 2004 Free Software Foundation, Inc.
4 ##
5 ## GNU Mailutils is free software; you can redistribute it and/or
6 ## modify it under the terms of the GNU General Public License as
7 ## published by the Free Software Foundation; either version 2, or (at
8 ## your option) any later version.
9 ##
10 ## This program is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program; if not, write to the Free Software
17 ## Foundation, Inc.
18 ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 INCLUDES = -I${top_srcdir}/include -I${top_srcdir}/mailbox \
21 -I${top_srcdir}/mailbox/include -I${top_builddir}/include/mailutils/gnu \
22 @INTLINCS@
23
24 lib_LTLIBRARIES = libmu_nntp.la
25
26 libmu_nntp_la_SOURCES = \
27 nntp_carrier.c \
28 nntp_connect.c \
29 nntp_create.c \
30 nntp_debug.c \
31 nntp_destroy.c \
32 nntp_disconnect.c \
33 nntp_readline.c \
34 nntp_response.c \
35 nntp_sendline.c \
36 nntp_stream.c \
37 nntp_timeout.c \
38 nntp_article.c \
39 nntp_head.c \
40 nntp_body.c
41
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 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 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <string.h>
23 #include <errno.h>
24 #include <mailutils/sys/nntp.h>
25
26 int
27 mu_nntp_article (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid, stream_t *pstream)
28 {
29 int status;
30 char *message_id = NULL;
31 if (number != 0)
32 {
33 message_id = malloc(128);
34 if (message_id == NULL)
35 {
36 return ENOMEM;
37 }
38 snprintf(message_id, 127, "%d", number);
39 }
40 status = mu_nntp_article_id (nntp, message_id, pnum, mid, pstream);
41 if (message_id)
42 {
43 free (message_id);
44 }
45 return status;
46 }
47
48 int
49 mu_nntp_article_id (mu_nntp_t nntp, const char *message_id, unsigned long *pnum, char **mid, stream_t *pstream)
50 {
51 int status;
52 unsigned long dummy = 0;
53 char *buf;
54
55 if (nntp == NULL)
56 return EINVAL;
57 if (pstream == NULL)
58 return MU_ERR_OUT_PTR_NULL;
59
60 switch (nntp->state)
61 {
62 case MU_NNTP_NO_STATE:
63 if (message_id == NULL || *message_id == '\0')
64 {
65 status = mu_nntp_writeline (nntp, "ARTICLE\r\n");
66 }
67 else
68 {
69 status = mu_nntp_writeline (nntp, "ARTICLE %s\r\n", message_id);
70 }
71 MU_NNTP_CHECK_ERROR (nntp, status);
72 mu_NNTP_debug_cmd (nntp);
73 nntp->state = MU_NNTP_ARTICLE;
74
75 case MU_NNTP_ARTICLE:
76 status = mu_nntp_send (nntp);
77 MU_NNTP_CHECK_EAGAIN (nntp, status);
78 nntp->acknowledge = 0;
79 nntp->state = MU_NNTP_ARTICLE_ACK;
80
81 case MU_NNTP_ARTICLE_ACK:
82 status = mu_nntp_response (nntp, NULL, 0, NULL);
83 MU_NNTP_CHECK_EAGAIN (nntp, status);
84 mu_nntp_debug_ack (nntp);
85 MU_NNTP_CHECK_OK (nntp);
86 nntp->state = MU_NNTP_ARTICLE_RX;
87 /* parse the answer now. */
88 if (pnum == NULL)
89 {
90 pnum = &dummy;
91 }
92 buf = calloc(sizeof(*buf), 128);
93 if (buf == NULL)
94 {
95 return ENOMEM;
96 }
97 sscanf (nntp->ack.buf, "220 %d %127s", pnum, buf);
98 if (*buf == '\0')
99 {
100 strcpy (buf, "<0>");
101 }
102 if (mid)
103 {
104 *mid = buf;
105 }
106 else
107 {
108 free (buf);
109 }
110
111 case MU_NNTP_ARTICLE_RX:
112 status = mu_nntp_stream_create (nntp, pstream);
113 MU_NNTP_CHECK_ERROR (nntp, status);
114 break;
115
116 /* They must deal with the error first by reopening. */
117 case MU_NNTP_ERROR:
118 status = ECANCELED;
119 break;
120
121 default:
122 status = EINPROGRESS;
123 }
124
125 return status;
126 }
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 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 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <string.h>
23 #include <errno.h>
24 #include <mailutils/sys/nntp.h>
25
26 int
27 mu_nntp_body (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid, stream_t *pstream)
28 {
29 int status;
30 char *message_id = NULL;
31 if (number != 0)
32 {
33 message_id = malloc(128);
34 if (message_id == NULL)
35 {
36 return ENOMEM;
37 }
38 snprintf (message_id, 127, "%d", number);
39 }
40 status = mu_nntp_body_id (nntp, message_id, pnum, mid, pstream);
41 if (message_id)
42 {
43 free (message_id);
44 }
45 return status;
46 }
47
48 int
49 mu_nntp_body_id (mu_nntp_t nntp, const char *message_id, unsigned long *pnum, char **mid, stream_t *pstream)
50 {
51 int status;
52 unsigned long dummy = 0;
53 char *buf;
54
55 if (nntp == NULL)
56 return EINVAL;
57 if (pstream == NULL)
58 return MU_ERR_OUT_PTR_NULL;
59
60 switch (nntp->state)
61 {
62 case MU_NNTP_NO_STATE:
63 if (message_id == 0 || *message_id == '\0')
64 {
65 status = mu_nntp_writeline (nntp, "BODY\r\n");
66 }
67 else
68 {
69 status = mu_nntp_writeline (nntp, "BODY %s\r\n", message_id);
70 }
71 MU_NNTP_CHECK_ERROR (nntp, status);
72 mu_NNTP_debug_cmd (nntp);
73 nntp->state = MU_NNTP_BODY;
74
75 case MU_NNTP_BODY:
76 status = mu_nntp_send (nntp);
77 MU_NNTP_CHECK_EAGAIN (nntp, status);
78 nntp->acknowledge = 0;
79 nntp->state = MU_NNTP_BODY_ACK;
80
81 case MU_NNTP_BODY_ACK:
82 status = mu_nntp_response (nntp, NULL, 0, NULL);
83 MU_NNTP_CHECK_EAGAIN (nntp, status);
84 mu_nntp_debug_ack (nntp);
85 MU_NNTP_CHECK_OK (nntp);
86 nntp->state = MU_NNTP_BODY_RX;
87 /* parse the answer now. */
88 if (pnum == NULL)
89 {
90 pnum = &dummy;
91 }
92 buf = calloc(1, 128);
93 if (buf == NULL)
94 {
95 return ENOMEM;
96 }
97 sscanf (nntp->ack.buf, "222 %d %127s", pnum, buf);
98 if (*buf == '\0')
99 {
100 strcpy (buf, "<0>");
101 }
102 if (mid)
103 {
104 *mid = buf;
105 }
106 else
107 {
108 free (buf);
109 }
110
111 case MU_NNTP_BODY_RX:
112 status = mu_nntp_stream_create (nntp, pstream);
113 MU_NNTP_CHECK_ERROR (nntp, status);
114 break;
115
116 /* They must deal with the error first by reopening. */
117 case MU_NNTP_ERROR:
118 status = ECANCELED;
119 break;
120
121 default:
122 status = EINPROGRESS;
123 }
124
125 return status;
126 }
1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001, 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 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <string.h>
23 #include <errno.h>
24 #include <mailutils/sys/nntp.h>
25
26 int
27 mu_nntp_head (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid, stream_t *pstream)
28 {
29 int status;
30 char *message_id = NULL;
31 if (number != 0)
32 {
33 message_id = malloc (128);
34 if (message_id == NULL)
35 {
36 return ENOMEM;
37 }
38 snprintf (message_id, 127, "%d", number);
39 }
40 status = mu_nntp_head_id (nntp, message_id, pnum, mid, pstream);
41 if (message_id)
42 {
43 free (message_id);
44 }
45 return status;
46 }
47
48 int
49 mu_nntp_head_id (mu_nntp_t nntp, const char *message_id, unsigned long *pnum, char **mid, stream_t *pstream)
50 {
51 int status;
52 unsigned long dummy = 0;
53 char *buf;
54
55 if (nntp == NULL)
56 return EINVAL;
57 if (pstream == NULL)
58 return MU_ERR_OUT_PTR_NULL;
59
60 switch (nntp->state)
61 {
62 case MU_NNTP_NO_STATE:
63 if (message_id == NULL || *message_id == '\0')
64 {
65 status = mu_nntp_writeline (nntp, "HEAD\r\n");
66 }
67 else
68 {
69 status = mu_nntp_writeline (nntp, "HEAD %s\r\n", message_id);
70 }
71 MU_NNTP_CHECK_ERROR (nntp, status);
72 mu_NNTP_debug_cmd (nntp);
73 nntp->state = MU_NNTP_HEAD;
74
75 case MU_NNTP_HEAD:
76 status = mu_nntp_send (nntp);
77 MU_NNTP_CHECK_EAGAIN (nntp, status);
78 nntp->acknowledge = 0;
79 nntp->state = MU_NNTP_HEAD_ACK;
80
81 case MU_NNTP_HEAD_ACK:
82 status = mu_nntp_response (nntp, NULL, 0, NULL);
83 MU_NNTP_CHECK_EAGAIN (nntp, status);
84 mu_nntp_debug_ack (nntp);
85 MU_NNTP_CHECK_OK (nntp);
86 nntp->state = MU_NNTP_HEAD_RX;
87 /* parse the answer now. */
88 if (pnum == NULL)
89 {
90 pnum = &dummy;
91 }
92 buf = calloc(sizeof(*buf), 128);
93 if (buf == NULL)
94 {
95 return ENOMEM;
96 }
97 sscanf (nntp->ack.buf, "221 %d %127s", pnum, buf);
98 if (*buf == '\0')
99 {
100 strcpy(buf, "<0>");
101 }
102 if (mid)
103 {
104 *mid = buf;
105 }
106 else
107 {
108 free (buf);
109 }
110
111 case MU_NNTP_HEAD_RX:
112 status = mu_nntp_stream_create (nntp, pstream);
113 MU_NNTP_CHECK_ERROR (nntp, status);
114 break;
115
116 /* They must deal with the error first by reopening. */
117 case MU_NNTP_ERROR:
118 status = ECANCELED;
119 break;
120
121 default:
122 status = EINPROGRESS;
123 }
124
125 return status;
126 }