- yaz_log(log_details, "%p ZOOM_connection_exec_task "
- "task removed (complete)", c);
- ZOOM_connection_remove_task (c);
- return 0;
- }
- yaz_log(log_details, "%p ZOOM_connection_exec_task "
- "task pending", c);
- return 1;
-}
-
-static zoom_ret send_sort_present (ZOOM_connection c)
-{
- zoom_ret r = zoom_complete;
-
- if (c->tasks && c->tasks->which == ZOOM_TASK_SEARCH)
- r = send_sort (c, c->tasks->u.search.resultset);
- if (r == zoom_complete)
- r = send_present (c);
- return r;
-}
-
-static int es_response (ZOOM_connection c,
- Z_ExtendedServicesResponse *res)
-{
- if (!c->tasks || c->tasks->which != ZOOM_TASK_PACKAGE)
- return 0;
- if (res->diagnostics && res->num_diagnostics > 0)
- response_diag(c, res->diagnostics[0]);
- if (res->taskPackage &&
- res->taskPackage->which == Z_External_extendedService)
- {
- Z_TaskPackage *taskPackage = res->taskPackage->u.extendedService;
- Odr_oct *id = taskPackage->targetReference;
-
- if (id)
- ZOOM_options_setl (c->tasks->u.package->options,
- "targetReference", (char*) id->buf, id->len);
- }
- if (res->taskPackage &&
- res->taskPackage->which == Z_External_octet)
- {
- Odr_oct *doc = res->taskPackage->u.octet_aligned;
- ZOOM_options_setl (c->tasks->u.package->options,
- "xmlUpdateDoc", (char*) doc->buf, doc->len);
- }
- return 1;
-}
-
-static void interpret_init_diag(ZOOM_connection c,
- Z_DiagnosticFormat *diag)
-{
- if (diag->num > 0)
- {
- Z_DiagnosticFormat_s *ds = diag->elements[0];
- if (ds->which == Z_DiagnosticFormat_s_defaultDiagRec)
- response_default_diag(c, ds->u.defaultDiagRec);
- }
-}
-
-
-static void interpret_otherinformation_field(ZOOM_connection c,
- Z_OtherInformation *ui)
-{
- int i;
- for (i = 0; i < ui->num_elements; i++)
- {
- Z_OtherInformationUnit *unit = ui->list[i];
- if (unit->which == Z_OtherInfo_externallyDefinedInfo &&
- unit->information.externallyDefinedInfo &&
- unit->information.externallyDefinedInfo->which ==
- Z_External_diag1)
- {
- interpret_init_diag(c, unit->information.externallyDefinedInfo->u.diag1);
- }
- }
-}
-
-static void recv_apdu (ZOOM_connection c, Z_APDU *apdu)
-{
- Z_InitResponse *initrs;
-
- c->mask = 0;
- yaz_log(log_details, "%p recv_apdu apdu->which=%d", c, apdu->which);
- switch(apdu->which)
- {
- case Z_APDU_initResponse:
- yaz_log(log_api, "%p recv_apd: Received Init response", c);
- initrs = apdu->u.initResponse;
- ZOOM_connection_option_set(c, "serverImplementationId",
- initrs->implementationId ?
- initrs->implementationId : "");
- ZOOM_connection_option_set(c, "serverImplementationName",
- initrs->implementationName ?
- initrs->implementationName : "");
- ZOOM_connection_option_set(c, "serverImplementationVersion",
- initrs->implementationVersion ?
- initrs->implementationVersion : "");
- /* Set the three old options too, for old applications */
- ZOOM_connection_option_set(c, "targetImplementationId",
- initrs->implementationId ?
- initrs->implementationId : "");
- ZOOM_connection_option_set(c, "targetImplementationName",
- initrs->implementationName ?
- initrs->implementationName : "");
- ZOOM_connection_option_set(c, "targetImplementationVersion",
- initrs->implementationVersion ?
- initrs->implementationVersion : "");
- if (!*initrs->result)
- {
- Z_External *uif = initrs->userInformationField;
-
- set_ZOOM_error(c, ZOOM_ERROR_INIT, 0); /* default error */
-
- if (uif && uif->which == Z_External_userInfo1)
- interpret_otherinformation_field(c, uif->u.userInfo1);
- }
- else
- {
- char *cookie =
- yaz_oi_get_string_oidval (&apdu->u.initResponse->otherInfo,
- VAL_COOKIE, 1, 0);
- xfree (c->cookie_in);
- c->cookie_in = 0;
- if (cookie)
- c->cookie_in = xstrdup(cookie);
- if (ODR_MASK_GET(initrs->options, Z_Options_namedResultSets) &&
- ODR_MASK_GET(initrs->protocolVersion, Z_ProtocolVersion_3))
- c->support_named_resultsets = 1;
- if (c->tasks)
- {
- assert (c->tasks->which == ZOOM_TASK_CONNECT);
- ZOOM_connection_remove_task (c);
- }
- ZOOM_connection_exec_task (c);
- }
- if (ODR_MASK_GET(initrs->options, Z_Options_negotiationModel))
- {
- NMEM tmpmem = nmem_create();
- Z_CharSetandLanguageNegotiation *p =
- yaz_get_charneg_record(initrs->otherInfo);
-
- if (p)
- {
- char *charset = NULL, *lang = NULL;
- int sel;
-
- yaz_get_response_charneg(tmpmem, p, &charset, &lang, &sel);
- yaz_log(log_details, "%p recv_apdu target accepted: "
- "charset %s, language %s, select %d",
- c,
- charset ? charset : "none", lang ? lang : "none", sel);
- if (charset)
- ZOOM_connection_option_set (c, "negotiation-charset",
- charset);
- if (lang)
- ZOOM_connection_option_set (c, "negotiation-lang",
- lang);
-
- ZOOM_connection_option_set (
- c, "negotiation-charset-in-effect-for-records",
- (sel != 0) ? "1" : "0");
- nmem_destroy(tmpmem);
- }
- }
- break;
- case Z_APDU_searchResponse:
- yaz_log(log_api, "%p recv_apdu Search response", c);
- handle_search_response (c, apdu->u.searchResponse);
- if (send_sort_present (c) == zoom_complete)
- ZOOM_connection_remove_task (c);
- break;
- case Z_APDU_presentResponse:
- yaz_log(log_api, "%p recv_apdu Present response", c);
- handle_present_response (c, apdu->u.presentResponse);
- if (send_present (c) == zoom_complete)
- ZOOM_connection_remove_task (c);
- break;
- case Z_APDU_sortResponse:
- yaz_log(log_api, "%p recv_apdu Sort response", c);
- sort_response (c, apdu->u.sortResponse);
- if (send_present (c) == zoom_complete)
- ZOOM_connection_remove_task (c);
- break;
- case Z_APDU_scanResponse:
- yaz_log(log_api, "%p recv_apdu Scan response", c);
- scan_response (c, apdu->u.scanResponse);
- ZOOM_connection_remove_task (c);
- break;
- case Z_APDU_extendedServicesResponse:
- yaz_log(log_api, "%p recv_apdu Extended Services response", c);
- es_response (c, apdu->u.extendedServicesResponse);
- ZOOM_connection_remove_task (c);
- break;
- case Z_APDU_close:
- yaz_log(log_api, "%p recv_apdu Close PDU", c);
- if (c->reconnect_ok)
- {
- do_close(c);
- c->tasks->running = 0;
- ZOOM_connection_insert_task (c, ZOOM_TASK_CONNECT);
- }
- else
- {
- set_ZOOM_error(c, ZOOM_ERROR_CONNECTION_LOST, 0);
- do_close(c);
- }
- break;
- default:
- yaz_log(log_api, "%p Received unknown PDU", c);
- set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0);
- do_close(c);