From 0136c8c68f939f12da477ac92c538bdefb37afc9 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Mon, 2 Jun 2008 15:03:45 +0000 Subject: [PATCH] * Began implenmenting OpenID table import/export * Disabled the code to automatically learn the highest message/user/room numbers in the event that citadel.control is missing, because if you run it on a virgin server, it CRASHES. --- citadel/control.c | 4 +- citadel/modules/openid/serv_openid_rp.c | 2 +- citadel/modules/vandelay/serv_vandelay.c | 47 +++++++++++++++++++++++- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/citadel/control.c b/citadel/control.c index 8da8192fa..74070e4aa 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -155,8 +155,8 @@ void get_control(void) fchown(fileno(control_fp), config.c_ctdluid, -1); memset(&CitControl, 0, sizeof(struct CitControl)); // Find highest room number and message number. - ForEachRoom(control_find_highest, NULL); - ForEachUser(control_find_user, NULL); + // ForEachRoom(control_find_highest, NULL); + // ForEachUser(control_find_user, NULL); fwrite(&CitControl, sizeof(struct CitControl), 1, control_fp); rewind(control_fp); diff --git a/citadel/modules/openid/serv_openid_rp.c b/citadel/modules/openid/serv_openid_rp.c index bd883bf31..80e25679d 100644 --- a/citadel/modules/openid/serv_openid_rp.c +++ b/citadel/modules/openid/serv_openid_rp.c @@ -56,7 +56,7 @@ struct ctdl_openid { * The structure of an openid record *key* is: * * |--------------claimed_id-------------| - * (auctual length of claimed id) + * (actual length of claimed id) * * * The structure of an openid record *value* is: diff --git a/citadel/modules/vandelay/serv_vandelay.c b/citadel/modules/vandelay/serv_vandelay.c index 66022d920..aeaf81ece 100644 --- a/citadel/modules/vandelay/serv_vandelay.c +++ b/citadel/modules/vandelay/serv_vandelay.c @@ -399,6 +399,25 @@ void artv_dump_message(long msgnum) { +void artv_export_openids(void) { + struct cdbdata *cdboi; + long usernum; + + cdb_rewind(CDB_OPENID); + while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) { + if (cdboi->len > sizeof(long)) { + client_write("openid\n", 7); + memcpy(&usernum, cdboi->ptr, sizeof(long)); + cprintf("%s\n", (cdboi->ptr)+sizeof(long) ); + cprintf("%ld\n", usernum); + } + cdb_free(cdboi); + } +} + + + + void artv_export_messages(void) { char buf[SIZ]; long msgnum; @@ -482,6 +501,8 @@ void artv_do_export(void) { cprintf("%d\n", CitControl.version); if (Ctx->kill_me != 1) artv_export_users(); + if (Ctx->kill_me != 1) + artv_export_openids(); if (Ctx->kill_me != 1) artv_export_rooms(); if (Ctx->kill_me != 1) @@ -665,8 +686,6 @@ void artv_import_floor(void) { } -/* - */ void artv_import_visit(void) { struct visit vbuf; char buf[SIZ]; @@ -691,6 +710,29 @@ void artv_import_visit(void) { } +void artv_import_openid(void) { + char buf[SIZ]; + long usernum; + char openid[1024]; + char *data; + int data_len; + + client_getln(buf, sizeof buf); usernum = atol(buf); + client_getln(openid, sizeof openid); + if (IsEmptyStr(openid)) return; + + data_len = sizeof(long) + strlen(openid) + 1; + data = malloc(data_len); + + memcpy(data, &usernum, sizeof(long)); + memcpy(&data[sizeof(long)], openid, strlen(openid) + 1); + + cdb_store(CDB_OPENID, openid, strlen(openid), data, data_len); + free(data); + + CtdlLogPrintf(CTDL_INFO, "Imported OpenID %s for user #%ld\n", openid, usernum); +} + void artv_import_message(long *iterations, char **b64buf, size_t *b64size, char **plain, size_t *plain_size) { struct MetaData smi; @@ -834,6 +876,7 @@ void artv_do_import(void) { else if (!strcasecmp(buf, "room")) artv_import_room(&iterations); else if (!strcasecmp(buf, "floor")) artv_import_floor(); else if (!strcasecmp(buf, "visit")) artv_import_visit(); + else if (!strcasecmp(buf, "openid")) artv_import_openid(); else if (!strcasecmp(buf, "message")) { b64mes[0] = 0; -- 2.30.2