- struct connection *co = iochan_getdata(i);
- struct client *cl = co->client;
- Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_initRequest);
-
- a->u.initRequest->implementationId = global_parameters.implementationId;
- a->u.initRequest->implementationName = global_parameters.implementationName;
- a->u.initRequest->implementationVersion =
- global_parameters.implementationVersion;
- ODR_MASK_SET(a->u.initRequest->options, Z_Options_search);
- ODR_MASK_SET(a->u.initRequest->options, Z_Options_present);
- ODR_MASK_SET(a->u.initRequest->options, Z_Options_namedResultSets);
-
- ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_1);
- ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_2);
- ODR_MASK_SET(a->u.initRequest->protocolVersion, Z_ProtocolVersion_3);
- if (send_apdu(cl, a) >= 0)
- {
- iochan_setflags(i, EVENT_INPUT);
- cl->state = Client_Initializing;
- }
- else
- cl->state = Client_Error;
- odr_reset(global_parameters.odr_out);
-}
-
-static void send_search(IOCHAN i)
-{
- struct connection *co = iochan_getdata(i);
- struct client *cl = co->client;
- struct session *se = cl->session;
- struct database *db = cl->database;
- Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_searchRequest);
- int ndb, cerror, cpos;
- char **databaselist;
- Z_Query *zquery;
- struct ccl_rpn_node *cn;
- int ssub = 0, lslb = 100000, mspn = 10;
-
- yaz_log(YLOG_DEBUG, "Sending search");
-
- cn = ccl_find_str(global_parameters.ccl_filter, se->query, &cerror, &cpos);
- if (!cn)
- return;
- a->u.searchRequest->query = zquery = odr_malloc(global_parameters.odr_out,
- sizeof(Z_Query));
- zquery->which = Z_Query_type_1;
- zquery->u.type_1 = ccl_rpn_query(global_parameters.odr_out, cn);
- ccl_rpn_delete(cn);
-
- for (ndb = 0; db->databases[ndb]; ndb++)
- ;
- databaselist = odr_malloc(global_parameters.odr_out, sizeof(char*) * ndb);
- for (ndb = 0; db->databases[ndb]; ndb++)
- databaselist[ndb] = db->databases[ndb];
-
- a->u.presentRequest->preferredRecordSyntax =
- yaz_oidval_to_z3950oid(global_parameters.odr_out,
- CLASS_RECSYN, VAL_USMARC);
- 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;
-
- if (send_apdu(cl, a) >= 0)
- {
- iochan_setflags(i, EVENT_INPUT);
- cl->state = Client_Searching;
- cl->requestid = se->requestid;
- }
- else
- cl->state = Client_Error;
-
- odr_reset(global_parameters.odr_out);
-}
-
-static void send_present(IOCHAN i)
-{
- struct connection *co = iochan_getdata(i);
- struct client *cl = co->client;
- Z_APDU *a = zget_APDU(global_parameters.odr_out, Z_APDU_presentRequest);
- int toget;
- int start = cl->records + 1;
-
- 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";
-
- a->u.presentRequest->preferredRecordSyntax =
- yaz_oidval_to_z3950oid(global_parameters.odr_out,
- CLASS_RECSYN, VAL_USMARC);
-
- 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, "Received init response");