#define REV_LEVEL 736 /* This version */
#define REV_MIN 591 /* Oldest compatible database */
#define EXPORT_REV_MIN 733 /* Oldest compatible export files */
-#define LIBCITADEL_MIN 114 /* Minimum required version of libcitadel */
+#define LIBCITADEL_MIN 115 /* Minimum required version of libcitadel */
#define SERVER_TYPE 0 /* zero for stock Citadel; other developers please
obtain SERVER_TYPE codes for your implementations */
*
* When using Berkeley DB, there's another reason for the two-phase purge: we
* don't want the entire thing being done as one huge transaction.
+ *
+ * You'll also notice that we build the in-memory list of records to be deleted
+ * sometimes with a linked list and sometimes with a hash table. There is no
+ * reason for this aside from the fact that the linked list ones were written
+ * before we had the hash table library available.
*/
}
+
+/*
+ * Purge OpenID assocations for missing users (theoretically this will never delete anything)
+ */
+int PurgeStaleOpenIDassociations(void) {
+ struct cdbdata *cdboi;
+ struct ctdluser usbuf;
+ HashList *keys = NULL;
+ HashPos *HashPos;
+ char *deleteme = NULL;
+ long len;
+ void *Value;
+ char *Key;
+ int num_deleted = 0;
+
+ keys = NewHash(1, NULL);
+ if (!keys) return(0);
+
+
+ cdb_rewind(CDB_OPENID);
+ while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
+ if (cdboi->len > sizeof(long)) {
+ long usernum;
+ usernum = ((long)*(cdboi->ptr));
+ if (getuserbynumber(&usbuf, usernum) != 0) {
+ deleteme = strdup(cdboi->ptr + sizeof(long)),
+ Put(keys, deleteme, strlen(deleteme), deleteme, generic_free_handler);
+ }
+ }
+ cdb_free(cdboi);
+ }
+
+ /* Go through the hash list, deleting keys we stored in it */
+
+ HashPos = GetNewHashPos();
+ while (GetNextHashPos(keys, HashPos, &len, &Key, &Value)!=0)
+ {
+ CtdlLogPrintf(CTDL_DEBUG, "Deleting associated OpenID <%s>\n", Value);
+ cdb_delete(CDB_OPENID, Value, strlen(Value));
+ /* note: don't free(Value) -- deleting the hash list will handle this for us */
+ ++num_deleted;
+ }
+ DeleteHashPos(&HashPos);
+ DeleteHash(&keys);
+ return num_deleted;
+}
+
+
+
+
+
void *purge_databases(void *args)
{
int retval;
CtdlLogPrintf(CTDL_NOTICE, "Purged %d entries from the EUID index.\n", retval);
}
+ if (!CtdlThreadCheckStop())
+ {
+ retval = PurgeStaleOpenIDassociations();
+ CtdlLogPrintf(CTDL_NOTICE, "Purged %d stale OpenID associations.\n", retval);
+ }
+
if (!CtdlThreadCheckStop())
{
retval = TDAP_ProcessAdjRefCountQueue();
*/
+
/*
* Attach an OpenID to a Citadel account
*/
*/
void openid_purge(struct ctdluser *usbuf) {
struct cdbdata *cdboi;
+ HashList *keys = NULL;
+ HashPos *HashPos;
+ char *deleteme = NULL;
+ long len;
+ void *Value;
+ char *Key;
+
+ keys = NewHash(1, NULL);
+ if (!keys) return;
+
cdb_rewind(CDB_OPENID);
while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
if (cdboi->len > sizeof(long)) {
if (((long)*(cdboi->ptr)) == usbuf->usernum) {
- CtdlLogPrintf(CTDL_DEBUG, "FIXME we have to delete an openid\n");
+ deleteme = strdup(cdboi->ptr + sizeof(long)),
+ Put(keys, deleteme, strlen(deleteme), deleteme, generic_free_handler);
}
}
cdb_free(cdboi);
}
- /* FIXME finish this */
+ /* Go through the hash list, deleting keys we stored in it */
+
+ HashPos = GetNewHashPos();
+ while (GetNextHashPos(keys, HashPos, &len, &Key, &Value)!=0)
+ {
+ CtdlLogPrintf(CTDL_DEBUG, "Deleting associated OpenID <%s>\n", Value);
+ cdb_delete(CDB_OPENID, Value, strlen(Value));
+ /* note: don't free(Value) -- deleting the hash list will handle this for us */
+ }
+ DeleteHashPos(&HashPos);
+ DeleteHash(&keys);
}
-/*
- * Callback function to free a pointer (used below in the hash list)
- */
-void free_oid_key(void *ptr) {
- free(ptr);
-}
/*
extract_token(thiskey, buf, 0, '|', sizeof thiskey);
extract_token(thisdata, buf, 1, '|', sizeof thisdata);
CtdlLogPrintf(CTDL_DEBUG, "%s: [%d] %s\n", thiskey, strlen(thisdata), thisdata);
- Put(keys, thiskey, strlen(thiskey), strdup(thisdata), free_oid_key);
+ Put(keys, thiskey, strlen(thiskey), strdup(thisdata), generic_free_handler);
}
free(Value);
}
DeleteHashPos(&HashPos);
+ DeleteHash(&keys);
}
* return strcmp (a, b);
* }
*/
+
+
+/*
+ * Generic function to free a pointer. This can be used as a callback with the
+ * hash table, even on systems where free() is defined as a macro or has had other
+ * horrible things done to it.
+ */
+void generic_free_handler(void *ptr) {
+ free(ptr);
+}
+
+
+
*/
#include <time.h>
#include <stdlib.h>
-#define LIBCITADEL_VERSION_NUMBER 114
+#define LIBCITADEL_VERSION_NUMBER 115
/*
* Here's a bunch of stupid magic to make the MIME parser portable.
int GetCount(HashList *Hash);
const void *GetSearchPayload(const void *HashVoid);
void SortByPayload(HashList *Hash, CompareFunc SortBy);
+void generic_free_handler(void *ptr);
+
+
void convert_spaces_to_underscores(char *str);
/*