* Began implenmenting OpenID table import/export
authorArt Cancro <ajc@citadel.org>
Mon, 2 Jun 2008 15:03:45 +0000 (15:03 +0000)
committerArt Cancro <ajc@citadel.org>
Mon, 2 Jun 2008 15:03:45 +0000 (15:03 +0000)
* 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
citadel/modules/openid/serv_openid_rp.c
citadel/modules/vandelay/serv_vandelay.c

index 8da8192fa07ae82089d9a7d6ec8c65783d29f69e..74070e4aaaab4d7075e45cf2f9104ecfdee42d69 100644 (file)
@@ -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);
index bd883bf31e4b6110463879a2218a8aa0eaeca3d0..80e25679d6505991080ff590aed3248649d46cf5 100644 (file)
@@ -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:
index 66022d9204246aa0efa702cb4d67123d815afa37..aeaf81ece5cd0faf198ce9dd4965a86afa19034e 100644 (file)
@@ -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;