}
-// 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) {
+// Prepare for a sequential search of an entire database. Returns a cursor.
+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
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(int cdb) {
+struct cdbdata *bdb_next_item(void *cursor, int cdb) {
DBT key, data;
struct cdbdata *cdbret;
int ret = 0;
bdb_abort();
}
bdb_close_cursor(cdb);
+ syslog(LOG_DEBUG, "\033[33m--- end cursor %x ---\033[0m", cdb);
return NULL; // presumably, end of file
}
char *value = NULL;
cprintf("%d all configuration variables\n", LISTING_FOLLOWS);
- cdb_rewind(CDB_CONFIG);
- while (cdbcfg = cdb_next_item(CDB_CONFIG), cdbcfg != NULL) {
+ void *cur = cdb_rewind(CDB_CONFIG);
+ while (cdbcfg = cdb_next_item(cur, CDB_CONFIG), cdbcfg != NULL) {
if (cdbcfg->len < 1020) {
keylen = strlen(cdbcfg->ptr);
key = cdbcfg->ptr;
int (*cdb_store)(int, const void *, int, void *, int) = NULL;
int (*cdb_delete)(int, void *, int) = NULL;
void (*cdb_free)(struct cdbdata *) = NULL;
-struct cdbdata * (*cdb_next_item)(int) = NULL;
+void * (*cdb_rewind)(int) = NULL;
+struct cdbdata * (*cdb_next_item)(void *, int) = NULL;
void (*cdb_close_cursor)(int) = NULL;
void (*cdb_begin_transaction)(void) = NULL;
void (*cdb_end_transaction)(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.
extern int (*cdb_store)(int, const void *, int, void *, int);
extern int (*cdb_delete)(int, void *, int);
extern void (*cdb_free)(struct cdbdata *);
-extern struct cdbdata * (*cdb_next_item)(int);
+extern void * (*cdb_rewind)(int);
+extern struct cdbdata * (*cdb_next_item)(void *, int);
extern void (*cdb_close_cursor)(int);
extern void (*cdb_begin_transaction)(void);
extern void (*cdb_end_transaction)(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
int ra;
cprintf("%d Who knows room:\n", LISTING_FOLLOWS);
- cdb_rewind(CDB_USERS);
- while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
+ void *cur = cdb_rewind(CDB_USERS);
+ while (cdbus = cdb_next_item(cur, CDB_USERS), cdbus != NULL) {
memset(&temp, 0, sizeof temp);
memcpy(&temp, cdbus->ptr, sizeof temp);
cdb_free(cdbus);
}
// There are unvalidated users. Traverse the user database, and return the first user we find that needs validation.
- cdb_rewind(CDB_USERS);
- while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
+ void *cur = cdb_rewind(CDB_USERS);
+ while (cdbus = cdb_next_item(cur, 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);
ForEachUser(AddValidUser, NULL);
// Now traverse through the visits, purging irrelevant records...
- cdb_rewind(CDB_VISIT);
- while(cdbvisit = cdb_next_item(CDB_VISIT), cdbvisit != NULL) {
+ void *cur = cdb_rewind(CDB_VISIT);
+ while(cdbvisit = cdb_next_item(cur, CDB_VISIT), cdbvisit != NULL) {
memset(&vbuf, 0, sizeof(struct visit));
memcpy(&vbuf, cdbvisit->ptr,
( (cdbvisit->len > sizeof(struct visit)) ?
// Phase 1: traverse through the table, discovering old records...
syslog(LOG_DEBUG, "Purge use table: phase 1");
- cdb_rewind(CDB_USETABLE);
- while(cdbut = cdb_next_item(CDB_USETABLE), cdbut != NULL) {
+ void *cur = cdb_rewind(CDB_USETABLE);
+ while(cdbut = cdb_next_item(cur, CDB_USETABLE), cdbut != NULL) {
++total;
if (cdbut->len > sizeof(struct UseTable))
memcpy(&ut, cdbut->ptr, sizeof(struct UseTable));
// Phase 1: traverse through the table, discovering old records...
syslog(LOG_DEBUG, "Purge EUID index: phase 1");
- cdb_rewind(CDB_EUIDINDEX);
- while(cdbei = cdb_next_item(CDB_EUIDINDEX), cdbei != NULL) {
+ void *cur = cdb_rewind(CDB_EUIDINDEX);
+ while(cdbei = cdb_next_item(cur, CDB_EUIDINDEX), cdbei != NULL) {
memcpy(&msgnum, cdbei->ptr, sizeof(long));
// Traverse the userlist
rights = NewStrBuf();
- cdb_rewind(CDB_USERS);
- while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
+ void *cur = cdb_rewind(CDB_USERS);
+ while (cdbus = cdb_next_item(cur, CDB_USERS), cdbus != NULL) {
memset(&temp, 0, sizeof temp);
memcpy(&temp, cdbus->ptr, sizeof temp);
cdb_free(cdbus);
struct ctdlroom qrbuf;
struct cdbdata *cdbqr;
- cdb_rewind(CDB_ROOMS);
- while (cdbqr = cdb_next_item(CDB_ROOMS), cdbqr != NULL) {
+ void *cur = cdb_rewind(CDB_ROOMS);
+ while (cdbqr = cdb_next_item(cur, 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);
// 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
- cdb_rewind(CDB_USERS);
- while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
+ void *cur = cdb_rewind(CDB_USERS);
+ while (cdbus = cdb_next_item(cur, CDB_USERS), cdbus != NULL) {
usptr = (struct ctdluser *) cdbus->ptr;
if (usptr->uid == number) {
}
// Phase 1 : build an array of all our user account names
- cdb_rewind(CDB_USERS);
- while (cdbus = cdb_next_item(CDB_USERS), cdbus != NULL) {
+ void *cur = cdb_rewind(CDB_USERS);
+ while (cdbus = cdb_next_item(cur, CDB_USERS), cdbus != NULL) {
usptr = (struct ctdluser *) cdbus->ptr;
if (strlen(usptr->fullname) > 0) {
array_append(all_users, usptr->fullname);