* please see the file GPL in the top level source directory.
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include <lib-lib/lib-lib.h>
-#include <lib-lib/mem.h>
-#include <lib-lib/str.h>
-#include <lib-lib/macros.h>
+#include <libgen.h>
+
+#include <lib-mime/mime.h>
+#include <lib-ui/curses.h>
+#include <lib-mx/mx.h>
#include "mutt.h"
-#include "mutt_curses.h"
#include "sort.h"
-#include "mx.h"
-#include "mime.h"
#include "nntp.h"
-#include "rfc822.h"
-#include "rfc1524.h"
-#include "rfc2047.h"
-
-#include "lib/debug.h"
-
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <libgen.h>
-#include <sys/stat.h>
void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d)
{
- LIST *l;
+ string_list_t *l;
if (!s || !d)
return;
- l = p_new(LIST, 1);
+ l = p_new(string_list_t, 1);
if (s->list)
s->tail->next = l;
else
char group[LONG_STRING];
int x = 1;
char *p = line, *b, *h;
- size_t len;
+ ssize_t len;
while (*p) {
if (*p++ == ',')
p++;
if (!*p)
return -1;
- len = p + 1 - line;
- if (len > sizeof (group))
- len = sizeof (group);
- strfcpy (group, line, len);
+ 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);
data->group = (char *) data + sizeof (NNTP_DATA);
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
data->lastMessage = data->entries[x - 1].last;
data->num = x;
mutt_newsgroup_stat (data);
- debug_print (2, ("Newsgroup %s\n", data->group));
return 0;
}
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;
}
p_delete(&buf);
mx_unlock_file (news->newsrc, fileno (fp), 0);
- fclose (fp);
+ m_fclose(&fp);
return 0;
}
struct stat st;
char buf[HUGE_STRING], *cp;
char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX];
- FILE *index;
+ FILE *idx;
NNTP_DATA *data;
int l, m, t;
if (!NewsCacheDir || !*NewsCacheDir)
return 0;
- strfcpy (dir, NewsCacheDir, sizeof (dir));
+ m_strcpy(dir, sizeof(dir), NewsCacheDir);
mutt_expand_path (dir, sizeof (dir));
if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0) {
p_delete(&news->cache);
snprintf (buf, sizeof (buf), "%s/.index", dir);
- if (!(index = safe_fopen (buf, "a+")))
+ if (!(idx = safe_fopen (buf, "a+")))
return 0;
- rewind (index);
- while (fgets (buf, sizeof (buf), index)) {
+ rewind (idx);
+ while (fgets (buf, sizeof (buf), idx)) {
buf[m_strlen(buf) - 1] = 0; /* strip ending '\n' */
- if (!str_ncmp (buf, "#: ", 3) &&
- !str_casecmp (buf + 3, news->conn->account.host))
+ if (!m_strncmp(buf, "#: ", 3) &&
+ !m_strcasecmp(buf + 3, news->conn->account.host))
break;
}
- while (fgets (buf, sizeof (buf), index)) {
+ while (fgets (buf, sizeof (buf), idx)) {
cp = buf;
while (*cp && *cp != ' ')
cp++;
if (!*cp)
continue;
cp[0] = 0;
- if (!str_cmp (buf, "#:"))
+ if (!m_strcmp(buf, "#:"))
break;
sscanf (cp + 1, "%s %d %d", file, &l, &m);
- if (!str_cmp (buf, "ALL")) {
+ if (!m_strcmp(buf, "ALL")) {
news->cache = m_strdup(file);
news->newgroups_time = m;
}
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);
mutt_newsgroup_stat (data);
}
}
- fclose (index);
+ m_fclose(&idx);
return 0;
}
-const char *nntp_format_str (char *dest, size_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':
- strncpy (fn, NewsServer, sizeof (fn) - 1);
- str_tolower (fn);
+ m_strcpy(fn, sizeof (fn), NewsServer);
+ m_strtolower(fn);
snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
snprintf (dest, destlen, tmp, fn);
break;
/* nntp_parse_url: given an NNPT URL, return host, port,
* username, password and newsgroup will recognise. */
-int nntp_parse_url (const char *server, ACCOUNT * acct,
- char *group, size_t group_len)
+int nntp_parse_url (const char *server, ACCOUNT * act,
+ char *group, ssize_t group_len)
{
ciss_url_t url;
char *c;
int ret = -1;
/* Defaults */
- acct->flags = 0;
- acct->port = NNTP_PORT;
- acct->type = M_ACCT_TYPE_NNTP;
+ act->flags = 0;
+ act->port = NNTP_PORT;
+ act->type = M_ACCT_TYPE_NNTP;
c = m_strdup(server);
url_parse_ciss (&url, c);
if (url.scheme == U_NNTP || url.scheme == U_NNTPS) {
if (url.scheme == U_NNTPS) {
- acct->flags |= M_ACCT_SSL;
- acct->port = NNTP_SSL_PORT;
+ act->has_ssl = 1;
+ act->port = NNTP_SSL_PORT;
}
*group = '\0';
if (url.path)
- strfcpy (group, url.path, group_len);
+ m_strcpy(group, group_len, url.path);
- ret = mutt_account_fromurl (acct, &url);
+ ret = mutt_account_fromurl (act, &url);
}
p_delete(&c);
return ret;
}
-void nntp_expand_path (char *line, size_t len, ACCOUNT * acct)
+void nntp_expand_path (char *line, ssize_t len, ACCOUNT * act)
{
ciss_url_t url;
url.path = m_strdup(line);
- mutt_account_tourl (acct, &url);
+ mutt_account_tourl (act, &url);
url_ciss_tostring (&url, line, len, 0);
p_delete(&url.path);
}
{
char file[_POSIX_PATH_MAX];
char *buf, *p;
- LIST *list;
- ACCOUNT acct;
+ string_list_t *list;
+ ACCOUNT act;
NNTP_SERVER *serv;
CONNECTION *conn;
- p_clear(&acct, 1);
+ p_clear(&act, 1);
if (!server || !*server) {
mutt_error _("No newsserver defined!");
}
strcpy (p, server);
- if ((nntp_parse_url (buf, &acct, file, sizeof (file))) < 0 || *file) {
+ if ((nntp_parse_url (buf, &act, file, sizeof (file))) < 0 || *file) {
p_delete(&buf);
mutt_error (_("%s is an invalid newsserver specification!"), server);
return NULL;
}
p_delete(&buf);
- conn = mutt_conn_find (NULL, &acct);
+ conn = mutt_conn_find (NULL, &act);
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) {
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;
- mutt_free_list (&serv->list);
+ string_list_wipe(&serv->list);
p_delete(&serv->newsrc);
p_delete(&serv->cache);
p_delete(&serv);
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;
}
}
static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf,
- char **pline, size_t * buflen)
+ char **pline, ssize_t * buflen)
{
char *line = *pline;
- size_t len = *buflen - (*pline - *buf);
+ ssize_t len = *buflen - (*pline - *buf);
int x, i;
if (len < LONG_STRING * 10) {
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;
line += i;
len -= i;
}
-#endif
}
*line++ = '\n';
*line = '\0';
}
static int mutt_update_list_file (char *filename, char *section,
- char *key, char *line) {
+ const char *key, char *line) {
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
*/
- strncpy (buf, filename, sizeof (buf));
- strncpy (tmpfile, basename (filename), sizeof (tmpfile));
- 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);
+ m_strcpy(buf, sizeof(buf), filename);
+ 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;
}
c = buf;
while (*c && *c != '\n') c++;
c[0] = 0; /* strip EOL */
- if (!strncmp (buf, "#: ", 3) && !str_casecmp (buf+3, section))
+ if (!strncmp (buf, "#: ", 3) && !m_strcasecmp(buf+3, section))
done++;
}
if (r != EOF && !done) {
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;
{
char *buf, *line;
NNTP_DATA *data;
- LIST *tmp;
+ string_list_t *tmp;
int r = -1;
- size_t len, llen;
+ ssize_t len, llen;
if (!news)
return -1;
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 */
if (news->newsrc &&
- (r = mutt_update_list_file (news->newsrc, NULL, "", buf)) == 0) {
+ (r = mutt_update_list_file(news->newsrc, NULL, "", buf)) == 0) {
struct stat st;
stat (news->newsrc, &st);
/* Updates info into .index file: ALL or about selected newsgroup */
static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data)
{
- char buf[LONG_STRING], *key = "ALL";
+ char buf[LONG_STRING];
char file[_POSIX_PATH_MAX];
+ const char *key = "ALL";
if (!serv || !serv->conn || !serv->conn->account.host)
return -1;
data->firstMessage, data->lastLoaded);
}
else {
- strfcpy (file, serv->cache, sizeof (file));
+ m_strcpy(file, sizeof(file), serv->cache);
snprintf (buf, sizeof (buf), "ALL %s 0 %d", file,
(int) serv->newgroups_time);
}
void nntp_clear_cacheindex (NNTP_SERVER * news)
{
NNTP_DATA *data;
- LIST *tmp;
+ string_list_t *tmp;
if (option (OPTSAVEUNSUB) || !news)
return;
if (!data || data->subscribed || !data->cache)
continue;
nntp_delete_cache (data);
- debug_print (2, ("Removed from .index: %s\n", data->group));
}
return;
}
char file[_POSIX_PATH_MAX];
NNTP_DATA *d;
FILE *f;
- LIST *l;
+ string_list_t *l;
if (!news || !news->newsgroups)
return -1;
f = safe_fopen (file, "w");
}
else {
- strfcpy (buf, news->conn->account.host, sizeof (buf));
+ m_strcpy(buf, sizeof(buf), news->conn->account.host);
f = mutt_mkname (buf);
news->cache = m_strdup(buf);
nntp_cache_expand (file, buf);
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);
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",
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;
}
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)) {
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) {
}
/* this routine gives the first newsgroup with new messages */
-void nntp_buffy (char* dst, size_t dstlen) {
- LIST *list;
+void nntp_buffy (char* dst, ssize_t dstlen) {
+ string_list_t *list;
int count = 0;
/* forward to current group */
NNTP_DATA *data = (NNTP_DATA *) list->data;
if (data && data->subscribed && data->unread &&
Context && Context->magic == M_NNTP &&
- str_cmp (data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
+ m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
list = list->next;
break;
}
if (data && data->subscribed && data->unread) {
if (Context && Context->magic == M_NNTP &&
- !str_cmp (data->group, ((NNTP_DATA *) Context->data)->group)) {
+ !m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group)) {
unsigned int i, unread = 0;
for (i = 0; i < Context->msgcount; i++)
if (!unread)
continue;
}
- strncpy (dst, data->group, dstlen);
+ m_strcpy(dst, dstlen, data->group);
break;
}
}