X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=nntp.c;h=52a549202a462d6f781d6decd387a71e776b37d9;hp=a533933ff0c92b1bf4c3a5d698234f1f1c9e3d78;hb=8f8c3e5bf47de967410f7acfd98bd33215ef3cea;hpb=94d1107856bbba2b77fbd3c0512b9e18f6ed574b diff --git a/nntp.c b/nntp.c index a533933..52a5492 100644 --- a/nntp.c +++ b/nntp.c @@ -47,12 +47,11 @@ static void mutt_newsgroup_stat(nntp_data_t *data) for (int i = 0; i < data->num; i++) { int first = MAX(data->entries[i].first, data->firstMessage); int last = MIN(data->entries[i].last, data->lastMessage); - if (first <= last) - data->unread -= last - first + 1; + data->unread -= MAX(0, last - first + 1); } } -static int nntp_parse_newsrc_line(nntp_server_t * news, const char *line) +static int nntp_parse_newsrc_line(nntp_server_t *news, const char *line) { nntp_data_t *data; char group[LONG_STRING]; @@ -74,8 +73,6 @@ static int nntp_parse_newsrc_line(nntp_server_t * news, const char *line) data->group = p_dupstr(line, p - line); 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); news->tail = nntp_data_list_append(news->tail, data); } else { @@ -86,18 +83,19 @@ static int nntp_parse_newsrc_line(nntp_server_t * news, const char *line) data->entries = p_new(NEWSRC_ENTRY, x * 2); data->max = x * 2; data->subscribed = (*p++ == ':'); + p = skipspaces(p); for (x = 0; *p; p++) { - p = skipspaces(p); data->entries[x].first = strtol(p, (char **)&p, 10); - p = skipspaces(p); + p += strcspn(p, "-,"); if (*p == '-') { + if (!*p) + break; data->entries[x].last = strtol(p + 1, (char **)&p, 10); } else { data->entries[x].last = data->entries[x].first; + p = strchrnul(p, ','); } - - p = strchrnul(p, ','); x += data->entries[x].last != 0; } @@ -201,8 +199,6 @@ static int nntp_parse_cacheindex(nntp_server_t *news) 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); news->tail = nntp_data_list_append(news->tail, data); } @@ -225,36 +221,29 @@ static int nntp_parse_cacheindex(nntp_server_t *news) /* nntp_parse_url: given an NNPT URL, return host, port, * username, password and newsgroup will recognise. */ -static int nntp_parse_url(const char *server, ACCOUNT * act, char *group, +static int nntp_parse_url(const char *server, ACCOUNT *act, char *group, ssize_t group_len) { - ciss_url_t url; - char *c; - int ret = -1; + ciss_url_t url; + char s[STRING]; - /* Defaults */ - act->flags = 0; - act->port = NNTP_PORT; - act->type = M_ACCT_TYPE_NNTP; + act->flags = 0; + act->port = 0; + 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) { - act->has_ssl = 1; - act->port = NNTP_SSL_PORT; - } + m_strcpy(s, sizeof(s), server); + url_parse_ciss(&url, s); - *group = '\0'; - if (url.path) - m_strcpy(group, group_len, url.path); + if (url.scheme != U_NNTP || url.scheme != U_NNTPS) + return -1; - ret = mutt_account_fromurl (act, &url); - } + act->has_ssl = (url.scheme == U_NNTPS); + if (!act->port) { + act->port = act->has_ssl ? NNTP_PORT : NNTP_SSL_PORT; + } + m_strcpy(group, group_len, url.path); - p_delete(&c); - return ret; + return mutt_account_fromurl(act, &url); } void nntp_expand_path (char *line, ssize_t len, ACCOUNT * act) @@ -291,8 +280,6 @@ static int add_group (char *buf, void *serv) nntp_data = nntp_data_new(); nntp_data->group = m_strdup(group); nntp_data->nserv = s; - if (s->newsgroups->nelem < s->newsgroups->curnelem * 2) - hash_resize (s->newsgroups, s->newsgroups->nelem * 2); hash_insert(s->newsgroups, nntp_data->group, nntp_data); s->tail = nntp_data_list_append(s->tail, nntp_data); } @@ -908,8 +895,6 @@ nntp_data_t *mutt_newsgroup_subscribe (nntp_server_t * news, char *group) data->group = m_strdup(group); 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); news->tail = nntp_data_list_append(news->tail, data); }