-/* $Id: zebraapi.c,v 1.81 2003-01-15 07:26:40 oleg Exp $
+/* $Id: zebraapi.c,v 1.82 2003-02-11 14:01:39 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
int zebra_errCode (ZebraHandle zh)
{
- return zh->errCode;
+ if (zh)
+ return zh->errCode;
+ return 0; /* is this the right thing to return ?*/
}
const char *zebra_errString (ZebraHandle zh)
{
- return diagbib1_str (zh->errCode);
+ if (zh)
+ return diagbib1_str (zh->errCode);
+ return "";
}
char *zebra_errAdd (ZebraHandle zh)
{
- return zh->errString;
+ if (zh)
+ return zh->errString;
+ return "";
}
int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
-/* $Id: zebraapi.h,v 1.23 2003-01-15 07:26:40 oleg Exp $
+/* $Id: zebraapi.h,v 1.24 2003-02-11 14:01:39 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
typedef struct zebra_session *ZebraHandle;
typedef struct zebra_service *ZebraService;
-/* Open Zebra using file 'configName' (usually zebra.cfg) */
+
+/******
+ * Starting and stopping
+ */
+
+/* Start Zebra using file 'configName' (usually zebra.cfg) */
+/* There should be exactly one ZebraService */
+YAZ_EXPORT ZebraService zebra_start (const char *configName);
+
+/* Close the whole Zebra */
+YAZ_EXPORT void zebra_stop (ZebraService zs);
+
+
+/* Open a ZebraHandle */
+/* There should be one handle for each thred doing something */
+/* with zebra, be that searching or indexing. In simple apps */
+/* one handle is sufficient */
YAZ_EXPORT ZebraHandle zebra_open (ZebraService zs);
+/* Close handle */
+YAZ_EXPORT void zebra_close (ZebraHandle zh);
+
+/*********
+ * Error handling
+ */
+
+/* last error code */
+YAZ_EXPORT int zebra_errCode (ZebraHandle zh);
+
+/* string representatio of above */
+YAZ_EXPORT const char *zebra_errString (ZebraHandle zh);
+
+/* extra information associated with error */
+YAZ_EXPORT char *zebra_errAdd (ZebraHandle zh);
+
+/**************
+ * Searching
+ */
+
/* Search using RPN-Query */
YAZ_EXPORT void zebra_search_rpn (ZebraHandle zh, ODR input, ODR output,
Z_RPNQuery *query,
oid_value input_format,
int num_recs, ZebraRetrievalRecord *recs);
+/* Delete Result Set(s) */
+YAZ_EXPORT int zebra_deleleResultSet(ZebraHandle zh, int function,
+ int num_setnames, char **setnames,
+ int *statuses);
+
+
/* Browse */
YAZ_EXPORT void zebra_scan (ZebraHandle zh, ODR stream,
Z_AttributesPlusTerm *zapt,
int *position, int *num_entries,
ZebraScanEntry **list,
int *is_partial);
-
-/* Delete Result Set(s) */
-YAZ_EXPORT int zebra_deleleResultSet(ZebraHandle zh, int function,
- int num_setnames, char **setnames,
- int *statuses);
-
-/* Close zebra and destroy handle */
-YAZ_EXPORT void zebra_close (ZebraHandle zh);
-
-/* last error code */
-YAZ_EXPORT int zebra_errCode (ZebraHandle zh);
-/* string representatio of above */
-YAZ_EXPORT const char *zebra_errString (ZebraHandle zh);
-
-/* extra information associated with error */
-YAZ_EXPORT char *zebra_errAdd (ZebraHandle zh);
+
+
+/*********
+ * Other
+ */
+
/* do authentication */
YAZ_EXPORT int zebra_auth (ZebraHandle zh, const char *user, const char *pass);
const char *input_str, int input_len,
char *output_str, int output_len);
+
+/******
+ * Admin
+ */
+
YAZ_EXPORT void zebra_admin_create (ZebraHandle zh, const char *db);
-YAZ_EXPORT ZebraService zebra_start (const char *configName);
-YAZ_EXPORT void zebra_stop (ZebraService zs);
YAZ_EXPORT void zebra_admin_shutdown (ZebraHandle zh);
YAZ_EXPORT void zebra_admin_start (ZebraHandle zh);
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
+#include <string.h>
#include <ctype.h>
#if HAVE_READLINE_READLINE_H
return 0; /* ok */
}
+/****************
+ * Error handling
+ */
+static int cmd_err ( char *args[], char *outbuff)
+{
+ char tmp[MAX_OUT_BUFF];
+ sprintf(tmp, "errCode: %d \nerrStr: %s\nerrAdd: %s \n",
+ zebra_errCode (zh),
+ zebra_errString (zh),
+ zebra_errAdd (zh) );
+ strcat(outbuff, tmp);
+ return 0; /* ok */
+}
+static int cmd_errcode ( char *args[], char *outbuff)
+{
+ char tmp[MAX_OUT_BUFF];
+ sprintf(tmp, "errCode: %d ",
+ zebra_errCode (zh));
+ strcat(outbuff, tmp);
+ return 0; /* ok */
+}
+static int cmd_errstr ( char *args[], char *outbuff)
+{
+ char tmp[MAX_OUT_BUFF];
+ sprintf(tmp, "errStr: %s",
+ zebra_errString (zh));
+ strcat(outbuff, tmp);
+ return 0; /* ok */
+}
+static int cmd_erradd ( char *args[], char *outbuff)
+{
+ char tmp[MAX_OUT_BUFF];
+ sprintf(tmp, "errAdd: %s \n",
+ zebra_errAdd (zh) );
+ strcat(outbuff, tmp);
+ return 0; /* ok */
+}
+
/**************************************
* Command table, parser, and help
"[level] text...",
"writes an entry in the log",
cmd_logf},
+
+ { "", "Error handling:","", 0},
+ { "err", "",
+ "Displays zebra's error status (code, str, add)",
+ cmd_err},
+ { "errcode", "",
+ "Displays zebra's error code",
+ cmd_errcode},
+ { "errstr", "",
+ "Displays zebra's error string",
+ cmd_errstr},
+ { "erradd", "",
+ "Displays zebra's additional error message",
+ cmd_erradd},
{ "", "Misc:","", 0},
{ "echo", "string",
char *args[MAX_NO_ARGS];
int n;
char argbuf[MAX_ARG_LEN];
+ int rc;
strncpy(argbuf,line, MAX_ARG_LEN-1);
argbuf[MAX_ARG_LEN-1]='\0'; /* just to be sure */
n=split_args(argbuf, args);
strcat(outbuff,tmp);
}
return 0;
- }
-
+}
+/* If Zebra reports an error after an operation,
+ * append it to the outbuff */
+static void Zerrors ( char *outbuff)
+{
+ int ec;
+ char tmp[MAX_OUT_BUFF];
+ if (!zh)
+ return ;
+ ec=zebra_errCode (zh);
+ if (ec)
+ {
+ sprintf(tmp, "Zebra error %d: %s, (%s) \n",
+ ec, zebra_errString (zh),
+ zebra_errAdd (zh) );
+ strcat(outbuff, tmp);
+ }
+}
+
/**************************************
* The shell
*/
#endif
outbuff[0]='\0';
rc=onecommand(buf, outbuff);
+ Zerrors(outbuff);
printf("%s\n", outbuff);
}