remove OPTNEWSCACHE, style.
authorPierre Habouzit <madcoder@debian.org>
Mon, 28 May 2007 10:57:09 +0000 (12:57 +0200)
committerPierre Habouzit <madcoder@debian.org>
Mon, 28 May 2007 10:57:09 +0000 (12:57 +0200)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
mutt.h
nntp.c

diff --git a/mutt.h b/mutt.h
index 0993bcc..df6c5f8 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -346,7 +346,6 @@ enum {
 #ifdef USE_NNTP
   OPTNEWS,                      /* (pseudo) used to change reader mode */
   OPTNEWSSEND,                  /* (pseudo) used to change behavior when posting */
 #ifdef USE_NNTP
   OPTNEWS,                      /* (pseudo) used to change reader mode */
   OPTNEWSSEND,                  /* (pseudo) used to change behavior when posting */
-  OPTNEWSCACHE,                 /* (pseudo) used to indicate if news cache exist */
 #endif
   OPTSHORTENHIERARCHY,          /* set when to shorten "hierarchies" in the sidebar */
   OPTSIDEBARNEWMAILONLY,
 #endif
   OPTSHORTENHIERARCHY,          /* set when to shorten "hierarchies" in the sidebar */
   OPTSIDEBARNEWMAILONLY,
diff --git a/nntp.c b/nntp.c
index 604b5d1..eb5cd42 100644 (file)
--- a/nntp.c
+++ b/nntp.c
 #define NNTP_PORT      119
 #define NNTP_SSL_PORT  563
 
 #define NNTP_PORT      119
 #define NNTP_SSL_PORT  563
 
-static unsigned int _checked = 0;
+static struct {
+    unsigned use_cache : 1;
+
+    int  checked;
+} nntp = { true, 0 };
 
 static int nntp_check_newgroups (nntp_server_t *, int);
 
 
 static int nntp_check_newgroups (nntp_server_t *, int);
 
@@ -143,69 +147,79 @@ static int slurp_newsrc (nntp_server_t * news)
  * and newsgroup cache names */
 static int nntp_parse_cacheindex(nntp_server_t *news)
 {
  * and newsgroup cache names */
 static int nntp_parse_cacheindex(nntp_server_t *news)
 {
-  nntp_data_t *data;
-  char file[_POSIX_PATH_MAX], buf[HUGE_STRING], *cp;
-  FILE *idx;
-  int l, m, t;
+    char buf[HUGE_STRING];
+    FILE *idx;
+
+    p_delete(&news->cache);
+    if (m_strisempty(mod_core.cachedir))
+        return 0;
+
+    nntp_cache_expand(buf, sizeof(buf), "%s.index", news->conn->account.host);
+    if (!(idx = safe_fopen(buf, "a+")))
+        return 0;
+    rewind(idx);
+
+    while (fgets(buf, sizeof(buf), idx)) {
+        buf[m_strlen(buf) - 1] = 0;  /* strip ending '\n' */
+        if (!m_strncmp(buf, "#: ", 3)
+        &&  !m_strcasecmp(buf + 3, news->conn->account.host)) {
+            break;
+        }
+    }
 
 
-  if (m_strisempty(mod_core.cachedir)) {
-    unset_option(OPTNEWSCACHE);
-    return 0;
-  } else {
-    set_option(OPTNEWSCACHE);
-  }
+    while (fgets(buf, sizeof(buf), idx)) {
+        char *p, *q;
+        int l, m, t;
 
 
-  p_delete(&news->cache);
-  nntp_cache_expand(buf, sizeof(buf), "%s.index", news->conn->account.host);
-  if (!(idx = safe_fopen (buf, "a+")))
-    return 0;
-  rewind (idx);
-  while (fgets (buf, sizeof (buf), idx)) {
-    buf[m_strlen(buf) - 1] = 0;  /* strip ending '\n' */
-    if (!m_strncmp(buf, "#: ", 3) &&
-        !m_strcasecmp(buf + 3, news->conn->account.host))
-      break;
-  }
-  while (fgets (buf, sizeof (buf), idx)) {
-    cp = buf;
-    while (*cp && *cp != ' ')
-      cp++;
-    if (!*cp)
-      continue;
-    cp[0] = 0;
-    if (!m_strcmp(buf, "#:"))
-      break;
-    sscanf (cp + 1, "%s %d %d", file, &l, &m);
-    if (!m_strcmp(buf, "ALL")) {
-      news->cache = m_strdup(file);
-      news->newgroups_time = m;
-    }
-    else if (news->newsgroups) {
-      if ((data = hash_find (news->newsgroups, buf)) == NULL) {
-        data = nntp_data_new();
-        data->group = m_strdup(buf);
-        data->nserv = news;
-        data->deleted = 1;
-        if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
-            hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
-        hash_insert (news->newsgroups, data->group, data);
-        nntp_data_list_append(&news->list, data);
-      }
-      data->cache = m_strdup(file);
-      t = 0;
-      if (!data->firstMessage || data->lastMessage < m)
-        t = 1;
-      if (!data->firstMessage)
-        data->firstMessage = l;
-      if (data->lastMessage < m)
-        data->lastMessage = m;
-      data->lastCached = m;
-      if (t || !data->unread)
-        mutt_newsgroup_stat (data);
+        if (m_strstart(buf, "#:", NULL))
+            break;
+
+        p = strchrnul(buf, ' ');
+        if (!*p)
+            continue;
+        *p++ = '\0';
+        p = vskipspaces(p);
+        q = strchrnul(p, ' ');
+        if (!*q)
+            continue;
+        *q++ = '\0';
+        l = strtol(q, &q, 10);
+        m = strtol(q, &q, 10);
+
+        if (!m_strcmp(buf, "ALL")) {
+            m_strreplace(&news->cache, m_strdup(p));
+            news->newgroups_time = m;
+            continue;
+        }
+
+        if (news->newsgroups) {
+            nntp_data_t *data = hash_find(news->newsgroups, buf);
+
+            if (!data) {
+                data = nntp_data_new();
+                data->group = m_strdup(buf);
+                data->nserv = news;
+                data->deleted = 1;
+                if (news->newsgroups->nelem < news->newsgroups->curnelem * 2)
+                    hash_resize (news->newsgroups, news->newsgroups->nelem * 2);
+                hash_insert (news->newsgroups, data->group, data);
+                nntp_data_list_append(&news->list, data);
+            }
+            m_strreplace(&data->cache, p);
+
+            t = !data->firstMessage || data->lastMessage < m;
+            if (!data->firstMessage)
+                data->firstMessage = l;
+            if (data->lastMessage < m)
+                data->lastMessage = m;
+            data->lastCached = m;
+            if (t || !data->unread)
+                mutt_newsgroup_stat(data);
+        }
     }
     }
-  }
-  m_fclose(&idx);
-  return 0;
+
+    m_fclose(&idx);
+    return 0;
 }
 
 /* nntp_parse_url: given an NNPT URL, return host, port,
 }
 
 /* nntp_parse_url: given an NNPT URL, return host, port,
@@ -260,8 +274,8 @@ static int add_group (char *buf, void *serv)
   nntp_data_t *nntp_data;
   static int n = 0;
 
   nntp_data_t *nntp_data;
   static int n = 0;
 
-  _checked = n;                 /* _checked have N, where N = number of groups */
-  if (!buf)                     /* at EOF must be zerouth */
+  nntp.checked = n;       /* nntp.checked have N, where N = number of groups */
+  if (!buf)               /* at EOF must be zerouth */
     n = 0;
 
   if (!s || !buf)
     n = 0;
 
   if (!s || !buf)
@@ -405,7 +419,7 @@ nntp_server_t *mutt_select_newsserver (char *server)
   serv->newsgroups = hash_new(1009, false);
   slurp_newsrc (serv);          /* load .newsrc */
   nntp_parse_cacheindex (serv); /* load .index */
   serv->newsgroups = hash_new(1009, false);
   slurp_newsrc (serv);          /* load .newsrc */
   nntp_parse_cacheindex (serv); /* load .index */
-  if (option (OPTNEWSCACHE) && serv->cache && nntp_get_cache_all (serv) >= 0)
+  if (nntp.use_cache && serv->cache && nntp_get_cache_all (serv) >= 0)
     nntp_check_newgroups (serv, 1);
   else if (nntp_get_active (serv) < 0) {
     hash_delete(&serv->newsgroups, NULL);
     nntp_check_newgroups (serv, 1);
   else if (nntp_get_active (serv) < 0) {
     hash_delete(&serv->newsgroups, NULL);
@@ -737,7 +751,7 @@ static void nntp_delete_cache (nntp_data_t * data)
 {
   char buf[_POSIX_PATH_MAX];
 
 {
   char buf[_POSIX_PATH_MAX];
 
-  if (!option (OPTNEWSCACHE) || !data || !data->cache || !data->nserv)
+  if (!nntp.use_cache || !data || !data->cache || !data->nserv)
     return;
 
   nntp_cache_expand(buf, ssizeof(buf), "%s", data->cache);
     return;
 
   nntp_cache_expand(buf, ssizeof(buf), "%s", data->cache);
@@ -775,7 +789,7 @@ static int nntp_save_cache_index (nntp_server_t * news)
 
   if (!news || !news->newsgroups)
     return -1;
 
   if (!news || !news->newsgroups)
     return -1;
-  if (!option (OPTNEWSCACHE))
+  if (!nntp.use_cache)
     return 0;
 
   if (news->cache) {
     return 0;
 
   if (news->cache) {
@@ -826,7 +840,7 @@ static int nntp_save_cache_group (CONTEXT * ctx)
   int i = 0, save = SORT_ORDER;
   int prev = 0;
 
   int i = 0, save = SORT_ORDER;
   int prev = 0;
 
-  if (!option (OPTNEWSCACHE))
+  if (!nntp.use_cache)
     return 0;
   if (!ctx || !ctx->data || ctx->magic != M_NNTP)
     return -1;
     return 0;
   if (!ctx || !ctx->data || ctx->magic != M_NNTP)
     return -1;
@@ -1676,7 +1690,7 @@ static int nntp_fetch_headers(CONTEXT * ctx, int first, int last)
 
   /* CACHE: must be loaded xover cache here */
   num = nntp_data->lastCached - first + 1;
 
   /* CACHE: must be loaded xover cache here */
   num = nntp_data->lastCached - first + 1;
-  if (option (OPTNEWSCACHE) && nntp_data->cache && num > 0) {
+  if (nntp.use_cache && nntp_data->cache && num > 0) {
   nntp_cache_expand(buf, ssizeof(buf), "%s", nntp_data->cache);
   mutt_message (msg2);
 
   nntp_cache_expand(buf, ssizeof(buf), "%s", nntp_data->cache);
   mutt_message (msg2);
 
@@ -2249,7 +2263,7 @@ static int nntp_check_newgroups (nntp_server_t * serv, int force)
   if (*emp)
     nntp_save_cache_index(serv);
   mutt_clear_error();
   if (*emp)
     nntp_save_cache_index(serv);
   mutt_clear_error();
-  return _checked;
+  return nntp.checked;
 }
 
 /* Load list of all newsgroups from active */
 }
 
 /* Load list of all newsgroups from active */
@@ -2290,7 +2304,7 @@ int nntp_get_active (nntp_server_t * serv)
   nntp_save_cache_index (serv);
 
   mutt_clear_error ();
   nntp_save_cache_index (serv);
 
   mutt_clear_error ();
-  return _checked;
+  return nntp.checked;
 }
 
 /*
 }
 
 /*
@@ -2377,9 +2391,9 @@ int nntp_check_children (CONTEXT * ctx, const char *msgid)
    * made sure that we dont have the article, so we need to visit
    * the server. Reading the cache at this point is also bad
    * because it would duplicate messages */
    * made sure that we dont have the article, so we need to visit
    * the server. Reading the cache at this point is also bad
    * because it would duplicate messages */
-  if (option (OPTNEWSCACHE)) {
+  if (nntp.use_cache) {
     tmp++;
     tmp++;
-    unset_option (OPTNEWSCACHE);
+    nntp.use_cache = false;
   }
   for (i = 0; i < cc.num; i++) {
     if ((ret = nntp_fetch_headers (ctx, cc.child[i], cc.child[i])))
   }
   for (i = 0; i < cc.num; i++) {
     if ((ret = nntp_fetch_headers (ctx, cc.child[i], cc.child[i])))
@@ -2389,7 +2403,7 @@ int nntp_check_children (CONTEXT * ctx, const char *msgid)
       ctx->hdrs[ctx->msgcount - 1]->read = 0;
   }
   if (tmp)
       ctx->hdrs[ctx->msgcount - 1]->read = 0;
   }
   if (tmp)
-    set_option (OPTNEWSCACHE);
+    nntp.use_cache = true;
   p_delete(&cc.child);
   return ret;
 }
   p_delete(&cc.child);
   return ret;
 }