/*
* $Log: admin.c,v $
- * Revision 1.1 2000-03-14 09:27:07 ian
+ * Revision 1.4 2000-03-16 13:55:49 ian
+ * Added commands for sending shutdown and startup admin requests via the admin ES.
+ *
+ * Revision 1.3 2000/03/14 15:23:17 ian
+ * Removed unwanted ifdef and include of zes-admin.h
+ *
+ * Revision 1.2 2000/03/14 14:06:04 ian
+ * Minor change to order of debugging output for send_apdu,
+ * fixed encoding of admin request.
+ *
+ * Revision 1.1 2000/03/14 09:27:07 ian
* Added code to enable sending of admin extended service requests
*
*
#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)
+int sendAdminES(int type, char* dbname, char* param1)
{
ODR out = getODROutputStream();
printf ("Admin request\n");
fflush(stdout);
+ /* Set up the OID for the external */
update_oid.proto = PROTO_Z3950;
update_oid.oclass = CLASS_EXTSERV;
update_oid.value = VAL_ADMINSERVICE;
req->packageType = odr_oiddup(out,oid);
req->packageName = "1.Extendedserveq";
- r = req->taskSpecificParameters = (Z_External *)
- odr_malloc (out, sizeof(*r));
+ /* Allocate the external */
+ r = req->taskSpecificParameters = (Z_External *) odr_malloc (out, sizeof(*r));
r->direct_reference = odr_oiddup(out,oid);
r->indirect_reference = 0;
r->descriptor = 0;
toKeep = r->u.adminService->u.esRequest->toKeep = (Z_ESAdminOriginPartToKeep *)
odr_malloc(out, sizeof(*r->u.adminService->u.esRequest->toKeep));
+ toKeep->which=type;
+
switch ( type )
{
- case 1:
- toKeep->which=Z_ESAdminOriginPartToKeep_reIndex;
- toKeep->u.reIndex=NULL;
+ case Z_ESAdminOriginPartToKeep_reIndex:
+ toKeep->u.reIndex=odr_nullval();
+ toKeep->databaseName = dbname;
break;
- case 2:
- toKeep->which=Z_ESAdminOriginPartToKeep_truncate;
- toKeep->u.truncate=NULL;
+
+ case Z_ESAdminOriginPartToKeep_truncate:
+ toKeep->u.truncate=odr_nullval();
+ toKeep->databaseName = dbname;
break;
- case 3:
- toKeep->which=Z_ESAdminOriginPartToKeep_delete;
- toKeep->u.delete=NULL;
+
+ case Z_ESAdminOriginPartToKeep_delete:
+ toKeep->u.delete=odr_nullval();
+ toKeep->databaseName = dbname;
break;
- case 4:
- toKeep->which=Z_ESAdminOriginPartToKeep_create;
- toKeep->u.create=NULL;
+
+ case Z_ESAdminOriginPartToKeep_create:
+ toKeep->u.create=odr_nullval();
+ toKeep->databaseName = dbname;
break;
- case 5:
- toKeep->which=Z_ESAdminOriginPartToKeep_import;
- toKeep->u.import=NULL;
+
+ case Z_ESAdminOriginPartToKeep_import:
+ toKeep->u.import = (Z_ImportParameters*)odr_malloc(out, sizeof(*toKeep->u.import));
+ toKeep->u.import->recordType=param1;
+ toKeep->databaseName = dbname;
+ /* Need to add additional setup of records here */
break;
- case 6:
- toKeep->which=Z_ESAdminOriginPartToKeep_refresh;
- toKeep->u.refresh=NULL;
+
+ case Z_ESAdminOriginPartToKeep_refresh:
+ toKeep->u.refresh=odr_nullval();
+ toKeep->databaseName = dbname;
break;
- case 7:
- toKeep->which=Z_ESAdminOriginPartToKeep_commit;
- toKeep->u.commit=NULL;
+
+ case Z_ESAdminOriginPartToKeep_commit:
+ toKeep->u.commit=odr_nullval();
break;
- }
+ case Z_ESAdminOriginPartToKeep_shutdown:
+ toKeep->u.commit=odr_nullval();
+ break;
+
+ case Z_ESAdminOriginPartToKeep_start:
+ toKeep->u.commit=odr_nullval();
+ break;
+
+ default:
+ /* Unknown admin service */
+ 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;
+ notToKeep->u.recordsWillFollow=odr_nullval();
send_apdu(apdu);
- return 2;
+ return 0;
}
/* cmd_adm_reindex <dbname>
Ask the specified database to fully reindex itself */
int cmd_adm_reindex(char* arg)
{
- sendAdminES(1,arg);
+ sendAdminES(Z_ESAdminOriginPartToKeep_reIndex,arg,NULL);
}
/* cmd_adm_truncate <dbname>
the database & it's explain information intact ready for new records */
int cmd_adm_truncate(char* arg)
{
- sendAdminES(2,arg);
+ if ( arg )
+ sendAdminES(Z_ESAdminOriginPartToKeep_truncate,arg,NULL);
}
/* cmd_adm_create <dbname>
Create a new database */
int cmd_adm_create(char* arg)
{
- sendAdminES(4,arg);
+ if ( arg )
+ sendAdminES(Z_ESAdminOriginPartToKeep_create,arg,NULL);
}
/* cmd_adm_delete <dbname>
Delete a database */
int cmd_adm_delete(char* arg)
{
- sendAdminES(3,arg);
+ if ( arg )
+ sendAdminES(Z_ESAdminOriginPartToKeep_delete,arg,NULL);
}
/* cmd_adm_import <dbname> <rectype> <sourcefile>
to existing records */
int cmd_adm_import(char* arg)
{
- sendAdminES(5,arg);
+ /* Size of chunks we wish to read from import file */
+ size_t chunk_size = 8192;
+
+ /* Buffer for reading chunks of data from import file */
+ char chunk_buffer[chunk_size];
+
+ if ( arg )
+ {
+ char dbname_buff[32];
+ char rectype_buff[32];
+ char filename_buff[32];
+ FILE* pImportFile = NULL;
+
+ if (sscanf (arg, "%s %s %s", dbname_buff, rectype_buff, filename_buff) != 3)
+ {
+ printf("Must specify database-name, record-type and filename for import\n");
+ return 0;
+ }
+
+ /* Attempt to open the file */
+
+ pImportFile = fopen(filename_buff,"r");
+
+ /* This chunk of code should move into client.c sometime soon for sending files via the update es */
+ /* This function will then refer to the standard client.c one for uploading a file using es update */
+ if ( pImportFile )
+ {
+ int iTotalWritten = 0;
+
+ /* We opened the import file without problems... So no we send the es request, ready to
+ start sending fragments of the import file as segment messages */
+ sendAdminES(Z_ESAdminOriginPartToKeep_import,arg,rectype_buff);
+
+ while ( ! feof(pImportFile ) )
+ {
+ /* Read buffer_size bytes from the file */
+ size_t num_items = fread((void*)chunk_buffer, 1, sizeof(chunk_buffer), pImportFile);
+
+ /* Write num_bytes of data to */
+
+ if ( feof(pImportFile ) )
+ {
+ /* This is the last chunk... Write it as the last fragment */
+ printf("Last segment of %d bytes\n", num_items);
+ }
+ else if ( iTotalWritten == 0 )
+ {
+ printf("First segment of %d bytes\n",num_items);
+ }
+ else
+ {
+ printf("Writing %d bytes\n", num_items);
+ }
+
+ iTotalWritten += num_items;
+ }
+ }
+ }
}
/* "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);
+ if ( arg )
+ sendAdminES(Z_ESAdminOriginPartToKeep_refresh,arg,NULL);
}
/* cmd_adm_commit
Make imported records a permenant & visible to the live system */
int cmd_adm_commit(char* arg)
{
- sendAdminES(7,NULL);
+ sendAdminES(Z_ESAdminOriginPartToKeep_commit,NULL,NULL);
+}
+
+int cmd_adm_shutdown(char* arg)
+{
+ sendAdminES(Z_ESAdminOriginPartToKeep_shutdown,NULL,NULL);
+}
+
+int cmd_adm_startup(char* arg)
+{
+ sendAdminES(Z_ESAdminOriginPartToKeep_start,NULL,NULL);
}