ctdldump/ctdlload is functionally complete.
authorArt Cancro <ajc@citadel.org>
Tue, 18 Jul 2023 03:12:20 +0000 (18:12 -0900)
committerArt Cancro <ajc@citadel.org>
Tue, 18 Jul 2023 03:12:20 +0000 (18:12 -0900)
citadel/utils/ctdlload.c

index ec9af713661f933703ca024d51d73b548b3d2893..b8845af1429b3935de688fd3a932d3d01ae8b253 100644 (file)
@@ -111,12 +111,6 @@ void close_dbenv(DB_ENV *dbenv) {
 }
 
 
-// Skeleton convert function
-int convert_foo(char *line, DBT *out_key, DBT *out_data) {
-       return(0);
-}
-
-
 // Convert a "msgtext" record to a message on disk.   NOT THREADSAFE
 // This also works for "bigmsg" records.
 int convert_msgtext(char *line, DBT *out_key, DBT *out_data) {
@@ -467,27 +461,33 @@ int convert_usetable(char *line, DBT *out_key, DBT *out_data) {
 }
 
 
-#if 0
-// Convert a "foo" record to a record on disk.
-int convert_foo(char *line, DBT *out_key, DBT *out_data) {
+// Import a config record
+// The key is the config key
+// The data is the config key, a null, the value, and another null
+int convert_config(char *line, DBT *out_key, DBT *out_data) {
        char *token;
-       struct ctdlfoo *r = malloc(sizeof(struct ctdlfoo));
-
-       memset(r, 0, sizeof(struct ctdlfoo));
        char *p = line;
+       char *k, *v;
 
        for (int i=0; (token = strsep(&p, "|")); ++i) {
                switch(i) {
+                       case 1:
+                               k = token;
+                               out_key->size = strlen(token);
+                               out_key->data = strdup(token);
+                               break;
+                       case 2:
+                               v = token;
+                               out_data->size = strlen(k) + strlen(v) + 2;
+                               out_data->data = reallok(NULL, out_data->size);
+                               strcpy(out_data->data, k);
+                               strcpy(out_data->data + strlen(k) + 1, v);
+                               break;
                }
        }
 
-       out_key->size = strlen(r->QRname);
-       out_key->data = strdup(r->QRname);
-       out_data->size = sizeof(struct ctdlfoo);
-       out_data->data = r;
        return(1);
 }
-#endif
 
 
 // Ingest one line of dump data.  NOT REENTRANT
@@ -578,7 +578,7 @@ void ingest_one(char *line, DB_ENV *dst_dbenv) {
        else if (!strcasecmp(record_type, "visit"))             row_was_good = convert_visit(line, &out_key, &out_data);
        else if (!strcasecmp(record_type, "use"))               row_was_good = convert_usetable(line, &out_key, &out_data);
        else if (!strcasecmp(record_type, "bigmsg"))            row_was_good = convert_msgtext(line, &out_key, &out_data);
-       else if (!strcasecmp(record_type, "config"))            row_was_good = convert_foo(line, &out_key, &out_data);
+       else if (!strcasecmp(record_type, "config"))            row_was_good = convert_config(line, &out_key, &out_data);
        else                                                    row_was_good = 0;
 
        if (row_was_good) {