Added code to enable sending of admin extended service requests
authorian <ian>
Tue, 14 Mar 2000 09:27:07 +0000 (09:27 +0000)
committerian <ian>
Tue, 14 Mar 2000 09:27:07 +0000 (09:27 +0000)
client/Makefile.am
client/Makefile.in
client/admin.c [new file with mode: 0644]
client/admin.h [new file with mode: 0644]
client/client.c

index 7b6b45a..484d4d0 100644 (file)
@@ -1,10 +1,10 @@
 ## Copyright (C) 1995-2000, Index Data
 ## All rights reserved.
-## $Id: Makefile.am,v 1.4 2000-02-29 15:52:33 adam Exp $
+## $Id: Makefile.am,v 1.5 2000-03-14 09:27:07 ian Exp $
 
 bin_PROGRAMS=yaz-client
 
-yaz_client_SOURCES=client.c
+yaz_client_SOURCES=client.c admin.c
 
 LDADD = ../lib/libyaz.a
 
index 1f6afca..b5fbf08 100644 (file)
@@ -70,7 +70,7 @@ VERSION = @VERSION@
 
 bin_PROGRAMS = yaz-client
 
-yaz_client_SOURCES = client.c
+yaz_client_SOURCES = client.c admin.c
 
 LDADD = ../lib/libyaz.a
 
@@ -84,7 +84,7 @@ DEFS = @DEFS@ -I. -I$(srcdir)
 CPPFLAGS = @CPPFLAGS@
 LDFLAGS = @LDFLAGS@
 LIBS = @LIBS@
-yaz_client_OBJECTS =  client.o
+yaz_client_OBJECTS =  client.o admin.o
 yaz_client_LDADD = $(LDADD)
 yaz_client_DEPENDENCIES =  ../lib/libyaz.a
 yaz_client_LDFLAGS = 
@@ -99,7 +99,7 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
 
 TAR = gtar
 GZIP_ENV = --best
-DEP_FILES =  .deps/client.P
+DEP_FILES =  .deps/admin.P .deps/client.P
 SOURCES = $(yaz_client_SOURCES)
 OBJECTS = $(yaz_client_OBJECTS)
 
@@ -201,7 +201,7 @@ distdir: $(DISTFILES)
        @for file in $(DISTFILES); do \
          d=$(srcdir); \
          if test -d $$d/$$file; then \
-           cp -pr $$/$$file $(distdir)/$$file; \
+           cp -pr $$d/$$file $(distdir)/$$file; \
          else \
            test -f $(distdir)/$$file \
            || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
diff --git a/client/admin.c b/client/admin.c
new file mode 100644 (file)
index 0000000..e803928
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * $Log: admin.c,v $
+ * Revision 1.1  2000-03-14 09:27:07  ian
+ * Added code to enable sending of admin extended service requests
+ *
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include <yaz/yaz-util.h>
+
+#include <yaz/tcpip.h>
+#ifdef USE_XTIMOSI
+#include <yaz/xmosi.h>
+#endif
+
+#include <yaz/proto.h>
+#include <yaz/marcdisp.h>
+#include <yaz/diagbib1.h>
+
+#include <yaz/pquery.h>
+
+#ifdef ASN_COMPILED
+/* #include <yaz/esadmin.h> */
+#endif
+
+
+/* Helper functions to get to various statics in the client */
+ODR getODROutputStream();
+void send_apdu(Z_APDU *a);
+
+
+
+int sendAdminES(int type, char* dbname)
+{
+    ODR out = getODROutputStream();
+
+    /* Type: 1=reindex, 2=truncate, 3=delete, 4=create, 5=import, 6=refresh, 7=commit */
+    Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest );
+    Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
+    Z_External *r;
+    int oid[OID_SIZE];
+    Z_ESAdminOriginPartToKeep  *toKeep;
+    Z_ESAdminOriginPartNotToKeep  *notToKeep;
+    oident update_oid;
+    printf ("Admin request\n");
+    fflush(stdout);
+
+    update_oid.proto = PROTO_Z3950;
+    update_oid.oclass = CLASS_EXTSERV;
+    update_oid.value = VAL_ADMINSERVICE;
+
+    oid_ent_to_oid (&update_oid, oid);
+    req->packageType = odr_oiddup(out,oid);
+    req->packageName = "1.Extendedserveq";
+
+    r = req->taskSpecificParameters = (Z_External *)
+       odr_malloc (out, sizeof(*r));
+    r->direct_reference = odr_oiddup(out,oid);
+    r->indirect_reference = 0;
+    r->descriptor = 0;
+    r->which = Z_External_ESAdmin;
+    r->u.adminService = (Z_Admin *) odr_malloc(out, sizeof(*r->u.adminService));
+    r->u.adminService->which = Z_Admin_esRequest;
+    r->u.adminService->u.esRequest = (Z_AdminEsRequest *) odr_malloc(out, sizeof(*r->u.adminService->u.esRequest));
+
+    toKeep = r->u.adminService->u.esRequest->toKeep = (Z_ESAdminOriginPartToKeep *) 
+                     odr_malloc(out, sizeof(*r->u.adminService->u.esRequest->toKeep));
+
+    switch ( type )
+    {
+        case 1:
+            toKeep->which=Z_ESAdminOriginPartToKeep_reIndex;
+           toKeep->u.reIndex=NULL;
+           break;
+       case 2:
+            toKeep->which=Z_ESAdminOriginPartToKeep_truncate;
+           toKeep->u.truncate=NULL;
+           break;
+       case 3:
+            toKeep->which=Z_ESAdminOriginPartToKeep_delete;
+           toKeep->u.delete=NULL;
+           break;
+       case 4:
+            toKeep->which=Z_ESAdminOriginPartToKeep_create;
+           toKeep->u.create=NULL;
+           break;
+        case 5:
+            toKeep->which=Z_ESAdminOriginPartToKeep_import;
+           toKeep->u.import=NULL;
+           break;
+        case 6:
+            toKeep->which=Z_ESAdminOriginPartToKeep_refresh;
+           toKeep->u.refresh=NULL;
+           break;
+        case 7:
+            toKeep->which=Z_ESAdminOriginPartToKeep_commit;
+           toKeep->u.commit=NULL;
+           break;
+    }
+
+
+    notToKeep = r->u.adminService->u.esRequest->notToKeep = (Z_ESAdminOriginPartNotToKeep *)
+       odr_malloc(out, sizeof(*r->u.adminService->u.esRequest->notToKeep));
+    notToKeep->which=Z_ESAdminOriginPartNotToKeep_recordsWillFollow;
+    notToKeep->u.recordsWillFollow=NULL;
+    
+    send_apdu(apdu);
+
+    return 2;
+}
+
+/* cmd_adm_reindex <dbname>
+   Ask the specified database to fully reindex itself */
+int cmd_adm_reindex(char* arg)
+{
+    sendAdminES(1,arg);
+}
+
+/* cmd_adm_truncate <dbname>
+   Truncate the specified database, removing all records and index entries, but leaving 
+   the database & it's explain information intact ready for new records */
+int cmd_adm_truncate(char* arg)
+{
+    sendAdminES(2,arg);
+}
+
+/* cmd_adm_create <dbname>
+   Create a new database */
+int cmd_adm_create(char* arg)
+{
+    sendAdminES(4,arg);
+}
+
+/* cmd_adm_delete <dbname>
+   Delete a database */
+int cmd_adm_delete(char* arg)
+{
+    sendAdminES(3,arg);
+}
+
+/* cmd_adm_import <dbname> <rectype> <sourcefile>
+   Import the specified updated into the database
+   N.B. That in this case, the import may contain instructions to delete records as well as new or updates
+   to existing records */
+int cmd_adm_import(char* arg)
+{
+    sendAdminES(5,arg);
+}
+
+/* "Freshen" the specified database, by checking metadata records against the sources from which they were 
+   generated, and creating a new record if the source has been touched since the last extraction */
+int cmd_adm_refresh(char* arg)
+{
+    sendAdminES(6,arg);
+}
+
+/* cmd_adm_commit 
+   Make imported records a permenant & visible to the live system */
+int cmd_adm_commit(char* arg)
+{
+    sendAdminES(7,NULL);
+}
+
diff --git a/client/admin.h b/client/admin.h
new file mode 100644 (file)
index 0000000..ac8faa2
--- /dev/null
@@ -0,0 +1,15 @@
+/*
+ * $Log: admin.h,v $
+ * Revision 1.1  2000-03-14 09:27:07  ian
+ * Added code to enable sending of admin extended service requests
+ *
+ *
+ */
+
+int cmd_adm_reindex(char* arg);
+int cmd_adm_truncate(char* arg);
+int cmd_adm_create(char* arg);
+int cmd_adm_delete(char* arg);
+int cmd_adm_import(char* arg);
+int cmd_adm_refresh(char* arg);
+int cmd_adm_commit(char* arg);
index 91c0740..a113433 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: client.c,v $
- * Revision 1.95  2000-02-28 11:20:05  adam
+ * Revision 1.96  2000-03-14 09:27:07  ian
+ * Added code to enable sending of admin extended service requests
+ *
+ * Revision 1.95  2000/02/28 11:20:05  adam
  * Using autoconf. New definitions: YAZ_BEGIN_CDECL/YAZ_END_CDECL.
  *
  * Revision 1.94  2000/01/31 13:15:21  adam
 #include <readline/history.h>
 #endif
 
+#include "admin.h"
+
 #define C_PROMPT "Z> "
 
 static ODR out, in, print;              /* encoding and decoding streams */
@@ -383,7 +388,12 @@ static QueryType queryType = QueryType_Prefix;
 static CCL_bibset bibset;               /* CCL bibset handle */
 #endif
 
-static void send_apdu(Z_APDU *a)
+ODR getODROutputStream()
+{
+    return out;
+}
+
+void send_apdu(Z_APDU *a)
 {
     char *buf;
     int len;
@@ -2251,6 +2261,14 @@ static int client(int wait)
        {"refid", cmd_refid, "<id>"},
        {"itemorder", cmd_itemorder, "1|2 <item>"},
        {"update", cmd_update, "<item>"},
+       /* Server Admin Functions */
+       {"adm-reindex", cmd_adm_reindex, "<database-name>"},
+       {"adm-truncate", cmd_adm_truncate, "('database'|'index')<object-name>"},
+       {"adm-create", cmd_adm_create, "<database-name>"},
+       {"adm-delete", cmd_adm_delete, "('database'|'index')<object-name>"},
+       {"adm-import", cmd_adm_import, "<database-name> <record-type> <source-file-name>"},
+       {"adm-refresh", cmd_adm_refresh, "<database-name>"},
+       {"adm-commit", cmd_adm_commit, ""},
         {0,0}
     };
     char *netbuffer= 0;