// 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) {
+int import_msgtext(char *line, DBT *out_key, DBT *out_data) {
static char *b64_decoded_msg = NULL;
static size_t b64_decoded_alloc = 0;
// Convert a "msgmeta" record to a message metadata record on disk. NOT THREADSAFE
-int convert_msgmeta(char *line, DBT *out_key, DBT *out_data) {
+int import_msgmeta(char *line, DBT *out_key, DBT *out_data) {
char *token;
struct MetaData *m = malloc(sizeof(struct MetaData));
// Convert a "user" record to a record on disk. (Source string is unusable after this function is called.)
-int convert_user(char *line, DBT *out_key, DBT *out_data) {
+int import_user(char *line, DBT *out_key, DBT *out_data) {
char userkey[USERNAME_SIZE];
char *token;
struct ctdluser *u = malloc(sizeof(struct ctdluser));
// Convert a "room" record to a record on disk. (Source string is unusable after this function is called.)
-int convert_room(char *line, DBT *out_key, DBT *out_data) {
+int import_room(char *line, DBT *out_key, DBT *out_data) {
char *token;
struct ctdlroom *r = malloc(sizeof(struct ctdlroom));
// Convert a floor record to a record on disk.
-int convert_floor(char *line, DBT *out_key, DBT *out_data) {
+int import_floor(char *line, DBT *out_key, DBT *out_data) {
char *token;
struct floor *f = malloc(sizeof(struct floor));
int floor_num;
// Import a msglist record
// msglist|26|32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51|
-int convert_msglist(char *line, DBT *out_key, DBT *out_data) {
+int import_msglist(char *line, DBT *out_key, DBT *out_data) {
long roomnum;
char *token, *mtoken;
char *p = line;
// Convert a "visit" record to a record on disk.
-int convert_visit(char *line, DBT *out_key, DBT *out_data) {
+int import_visit(char *line, DBT *out_key, DBT *out_data) {
char *token;
struct visit *v = malloc(sizeof(struct visit));
}
+// Convert a "dir" record to a record on disk.
+int import_dir(char *line, DBT *out_key, DBT *out_data) {
+ return(0);
+}
+
+
// Convert a "usetable" record to a record on disk.
-int convert_usetable(char *line, DBT *out_key, DBT *out_data) {
+int import_usetable(char *line, DBT *out_key, DBT *out_data) {
char *token;
struct UseTable *u = malloc(sizeof(struct UseTable));
}
+int import_fulltext(char *line, DBT *out_key, DBT *out_data) {
+ return(0);
+}
+int import_euidindex(char *line, DBT *out_key, DBT *out_data) {
+ return(0);
+}
+int import_usersbynumber(char *line, DBT *out_key, DBT *out_data) {
+ return(0);
+}
+
+
+
+
// 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) {
+int import_config(char *line, DBT *out_key, DBT *out_data) {
char *token;
char *p = line;
char *k, *v;
memset(&out_key, 0, sizeof(DBT));
memset(&out_data, 0, sizeof(DBT));
row_was_good = 0;
- if (!strcasecmp(record_type, "msgtext")) row_was_good = convert_msgtext(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "msgmeta")) row_was_good = convert_msgmeta(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "user")) row_was_good = convert_user(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "room")) row_was_good = convert_room(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "floor")) row_was_good = convert_floor(line, &out_key, &out_data);
- else if (!strcasecmp(record_type, "msglist")) row_was_good = convert_msglist(line, &out_key, &out_data);
- 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_config(line, &out_key, &out_data);
+ 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 (row_was_good) {
int main(int argc, char **argv) {
char *dst_dir = NULL;
int confirmed = 0;
- static DB_ENV *dst_dbenv; // Source DB environment (global)
+ static DB_ENV *dst_dbenv; // Target DB environment
// display the greeting
fprintf(stderr, "\033[44m\033[33m\033[1m \033[K\033[0m\n"
exit(0);
}
- char cmd[1024];
+ // Remove any database that is already in the target directory (yes, delete it, be careful)
+ char cmd[PATH_MAX];
snprintf(cmd, sizeof cmd, "rm -fv %s/cdb.* %s/log.*", dst_dir, dst_dir);
system(cmd);