+/** \brief use term value as hit count
+ \param s RPN structure
+ \return >= 0: search term number or -1: not found
+
+ Traverse RPN tree 'in order' and use term value as hit count.
+ Only terms that looks a numeric is used.. Returns -1 if
+ no sub tree has a hit count term
+*/
+static Odr_int get_term_hit(Z_RPNStructure *s)
+{
+ Odr_int h = -1;
+ switch(s->which)
+ {
+ case Z_RPNStructure_simple:
+ if (s->u.simple->which == Z_Operand_APT)
+ {
+ Z_AttributesPlusTerm *apt = s->u.simple->u.attributesPlusTerm;
+ if (apt->term->which == Z_Term_general)
+ {
+ Odr_oct *oct = apt->term->u.general;
+ if (oct->len > 0 && oct->buf[0] >= '0' && oct->buf[0] <= '9')
+ {
+ char *endptr;
+ WRBUF hits_str = wrbuf_alloc();
+ wrbuf_write(hits_str, (const char *) oct->buf, oct->len);
+ h = odr_atoi(wrbuf_cstr(hits_str));
+ wrbuf_destroy(hits_str);
+ }
+ }
+ }
+ break;
+ case Z_RPNStructure_complex:
+ h = get_term_hit(s->u.complex->s1);
+ if (h == -1)
+ h = get_term_hit(s->u.complex->s2);
+ break;
+ }
+ return h;
+}
+
+/** \brief gets hit count for numeric terms in RPN queries
+ \param q RPN Query
+ \return number of hits (random or number for term)
+
+ This is just for testing.. A real database of course uses
+ the content of a database to establish a value.. In our case, we
+ have a way to trigger a certain hit count. Good for testing of
+ client applications etc
+*/
+static Odr_int get_hit_count(Z_Query *q)
+{
+ Odr_int h = -1;
+ if (q->which == Z_Query_type_1 || q->which == Z_Query_type_101)
+ h = get_term_hit(q->u.type_1->RPNStructure);
+ if (h == -1)
+ h = rand() % 24;
+ return h;
+}
+
+/** \brief checks if it's a dummy Slow database
+ \param basename database name to check
+ \param association backend association (or NULL if not available)
+ \retval 1 is slow database
+ \retval 0 is not a slow database
+
+ The Slow database is for testing.. It allows us to simulate
+ a slow server...
+*/
+static int check_slow(const char *basename, bend_association association)
+{
+ if (strncmp(basename, "Slow", 4) == 0)
+ {
+#if HAVE_UNISTD_H
+ int i, w = 3;
+ if (basename[4])
+ sscanf(basename+4, "%d", &w);
+ /* wait up to 3 seconds and check if connection is still alive */
+ for (i = 0; i < w; i++)
+ {
+ if (association && !bend_assoc_is_alive(association))
+ {
+ yaz_log(YLOG_LOG, "search aborted");
+ break;
+ }
+ sleep(1);
+ }
+#endif
+ return 1;
+ }
+ return 0;
+}
+