-/* $Id: zebraapi.c,v 1.71 2002-09-13 11:03:46 heikki Exp $
+/* $Id: zebraapi.c,v 1.80 2003-01-13 10:56:09 oleg Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
zh->destroyed = 0;
zh->errCode = 0;
zh->errString = 0;
- zh->res = 0;
+ zh->res = 0;
zh->reg_name = xstrdup ("");
zh->path_reg = 0;
}
if (useshadow)
bf_cache (reg->bfs, res_get (res, "shadow"));
- data1_set_tabpath (reg->dh, res_get(res, "profilePath"));
+ data1_set_tabpath (reg->dh, res_get_def(res, "profilePath",
+ DEFAULT_PROFILE_PATH));
data1_set_tabroot (reg->dh, reg_path);
reg->recTypes = recTypes_init (reg->dh);
recTypes_default_handlers (reg->recTypes);
reg->isamb = 0;
reg->zei = 0;
reg->matchDict = 0;
+ reg->key_file_no = 0;
zebraRankInstall (reg, rank1_class);
return ;
yaz_log (LOG_LOG, "zebra_stop");
- zebra_mutex_cond_lock (&zs->session_lock);
while (zs->sessions)
{
zebra_close (zs->sessions);
}
- zebra_mutex_cond_unlock (&zs->session_lock);
-
zebra_mutex_cond_destroy (&zs->session_lock);
if (zs->passwd_db)
}
sp = &(*sp)->next;
}
-// if (!zs->sessions && zs->stop_flag)
-// zebra_register_deactivate(zs);
zebra_mutex_cond_unlock (&zs->session_lock);
xfree (zh->reg_name);
xfree (zh);
return 1;
}
-void zebra_admin_import_begin (ZebraHandle zh, const char *database)
+void zebra_admin_import_begin (ZebraHandle zh, const char *database,
+ const char *record_type)
{
+ if (zebra_select_database(zh, database))
+ return;
zebra_begin_trans (zh);
xfree (zh->admin_databaseName);
zh->admin_databaseName = xstrdup(database);
}
}
+int zebra_admin_exchange_record (ZebraHandle zh,
+ const char *database,
+ const char *rec_buf,
+ size_t rec_len,
+ const char *recid_buf, size_t recid_len,
+ int action)
+{
+ int sysno = 0;
+ char *rinfo = 0;
+ char recid_z[256];
+
+ if (!recid_buf || recid_len <= 0 || recid_len >= sizeof(recid_z))
+ return -1;
+ memcpy (recid_z, recid_buf, recid_len);
+ recid_z[recid_len] = 0;
+
+ rinfo = dict_lookup (zh->reg->matchDict, recid_z);
+ if (rinfo)
+ {
+ if (action == 1) /* fail if insert */
+ return -1;
+ memcpy (&sysno, rinfo+1, sizeof(sysno));
+ }
+ else
+ {
+ if (action == 2 || action == 3) /* fail if delete or update */
+ return -1;
+ }
+ extract_rec_in_mem (zh, "grs.sgml", rec_buf, rec_len, database,
+ action == 3 ? 1 : 0 /* delete flag */,
+ 0, &sysno, 1, 1, 0);
+ if (action == 1)
+ {
+ dict_insert (zh->reg->matchDict, recid_z, sizeof(sysno), &sysno);
+ }
+ else if (action == 3)
+ {
+ dict_delete (zh->reg->matchDict, recid_z);
+ }
+ return 0;
+}
+
void zebra_admin_create (ZebraHandle zh, const char *database)
{
ZebraService zs;
+ if (zebra_select_database (zh, database))
+ return;
zebra_begin_trans (zh);
zs = zh->service;
/* explainDatabase */))
{
zh->errCode = 224;
- zh->errString = "Database already exist";
+ zh->errString = "database already exist";
}
zebra_end_trans (zh);
}
zebra_register_close (zh->service, zh->reg);
zh->reg = 0;
-
yaz_log (LOG_LOG, "Records: %7d i/u/d %d/%d/%d",
zh->records_processed, zh->records_inserted,
zh->records_updated, zh->records_deleted);
int zebra_record_encoding (ZebraHandle zh, const char *encoding)
{
xfree (zh->record_encoding);
+
+ /*
+ * Fixme!
+ */
+
+ if (zh->iconv_to_utf8 != 0)
+ yaz_iconv_close(zh->iconv_to_utf8);
+ if (zh->iconv_from_utf8 != 0)
+ yaz_iconv_close(zh->iconv_from_utf8);
+
zh->record_encoding = xstrdup (encoding);
+
+ logf(LOG_DEBUG, "Reset record encoding: %s", encoding);
+
+ zh->iconv_to_utf8 =
+ yaz_iconv_open ("UTF-8", encoding);
+ if (zh->iconv_to_utf8 == 0)
+ yaz_log (LOG_WARN, "iconv: %s to UTF-8 unsupported", encoding);
+ zh->iconv_from_utf8 =
+ yaz_iconv_open (encoding, "UTF-8");
+ if (zh->iconv_to_utf8 == 0)
+ yaz_log (LOG_WARN, "iconv: UTF-8 to %s unsupported", encoding);
+
return 0;
}
+
+void zebra_set_resource(ZebraHandle zh, const char *name, const char *value)
+{
+ res_put(zh->res, name, value);
+}
+
+const char *zebra_get_resource(ZebraHandle zh,
+ const char *name, const char *defaultvalue)
+{
+ return res_get_def( zh->res, name, (char *)defaultvalue);
+}