From: Adam Dickmeiss Date: Wed, 14 Oct 2009 14:29:36 +0000 (+0200) Subject: Settings, bytarget + db out-of-range check X-Git-Tag: v1.2.3~21 X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=ddf9bdfd1e80474ce5a3772f77c4401908654b6e;p=pazpar2-moved-to-github.git Settings, bytarget + db out-of-range check Command bytarget with argument settings=1 will show settings per target.. This is to be able to verify correct settings and be able to test that they are correct. The database settings array size is now also stored.. Problems with database settings array is that if not carefull it will be too small (smaller than dictionary per-service in settings). --- diff --git a/src/database.c b/src/database.c index 0a87d0c..fe0e1cd 100644 --- a/src/database.c +++ b/src/database.c @@ -164,6 +164,7 @@ static struct database *load_database(const char *id, db->settings = nmem_malloc(service->nmem, sizeof(struct settings*) * settings_num(service)); + db->num_settings = settings_num(service); memset(db->settings, 0, sizeof(struct settings*) * settings_num(service)); idset = nmem_malloc(service->nmem, sizeof(*idset)); idset->precedence = 0; diff --git a/src/http_command.c b/src/http_command.c index 37ad0bc..9749ce6 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -472,6 +472,7 @@ static void cmd_bytarget(struct http_channel *c) struct http_request *rq = c->request; struct http_session *s = locate_session(rq, rs); struct hitsbytarget *ht; + const char *settings = http_argbyname(rq, "settings"); int count, i; if (!s) @@ -502,8 +503,14 @@ static void cmd_bytarget(struct http_channel *c) wrbuf_puts(c->wrbuf, ""); wrbuf_xmlputs(c->wrbuf, ht[i].state); wrbuf_puts(c->wrbuf, "\n"); - + if (settings && *settings == '1') + { + wrbuf_puts(c->wrbuf, "\n"); + wrbuf_puts(c->wrbuf, wrbuf_cstr(ht[i].settings_xml)); + wrbuf_puts(c->wrbuf, "\n"); + } wrbuf_puts(c->wrbuf, ""); + wrbuf_destroy(ht[i].settings_xml); } wrbuf_puts(c->wrbuf, ""); diff --git a/src/logic.c b/src/logic.c index 9e24e8a..5399dd0 100644 --- a/src/logic.c +++ b/src/logic.c @@ -269,6 +269,29 @@ static xmlDoc *normalize_record(struct session_database *sdb, return rdoc; } +void session_settings_dump(struct session *se, + struct session_database *db, + WRBUF w) +{ + if (db->settings) + { + struct conf_service *service = se->service; + int i, num = settings_num(service); + for (i = 0; i < num; i++) + { + struct setting *s = db->settings[i]; + for (;s; s = s->next) + { + wrbuf_puts(w, "name); + wrbuf_puts(w, "\" value=\""); + wrbuf_xmlputs(w, s->value); + wrbuf_puts(w, "\"/>\n"); + } + } + } +} + // Retrieve first defined value for 'name' for given database. // Will be extended to take into account user associated with session const char *session_setting_oneval(struct session_database *db, int offset) @@ -692,6 +715,7 @@ struct hitsbytarget *hitsbytarget(struct session *se, int *count, NMEM nmem) *count = 0; for (cl = se->clients; cl; cl = client_next_in_session(cl)) { + WRBUF w = wrbuf_alloc(); const char *name = session_setting_oneval(client_get_database(cl), PZ_NAME); @@ -702,6 +726,8 @@ struct hitsbytarget *hitsbytarget(struct session *se, int *count, NMEM nmem) res[*count].diagnostic = client_get_diagnostic(cl); res[*count].state = client_get_state_str(cl); res[*count].connected = client_get_connection(cl) ? 1 : 0; + session_settings_dump(se, client_get_database(cl), w); + res[*count].settings_xml = w; (*count)++; } return res; diff --git a/src/pazpar2.h b/src/pazpar2.h index 0140ebc..b84d11a 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -64,6 +64,7 @@ struct database { char **databases; int errors; struct zr_explain *explain; + int num_settings; struct setting **settings; struct database *next; }; @@ -153,6 +154,7 @@ struct hitsbytarget { int records; const char *state; int connected; + WRBUF settings_xml; }; struct hitsbytarget *hitsbytarget(struct session *s, int *count, NMEM nmem);