Fixed bug #1507: Command record=..&id=.. should block if it does not exist.
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 5 Sep 2007 08:40:12 +0000 (08:40 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 5 Sep 2007 08:40:12 +0000 (08:40 +0000)
Added a new session watch type plus two HTTP requests for testing of
this.

src/client.c
src/http_command.c
src/logic.c
src/pazpar2.h
test/test_http_22.res [new file with mode: 0644]
test/test_http_23.res [new file with mode: 0644]
test/test_http_urls

index 25fbb5f..25dae7a 100644 (file)
@@ -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);
index cfd4dc1..7699b9a 100644 (file)
@@ -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 <stdio.h>
@@ -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;
         }
     }
 
index e3f5f17..e8c2e88 100644 (file)
@@ -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
index a21c1f1..e6d59d3 100644 (file)
@@ -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 (file)
index 0000000..d2e0e58
--- /dev/null
@@ -0,0 +1 @@
+<search><status>OK</status></search>
\ No newline at end of file
diff --git a/test/test_http_23.res b/test/test_http_23.res
new file mode 100644 (file)
index 0000000..dbd5c2a
--- /dev/null
@@ -0,0 +1,23 @@
+<record>
+<recid>title how to program a computer author jack collins medium book</recid>
+
+<md-title>How to program a computer</md-title>
+<md-author>Jack Collins</md-author>
+<md-lccn>11224467</md-lccn>
+<md-lccn>11224466</md-lccn><location id="z3950.indexdata.com/marc" name="Local Test">
+<md-title>How to program a computer</md-title>
+<md-author>Jack Collins</md-author>
+<md-id>11224467</md-id>
+<md-lccn>11224467</md-lccn>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
+<md-test_usersetting_2>Shit: 
+        YYYYYYYYY</md-test_usersetting_2></location>
+<location id="z3950.indexdata.com/marc" name="Local Test">
+<md-title>How to program a computer</md-title>
+<md-author>Jack Collins</md-author>
+<md-id>11224466</md-id>
+<md-lccn>11224466</md-lccn>
+<md-test-usersetting>XXXXXXXXXX</md-test-usersetting>
+<md-test_usersetting_2>Shit: 
+        YYYYYYYYY</md-test_usersetting_2></location>
+</record>
index bddbe4b..86080c9 100644 (file)
@@ -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