- static bend_initresult r;
- static char *name = "zserver";
-
- r.errcode = 0;
- r.errstring = 0;
- r.handle = name;
-
- server_info.sets = NULL;
- if (!(server_info.sys_idx_fd = open (FNAME_SYS_IDX, O_RDONLY)))
- {
- r.errcode = 1;
- r.errstring = "dict_open fail: filedict";
- return &r;
- }
- if (!(server_info.fileDict = dict_open (FNAME_FILE_DICT, 10, 0)))
- {
- r.errcode = 1;
- r.errstring = "dict_open fail: filedict";
- return &r;
- }
- if (!(server_info.wordDict = dict_open (FNAME_WORD_DICT, 40, 0)))
- {
- dict_close (server_info.fileDict);
- r.errcode = 1;
- r.errstring = "dict_open fail: worddict";
- return &r;
- }
- if (!(server_info.wordIsam = is_open (FNAME_WORD_ISAM, key_compare, 0,
- sizeof (struct it_key))))
- {
- dict_close (server_info.wordDict);
- dict_close (server_info.fileDict);
- r.errcode = 1;
- r.errstring = "is_open fail: wordisam";
- return &r;
- }
- server_info.recordBuf = NULL;
- server_info.odr = odr_createmem (ODR_ENCODE);
- return &r;
+ bend_initresult *r = (bend_initresult *)
+ odr_malloc (q->stream, sizeof(*r));
+ ZebraHandle zh;
+ struct statserv_options_block *sob;
+ char *user = NULL;
+ char *passwd = NULL;
+
+ r->errcode = 0;
+ r->errstring = 0;
+ q->bend_sort = bend_sort;
+ q->bend_delete = bend_delete;
+ q->bend_esrequest = bend_esrequest;
+ q->bend_segment = bend_segment;
+ q->bend_search = bend_search;
+ q->bend_fetch = bend_fetch;
+ q->bend_scan = bend_scan;
+
+ q->implementation_name = "Zebra Information Server";
+ q->implementation_version = "Zebra " ZEBRAVER;
+
+ yaz_log (YLOG_DEBUG, "bend_init");
+
+ sob = statserv_getcontrol ();
+ if (!(zh = zebra_open (sob->handle)))
+ {
+ yaz_log (YLOG_WARN, "Failed to read config `%s'", sob->configname);
+ r->errcode = 1;
+ return r;
+ }
+ r->handle = zh;
+ if (q->auth)
+ {
+ if (q->auth->which == Z_IdAuthentication_open)
+ {
+ char *openpass = xstrdup (q->auth->u.open);
+ char *cp = strchr (openpass, '/');
+ if (cp)
+ {
+ *cp = '\0';
+ user = nmem_strdup (odr_getmem (q->stream), openpass);
+ passwd = nmem_strdup (odr_getmem (q->stream), cp+1);
+ }
+ xfree (openpass);
+ }
+ else if (q->auth->which == Z_IdAuthentication_idPass)
+ {
+ Z_IdPass *idPass = q->auth->u.idPass;
+
+ user = idPass->userId;
+ passwd = idPass->password;
+ }
+ }
+ if (zebra_auth (zh, user, passwd))
+ {
+ r->errcode = 222;
+ r->errstring = user;
+ return r;
+ }
+ if (q->charneg_request) /* characater set and langauge negotiation? */
+ {
+ char **charsets = 0;
+ int num_charsets;
+ char **langs = 0;
+ int num_langs = 0;
+ int selected = 0;
+ 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);
+
+ for (i = 0; i < num_charsets; i++)
+ {
+ const char *right_name = "";
+ /*
+ * FIXME! It is like rudiment :-))
+ * We have to support this short names of character sets,
+ * because a lot servers in Russia to use own in during
+ * character set and language negotiation still.
+ */
+
+ if (!yaz_matchstr(charsets[i], "win")) {
+ right_name = "WINDOWS-1251";
+ } else if (!yaz_matchstr(charsets[i], "koi")) {
+ right_name = "KOI8-R";
+ } else if (!yaz_matchstr(charsets[i], "iso")) {
+ right_name = "ISO-8859-5";
+ } else if (!yaz_matchstr(charsets[i], "dos")) {
+ right_name = "CP866";
+ } else if (!yaz_matchstr(charsets[i], "uni")) {
+ right_name = "UTF-8";
+ } else {
+ right_name = charsets[i];
+ }
+ 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");
+ if (selected)
+ zebra_record_encoding (zh, right_name);
+ q->charneg_response =
+ 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);
+ }
+ }
+ nmem_destroy(nmem);
+ }
+ return r;