Revert "Changed the API for cdb_rewind() / cdb_next_item() to make the caller hold...
authorArt Cancro <ajc@citadel.org>
Fri, 11 Aug 2023 12:42:20 +0000 (03:42 -0900)
committerArt Cancro <ajc@citadel.org>
Fri, 11 Aug 2023 12:42:20 +0000 (03:42 -0900)
This reverts commit 733c6e8f2a624fb641cc50a9d253b3a914c25bba.

citadel/server/backends/berkeley_db/berkeley_db.c
citadel/server/control.c
citadel/server/database.c
citadel/server/database.h
citadel/server/modules/ctdlproto/serv_rooms.c
citadel/server/modules/ctdlproto/serv_user.c
citadel/server/modules/expire/serv_expire.c
citadel/server/modules/imap/imap_acl.c
citadel/server/room_ops.c
citadel/server/user_ops.c

index 21c703a5f1f785e6c0f9433a4b7af7db060f5efb..ee437e0467ba1278e5764ef4a0dabe96ea05240f 100644 (file)
@@ -603,13 +603,16 @@ void bdb_close_cursor(int cdb) {
 }
 
 
-// Prepare for a sequential search of an entire database.  Returns a cursor.
-void *bdb_rewind(int cdb) {
+// Prepare for a sequential search of an entire database.
+// (There is guaranteed to be no more than one traversal in
+// progress per thread at any given time.)
+void bdb_rewind(int cdb) {
        int ret = 0;
 
        if (TSD->cursors[cdb] != NULL) {
                syslog(LOG_ERR, "bdb: bdb_rewind: must close cursor on database %d before reopening", cdb);
                bdb_abort();
+               // bdb_cclose(TSD->cursors[cdb]);
        }
 
        // Now initialize the cursor
@@ -618,15 +621,12 @@ void *bdb_rewind(int cdb) {
                syslog(LOG_ERR, "bdb: bdb_rewind: db_cursor: %s", db_strerror(ret));
                bdb_abort();
        }
-
-       syslog(LOG_DEBUG, "\033[33m--- begin cursor %x ---\033[0m", cdb);
-       return((void *)TSD->cursors[cdb]);
 }
 
 
 // Fetch the next item in a sequential search.  Returns a pointer to a 
 // cdbdata structure, or NULL if we've hit the end.
-struct cdbdata *bdb_next_item(void *cursor, int cdb) {
+struct cdbdata *bdb_next_item(int cdb) {
        DBT key, data;
        struct cdbdata *cdbret;
        int ret = 0;
@@ -644,7 +644,6 @@ struct cdbdata *bdb_next_item(void *cursor, int cdb) {
                        bdb_abort();
                }
                bdb_close_cursor(cdb);
-               syslog(LOG_DEBUG, "\033[33m--- end cursor %x ---\033[0m", cdb);
                return NULL;    // presumably, end of file
        }
 
index 80c24da55afcca056425c6ea7bf293bf99026745..27bc05b01e52ceded4715719327b59281520ecdd 100644 (file)
@@ -654,8 +654,8 @@ void cmd_conf(char *argbuf) {
                char *value = NULL;
        
                cprintf("%d all configuration variables\n", LISTING_FOLLOWS);
-               void *cur = cdb_rewind(CDB_CONFIG);
-               while (cdbcfg = cdb_next_item(cur, CDB_CONFIG), cdbcfg != NULL) {
+               cdb_rewind(CDB_CONFIG);
+               while (cdbcfg = cdb_next_item(CDB_CONFIG), cdbcfg != NULL) {
                        if (cdbcfg->len < 1020) {
                                keylen = strlen(cdbcfg->ptr);
                                key = cdbcfg->ptr;
index dcae3d0a0af1ef175a1b8bf01da13b68eb109d0c..5aa7d0e27ebd496efc9ebc8a719e830d01d76ceb 100644 (file)
@@ -26,8 +26,7 @@ void                  (*cdb_close_databases)(void)                            = NULL;
 int                    (*cdb_store)(int, const void *, int, void *, int)       = NULL;
 int                    (*cdb_delete)(int, void *, int)                         = NULL;
 void                   (*cdb_free)(struct cdbdata *)                           = NULL;
-void *                 (*cdb_rewind)(int)                                      = NULL;
-struct cdbdata *       (*cdb_next_item)(void *, int)                           = NULL;
+struct cdbdata *       (*cdb_next_item)(int)                                   = NULL;
 void                   (*cdb_close_cursor)(int)                                = NULL;
 void                   (*cdb_begin_transaction)(void)                          = NULL;
 void                   (*cdb_end_transaction)(void)                            = NULL;
@@ -37,6 +36,7 @@ void                  (*cdb_chmod_data)(void)                                 = NULL;
 void                   (*check_handles)(void *)                                = NULL;
 void                   (*cdb_compact)(void)                                    = NULL;
 void                   (*cdb_checkpoint)(void)                                 = NULL;
+void                   (*cdb_rewind)(int)                                      = NULL;
 struct cdbdata *       (*cdb_fetch)(int, const void *, int)                    = NULL;
 
 // This function is responsible for choosing and initializing a back end.
index 9353b6085b978d6ab8e50a409a4fcf25f206ebc4..418a2f5de8aa58bcb10d61a620c6d5b8fde920e6 100644 (file)
@@ -12,8 +12,7 @@ extern void           (*cdb_close_databases)(void);
 extern int             (*cdb_store)(int, const void *, int, void *, int);
 extern int             (*cdb_delete)(int, void *, int);
 extern void            (*cdb_free)(struct cdbdata *);
-extern void *          (*cdb_rewind)(int);
-extern struct cdbdata *        (*cdb_next_item)(void *, int);
+extern struct cdbdata *        (*cdb_next_item)(int);
 extern void            (*cdb_close_cursor)(int);
 extern void            (*cdb_begin_transaction)(void);
 extern void            (*cdb_end_transaction)(void);
@@ -24,5 +23,6 @@ extern void           (*check_handles)(void *);
 extern struct cdbdata *        (*cdb_fetch)(int, const void *, int);
 extern void            (*cdb_checkpoint)(void);
 extern void            (*cdb_compact)(void);
+extern void            (*cdb_rewind)(int);
 
 #endif
index 6b3cdfc036c3953b08ffd0fd9d8fcc67163db85e..1ca2fc04fd99d16897bea1a83cbdde0b2cd612dc 100644 (file)
@@ -326,8 +326,8 @@ void cmd_whok(char *cmdbuf) {
        int ra;
 
        cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
-       void *cur = cdb_rewind(CDB_USERS);
-       while (cdbus = cdb_next_item(cur, CDB_USERS), cdbus != NULL) {
+       cdb_rewind(CDB_USERS);
+       while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
                memset(&temp, 0, sizeof temp);
                memcpy(&temp, cdbus->ptr, sizeof temp);
                cdb_free(cdbus);
index 8e7e50593cf7ed0255cba1c69964e5340823c963..f5f4ef525faaad5118cc7cc430dd75845f6f3396 100644 (file)
@@ -394,8 +394,8 @@ void cmd_gnur(char *argbuf) {
        }
 
        // There are unvalidated users.  Traverse the user database, and return the first user we find that needs validation.
-       void *cur = cdb_rewind(CDB_USERS);
-       while (cdbus = cdb_next_item(cur, CDB_USERS), cdbus != NULL) {
+       cdb_rewind(CDB_USERS);
+       while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
                memset(&usbuf, 0, sizeof(struct ctdluser));
                memcpy(&usbuf, cdbus->ptr, ((cdbus->len > sizeof(struct ctdluser)) ?  sizeof(struct ctdluser) : cdbus->len));
                cdb_free(cdbus);
index e07c5138285fa894fa62e2312a1ac355c7d01265..096360aa4229deaed24add2d4c59c981556e849e 100644 (file)
@@ -507,8 +507,8 @@ int PurgeVisits(void) {
        ForEachUser(AddValidUser, NULL);
 
        // Now traverse through the visits, purging irrelevant records...
-       void *cur = cdb_rewind(CDB_VISIT);
-       while(cdbvisit = cdb_next_item(cur, CDB_VISIT), cdbvisit != NULL) {
+       cdb_rewind(CDB_VISIT);
+       while(cdbvisit = cdb_next_item(CDB_VISIT), cdbvisit != NULL) {
                memset(&vbuf, 0, sizeof(struct visit));
                memcpy(&vbuf, cdbvisit->ptr,
                        ( (cdbvisit->len > sizeof(struct visit)) ?
@@ -587,8 +587,8 @@ int PurgeUseTable(StrBuf *ErrMsg) {
        // Phase 1: traverse through the table, discovering old records...
 
        syslog(LOG_DEBUG, "Purge use table: phase 1");
-       void *cur = cdb_rewind(CDB_USETABLE);
-       while(cdbut = cdb_next_item(cur, CDB_USETABLE), cdbut != NULL) {
+       cdb_rewind(CDB_USETABLE);
+       while(cdbut = cdb_next_item(CDB_USETABLE), cdbut != NULL) {
                ++total;
                if (cdbut->len > sizeof(struct UseTable))
                        memcpy(&ut, cdbut->ptr, sizeof(struct UseTable));
@@ -629,8 +629,8 @@ int PurgeEuidIndexTable(void) {
 
        // Phase 1: traverse through the table, discovering old records...
        syslog(LOG_DEBUG, "Purge EUID index: phase 1");
-       void *cur = cdb_rewind(CDB_EUIDINDEX);
-       while(cdbei = cdb_next_item(cur, CDB_EUIDINDEX), cdbei != NULL) {
+       cdb_rewind(CDB_EUIDINDEX);
+       while(cdbei = cdb_next_item(CDB_EUIDINDEX), cdbei != NULL) {
 
                memcpy(&msgnum, cdbei->ptr, sizeof(long));
 
index 148d8788a304fa4a8852d80600b574ffab7cf2c2..1cb6337f8cdfd0818c77cfd43e7d48ebe6c8a601 100644 (file)
@@ -135,8 +135,8 @@ void imap_getacl(int num_parms, ConstStr *Params) {
 
        // Traverse the userlist
        rights = NewStrBuf();
-       void *cur = cdb_rewind(CDB_USERS);
-       while (cdbus = cdb_next_item(cur, CDB_USERS), cdbus != NULL) {
+       cdb_rewind(CDB_USERS);
+       while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
                memset(&temp, 0, sizeof temp);
                memcpy(&temp, cdbus->ptr, sizeof temp);
                cdb_free(cdbus);
index 21ab47ac800e3ecb1893cc58ab1c9f27afb35108..7fefdbbf3d4b51b8ceb888823c4327635ce1700d 100644 (file)
@@ -527,8 +527,8 @@ void CtdlForEachRoom(ForEachRoomCallBack callback_func, void *in_data) {
        struct ctdlroom qrbuf;
        struct cdbdata *cdbqr;
 
-       void *cur = cdb_rewind(CDB_ROOMS);
-       while (cdbqr = cdb_next_item(cur, CDB_ROOMS), cdbqr != NULL) {
+       cdb_rewind(CDB_ROOMS);
+       while (cdbqr = cdb_next_item(CDB_ROOMS), cdbqr != NULL) {
                memset(&qrbuf, 0, sizeof(struct ctdlroom));
                memcpy(&qrbuf, cdbqr->ptr, ((cdbqr->len > sizeof(struct ctdlroom)) ?  sizeof(struct ctdlroom) : cdbqr->len) );
                cdb_free(cdbqr);
index 6abb6993eb550548b179abefb4145e9095b97d51..76897347cd11f10674f7e506dba70d17dfca44ba 100644 (file)
@@ -401,8 +401,8 @@ int getuserbyuid(struct ctdluser *usbuf, uid_t number) {
        // Yes, we do this the long way.
        // No, we don't use CtdlForEachUser() because that requires multiple reads for each record
        // TODO: make an index
-       void *cur = cdb_rewind(CDB_USERS);
-       while (cdbus = cdb_next_item(cur, CDB_USERS), cdbus != NULL) {
+       cdb_rewind(CDB_USERS);
+       while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
                usptr = (struct ctdluser *) cdbus->ptr;
 
                if (usptr->uid == number) {
@@ -1044,8 +1044,8 @@ void ForEachUser(void (*CallBack) (char *, void *out_data), void *in_data) {
        }
 
        // Phase 1 : build an array of all our user account names
-       void *cur = cdb_rewind(CDB_USERS);
-       while (cdbus = cdb_next_item(cur, CDB_USERS), cdbus != NULL) {
+       cdb_rewind(CDB_USERS);
+       while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
                usptr = (struct ctdluser *) cdbus->ptr;
                if (strlen(usptr->fullname) > 0) {
                        array_append(all_users, usptr->fullname);