X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fzebrasrv.c;h=9629d4152b5af9dcc4895dc4f7f18507b28376fc;hb=e9f4ac05ebcdf0bf3497e62d0f70e9b643d9cc80;hp=613febbd3f425d33b1b9b2b16bc5423356ebce1f;hpb=4c112f15503aebed494fab8aa5296c3661bfb31c;p=idzebra-moved-to-github.git diff --git a/index/zebrasrv.c b/index/zebrasrv.c index 613febb..9629d41 100644 --- a/index/zebrasrv.c +++ b/index/zebrasrv.c @@ -1,5 +1,5 @@ -/* $Id: zebrasrv.c,v 1.3 2006-12-05 09:26:37 adam Exp $ - Copyright (C) 1995-2006 +/* $Id: zebrasrv.c,v 1.20 2007-10-25 07:43:13 adam Exp $ + Copyright (C) 1995-2007 Index Data ApS This file is part of the Zebra server. @@ -61,6 +61,7 @@ bend_initresult *bend_init (bend_initrequest *q) struct statserv_options_block *sob; char *user = NULL; char *passwd = NULL; + char version_str[16]; r->errcode = 0; r->errstring = 0; @@ -72,8 +73,10 @@ bend_initresult *bend_init (bend_initrequest *q) q->bend_fetch = bend_fetch; q->bend_scan = bend_scan; + zebra_get_version(version_str, 0); + q->implementation_name = "Zebra Information Server"; - q->implementation_version = "Zebra " ZEBRAVER; + q->implementation_version = odr_strdup(q->stream, version_str); yaz_log (YLOG_DEBUG, "bend_init"); @@ -85,6 +88,8 @@ bend_initresult *bend_init (bend_initrequest *q) return r; } r->handle = zh; + + q->query_charset = odr_strdup(q->stream, zebra_get_encoding(zh)); if (q->auth) { if (q->auth->which == Z_IdAuthentication_open) @@ -113,7 +118,7 @@ bend_initresult *bend_init (bend_initrequest *q) r->errstring = user; return r; } - if (q->charneg_request) /* characater set and langauge negotiation? */ + if (q->charneg_request) /* characater set and language negotiation? */ { char **charsets = 0; int num_charsets; @@ -123,11 +128,9 @@ bend_initresult *bend_init (bend_initrequest *q) int i; NMEM nmem = nmem_create(); - yaz_log (YLOG_LOG, "character set and language negotiation"); - - yaz_get_proposal_charneg (nmem, q->charneg_request, - &charsets, &num_charsets, - &langs, &num_langs, &selected); + yaz_get_proposal_charneg(nmem, q->charneg_request, + &charsets, &num_charsets, + &langs, &num_langs, &selected); for (i = 0; i < num_charsets; i++) { @@ -152,21 +155,21 @@ bend_initresult *bend_init (bend_initrequest *q) } else { right_name = charsets[i]; } - if (odr_set_charset (q->decode, "UTF-8", right_name) == 0) + if (odr_set_charset(q->decode, "UTF-8", right_name) == 0) { - yaz_log (YLOG_LOG, "charset %d %s (proper name %s): OK", i, - charsets[i], right_name); - odr_set_charset (q->stream, right_name, "UTF-8"); + yaz_log(YLOG_LOG, "charset %d %s (proper name %s): OK", i, + charsets[i], right_name); + odr_set_charset(q->stream, right_name, "UTF-8"); if (selected) zebra_record_encoding(zh, right_name); zebra_octet_term_encoding(zh, right_name); q->charneg_response = - yaz_set_response_charneg (q->stream, charsets[i], - 0, selected); + yaz_set_response_charneg(q->stream, charsets[i], + 0, selected); break; } else { - yaz_log (YLOG_LOG, "charset %d %s (proper name %s): unsupported", i, - charsets[i], right_name); + yaz_log(YLOG_LOG, "charset %d %s (proper name %s): unsupported", i, + charsets[i], right_name); } } nmem_destroy(nmem); @@ -197,8 +200,8 @@ static void search_terms(ZebraHandle zh, bend_search_rr *r) r->search_info->list[0]->which = Z_OtherInfo_externallyDefinedInfo; ext = odr_malloc (r->stream, sizeof(*ext)); r->search_info->list[0]->information.externallyDefinedInfo = ext; - ext->direct_reference = - yaz_oidval_to_z3950oid (r->stream, CLASS_USERINFO, VAL_SEARCHRES1); + ext->direct_reference = odr_oiddup(r->stream, + yaz_oid_userinfo_searchresult_1); ext->indirect_reference = 0; ext->descriptor = 0; ext->which = Z_External_searchResult1; @@ -261,6 +264,15 @@ static void search_terms(ZebraHandle zh, bend_search_rr *r) } } + +static int break_handler(void *client_data) +{ + bend_association assoc =(bend_association) client_data; + if (!bend_assoc_is_alive(assoc)) + return 1; + return 0; +} + int bend_search(void *handle, bend_search_rr *r) { ZebraHandle zh = (ZebraHandle) handle; @@ -274,12 +286,15 @@ int bend_search(void *handle, bend_search_rr *r) zebra_result (zh, &r->errcode, &r->errstring); return 0; } + zebra_set_break_handler(zh, break_handler, r->association); yaz_log (YLOG_DEBUG, "ResultSet '%s'", r->setname); switch (r->query->which) { case Z_Query_type_1: case Z_Query_type_101: - res = zebra_search_RPN(zh, r->stream, r->query->u.type_1, - r->setname, &zhits); + res = zebra_search_RPN_x(zh, r->stream, r->query->u.type_1, + r->setname, &zhits, + &r->estimated_hit_count, + &r->partial_resultset); if (res != ZEBRA_OK) zebra_result(zh, &r->errcode, &r->errstring); else @@ -297,11 +312,12 @@ int bend_search(void *handle, bend_search_rr *r) default: r->errcode = YAZ_BIB1_QUERY_TYPE_UNSUPP; } + zebra_set_break_handler(zh, 0, 0); return 0; } -int bend_fetch (void *handle, bend_fetch_rr *r) +int bend_fetch(void *handle, bend_fetch_rr *r) { ZebraHandle zh = (ZebraHandle) handle; ZebraRetrievalRecord retrievalRecord; @@ -330,7 +346,7 @@ int bend_fetch (void *handle, bend_fetch_rr *r) r->basename = retrievalRecord.base; r->record = retrievalRecord.buf; r->len = retrievalRecord.len; - r->output_format = retrievalRecord.format; + r->output_format = odr_oiddup(r->stream, retrievalRecord.format); } return 0; } @@ -354,8 +370,6 @@ static int bend_scan (void *handle, bend_scan_rr *r) r->errstring = 0; return 0; } - r->entries = (struct scan_entry *) - odr_malloc (r->stream, sizeof(*r->entries) * r->num_entries); res = zebra_scan(zh, r->stream, r->term, r->attributeset, &r->term_position, @@ -370,6 +384,7 @@ static int bend_scan (void *handle, bend_scan_rr *r) for (i = 0; i < r->num_entries; i++) { r->entries[i].term = entries[i].term; + r->entries[i].display_term = entries[i].display_term; r->entries[i].occurrences = CAST_ZINT_TO_INT(entries[i].occurrences); } @@ -386,7 +401,6 @@ void bend_close (void *handle) { zebra_close ((ZebraHandle) handle); xmalloc_trav("bend_close"); - nmem_print_list(); } int bend_sort (void *handle, bend_sort_rr *rr) @@ -583,7 +597,6 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr) for (i = 0; notToKeep && i < notToKeep->num; i++) { Z_External *rec = notToKeep->elements[i]->record; - struct oident *oident = 0; Odr_oct *opaque_recid = 0; zint *sysno = 0; zint sysno_tmp; @@ -603,10 +616,14 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr) } if (rec->direct_reference) { - oident = oid_getentbyoid(rec->direct_reference); - if (oident) + char oid_name_str[OID_STR_MAX]; + const char *oid_name = + yaz_oid_to_string_buf( + rec->direct_reference, + 0, oid_name_str); + if (oid_name) yaz_log (YLOG_LOG, "record %d type %s", i, - oident->desc); + oid_name); } switch (rec->which) { @@ -630,110 +647,58 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr) rec->u.octet_aligned->len, rec->u.octet_aligned->buf); } - if (oident && oident->value != VAL_TEXT_XML) - { - rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "only XML update supported"; - break; - } if (rec->which == Z_External_octet) { - int action = 0; + enum zebra_recctrl_action_t action = action_update; + char recid_str[256]; + const char *match_criteria = 0; + ZEBRA_RES res; if (*toKeep->action == Z_IUOriginPartToKeep_recordInsert) - action = 1; - if (*toKeep->action == + action = action_insert; + else if (*toKeep->action == Z_IUOriginPartToKeep_recordReplace) - action = 2; - if (*toKeep->action == + action = action_replace; + else if (*toKeep->action == Z_IUOriginPartToKeep_recordDelete) - action = 3; - if (*toKeep->action == + action = action_delete; + else if (*toKeep->action == Z_IUOriginPartToKeep_specialUpdate) - action = 4; - - if (!action) + action = action_update; + else { rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; rr->errstring = "unsupported ES Update action"; break; } - else if (opaque_recid) + + if (opaque_recid) { - int r = zebra_admin_exchange_record ( - zh, - (const char *) rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - (const char *) opaque_recid->buf, - opaque_recid->len, - action); - if (r) + size_t l = opaque_recid->len; + if (l >= sizeof(recid_str)) { - zebra_result(zh, &rr->errcode, - &rr->errstring); + rr->errcode = YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; + rr->errstring = "opaque record ID too large"; break; } - } - else - { - ZEBRA_RES r = ZEBRA_FAIL; - switch(action) { - case 1: - r = zebra_insert_record( - zh, - 0, /* recordType */ - sysno, - 0, /* match */ - 0, /* fname */ - (const char *) rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - 0); - if (r == ZEBRA_FAIL) - { - rr->errcode = - YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "insert_record failed"; - } - break; - case 2: - case 4: - r = zebra_update_record( - zh, - 0, /* recordType */ - sysno, - 0, /* match */ - 0, /* fname */ - (const char *) rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - 1); - if (r == ZEBRA_FAIL) - { - rr->errcode = - YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "update_record failed"; - } - break; - case 3: - r = zebra_delete_record( - zh, - 0, /* recordType */ - sysno, - 0, /* match */ - 0, /* fname */ - (const char *) rec->u.octet_aligned->buf, - rec->u.octet_aligned->len, - 0); - if (r == ZEBRA_FAIL) - { - rr->errcode = - YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; - rr->errstring = "delete_record failed"; - } - break; - } - } + memcpy(recid_str, opaque_recid->buf, l); + recid_str[l] = '\0'; + match_criteria = recid_str; + } + res = zebra_update_record( + zh, action, + 0, /* recordType */ + sysno, match_criteria, 0, /* fname */ + (const char *) rec->u.octet_aligned->buf, + rec->u.octet_aligned->len); + if (res == ZEBRA_FAIL) + { + rr->errcode = + YAZ_BIB1_ES_IMMEDIATE_EXECUTION_FAILED; + rr->errstring = "update_record failed"; + } } } if (zebra_end_trans (zh) != ZEBRA_OK) @@ -762,7 +727,7 @@ static void bend_start (struct statserv_options_block *sob) zebra_stop((ZebraService) sob->handle); res_set(default_res, "profilePath", DEFAULT_PROFILE_PATH); res_set(default_res, "modulePath", DEFAULT_MODULE_PATH); - sob->handle = zebra_start(sob->configname); + sob->handle = zebra_start_res(sob->configname, default_res, 0); res_close(default_res); if (!sob->handle) { @@ -772,7 +737,7 @@ static void bend_start (struct statserv_options_block *sob) #ifdef WIN32 #else - if (!sob->inetd) + if (!sob->inetd && !sob->background) { char pidfname[4096]; struct flock area; @@ -819,7 +784,7 @@ static void bend_stop(struct statserv_options_block *sob) #ifdef WIN32 #else - if (!sob->inetd && sob->handle) + if (!sob->inetd && !sob->background && sob->handle) { char pidfname[4096]; zebra_pidfname(sob->handle, pidfname);