]> granicus.if.org Git - neomutt/commitdiff
create libnntp
authorRichard Russon <rich@flatcap.org>
Sat, 7 Jul 2018 10:50:34 +0000 (11:50 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 16 Jul 2018 22:13:05 +0000 (23:13 +0100)
17 files changed:
Makefile.autosetup
browser.c
complete.c
compose.c
curs_main.c
main.c
mx.c
nntp/newsrc.c [moved from newsrc.c with 99% similarity]
nntp/nntp.c [moved from nntp.c with 99% similarity]
nntp/nntp.h [moved from nntp.h with 74% similarity]
nntp/nntp_private.h [new file with mode: 0644]
pager.c
po/POTFILES.in
send.c
sendlib.c
sort.c
sort.h

index fd7901caa995069e447a930f3470fd9268963759..db5fc7b9461226f517921744c1019299c47c8c08 100644 (file)
@@ -67,8 +67,8 @@ NEOMUTTOBJS=  addrbook.o alias.o bcache.o browser.o buffy.o \
                enriched.o enter.o filter.o flags.o from.o group.o handler.o \
                hdrline.o help.o history.o hook.o init.o keymap.o \
                main.o mbox.o menu.o mh.o muttlib.o mutt_account.o mutt_attach.o mutt_body.o mutt_header.o \
-               mutt_logging.o mutt_signal.o mutt_socket.o mutt_thread.o mutt_window.o mx.o newsrc.o \
-               nntp.o pager.o parse.o pattern.o \
+               mutt_logging.o mutt_signal.o mutt_socket.o mutt_thread.o mutt_window.o mx.o \
+               pager.o parse.o pattern.o \
                postpone.o progress.o query.o recvattach.o recvcmd.o resize.o rfc1524.o \
                rfc2047.o rfc2231.o rfc3676.o safe_asprintf.o score.o send.o \
                sendlib.o sidebar.o smtp.o sort.o state.o status.o system.o \
@@ -106,6 +106,14 @@ CLEANFILES+=       $(LIBPOP) $(LIBPOPOBJS)
 MUTTLIBS+=     $(LIBPOP)
 ALLOBJS+=      $(LIBPOPOBJS)
 
+###############################################################################
+# libnntp
+LIBNNTP=       libnntp.a
+LIBNNTPOBJS=   nntp/newsrc.o nntp/nntp.o
+CLEANFILES+=   $(LIBNNTP) $(LIBNNTPOBJS)
+MUTTLIBS+=     $(LIBNNTP)
+ALLOBJS+=      $(LIBNNTPOBJS)
+
 ###############################################################################
 # libmutt
 LIBMUTT=       libmutt.a
@@ -250,6 +258,13 @@ $(LIBPOP): $(PWD)/pop $(LIBPOPOBJS)
 $(PWD)/pop:
        $(MKDIR_P) $(PWD)/pop
 
+# libnntp
+$(LIBNNTP): $(PWD)/nntp $(LIBNNTPOBJS)
+       $(AR) cr $@ $(LIBNNTPOBJS)
+       $(RANLIB) $@
+$(PWD)/nntp:
+       $(MKDIR_P) $(PWD)/nntp
+
 # libncrypt
 $(LIBNCRYPT): $(PWD)/ncrypt $(LIBNCRYPTOBJS)
        $(AR) cr $@ $(LIBNCRYPTOBJS)
index c31a5c21bbc645a169a9368e06a4c9eb2950bd87..49bf8cc4e336aa44407666f5d9d3f1f87447f3c6 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -59,7 +59,7 @@
 #include "imap/imap.h"
 #endif
 #ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
 #endif
 #ifdef USE_NOTMUCH
 #include "mutt_notmuch.h"
index 6e2b44fc26bf15fbdb4d9e448218116c9a9a89a3..d3f71db2889f41be6f548addcb34a4d5224a24b3 100644 (file)
@@ -41,7 +41,7 @@
 #include "mailbox.h"
 #endif
 #ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
 #endif
 
 /**
index 14f53391ee5a4de8200cf674167e6c36bd0f920f..09836d1579ea321b515f5c20f7499167fc55f519 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -58,7 +58,7 @@
 #include "remailer.h"
 #endif
 #ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
 #endif
 
 static const char *There_are_no_attachments = N_("There are no attachments.");
index c8bb393437f455f09a2b9c13ee8075990ecef50e..4f75221402a7560f91d00fd2cb31e20c73df2419 100644 (file)
@@ -67,7 +67,7 @@
 #include "mutt_notmuch.h"
 #endif
 #ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
 #endif
 #ifdef ENABLE_NLS
 #include <libintl.h>
diff --git a/main.c b/main.c
index 66f14b5315fcf004de85dbc20681e69ab60e42a4..7a616b78d36188196e83d27b58edde1540c6c52c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -70,7 +70,7 @@
 #include "imap/imap.h"
 #endif
 #ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
 #endif
 
 #define MUTT_IGNORE (1 << 0)  /* -z */
diff --git a/mx.c b/mx.c
index fd928fc4c70bafad1af5af6d39d402871ab09de6..d64129be3accf63e6a78b605d4e73bab8597344d 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -69,7 +69,7 @@
 #include "pop/pop.h"
 #endif
 #ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
 #endif
 #ifdef USE_NOTMUCH
 #include "mutt_notmuch.h"
similarity index 99%
rename from newsrc.c
rename to nntp/newsrc.c
index 8c4393feaf67a1d958ead920ead1347edbaad263..3f38d3d80b0ed2a15949bb682d50cf0a39b0417b 100644 (file)
--- a/newsrc.c
@@ -38,6 +38,7 @@
 #include <sys/stat.h>
 #include <time.h>
 #include <unistd.h>
+#include "nntp_private.h"
 #include "mutt/mutt.h"
 #include "conn/conn.h"
 #include "mutt.h"
similarity index 99%
rename from nntp.c
rename to nntp/nntp.c
index a377c94712b42567e4d733c4221b7d4cad4fedca..b71a21190c6aae831f057b1776c38957f8b46fd9 100644 (file)
--- a/nntp.c
@@ -35,6 +35,7 @@
 #include <string.h>
 #include <strings.h>
 #include <unistd.h>
+#include "nntp_private.h"
 #include "mutt/mutt.h"
 #include "email/email.h"
 #include "conn/conn.h"
@@ -53,6 +54,7 @@
 #include "options.h"
 #include "progress.h"
 #include "protos.h"
+#include "sort.h"
 #include "url.h"
 #ifdef USE_HCACHE
 #include "hcache/hcache.h"
@@ -2594,6 +2596,26 @@ int nntp_check_children(struct Context *ctx, const char *msgid)
   return (rc < 0) ? -1 : 0;
 }
 
+/**
+ * nntp_compare_order - Sort to mailbox order
+ * @param a First Header to compare
+ * @param b First Header to compare
+ * @retval -1 a precedes b
+ * @retval  0 a and b are identical
+ * @retval  1 b precedes a
+ */
+int nntp_compare_order(const void *a, const void *b)
+{
+  struct Header **ha = (struct Header **) a;
+  struct Header **hb = (struct Header **) b;
+
+  anum_t na = NHDR(*ha)->article_num;
+  anum_t nb = NHDR(*hb)->article_num;
+  int result = (na == nb) ? 0 : (na > nb) ? 1 : -1;
+  result = perform_auxsort(result, a, b);
+  return (SORTCODE(result));
+}
+
 // clang-format off
 /**
  * struct mx_nntp_ops - Mailbox callback functions for NNTP mailboxes
similarity index 74%
rename from nntp.h
rename to nntp/nntp.h
index f314bfdacb30f06e1522e804552619264e112e89..5262ac955db8c2fb577478039e653136d62216a1 100644 (file)
--- a/nntp.h
@@ -22,8 +22,8 @@
  * this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef _MUTT_NNTP_H
-#define _MUTT_NNTP_H
+#ifndef _NNTP_NNTP_H
+#define _NNTP_NNTP_H
 
 #include <stdbool.h>
 #include <stdint.h>
@@ -41,44 +41,28 @@ struct Account;
 struct Header;
 struct Context;
 
-#define NNTP_PORT 119
-#define NNTP_SSL_PORT 563
-
-/* number of entries in article cache */
-#define NNTP_ACACHE_LEN 10
-
 /* article number type and format */
 #define anum_t uint32_t
 #define ANUM "%u"
 
-/**
- * enum NntpStatus - NNTP server return values
- */
-enum NntpStatus
-{
-  NNTP_NONE = 0,
-  NNTP_OK,
-  NNTP_BYE
-};
-
 /**
  * struct NntpServer - NNTP-specific server data
  */
 struct NntpServer
 {
-  bool hasCAPABILITIES : 1;
-  bool hasSTARTTLS : 1;
-  bool hasDATE : 1;
+  bool hasCAPABILITIES    : 1;
+  bool hasSTARTTLS        : 1;
+  bool hasDATE            : 1;
   bool hasLIST_NEWSGROUPS : 1;
-  bool hasXGTITLE : 1;
-  bool hasLISTGROUP : 1;
-  bool hasLISTGROUPrange : 1;
-  bool hasOVER : 1;
-  bool hasXOVER : 1;
-  unsigned int use_tls : 3;
-  unsigned int status : 3;
-  bool cacheable : 1;
-  bool newsrc_modified : 1;
+  bool hasXGTITLE         : 1;
+  bool hasLISTGROUP       : 1;
+  bool hasLISTGROUPrange  : 1;
+  bool hasOVER            : 1;
+  bool hasXOVER           : 1;
+  unsigned int use_tls    : 3;
+  unsigned int status     : 3;
+  bool cacheable          : 1;
+  bool newsrc_modified    : 1;
   FILE *newsrc_fp;
   char *newsrc_file;
   char *authenticators;
@@ -95,12 +79,12 @@ struct NntpServer
 };
 
 /**
- * struct NewsrcEntry - An entry in a .newsrc (subscribed newsgroups)
+ * struct NntpHeaderData - NNTP-specific header data
  */
-struct NewsrcEntry
+struct NntpHeaderData
 {
-  anum_t first;
-  anum_t last;
+  anum_t article_num;
+  bool parsed : 1;
 };
 
 /**
@@ -112,6 +96,18 @@ struct NntpAcache
   char *path;
 };
 
+/**
+ * struct NewsrcEntry - An entry in a .newsrc (subscribed newsgroups)
+ */
+struct NewsrcEntry
+{
+  anum_t first;
+  anum_t last;
+};
+
+/* number of entries in article cache */
+#define NNTP_ACACHE_LEN 10
+
 /**
  * struct NntpData - NNTP-specific server data
  */
@@ -125,9 +121,9 @@ struct NntpData
   anum_t last_cached;
   anum_t unread;
   bool subscribed : 1;
-  bool new : 1;
-  bool allowed : 1;
-  bool deleted : 1;
+  bool new        : 1;
+  bool allowed    : 1;
+  bool deleted    : 1;
   unsigned int newsrc_len;
   struct NewsrcEntry *newsrc_ent;
   struct NntpServer *nserv;
@@ -135,31 +131,6 @@ struct NntpData
   struct BodyCache *bcache;
 };
 
-/**
- * struct NntpHeaderData - NNTP-specific header data
- */
-struct NntpHeaderData
-{
-  anum_t article_num;
-  bool parsed : 1;
-};
-
-#define NHDR(hdr) ((struct NntpHeaderData *) ((hdr)->data))
-
-/* internal functions */
-int nntp_add_group(char *line, void *data);
-int nntp_active_save_cache(struct NntpServer *nserv);
-int nntp_check_new_groups(struct NntpServer *nserv);
-int nntp_open_connection(struct NntpServer *nserv);
-void nntp_newsrc_gen_entries(struct Context *ctx);
-void nntp_bcache_update(struct NntpData *nntp_data);
-void nntp_article_status(struct Context *ctx, struct Header *hdr, char *group, anum_t anum);
-void nntp_group_unread_stat(struct NntpData *nntp_data);
-void nntp_data_free(void *data);
-void nntp_acache_free(struct NntpData *nntp_data);
-void nntp_delete_group_cache(struct NntpData *nntp_data);
-
-/* exposed interface */
 struct NntpServer *nntp_select_server(char *server, bool leave_lock);
 struct NntpData *mutt_newsgroup_subscribe(struct NntpServer *nserv, char *group);
 struct NntpData *mutt_newsgroup_unsubscribe(struct NntpServer *nserv, char *group);
@@ -179,13 +150,12 @@ const char *nntp_format_str(char *buf, size_t buflen, size_t col, int cols, char
                             const char *src, const char *prec, const char *if_str,
                             const char *else_str, unsigned long data, enum FormatFlag flags);
 
+void nntp_article_status(struct Context *ctx, struct Header *hdr, char *group, anum_t anum);
+
 extern struct NntpServer *CurrentNewsSrv;
 
-#ifdef USE_HCACHE
-header_cache_t *nntp_hcache_open(struct NntpData *nntp_data);
-void nntp_hcache_update(struct NntpData *nntp_data, header_cache_t *hc);
-#endif
+int nntp_compare_order(const void *a, const void *b);
 
 extern struct MxOps mx_nntp_ops;
 
-#endif /* _MUTT_NNTP_H */
+#endif /* _NNTP_NNTP_H */
diff --git a/nntp/nntp_private.h b/nntp/nntp_private.h
new file mode 100644 (file)
index 0000000..feb946e
--- /dev/null
@@ -0,0 +1,66 @@
+/**
+ * @file
+ * Usenet network mailbox type; talk to an NNTP server
+ *
+ * @authors
+ * Copyright (C) 2018 Richard Russon <rich@flatcap.org>
+ *
+ * @copyright
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _NNTP_PRIVATE_H
+#define _NNTP_PRIVATE_H
+
+#ifdef USE_HCACHE
+#include "hcache/hcache.h"
+#endif
+
+struct Context;
+struct Header;
+struct NntpData;
+struct NntpServer;
+
+#define NNTP_PORT 119
+#define NNTP_SSL_PORT 563
+
+/**
+ * enum NntpStatus - NNTP server return values
+ */
+enum NntpStatus
+{
+  NNTP_NONE = 0,
+  NNTP_OK,
+  NNTP_BYE
+};
+
+#define NHDR(hdr) ((struct NntpHeaderData *) ((hdr)->data))
+
+void nntp_acache_free(struct NntpData *nntp_data);
+int  nntp_active_save_cache(struct NntpServer *nserv);
+int  nntp_add_group(char *line, void *data);
+void nntp_bcache_update(struct NntpData *nntp_data);
+int  nntp_check_new_groups(struct NntpServer *nserv);
+void nntp_data_free(void *data);
+void nntp_delete_group_cache(struct NntpData *nntp_data);
+void nntp_group_unread_stat(struct NntpData *nntp_data);
+void nntp_newsrc_gen_entries(struct Context *ctx);
+int  nntp_open_connection(struct NntpServer *nserv);
+
+#ifdef USE_HCACHE
+header_cache_t *nntp_hcache_open(struct NntpData *nntp_data);
+void nntp_hcache_update(struct NntpData *nntp_data, header_cache_t *hc);
+#endif
+
+#endif /* _NNTP_PRIVATE_H */
diff --git a/pager.c b/pager.c
index 5847cd3ea574e327ef7c7254bca32b4439128182..470ed2a7accf5e794e3ac6641ccc4d0b0e4bad13 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -58,7 +58,7 @@
 #include "sidebar.h"
 #endif
 #ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
 #endif
 #ifdef ENABLE_NLS
 #include <libintl.h>
index e35b136c76f3c12efedf4f4ef00b44c414fc90f4..27c972c4f48127fc437b8cb8c69ec43f41c3d073 100644 (file)
@@ -117,8 +117,8 @@ ncrypt/pgplib.c
 ncrypt/pgpmicalg.c
 ncrypt/pgppacket.c
 ncrypt/smime.c
-newsrc.c
-nntp.c
+nntp/newsrc.c
+nntp/nntp.c
 opcodes.h
 pager.c
 parse.c
diff --git a/send.c b/send.c
index 5c3e61a33a10f4b3862b4f5144fb12a3f25b9ef7..4d434f279a7bf1bde93851228867d63b6c1b231b 100644 (file)
--- a/send.c
+++ b/send.c
@@ -50,7 +50,7 @@
 #include "url.h"
 #ifdef USE_NNTP
 #include "mx.h"
-#include "nntp.h"
+#include "nntp/nntp.h"
 #endif
 #ifdef MIXMASTER
 #include "remailer.h"
index 23a3e5d57905d6a5ec65f7181aa5dd7543c001e3..78cb889bdbb1d7933a6c8e7e45ab0703bc03d0ab 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -57,7 +57,7 @@
 #include "rfc2231.h"
 #include "state.h"
 #ifdef USE_NNTP
-#include "nntp.h"
+#include "nntp/nntp.h"
 #endif
 #ifdef HAVE_SYSEXITS_H
 #include <sysexits.h>
diff --git a/sort.c b/sort.c
index 825d1823dacf81cc9ec8bda8ec91ee4e696fe4e0..33467eaf27b0cdf09cc3de60c75ebb24cbfb084b 100644 (file)
--- a/sort.c
+++ b/sort.c
 #include "protos.h"
 #ifdef USE_NNTP
 #include "mx.h"
-#include "nntp.h"
+#include "nntp/nntp.h"
 #endif
 
-#define SORTCODE(x) (Sort & SORT_REVERSE) ? -(x) : x
-
 /* function to use as discriminator when normal sort method is equal */
 static sort_t *AuxSort = NULL;
 
-static int perform_auxsort(int retval, const void *a, const void *b)
+int perform_auxsort(int retval, const void *a, const void *b)
 {
   /* If the items compared equal by the main sort
    * and we're not already doing an 'aux' sort...  */
@@ -164,19 +162,8 @@ static int compare_order(const void *a, const void *b)
   struct Header **ha = (struct Header **) a;
   struct Header **hb = (struct Header **) b;
 
-#ifdef USE_NNTP
-  if (Context && Context->magic == MUTT_NNTP)
-  {
-    anum_t na = NHDR(*ha)->article_num;
-    anum_t nb = NHDR(*hb)->article_num;
-    int result = na == nb ? 0 : na > nb ? 1 : -1;
-    result = perform_auxsort(result, a, b);
-    return (SORTCODE(result));
-  }
-  else
-#endif
-    /* no need to auxsort because you will never have equality here */
-    return (SORTCODE((*ha)->index - (*hb)->index));
+  /* no need to auxsort because you will never have equality here */
+  return (SORTCODE((*ha)->index - (*hb)->index));
 }
 
 static int compare_spam(const void *a, const void *b)
@@ -276,6 +263,11 @@ sort_t *mutt_get_sort_func(int method)
     case SORT_LABEL:
       return compare_label;
     case SORT_ORDER:
+#ifdef USE_NNTP
+      if (Context && (Context->magic == MUTT_NNTP))
+        return nntp_compare_order;
+      else
+#endif
       return compare_order;
     case SORT_RECEIVED:
       return compare_date_received;
diff --git a/sort.h b/sort.h
index 393a9eba0b14f750e071fb3d30fb752d77f57ae8..47059498cfea3c910a1493bafd3419fcac46560e 100644 (file)
--- a/sort.h
+++ b/sort.h
@@ -67,11 +67,14 @@ struct Context;
 #define SORT_REVERSE (1 << 8)
 #define SORT_LAST    (1 << 9)
 
+#define SORTCODE(x) (Sort & SORT_REVERSE) ? -(x) : x
+
 typedef int sort_t(const void *a, const void *b);
 sort_t *mutt_get_sort_func(int method);
 
 void mutt_sort_headers(struct Context *ctx, int init);
 int mutt_select_sort(int reverse);
+int perform_auxsort(int retval, const void *a, const void *b);
 
 extern const struct Mapping SortMethods[];