]> granicus.if.org Git - neomutt/commitdiff
tidy bcache
authorRichard Russon <rich@flatcap.org>
Fri, 8 Jun 2018 14:11:38 +0000 (15:11 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 11 Jun 2018 10:52:42 +0000 (11:52 +0100)
bcache.c
bcache.h

index 6e0b505fd448925289ef19dfe072b1dc49ef9645..77e89f3afc4dd7bdde0b43b8fc21157091f4632c 100644 (file)
--- a/bcache.c
+++ b/bcache.c
@@ -46,6 +46,15 @@ struct BodyCache
   size_t pathlen;
 };
 
+/**
+ * bcache_path - Create the cache path for a given account/mailbox
+ * @param account Account info
+ * @param mailbox Mailbox name
+ * @param dst     Buffer for the name
+ * @param dstlen  Length of the buffer
+ * @retval  0 Success
+ * @retval -1 Failure
+ */
 static int bcache_path(struct Account *account, const char *mailbox, char *dst, size_t dstlen)
 {
   char host[STRING];
@@ -85,6 +94,12 @@ static int bcache_path(struct Account *account, const char *mailbox, char *dst,
   return 0;
 }
 
+/**
+ * mutt_bcache_move - Change the id of a message in the cache
+ * @param bcache Body cache
+ * @param id     Per-mailbox unique identifier for the message
+ * @param newid  New id for the message
+ */
 static int mutt_bcache_move(struct BodyCache *bcache, const char *id, const char *newid)
 {
   char path[PATH_MAX];
@@ -101,6 +116,16 @@ static int mutt_bcache_move(struct BodyCache *bcache, const char *id, const char
   return rename(path, newpath);
 }
 
+/**
+ * mutt_bcache_open - Open an Email-Body Cache
+ * @param account current mailbox' account (required)
+ * @param mailbox path to the mailbox of the account (optional)
+ * @retval NULL Failure
+ *
+ * The driver using it is responsible for ensuring that hierarchies are
+ * separated by '/' (if it knows of such a concepts like mailboxes or
+ * hierarchies)
+ */
 struct BodyCache *mutt_bcache_open(struct Account *account, const char *mailbox)
 {
   struct BodyCache *bcache = NULL;
@@ -121,6 +146,12 @@ bail:
   return NULL;
 }
 
+/**
+ * mutt_bcache_close - Close an Email-Body Cache
+ * @param bcache Body cache
+ *
+ * Free all memory of bcache and finally FREE() it, too.
+ */
 void mutt_bcache_close(struct BodyCache **bcache)
 {
   if (!bcache || !*bcache)
@@ -128,6 +159,13 @@ void mutt_bcache_close(struct BodyCache **bcache)
   FREE(bcache);
 }
 
+/**
+ * mutt_bcache_get - Open a file in the Body Cache
+ * @param bcache Body Cache from mutt_bcache_open()
+ * @param id     Per-mailbox unique identifier for the message
+ * @retval ptr  Success
+ * @retval NULL Failure
+ */
 FILE *mutt_bcache_get(struct BodyCache *bcache, const char *id)
 {
   char path[PATH_MAX];
@@ -147,6 +185,16 @@ FILE *mutt_bcache_get(struct BodyCache *bcache, const char *id)
   return fp;
 }
 
+/**
+ * mutt_bcache_put - Create a file in the Body Cache
+ * @param bcache Body Cache from mutt_bcache_open()
+ * @param id     Per-mailbox unique identifier for the message
+ * @retval ptr  Success
+ * @retval NULL Failure
+ *
+ * The returned FILE* is in a temporary location.
+ * Use mutt_bcache_commit to put it into place
+ */
 FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id)
 {
   char path[PATH_MAX];
@@ -183,6 +231,13 @@ FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id)
   return mutt_file_fopen(path, "w+");
 }
 
+/**
+ * mutt_bcache_commit - Move a temporary file into the Body Cache
+ * @param bcache Body Cache from mutt_bcache_open()
+ * @param id     Per-mailbox unique identifier for the message
+ * @retval  0 Success
+ * @retval -1 Failure
+ */
 int mutt_bcache_commit(struct BodyCache *bcache, const char *id)
 {
   char tmpid[PATH_MAX];
@@ -192,6 +247,13 @@ int mutt_bcache_commit(struct BodyCache *bcache, const char *id)
   return mutt_bcache_move(bcache, tmpid, id);
 }
 
+/**
+ * mutt_bcache_del - Delete a file from the Body Cache
+ * @param bcache Body Cache from mutt_bcache_open()
+ * @param id     Per-mailbox unique identifier for the message
+ * @retval  0 Success
+ * @retval -1 Failure
+ */
 int mutt_bcache_del(struct BodyCache *bcache, const char *id)
 {
   char path[PATH_MAX];
@@ -208,6 +270,13 @@ int mutt_bcache_del(struct BodyCache *bcache, const char *id)
   return unlink(path);
 }
 
+/**
+ * mutt_bcache_exists - Check if a file exists in the Body Cache
+ * @param bcache Body Cache from mutt_bcache_open()
+ * @param id     Per-mailbox unique identifier for the message
+ * @retval  0 Success
+ * @retval -1 Failure
+ */
 int mutt_bcache_exists(struct BodyCache *bcache, const char *id)
 {
   char path[PATH_MAX];
@@ -231,9 +300,26 @@ int mutt_bcache_exists(struct BodyCache *bcache, const char *id)
   return rc;
 }
 
-int mutt_bcache_list(struct BodyCache *bcache,
-                     int (*want_id)(const char *id, struct BodyCache *bcache, void *data),
-                     void *data)
+/**
+ * mutt_bcache_list - Find matching entries in the Body Cache
+ * @param bcache Body Cache from mutt_bcache_open()
+ * @param want_id Callback function called for each match
+ * @param data    Data to pass to the callback function
+ * @retval -1  Failure
+ * @retval >=0 count of matching items
+ *
+ * This more or less "examines" the cache and calls a function with
+ * each id it finds if given.
+ *
+ * The optional callback function gets the id of a message, the very same
+ * body cache handle mutt_bcache_list() is called with (to, perhaps,
+ * perform further operations on the bcache), and a data cookie which is
+ * just passed as-is. If the return value of the callback is non-zero, the
+ * listing is aborted and continued otherwise. The callback is optional
+ * so that this function can be used to count the items in the cache
+ * (see below for return value).
+ */
+int mutt_bcache_list(struct BodyCache *bcache, bcache_list_t *want_id, void *data)
 {
   DIR *d = NULL;
   struct dirent *de = NULL;
index 2da3548e6e97f26fdfa8161ded66df869dfd47b9..842e4c1b7f8f2fd0372ae24c3f078c99ad52aa2a 100644 (file)
--- a/bcache.h
+++ b/bcache.h
@@ -30,94 +30,17 @@ struct Account;
 struct BodyCache;
 
 /**
- * mutt_bcache_open - Open an Email-Body Cache
- * @param account current mailbox' account (required)
- * @param mailbox path to the mailbox of the account (optional)
- * @retval NULL Failure
- *
- * The driver using it is responsible for ensuring that hierarchies are
- * separated by '/' (if it knows of such a concepts like mailboxes or
- * hierarchies)
- */
-struct BodyCache *mutt_bcache_open(struct Account *account, const char *mailbox);
-
-/**
- * mutt_bcache_close - Close an Email-Body Cache
- * @param bcache Body cache
- *
- * Free all memory of bcache and finally FREE() it, too.
- */
-void mutt_bcache_close(struct BodyCache **bcache);
-
-/**
- * mutt_bcache_get - Open a file in the Body Cache
- * @param bcache Body Cache from mutt_bcache_open()
- * @param id     Per-mailbox unique identifier for the message
- * @retval ptr  Success
- * @retval NULL Failure
+ * Callback function for mutt_bcache_list
  */
-FILE *mutt_bcache_get(struct BodyCache *bcache, const char *id);
+typedef int bcache_list_t(const char *id, struct BodyCache *bcache, void *data);
 
-/**
- * mutt_bcache_put - Create a file in the Body Cache
- * @param bcache Body Cache from mutt_bcache_open()
- * @param id     Per-mailbox unique identifier for the message
- * @retval ptr  Success
- * @retval NULL Failure
- *
- * The returned FILE* is in a temporary location.
- * Use mutt_bcache_commit to put it into place
- */
-FILE *mutt_bcache_put(struct BodyCache *bcache, const char *id);
-
-/**
- * mutt_bcache_commit - Move a temporary file into the Body Cache
- * @param bcache Body Cache from mutt_bcache_open()
- * @param id     Per-mailbox unique identifier for the message
- * @retval  0 Success
- * @retval -1 Failure
- */
-int mutt_bcache_commit(struct BodyCache *bcache, const char *id);
-
-/**
- * mutt_bcache_del - Delete a file from the Body Cache
- * @param bcache Body Cache from mutt_bcache_open()
- * @param id     Per-mailbox unique identifier for the message
- * @retval  0 Success
- * @retval -1 Failure
- */
-int mutt_bcache_del(struct BodyCache *bcache, const char *id);
-
-/**
- * mutt_bcache_exists - Check if a file exists in the Body Cache
- * @param bcache Body Cache from mutt_bcache_open()
- * @param id     Per-mailbox unique identifier for the message
- * @retval  0 Success
- * @retval -1 Failure
- */
-int mutt_bcache_exists(struct BodyCache *bcache, const char *id);
-
-/**
- * mutt_bcache_list - Find matching entries in the Body Cache
- * @param bcache Body Cache from mutt_bcache_open()
- * @param want_id Callback function called for each match
- * @param data    Data to pass to the callback function
- * @retval -1  Failure
- * @retval >=0 count of matching items
- *
- * This more or less "examines" the cache and calls a function with
- * each id it finds if given.
- *
- * The optional callback function gets the id of a message, the very same
- * body cache handle mutt_bcache_list() is called with (to, perhaps,
- * perform further operations on the bcache), and a data cookie which is
- * just passed as-is. If the return value of the callback is non-zero, the
- * listing is aborted and continued otherwise. The callback is optional
- * so that this function can be used to count the items in the cache
- * (see below for return value).
- */
-int mutt_bcache_list(struct BodyCache *bcache,
-                     int (*want_id)(const char *id, struct BodyCache *bcache, void *data),
-                     void *data);
+void              mutt_bcache_close(struct BodyCache **bcache);
+int               mutt_bcache_commit(struct BodyCache *bcache, const char *id);
+int               mutt_bcache_del(struct BodyCache *bcache, const char *id);
+int               mutt_bcache_exists(struct BodyCache *bcache, const char *id);
+FILE *            mutt_bcache_get(struct BodyCache *bcache, const char *id);
+int               mutt_bcache_list(struct BodyCache *bcache, bcache_list_t *want_id, void *data);
+struct BodyCache *mutt_bcache_open(struct Account *account, const char *mailbox);
+FILE *            mutt_bcache_put(struct BodyCache *bcache, const char *id);
 
 #endif /* _MUTT_BCACHE_H */