From 7db06f8379d23e8f1bce2c87f3ce082bb56ac2db Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 5 Sep 2007 08:40:12 +0000 Subject: [PATCH] Fixed bug #1507: Command record=..&id=.. should block if it does not exist. Added a new session watch type plus two HTTP requests for testing of this. --- src/client.c | 6 ++++-- src/http_command.c | 27 ++++++++++++++++++++------- src/logic.c | 24 ++++++++++++++++-------- src/pazpar2.h | 9 ++++++--- test/test_http_22.res | 1 + test/test_http_23.res | 23 +++++++++++++++++++++++ test/test_http_urls | 4 +++- 7 files changed, 73 insertions(+), 21 deletions(-) create mode 100644 test/test_http_22.res create mode 100644 test/test_http_23.res diff --git a/src/client.c b/src/client.c index 25fbb5f..25dae7a 100644 --- a/src/client.c +++ b/src/client.c @@ -1,4 +1,4 @@ -/* $Id: client.c,v 1.18 2007-08-17 12:39:11 adam Exp $ +/* $Id: client.c,v 1.19 2007-09-05 08:40:12 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -581,7 +581,9 @@ static void ingest_records(struct client *cl, Z_Records *r) continue; } if (rlist->num_records) - session_alert_watch(s, SESSION_WATCH_RECORDS); + session_alert_watch(s, SESSION_WATCH_SHOW); + if (rlist->num_records) + session_alert_watch(s, SESSION_WATCH_RECORD); #if USE_TIMING yaz_timing_stop(t); diff --git a/src/http_command.c b/src/http_command.c index cfd4dc1..7699b9a 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,4 +1,4 @@ -/* $Id: http_command.c,v 1.59 2007-09-05 07:24:04 adam Exp $ +/* $Id: http_command.c,v 1.60 2007-09-05 08:40:12 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -20,7 +20,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA */ /* - * $Id: http_command.c,v 1.59 2007-09-05 07:24:04 adam Exp $ + * $Id: http_command.c,v 1.60 2007-09-05 08:40:12 adam Exp $ */ #include @@ -519,6 +519,8 @@ void show_raw_reset(void *data, struct http_channel *c) client_show_raw_reset(client); } +static void cmd_record_ready(void *data); + static void cmd_record(struct http_channel *c) { struct http_response *rs = c->response; @@ -540,7 +542,11 @@ static void cmd_record(struct http_channel *c) wrbuf_rewind(c->wrbuf); if (!(rec = show_single(s->psession, idstr))) { - error(rs, PAZPAR2_RECORD_MISSING, idstr); + if (session_set_watch(s->psession, SESSION_WATCH_RECORD, + cmd_record_ready, c, c) != 0) + { + error(rs, PAZPAR2_RECORD_MISSING, idstr); + } return; } if (offsetstr) @@ -586,6 +592,14 @@ static void cmd_record(struct http_channel *c) } } +static void cmd_record_ready(void *data) +{ + struct http_channel *c = (struct http_channel *) data; + + yaz_log(YLOG_LOG, "cmd_records_ready chan=%p", c); + cmd_record(c); +} + static void show_records(struct http_channel *c, int active) { struct http_request *rq = c->request; @@ -678,13 +692,12 @@ static void cmd_show(struct http_channel *c) if (status && (!s->psession->reclist || !s->psession->reclist->num_records)) { // if there is already a watch/block. we do not block this one - if (session_set_watch(s->psession, - SESSION_WATCH_RECORDS, - show_records_ready, c, c) == 0) + if (session_set_watch(s->psession, SESSION_WATCH_SHOW, + show_records_ready, c, c) != 0) { yaz_log(YLOG_DEBUG, "Blocking on cmd_show"); - return; } + return; } } diff --git a/src/logic.c b/src/logic.c index e3f5f17..e8c2e88 100644 --- a/src/logic.c +++ b/src/logic.c @@ -1,4 +1,4 @@ -/* $Id: logic.c,v 1.63 2007-09-05 07:24:04 adam Exp $ +/* $Id: logic.c,v 1.64 2007-09-05 08:40:12 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -551,13 +551,21 @@ int session_set_watch(struct session *s, int what, void session_alert_watch(struct session *s, int what) { - if (!s->watchlist[what].fun) - return; - http_remove_observer(s->watchlist[what].obs); - (*s->watchlist[what].fun)(s->watchlist[what].data); - s->watchlist[what].fun = 0; - s->watchlist[what].data = 0; - s->watchlist[what].obs = 0; + if (s->watchlist[what].fun) + { + /* our watch is no longer associated with http_channel */ + http_remove_observer(s->watchlist[what].obs); + session_watchfun fun = s->watchlist[what].fun; + void *data = s->watchlist[what].data; + + /* reset watch before fun is invoked - in case fun wants to set + it again */ + s->watchlist[what].fun = 0; + s->watchlist[what].data = 0; + s->watchlist[what].obs = 0; + + fun(data); + } } //callback for grep_databases diff --git a/src/pazpar2.h b/src/pazpar2.h index a21c1f1..e6d59d3 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -1,4 +1,4 @@ -/* $Id: pazpar2.h,v 1.48 2007-09-05 07:24:04 adam Exp $ +/* $Id: pazpar2.h,v 1.49 2007-09-05 08:40:12 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -104,8 +104,11 @@ struct session_database struct session_database *next; }; -#define SESSION_WATCH_RECORDS 0 -#define SESSION_WATCH_MAX 0 + + +#define SESSION_WATCH_SHOW 0 +#define SESSION_WATCH_RECORD 1 +#define SESSION_WATCH_MAX 1 #define SESSION_MAX_TERMLISTS 10 diff --git a/test/test_http_22.res b/test/test_http_22.res new file mode 100644 index 0000000..d2e0e58 --- /dev/null +++ b/test/test_http_22.res @@ -0,0 +1 @@ +OK \ No newline at end of file diff --git a/test/test_http_23.res b/test/test_http_23.res new file mode 100644 index 0000000..dbd5c2a --- /dev/null +++ b/test/test_http_23.res @@ -0,0 +1,23 @@ + +title how to program a computer author jack collins medium book + +How to program a computer +Jack Collins +11224467 +11224466 +How to program a computer +Jack Collins +11224467 +11224467 +XXXXXXXXXX +Shit: + YYYYYYYYY + +How to program a computer +Jack Collins +11224466 +11224466 +XXXXXXXXXX +Shit: + YYYYYYYYY + diff --git a/test/test_http_urls b/test/test_http_urls index bddbe4b..86080c9 100644 --- a/test/test_http_urls +++ b/test/test_http_urls @@ -20,5 +20,7 @@ http://localhost:9763/search.pz2?session=2&command=search&query=computer http://localhost:9763/search.pz2?session=2&command=show&start=0&number=1&block=1 http://localhost:9763/search.pz2?session=2&command=search&query=kubiak%20stanis%C5%82aw http://localhost:9763/search.pz2?session=2&command=search&query=kubiak%20sts%C5%82aw +2 http://localhost:9763/search.pz2?session=2&command=bytarget - +http://localhost:9763/search.pz2?session=1&command=search&query=computer +http://localhost:9763/search.pz2?session=1&command=record&id=title+how+to+program+a+computer+author+jack+collins+medium+book -- 1.7.10.4