2 * $Id: zoom-c.c,v 1.27 2002-05-14 13:42:26 oleg 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_connection ZOOM_connection_create (ZOOM_options options)
141 ZOOM_connection c = (ZOOM_connection) xmalloc (sizeof(*c));
145 c->state = STATE_IDLE;
146 c->error = ZOOM_ERROR_NONE;
154 c->options = ZOOM_options_create_with_parent(options);
163 c->odr_in = odr_createmem (ODR_DECODE);
164 c->odr_out = odr_createmem (ODR_ENCODE);
167 c->support_named_resultsets = 0;
168 c->last_event = ZOOM_EVENT_NONE;
170 c->m_queue_front = 0;
175 /* set database names. Take local databases (if set); otherwise
176 take databases given in ZURL (if set); otherwise use Default */
177 static char **set_DatabaseNames (ZOOM_connection con, ZOOM_options options,
180 char **databaseNames;
183 const char *cp = ZOOM_options_get (options, "databaseName");
187 cp = strchr (con->host_port, '/');
194 while ((c = strchr(c, '+')))
202 databaseNames = (char**)
203 odr_malloc (con->odr_out, no * sizeof(*databaseNames));
207 c = strchr (cp, '+');
215 /* cp ptr to first char of db name, c is char
217 databaseNames[no] = (char*) odr_malloc (con->odr_out, 1+c-cp);
218 memcpy (databaseNames[no], cp, c-cp);
219 databaseNames[no++][c-cp] = '\0';
224 databaseNames[no] = NULL;
226 return databaseNames;
229 ZOOM_connection ZOOM_connection_new (const char *host, int portnum)
231 ZOOM_connection c = ZOOM_connection_create (0);
233 ZOOM_connection_connect (c, host, portnum);
237 void ZOOM_connection_connect(ZOOM_connection c,
238 const char *host, int portnum)
243 val = ZOOM_options_get (c->options, "proxy");
245 c->proxy = xstrdup (val);
252 sprintf (hostn, "%.80s:%d", host, portnum);
253 c->host_port = xstrdup(hostn);
256 c->host_port = xstrdup(host);
258 ZOOM_options_set(c->options, "host", c->host_port);
260 c->async = ZOOM_options_get_bool (c->options, "async", 0);
262 c->error = ZOOM_ERROR_NONE;
264 task = ZOOM_connection_add_task (c, ZOOM_TASK_CONNECT);
268 while (ZOOM_event (1, &c))
273 ZOOM_query ZOOM_query_create(void)
275 ZOOM_query s = (ZOOM_query) xmalloc (sizeof(*s));
280 s->odr = odr_createmem (ODR_ENCODE);
285 void ZOOM_query_destroy(ZOOM_query s)
291 yaz_log (LOG_DEBUG, "ZOOM_query_destroy count=%d", s->refcount);
292 if (s->refcount == 0)
294 odr_destroy (s->odr);
299 int ZOOM_query_prefix(ZOOM_query s, const char *str)
301 s->query = (Z_Query *) odr_malloc (s->odr, sizeof(*s->query));
302 s->query->which = Z_Query_type_1;
303 s->query->u.type_1 = p_query_rpn(s->odr, PROTO_Z3950, str);
304 if (!s->query->u.type_1)
309 int ZOOM_query_sortby(ZOOM_query s, const char *criteria)
311 s->sort_spec = yaz_sort_spec (s->odr, criteria);
317 static int do_write(ZOOM_connection c);
319 void ZOOM_connection_destroy(ZOOM_connection c)
326 for (r = c->resultsets; r; r = r->next)
331 odr_destroy (c->odr_in);
332 odr_destroy (c->odr_out);
333 ZOOM_options_destroy (c->options);
334 ZOOM_connection_remove_tasks (c);
335 xfree (c->host_port);
337 xfree (c->cookie_out);
338 xfree (c->cookie_in);
342 void ZOOM_resultset_addref (ZOOM_resultset r)
347 ZOOM_resultset ZOOM_resultset_create ()
349 ZOOM_resultset r = (ZOOM_resultset) xmalloc (sizeof(*r));
353 r->odr = odr_createmem (ODR_ENCODE);
367 ZOOM_resultset ZOOM_connection_search_pqf(ZOOM_connection c, const char *q)
370 ZOOM_query s = ZOOM_query_create();
372 ZOOM_query_prefix (s, q);
374 r = ZOOM_connection_search (c, s);
375 ZOOM_query_destroy (s);
379 ZOOM_resultset ZOOM_connection_search(ZOOM_connection c, ZOOM_query q)
381 ZOOM_resultset r = ZOOM_resultset_create ();
385 r->r_sort_spec = q->sort_spec;
386 r->r_query = q->query;
389 r->options = ZOOM_options_create_with_parent(c->options);
391 r->start = ZOOM_options_get_int(r->options, "start", 0);
392 r->count = ZOOM_options_get_int(r->options, "count", 0);
393 r->piggyback = ZOOM_options_get_bool (r->options, "piggyback", 1);
394 cp = ZOOM_options_get (r->options, "setname");
396 r->setname = xstrdup (cp);
400 r->next = c->resultsets;
403 task = ZOOM_connection_add_task (c, ZOOM_TASK_SEARCH);
404 task->u.search.resultset = r;
405 ZOOM_resultset_addref (r);
411 while (ZOOM_event (1, &c))
417 void ZOOM_resultset_destroy(ZOOM_resultset r)
422 yaz_log (LOG_DEBUG, "destroy r = %p count=%d", r, r->refcount);
423 if (r->refcount == 0)
425 ZOOM_record_cache rc;
427 for (rc = r->record_cache; rc; rc = rc->next)
428 if (rc->rec.wrbuf_marc)
429 wrbuf_free (rc->rec.wrbuf_marc, 1);
432 /* remove ourselves from the resultsets in connection */
433 ZOOM_resultset *rp = &r->connection->resultsets;
436 assert (*rp); /* we must be in this list!! */
438 { /* OK, we're here - take us out of it */
445 ZOOM_query_destroy (r->search);
446 ZOOM_options_destroy (r->options);
447 odr_destroy (r->odr);
453 size_t ZOOM_resultset_size (ZOOM_resultset r)
458 static void do_close (ZOOM_connection c)
464 c->state = STATE_IDLE;
467 static void ZOOM_resultset_retrieve (ZOOM_resultset r,
468 int force_sync, int start, int count)
478 task = ZOOM_connection_add_task (c, ZOOM_TASK_RETRIEVE);
479 task->u.retrieve.resultset = r;
480 task->u.retrieve.start = start;
481 task->u.retrieve.count = count;
483 ZOOM_resultset_addref (r);
485 if (!r->connection->async || force_sync)
486 while (r->connection && ZOOM_event (1, &r->connection))
490 void ZOOM_resultset_records (ZOOM_resultset r, ZOOM_record *recs,
491 size_t start, size_t count)
493 int force_present = 0;
499 ZOOM_resultset_retrieve (r, force_present, start, count);
503 for (i = 0; i< count; i++)
504 recs[i] = ZOOM_resultset_record_immediate (r, i+start);
508 static int do_connect (ZOOM_connection c)
511 const char *effective_host;
514 effective_host = c->proxy;
516 effective_host = c->host_port;
518 yaz_log (LOG_DEBUG, "do_connect host=%s", effective_host);
521 c->cs = cs_create_host (effective_host, 0, &add);
525 int ret = cs_connect (c->cs, add);
526 yaz_log (LOG_DEBUG, "cs_connect returned %d", ret);
529 ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_CONNECT);
530 ZOOM_connection_put_event(c, event);
531 ZOOM_connection_send_init(c);
532 c->state = STATE_ESTABLISHED;
537 c->state = STATE_CONNECTING;
538 c->mask = ZOOM_SELECT_EXCEPT;
539 if (c->cs->io_pending & CS_WANT_WRITE)
540 c->mask += ZOOM_SELECT_WRITE;
541 if (c->cs->io_pending & CS_WANT_READ)
542 c->mask += ZOOM_SELECT_READ;
546 c->state = STATE_IDLE;
547 c->error = ZOOM_ERROR_CONNECT;
551 int z3950_connection_socket(ZOOM_connection c)
554 return cs_fileno(c->cs);
558 int z3950_connection_mask(ZOOM_connection c)
565 static int encode_APDU(ZOOM_connection c, Z_APDU *a, ODR out)
570 sprintf (str, "send_APDU t=%p type=%d", c, a->which);
573 Z_OtherInformation **oi;
575 yaz_oi_set_string_oidval(oi, out, VAL_COOKIE, 1, c->cookie_out);
577 if (!z_APDU(out, &a, 0, 0))
579 FILE *outf = fopen("/tmp/apdu.txt", "w");
582 ODR odr_pr = odr_createmem(ODR_PRINT);
583 fprintf (outf, "a=%p\n", a);
584 odr_setprint(odr_pr, outf);
585 z_APDU(odr_pr, &a, 0, 0);
589 c->error = ZOOM_ERROR_ENCODE;
597 static int send_APDU (ZOOM_connection c, Z_APDU *a)
601 if (encode_APDU(c, a, c->odr_out))
603 c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0);
604 event = ZOOM_Event_create (ZOOM_EVENT_SEND_APDU);
605 ZOOM_connection_put_event (c, event);
606 odr_reset(c->odr_out);
611 static int ZOOM_connection_send_init (ZOOM_connection c)
614 Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_initRequest);
615 Z_InitRequest *ireq = apdu->u.initRequest;
616 Z_IdAuthentication *auth = (Z_IdAuthentication *)
617 odr_malloc(c->odr_out, sizeof(*auth));
618 const char *auth_groupId = ZOOM_options_get (c->options, "group");
619 const char *auth_userId = ZOOM_options_get (c->options, "user");
620 const char *auth_password = ZOOM_options_get (c->options, "pass");
622 ODR_MASK_SET(ireq->options, Z_Options_search);
623 ODR_MASK_SET(ireq->options, Z_Options_present);
624 ODR_MASK_SET(ireq->options, Z_Options_scan);
625 ODR_MASK_SET(ireq->options, Z_Options_sort);
626 ODR_MASK_SET(ireq->options, Z_Options_extendedServices);
627 ODR_MASK_SET(ireq->options, Z_Options_namedResultSets);
629 ODR_MASK_SET(ireq->protocolVersion, Z_ProtocolVersion_1);
630 ODR_MASK_SET(ireq->protocolVersion, Z_ProtocolVersion_2);
631 ODR_MASK_SET(ireq->protocolVersion, Z_ProtocolVersion_3);
633 impname = ZOOM_options_get (c->options, "implementationName");
634 ireq->implementationName =
635 (char *) odr_malloc (c->odr_out, 15 + (impname ? strlen(impname) : 0));
636 strcpy (ireq->implementationName, "");
639 strcat (ireq->implementationName, impname);
640 strcat (ireq->implementationName, "/");
642 strcat (ireq->implementationName, "ZOOM-C/YAZ");
644 *ireq->maximumRecordSize =
645 ZOOM_options_get_int (c->options, "maximumRecordSize", 1024*1024);
646 *ireq->preferredMessageSize =
647 ZOOM_options_get_int (c->options, "preferredMessageSize", 1024*1024);
649 if (auth_groupId || auth_password)
651 Z_IdPass *pass = (Z_IdPass *) odr_malloc(c->odr_out, sizeof(*pass));
654 if (auth_groupId && *auth_groupId)
656 pass->groupId = (char *)
657 odr_malloc(c->odr_out, strlen(auth_groupId)+1);
658 strcpy(pass->groupId, auth_groupId);
662 if (auth_userId && *auth_userId)
664 pass->userId = (char *)
665 odr_malloc(c->odr_out, strlen(auth_userId)+1);
666 strcpy(pass->userId, auth_userId);
670 if (auth_password && *auth_password)
672 pass->password = (char *)
673 odr_malloc(c->odr_out, strlen(auth_password)+1);
674 strcpy(pass->password, auth_password);
679 auth->which = Z_IdAuthentication_idPass;
680 auth->u.idPass = pass;
681 ireq->idAuthentication = auth;
684 else if (auth_userId)
686 auth->which = Z_IdAuthentication_open;
687 auth->u.open = (char *)
688 odr_malloc(c->odr_out, strlen(auth_userId)+1);
689 strcpy(auth->u.open, auth_userId);
690 ireq->idAuthentication = auth;
693 yaz_oi_set_string_oidval(&ireq->otherInfo, c->odr_out,
694 VAL_PROXY, 1, c->host_port);
701 static int ZOOM_connection_send_search (ZOOM_connection c)
704 int lslb, ssub, mspn;
706 Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_searchRequest);
707 Z_SearchRequest *search_req = apdu->u.searchRequest;
708 const char *elementSetName;
709 const char *smallSetElementSetName;
710 const char *mediumSetElementSetName;
714 assert (c->tasks->which == ZOOM_TASK_SEARCH);
716 r = c->tasks->u.search.resultset;
719 ZOOM_options_get (r->options, "elementSetName");
720 smallSetElementSetName =
721 ZOOM_options_get (r->options, "smallSetElementSetName");
722 mediumSetElementSetName =
723 ZOOM_options_get (r->options, "mediumSetElementSetName");
725 ZOOM_options_get (r->options, "schema");
727 if (!smallSetElementSetName)
728 smallSetElementSetName = elementSetName;
730 if (!mediumSetElementSetName)
731 mediumSetElementSetName = elementSetName;
736 /* prepare query for the search request */
737 search_req->query = r->r_query;
739 search_req->databaseNames =
740 set_DatabaseNames (c, r->options, &search_req->num_databaseNames);
742 /* get syntax (no need to provide unless piggyback is in effect) */
743 syntax = ZOOM_options_get (r->options, "preferredRecordSyntax");
745 lslb = ZOOM_options_get_int (r->options, "largeSetLowerBound", -1);
746 ssub = ZOOM_options_get_int (r->options, "smallSetUpperBound", -1);
747 mspn = ZOOM_options_get_int (r->options, "mediumSetPresentNumber", -1);
748 if (lslb != -1 && ssub != -1 && mspn != -1)
750 /* So're a Z39.50 expert? Let's hope you don't do sort */
751 *search_req->largeSetLowerBound = lslb;
752 *search_req->smallSetUpperBound = ssub;
753 *search_req->mediumSetPresentNumber = mspn;
755 else if (r->start == 0 && r->count > 0
756 && r->piggyback && !r->r_sort_spec && !schema)
758 /* Regular piggyback - do it unless we're going to do sort */
759 *search_req->largeSetLowerBound = 2000000000;
760 *search_req->smallSetUpperBound = r->count;
761 *search_req->mediumSetPresentNumber = r->count;
762 smallSetElementSetName = 0; /* no need to provide this */
766 /* non-piggyback. Need not provide elementsets or syntaxes .. */
767 smallSetElementSetName = 0;
768 mediumSetElementSetName = 0;
771 if (smallSetElementSetName && *smallSetElementSetName)
773 Z_ElementSetNames *esn = (Z_ElementSetNames *)
774 odr_malloc (c->odr_out, sizeof(*esn));
776 esn->which = Z_ElementSetNames_generic;
777 esn->u.generic = odr_strdup (c->odr_out, smallSetElementSetName);
778 search_req->smallSetElementSetNames = esn;
780 if (mediumSetElementSetName && *mediumSetElementSetName)
782 Z_ElementSetNames *esn = (Z_ElementSetNames *)
783 odr_malloc (c->odr_out, sizeof(*esn));
785 esn->which = Z_ElementSetNames_generic;
786 esn->u.generic = odr_strdup (c->odr_out, mediumSetElementSetName);
787 search_req->mediumSetElementSetNames = esn;
790 search_req->preferredRecordSyntax =
791 yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, syntax);
795 if (c->support_named_resultsets)
799 /* find the lowest unused ordinal so that we re-use
800 result sets on the server. */
801 for (ord = 1; ; ord++)
804 sprintf (setname, "%d", ord);
805 for (rp = c->resultsets; rp; rp = rp->next)
806 if (rp->setname && !strcmp (rp->setname, setname))
811 r->setname = xstrdup (setname);
812 yaz_log (LOG_DEBUG, "allocating %s", r->setname);
815 r->setname = xstrdup ("default");
816 ZOOM_options_set (r->options, "setname", r->setname);
818 search_req->resultSetName = odr_strdup(c->odr_out, r->setname);
819 /* send search request */
825 static void response_diag (ZOOM_connection c, Z_DiagRec *p)
827 Z_DefaultDiagFormat *r;
832 if (p->which != Z_DiagRec_defaultFormat)
834 c->error = ZOOM_ERROR_DECODE;
837 r = p->u.defaultFormat;
840 case Z_DefaultDiagFormat_v2Addinfo:
841 addinfo = r->u.v2Addinfo;
843 case Z_DefaultDiagFormat_v3Addinfo:
844 addinfo = r->u.v3Addinfo;
848 c->addinfo = xstrdup (addinfo);
849 c->error = *r->condition;
852 ZOOM_record ZOOM_record_clone (ZOOM_record srec)
859 odr_enc = odr_createmem(ODR_ENCODE);
860 if (!z_NamePlusRecord (odr_enc, &srec->npr, 0, 0))
862 buf = odr_getbuf (odr_enc, &size, 0);
864 nrec = (ZOOM_record) xmalloc (sizeof(*nrec));
865 nrec->odr = odr_createmem(ODR_DECODE);
866 nrec->wrbuf_marc = 0;
867 odr_setbuf (nrec->odr, buf, size, 0);
868 z_NamePlusRecord (nrec->odr, &nrec->npr, 0, 0);
870 odr_destroy (odr_enc);
874 ZOOM_record ZOOM_resultset_record_immediate (ZOOM_resultset s,size_t pos)
876 return record_cache_lookup (s, pos, 0);
879 ZOOM_record ZOOM_resultset_record (ZOOM_resultset r, size_t pos)
881 ZOOM_resultset_retrieve (r, 1, pos, 1);
882 return ZOOM_resultset_record_immediate (r, pos);
885 void ZOOM_record_destroy (ZOOM_record rec)
890 wrbuf_free (rec->wrbuf_marc, 1);
891 odr_destroy (rec->odr);
895 const char *ZOOM_record_get (ZOOM_record rec, const char *type, int *len)
897 Z_NamePlusRecord *npr;
899 *len = 0; /* if return 0 */
906 if (!strcmp (type, "database"))
908 *len = strlen(npr->databaseName)+1;
909 return npr->databaseName;
911 else if (!strcmp (type, "syntax"))
913 if (npr->which == Z_NamePlusRecord_databaseRecord)
915 Z_External *r = (Z_External *) npr->u.databaseRecord;
916 oident *ent = oid_getentbyoid(r->direct_reference);
919 *len = strlen(ent->desc)+1;
925 else if (!strcmp (type, "render") &&
926 npr->which == Z_NamePlusRecord_databaseRecord)
928 Z_External *r = (Z_External *) npr->u.databaseRecord;
929 oident *ent = oid_getentbyoid(r->direct_reference);
931 if (r->which == Z_External_sutrs)
933 *len = r->u.sutrs->len;
934 return (const char *) r->u.sutrs->buf;
936 else if (r->which == Z_External_octet)
945 case VAL_APPLICATION_XML:
948 if (!rec->wrbuf_marc)
949 rec->wrbuf_marc = wrbuf_alloc();
950 wrbuf_rewind (rec->wrbuf_marc);
951 if (yaz_marc_decode ((const char *)
952 r->u.octet_aligned->buf,
954 r->u.octet_aligned->len,
957 *len = wrbuf_len(rec->wrbuf_marc);
958 return wrbuf_buf(rec->wrbuf_marc);
961 *len = r->u.octet_aligned->len;
962 return (const char *) r->u.octet_aligned->buf;
964 else if (r->which == Z_External_grs1)
971 else if (!strcmp (type, "xml") &&
972 npr->which == Z_NamePlusRecord_databaseRecord)
974 Z_External *r = (Z_External *) npr->u.databaseRecord;
975 oident *ent = oid_getentbyoid(r->direct_reference);
977 if (r->which == Z_External_sutrs)
979 *len = r->u.sutrs->len;
980 return (const char *) r->u.sutrs->buf;
982 else if (r->which == Z_External_octet)
991 case VAL_APPLICATION_XML:
994 if (!rec->wrbuf_marc)
995 rec->wrbuf_marc = wrbuf_alloc();
996 wrbuf_rewind (rec->wrbuf_marc);
997 if (yaz_marc_decode ((const char *)
998 r->u.octet_aligned->buf,
1000 r->u.octet_aligned->len,
1003 *len = wrbuf_len(rec->wrbuf_marc);
1004 return wrbuf_buf(rec->wrbuf_marc);
1007 *len = r->u.octet_aligned->len;
1008 return (const char *) r->u.octet_aligned->buf;
1010 else if (r->which == Z_External_grs1)
1017 else if (!strcmp (type, "raw"))
1019 if (npr->which == Z_NamePlusRecord_databaseRecord)
1021 Z_External *r = (Z_External *) npr->u.databaseRecord;
1023 if (r->which == Z_External_sutrs)
1025 *len = r->u.sutrs->len;
1026 return (const char *) r->u.sutrs->buf;
1028 else if (r->which == Z_External_octet)
1030 *len = r->u.octet_aligned->len;
1031 return (const char *) r->u.octet_aligned->buf;
1033 else /* grs-1, explain, ... */
1036 return (const char *) npr->u.databaseRecord;
1044 static void record_cache_add (ZOOM_resultset r,
1045 Z_NamePlusRecord *npr,
1047 const char *elementSetName)
1049 ZOOM_record_cache rc;
1051 for (rc = r->record_cache; rc; rc = rc->next)
1055 if ((!elementSetName && !rc->elementSetName)
1056 || (elementSetName && rc->elementSetName &&
1057 !strcmp (elementSetName, rc->elementSetName)))
1059 /* not destroying rc->npr (it's handled by nmem )*/
1061 /* keeping wrbuf_marc too */
1066 rc = (ZOOM_record_cache) odr_malloc (r->odr, sizeof(*rc));
1069 rc->rec.wrbuf_marc = 0;
1071 rc->elementSetName = odr_strdup (r->odr, elementSetName);
1073 rc->elementSetName = 0;
1075 rc->next = r->record_cache;
1076 r->record_cache = rc;
1079 static ZOOM_record record_cache_lookup (ZOOM_resultset r,
1081 const char *elementSetName)
1083 ZOOM_record_cache rc;
1085 for (rc = r->record_cache; rc; rc = rc->next)
1089 if ((!elementSetName && !rc->elementSetName)
1090 || (elementSetName && rc->elementSetName &&
1091 !strcmp (elementSetName, rc->elementSetName)))
1098 static void handle_records (ZOOM_connection c, Z_Records *sr,
1101 ZOOM_resultset resultset;
1105 switch (c->tasks->which)
1107 case ZOOM_TASK_SEARCH:
1108 resultset = c->tasks->u.search.resultset;
1110 case ZOOM_TASK_RETRIEVE:
1111 resultset = c->tasks->u.retrieve.resultset;
1116 if (sr && sr->which == Z_Records_NSD)
1118 Z_DiagRec dr, *dr_p = &dr;
1119 dr.which = Z_DiagRec_defaultFormat;
1120 dr.u.defaultFormat = sr->u.nonSurrogateDiagnostic;
1122 response_diag (c, dr_p);
1124 else if (sr && sr->which == Z_Records_multipleNSD)
1126 if (sr->u.multipleNonSurDiagnostics->num_diagRecs >= 1)
1127 response_diag(c, sr->u.multipleNonSurDiagnostics->diagRecs[0]);
1129 c->error = ZOOM_ERROR_DECODE;
1133 if (resultset->count + resultset->start > resultset->size)
1134 resultset->count = resultset->size - resultset->start;
1135 if (resultset->count < 0)
1136 resultset->count = 0;
1137 if (sr && sr->which == Z_Records_DBOSD)
1140 NMEM nmem = odr_extract_mem (c->odr_in);
1141 Z_NamePlusRecordList *p =
1142 sr->u.databaseOrSurDiagnostics;
1143 for (i = 0; i<p->num_records; i++)
1145 record_cache_add (resultset, p->records[i],
1146 i+ resultset->start, 0);
1148 /* transfer our response to search_nmem .. we need it later */
1149 nmem_transfer (resultset->odr->mem, nmem);
1150 nmem_destroy (nmem);
1151 if (present_phase && p->num_records == 0)
1153 /* present response and we didn't get any records! */
1154 c->error = ZOOM_ERROR_DECODE;
1157 else if (present_phase)
1159 /* present response and we didn't get any records! */
1160 c->error = ZOOM_ERROR_DECODE;
1165 static void handle_present_response (ZOOM_connection c, Z_PresentResponse *pr)
1167 handle_records (c, pr->records, 1);
1170 static void handle_search_response (ZOOM_connection c, Z_SearchResponse *sr)
1172 ZOOM_resultset resultset;
1174 yaz_log (LOG_DEBUG, "got search response");
1176 if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH)
1179 resultset = c->tasks->u.search.resultset;
1181 resultset->size = *sr->resultCount;
1182 handle_records (c, sr->records, 0);
1185 static void sort_response (ZOOM_connection c, Z_SortResponse *res)
1187 if (res->diagnostics && res->num_diagnostics > 0)
1188 response_diag (c, res->diagnostics[0]);
1191 static int scan_response (ZOOM_connection c, Z_ScanResponse *res)
1193 NMEM nmem = odr_extract_mem (c->odr_in);
1196 if (!c->tasks || c->tasks->which != ZOOM_TASK_SCAN)
1198 scan = c->tasks->u.scan.scan;
1200 if (res->entries && res->entries->nonsurrogateDiagnostics)
1201 response_diag(c, res->entries->nonsurrogateDiagnostics[0]);
1202 scan->scan_response = res;
1203 nmem_transfer (scan->odr->mem, nmem);
1205 ZOOM_options_set_int (scan->options, "stepSize", *res->stepSize);
1206 if (res->positionOfTerm)
1207 ZOOM_options_set_int (scan->options, "position", *res->positionOfTerm);
1208 if (res->scanStatus)
1209 ZOOM_options_set_int (scan->options, "scanStatus", *res->scanStatus);
1210 if (res->numberOfEntriesReturned)
1211 ZOOM_options_set_int (scan->options, "number",
1212 *res->numberOfEntriesReturned);
1213 nmem_destroy (nmem);
1217 static int send_sort (ZOOM_connection c)
1219 ZOOM_resultset resultset;
1221 if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH)
1224 resultset = c->tasks->u.search.resultset;
1228 resultset->r_sort_spec = 0;
1231 if (resultset->r_sort_spec)
1233 Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_sortRequest);
1234 Z_SortRequest *req = apdu->u.sortRequest;
1236 req->num_inputResultSetNames = 1;
1237 req->inputResultSetNames = (Z_InternationalString **)
1238 odr_malloc (c->odr_out, sizeof(*req->inputResultSetNames));
1239 req->inputResultSetNames[0] =
1240 odr_strdup (c->odr_out, resultset->setname);
1241 req->sortedResultSetName = odr_strdup (c->odr_out, resultset->setname);
1242 req->sortSequence = resultset->r_sort_spec;
1243 resultset->r_sort_spec = 0;
1244 send_APDU (c, apdu);
1250 static int send_present (ZOOM_connection c)
1252 Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_presentRequest);
1253 Z_PresentRequest *req = apdu->u.presentRequest;
1255 const char *syntax =
1256 ZOOM_options_get (c->options, "preferredRecordSyntax");
1257 const char *element =
1258 ZOOM_options_get (c->options, "elementSetName");
1259 const char *schema =
1260 ZOOM_options_get (c->options, "schema");
1261 ZOOM_resultset resultset;
1266 switch (c->tasks->which)
1268 case ZOOM_TASK_SEARCH:
1269 resultset = c->tasks->u.search.resultset;
1271 case ZOOM_TASK_RETRIEVE:
1272 resultset = c->tasks->u.retrieve.resultset;
1273 resultset->start = c->tasks->u.retrieve.start;
1274 resultset->count = c->tasks->u.retrieve.count;
1276 if (resultset->start >= resultset->size)
1278 if (resultset->start + resultset->count > resultset->size)
1279 resultset->count = resultset->size - resultset->start;
1285 if (c->error) /* don't continue on error */
1287 if (resultset->start < 0)
1289 for (i = 0; i<resultset->count; i++)
1292 record_cache_lookup (resultset, i + resultset->start, 0);
1296 if (i == resultset->count)
1299 resultset->start += i;
1300 resultset->count -= i;
1301 *req->resultSetStartPoint = resultset->start + 1;
1302 *req->numberOfRecordsRequested = resultset->count;
1303 assert (*req->numberOfRecordsRequested > 0);
1305 if (syntax && *syntax)
1306 req->preferredRecordSyntax =
1307 yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, syntax);
1309 if (schema && *schema)
1311 Z_RecordComposition *compo = (Z_RecordComposition *)
1312 odr_malloc (c->odr_out, sizeof(*compo));
1314 req->recordComposition = compo;
1315 compo->which = Z_RecordComp_complex;
1316 compo->u.complex = (Z_CompSpec *)
1317 odr_malloc(c->odr_out, sizeof(*compo->u.complex));
1318 compo->u.complex->selectAlternativeSyntax = (bool_t *)
1319 odr_malloc(c->odr_out, sizeof(bool_t));
1320 *compo->u.complex->selectAlternativeSyntax = 0;
1322 compo->u.complex->generic = (Z_Specification *)
1323 odr_malloc(c->odr_out, sizeof(*compo->u.complex->generic));
1325 compo->u.complex->generic->schema = (Odr_oid *)
1326 yaz_str_to_z3950oid (c->odr_out, CLASS_SCHEMA, schema);
1328 if (!compo->u.complex->generic->schema)
1330 /* OID wasn't a schema! Try record syntax instead. */
1332 compo->u.complex->generic->schema = (Odr_oid *)
1333 yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, schema);
1335 if (element && *element)
1337 compo->u.complex->generic->elementSpec = (Z_ElementSpec *)
1338 odr_malloc(c->odr_out, sizeof(Z_ElementSpec));
1339 compo->u.complex->generic->elementSpec->which =
1340 Z_ElementSpec_elementSetName;
1341 compo->u.complex->generic->elementSpec->u.elementSetName =
1342 odr_strdup (c->odr_out, element);
1345 compo->u.complex->generic->elementSpec = 0;
1346 compo->u.complex->num_dbSpecific = 0;
1347 compo->u.complex->dbSpecific = 0;
1348 compo->u.complex->num_recordSyntax = 0;
1349 compo->u.complex->recordSyntax = 0;
1351 else if (element && *element)
1353 Z_ElementSetNames *esn = (Z_ElementSetNames *)
1354 odr_malloc (c->odr_out, sizeof(*esn));
1355 Z_RecordComposition *compo = (Z_RecordComposition *)
1356 odr_malloc (c->odr_out, sizeof(*compo));
1358 esn->which = Z_ElementSetNames_generic;
1359 esn->u.generic = odr_strdup (c->odr_out, element);
1360 compo->which = Z_RecordComp_simple;
1361 compo->u.simple = esn;
1362 req->recordComposition = compo;
1364 req->resultSetId = odr_strdup(c->odr_out, resultset->setname);
1365 send_APDU (c, apdu);
1369 ZOOM_scanset ZOOM_connection_scan (ZOOM_connection c, const char *start)
1371 ZOOM_scanset scan = (ZOOM_scanset) xmalloc (sizeof(*scan));
1373 scan->connection = c;
1374 scan->odr = odr_createmem (ODR_DECODE);
1375 scan->options = ZOOM_options_create_with_parent (c->options);
1377 scan->scan_response = 0;
1379 if ((scan->termListAndStartPoint =
1380 p_query_scan(scan->odr, PROTO_Z3950, &scan->attributeSet,
1383 ZOOM_task task = ZOOM_connection_add_task (c, ZOOM_TASK_SCAN);
1384 task->u.scan.scan = scan;
1389 while (ZOOM_event (1, &c))
1396 void ZOOM_scanset_destroy (ZOOM_scanset scan)
1401 if (scan->refcount == 0)
1403 odr_destroy (scan->odr);
1405 ZOOM_options_destroy (scan->options);
1410 int send_scan (ZOOM_connection c)
1413 Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_scanRequest);
1414 Z_ScanRequest *req = apdu->u.scanRequest;
1417 assert (c->tasks->which == ZOOM_TASK_SCAN);
1418 scan = c->tasks->u.scan.scan;
1420 req->termListAndStartPoint = scan->termListAndStartPoint;
1421 req->attributeSet = scan->attributeSet;
1423 *req->numberOfTermsRequested =
1424 ZOOM_options_get_int(scan->options, "number", 10);
1426 req->preferredPositionInResponse =
1427 odr_intdup (c->odr_out,
1428 ZOOM_options_get_int(scan->options, "position", 1));
1431 odr_intdup (c->odr_out,
1432 ZOOM_options_get_int(scan->options, "stepSize", 0));
1434 req->databaseNames = set_DatabaseNames (c, scan->options,
1435 &req->num_databaseNames);
1437 send_APDU (c, apdu);
1442 size_t ZOOM_scanset_size (ZOOM_scanset scan)
1444 if (!scan || !scan->scan_response || !scan->scan_response->entries)
1446 return scan->scan_response->entries->num_entries;
1449 const char *ZOOM_scanset_term (ZOOM_scanset scan, size_t pos,
1452 const char *term = 0;
1453 size_t noent = ZOOM_scanset_size (scan);
1454 Z_ScanResponse *res = scan->scan_response;
1460 if (res->entries->entries[pos]->which == Z_Entry_termInfo)
1462 Z_TermInfo *t = res->entries->entries[pos]->u.termInfo;
1464 if (t->term->which == Z_Term_general)
1466 term = (const char *) t->term->u.general->buf;
1467 *len = t->term->u.general->len;
1469 *occ = t->globalOccurrences ? *t->globalOccurrences : 0;
1474 const char *ZOOM_scanset_option_get (ZOOM_scanset scan, const char *key)
1476 return ZOOM_options_get (scan->options, key);
1479 void ZOOM_scanset_option_set (ZOOM_scanset scan, const char *key,
1482 ZOOM_options_set (scan->options, key, val);
1485 static int ZOOM_connection_exec_task (ZOOM_connection c)
1487 ZOOM_task task = c->tasks;
1489 yaz_log (LOG_DEBUG, "ZOOM_connection_exec_task");
1492 if (c->error != ZOOM_ERROR_NONE ||
1493 (!c->cs && task->which != ZOOM_TASK_CONNECT))
1495 ZOOM_connection_remove_tasks (c);
1498 yaz_log (LOG_DEBUG, "ZOOM_connection_exec_task type=%d", task->which);
1502 switch (task->which)
1504 case ZOOM_TASK_SEARCH:
1505 /* see if search hasn't been sent yet. */
1506 if (ZOOM_connection_send_search (c))
1509 case ZOOM_TASK_RETRIEVE:
1510 if (send_present (c))
1513 case ZOOM_TASK_CONNECT:
1517 case ZOOM_TASK_SCAN:
1521 ZOOM_connection_remove_task (c);
1525 static int send_sort_present (ZOOM_connection c)
1527 int r = send_sort (c);
1529 r = send_present (c);
1533 static void handle_apdu (ZOOM_connection c, Z_APDU *apdu)
1535 Z_InitResponse *initrs;
1537 yaz_log (LOG_DEBUG, "hande_apdu type=%d", apdu->which);
1541 case Z_APDU_initResponse:
1542 initrs = apdu->u.initResponse;
1543 if (!*initrs->result)
1545 c->error = ZOOM_ERROR_INIT;
1550 yaz_oi_get_string_oidval (&apdu->u.initResponse->otherInfo,
1552 xfree (c->cookie_in);
1555 c->cookie_in = xstrdup(cookie);
1556 if (ODR_MASK_GET(initrs->options, Z_Options_namedResultSets) &&
1557 ODR_MASK_GET(initrs->protocolVersion, Z_ProtocolVersion_3))
1558 c->support_named_resultsets = 1;
1561 assert (c->tasks->which == ZOOM_TASK_CONNECT);
1562 ZOOM_connection_remove_task (c);
1564 ZOOM_connection_exec_task (c);
1567 case Z_APDU_searchResponse:
1568 handle_search_response (c, apdu->u.searchResponse);
1569 if (!send_sort_present (c))
1570 ZOOM_connection_remove_task (c);
1572 case Z_APDU_presentResponse:
1573 handle_present_response (c, apdu->u.presentResponse);
1574 if (!send_present (c))
1575 ZOOM_connection_remove_task (c);
1577 case Z_APDU_sortResponse:
1578 sort_response (c, apdu->u.sortResponse);
1579 if (!send_present (c))
1580 ZOOM_connection_remove_task (c);
1582 case Z_APDU_scanResponse:
1583 scan_response (c, apdu->u.scanResponse);
1584 ZOOM_connection_remove_task (c);
1588 static int do_read (ZOOM_connection c)
1594 event = ZOOM_Event_create (ZOOM_EVENT_RECV_DATA);
1595 ZOOM_connection_put_event (c, event);
1597 r = cs_get (c->cs, &c->buf_in, &c->len_in);
1602 c->error= ZOOM_ERROR_CONNECTION_LOST;
1608 odr_reset (c->odr_in);
1609 odr_setbuf (c->odr_in, c->buf_in, r, 0);
1610 event = ZOOM_Event_create (ZOOM_EVENT_RECV_APDU);
1611 ZOOM_connection_put_event (c, event);
1612 if (!z_APDU (c->odr_in, &apdu, 0, 0))
1614 c->error = ZOOM_ERROR_DECODE;
1619 handle_apdu (c, apdu);
1625 static int do_write_ex (ZOOM_connection c, char *buf_out, int len_out)
1630 event = ZOOM_Event_create(ZOOM_EVENT_SEND_DATA);
1631 ZOOM_connection_put_event (c, event);
1633 if ((r=cs_put (c->cs, buf_out, len_out)) < 0)
1635 if (c->state == STATE_CONNECTING)
1636 c->error = ZOOM_ERROR_CONNECT;
1638 c->error = ZOOM_ERROR_CONNECTION_LOST;
1644 c->mask = ZOOM_SELECT_EXCEPT;
1645 if (c->cs->io_pending & CS_WANT_WRITE)
1646 c->mask += ZOOM_SELECT_WRITE;
1647 if (c->cs->io_pending & CS_WANT_READ)
1648 c->mask += ZOOM_SELECT_READ;
1649 yaz_log (LOG_DEBUG, "do_write_ex 1 mask=%d", c->mask);
1653 c->mask = ZOOM_SELECT_READ|ZOOM_SELECT_EXCEPT;
1654 yaz_log (LOG_DEBUG, "do_write_ex 2 mask=%d", c->mask);
1659 static int do_write(ZOOM_connection c)
1661 return do_write_ex (c, c->buf_out, c->len_out);
1665 const char *ZOOM_connection_option_get (ZOOM_connection c, const char *key)
1667 return ZOOM_options_get (c->options, key);
1670 void ZOOM_connection_option_set (ZOOM_connection c, const char *key,
1673 ZOOM_options_set (c->options, key, val);
1676 const char *ZOOM_resultset_option_get (ZOOM_resultset r, const char *key)
1678 return ZOOM_options_get (r->options, key);
1681 void ZOOM_resultset_option_set (ZOOM_resultset r, const char *key,
1684 ZOOM_options_set (r->options, key, val);
1688 int ZOOM_connection_errcode (ZOOM_connection c)
1690 return ZOOM_connection_error (c, 0, 0);
1693 const char *ZOOM_connection_errmsg (ZOOM_connection c)
1696 ZOOM_connection_error (c, &msg, 0);
1700 const char *ZOOM_connection_addinfo (ZOOM_connection c)
1702 const char *addinfo;
1703 ZOOM_connection_error (c, 0, &addinfo);
1707 int ZOOM_connection_error (ZOOM_connection c, const char **cp,
1708 const char **addinfo)
1710 int error = c->error;
1715 case ZOOM_ERROR_NONE:
1716 *cp = "No error"; break;
1717 case ZOOM_ERROR_CONNECT:
1718 *cp = "Connect failed"; break;
1719 case ZOOM_ERROR_MEMORY:
1720 *cp = "Out of memory"; break;
1721 case ZOOM_ERROR_ENCODE:
1722 *cp = "Encoding failed"; break;
1723 case ZOOM_ERROR_DECODE:
1724 *cp = "Decoding failed"; break;
1725 case ZOOM_ERROR_CONNECTION_LOST:
1726 *cp = "Connection lost"; break;
1727 case ZOOM_ERROR_INIT:
1728 *cp = "Init rejected"; break;
1729 case ZOOM_ERROR_INTERNAL:
1730 *cp = "Internal failure"; break;
1731 case ZOOM_ERROR_TIMEOUT:
1732 *cp = "Timeout"; break;
1734 *cp = diagbib1_str (error);
1740 *addinfo = c->addinfo;
1747 int ZOOM_connection_do_io(ZOOM_connection c, int mask)
1749 ZOOM_Event event = 0;
1750 int r = cs_look(c->cs);
1751 yaz_log (LOG_DEBUG, "ZOOM_connection_do_io c=%p mask=%d cs_look=%d",
1756 event = ZOOM_Event_create (ZOOM_EVENT_CONNECT);
1757 c->error = ZOOM_ERROR_CONNECT;
1759 ZOOM_connection_put_event (c, event);
1761 else if (r == CS_CONNECT)
1764 event = ZOOM_Event_create (ZOOM_EVENT_CONNECT);
1766 ret = cs_rcvconnect (c->cs);
1767 yaz_log (LOG_DEBUG, "cs_rcvconnect returned %d", ret);
1770 c->mask = ZOOM_SELECT_EXCEPT;
1771 if (c->cs->io_pending & CS_WANT_WRITE)
1772 c->mask += ZOOM_SELECT_WRITE;
1773 if (c->cs->io_pending & CS_WANT_READ)
1774 c->mask += ZOOM_SELECT_READ;
1775 ZOOM_connection_put_event (c, event);
1779 ZOOM_connection_put_event (c, event);
1780 ZOOM_connection_send_init (c);
1781 c->state = STATE_ESTABLISHED;
1785 c->error = ZOOM_ERROR_CONNECT;
1787 ZOOM_connection_put_event (c, event);
1792 if (mask & ZOOM_SELECT_READ)
1794 if (c->cs && (mask & ZOOM_SELECT_WRITE))
1800 int ZOOM_connection_last_event(ZOOM_connection cs)
1803 return ZOOM_EVENT_NONE;
1804 return cs->last_event;
1807 int ZOOM_event (int no, ZOOM_connection *cs)
1810 struct pollfd pollfds[1024];
1811 ZOOM_connection poll_cs[1024];
1814 fd_set input, output, except;
1819 for (i = 0; i<no; i++)
1821 ZOOM_connection c = cs[i];
1823 if (c && (event = ZOOM_connection_get_event(c)))
1825 ZOOM_Event_destroy (event);
1829 for (i = 0; i<no; i++)
1831 ZOOM_connection c = cs[i];
1833 if (c && ZOOM_connection_exec_task (c))
1835 if ((event = ZOOM_connection_get_event(c)))
1837 ZOOM_Event_destroy (event);
1853 for (i = 0; i<no; i++)
1855 ZOOM_connection c = cs[i];
1860 fd = z3950_connection_socket(c);
1861 mask = z3950_connection_mask(c);
1871 short poll_events = 0;
1873 if (mask & ZOOM_SELECT_READ)
1874 poll_events += POLLIN;
1875 if (mask & ZOOM_SELECT_WRITE)
1876 poll_events += POLLOUT;
1877 if (mask & ZOOM_SELECT_EXCEPT)
1878 poll_events += POLLERR;
1879 pollfds[nfds].fd = fd;
1880 pollfds[nfds].events = poll_events;
1881 pollfds[nfds].revents = 0;
1886 if (mask & ZOOM_SELECT_READ)
1888 FD_SET (fd, &input);
1891 if (mask & ZOOM_SELECT_WRITE)
1893 FD_SET (fd, &output);
1896 if (mask & ZOOM_SELECT_EXCEPT)
1898 FD_SET (fd, &except);
1906 r = poll (pollfds, nfds, 15000);
1907 for (i = 0; i<nfds; i++)
1909 ZOOM_connection c = poll_cs[i];
1913 if (pollfds[i].revents & POLLIN)
1914 mask += ZOOM_SELECT_READ;
1915 if (pollfds[i].revents & POLLOUT)
1916 mask += ZOOM_SELECT_WRITE;
1917 if (pollfds[i].revents & POLLERR)
1918 mask += ZOOM_SELECT_EXCEPT;
1920 ZOOM_connection_do_io(c, mask);
1922 else if (r == 0 && c->mask)
1924 ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_TIMEOUT);
1925 /* timeout and this connection was waiting */
1926 c->error = ZOOM_ERROR_TIMEOUT;
1928 ZOOM_connection_put_event(c, event);
1932 yaz_log (LOG_DEBUG, "select start");
1933 r = select (max_fd+1, &input, &output, &except, &tv);
1934 yaz_log (LOG_DEBUG, "select stop, returned r=%d", r);
1935 for (i = 0; i<no; i++)
1937 ZOOM_connection c = cs[i];
1942 fd = z3950_connection_socket(c);
1946 /* no timeout and real socket */
1947 if (FD_ISSET(fd, &input))
1948 mask += ZOOM_SELECT_READ;
1949 if (FD_ISSET(fd, &output))
1950 mask += ZOOM_SELECT_WRITE;
1951 if (FD_ISSET(fd, &except))
1952 mask += ZOOM_SELECT_EXCEPT;
1954 ZOOM_connection_do_io(c, mask);
1956 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 yaz_log (LOG_DEBUG, "timeout");
1963 ZOOM_connection_put_event(c, event);
1967 for (i = 0; i<no; i++)
1969 ZOOM_connection c = cs[i];
1971 if (c && (event = ZOOM_connection_get_event(c)))
1973 ZOOM_Event_destroy (event);