]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/vandelay/serv_vandelay.c
Added code to provide a preliminary single user mode.
[citadel.git] / citadel / modules / vandelay / serv_vandelay.c
index 2b2d03ae36dcd6677e72f93def72ea575cedd439..79533aa2f2e9160f0d4bbef2c64e9d63dc8c9ec3 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;
@@ -461,7 +480,7 @@ void artv_do_export(void) {
 
        Ctx = CC;
        cprintf("%d Exporting all Citadel databases.\n", LISTING_FOLLOWS);
-
+       Ctx->dont_term = 1;
        cprintf("version\n%d\n", REV_LEVEL);
 
        /* export the config file (this is done using x-macros) */
@@ -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)
@@ -490,8 +511,8 @@ void artv_do_export(void) {
                artv_export_visits();
        if (Ctx->kill_me != 1)
                artv_export_messages();
-
        client_write("000\n", 4);
+       Ctx->dont_term = 0;
 }
 
 void artv_do_dump(void) {
@@ -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(openid, sizeof openid);
+       client_getln(buf, sizeof buf);  usernum = atol(buf);
+       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;
@@ -799,6 +841,8 @@ void artv_do_import(void) {
        plain[0] = 0;
        plain_size = SIZ;
        
+       CC->dont_term = 1;
+
        cprintf("%d sock it to me\n", SEND_LISTING);
        abuf[0] = '\0';
        unbuffer_output();
@@ -834,6 +878,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;
@@ -848,6 +893,8 @@ void artv_do_import(void) {
        CtdlLogPrintf(CTDL_INFO, "Invalid keyword <%s>.  Flushing input.\n", buf);
        while (client_getln(buf, sizeof buf) >= 0 && strcmp(buf, "000"))  ;;
        rebuild_euid_index();
+       rebuild_usersbynumber();
+       CC->dont_term = 0;
 }
 
 
@@ -857,26 +904,28 @@ void cmd_artv(char *cmdbuf) {
        static int is_running = 0;
 
        if (CtdlAccessCheck(ac_internal)) return;
-       if (is_running) {
+       
+       if (CtdlTrySingleUser())
+       {
+               CtdlMakeTempFileName(artv_tempfilename1, sizeof artv_tempfilename1);
+               CtdlMakeTempFileName(artv_tempfilename2, sizeof artv_tempfilename2);
+
+               extract_token(cmd, cmdbuf, 0, '|', sizeof cmd);
+               if (!strcasecmp(cmd, "export")) artv_do_export();
+               else if (!strcasecmp(cmd, "import")) artv_do_import();
+               else if (!strcasecmp(cmd, "dump")) artv_do_dump();
+               else cprintf("%d illegal command\n", ERROR + ILLEGAL_VALUE);
+
+               unlink(artv_tempfilename1);
+               unlink(artv_tempfilename2);
+               
+               CtdlEndSingleUser();
+       }
+       else
+       {
                cprintf("%d The importer/exporter is already running.\n",
                        ERROR + RESOURCE_BUSY);
-               return;
        }
-       is_running = 1;
-
-       CtdlMakeTempFileName(artv_tempfilename1, sizeof artv_tempfilename1);
-       CtdlMakeTempFileName(artv_tempfilename2, sizeof artv_tempfilename2);
-
-       extract_token(cmd, cmdbuf, 0, '|', sizeof cmd);
-       if (!strcasecmp(cmd, "export")) artv_do_export();
-       else if (!strcasecmp(cmd, "import")) artv_do_import();
-       else if (!strcasecmp(cmd, "dump")) artv_do_dump();
-       else cprintf("%d illegal command\n", ERROR + ILLEGAL_VALUE);
-
-       unlink(artv_tempfilename1);
-       unlink(artv_tempfilename2);
-
-       is_running = 0;
 }