- boost::mutex::scoped_lock lock(m_sessions_mutex);
-
- Ses_it it = m_sessions.find(package.session());
- if (it == m_sessions.end())
- {
- ODR odr = odr_createmem(ODR_ENCODE);
-
- Z_APDU *apdu = zget_APDU(odr, Z_APDU_close);
-
- *apdu->u.close->closeReason = Z_Close_protocolError;
- apdu->u.close->diagnosticInformation =
- odr_strdup(odr, "no session for search request");
-
- package.response() = apdu;
- package.session().close();
- odr_destroy(odr);
- return;
- }
- if (it->second.m_use_vhost)
- {
- move_later = true;
- return;
- }
- if (req->num_databaseNames != 1)
- { // exactly one database must be specified
- ODR odr = odr_createmem(ODR_ENCODE);
- Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse);
-
- Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
- apdu->u.searchResponse->records = rec;
- rec->which = Z_Records_NSD;
- rec->u.nonSurrogateDiagnostic =
- zget_DefaultDiagFormat(
- odr, YAZ_BIB1_TOO_MANY_DATABASES_SPECIFIED, 0);
- package.response() = apdu;
-
- odr_destroy(odr);
- return;
- }
- database = req->databaseNames[0];
- std::map<std::string, Virt_db_map>::iterator map_it;
- map_it = m_maps.find(database);
- if (map_it == m_maps.end())
- { // no map for database: return diagnostic
- ODR odr = odr_createmem(ODR_ENCODE);
- Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse);
-
- Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
- apdu->u.searchResponse->records = rec;
- rec->which = Z_Records_NSD;
- rec->u.nonSurrogateDiagnostic =
- zget_DefaultDiagFormat(
- odr, YAZ_BIB1_DATABASE_UNAVAILABLE, database.c_str());
- package.response() = apdu;
-
- odr_destroy(odr);
- return;
- }
- if (*req->replaceIndicator == 0)
- {
- Sets_it sets_it = it->second.m_sets.find(req->resultSetName);
- if (sets_it != it->second.m_sets.end())
- {
- ODR odr = odr_createmem(ODR_ENCODE);
- Z_APDU *apdu = zget_APDU(odr, Z_APDU_searchResponse);
-
- Z_Records *rec = (Z_Records *) odr_malloc(odr, sizeof(Z_Records));
- apdu->u.searchResponse->records = rec;
- rec->which = Z_Records_NSD;
- rec->u.nonSurrogateDiagnostic =
- zget_DefaultDiagFormat(
- odr,
- YAZ_BIB1_RESULT_SET_EXISTS_AND_REPLACE_INDICATOR_OFF,
- 0);
- package.response() = apdu;
-
- odr_destroy(odr);
- return;
- }
- }
- it->second.m_sets.erase(req->resultSetName);
- vhost = map_it->second.m_vhost;
- }
- // we might look for an existing session with same vhost
- Session id;
- const char *vhost_cstr = vhost.c_str();
- if (true)
- { // sending init to backend
- Package init_package(id, package.origin());
- init_package.copy_filter(package);