From 3b5d9ce6b714e69e96b8c738c4055196cb1f42b4 Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 14 Mar 2000 09:27:07 +0000 Subject: [PATCH] Added code to enable sending of admin extended service requests --- client/Makefile.am | 4 +- client/Makefile.in | 8 +-- client/admin.c | 167 ++++++++++++++++++++++++++++++++++++++++++++++++++++ client/admin.h | 15 +++++ client/client.c | 22 ++++++- 5 files changed, 208 insertions(+), 8 deletions(-) create mode 100644 client/admin.c create mode 100644 client/admin.h diff --git a/client/Makefile.am b/client/Makefile.am index 7b6b45a..484d4d0 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -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 diff --git a/client/Makefile.in b/client/Makefile.in index 1f6afca..b5fbf08 100644 --- a/client/Makefile.in +++ b/client/Makefile.in @@ -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 index 0000000..e803928 --- /dev/null +++ b/client/admin.c @@ -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 +#include +#include + +#include + +#include +#ifdef USE_XTIMOSI +#include +#endif + +#include +#include +#include + +#include + +#ifdef ASN_COMPILED +/* #include */ +#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 + Ask the specified database to fully reindex itself */ +int cmd_adm_reindex(char* arg) +{ + sendAdminES(1,arg); +} + +/* cmd_adm_truncate + 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 + Create a new database */ +int cmd_adm_create(char* arg) +{ + sendAdminES(4,arg); +} + +/* cmd_adm_delete + Delete a database */ +int cmd_adm_delete(char* arg) +{ + sendAdminES(3,arg); +} + +/* cmd_adm_import + 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 index 0000000..ac8faa2 --- /dev/null +++ b/client/admin.h @@ -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); diff --git a/client/client.c b/client/client.c index 91c0740..a113433 100644 --- a/client/client.c +++ b/client/client.c @@ -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 @@ -345,6 +348,8 @@ #include #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, ""}, {"itemorder", cmd_itemorder, "1|2 "}, {"update", cmd_update, ""}, + /* Server Admin Functions */ + {"adm-reindex", cmd_adm_reindex, ""}, + {"adm-truncate", cmd_adm_truncate, "('database'|'index')"}, + {"adm-create", cmd_adm_create, ""}, + {"adm-delete", cmd_adm_delete, "('database'|'index')"}, + {"adm-import", cmd_adm_import, " "}, + {"adm-refresh", cmd_adm_refresh, ""}, + {"adm-commit", cmd_adm_commit, ""}, {0,0} }; char *netbuffer= 0; -- 1.7.10.4