-/* $Id: zebraapi.c,v 1.67 2002-08-18 10:20:35 adam Exp $
+/* $Id: zebraapi.c,v 1.73 2002-09-17 12:27:12 adam Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
default_encoding = res_get_def(zs->global_res, "encoding", "ISO-8859-1");
zh->record_encoding = xstrdup (default_encoding);
-#if HAVE_ICONV_H
+
zh->iconv_to_utf8 =
- iconv_open ("UTF-8", default_encoding);
- if (zh->iconv_to_utf8 == (iconv_t)(-1))
+ yaz_iconv_open ("UTF-8", default_encoding);
+ if (zh->iconv_to_utf8 == 0)
yaz_log (LOG_WARN, "iconv: %s to UTF-8 unsupported",
default_encoding);
zh->iconv_from_utf8 =
- iconv_open (default_encoding, "UTF-8");
- if (zh->iconv_to_utf8 == (iconv_t)(-1))
+ yaz_iconv_open (default_encoding, "UTF-8");
+ if (zh->iconv_to_utf8 == 0)
yaz_log (LOG_WARN, "iconv: UTF-8 to %s unsupported",
default_encoding);
-#endif
zebra_mutex_cond_lock (&zs->session_lock);
yaz_log (LOG_LOG, "zebra_start %s", configName);
- if (!(res = res_open (configName, 0)))
- yaz_log (LOG_WARN, "Cannot read resources `%s'", configName);
- else
+ if ((res = res_open (configName, 0)))
{
ZebraService zh = xmalloc (sizeof(*zh));
zebra_close_res (zh);
xfree (zh->record_encoding);
-#if HAVE_ICONV_H
- if (zh->iconv_to_utf8 != (iconv_t) (-1))
- iconv_close (zh->iconv_to_utf8);
- if (zh->iconv_from_utf8 != (iconv_t) (-1))
- iconv_close (zh->iconv_from_utf8);
-#endif
+
+ 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);
xfree (zh->admin_databaseName);
zebra_mutex_cond_lock (&zs->session_lock);
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);
}
fname = zebra_mk_fname (res_get(zh->res, "lockDir"), state_fname);
f = fopen (fname, "w");
- yaz_log (LOG_LOG, "%c %d %ld", val, seqno, p);
+ yaz_log (LOG_DEBUG, "%c %d %ld", val, seqno, p);
fprintf (f, "%c %d %ld\n", val, seqno, p);
fclose (f);
xfree (fname);
void zebra_repository_update (ZebraHandle zh)
{
- zebra_begin_trans (zh);
logf (LOG_LOG, "updating %s", zh->rGroup.path);
repositoryUpdate (zh);
- zebra_end_trans (zh);
}
void zebra_repository_delete (ZebraHandle zh)