2 * $Id: zoom-c.c,v 1.28 2002-05-17 12:48:30 adam Exp $
4 * ZOOM layer for C, connections, result sets, queries.
7 #include <yaz/xmalloc.h>
8 #include <yaz/otherinfo.h>
10 #include <yaz/pquery.h>
11 #include <yaz/diagbib1.h>
19 static int ZOOM_connection_send_init (ZOOM_connection c);
21 static ZOOM_Event ZOOM_Event_create (int kind)
23 ZOOM_Event event = (ZOOM_Event) xmalloc (sizeof(*event));
30 static void ZOOM_Event_destroy (ZOOM_Event event)
35 static void ZOOM_connection_put_event (ZOOM_connection c, ZOOM_Event event)
39 c->m_queue_back->prev = event;
40 assert (c->m_queue_front);
44 assert (!c->m_queue_front);
45 c->m_queue_front = event;
47 event->next = c->m_queue_back;
49 c->m_queue_back = event;
52 static ZOOM_Event ZOOM_connection_get_event(ZOOM_connection c)
54 ZOOM_Event event = c->m_queue_front;
57 assert (c->m_queue_back);
58 c->m_queue_front = event->prev;
61 assert (c->m_queue_back);
62 c->m_queue_front->next = 0;
66 c->last_event = event->kind;
70 static void clear_error (ZOOM_connection c)
75 case ZOOM_ERROR_CONNECT:
76 case ZOOM_ERROR_MEMORY:
77 case ZOOM_ERROR_DECODE:
78 case ZOOM_ERROR_CONNECTION_LOST:
80 case ZOOM_ERROR_INTERNAL:
83 c->error = ZOOM_ERROR_NONE;
89 ZOOM_task ZOOM_connection_add_task (ZOOM_connection c, int which)
91 ZOOM_task *taskp = &c->tasks;
93 taskp = &(*taskp)->next;
94 *taskp = (ZOOM_task) xmalloc (sizeof(**taskp));
95 (*taskp)->running = 0;
96 (*taskp)->which = which;
102 void ZOOM_connection_remove_task (ZOOM_connection c)
104 ZOOM_task task = c->tasks;
108 c->tasks = task->next;
111 case ZOOM_TASK_SEARCH:
112 ZOOM_resultset_destroy (task->u.search.resultset);
114 case ZOOM_TASK_RETRIEVE:
115 ZOOM_resultset_destroy (task->u.retrieve.resultset);
117 case ZOOM_TASK_CONNECT:
120 ZOOM_scanset_destroy (task->u.scan.scan);
129 void ZOOM_connection_remove_tasks (ZOOM_connection c)
132 ZOOM_connection_remove_task(c);
135 static ZOOM_record record_cache_lookup (ZOOM_resultset r,
137 const char *elementSetName);
139 ZOOM_API(ZOOM_connection)
140 ZOOM_connection_create (ZOOM_options options)
142 ZOOM_connection c = (ZOOM_connection) xmalloc (sizeof(*c));
146 c->state = STATE_IDLE;
147 c->error = ZOOM_ERROR_NONE;
155 c->options = ZOOM_options_create_with_parent(options);
164 c->odr_in = odr_createmem (ODR_DECODE);
165 c->odr_out = odr_createmem (ODR_ENCODE);
168 c->support_named_resultsets = 0;
169 c->last_event = ZOOM_EVENT_NONE;
171 c->m_queue_front = 0;
176 /* set database names. Take local databases (if set); otherwise
177 take databases given in ZURL (if set); otherwise use Default */
178 static char **set_DatabaseNames (ZOOM_connection con, ZOOM_options options,
181 char **databaseNames;
184 const char *cp = ZOOM_options_get (options, "databaseName");
188 cp = strchr (con->host_port, '/');
195 while ((c = strchr(c, '+')))
203 databaseNames = (char**)
204 odr_malloc (con->odr_out, no * sizeof(*databaseNames));
208 c = strchr (cp, '+');
216 /* cp ptr to first char of db name, c is char
218 databaseNames[no] = (char*) odr_malloc (con->odr_out, 1+c-cp);
219 memcpy (databaseNames[no], cp, c-cp);
220 databaseNames[no++][c-cp] = '\0';
225 databaseNames[no] = NULL;
227 return databaseNames;
230 ZOOM_API(ZOOM_connection)
231 ZOOM_connection_new (const char *host, int portnum)
233 ZOOM_connection c = ZOOM_connection_create (0);
235 ZOOM_connection_connect (c, host, portnum);
240 ZOOM_connection_connect(ZOOM_connection c,
241 const char *host, int portnum)
246 val = ZOOM_options_get (c->options, "proxy");
248 c->proxy = xstrdup (val);
255 sprintf (hostn, "%.80s:%d", host, portnum);
256 c->host_port = xstrdup(hostn);
259 c->host_port = xstrdup(host);
261 ZOOM_options_set(c->options, "host", c->host_port);
263 c->async = ZOOM_options_get_bool (c->options, "async", 0);
265 c->error = ZOOM_ERROR_NONE;
267 task = ZOOM_connection_add_task (c, ZOOM_TASK_CONNECT);
271 while (ZOOM_event (1, &c))
277 ZOOM_query_create(void)
279 ZOOM_query s = (ZOOM_query) xmalloc (sizeof(*s));
284 s->odr = odr_createmem (ODR_ENCODE);
290 ZOOM_query_destroy(ZOOM_query s)
296 yaz_log (LOG_DEBUG, "ZOOM_query_destroy count=%d", s->refcount);
297 if (s->refcount == 0)
299 odr_destroy (s->odr);
305 ZOOM_query_prefix(ZOOM_query s, const char *str)
307 s->query = (Z_Query *) odr_malloc (s->odr, sizeof(*s->query));
308 s->query->which = Z_Query_type_1;
309 s->query->u.type_1 = p_query_rpn(s->odr, PROTO_Z3950, str);
310 if (!s->query->u.type_1)
316 ZOOM_query_sortby(ZOOM_query s, const char *criteria)
318 s->sort_spec = yaz_sort_spec (s->odr, criteria);
324 static int do_write(ZOOM_connection c);
327 ZOOM_connection_destroy(ZOOM_connection c)
334 for (r = c->resultsets; r; r = r->next)
339 odr_destroy (c->odr_in);
340 odr_destroy (c->odr_out);
341 ZOOM_options_destroy (c->options);
342 ZOOM_connection_remove_tasks (c);
343 xfree (c->host_port);
345 xfree (c->cookie_out);
346 xfree (c->cookie_in);
350 void ZOOM_resultset_addref (ZOOM_resultset r)
355 ZOOM_resultset ZOOM_resultset_create ()
357 ZOOM_resultset r = (ZOOM_resultset) xmalloc (sizeof(*r));
361 r->odr = odr_createmem (ODR_ENCODE);
375 ZOOM_API(ZOOM_resultset)
376 ZOOM_connection_search_pqf(ZOOM_connection c, const char *q)
379 ZOOM_query s = ZOOM_query_create();
381 ZOOM_query_prefix (s, q);
383 r = ZOOM_connection_search (c, s);
384 ZOOM_query_destroy (s);
388 ZOOM_API(ZOOM_resultset)
389 ZOOM_connection_search(ZOOM_connection c, ZOOM_query q)
391 ZOOM_resultset r = ZOOM_resultset_create ();
395 r->r_sort_spec = q->sort_spec;
396 r->r_query = q->query;
399 r->options = ZOOM_options_create_with_parent(c->options);
401 r->start = ZOOM_options_get_int(r->options, "start", 0);
402 r->count = ZOOM_options_get_int(r->options, "count", 0);
403 r->piggyback = ZOOM_options_get_bool (r->options, "piggyback", 1);
404 cp = ZOOM_options_get (r->options, "setname");
406 r->setname = xstrdup (cp);
410 r->next = c->resultsets;
413 task = ZOOM_connection_add_task (c, ZOOM_TASK_SEARCH);
414 task->u.search.resultset = r;
415 ZOOM_resultset_addref (r);
421 while (ZOOM_event (1, &c))
428 ZOOM_resultset_destroy(ZOOM_resultset r)
433 yaz_log (LOG_DEBUG, "destroy r = %p count=%d", r, r->refcount);
434 if (r->refcount == 0)
436 ZOOM_record_cache rc;
438 for (rc = r->record_cache; rc; rc = rc->next)
439 if (rc->rec.wrbuf_marc)
440 wrbuf_free (rc->rec.wrbuf_marc, 1);
443 /* remove ourselves from the resultsets in connection */
444 ZOOM_resultset *rp = &r->connection->resultsets;
447 assert (*rp); /* we must be in this list!! */
449 { /* OK, we're here - take us out of it */
456 ZOOM_query_destroy (r->search);
457 ZOOM_options_destroy (r->options);
458 odr_destroy (r->odr);
465 ZOOM_resultset_size (ZOOM_resultset r)
470 static void do_close (ZOOM_connection c)
476 c->state = STATE_IDLE;
479 static void ZOOM_resultset_retrieve (ZOOM_resultset r,
480 int force_sync, int start, int count)
490 task = ZOOM_connection_add_task (c, ZOOM_TASK_RETRIEVE);
491 task->u.retrieve.resultset = r;
492 task->u.retrieve.start = start;
493 task->u.retrieve.count = count;
495 ZOOM_resultset_addref (r);
497 if (!r->connection->async || force_sync)
498 while (r->connection && ZOOM_event (1, &r->connection))
503 ZOOM_resultset_records (ZOOM_resultset r, ZOOM_record *recs,
504 size_t start, size_t count)
506 int force_present = 0;
512 ZOOM_resultset_retrieve (r, force_present, start, count);
516 for (i = 0; i< count; i++)
517 recs[i] = ZOOM_resultset_record_immediate (r, i+start);
521 static int do_connect (ZOOM_connection c)
524 const char *effective_host;
527 effective_host = c->proxy;
529 effective_host = c->host_port;
531 yaz_log (LOG_DEBUG, "do_connect host=%s", effective_host);
534 c->cs = cs_create_host (effective_host, 0, &add);
538 int ret = cs_connect (c->cs, add);
539 yaz_log (LOG_DEBUG, "cs_connect returned %d", ret);
542 ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_CONNECT);
543 ZOOM_connection_put_event(c, event);
544 ZOOM_connection_send_init(c);
545 c->state = STATE_ESTABLISHED;
550 c->state = STATE_CONNECTING;
551 c->mask = ZOOM_SELECT_EXCEPT;
552 if (c->cs->io_pending & CS_WANT_WRITE)
553 c->mask += ZOOM_SELECT_WRITE;
554 if (c->cs->io_pending & CS_WANT_READ)
555 c->mask += ZOOM_SELECT_READ;
559 c->state = STATE_IDLE;
560 c->error = ZOOM_ERROR_CONNECT;
564 int z3950_connection_socket(ZOOM_connection c)
567 return cs_fileno(c->cs);
571 int z3950_connection_mask(ZOOM_connection c)
578 static int encode_APDU(ZOOM_connection c, Z_APDU *a, ODR out)
583 sprintf (str, "send_APDU t=%p type=%d", c, a->which);
586 Z_OtherInformation **oi;
588 yaz_oi_set_string_oidval(oi, out, VAL_COOKIE, 1, c->cookie_out);
590 if (!z_APDU(out, &a, 0, 0))
592 FILE *outf = fopen("/tmp/apdu.txt", "w");
595 ODR odr_pr = odr_createmem(ODR_PRINT);
596 fprintf (outf, "a=%p\n", a);
597 odr_setprint(odr_pr, outf);
598 z_APDU(odr_pr, &a, 0, 0);
602 c->error = ZOOM_ERROR_ENCODE;
610 static int send_APDU (ZOOM_connection c, Z_APDU *a)
614 if (encode_APDU(c, a, c->odr_out))
616 c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0);
617 event = ZOOM_Event_create (ZOOM_EVENT_SEND_APDU);
618 ZOOM_connection_put_event (c, event);
619 odr_reset(c->odr_out);
624 static int ZOOM_connection_send_init (ZOOM_connection c)
627 Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_initRequest);
628 Z_InitRequest *ireq = apdu->u.initRequest;
629 Z_IdAuthentication *auth = (Z_IdAuthentication *)
630 odr_malloc(c->odr_out, sizeof(*auth));
631 const char *auth_groupId = ZOOM_options_get (c->options, "group");
632 const char *auth_userId = ZOOM_options_get (c->options, "user");
633 const char *auth_password = ZOOM_options_get (c->options, "pass");
635 ODR_MASK_SET(ireq->options, Z_Options_search);
636 ODR_MASK_SET(ireq->options, Z_Options_present);
637 ODR_MASK_SET(ireq->options, Z_Options_scan);
638 ODR_MASK_SET(ireq->options, Z_Options_sort);
639 ODR_MASK_SET(ireq->options, Z_Options_extendedServices);
640 ODR_MASK_SET(ireq->options, Z_Options_namedResultSets);
642 ODR_MASK_SET(ireq->protocolVersion, Z_ProtocolVersion_1);
643 ODR_MASK_SET(ireq->protocolVersion, Z_ProtocolVersion_2);
644 ODR_MASK_SET(ireq->protocolVersion, Z_ProtocolVersion_3);
646 impname = ZOOM_options_get (c->options, "implementationName");
647 ireq->implementationName =
648 (char *) odr_malloc (c->odr_out, 15 + (impname ? strlen(impname) : 0));
649 strcpy (ireq->implementationName, "");
652 strcat (ireq->implementationName, impname);
653 strcat (ireq->implementationName, "/");
655 strcat (ireq->implementationName, "ZOOM-C/YAZ");
657 *ireq->maximumRecordSize =
658 ZOOM_options_get_int (c->options, "maximumRecordSize", 1024*1024);
659 *ireq->preferredMessageSize =
660 ZOOM_options_get_int (c->options, "preferredMessageSize", 1024*1024);
662 if (auth_groupId || auth_password)
664 Z_IdPass *pass = (Z_IdPass *) odr_malloc(c->odr_out, sizeof(*pass));
667 if (auth_groupId && *auth_groupId)
669 pass->groupId = (char *)
670 odr_malloc(c->odr_out, strlen(auth_groupId)+1);
671 strcpy(pass->groupId, auth_groupId);
675 if (auth_userId && *auth_userId)
677 pass->userId = (char *)
678 odr_malloc(c->odr_out, strlen(auth_userId)+1);
679 strcpy(pass->userId, auth_userId);
683 if (auth_password && *auth_password)
685 pass->password = (char *)
686 odr_malloc(c->odr_out, strlen(auth_password)+1);
687 strcpy(pass->password, auth_password);
692 auth->which = Z_IdAuthentication_idPass;
693 auth->u.idPass = pass;
694 ireq->idAuthentication = auth;
697 else if (auth_userId)
699 auth->which = Z_IdAuthentication_open;
700 auth->u.open = (char *)
701 odr_malloc(c->odr_out, strlen(auth_userId)+1);
702 strcpy(auth->u.open, auth_userId);
703 ireq->idAuthentication = auth;
706 yaz_oi_set_string_oidval(&ireq->otherInfo, c->odr_out,
707 VAL_PROXY, 1, c->host_port);
714 static int ZOOM_connection_send_search (ZOOM_connection c)
717 int lslb, ssub, mspn;
719 Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_searchRequest);
720 Z_SearchRequest *search_req = apdu->u.searchRequest;
721 const char *elementSetName;
722 const char *smallSetElementSetName;
723 const char *mediumSetElementSetName;
727 assert (c->tasks->which == ZOOM_TASK_SEARCH);
729 r = c->tasks->u.search.resultset;
732 ZOOM_options_get (r->options, "elementSetName");
733 smallSetElementSetName =
734 ZOOM_options_get (r->options, "smallSetElementSetName");
735 mediumSetElementSetName =
736 ZOOM_options_get (r->options, "mediumSetElementSetName");
738 ZOOM_options_get (r->options, "schema");
740 if (!smallSetElementSetName)
741 smallSetElementSetName = elementSetName;
743 if (!mediumSetElementSetName)
744 mediumSetElementSetName = elementSetName;
749 /* prepare query for the search request */
750 search_req->query = r->r_query;
752 search_req->databaseNames =
753 set_DatabaseNames (c, r->options, &search_req->num_databaseNames);
755 /* get syntax (no need to provide unless piggyback is in effect) */
756 syntax = ZOOM_options_get (r->options, "preferredRecordSyntax");
758 lslb = ZOOM_options_get_int (r->options, "largeSetLowerBound", -1);
759 ssub = ZOOM_options_get_int (r->options, "smallSetUpperBound", -1);
760 mspn = ZOOM_options_get_int (r->options, "mediumSetPresentNumber", -1);
761 if (lslb != -1 && ssub != -1 && mspn != -1)
763 /* So're a Z39.50 expert? Let's hope you don't do sort */
764 *search_req->largeSetLowerBound = lslb;
765 *search_req->smallSetUpperBound = ssub;
766 *search_req->mediumSetPresentNumber = mspn;
768 else if (r->start == 0 && r->count > 0
769 && r->piggyback && !r->r_sort_spec && !schema)
771 /* Regular piggyback - do it unless we're going to do sort */
772 *search_req->largeSetLowerBound = 2000000000;
773 *search_req->smallSetUpperBound = r->count;
774 *search_req->mediumSetPresentNumber = r->count;
775 smallSetElementSetName = 0; /* no need to provide this */
779 /* non-piggyback. Need not provide elementsets or syntaxes .. */
780 smallSetElementSetName = 0;
781 mediumSetElementSetName = 0;
784 if (smallSetElementSetName && *smallSetElementSetName)
786 Z_ElementSetNames *esn = (Z_ElementSetNames *)
787 odr_malloc (c->odr_out, sizeof(*esn));
789 esn->which = Z_ElementSetNames_generic;
790 esn->u.generic = odr_strdup (c->odr_out, smallSetElementSetName);
791 search_req->smallSetElementSetNames = esn;
793 if (mediumSetElementSetName && *mediumSetElementSetName)
795 Z_ElementSetNames *esn = (Z_ElementSetNames *)
796 odr_malloc (c->odr_out, sizeof(*esn));
798 esn->which = Z_ElementSetNames_generic;
799 esn->u.generic = odr_strdup (c->odr_out, mediumSetElementSetName);
800 search_req->mediumSetElementSetNames = esn;
803 search_req->preferredRecordSyntax =
804 yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, syntax);
808 if (c->support_named_resultsets)
812 /* find the lowest unused ordinal so that we re-use
813 result sets on the server. */
814 for (ord = 1; ; ord++)
817 sprintf (setname, "%d", ord);
818 for (rp = c->resultsets; rp; rp = rp->next)
819 if (rp->setname && !strcmp (rp->setname, setname))
824 r->setname = xstrdup (setname);
825 yaz_log (LOG_DEBUG, "allocating %s", r->setname);
828 r->setname = xstrdup ("default");
829 ZOOM_options_set (r->options, "setname", r->setname);
831 search_req->resultSetName = odr_strdup(c->odr_out, r->setname);
832 /* send search request */
838 static void response_diag (ZOOM_connection c, Z_DiagRec *p)
840 Z_DefaultDiagFormat *r;
845 if (p->which != Z_DiagRec_defaultFormat)
847 c->error = ZOOM_ERROR_DECODE;
850 r = p->u.defaultFormat;
853 case Z_DefaultDiagFormat_v2Addinfo:
854 addinfo = r->u.v2Addinfo;
856 case Z_DefaultDiagFormat_v3Addinfo:
857 addinfo = r->u.v3Addinfo;
861 c->addinfo = xstrdup (addinfo);
862 c->error = *r->condition;
865 ZOOM_API(ZOOM_record)
866 ZOOM_record_clone (ZOOM_record srec)
873 odr_enc = odr_createmem(ODR_ENCODE);
874 if (!z_NamePlusRecord (odr_enc, &srec->npr, 0, 0))
876 buf = odr_getbuf (odr_enc, &size, 0);
878 nrec = (ZOOM_record) xmalloc (sizeof(*nrec));
879 nrec->odr = odr_createmem(ODR_DECODE);
880 nrec->wrbuf_marc = 0;
881 odr_setbuf (nrec->odr, buf, size, 0);
882 z_NamePlusRecord (nrec->odr, &nrec->npr, 0, 0);
884 odr_destroy (odr_enc);
888 ZOOM_API(ZOOM_record)
889 ZOOM_resultset_record_immediate (ZOOM_resultset s,size_t pos)
891 return record_cache_lookup (s, pos, 0);
894 ZOOM_API(ZOOM_record)
895 ZOOM_resultset_record (ZOOM_resultset r, size_t pos)
897 ZOOM_resultset_retrieve (r, 1, pos, 1);
898 return ZOOM_resultset_record_immediate (r, pos);
902 ZOOM_record_destroy (ZOOM_record rec)
907 wrbuf_free (rec->wrbuf_marc, 1);
908 odr_destroy (rec->odr);
912 ZOOM_API(const char *)
913 ZOOM_record_get (ZOOM_record rec, const char *type, int *len)
915 Z_NamePlusRecord *npr;
917 *len = 0; /* if return 0 */
924 if (!strcmp (type, "database"))
926 *len = strlen(npr->databaseName)+1;
927 return npr->databaseName;
929 else if (!strcmp (type, "syntax"))
931 if (npr->which == Z_NamePlusRecord_databaseRecord)
933 Z_External *r = (Z_External *) npr->u.databaseRecord;
934 oident *ent = oid_getentbyoid(r->direct_reference);
937 *len = strlen(ent->desc)+1;
943 else if (!strcmp (type, "render") &&
944 npr->which == Z_NamePlusRecord_databaseRecord)
946 Z_External *r = (Z_External *) npr->u.databaseRecord;
947 oident *ent = oid_getentbyoid(r->direct_reference);
949 if (r->which == Z_External_sutrs)
951 *len = r->u.sutrs->len;
952 return (const char *) r->u.sutrs->buf;
954 else if (r->which == Z_External_octet)
963 case VAL_APPLICATION_XML:
966 if (!rec->wrbuf_marc)
967 rec->wrbuf_marc = wrbuf_alloc();
968 wrbuf_rewind (rec->wrbuf_marc);
969 if (yaz_marc_decode ((const char *)
970 r->u.octet_aligned->buf,
972 r->u.octet_aligned->len,
975 *len = wrbuf_len(rec->wrbuf_marc);
976 return wrbuf_buf(rec->wrbuf_marc);
979 *len = r->u.octet_aligned->len;
980 return (const char *) r->u.octet_aligned->buf;
982 else if (r->which == Z_External_grs1)
989 else if (!strcmp (type, "xml") &&
990 npr->which == Z_NamePlusRecord_databaseRecord)
992 Z_External *r = (Z_External *) npr->u.databaseRecord;
993 oident *ent = oid_getentbyoid(r->direct_reference);
995 if (r->which == Z_External_sutrs)
997 *len = r->u.sutrs->len;
998 return (const char *) r->u.sutrs->buf;
1000 else if (r->which == Z_External_octet)
1009 case VAL_APPLICATION_XML:
1012 if (!rec->wrbuf_marc)
1013 rec->wrbuf_marc = wrbuf_alloc();
1014 wrbuf_rewind (rec->wrbuf_marc);
1015 if (yaz_marc_decode ((const char *)
1016 r->u.octet_aligned->buf,
1018 r->u.octet_aligned->len,
1021 *len = wrbuf_len(rec->wrbuf_marc);
1022 return wrbuf_buf(rec->wrbuf_marc);
1025 *len = r->u.octet_aligned->len;
1026 return (const char *) r->u.octet_aligned->buf;
1028 else if (r->which == Z_External_grs1)
1035 else if (!strcmp (type, "raw"))
1037 if (npr->which == Z_NamePlusRecord_databaseRecord)
1039 Z_External *r = (Z_External *) npr->u.databaseRecord;
1041 if (r->which == Z_External_sutrs)
1043 *len = r->u.sutrs->len;
1044 return (const char *) r->u.sutrs->buf;
1046 else if (r->which == Z_External_octet)
1048 *len = r->u.octet_aligned->len;
1049 return (const char *) r->u.octet_aligned->buf;
1051 else /* grs-1, explain, ... */
1054 return (const char *) npr->u.databaseRecord;
1062 static void record_cache_add (ZOOM_resultset r,
1063 Z_NamePlusRecord *npr,
1065 const char *elementSetName)
1067 ZOOM_record_cache rc;
1069 for (rc = r->record_cache; rc; rc = rc->next)
1073 if ((!elementSetName && !rc->elementSetName)
1074 || (elementSetName && rc->elementSetName &&
1075 !strcmp (elementSetName, rc->elementSetName)))
1077 /* not destroying rc->npr (it's handled by nmem )*/
1079 /* keeping wrbuf_marc too */
1084 rc = (ZOOM_record_cache) odr_malloc (r->odr, sizeof(*rc));
1087 rc->rec.wrbuf_marc = 0;
1089 rc->elementSetName = odr_strdup (r->odr, elementSetName);
1091 rc->elementSetName = 0;
1093 rc->next = r->record_cache;
1094 r->record_cache = rc;
1097 static ZOOM_record record_cache_lookup (ZOOM_resultset r,
1099 const char *elementSetName)
1101 ZOOM_record_cache rc;
1103 for (rc = r->record_cache; rc; rc = rc->next)
1107 if ((!elementSetName && !rc->elementSetName)
1108 || (elementSetName && rc->elementSetName &&
1109 !strcmp (elementSetName, rc->elementSetName)))
1116 static void handle_records (ZOOM_connection c, Z_Records *sr,
1119 ZOOM_resultset resultset;
1123 switch (c->tasks->which)
1125 case ZOOM_TASK_SEARCH:
1126 resultset = c->tasks->u.search.resultset;
1128 case ZOOM_TASK_RETRIEVE:
1129 resultset = c->tasks->u.retrieve.resultset;
1134 if (sr && sr->which == Z_Records_NSD)
1136 Z_DiagRec dr, *dr_p = &dr;
1137 dr.which = Z_DiagRec_defaultFormat;
1138 dr.u.defaultFormat = sr->u.nonSurrogateDiagnostic;
1140 response_diag (c, dr_p);
1142 else if (sr && sr->which == Z_Records_multipleNSD)
1144 if (sr->u.multipleNonSurDiagnostics->num_diagRecs >= 1)
1145 response_diag(c, sr->u.multipleNonSurDiagnostics->diagRecs[0]);
1147 c->error = ZOOM_ERROR_DECODE;
1151 if (resultset->count + resultset->start > resultset->size)
1152 resultset->count = resultset->size - resultset->start;
1153 if (resultset->count < 0)
1154 resultset->count = 0;
1155 if (sr && sr->which == Z_Records_DBOSD)
1158 NMEM nmem = odr_extract_mem (c->odr_in);
1159 Z_NamePlusRecordList *p =
1160 sr->u.databaseOrSurDiagnostics;
1161 for (i = 0; i<p->num_records; i++)
1163 record_cache_add (resultset, p->records[i],
1164 i+ resultset->start, 0);
1166 /* transfer our response to search_nmem .. we need it later */
1167 nmem_transfer (resultset->odr->mem, nmem);
1168 nmem_destroy (nmem);
1169 if (present_phase && p->num_records == 0)
1171 /* present response and we didn't get any records! */
1172 c->error = ZOOM_ERROR_DECODE;
1175 else if (present_phase)
1177 /* present response and we didn't get any records! */
1178 c->error = ZOOM_ERROR_DECODE;
1183 static void handle_present_response (ZOOM_connection c, Z_PresentResponse *pr)
1185 handle_records (c, pr->records, 1);
1188 static void handle_search_response (ZOOM_connection c, Z_SearchResponse *sr)
1190 ZOOM_resultset resultset;
1192 yaz_log (LOG_DEBUG, "got search response");
1194 if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH)
1197 resultset = c->tasks->u.search.resultset;
1199 resultset->size = *sr->resultCount;
1200 handle_records (c, sr->records, 0);
1203 static void sort_response (ZOOM_connection c, Z_SortResponse *res)
1205 if (res->diagnostics && res->num_diagnostics > 0)
1206 response_diag (c, res->diagnostics[0]);
1209 static int scan_response (ZOOM_connection c, Z_ScanResponse *res)
1211 NMEM nmem = odr_extract_mem (c->odr_in);
1214 if (!c->tasks || c->tasks->which != ZOOM_TASK_SCAN)
1216 scan = c->tasks->u.scan.scan;
1218 if (res->entries && res->entries->nonsurrogateDiagnostics)
1219 response_diag(c, res->entries->nonsurrogateDiagnostics[0]);
1220 scan->scan_response = res;
1221 nmem_transfer (scan->odr->mem, nmem);
1223 ZOOM_options_set_int (scan->options, "stepSize", *res->stepSize);
1224 if (res->positionOfTerm)
1225 ZOOM_options_set_int (scan->options, "position", *res->positionOfTerm);
1226 if (res->scanStatus)
1227 ZOOM_options_set_int (scan->options, "scanStatus", *res->scanStatus);
1228 if (res->numberOfEntriesReturned)
1229 ZOOM_options_set_int (scan->options, "number",
1230 *res->numberOfEntriesReturned);
1231 nmem_destroy (nmem);
1235 static int send_sort (ZOOM_connection c)
1237 ZOOM_resultset resultset;
1239 if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH)
1242 resultset = c->tasks->u.search.resultset;
1246 resultset->r_sort_spec = 0;
1249 if (resultset->r_sort_spec)
1251 Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_sortRequest);
1252 Z_SortRequest *req = apdu->u.sortRequest;
1254 req->num_inputResultSetNames = 1;
1255 req->inputResultSetNames = (Z_InternationalString **)
1256 odr_malloc (c->odr_out, sizeof(*req->inputResultSetNames));
1257 req->inputResultSetNames[0] =
1258 odr_strdup (c->odr_out, resultset->setname);
1259 req->sortedResultSetName = odr_strdup (c->odr_out, resultset->setname);
1260 req->sortSequence = resultset->r_sort_spec;
1261 resultset->r_sort_spec = 0;
1262 send_APDU (c, apdu);
1268 static int send_present (ZOOM_connection c)
1270 Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_presentRequest);
1271 Z_PresentRequest *req = apdu->u.presentRequest;
1273 const char *syntax =
1274 ZOOM_options_get (c->options, "preferredRecordSyntax");
1275 const char *element =
1276 ZOOM_options_get (c->options, "elementSetName");
1277 const char *schema =
1278 ZOOM_options_get (c->options, "schema");
1279 ZOOM_resultset resultset;
1284 switch (c->tasks->which)
1286 case ZOOM_TASK_SEARCH:
1287 resultset = c->tasks->u.search.resultset;
1289 case ZOOM_TASK_RETRIEVE:
1290 resultset = c->tasks->u.retrieve.resultset;
1291 resultset->start = c->tasks->u.retrieve.start;
1292 resultset->count = c->tasks->u.retrieve.count;
1294 if (resultset->start >= resultset->size)
1296 if (resultset->start + resultset->count > resultset->size)
1297 resultset->count = resultset->size - resultset->start;
1303 if (c->error) /* don't continue on error */
1305 if (resultset->start < 0)
1307 for (i = 0; i<resultset->count; i++)
1310 record_cache_lookup (resultset, i + resultset->start, 0);
1314 if (i == resultset->count)
1317 resultset->start += i;
1318 resultset->count -= i;
1319 *req->resultSetStartPoint = resultset->start + 1;
1320 *req->numberOfRecordsRequested = resultset->count;
1321 assert (*req->numberOfRecordsRequested > 0);
1323 if (syntax && *syntax)
1324 req->preferredRecordSyntax =
1325 yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, syntax);
1327 if (schema && *schema)
1329 Z_RecordComposition *compo = (Z_RecordComposition *)
1330 odr_malloc (c->odr_out, sizeof(*compo));
1332 req->recordComposition = compo;
1333 compo->which = Z_RecordComp_complex;
1334 compo->u.complex = (Z_CompSpec *)
1335 odr_malloc(c->odr_out, sizeof(*compo->u.complex));
1336 compo->u.complex->selectAlternativeSyntax = (bool_t *)
1337 odr_malloc(c->odr_out, sizeof(bool_t));
1338 *compo->u.complex->selectAlternativeSyntax = 0;
1340 compo->u.complex->generic = (Z_Specification *)
1341 odr_malloc(c->odr_out, sizeof(*compo->u.complex->generic));
1343 compo->u.complex->generic->schema = (Odr_oid *)
1344 yaz_str_to_z3950oid (c->odr_out, CLASS_SCHEMA, schema);
1346 if (!compo->u.complex->generic->schema)
1348 /* OID wasn't a schema! Try record syntax instead. */
1350 compo->u.complex->generic->schema = (Odr_oid *)
1351 yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, schema);
1353 if (element && *element)
1355 compo->u.complex->generic->elementSpec = (Z_ElementSpec *)
1356 odr_malloc(c->odr_out, sizeof(Z_ElementSpec));
1357 compo->u.complex->generic->elementSpec->which =
1358 Z_ElementSpec_elementSetName;
1359 compo->u.complex->generic->elementSpec->u.elementSetName =
1360 odr_strdup (c->odr_out, element);
1363 compo->u.complex->generic->elementSpec = 0;
1364 compo->u.complex->num_dbSpecific = 0;
1365 compo->u.complex->dbSpecific = 0;
1366 compo->u.complex->num_recordSyntax = 0;
1367 compo->u.complex->recordSyntax = 0;
1369 else if (element && *element)
1371 Z_ElementSetNames *esn = (Z_ElementSetNames *)
1372 odr_malloc (c->odr_out, sizeof(*esn));
1373 Z_RecordComposition *compo = (Z_RecordComposition *)
1374 odr_malloc (c->odr_out, sizeof(*compo));
1376 esn->which = Z_ElementSetNames_generic;
1377 esn->u.generic = odr_strdup (c->odr_out, element);
1378 compo->which = Z_RecordComp_simple;
1379 compo->u.simple = esn;
1380 req->recordComposition = compo;
1382 req->resultSetId = odr_strdup(c->odr_out, resultset->setname);
1383 send_APDU (c, apdu);
1387 ZOOM_API(ZOOM_scanset)
1388 ZOOM_connection_scan (ZOOM_connection c, const char *start)
1390 ZOOM_scanset scan = (ZOOM_scanset) xmalloc (sizeof(*scan));
1392 scan->connection = c;
1393 scan->odr = odr_createmem (ODR_DECODE);
1394 scan->options = ZOOM_options_create_with_parent (c->options);
1396 scan->scan_response = 0;
1398 if ((scan->termListAndStartPoint =
1399 p_query_scan(scan->odr, PROTO_Z3950, &scan->attributeSet,
1402 ZOOM_task task = ZOOM_connection_add_task (c, ZOOM_TASK_SCAN);
1403 task->u.scan.scan = scan;
1408 while (ZOOM_event (1, &c))
1416 ZOOM_scanset_destroy (ZOOM_scanset scan)
1421 if (scan->refcount == 0)
1423 odr_destroy (scan->odr);
1425 ZOOM_options_destroy (scan->options);
1430 static int send_scan (ZOOM_connection c)
1433 Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_scanRequest);
1434 Z_ScanRequest *req = apdu->u.scanRequest;
1437 assert (c->tasks->which == ZOOM_TASK_SCAN);
1438 scan = c->tasks->u.scan.scan;
1440 req->termListAndStartPoint = scan->termListAndStartPoint;
1441 req->attributeSet = scan->attributeSet;
1443 *req->numberOfTermsRequested =
1444 ZOOM_options_get_int(scan->options, "number", 10);
1446 req->preferredPositionInResponse =
1447 odr_intdup (c->odr_out,
1448 ZOOM_options_get_int(scan->options, "position", 1));
1451 odr_intdup (c->odr_out,
1452 ZOOM_options_get_int(scan->options, "stepSize", 0));
1454 req->databaseNames = set_DatabaseNames (c, scan->options,
1455 &req->num_databaseNames);
1457 send_APDU (c, apdu);
1463 ZOOM_scanset_size (ZOOM_scanset scan)
1465 if (!scan || !scan->scan_response || !scan->scan_response->entries)
1467 return scan->scan_response->entries->num_entries;
1470 ZOOM_API(const char *)
1471 ZOOM_scanset_term (ZOOM_scanset scan, size_t pos,
1474 const char *term = 0;
1475 size_t noent = ZOOM_scanset_size (scan);
1476 Z_ScanResponse *res = scan->scan_response;
1482 if (res->entries->entries[pos]->which == Z_Entry_termInfo)
1484 Z_TermInfo *t = res->entries->entries[pos]->u.termInfo;
1486 if (t->term->which == Z_Term_general)
1488 term = (const char *) t->term->u.general->buf;
1489 *len = t->term->u.general->len;
1491 *occ = t->globalOccurrences ? *t->globalOccurrences : 0;
1496 ZOOM_API(const char *)
1497 ZOOM_scanset_option_get (ZOOM_scanset scan, const char *key)
1499 return ZOOM_options_get (scan->options, key);
1503 ZOOM_scanset_option_set (ZOOM_scanset scan, const char *key,
1506 ZOOM_options_set (scan->options, key, val);
1509 static int ZOOM_connection_exec_task (ZOOM_connection c)
1511 ZOOM_task task = c->tasks;
1513 yaz_log (LOG_DEBUG, "ZOOM_connection_exec_task");
1516 if (c->error != ZOOM_ERROR_NONE ||
1517 (!c->cs && task->which != ZOOM_TASK_CONNECT))
1519 ZOOM_connection_remove_tasks (c);
1522 yaz_log (LOG_DEBUG, "ZOOM_connection_exec_task type=%d", task->which);
1526 switch (task->which)
1528 case ZOOM_TASK_SEARCH:
1529 /* see if search hasn't been sent yet. */
1530 if (ZOOM_connection_send_search (c))
1533 case ZOOM_TASK_RETRIEVE:
1534 if (send_present (c))
1537 case ZOOM_TASK_CONNECT:
1541 case ZOOM_TASK_SCAN:
1545 ZOOM_connection_remove_task (c);
1549 static int send_sort_present (ZOOM_connection c)
1551 int r = send_sort (c);
1553 r = send_present (c);
1557 static void handle_apdu (ZOOM_connection c, Z_APDU *apdu)
1559 Z_InitResponse *initrs;
1561 yaz_log (LOG_DEBUG, "hande_apdu type=%d", apdu->which);
1565 case Z_APDU_initResponse:
1566 initrs = apdu->u.initResponse;
1567 if (!*initrs->result)
1569 c->error = ZOOM_ERROR_INIT;
1574 yaz_oi_get_string_oidval (&apdu->u.initResponse->otherInfo,
1576 xfree (c->cookie_in);
1579 c->cookie_in = xstrdup(cookie);
1580 if (ODR_MASK_GET(initrs->options, Z_Options_namedResultSets) &&
1581 ODR_MASK_GET(initrs->protocolVersion, Z_ProtocolVersion_3))
1582 c->support_named_resultsets = 1;
1585 assert (c->tasks->which == ZOOM_TASK_CONNECT);
1586 ZOOM_connection_remove_task (c);
1588 ZOOM_connection_exec_task (c);
1591 case Z_APDU_searchResponse:
1592 handle_search_response (c, apdu->u.searchResponse);
1593 if (!send_sort_present (c))
1594 ZOOM_connection_remove_task (c);
1596 case Z_APDU_presentResponse:
1597 handle_present_response (c, apdu->u.presentResponse);
1598 if (!send_present (c))
1599 ZOOM_connection_remove_task (c);
1601 case Z_APDU_sortResponse:
1602 sort_response (c, apdu->u.sortResponse);
1603 if (!send_present (c))
1604 ZOOM_connection_remove_task (c);
1606 case Z_APDU_scanResponse:
1607 scan_response (c, apdu->u.scanResponse);
1608 ZOOM_connection_remove_task (c);
1612 static int do_read (ZOOM_connection c)
1618 event = ZOOM_Event_create (ZOOM_EVENT_RECV_DATA);
1619 ZOOM_connection_put_event (c, event);
1621 r = cs_get (c->cs, &c->buf_in, &c->len_in);
1626 c->error= ZOOM_ERROR_CONNECTION_LOST;
1632 odr_reset (c->odr_in);
1633 odr_setbuf (c->odr_in, c->buf_in, r, 0);
1634 event = ZOOM_Event_create (ZOOM_EVENT_RECV_APDU);
1635 ZOOM_connection_put_event (c, event);
1636 if (!z_APDU (c->odr_in, &apdu, 0, 0))
1638 c->error = ZOOM_ERROR_DECODE;
1643 handle_apdu (c, apdu);
1649 static int do_write_ex (ZOOM_connection c, char *buf_out, int len_out)
1654 event = ZOOM_Event_create(ZOOM_EVENT_SEND_DATA);
1655 ZOOM_connection_put_event (c, event);
1657 if ((r=cs_put (c->cs, buf_out, len_out)) < 0)
1659 if (c->state == STATE_CONNECTING)
1660 c->error = ZOOM_ERROR_CONNECT;
1662 c->error = ZOOM_ERROR_CONNECTION_LOST;
1668 c->mask = ZOOM_SELECT_EXCEPT;
1669 if (c->cs->io_pending & CS_WANT_WRITE)
1670 c->mask += ZOOM_SELECT_WRITE;
1671 if (c->cs->io_pending & CS_WANT_READ)
1672 c->mask += ZOOM_SELECT_READ;
1673 yaz_log (LOG_DEBUG, "do_write_ex 1 mask=%d", c->mask);
1677 c->mask = ZOOM_SELECT_READ|ZOOM_SELECT_EXCEPT;
1678 yaz_log (LOG_DEBUG, "do_write_ex 2 mask=%d", c->mask);
1683 static int do_write(ZOOM_connection c)
1685 return do_write_ex (c, c->buf_out, c->len_out);
1689 ZOOM_API(const char *)
1690 ZOOM_connection_option_get (ZOOM_connection c, const char *key)
1692 return ZOOM_options_get (c->options, key);
1696 ZOOM_connection_option_set (ZOOM_connection c, const char *key,
1699 ZOOM_options_set (c->options, key, val);
1702 ZOOM_API(const char *)
1703 ZOOM_resultset_option_get (ZOOM_resultset r, const char *key)
1705 return ZOOM_options_get (r->options, key);
1709 ZOOM_resultset_option_set (ZOOM_resultset r, const char *key,
1712 ZOOM_options_set (r->options, key, val);
1717 ZOOM_connection_errcode (ZOOM_connection c)
1719 return ZOOM_connection_error (c, 0, 0);
1722 ZOOM_API(const char *)
1723 ZOOM_connection_errmsg (ZOOM_connection c)
1726 ZOOM_connection_error (c, &msg, 0);
1730 ZOOM_API(const char *)
1731 ZOOM_connection_addinfo (ZOOM_connection c)
1733 const char *addinfo;
1734 ZOOM_connection_error (c, 0, &addinfo);
1739 ZOOM_connection_error (ZOOM_connection c, const char **cp,
1740 const char **addinfo)
1742 int error = c->error;
1747 case ZOOM_ERROR_NONE:
1748 *cp = "No error"; break;
1749 case ZOOM_ERROR_CONNECT:
1750 *cp = "Connect failed"; break;
1751 case ZOOM_ERROR_MEMORY:
1752 *cp = "Out of memory"; break;
1753 case ZOOM_ERROR_ENCODE:
1754 *cp = "Encoding failed"; break;
1755 case ZOOM_ERROR_DECODE:
1756 *cp = "Decoding failed"; break;
1757 case ZOOM_ERROR_CONNECTION_LOST:
1758 *cp = "Connection lost"; break;
1759 case ZOOM_ERROR_INIT:
1760 *cp = "Init rejected"; break;
1761 case ZOOM_ERROR_INTERNAL:
1762 *cp = "Internal failure"; break;
1763 case ZOOM_ERROR_TIMEOUT:
1764 *cp = "Timeout"; break;
1766 *cp = diagbib1_str (error);
1772 *addinfo = c->addinfo;
1779 static int ZOOM_connection_do_io(ZOOM_connection c, int mask)
1781 ZOOM_Event event = 0;
1782 int r = cs_look(c->cs);
1783 yaz_log (LOG_DEBUG, "ZOOM_connection_do_io c=%p mask=%d cs_look=%d",
1788 event = ZOOM_Event_create (ZOOM_EVENT_CONNECT);
1789 c->error = ZOOM_ERROR_CONNECT;
1791 ZOOM_connection_put_event (c, event);
1793 else if (r == CS_CONNECT)
1796 event = ZOOM_Event_create (ZOOM_EVENT_CONNECT);
1798 ret = cs_rcvconnect (c->cs);
1799 yaz_log (LOG_DEBUG, "cs_rcvconnect returned %d", ret);
1802 c->mask = ZOOM_SELECT_EXCEPT;
1803 if (c->cs->io_pending & CS_WANT_WRITE)
1804 c->mask += ZOOM_SELECT_WRITE;
1805 if (c->cs->io_pending & CS_WANT_READ)
1806 c->mask += ZOOM_SELECT_READ;
1807 ZOOM_connection_put_event (c, event);
1811 ZOOM_connection_put_event (c, event);
1812 ZOOM_connection_send_init (c);
1813 c->state = STATE_ESTABLISHED;
1817 c->error = ZOOM_ERROR_CONNECT;
1819 ZOOM_connection_put_event (c, event);
1824 if (mask & ZOOM_SELECT_READ)
1826 if (c->cs && (mask & ZOOM_SELECT_WRITE))
1833 ZOOM_connection_last_event(ZOOM_connection cs)
1836 return ZOOM_EVENT_NONE;
1837 return cs->last_event;
1841 ZOOM_event (int no, ZOOM_connection *cs)
1844 struct pollfd pollfds[1024];
1845 ZOOM_connection poll_cs[1024];
1848 fd_set input, output, except;
1853 for (i = 0; i<no; i++)
1855 ZOOM_connection c = cs[i];
1857 if (c && (event = ZOOM_connection_get_event(c)))
1859 ZOOM_Event_destroy (event);
1863 for (i = 0; i<no; i++)
1865 ZOOM_connection c = cs[i];
1867 if (c && ZOOM_connection_exec_task (c))
1869 if ((event = ZOOM_connection_get_event(c)))
1871 ZOOM_Event_destroy (event);
1887 for (i = 0; i<no; i++)
1889 ZOOM_connection c = cs[i];
1894 fd = z3950_connection_socket(c);
1895 mask = z3950_connection_mask(c);
1905 short poll_events = 0;
1907 if (mask & ZOOM_SELECT_READ)
1908 poll_events += POLLIN;
1909 if (mask & ZOOM_SELECT_WRITE)
1910 poll_events += POLLOUT;
1911 if (mask & ZOOM_SELECT_EXCEPT)
1912 poll_events += POLLERR;
1913 pollfds[nfds].fd = fd;
1914 pollfds[nfds].events = poll_events;
1915 pollfds[nfds].revents = 0;
1920 if (mask & ZOOM_SELECT_READ)
1922 FD_SET (fd, &input);
1925 if (mask & ZOOM_SELECT_WRITE)
1927 FD_SET (fd, &output);
1930 if (mask & ZOOM_SELECT_EXCEPT)
1932 FD_SET (fd, &except);
1940 r = poll (pollfds, nfds, 15000);
1941 for (i = 0; i<nfds; i++)
1943 ZOOM_connection c = poll_cs[i];
1947 if (pollfds[i].revents & POLLIN)
1948 mask += ZOOM_SELECT_READ;
1949 if (pollfds[i].revents & POLLOUT)
1950 mask += ZOOM_SELECT_WRITE;
1951 if (pollfds[i].revents & POLLERR)
1952 mask += ZOOM_SELECT_EXCEPT;
1954 ZOOM_connection_do_io(c, mask);
1956 else if (r == 0 && c->mask)
1958 ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_TIMEOUT);
1959 /* timeout and this connection was waiting */
1960 c->error = ZOOM_ERROR_TIMEOUT;
1962 ZOOM_connection_put_event(c, event);
1966 yaz_log (LOG_DEBUG, "select start");
1967 r = select (max_fd+1, &input, &output, &except, &tv);
1968 yaz_log (LOG_DEBUG, "select stop, returned r=%d", r);
1969 for (i = 0; i<no; i++)
1971 ZOOM_connection c = cs[i];
1976 fd = z3950_connection_socket(c);
1980 /* no timeout and real socket */
1981 if (FD_ISSET(fd, &input))
1982 mask += ZOOM_SELECT_READ;
1983 if (FD_ISSET(fd, &output))
1984 mask += ZOOM_SELECT_WRITE;
1985 if (FD_ISSET(fd, &except))
1986 mask += ZOOM_SELECT_EXCEPT;
1988 ZOOM_connection_do_io(c, mask);
1990 if (r == 0 && c->mask)
1992 ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_TIMEOUT);
1993 /* timeout and this connection was waiting */
1994 c->error = ZOOM_ERROR_TIMEOUT;
1996 yaz_log (LOG_DEBUG, "timeout");
1997 ZOOM_connection_put_event(c, event);
2001 for (i = 0; i<no; i++)
2003 ZOOM_connection c = cs[i];
2005 if (c && (event = ZOOM_connection_get_event(c)))
2007 ZOOM_Event_destroy (event);