Update of /cvsroot/srvx/services/src
In directory usw-pr-cvs1:/tmp/cvs-serv6815/src
Modified Files:
saxdb.c
Log Message:
implement "mondo" database read/write
Index: saxdb.c
===================================================================
RCS file: /cvsroot/srvx/services/src/saxdb.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** saxdb.c 17 Aug 2002 20:59:40 -0000 1.6
--- saxdb.c 18 Aug 2002 05:42:50 -0000 1.7
***************
*** 48,51 ****
--- 48,52 ----
static struct saxdb *mondo_db;
static struct dict *saxdbs; /* -> struct saxdb */
+ static struct dict *mondo_sections; /* -> struct saxdb */
static struct module *saxdb_module;
***************
*** 63,66 ****
--- 64,68 ----
struct saxdb *
saxdb_register(const char *name, saxdb_reader_func_t *reader, saxdb_writer_func_t *writer) {
+ char mondo_path[MAXLEN];
struct saxdb *db;
int ii;
***************
*** 74,78 ****
strcpy(db->filename+ii, ".db");
dict_insert(saxdbs, db->name, db);
! saxdb_read_db(db);
return db;
}
--- 76,81 ----
strcpy(db->filename+ii, ".db");
dict_insert(saxdbs, db->name, db);
! sprintf(mondo_path, "dbs/%s/mondo_section", name);
! if (!conf_get_data(mondo_path, RECDB_QSTRING)) saxdb_read_db(db);
return db;
}
***************
*** 182,186 ****
saxdb_pre_object(struct saxdb_context *dest) {
unsigned int ii;
! for (ii=0; ii<dest->indent; ++ii) saxdb_put_char(dest, '\t');
}
#else
--- 185,191 ----
saxdb_pre_object(struct saxdb_context *dest) {
unsigned int ii;
! if (COMPLEX(dest)) {
! for (ii=0; ii<dest->indent; ++ii) saxdb_put_char(dest, '\t');
! }
}
#else
***************
*** 210,215 ****
assert(dest->complex.used > 0);
if (COMPLEX(dest)) dest->indent--;
- dest->complex.used--;
saxdb_pre_object(dest);
saxdb_put_char(dest, '}');
saxdb_post_object(dest);
--- 215,220 ----
assert(dest->complex.used > 0);
if (COMPLEX(dest)) dest->indent--;
saxdb_pre_object(dest);
+ dest->complex.used--;
saxdb_put_char(dest, '}');
saxdb_post_object(dest);
***************
*** 261,270 ****
static SAXDB_READER(saxdb_mondo_reader) {
! (void)db; /* TODO */
return 0;
}
static SAXDB_WRITER(saxdb_mondo_writer) {
! (void)ctx; /* TODO */
return 0;
}
--- 266,300 ----
static SAXDB_READER(saxdb_mondo_reader) {
! struct saxdb *saxdb;
! dict_iterator_t it;
! struct record_data *rd;
! int res;
!
! for (it = dict_first(db); it; it = iter_next(it)) {
! saxdb = dict_find(mondo_sections, iter_key(it), NULL);
! if (!saxdb) continue;
! rd = iter_data(it);
! if (rd->type == RECDB_OBJECT) {
! res = saxdb->reader(rd->d.object);
! if (res) return res;
! }
! }
return 0;
}
static SAXDB_WRITER(saxdb_mondo_writer) {
! struct saxdb *saxdb;
! dict_iterator_t it;
! int res;
!
! for (it = dict_first(mondo_sections); it; it = iter_next(it)) {
! saxdb = iter_data(it);
! saxdb_start_record(ctx, iter_key(it), 1);
! res = saxdb->writer(ctx);
! if (res) return res;
! /* cheat a little here ;) */
! saxdb_put_char(ctx, '\n');
! saxdb_end_record(ctx);
! }
return 0;
}
***************
*** 293,296 ****
--- 323,327 ----
if ((str = database_get_data(node, "mondo_section", RECDB_QSTRING))) {
db->mondo_section = strdup(str);
+ dict_insert(mondo_sections, db->mondo_section, db);
}
if ((str = database_get_data(node, "filename", RECDB_QSTRING))) {
***************
*** 300,306 ****
sprintf(db->filename, "%s.db", iter_key(it));
}
! if ((str = database_get_data(node, "frequency", RECDB_QSTRING))) {
! db->write_interval = ParseInterval(str);
! }
if (db->write_interval && !db->mondo_section) {
timeq_add(now + db->write_interval, saxdb_timed_write, db);
--- 331,336 ----
sprintf(db->filename, "%s.db", iter_key(it));
}
! str = database_get_data(node, "frequency", RECDB_QSTRING);
! db->write_interval = str ? ParseInterval(str) : 1800;
if (db->write_interval && !db->mondo_section) {
timeq_add(now + db->write_interval, saxdb_timed_write, db);
***************
*** 361,365 ****
stop.tv_usec += 1000000;
}
! send_message(user, cmd->parent->bot, "Wrote all saxdb databases (in "FMT_TIME_T".%03lu seconds).", stop.tv_sec, stop.tv_usec);
return 1;
}
--- 391,395 ----
stop.tv_usec += 1000000;
}
! send_message(user, cmd->parent->bot, "Wrote all databases (in "FMT_TIME_T".%03lu seconds).", stop.tv_sec, stop.tv_usec);
return 1;
}
***************
*** 369,372 ****
--- 399,403 ----
saxdbs = dict_new();
dict_set_free_data(saxdbs, saxdb_free);
+ mondo_sections = dict_new();
saxdb_register("mondo", saxdb_mondo_reader, saxdb_mondo_writer);
saxdb_module = module_register("saxdb", MAIN_LOG, "saxdb.help", NULL);
|