+ id = strtoul(str, NULL, 0);
+
+ if (!(str = database_get_data(hir->d.object, KEY_RECIPIENT, RECDB_QSTRING))) {
+ log_module(MS_LOG, LOG_ERROR, "Recipient not present in history %s; skipping", key);
+ return 0;
+ } else if (!(recipient = get_handle_info(str))) {
+ log_module(MS_LOG, LOG_ERROR, "Invalid recipient %s in history %s; skipping", str, key);
+ return 0;
+ }
+
+ if (!(str = database_get_data(hir->d.object, KEY_FROM, RECDB_QSTRING))) {
+ log_module(MS_LOG, LOG_ERROR, "Sender not present in history %s; skipping", key);
+ return 0;
+ } else if (!(sender = get_handle_info(str))) {
+ log_module(MS_LOG, LOG_ERROR, "Invalid sender %s in history %s; skipping", str, key);
+ return 0;
+ }
+
+ history = add_history(sent, memoserv_get_account(recipient), memoserv_get_account(sender), id);
+
+ return 0;
+}
+
+static int
+memoserv_saxdb_read(struct dict *database)
+{
+ struct dict *section;
+ dict_iterator_t it;
+
+ if((section = database_get_data(database, KEY_MAIN_ACCOUNTS, RECDB_OBJECT)))
+ for(it = dict_first(section); it; it = iter_next(it))
+ memoserv_user_read(iter_key(it), iter_data(it));
+
+ if((section = database_get_data(database, KEY_MAIN_MEMOS, RECDB_OBJECT)))
+ for(it = dict_first(section); it; it = iter_next(it))
+ memoserv_memo_read(iter_key(it), iter_data(it));
+
+ if((section = database_get_data(database, KEY_MAIN_HISTORY, RECDB_OBJECT)))
+ for(it = dict_first(section); it; it = iter_next(it))
+ memoserv_history_read(iter_key(it), iter_data(it));
+
+ return 0;
+}
+
+static int
+memoserv_write_users(struct saxdb_context *ctx, struct memo_account *ma)
+{
+ saxdb_start_record(ctx, ma->handle->handle, 0);
+
+ saxdb_write_int(ctx, KEY_FLAGS, ma->flags);
+ saxdb_write_int(ctx, KEY_LIMIT, ma->limit);
+
+ saxdb_end_record(ctx);
+ return 0;
+}
+
+static int
+memoserv_write_memos(struct saxdb_context *ctx, struct memo *memo)
+{
+ char str[20];
+
+ memset(str, '\0', sizeof(str));
+ saxdb_start_record(ctx, inttobase64(str, memo->id, sizeof(str)-1), 0);
+
+ saxdb_write_int(ctx, KEY_SENT, memo->sent);
+ saxdb_write_int(ctx, KEY_ID, memo->id);
+ saxdb_write_string(ctx, KEY_RECIPIENT, memo->recipient->handle->handle);
+ saxdb_write_string(ctx, KEY_FROM, memo->sender->handle->handle);
+ saxdb_write_string(ctx, KEY_MESSAGE, memo->message);
+
+ if (memo->is_read)
+ saxdb_write_int(ctx, KEY_READ, 1);
+
+ if (memo->reciept)
+ saxdb_write_int(ctx, KEY_RECIEPT, 1);
+
+ saxdb_end_record(ctx);
+ return 0;
+}
+
+static int
+memoserv_write_history(struct saxdb_context *ctx, struct history *history)
+{
+ char str[20];
+
+ memset(str, '\0', sizeof(str));
+ saxdb_start_record(ctx, inttobase64(str, history->id, sizeof(str)-1), 0);
+
+ saxdb_write_int(ctx, KEY_SENT, history->sent);
+ saxdb_write_int(ctx, KEY_ID, history->id);
+ saxdb_write_string(ctx, KEY_RECIPIENT, history->recipient->handle->handle);
+ saxdb_write_string(ctx, KEY_FROM, history->sender->handle->handle);
+
+ saxdb_end_record(ctx);