From 66940066b5771273920ec17ff08e60041b490951 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 27 May 2007 14:00:50 +0200 Subject: [PATCH] use nntp_data_new and stop hiding the group in the struct, useless win. Signed-off-by: Pierre Habouzit --- nntp.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/nntp.c b/nntp.c index d6054a3..9796e8c 100644 --- a/nntp.c +++ b/nntp.c @@ -50,15 +50,14 @@ static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line) return -1; m_strncpy(group, ssizeof(group), line, p - line); - if ((data = (nntp_data_t *) hash_find (news->newsgroups, group)) == NULL) { - data = xmalloc(sizeof(nntp_data_t) + m_strlen(group) + 1); - data->group = (char *) data + sizeof (nntp_data_t); - strcpy (data->group, group); + if ((data = hash_find(news->newsgroups, group)) == NULL) { + data = nntp_data_new(); + 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); + hash_insert(news->newsgroups, data->group, data); nntp_data_list_append(&news->list, data); } else { p_delete(&data->entries); @@ -196,10 +195,9 @@ static int nntp_parse_cacheindex (NNTP_SERVER * news) news->newgroups_time = m; } else if (news->newsgroups) { - if ((data = (nntp_data_t *) hash_find (news->newsgroups, buf)) == NULL) { - data = xmalloc(sizeof(nntp_data_t) + m_strlen(buf) + 1); - data->group = (char *) data + sizeof (nntp_data_t); - strcpy (data->group, buf); + 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) @@ -933,9 +931,8 @@ nntp_data_t *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group) if (!news || !news->newsgroups || !group || !*group) return NULL; if (!(data = (nntp_data_t *) hash_find (news->newsgroups, group))) { - data = xmalloc(sizeof(nntp_data_t) + m_strlen(group) + 1); - data->group = (char *) data + sizeof (nntp_data_t); - strcpy (data->group, group); + data = nntp_data_new(); + data->group = m_strdup(group); data->nserv = news; data->deleted = 1; if (news->newsgroups->nelem < news->newsgroups->curnelem * 2) @@ -1847,11 +1844,10 @@ static int nntp_open_mailbox (CONTEXT * ctx) CurrentNewsSrv = serv; /* create NNTP-specific state struct if nof found in list */ - if ((nntp_data = (nntp_data_t *) hash_find (serv->newsgroups, buf)) == NULL) { - nntp_data = xmalloc(sizeof(nntp_data_t) + m_strlen(buf) + 1); - nntp_data->group = (char *) nntp_data + sizeof (nntp_data_t); - strcpy (nntp_data->group, buf); - hash_insert (serv->newsgroups, nntp_data->group, nntp_data); + if ((nntp_data = hash_find(serv->newsgroups, buf)) == NULL) { + nntp_data = nntp_data_new(); + nntp_data->group = m_strdup(buf); + hash_insert(serv->newsgroups, nntp_data->group, nntp_data); nntp_data_list_append(&serv->list, nntp_data); } ctx->data = nntp_data; @@ -2102,6 +2098,7 @@ void nntp_data_wipe(nntp_data_t *data) p_delete(&data->entries); p_delete(&data->desc); p_delete(&data->cache); + p_delete(&data->group); nntp_free_acache(data); } @@ -2244,15 +2241,14 @@ static int add_group (char *buf, void *serv) sscanf (buf, "%s %d %d %c %[^\n]", group, &last, &first, &mod, desc); if (!group) return 0; - if ((nntp_data = (nntp_data_t *) hash_find (s->newsgroups, group)) == NULL) { + if ((nntp_data = hash_find(s->newsgroups, group)) == NULL) { n++; - nntp_data = xmalloc(sizeof(nntp_data_t) + m_strlen(group) + 1); - nntp_data->group = (char *) nntp_data + sizeof (nntp_data_t); - strcpy (nntp_data->group, group); + 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); + hash_insert(s->newsgroups, nntp_data->group, nntp_data); nntp_data_list_append(&s->list, nntp_data); } nntp_data->deleted = 0; -- 2.20.1