X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=client%2Fadmin.c;h=9022950b3235d3d43ee98a0d30565fdbb01b33a9;hb=49efb9d1b4fc68e075b5121b68922f866f4b330f;hp=e8039285adc5c4b4cddb13b4e81cbf3914c611da;hpb=3b5d9ce6b714e69e96b8c738c4055196cb1f42b4;p=yaz-moved-to-github.git diff --git a/client/admin.c b/client/admin.c index e803928..9022950 100644 --- a/client/admin.c +++ b/client/admin.c @@ -1,6 +1,16 @@ /* * $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 * * @@ -23,18 +33,13 @@ #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) +int sendAdminES(int type, char* dbname, char* param1) { ODR out = getODROutputStream(); @@ -49,6 +54,7 @@ int sendAdminES(int type, char* dbname) 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; @@ -57,8 +63,8 @@ int sendAdminES(int type, char* dbname) 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; @@ -70,54 +76,74 @@ int sendAdminES(int type, char* dbname) 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 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 @@ -125,21 +151,24 @@ int cmd_adm_reindex(char* arg) 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 Create a new database */ int cmd_adm_create(char* arg) { - sendAdminES(4,arg); + if ( arg ) + sendAdminES(Z_ESAdminOriginPartToKeep_create,arg,NULL); } /* cmd_adm_delete Delete a database */ int cmd_adm_delete(char* arg) { - sendAdminES(3,arg); + if ( arg ) + sendAdminES(Z_ESAdminOriginPartToKeep_delete,arg,NULL); } /* cmd_adm_import @@ -148,20 +177,88 @@ int cmd_adm_delete(char* arg) 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); }