Commit 631effe4 631effe4bb766bb5174fb5bf5f64208f06ea88ec by Alain Magloire

new Macros and declarations.

1 parent 8bc0b928
...@@ -45,19 +45,34 @@ extern int mu_nntp_set_debug (mu_nntp_t nntp, mu_debug_t debug); ...@@ -45,19 +45,34 @@ extern int mu_nntp_set_debug (mu_nntp_t nntp, mu_debug_t debug);
45 extern int mu_nntp_stls (mu_nntp_t nntp); 45 extern int mu_nntp_stls (mu_nntp_t nntp);
46 46
47 47
48 extern int mu_nntp_article (mu_nntp_t nntp, unsigned long num, unsigned long *pnum, char **mid, stream_t *stream); 48 extern int mu_nntp_mode_reader (mu_nntp_t nntp);
49
50 /* A list is return with the multi-line answer. It is the responsability of
51 the caller to call list_destroy() to dipose of the list. */
52 extern int mu_nntp_list_extensions (mu_nntp_t nntp, list_t *plist);
53
54 extern int mu_nntp_quit (mu_nntp_t nntp);
55
56 extern int mu_nntp_group (mu_nntp_t nntp, const char *group, unsigned long *total, unsigned long *first,
57 unsigned long *last, char **name);
58
59 extern int mu_nntp_last (mu_nntp_t nntp, unsigned long *number, char **mid);
60 extern int mu_nntp_next (mu_nntp_t nntp, unsigned long *number, char **mid);
61
62 extern int mu_nntp_article (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid, stream_t *stream);
49 extern int mu_nntp_article_id (mu_nntp_t nntp, const char *id, unsigned long *pnum, char **mid, stream_t *stream); 63 extern int mu_nntp_article_id (mu_nntp_t nntp, const char *id, unsigned long *pnum, char **mid, stream_t *stream);
50 64
51 extern int mu_nntp_head (mu_nntp_t nntp, unsigned long num, unsigned long *pnum, char **mid, stream_t *stream); 65 extern int mu_nntp_head (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid, stream_t *stream);
52 extern int mu_nntp_head_id (mu_nntp_t nntp, const char *name, unsigned long *pnum, char **mid, stream_t *stream); 66 extern int mu_nntp_head_id (mu_nntp_t nntp, const char *name, unsigned long *pnum, char **mid, stream_t *stream);
53 67
54 extern int mu_nntp_body (mu_nntp_t nntp, unsigned long num, unsigned long *pnum, char **mid, stream_t *stream); 68 extern int mu_nntp_body (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid, stream_t *stream);
55 extern int mu_nntp_body_id (mu_nntp_t nntp, const char *name, unsigned long *pnum, char **mid, stream_t *stream); 69 extern int mu_nntp_body_id (mu_nntp_t nntp, const char *id, unsigned long *pnum, char **mid, stream_t *stream);
56 70
57 extern int mu_nntp_stat (mu_nntp_t nntp, unsigned long num, char **id); 71 extern int mu_nntp_stat (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid);
58 extern int mu_nntp_stat_id (mu_nntp_t nntp, const char *name, char **id); 72 extern int mu_nntp_stat_id (mu_nntp_t nntp, const char *id, unsigned long *pnum, char **mid);
59 73
60 extern int mu_nntp_group (mu_nntp_t nntp, const char *group, long *total, long *first, long *last, char **name); 74 extern int mu_nntp_date (mu_nntp_t nntp, unsigned int *year, unsigned int *month, unsigned int *day,
75 unsigned int *hour, unsigned int *minute, unsigned int *second);
61 76
62 77
63 /* Reads the multi-line response of the server, nread will be 0 when the termination octets 78 /* Reads the multi-line response of the server, nread will be 0 when the termination octets
......
...@@ -30,15 +30,46 @@ ...@@ -30,15 +30,46 @@
30 extern "C" { 30 extern "C" {
31 #endif 31 #endif
32 32
33 /* Response codes. */
34
35 #define MU_NNTP_RESP_CODE_SERVER_DATE 111
36
37 #define MU_NNTP_RESP_CODE_POSTING_ALLOWED 200
38 #define MU_NNTP_RESP_CODE_POSTING_PROHIBITED 201
39 #define MU_NNTP_RESP_CODE_LIST_FOLLOW 202
40
41 #define MU_NNTP_RESP_CODE_CLOSING 205
42 #define MU_NNTP_RESP_CODE_GROUP_SELECTED 211
43
44 #define MU_NNTP_RESP_CODE_ARTICLE_FOLLOW 220
45 #define MU_NNTP_RESP_CODE_HEAD_FOLLOW 221
46 #define MU_NNTP_RESP_CODE_BODY_FOLLOW 222
47 #define MU_NNTP_RESP_CODE_ARTICLE_FOUND 223
48
49 #define MU_NNTP_RESP_CODE_TEMP_UNAVAILABLE 400
50 #define MU_NNTP_RESP_CODE_NO_EXTENSION 402
51 #define MU_NNTP_RESP_CODE_NO_ARTICLE_WITH_MID 430
52 #define MU_NNTP_RESP_CODE_NO_GROUP_SELECTED 412
53 #define MU_NNTP_RESP_CODE_NUMBER_INVALID 420
54 #define MU_NNTP_RESP_CODE_NO_ARTICLE 422
55 #define MU_NNTP_RESP_CODE_NO_ARTICLE_IN_RANGE 423
56 #define MU_NNTP_RESP_CODE_PERM_UNAVAILABLE 502
57
33 enum mu_nntp_state 58 enum mu_nntp_state
34 { 59 {
35 MU_NNTP_NO_STATE, 60 MU_NNTP_NO_STATE,
36 MU_NNTP_CONNECT, MU_NNTP_GREETINGS, 61 MU_NNTP_CONNECT, MU_NNTP_GREETINGS,
62 MU_NNTP_MODE_READER, MU_NNTP_MODE_READER_ACK,
63 MU_NNTP_LIST_EXTENSIONS, MU_NNTP_LIST_EXTENSIONS_ACK, MU_NNTP_LIST_EXTENSIONS_RX,
64 MU_NNTP_QUIT, MU_NNTP_QUIT_ACK,
65 MU_NNTP_GROUP, MU_NNTP_GROUP_ACK,
66 MU_NNTP_LAST, MU_NNTP_LAST_ACK,
67 MU_NNTP_NEXT, MU_NNTP_NEXT_ACK,
37 MU_NNTP_ARTICLE, MU_NNTP_ARTICLE_ACK, MU_NNTP_ARTICLE_RX, 68 MU_NNTP_ARTICLE, MU_NNTP_ARTICLE_ACK, MU_NNTP_ARTICLE_RX,
38 MU_NNTP_HEAD, MU_NNTP_HEAD_ACK, MU_NNTP_HEAD_RX, 69 MU_NNTP_HEAD, MU_NNTP_HEAD_ACK, MU_NNTP_HEAD_RX,
39 MU_NNTP_BODY, MU_NNTP_BODY_ACK, MU_NNTP_BODY_RX, 70 MU_NNTP_BODY, MU_NNTP_BODY_ACK, MU_NNTP_BODY_RX,
40 MU_NNTP_STAT, MU_NNTP_STAT_ACK, 71 MU_NNTP_STAT, MU_NNTP_STAT_ACK,
41 MU_NNTP_STLS, MU_NNTP_STLS_ACK, MU_NNTP_STLS_CONNECT, 72 MU_NNTP_DATE, MU_NNTP_DATE_ACK,
42 MU_NNTP_DONE, MU_NNTP_UNKNOWN, MU_NNTP_ERROR 73 MU_NNTP_DONE, MU_NNTP_UNKNOWN, MU_NNTP_ERROR
43 }; 74 };
44 75
...@@ -79,8 +110,9 @@ struct _mu_nntp ...@@ -79,8 +110,9 @@ struct _mu_nntp
79 110
80 extern int mu_nntp_debug_cmd (mu_nntp_t); 111 extern int mu_nntp_debug_cmd (mu_nntp_t);
81 extern int mu_nntp_debug_ack (mu_nntp_t); 112 extern int mu_nntp_debug_ack (mu_nntp_t);
82 extern int mu_nntp_stream_create (mu_nntp_t pop3, stream_t *pstream); 113 extern int mu_nntp_stream_create (mu_nntp_t nntp, stream_t *pstream);
83 extern int mu_nntp_carrier_is_ready (stream_t carrier, int flag, int timeout); 114 extern int mu_nntp_carrier_is_ready (stream_t carrier, int flag, int timeout);
115 extern int mu_nntp_parse_article (mu_nntp_t nntp, int code, unsigned long *pnum, char **mid);
84 116
85 /* Check for non recoverable error. 117 /* Check for non recoverable error.
86 The error is consider not recoverable if not part of the signal set: 118 The error is consider not recoverable if not part of the signal set:
...@@ -118,12 +150,23 @@ do \ ...@@ -118,12 +150,23 @@ do \
118 } \ 150 } \
119 while (0) 151 while (0)
120 152
121 /* Check if we got "2xx". In NNTP protocol and ack of "2xx" means the command was successfull. 153 /* Check if we got the rigth. In NNTP protocol and ack of "2xx" means the command was completed.
122 */ 154 */
123 #define MU_NNTP_CHECK_OK(nntp) \ 155 #define MU_NNTP_CHECK_CODE(nntp, code) \
156 do \
157 { \
158 if (mu_nntp_response_code (nntp) == code) \
159 { \
160 nntp->state = MU_NNTP_NO_STATE; \
161 return EACCES; \
162 } \
163 } \
164 while (0)
165
166 #define MU_NNTP_CHECK_CODE2(nntp, code1, code2) \
124 do \ 167 do \
125 { \ 168 { \
126 if (nntp->ack.buf[0] != '2') \ 169 if (mu_nntp_response_code (nntp) == code1 || mu_nntp_response_code (nntp) == code2) \
127 { \ 170 { \
128 nntp->state = MU_NNTP_NO_STATE; \ 171 nntp->state = MU_NNTP_NO_STATE; \
129 return EACCES; \ 172 return EACCES; \
......