X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=nntp%2Fnewsrc.c;h=0eac04017c9c65d2f1b9c0241f4958efea5967f5;hp=e9709f74f15a4748a9a5e237fbc9c25ee494f4b3;hb=4e846802eb1912873b56a27644215e6eeb91dc76;hpb=ac813896ca32d850febc2d95065ac4fa040f11f9 diff --git a/nntp/newsrc.c b/nntp/newsrc.c index e9709f7..0eac040 100644 --- a/nntp/newsrc.c +++ b/nntp/newsrc.c @@ -9,32 +9,17 @@ * please see the file GPL in the top level source directory. */ -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include +#include -#include -#include -#include -#include -#include +#include #include - #include +#include #include "mutt.h" #include "sort.h" -#include "mx.h" #include "nntp.h" -#include "rfc1524.h" void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d) { @@ -70,9 +55,7 @@ static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line) p++; if (!*p) return -1; - len = p + 1 - line; - if (len > sizeof (group)) - len = sizeof (group); + len = MIN(p + 1 - line, ssizeof(group)); m_strcpy(group, len, line); if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) { data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1); @@ -81,9 +64,8 @@ static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line) data->nserv = news; data->deleted = 1; if (news->newsgroups->nelem < news->newsgroups->curnelem * 2) - news->newsgroups = hash_resize (news->newsgroups, news->newsgroups->nelem * 2); - hash_insert (news->newsgroups, data->group, data, 0); + hash_insert (news->newsgroups, data->group, data); nntp_add_to_list (news, data); } else @@ -126,7 +108,6 @@ static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line) data->lastMessage = data->entries[x - 1].last; data->num = x; mutt_newsgroup_stat (data); - debug_print (2, ("Newsgroup %s\n", data->group)); return 0; } @@ -145,7 +126,7 @@ static int slurp_newsrc (NNTP_SERVER * news) return -1; /* hmm, should we use dotlock? */ if (mx_lock_file (news->newsrc, fileno (fp), 0, 0, 1)) { - fclose (fp); + m_fclose(&fp); return -1; } @@ -155,7 +136,7 @@ static int slurp_newsrc (NNTP_SERVER * news) p_delete(&buf); mx_unlock_file (news->newsrc, fileno (fp), 0); - fclose (fp); + m_fclose(&fp); return 0; } @@ -233,9 +214,8 @@ static int nntp_parse_cacheindex (NNTP_SERVER * news) data->nserv = news; data->deleted = 1; if (news->newsgroups->nelem < news->newsgroups->curnelem * 2) - news->newsgroups = hash_resize (news->newsgroups, news->newsgroups->nelem * 2); - hash_insert (news->newsgroups, data->group, data, 0); + hash_insert (news->newsgroups, data->group, data); nntp_add_to_list (news, data); } data->cache = m_strdup(file); @@ -251,16 +231,18 @@ static int nntp_parse_cacheindex (NNTP_SERVER * news) mutt_newsgroup_stat (data); } } - fclose (idx); + m_fclose(&idx); return 0; } -const char *nntp_format_str (char *dest, ssize_t destlen, char op, - const char *src, const char *fmt, - const char *ifstring, const char *elsestring, - unsigned long data, format_flag flags) +const char *nntp_format_str(char *dest, ssize_t destlen, char op, + const char *src, const char *fmt, + const char *ifstr __attribute__((unused)), + const char *elstr __attribute__((unused)), + anytype data __attribute__((unused)), + format_flag flags __attribute__((unused))) { - char fn[SHORT_STRING], tmp[SHORT_STRING]; + char fn[STRING], tmp[STRING]; switch (op) { case 's': @@ -292,7 +274,7 @@ int nntp_parse_url (const char *server, ACCOUNT * act, if (url.scheme == U_NNTP || url.scheme == U_NNTPS) { if (url.scheme == U_NNTPS) { - act->flags |= M_ACCT_SSL; + act->has_ssl = 1; act->port = NNTP_SSL_PORT; } @@ -362,9 +344,8 @@ NNTP_SERVER *mutt_select_newsserver (char *server) if (!conn) return NULL; - mutt_FormatString (file, sizeof (file), NONULL (NewsRc), nntp_format_str, 0, - 0); - mutt_expand_path (file, sizeof (file)); + m_strformat(file, sizeof(file), 0, NewsRc, nntp_format_str, NULL, 0); + mutt_expand_path(file, sizeof(file)); serv = (NNTP_SERVER *) conn->data; if (serv) { @@ -397,13 +378,13 @@ NNTP_SERVER *mutt_select_newsserver (char *server) serv = p_new(NNTP_SERVER, 1); serv->conn = conn; serv->newsrc = m_strdup(file); - serv->newsgroups = hash_create (1009); + 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) nntp_check_newgroups (serv, 1); else if (nntp_get_active (serv) < 0) { - hash_destroy (&serv->newsgroups, nntp_delete_data); + hash_delete (&serv->newsgroups, nntp_delete_data); for (list = serv->list; list; list = list->next) list->data = NULL; string_list_wipe(&serv->list); @@ -437,10 +418,6 @@ void nntp_get_status (CONTEXT * ctx, HEADER * h, char *group, int article) data = (NNTP_DATA *) hash_find (data->nserv->newsgroups, group); if (!data) { -#ifdef DEBUG - if (group) - debug_print (3, ("newsgroup %s not found\n", group)); -#endif return; } @@ -464,8 +441,7 @@ void nntp_get_status (CONTEXT * ctx, HEADER * h, char *group, int article) void mutt_newsgroup_stat (NNTP_DATA * data) { - int i; - unsigned int first, last; + int i, first, last; data->unread = 0; if (data->lastMessage == 0 || data->firstMessage > data->lastMessage) @@ -533,15 +509,6 @@ static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf, len--; } -#if 0 - if (data->entries[x].first == data->entries[x].last) - snprintf (line, len, "%d%n", data->entries[x].first, &i); - else - snprintf (line, len, "%d-%d%n", - data->entries[x].first, data->entries[x].last, &i); - len -= i; - line += i; -#else i = puti (line, data->entries[x].first); line += i; len -= i; @@ -552,7 +519,6 @@ static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf, line += i; len -= i; } -#endif } *line++ = '\n'; *line = '\0'; @@ -563,7 +529,7 @@ void newsrc_gen_entries (CONTEXT * ctx) { NNTP_DATA *data = (NNTP_DATA *) ctx->data; int series, x; - unsigned int last = 0, first = 1; + int last = 0, first = 1; int save_sort = SORT_ORDER; if (Sort != SORT_ORDER) { @@ -633,35 +599,33 @@ static int mutt_update_list_file (char *filename, char *section, FILE *ifp; FILE *ofp; char buf[HUGE_STRING]; - char tmpfile[_POSIX_PATH_MAX], link[_POSIX_PATH_MAX]; + char tmpf[_POSIX_PATH_MAX], lnk[_POSIX_PATH_MAX]; char *c; int ext = 0, done = 0, r = 0, l = 0; /* if file not exist, create it */ if ((ifp = safe_fopen (filename, "a"))) - fclose (ifp); - debug_print (1, ("Opening %s\n", filename)); + m_fclose(&ifp); if (!(ifp = safe_fopen (filename, "r"))) { mutt_error (_("Unable to open %s for reading"), filename); return -1; } if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) { - fclose (ifp); + m_fclose(&ifp); mutt_error (_("Unable to lock %s"), filename); return -1; } - /* use mutt_adv_mktemp() to get a tempfile in the same + + /* use m_tempfile() to get a tempfile in the same * directory as filename is so that we can follow symlinks * via rename(2); as dirname(2) may modify its argument, * temporarily use buf as copy of it */ m_strcpy(buf, sizeof(buf), filename); - m_strcpy(tmpfile, sizeof(tmpfile), basename(filename)); - mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile)); - debug_print (1, ("Opening %s\n", tmpfile)); - if (!(ofp = fopen (tmpfile, "w"))) { - fclose (ifp); - mutt_error (_("Unable to open %s for writing"), tmpfile); + ofp = m_tempfile(tmpf, sizeof(tmpf), dirname(buf), filename); + if (!ofp) { + m_fclose(&ifp); + mutt_error (_("Unable to open %s for writing"), tmpf); return -1; } @@ -722,20 +686,19 @@ static int mutt_update_list_file (char *filename, char *section, r = fputc ('\n', ofp); } mx_unlock_file (filename, fileno (ifp), 0); - fclose (ofp); - fclose (ifp); + m_fclose(&ofp); + m_fclose(&ifp); if (r == EOF) { - unlink (tmpfile); - mutt_error (_("Can't write %s"), tmpfile); + unlink (tmpf); + mutt_error (_("Can't write %s"), tmpf); return -1; } - link[0] = '\0'; - if ((l = readlink (filename, link, sizeof (link)-1)) > 0) - link[l] = '\0'; - debug_print (1, ("Renaming %s to %s\n",tmpfile, l > 0 ? link : filename)); - if (rename (tmpfile, l > 0 ? link : filename) < 0) { - unlink (tmpfile); - mutt_error (_("Can't rename %s to %s"), tmpfile, l > 0 ? link : filename); + lnk[0] = '\0'; + if ((l = readlink (filename, lnk, sizeof(lnk)-1)) > 0) + lnk[l] = '\0'; + if (rename (tmpf, l > 0 ? lnk : filename) < 0) { + unlink (tmpf); + mutt_error (_("Can't rename %s to %s"), tmpf, l > 0 ? lnk : filename); return -1; } return 0; @@ -759,7 +722,6 @@ int mutt_newsrc_update (NNTP_SERVER * news) if (!data || !data->rc) continue; nntp_create_newsrc_line (data, &buf, &line, &llen); - debug_print (2, ("Added to newsrc: %s\n", line)); line += m_strlen(line); } /* newrc being fully rewritten */ @@ -831,7 +793,6 @@ void nntp_clear_cacheindex (NNTP_SERVER * news) if (!data || data->subscribed || !data->cache) continue; nntp_delete_cache (data); - debug_print (2, ("Removed from .index: %s\n", data->group)); } return; } @@ -873,13 +834,13 @@ int nntp_save_cache_index (NNTP_SERVER * news) snprintf (buf, sizeof (buf), "%s %d %d %c\n", d->group, d->lastMessage, d->firstMessage, d->allowed ? 'y' : 'n'); if (fputs (buf, f) == EOF) { - fclose (f); + m_fclose(&f); unlink (file); return -1; } } } - fclose (f); + m_fclose(&f); if (nntp_update_cacheindex (news, NULL)) { unlink (file); @@ -933,7 +894,7 @@ int nntp_save_cache_group (CONTEXT * ctx) if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->article_num != prev) { h = ctx->hdrs[i]; addr[0] = 0; - rfc822_write_address (addr, sizeof (addr), h->env->from, 0); + rfc822_addrcat(addr, sizeof(addr), h->env->from, 0); tm = gmtime (&h->date_sent); snprintf (buf, sizeof (buf), "%d\t%s\t%s\t%d %s %d %02d:%02d:%02d GMT\t%s\t", @@ -946,7 +907,7 @@ int nntp_save_cache_group (CONTEXT * ctx) snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n", h->content->length, h->lines, NONULL (h->env->xref)); if (fputs (buf, f) == EOF) { - fclose (f); + m_fclose(&f); unlink (file); return -1; } @@ -958,7 +919,7 @@ int nntp_save_cache_group (CONTEXT * ctx) Sort = save; mutt_sort_headers (ctx, 0); } - fclose (f); + m_fclose(&f); if (nntp_update_cacheindex (((NNTP_DATA *) ctx->data)->nserv, (NNTP_DATA *) ctx->data)) { @@ -999,9 +960,8 @@ NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group) data->nserv = news; data->deleted = 1; if (news->newsgroups->nelem < news->newsgroups->curnelem * 2) - news->newsgroups = hash_resize (news->newsgroups, news->newsgroups->nelem * 2); - hash_insert (news->newsgroups, data->group, data, 0); + hash_insert (news->newsgroups, data->group, data); nntp_add_to_list (news, data); } if (!data->subscribed) { @@ -1105,7 +1065,7 @@ void nntp_buffy (char* dst, ssize_t dstlen) { if (data && data->subscribed && data->unread) { if (Context && Context->magic == M_NNTP && !m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group)) { - unsigned int i, unread = 0; + int i, unread = 0; for (i = 0; i < Context->msgcount; i++) if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted)