mailutils/nntp.h mailutils/sys/nntp.h
new declarations.
Showing
2 changed files
with
122 additions
and
6 deletions
... | @@ -48,32 +48,107 @@ extern int mu_nntp_stls (mu_nntp_t nntp); | ... | @@ -48,32 +48,107 @@ extern int mu_nntp_stls (mu_nntp_t nntp); |
48 | extern int mu_nntp_mode_reader (mu_nntp_t nntp); | 48 | extern int mu_nntp_mode_reader (mu_nntp_t nntp); |
49 | 49 | ||
50 | /* A list is return with the multi-line answer. It is the responsability of | 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. */ | 51 | the caller to call list_destroy() to dispose of the list. */ |
52 | extern int mu_nntp_list_extensions (mu_nntp_t nntp, list_t *plist); | 52 | extern int mu_nntp_list_extensions (mu_nntp_t nntp, list_t *plist); |
53 | 53 | ||
54 | extern int mu_nntp_quit (mu_nntp_t nntp); | 54 | extern int mu_nntp_quit (mu_nntp_t nntp); |
55 | 55 | ||
56 | /* The argument name is allocated with malloc(3). The caller is responsable to call free(3) */ | ||
56 | extern int mu_nntp_group (mu_nntp_t nntp, const char *group, unsigned long *total, unsigned long *first, | 57 | 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 | unsigned long *last, char **name); |
58 | 59 | ||
60 | /* The argument mid is allocated with malloc(3). The caller is responsable to call free(3) */ | ||
59 | extern int mu_nntp_last (mu_nntp_t nntp, unsigned long *number, char **mid); | 61 | 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); | 62 | extern int mu_nntp_next (mu_nntp_t nntp, unsigned long *number, char **mid); |
61 | 63 | ||
64 | /* The argument mid is allocated with malloc(3). The caller is responsable to call free(3). | ||
65 | The caller must call stream_destoy() when done, no other commands are permitted until the stream is destroyed. */ | ||
62 | extern int mu_nntp_article (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid, stream_t *stream); | 66 | extern int mu_nntp_article (mu_nntp_t nntp, unsigned long number, 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); | 67 | extern int mu_nntp_article_id (mu_nntp_t nntp, const char *id, unsigned long *pnum, char **mid, stream_t *stream); |
64 | |||
65 | extern int mu_nntp_head (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid, stream_t *stream); | 68 | extern int mu_nntp_head (mu_nntp_t nntp, unsigned long number, 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); | 69 | extern int mu_nntp_head_id (mu_nntp_t nntp, const char *name, unsigned long *pnum, char **mid, stream_t *stream); |
67 | |||
68 | extern int mu_nntp_body (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid, stream_t *stream); | 70 | extern int mu_nntp_body (mu_nntp_t nntp, unsigned long number, 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); | 71 | extern int mu_nntp_body_id (mu_nntp_t nntp, const char *id, unsigned long *pnum, char **mid, stream_t *stream); |
70 | 72 | ||
73 | /* The argument mid is allocated with malloc(3). The caller is responsable to call free(3) */ | ||
71 | extern int mu_nntp_stat (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid); | 74 | extern int mu_nntp_stat (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid); |
72 | extern int mu_nntp_stat_id (mu_nntp_t nntp, const char *id, unsigned long *pnum, char **mid); | 75 | extern int mu_nntp_stat_id (mu_nntp_t nntp, const char *id, unsigned long *pnum, char **mid); |
73 | 76 | ||
74 | extern int mu_nntp_date (mu_nntp_t nntp, unsigned int *year, unsigned int *month, unsigned int *day, | 77 | 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); | 78 | unsigned int *hour, unsigned int *minute, unsigned int *second); |
76 | 79 | ||
80 | /* The caller must call stream_destoy() when done, no other commands are permitted until the stream is destroyed. */ | ||
81 | extern int mu_nntp_help (mu_nntp_t nntp, stream_t *stream); | ||
82 | |||
83 | |||
84 | /* A list is return with the multi-line answer. It is the responsability of | ||
85 | the caller to call list_destroy() to dispose of the list. */ | ||
86 | extern int mu_nntp_newgroups (mu_nntp_t nntp, unsigned int year, unsigned int month, unsigned int day, | ||
87 | unsigned int hour, unsigned int minute, unsigned int second, int is_gmt, list_t *plist); | ||
88 | /* A list is return with the multi-line answer. It is the responsability of | ||
89 | the caller to call list_destroy() to dispose of the list. */ | ||
90 | extern int mu_nntp_newnews (mu_nntp_t nntp, const char *wildmat, unsigned int year, unsigned int month, unsigned int day, | ||
91 | unsigned int hour, unsigned int minute, unsigned int second, int is_gmt, list_t *plist); | ||
92 | |||
93 | extern int mu_nntp_post (mu_nntp_t nntp, stream_t stream); | ||
94 | extern int mu_nntp_ihave (mu_nntp_t nntp, const char *mid, stream_t stream); | ||
95 | |||
96 | |||
97 | /* A list is return with the multi-line answer. It is the responsability of | ||
98 | the caller to call list_destroy() to dispose of the list. */ | ||
99 | extern int mu_nntp_list_active (mu_nntp_t nntp, const char *wildmat, list_t *plist); | ||
100 | extern int mu_nntp_list_active_times (mu_nntp_t nntp, const char *wildmat, list_t *plist); | ||
101 | extern int mu_nntp_list_distributions (mu_nntp_t nntp, const char *wildmat, list_t *plist); | ||
102 | extern int mu_nntp_list_distrib_pats (mu_nntp_t nntp, list_t *plist); | ||
103 | extern int mu_nntp_list_newsgroups (mu_nntp_t nntp, const char *wildmat, list_t *plist); | ||
104 | |||
105 | |||
106 | /* Parse the list active response. | ||
107 | "group high low status" | ||
108 | group: is the name of the group | ||
109 | high: high wather mark | ||
110 | low: low water mark | ||
111 | status: current status | ||
112 | 'y': posting is permitted | ||
113 | 'm': posting is not permitted | ||
114 | 'm': postings will be moderated | ||
115 | |||
116 | The argument group is allocated with malloc(3). The caller is responsable to call free(3). | ||
117 | */ | ||
118 | extern int mu_nntp_parse_list_active (const char *buffer, char **group, unsigned long *high, unsigned long *low, char *status); | ||
119 | extern int mu_nntp_parse_newgroups (const char *buffer, char **group, unsigned long *high, unsigned long *low, char *status); | ||
120 | /* Parse the list active.times response. | ||
121 | "group time creator" | ||
122 | group: is the name of the group | ||
123 | time: measure in seconds since Jan 1 1970 | ||
124 | creator: entity taht created the newsgroup | ||
125 | |||
126 | The argument group/creator is allocated with malloc(3). The caller is responsable to call free(3). | ||
127 | */ | ||
128 | extern int mu_nntp_parse_list_active_times (const char *buffer, char **group, unsigned long *time, char **creator); | ||
129 | /* Parse the list distributions response. | ||
130 | "key value" | ||
131 | key: field key. | ||
132 | value: short explaination of key | ||
133 | |||
134 | The argument key/value is allocated with malloc(3). The caller is responsable to call free(3). | ||
135 | */ | ||
136 | extern int mu_nntp_parse_list_distributions (const char *buffer, char **key, char **value); | ||
137 | /* Parse the list distributions response. | ||
138 | "weight:wildmat:distrib" | ||
139 | weight: | ||
140 | wildmat: | ||
141 | distrib: | ||
142 | |||
143 | The argument wildmat/distrib is allocated with malloc(3). The caller is responsable to call free(3). | ||
144 | */ | ||
145 | extern int mu_nntp_parse_list_distrib_pats (const char *buffer, unsigned long *weight, char **wildmat, char **distrib); | ||
146 | /* Parse the list distributions response. | ||
147 | "group description" | ||
148 | |||
149 | The argument group/description is allocated with malloc(3). The caller is responsable to call free(3). | ||
150 | */ | ||
151 | extern int mu_nntp_parse_list_newsgroups (const char *buffer, char **group, char **description); | ||
77 | 152 | ||
78 | /* Reads the multi-line response of the server, nread will be 0 when the termination octets | 153 | /* Reads the multi-line response of the server, nread will be 0 when the termination octets |
79 | are detected. Clients should not use this function unless they are sending direct command. */ | 154 | are detected. Clients should not use this function unless they are sending direct command. */ | ... | ... |
... | @@ -32,20 +32,32 @@ extern "C" { | ... | @@ -32,20 +32,32 @@ extern "C" { |
32 | 32 | ||
33 | /* Response codes. */ | 33 | /* Response codes. */ |
34 | 34 | ||
35 | #define MU_NNTP_RESP_CODE_HELP_FOLLOW 100 | ||
35 | #define MU_NNTP_RESP_CODE_SERVER_DATE 111 | 36 | #define MU_NNTP_RESP_CODE_SERVER_DATE 111 |
36 | 37 | ||
37 | #define MU_NNTP_RESP_CODE_POSTING_ALLOWED 200 | 38 | #define MU_NNTP_RESP_CODE_POSTING_ALLOWED 200 |
38 | #define MU_NNTP_RESP_CODE_POSTING_PROHIBITED 201 | 39 | #define MU_NNTP_RESP_CODE_POSTING_PROHIBITED 201 |
39 | #define MU_NNTP_RESP_CODE_LIST_FOLLOW 202 | 40 | #define MU_NNTP_RESP_CODE_EXTENSIONS_FOLLOW 202 |
40 | 41 | ||
41 | #define MU_NNTP_RESP_CODE_CLOSING 205 | 42 | #define MU_NNTP_RESP_CODE_CLOSING 205 |
42 | #define MU_NNTP_RESP_CODE_GROUP_SELECTED 211 | 43 | #define MU_NNTP_RESP_CODE_GROUP_SELECTED 211 |
43 | 44 | ||
45 | #define MU_NNTP_RESP_CODE_LIST_FOLLOW 215 | ||
46 | |||
44 | #define MU_NNTP_RESP_CODE_ARTICLE_FOLLOW 220 | 47 | #define MU_NNTP_RESP_CODE_ARTICLE_FOLLOW 220 |
45 | #define MU_NNTP_RESP_CODE_HEAD_FOLLOW 221 | 48 | #define MU_NNTP_RESP_CODE_HEAD_FOLLOW 221 |
46 | #define MU_NNTP_RESP_CODE_BODY_FOLLOW 222 | 49 | #define MU_NNTP_RESP_CODE_BODY_FOLLOW 222 |
47 | #define MU_NNTP_RESP_CODE_ARTICLE_FOUND 223 | 50 | #define MU_NNTP_RESP_CODE_ARTICLE_FOUND 223 |
48 | 51 | ||
52 | #define MU_NNTP_RESP_CODE_NEWNEWS_FOLLOW 230 | ||
53 | #define MU_NNTP_RESP_CODE_NEWGROUPS_FOLLOW 231 | ||
54 | #define MU_NNTP_RESP_CODE_TRANSFER_OK 235 | ||
55 | |||
56 | #define MU_NNTP_RESP_CODE_ARTICLE_RECEIVED 240 | ||
57 | |||
58 | #define MU_NNTP_RESP_CODE_TRANSFER_ARTICLE 335 | ||
59 | #define MU_NNTP_RESP_CODE_SEND_ARTICLE 340 | ||
60 | |||
49 | #define MU_NNTP_RESP_CODE_TEMP_UNAVAILABLE 400 | 61 | #define MU_NNTP_RESP_CODE_TEMP_UNAVAILABLE 400 |
50 | #define MU_NNTP_RESP_CODE_NO_EXTENSION 402 | 62 | #define MU_NNTP_RESP_CODE_NO_EXTENSION 402 |
51 | #define MU_NNTP_RESP_CODE_NO_ARTICLE_WITH_MID 430 | 63 | #define MU_NNTP_RESP_CODE_NO_ARTICLE_WITH_MID 430 |
... | @@ -53,6 +65,11 @@ extern "C" { | ... | @@ -53,6 +65,11 @@ extern "C" { |
53 | #define MU_NNTP_RESP_CODE_NUMBER_INVALID 420 | 65 | #define MU_NNTP_RESP_CODE_NUMBER_INVALID 420 |
54 | #define MU_NNTP_RESP_CODE_NO_ARTICLE 422 | 66 | #define MU_NNTP_RESP_CODE_NO_ARTICLE 422 |
55 | #define MU_NNTP_RESP_CODE_NO_ARTICLE_IN_RANGE 423 | 67 | #define MU_NNTP_RESP_CODE_NO_ARTICLE_IN_RANGE 423 |
68 | #define MU_NNTP_RESP_CODE_ARTICLE_NOT_WANTED 435 | ||
69 | #define MU_NNTP_RESP_CODE_TRANSFER_NOT_POSSIBLE 436 | ||
70 | #define MU_NNTP_RESP_CODE_TRANSFER_REJECTED 437 | ||
71 | #define MU_NNTP_RESP_CODE_POSTING_NOT_PERMITTED 440 | ||
72 | #define MU_NNTP_RESP_CODE_POSTING_FAILED 441 | ||
56 | #define MU_NNTP_RESP_CODE_PERM_UNAVAILABLE 502 | 73 | #define MU_NNTP_RESP_CODE_PERM_UNAVAILABLE 502 |
57 | 74 | ||
58 | enum mu_nntp_state | 75 | enum mu_nntp_state |
... | @@ -61,6 +78,11 @@ enum mu_nntp_state | ... | @@ -61,6 +78,11 @@ enum mu_nntp_state |
61 | MU_NNTP_CONNECT, MU_NNTP_GREETINGS, | 78 | MU_NNTP_CONNECT, MU_NNTP_GREETINGS, |
62 | MU_NNTP_MODE_READER, MU_NNTP_MODE_READER_ACK, | 79 | MU_NNTP_MODE_READER, MU_NNTP_MODE_READER_ACK, |
63 | MU_NNTP_LIST_EXTENSIONS, MU_NNTP_LIST_EXTENSIONS_ACK, MU_NNTP_LIST_EXTENSIONS_RX, | 80 | MU_NNTP_LIST_EXTENSIONS, MU_NNTP_LIST_EXTENSIONS_ACK, MU_NNTP_LIST_EXTENSIONS_RX, |
81 | MU_NNTP_LIST_ACTIVE, MU_NNTP_LIST_ACTIVE_ACK, MU_NNTP_LIST_ACTIVE_RX, | ||
82 | MU_NNTP_LIST_ACTIVE_TIMES, MU_NNTP_LIST_ACTIVE_TIMES_ACK, MU_NNTP_LIST_ACTIVE_TIMES_RX, | ||
83 | MU_NNTP_LIST_DISTRIBUTIONS, MU_NNTP_LIST_DISTRIBUTIONS_ACK, MU_NNTP_LIST_DISTRIBUTIONS_RX, | ||
84 | MU_NNTP_LIST_DISTRIB_PATS, MU_NNTP_LIST_DISTRIB_PATS_ACK, MU_NNTP_LIST_DISTRIB_PATS_RX, | ||
85 | MU_NNTP_LIST_NEWSGROUPS, MU_NNTP_LIST_NEWSGROUPS_ACK, MU_NNTP_LIST_NEWSGROUPS_RX, | ||
64 | MU_NNTP_QUIT, MU_NNTP_QUIT_ACK, | 86 | MU_NNTP_QUIT, MU_NNTP_QUIT_ACK, |
65 | MU_NNTP_GROUP, MU_NNTP_GROUP_ACK, | 87 | MU_NNTP_GROUP, MU_NNTP_GROUP_ACK, |
66 | MU_NNTP_LAST, MU_NNTP_LAST_ACK, | 88 | MU_NNTP_LAST, MU_NNTP_LAST_ACK, |
... | @@ -70,6 +92,11 @@ enum mu_nntp_state | ... | @@ -70,6 +92,11 @@ enum mu_nntp_state |
70 | MU_NNTP_BODY, MU_NNTP_BODY_ACK, MU_NNTP_BODY_RX, | 92 | MU_NNTP_BODY, MU_NNTP_BODY_ACK, MU_NNTP_BODY_RX, |
71 | MU_NNTP_STAT, MU_NNTP_STAT_ACK, | 93 | MU_NNTP_STAT, MU_NNTP_STAT_ACK, |
72 | MU_NNTP_DATE, MU_NNTP_DATE_ACK, | 94 | MU_NNTP_DATE, MU_NNTP_DATE_ACK, |
95 | MU_NNTP_HELP, MU_NNTP_HELP_ACK, MU_NNTP_HELP_RX, | ||
96 | MU_NNTP_NEWGROUPS, MU_NNTP_NEWGROUPS_ACK, MU_NNTP_NEWGROUPS_RX, | ||
97 | MU_NNTP_NEWNEWS, MU_NNTP_NEWNEWS_ACK, MU_NNTP_NEWNEWS_RX, | ||
98 | MU_NNTP_POST, MU_NNTP_POST_ACK, MU_NNTP_POST_0, MU_NNTP_POST_1, MU_NNTP_POST_2, MU_NNTP_POST_3, | ||
99 | MU_NNTP_IHAVE, MU_NNTP_IHAVE_ACK, MU_NNTP_IHAVE_0, MU_NNTP_IHAVE_1, MU_NNTP_IHAVE_2, MU_NNTP_IHAVE_3, | ||
73 | MU_NNTP_DONE, MU_NNTP_UNKNOWN, MU_NNTP_ERROR | 100 | MU_NNTP_DONE, MU_NNTP_UNKNOWN, MU_NNTP_ERROR |
74 | }; | 101 | }; |
75 | 102 | ||
... | @@ -82,6 +109,16 @@ struct mu_nntp_work_buf | ... | @@ -82,6 +109,16 @@ struct mu_nntp_work_buf |
82 | size_t len; | 109 | size_t len; |
83 | }; | 110 | }; |
84 | 111 | ||
112 | /* Structure holding the data for post. */ | ||
113 | struct mu_nntp_post_buf | ||
114 | { | ||
115 | char *buf; | ||
116 | int sent_crlf; | ||
117 | size_t nread; | ||
118 | long offset; | ||
119 | size_t len; | ||
120 | }; | ||
121 | |||
85 | /* Structure to hold things general to nntp connection, like its state, etc ... */ | 122 | /* Structure to hold things general to nntp connection, like its state, etc ... */ |
86 | struct _mu_nntp | 123 | struct _mu_nntp |
87 | { | 124 | { |
... | @@ -99,6 +136,9 @@ struct _mu_nntp | ... | @@ -99,6 +136,9 @@ struct _mu_nntp |
99 | struct mu_nntp_work_buf ack; | 136 | struct mu_nntp_work_buf ack; |
100 | int acknowledge; | 137 | int acknowledge; |
101 | 138 | ||
139 | /* Holds the buffer/offset etc ... for the article to post. */ | ||
140 | struct mu_nntp_post_buf post; | ||
141 | |||
102 | unsigned timeout; /* Default is 10 minutes. */ | 142 | unsigned timeout; /* Default is 10 minutes. */ |
103 | 143 | ||
104 | mu_debug_t debug; /* debugging trace. */ | 144 | mu_debug_t debug; /* debugging trace. */ |
... | @@ -114,6 +154,7 @@ extern int mu_nntp_stream_create (mu_nntp_t nntp, stream_t *pstream); | ... | @@ -114,6 +154,7 @@ extern int mu_nntp_stream_create (mu_nntp_t nntp, stream_t *pstream); |
114 | extern int mu_nntp_carrier_is_ready (stream_t carrier, int flag, int timeout); | 154 | 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); | 155 | extern int mu_nntp_parse_article (mu_nntp_t nntp, int code, unsigned long *pnum, char **mid); |
116 | 156 | ||
157 | |||
117 | /* Check for non recoverable error. | 158 | /* Check for non recoverable error. |
118 | The error is consider not recoverable if not part of the signal set: | 159 | The error is consider not recoverable if not part of the signal set: |
119 | EAGAIN, EINPROGRESS, EINTR. | 160 | EAGAIN, EINPROGRESS, EINTR. |
... | @@ -155,7 +196,7 @@ while (0) | ... | @@ -155,7 +196,7 @@ while (0) |
155 | #define MU_NNTP_CHECK_CODE(nntp, code) \ | 196 | #define MU_NNTP_CHECK_CODE(nntp, code) \ |
156 | do \ | 197 | do \ |
157 | { \ | 198 | { \ |
158 | if (mu_nntp_response_code (nntp) == code) \ | 199 | if (mu_nntp_response_code (nntp) != code) \ |
159 | { \ | 200 | { \ |
160 | nntp->state = MU_NNTP_NO_STATE; \ | 201 | nntp->state = MU_NNTP_NO_STATE; \ |
161 | return EACCES; \ | 202 | return EACCES; \ |
... | @@ -166,7 +207,7 @@ while (0) | ... | @@ -166,7 +207,7 @@ while (0) |
166 | #define MU_NNTP_CHECK_CODE2(nntp, code1, code2) \ | 207 | #define MU_NNTP_CHECK_CODE2(nntp, code1, code2) \ |
167 | do \ | 208 | do \ |
168 | { \ | 209 | { \ |
169 | if (mu_nntp_response_code (nntp) == code1 || mu_nntp_response_code (nntp) == code2) \ | 210 | if (mu_nntp_response_code (nntp) != code1 && mu_nntp_response_code (nntp) != code2) \ |
170 | { \ | 211 | { \ |
171 | nntp->state = MU_NNTP_NO_STATE; \ | 212 | nntp->state = MU_NNTP_NO_STATE; \ |
172 | return EACCES; \ | 213 | return EACCES; \ | ... | ... |
-
Please register or sign in to post a comment