-
- for (ndb = 0; sdb->database->databases[ndb]; ndb++)
- ;
- databaselist = odr_malloc(global_parameters.odr_out, sizeof(char*) * ndb);
- for (ndb = 0; sdb->database->databases[ndb]; ndb++)
- databaselist[ndb] = sdb->database->databases[ndb];
-
- if (!(piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK)) || *piggyback == '1')
- {
- if ((recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX)))
- {
-#if YAZ_VERSIONL >= 0x020163
- a->u.searchRequest->preferredRecordSyntax =
- yaz_string_to_oid_odr(yaz_oid_std(),
- CLASS_RECSYN, recsyn,
- global_parameters.odr_out);
-#else
- a->u.searchRequest->preferredRecordSyntax =
- yaz_str_to_z3950oid(global_parameters.odr_out,
- CLASS_RECSYN, recsyn);
-#endif
- }
- a->u.searchRequest->smallSetUpperBound = &ssub;
- a->u.searchRequest->largeSetLowerBound = &lslb;
- a->u.searchRequest->mediumSetPresentNumber = &mspn;
- }
- a->u.searchRequest->resultSetName = "Default";
- a->u.searchRequest->databaseNames = databaselist;
- a->u.searchRequest->num_databaseNames = ndb;
-
-
- { //scope for sending and logging queries
- WRBUF wbquery = wrbuf_alloc();
- yaz_query_to_wrbuf(wbquery, zquery);
-
-
- if (send_apdu(cl, a) >= 0)
- {
- iochan_setflags(i, EVENT_INPUT);
- cl->state = Client_Searching;
- cl->requestid = se->requestid;
- yaz_log(YLOG_LOG, "SearchRequest %s %s %s",
- cl->database->database->url,
- queryenc ? queryenc : "UTF-8",
- wrbuf_cstr(wbquery));
- }
- else {
- cl->state = Client_Error;
- yaz_log(YLOG_WARN, "Failed SearchRequest %s %s %s",
- cl->database->database->url,
- queryenc ? queryenc : "UTF-8",
- wrbuf_cstr(wbquery));
- }
-
- wrbuf_destroy(wbquery);
- }
-
- odr_reset(global_parameters.odr_out);
-}
-
-static void send_present(IOCHAN i)
-{
- struct connection *co = iochan_getdata(i);
- struct client *cl = co->client;
- struct session_database *sdb = cl->database;
- Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
- int toget;
- int start = cl->records + 1;
- char *recsyn;
-
- toget = global_parameters.chunk;
- if (toget > global_parameters.toget - cl->records)
- toget = global_parameters.toget - cl->records;
- if (toget > cl->hits - cl->records)
- toget = cl->hits - cl->records;
-
- yaz_log(YLOG_DEBUG, "Trying to present %d records\n", toget);
-
- a->u.presentRequest->resultSetStartPoint = &start;
- a->u.presentRequest->numberOfRecordsRequested = &toget;
-
- a->u.presentRequest->resultSetId = "Default";
-
- if ((recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX)))
- {
-#if YAZ_VERSIONL >= 0x020163
- a->u.presentRequest->preferredRecordSyntax =
- yaz_string_to_oid_odr(yaz_oid_std(),
- CLASS_RECSYN, recsyn,
- global_parameters.odr_out);
-#else
- a->u.presentRequest->preferredRecordSyntax =
- yaz_str_to_z3950oid(global_parameters.odr_out,
- CLASS_RECSYN, recsyn);
-#endif
- }
-
- if (send_apdu(cl, a) >= 0)
- {
- iochan_setflags(i, EVENT_INPUT);
- cl->state = Client_Presenting;
- }
- else
- cl->state = Client_Error;
- odr_reset(global_parameters.odr_out);
-}
-
-static void do_initResponse(IOCHAN i, Z_APDU *a)
-{
- struct connection *co = iochan_getdata(i);
- struct client *cl = co->client;
- Z_InitResponse *r = a->u.initResponse;
-
- yaz_log(YLOG_DEBUG, "Init response %s", cl->database->database->url);
-
- if (*r->result)
- {
- cl->state = Client_Idle;
- }
- else
- cl->state = Client_Failed; // FIXME need to do something to the connection
-}
-
-static void do_searchResponse(IOCHAN i, Z_APDU *a)
-{
- struct connection *co = iochan_getdata(i);
- struct client *cl = co->client;
- struct session *se = cl->session;
- Z_SearchResponse *r = a->u.searchResponse;
-
- yaz_log(YLOG_DEBUG, "Search response %s (status=%d)",
- cl->database->database->url, *r->searchStatus);
-
- if (*r->searchStatus)
- {
- cl->hits = *r->resultCount;
- se->total_hits += cl->hits;
- if (r->presentStatus && !*r->presentStatus && r->records)
- {
- yaz_log(YLOG_DEBUG, "Records in search response %s",
- cl->database->database->url);
- ingest_records(cl, r->records);
- }
- cl->state = Client_Idle;
- }
- else
- { /*"FAILED"*/
- cl->hits = 0;
- cl->state = Client_Error;
- if (r->records) {
- Z_Records *recs = r->records;
- if (recs->which == Z_Records_NSD)
- {
- yaz_log(YLOG_WARN,
- "Search response: Non-surrogate diagnostic %s",
- cl->database->database->url);
- cl->diagnostic = *recs->u.nonSurrogateDiagnostic->condition;
- cl->state = Client_Error;
- }
- }
- }
-}
-
-static void do_closeResponse(IOCHAN i, Z_APDU *a)
-{
- struct connection *co = iochan_getdata(i);
- struct client *cl = co->client;
- /* Z_Close *r = a->u.close; */
-
- yaz_log(YLOG_WARN, "Close response %s", cl->database->database->url);
-
- cl->state = Client_Failed;
- connection_destroy(co);