summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mailutils/nntp.h83
-rw-r--r--include/mailutils/sys/nntp.h115
2 files changed, 157 insertions, 41 deletions
diff --git a/include/mailutils/nntp.h b/include/mailutils/nntp.h
index 9dfede4f5..4b2ff027a 100644
--- a/include/mailutils/nntp.h
+++ b/include/mailutils/nntp.h
@@ -48,36 +48,111 @@ extern int mu_nntp_stls (mu_nntp_t nntp);
extern int mu_nntp_mode_reader (mu_nntp_t nntp);
/* A list is return with the multi-line answer. It is the responsability of
- the caller to call list_destroy() to dipose of the list. */
+ the caller to call list_destroy() to dispose of the list. */
extern int mu_nntp_list_extensions (mu_nntp_t nntp, list_t *plist);
extern int mu_nntp_quit (mu_nntp_t nntp);
+/* The argument name is allocated with malloc(3). The caller is responsable to call free(3) */
extern int mu_nntp_group (mu_nntp_t nntp, const char *group, unsigned long *total, unsigned long *first,
unsigned long *last, char **name);
+/* The argument mid is allocated with malloc(3). The caller is responsable to call free(3) */
extern int mu_nntp_last (mu_nntp_t nntp, unsigned long *number, char **mid);
extern int mu_nntp_next (mu_nntp_t nntp, unsigned long *number, char **mid);
+/* The argument mid is allocated with malloc(3). The caller is responsable to call free(3).
+ The caller must call stream_destoy() when done, no other commands are permitted until the stream is destroyed. */
extern int mu_nntp_article (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid, stream_t *stream);
extern int mu_nntp_article_id (mu_nntp_t nntp, const char *id, unsigned long *pnum, char **mid, stream_t *stream);
-
extern int mu_nntp_head (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid, stream_t *stream);
extern int mu_nntp_head_id (mu_nntp_t nntp, const char *name, unsigned long *pnum, char **mid, stream_t *stream);
-
extern int mu_nntp_body (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid, stream_t *stream);
extern int mu_nntp_body_id (mu_nntp_t nntp, const char *id, unsigned long *pnum, char **mid, stream_t *stream);
+/* The argument mid is allocated with malloc(3). The caller is responsable to call free(3) */
extern int mu_nntp_stat (mu_nntp_t nntp, unsigned long number, unsigned long *pnum, char **mid);
extern int mu_nntp_stat_id (mu_nntp_t nntp, const char *id, unsigned long *pnum, char **mid);
extern int mu_nntp_date (mu_nntp_t nntp, unsigned int *year, unsigned int *month, unsigned int *day,
unsigned int *hour, unsigned int *minute, unsigned int *second);
+/* The caller must call stream_destoy() when done, no other commands are permitted until the stream is destroyed. */
+extern int mu_nntp_help (mu_nntp_t nntp, stream_t *stream);
+
+
+/* A list is return with the multi-line answer. It is the responsability of
+ the caller to call list_destroy() to dispose of the list. */
+extern int mu_nntp_newgroups (mu_nntp_t nntp, unsigned int year, unsigned int month, unsigned int day,
+ unsigned int hour, unsigned int minute, unsigned int second, int is_gmt, list_t *plist);
+/* A list is return with the multi-line answer. It is the responsability of
+ the caller to call list_destroy() to dispose of the list. */
+extern int mu_nntp_newnews (mu_nntp_t nntp, const char *wildmat, unsigned int year, unsigned int month, unsigned int day,
+ unsigned int hour, unsigned int minute, unsigned int second, int is_gmt, list_t *plist);
+
+extern int mu_nntp_post (mu_nntp_t nntp, stream_t stream);
+extern int mu_nntp_ihave (mu_nntp_t nntp, const char *mid, stream_t stream);
+
+
+/* A list is return with the multi-line answer. It is the responsability of
+ the caller to call list_destroy() to dispose of the list. */
+extern int mu_nntp_list_active (mu_nntp_t nntp, const char *wildmat, list_t *plist);
+extern int mu_nntp_list_active_times (mu_nntp_t nntp, const char *wildmat, list_t *plist);
+extern int mu_nntp_list_distributions (mu_nntp_t nntp, const char *wildmat, list_t *plist);
+extern int mu_nntp_list_distrib_pats (mu_nntp_t nntp, list_t *plist);
+extern int mu_nntp_list_newsgroups (mu_nntp_t nntp, const char *wildmat, list_t *plist);
+
+
+/* Parse the list active response.
+ "group high low status"
+ group: is the name of the group
+ high: high wather mark
+ low: low water mark
+ status: current status
+ 'y': posting is permitted
+ 'm': posting is not permitted
+ 'm': postings will be moderated
+
+ The argument group is allocated with malloc(3). The caller is responsable to call free(3).
+*/
+extern int mu_nntp_parse_list_active (const char *buffer, char **group, unsigned long *high, unsigned long *low, char *status);
+extern int mu_nntp_parse_newgroups (const char *buffer, char **group, unsigned long *high, unsigned long *low, char *status);
+/* Parse the list active.times response.
+ "group time creator"
+ group: is the name of the group
+ time: measure in seconds since Jan 1 1970
+ creator: entity taht created the newsgroup
+
+ The argument group/creator is allocated with malloc(3). The caller is responsable to call free(3).
+*/
+extern int mu_nntp_parse_list_active_times (const char *buffer, char **group, unsigned long *time, char **creator);
+/* Parse the list distributions response.
+ "key value"
+ key: field key.
+ value: short explaination of key
+
+ The argument key/value is allocated with malloc(3). The caller is responsable to call free(3).
+*/
+extern int mu_nntp_parse_list_distributions (const char *buffer, char **key, char **value);
+/* Parse the list distributions response.
+ "weight:wildmat:distrib"
+ weight:
+ wildmat:
+ distrib:
+
+ The argument wildmat/distrib is allocated with malloc(3). The caller is responsable to call free(3).
+*/
+extern int mu_nntp_parse_list_distrib_pats (const char *buffer, unsigned long *weight, char **wildmat, char **distrib);
+/* Parse the list distributions response.
+ "group description"
+
+ The argument group/description is allocated with malloc(3). The caller is responsable to call free(3).
+*/
+extern int mu_nntp_parse_list_newsgroups (const char *buffer, char **group, char **description);
/* 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);
+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. */
diff --git a/include/mailutils/sys/nntp.h b/include/mailutils/sys/nntp.h
index 74c451dd3..ba3da718f 100644
--- a/include/mailutils/sys/nntp.h
+++ b/include/mailutils/sys/nntp.h
@@ -32,45 +32,72 @@ extern "C" {
/* Response codes. */
-#define MU_NNTP_RESP_CODE_SERVER_DATE 111
-
-#define MU_NNTP_RESP_CODE_POSTING_ALLOWED 200
-#define MU_NNTP_RESP_CODE_POSTING_PROHIBITED 201
-#define MU_NNTP_RESP_CODE_LIST_FOLLOW 202
-
-#define MU_NNTP_RESP_CODE_CLOSING 205
-#define MU_NNTP_RESP_CODE_GROUP_SELECTED 211
-
-#define MU_NNTP_RESP_CODE_ARTICLE_FOLLOW 220
-#define MU_NNTP_RESP_CODE_HEAD_FOLLOW 221
-#define MU_NNTP_RESP_CODE_BODY_FOLLOW 222
-#define MU_NNTP_RESP_CODE_ARTICLE_FOUND 223
-
-#define MU_NNTP_RESP_CODE_TEMP_UNAVAILABLE 400
-#define MU_NNTP_RESP_CODE_NO_EXTENSION 402
-#define MU_NNTP_RESP_CODE_NO_ARTICLE_WITH_MID 430
-#define MU_NNTP_RESP_CODE_NO_GROUP_SELECTED 412
-#define MU_NNTP_RESP_CODE_NUMBER_INVALID 420
-#define MU_NNTP_RESP_CODE_NO_ARTICLE 422
-#define MU_NNTP_RESP_CODE_NO_ARTICLE_IN_RANGE 423
-#define MU_NNTP_RESP_CODE_PERM_UNAVAILABLE 502
+#define MU_NNTP_RESP_CODE_HELP_FOLLOW 100
+#define MU_NNTP_RESP_CODE_SERVER_DATE 111
+
+#define MU_NNTP_RESP_CODE_POSTING_ALLOWED 200
+#define MU_NNTP_RESP_CODE_POSTING_PROHIBITED 201
+#define MU_NNTP_RESP_CODE_EXTENSIONS_FOLLOW 202
+
+#define MU_NNTP_RESP_CODE_CLOSING 205
+#define MU_NNTP_RESP_CODE_GROUP_SELECTED 211
+
+#define MU_NNTP_RESP_CODE_LIST_FOLLOW 215
+
+#define MU_NNTP_RESP_CODE_ARTICLE_FOLLOW 220
+#define MU_NNTP_RESP_CODE_HEAD_FOLLOW 221
+#define MU_NNTP_RESP_CODE_BODY_FOLLOW 222
+#define MU_NNTP_RESP_CODE_ARTICLE_FOUND 223
+
+#define MU_NNTP_RESP_CODE_NEWNEWS_FOLLOW 230
+#define MU_NNTP_RESP_CODE_NEWGROUPS_FOLLOW 231
+#define MU_NNTP_RESP_CODE_TRANSFER_OK 235
+
+#define MU_NNTP_RESP_CODE_ARTICLE_RECEIVED 240
+
+#define MU_NNTP_RESP_CODE_TRANSFER_ARTICLE 335
+#define MU_NNTP_RESP_CODE_SEND_ARTICLE 340
+
+#define MU_NNTP_RESP_CODE_TEMP_UNAVAILABLE 400
+#define MU_NNTP_RESP_CODE_NO_EXTENSION 402
+#define MU_NNTP_RESP_CODE_NO_ARTICLE_WITH_MID 430
+#define MU_NNTP_RESP_CODE_NO_GROUP_SELECTED 412
+#define MU_NNTP_RESP_CODE_NUMBER_INVALID 420
+#define MU_NNTP_RESP_CODE_NO_ARTICLE 422
+#define MU_NNTP_RESP_CODE_NO_ARTICLE_IN_RANGE 423
+#define MU_NNTP_RESP_CODE_ARTICLE_NOT_WANTED 435
+#define MU_NNTP_RESP_CODE_TRANSFER_NOT_POSSIBLE 436
+#define MU_NNTP_RESP_CODE_TRANSFER_REJECTED 437
+#define MU_NNTP_RESP_CODE_POSTING_NOT_PERMITTED 440
+#define MU_NNTP_RESP_CODE_POSTING_FAILED 441
+#define MU_NNTP_RESP_CODE_PERM_UNAVAILABLE 502
enum mu_nntp_state
{
MU_NNTP_NO_STATE,
- MU_NNTP_CONNECT, MU_NNTP_GREETINGS,
- MU_NNTP_MODE_READER, MU_NNTP_MODE_READER_ACK,
- MU_NNTP_LIST_EXTENSIONS, MU_NNTP_LIST_EXTENSIONS_ACK, MU_NNTP_LIST_EXTENSIONS_RX,
- MU_NNTP_QUIT, MU_NNTP_QUIT_ACK,
- MU_NNTP_GROUP, MU_NNTP_GROUP_ACK,
- MU_NNTP_LAST, MU_NNTP_LAST_ACK,
- MU_NNTP_NEXT, MU_NNTP_NEXT_ACK,
- MU_NNTP_ARTICLE, MU_NNTP_ARTICLE_ACK, MU_NNTP_ARTICLE_RX,
- MU_NNTP_HEAD, MU_NNTP_HEAD_ACK, MU_NNTP_HEAD_RX,
- MU_NNTP_BODY, MU_NNTP_BODY_ACK, MU_NNTP_BODY_RX,
- MU_NNTP_STAT, MU_NNTP_STAT_ACK,
- MU_NNTP_DATE, MU_NNTP_DATE_ACK,
- MU_NNTP_DONE, MU_NNTP_UNKNOWN, MU_NNTP_ERROR
+ MU_NNTP_CONNECT, MU_NNTP_GREETINGS,
+ MU_NNTP_MODE_READER, MU_NNTP_MODE_READER_ACK,
+ MU_NNTP_LIST_EXTENSIONS, MU_NNTP_LIST_EXTENSIONS_ACK, MU_NNTP_LIST_EXTENSIONS_RX,
+ MU_NNTP_LIST_ACTIVE, MU_NNTP_LIST_ACTIVE_ACK, MU_NNTP_LIST_ACTIVE_RX,
+ MU_NNTP_LIST_ACTIVE_TIMES, MU_NNTP_LIST_ACTIVE_TIMES_ACK, MU_NNTP_LIST_ACTIVE_TIMES_RX,
+ MU_NNTP_LIST_DISTRIBUTIONS, MU_NNTP_LIST_DISTRIBUTIONS_ACK, MU_NNTP_LIST_DISTRIBUTIONS_RX,
+ MU_NNTP_LIST_DISTRIB_PATS, MU_NNTP_LIST_DISTRIB_PATS_ACK, MU_NNTP_LIST_DISTRIB_PATS_RX,
+ MU_NNTP_LIST_NEWSGROUPS, MU_NNTP_LIST_NEWSGROUPS_ACK, MU_NNTP_LIST_NEWSGROUPS_RX,
+ MU_NNTP_QUIT, MU_NNTP_QUIT_ACK,
+ MU_NNTP_GROUP, MU_NNTP_GROUP_ACK,
+ MU_NNTP_LAST, MU_NNTP_LAST_ACK,
+ MU_NNTP_NEXT, MU_NNTP_NEXT_ACK,
+ MU_NNTP_ARTICLE, MU_NNTP_ARTICLE_ACK, MU_NNTP_ARTICLE_RX,
+ MU_NNTP_HEAD, MU_NNTP_HEAD_ACK, MU_NNTP_HEAD_RX,
+ MU_NNTP_BODY, MU_NNTP_BODY_ACK, MU_NNTP_BODY_RX,
+ MU_NNTP_STAT, MU_NNTP_STAT_ACK,
+ MU_NNTP_DATE, MU_NNTP_DATE_ACK,
+ MU_NNTP_HELP, MU_NNTP_HELP_ACK, MU_NNTP_HELP_RX,
+ MU_NNTP_NEWGROUPS, MU_NNTP_NEWGROUPS_ACK, MU_NNTP_NEWGROUPS_RX,
+ MU_NNTP_NEWNEWS, MU_NNTP_NEWNEWS_ACK, MU_NNTP_NEWNEWS_RX,
+ MU_NNTP_POST, MU_NNTP_POST_ACK, MU_NNTP_POST_0, MU_NNTP_POST_1, MU_NNTP_POST_2, MU_NNTP_POST_3,
+ MU_NNTP_IHAVE, MU_NNTP_IHAVE_ACK, MU_NNTP_IHAVE_0, MU_NNTP_IHAVE_1, MU_NNTP_IHAVE_2, MU_NNTP_IHAVE_3,
+ MU_NNTP_DONE, MU_NNTP_UNKNOWN, MU_NNTP_ERROR
};
/* Structure holding the data necessary to do proper buffering. */
@@ -82,6 +109,16 @@ struct mu_nntp_work_buf
size_t len;
};
+/* Structure holding the data for post. */
+struct mu_nntp_post_buf
+ {
+ char *buf;
+ int sent_crlf;
+ size_t nread;
+ long offset;
+ size_t len;
+ };
+
/* Structure to hold things general to nntp connection, like its state, etc ... */
struct _mu_nntp
{
@@ -99,6 +136,9 @@ struct _mu_nntp
struct mu_nntp_work_buf ack;
int acknowledge;
+ /* Holds the buffer/offset etc ... for the article to post. */
+ struct mu_nntp_post_buf post;
+
unsigned timeout; /* Default is 10 minutes. */
mu_debug_t debug; /* debugging trace. */
@@ -114,6 +154,7 @@ extern int mu_nntp_stream_create (mu_nntp_t nntp, stream_t *pstream);
extern int mu_nntp_carrier_is_ready (stream_t carrier, int flag, int timeout);
extern int mu_nntp_parse_article (mu_nntp_t nntp, int code, unsigned long *pnum, char **mid);
+
/* Check for non recoverable error.
The error is consider not recoverable if not part of the signal set:
EAGAIN, EINPROGRESS, EINTR.
@@ -155,7 +196,7 @@ while (0)
#define MU_NNTP_CHECK_CODE(nntp, code) \
do \
{ \
- if (mu_nntp_response_code (nntp) == code) \
+ if (mu_nntp_response_code (nntp) != code) \
{ \
nntp->state = MU_NNTP_NO_STATE; \
return EACCES; \
@@ -166,7 +207,7 @@ while (0)
#define MU_NNTP_CHECK_CODE2(nntp, code1, code2) \
do \
{ \
- if (mu_nntp_response_code (nntp) == code1 || mu_nntp_response_code (nntp) == code2) \
+ if (mu_nntp_response_code (nntp) != code1 && mu_nntp_response_code (nntp) != code2) \
{ \
nntp->state = MU_NNTP_NO_STATE; \
return EACCES; \

Return to:

Send suggestions and report system problems to the System administrator.