Skip to content

Commit

Permalink
nntp: refactor Account/Mailbox/Email private data
Browse files Browse the repository at this point in the history
  • Loading branch information
flatcap committed Feb 27, 2021
1 parent 78ae593 commit 3c425f0
Show file tree
Hide file tree
Showing 21 changed files with 392 additions and 176 deletions.
2 changes: 1 addition & 1 deletion Makefile.autosetup
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ $(PWD)/ncrypt:
# libnntp
LIBNNTP= libnntp.a
LIBNNTPOBJS= nntp/browse.o nntp/config.o nntp/complete.o nntp/newsrc.o \
nntp/nntp.o
nntp/nntp.o nntp/adata.o nntp/edata.o nntp/mdata.o
CLEANFILES+= $(LIBNNTP) $(LIBNNTPOBJS)
ALLOBJS+= $(LIBNNTPOBJS)

Expand Down
2 changes: 2 additions & 0 deletions browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
#endif
#ifdef USE_NNTP
#include "nntp/lib.h"
#include "nntp/adata.h"
#include "nntp/mdata.h"
#endif

/* These Config Variables are only used in browser.c */
Expand Down
1 change: 1 addition & 0 deletions compose/compose.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#endif
#ifdef USE_NNTP
#include "nntp/lib.h"
#include "nntp/adata.h"
#endif
#ifdef USE_POP
#include "pop/lib.h"
Expand Down
4 changes: 3 additions & 1 deletion debug/graphviz.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
#include "maildir/mdata.h"
#include "maildir/private.h"
#include "mutt_globals.h"
#include "notmuch/mdata.h"
#include "nntp/adata.h"
#include "nntp/mdata.h"
#include "notmuch/adata.h"
#include "notmuch/mdata.h"
#include "notmuch/private.h"
#include "pop/adata.h"
#include "pop/private.h"
Expand Down
2 changes: 2 additions & 0 deletions index.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
#endif
#ifdef USE_NNTP
#include "nntp/lib.h"
#include "nntp/adata.h"
#include "nntp/mdata.h"
#endif
#ifdef ENABLE_NLS
#include <libintl.h>
Expand Down
2 changes: 2 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
#endif
#ifdef USE_NNTP
#include "nntp/lib.h"
#include "nntp/adata.h"
#include "nntp/mdata.h"
#endif
#ifdef USE_AUTOCRYPT
#include "autocrypt/lib.h"
Expand Down
2 changes: 2 additions & 0 deletions mx.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
#endif
#ifdef USE_NNTP
#include "nntp/lib.h"
#include "nntp/adata.h"
#include "nntp/mdata.h"
#endif
#ifdef USE_NOTMUCH
#include "notmuch/lib.h"
Expand Down
89 changes: 89 additions & 0 deletions nntp/adata.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* @file
* Nntp-specific Account data
*
* @authors
* Copyright (C) 2021 Richard Russon <[email protected]>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* @page nntp_adata Nntp-specific Account data
*
* Nntp-specific Account data
*/

#include "config.h"
#include "private.h"
#include "mutt/lib.h"
#include "adata.h"

/**
* nntp_adata_free - Free the private Account data - Implements Account::adata_free()
*
* The NntpAccountData struct stores global NNTP data, such as the connection to
* the database. This function will close the database, free the resources and
* the struct itself.
*/
void nntp_adata_free(void **ptr)
{
if (!ptr || !*ptr)
return;

struct NntpAccountData *adata = *ptr;

mutt_file_fclose(&adata->fp_newsrc);
FREE(&adata->newsrc_file);
FREE(&adata->authenticators);
FREE(&adata->overview_fmt);
FREE(&adata->conn);
FREE(&adata->groups_list);
mutt_hash_free(&adata->groups_hash);
FREE(ptr);
}

/**
* nntp_adata_new - Allocate and initialise a new NntpAccountData structure
* @param conn Network connection
* @retval ptr New NntpAccountData
*/
struct NntpAccountData *nntp_adata_new(struct Connection *conn)
{
struct NntpAccountData *adata = mutt_mem_calloc(1, sizeof(struct NntpAccountData));
adata->conn = conn;
adata->groups_hash = mutt_hash_new(1009, MUTT_HASH_NO_FLAGS);
mutt_hash_set_destructor(adata->groups_hash, nntp_hashelem_free, 0);
adata->groups_max = 16;
adata->groups_list =
mutt_mem_malloc(adata->groups_max * sizeof(struct NntpMboxData *));
return adata;
}

#if 0
/**
* nntp_adata_get - Get the Account data for this mailbox
* @retval ptr Private Account data
*/
struct NntpAccountData *nntp_adata_get(struct Mailbox *m)
{
if (!m || (m->type != MUTT_NNTP))
return NULL;
struct Account *a = m->account;
if (!a)
return NULL;
return a->adata;
}
#endif
67 changes: 67 additions & 0 deletions nntp/adata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @file
* Nntp-specific Account data
*
* @authors
* Copyright (C) 2021 Richard Russon <[email protected]>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MUTT_NNTP_ADATA_H
#define MUTT_NNTP_ADATA_H

#include <stdbool.h>

struct Mailbox;

/**
* struct NntpAccountData - NNTP-specific Account data - @extends Account
*/
struct NntpAccountData
{
bool hasCAPABILITIES : 1;
bool hasSTARTTLS : 1;
bool hasDATE : 1;
bool hasLIST_NEWSGROUPS : 1;
bool hasXGTITLE : 1;
bool hasLISTGROUP : 1;
bool hasLISTGROUPrange : 1;
bool hasOVER : 1;
bool hasXOVER : 1;
unsigned int use_tls : 3;
unsigned int status : 3;
bool cacheable : 1;
bool newsrc_modified : 1;
FILE *fp_newsrc;
char *newsrc_file;
char *authenticators;
char *overview_fmt;
off_t size;
time_t mtime;
time_t newgroups_time;
time_t check_time;
unsigned int groups_num;
unsigned int groups_max;
void **groups_list;
struct HashTable *groups_hash;
struct Connection *conn;
};

void nntp_adata_free(void **ptr);
struct NntpAccountData *nntp_adata_get (struct Mailbox *m);
struct NntpAccountData *nntp_adata_new (struct Connection *conn);

#endif /* MUTT_NNTP_ADATA_H */
2 changes: 2 additions & 0 deletions nntp/browse.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
#include "mutt/lib.h"
#include "email/lib.h"
#include "lib.h"
#include "adata.h"
#include "browser.h"
#include "format_flags.h"
#include "mdata.h"
#include "muttlib.h"

/**
Expand Down
2 changes: 2 additions & 0 deletions nntp/complete.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <stdio.h>
#include "mutt/lib.h"
#include "lib.h"
#include "adata.h"
#include "mdata.h"

/**
* nntp_complete - Auto-complete NNTP newsgroups
Expand Down
62 changes: 62 additions & 0 deletions nntp/edata.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @file
* Nntp-specific Email data
*
* @authors
* Copyright (C) 2021 Richard Russon <[email protected]>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
* @page nntp_edata Nntp-specific Email data
*
* Nntp-specific Email data
*/

#include "config.h"
#include "mutt/lib.h"
#include "email/lib.h"
#include "edata.h"

/**
* nntp_edata_free - Free the private Email data - Implements Email::edata_free()
*/
void nntp_edata_free(void **ptr)
{
// struct NntpEmailData *edata = *ptr;
FREE(ptr);
}

/**
* nntp_edata_new - Create a new NntpEmailData for an Email
* @retval ptr New NntpEmailData struct
*/
struct NntpEmailData *nntp_edata_new(void)
{
return mutt_mem_calloc(1, sizeof(struct NntpEmailData));
}

/**
* nntp_edata_get - Get the private data for this Email
* @param e Email
* @retval ptr Private Email data
*/
struct NntpEmailData *nntp_edata_get(struct Email *e)
{
if (!e)
return NULL;
return e->edata;
}
41 changes: 41 additions & 0 deletions nntp/edata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @file
* Nntp-specific Email data
*
* @authors
* Copyright (C) 2021 Richard Russon <[email protected]>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef MUTT_NNTP_EDATA_H
#define MUTT_NNTP_EDATA_H

#include "lib.h"

/**
* struct NntpEmailData - NNTP-specific Email data - @extends Email
*/
struct NntpEmailData
{
anum_t article_num;
bool parsed : 1;
};

void nntp_edata_free(void **ptr);
struct NntpEmailData *nntp_edata_new (void);
struct NntpEmailData *nntp_edata_get (struct Email *e);

#endif /* MUTT_NNTP_EDATA_H */
Loading

0 comments on commit 3c425f0

Please sign in to comment.