void (*export_functions[])(int which_cdb, DBT *in_key, DBT *in_data) = {
- export_msgmain, // CDB_MSGMAIN
- export_user, // CDB_USERS
- export_room, // CDB_ROOMS
- export_floor, // CDB_FLOORTAB
- export_msglist, // CDB_MSGLISTS
- export_visit, // CDB_VISIT
- export_dir, // CDB_DIRECTORY
- export_usetable, // CDB_USETABLE
- export_bigmsg, // CDB_BIGMSGS
- export_fulltext, // CDB_FULLTEXT
- export_euidindex, // CDB_EUIDINDEX
- export_usersbynumber, // CDB_USERSBYNUMBER
- zero_function, // CDB_UNUSED1 (obsolete)
- export_config // CDB_CONFIG
+ export_msgmain, // 00 CDB_MSGMAIN
+ export_user, // 01 CDB_USERS
+ export_room, // 02 CDB_ROOMS
+ export_floor, // 03 CDB_FLOORTAB
+ export_msglist, // 04 CDB_MSGLISTS
+ export_visit, // 05 CDB_VISIT
+ export_dir, // 06 CDB_DIRECTORY
+ export_usetable, // 07 CDB_USETABLE
+ export_bigmsg, // 08 CDB_BIGMSGS
+ export_fulltext, // 09 CDB_FULLTEXT
+ export_euidindex, // 0a CDB_EUIDINDEX
+ export_usersbynumber, // 0b CDB_USERSBYNUMBER
+ zero_function, // 0c CDB_UNUSED1 (obsolete)
+ export_config // 0d CDB_CONFIG
};
// open the file containing the source table
ret = src_dbp->open(src_dbp, NULL, dbfilename, NULL, DB_BTREE, 0, 0600);
if (ret) {
- fprintf(stderr, "ctdldump: db_open: %s\n", db_strerror(ret));
+ fprintf(stderr, "ctdldump: db_open(%s): %s\n", dbfilename, db_strerror(ret));
fprintf(stderr, "ctdldump: exit code %d\n", ret);
exit(CTDLEXIT_DB);
}
close_dbenv(src_dbenv);
printf("end|\n");
+ fprintf(stderr, "ctdldump: \033[32m\033[1mfinished\033[0m\n");
exit(0);
}
// Convert a "dir" record to a record on disk.
int import_dir(char *line, DBT *out_key, DBT *out_data) {
- // FIXME
- return(0);
+ char dirkey[SIZ];
+ char username[USERNAME_SIZE];
+ char *token;
+
+ char *p = line;
+ for (int i=0; (token = strsep(&p, "|")); ++i) {
+ switch(i) {
+ case 1:
+ strncpy(dirkey, token, sizeof(dirkey));
+ break;
+ case 2:
+ strncpy(username, token, sizeof(username));
+ break;
+ }
+ }
+
+ out_key->size = strlen(dirkey);
+ out_key->data = reallok(NULL, out_key->size);
+ out_data->size = strlen(username) + 1;
+ out_data->data = strdup(username);
+ return(1);
}
fflush(stderr);
}
- // Identify the record type we are currently working with
+ // Clear out our record buffer
+ memset(&out_key, 0, sizeof(DBT));
+ memset(&out_data, 0, sizeof(DBT));
+ row_was_good = 0;
+
+ // Identify the record type we are currently working with,
+ // then call the correct conversion function to load up our record buffer.
extract_token(record_type, line, 0, '|', sizeof record_type);
- if (!strcasecmp(record_type, "msgtext")) current_cdb = CDB_MSGMAIN;
- else if (!strcasecmp(record_type, "msgmeta")) current_cdb = CDB_MSGMAIN;
- else if (!strcasecmp(record_type, "user")) current_cdb = CDB_USERS;
- else if (!strcasecmp(record_type, "room")) current_cdb = CDB_ROOMS;
- else if (!strcasecmp(record_type, "floor")) current_cdb = CDB_FLOORTAB;
- else if (!strcasecmp(record_type, "msglist")) current_cdb = CDB_MSGLISTS;
- else if (!strcasecmp(record_type, "visit")) current_cdb = CDB_VISIT;
- else if (!strcasecmp(record_type, "dir")) current_cdb = CDB_DIRECTORY;
- else if (!strcasecmp(record_type, "use")) current_cdb = CDB_USETABLE;
- else if (!strcasecmp(record_type, "bigmsg")) current_cdb = CDB_BIGMSGS;
- else if (!strcasecmp(record_type, "fulltext")) current_cdb = CDB_FULLTEXT;
- else if (!strcasecmp(record_type, "euidindex")) current_cdb = CDB_EUIDINDEX;
- else if (!strcasecmp(record_type, "usersbynumber")) current_cdb = CDB_USERSBYNUMBER;
- else if (!strcasecmp(record_type, "config")) current_cdb = CDB_CONFIG;
- else current_cdb = -1 ;
+ if (!strcasecmp(record_type, "msgtext")) {
+ current_cdb = CDB_MSGMAIN;
+ row_was_good = import_msgtext(line, &out_key, &out_data);
+ }
+ else if (!strcasecmp(record_type, "msgmeta")) {
+ current_cdb = CDB_MSGMAIN;
+ row_was_good = import_msgmeta(line, &out_key, &out_data);
+ }
+ else if (!strcasecmp(record_type, "user")) {
+ current_cdb = CDB_USERS;
+ row_was_good = import_user(line, &out_key, &out_data);
+ }
+ else if (!strcasecmp(record_type, "room")) {
+ current_cdb = CDB_ROOMS;
+ row_was_good = import_room(line, &out_key, &out_data);
+ }
+ else if (!strcasecmp(record_type, "floor")) {
+ current_cdb = CDB_FLOORTAB;
+ row_was_good = import_floor(line, &out_key, &out_data);
+ }
+ else if (!strcasecmp(record_type, "msglist")) {
+ current_cdb = CDB_MSGLISTS;
+ row_was_good = import_msglist(line, &out_key, &out_data);
+ }
+ else if (!strcasecmp(record_type, "visit")) {
+ current_cdb = CDB_VISIT;
+ row_was_good = import_visit(line, &out_key, &out_data);
+ }
+ else if (!strcasecmp(record_type, "dir")) {
+ current_cdb = CDB_DIRECTORY;
+ row_was_good = import_dir(line, &out_key, &out_data);
+ }
+ else if (!strcasecmp(record_type, "use")) {
+ current_cdb = CDB_USETABLE;
+ row_was_good = import_usetable(line, &out_key, &out_data);
+ }
+ else if (!strcasecmp(record_type, "bigmsg")) {
+ current_cdb = CDB_BIGMSGS;
+ row_was_good = import_msgtext(line, &out_key, &out_data);
+ }
+ else if (!strcasecmp(record_type, "fulltext")) {
+ current_cdb = CDB_FULLTEXT;
+ row_was_good = import_fulltext(line, &out_key, &out_data);
+ }
+ else if (!strcasecmp(record_type, "euidindex")) {
+ current_cdb = CDB_EUIDINDEX;
+ row_was_good = import_euidindex(line, &out_key, &out_data);
+ }
+ else if (!strcasecmp(record_type, "usersbynumber")) {
+ current_cdb = CDB_USERSBYNUMBER;
+ row_was_good = import_usersbynumber(line, &out_key, &out_data);
+ }
+ else if (!strcasecmp(record_type, "config")) {
+ current_cdb = CDB_CONFIG;
+ row_was_good = import_config(line, &out_key, &out_data);
+ }
+ else {
+ current_cdb = -1 ;
+ }
+ // If the current record is a different table than the previous record,
+ // then close the other table and open the correct one.
if (current_cdb != previous_cdb) {
if (previous_cdb >= 0) {
fprintf(stderr, "\n");
// open the file containing the destination table
ret = dst_dbp->open(dst_dbp, NULL, dbfilename, NULL, DB_BTREE, (DB_CREATE | DB_TRUNCATE), 0600);
if (ret) {
- fprintf(stderr, "db: db_open: %s\n", db_strerror(ret));
+ fprintf(stderr, "db: db_open(%s): %s\n", dbfilename, db_strerror(ret));
fprintf(stderr, "db: exit code %d\n", ret);
exit(CTDLEXIT_DB);
}
previous_cdb = current_cdb;
}
- // If we have a valid record type and a target database open, dispatch the correct record type handler.
- memset(&out_key, 0, sizeof(DBT));
- memset(&out_data, 0, sizeof(DBT));
- row_was_good = 0;
- if (!strcasecmp(record_type, "msgtext")) row_was_good = import_msgtext(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "msgmeta")) row_was_good = import_msgmeta(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "user")) row_was_good = import_user(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "room")) row_was_good = import_room(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "floor")) row_was_good = import_floor(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "msglist")) row_was_good = import_msglist(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "visit")) row_was_good = import_visit(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "dir")) row_was_good = import_dir(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "use")) row_was_good = import_usetable(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "bigmsg")) row_was_good = import_msgtext(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "fulltext")) row_was_good = import_fulltext(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "euidindex")) row_was_good = import_euidindex(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "usersbynumber")) row_was_good = import_usersbynumber(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "config")) row_was_good = import_config(line, &out_key, &out_data);
- else row_was_good = 0;
-
+ // If the conversion function was successful, write the record to the database.
if (row_was_good) {
++good_rows;
ret = dst_dbp->put(dst_dbp, NULL, &out_key, &out_data, 0);
ingest(dst_dbenv);
close_dbenv(dst_dbenv);
+ fprintf(stderr, "ctdlload: \033[32m\033[1mfinished\033[0m\n");
exit(0);
}