X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=client%2Fadmin.c;h=4f96bce1006f73db2ee3aa45e450c7b1c5044263;hb=e12377e7ea8e58cf447492b5cb9887b839a78700;hp=4e6834811690f1bc846488c73e70b5e3b99347f1;hpb=7acd51b7cdffca5ad92a777d2c6e8e9bae1f9fd3;p=yaz-moved-to-github.git diff --git a/client/admin.c b/client/admin.c index 4e68348..4f96bce 100644 --- a/client/admin.c +++ b/client/admin.c @@ -1,43 +1,24 @@ /* - * $Log: admin.c,v $ - * Revision 1.7 2000-04-05 07:39:54 adam - * Added shared library support (libtool). - * - * Revision 1.6 2000/03/20 19:06:25 adam - * Added Segment request for fronend server. Work on admin for client. - * - * Revision 1.5 2000/03/17 12:47:02 adam - * Minor changes to admin client. - * - * 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 - * + * Copyright (c) 1995-2003, Index Data + * See the file LICENSE for details. * + * $Id: admin.c,v 1.15 2003-01-06 08:20:26 adam Exp $ */ #include #include #include #include + +#if HAVE_FNMATCH_H #include #include #include +#endif + #include #include -#ifdef USE_XTIMOSI -#include -#endif #include #include @@ -45,11 +26,10 @@ #include -#ifdef ASN_COMPILED +#include "admin.h" /* Helper functions to get to various statics in the client */ ODR getODROutputStream(); -void send_apdu(Z_APDU *a); extern char *databaseNames[]; extern int num_databaseNames; @@ -58,7 +38,7 @@ int sendAdminES(int type, char* param1) { ODR out = getODROutputStream(); char *dbname = odr_strdup (out, databaseNames[0]); - + /* 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; @@ -80,18 +60,22 @@ int sendAdminES(int type, char* param1) req->packageName = "1.Extendedserveq"; /* Allocate the external */ - r = req->taskSpecificParameters = (Z_External *) odr_malloc (out, sizeof(*r)); + 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 = (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)); - + 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)); + toKeep->which=type; toKeep->databaseName = dbname; switch ( type ) @@ -110,7 +94,8 @@ int sendAdminES(int type, char* param1) toKeep->u.create=odr_nullval(); break; case Z_ESAdminOriginPartToKeep_import: - toKeep->u.import = (Z_ImportParameters*)odr_malloc(out, sizeof(*toKeep->u.import)); + toKeep->u.import = (Z_ImportParameters*) + odr_malloc(out, sizeof(*toKeep->u.import)); toKeep->u.import->recordType=param1; /* Need to add additional setup of records here */ break; @@ -130,7 +115,7 @@ int sendAdminES(int type, char* param1) /* Unknown admin service */ break; } - + notToKeep = r->u.adminService->u.esRequest->notToKeep = (Z_ESAdminOriginPartNotToKeep *) odr_malloc(out, sizeof(*r->u.adminService->u.esRequest->notToKeep)); @@ -192,6 +177,7 @@ int cmd_adm_drop(char* arg) N.B. That in this case, the import may contain instructions to delete records as well as new or updates to existing records */ +#if HAVE_FNMATCH_H int cmd_adm_import(char *arg) { char type_str[20], dir_str[1024], pattern_str[1024]; @@ -201,6 +187,7 @@ int cmd_adm_import(char *arg) struct dirent *ent; int chunk = 10; Z_APDU *apdu = 0; + Z_Segment *segment = 0; ODR out = getODROutputStream(); if (arg && sscanf (arg, "%19s %1023s %1023s", type_str, @@ -213,7 +200,7 @@ int cmd_adm_import(char *arg) return 0; sendAdminES(Z_ESAdminOriginPartToKeep_import, type_str); - + printf ("sent es request\n"); if ((cp=strrchr(dir_str, '/')) && cp[1] == 0) sep=""; @@ -231,9 +218,8 @@ int cmd_adm_import(char *arg) if (S_ISREG(status.st_mode) && (inf = fopen(fname, "r"))) { - Z_Segment *segment; Z_NamePlusRecord *rec; - Odr_oct *oct = odr_malloc (out, sizeof(*oct)); + Odr_oct *oct = (Odr_oct *) odr_malloc (out, sizeof(*oct)); if (!apdu) { @@ -252,7 +238,7 @@ int cmd_adm_import(char *arg) rec->u.intermediateFragment->u.notExternallyTagged = oct; oct->len = oct->size = status.st_size; - oct->buf = odr_malloc (out, oct->size); + oct->buf = (unsigned char *) odr_malloc (out, oct->size); fread (oct->buf, 1, oct->size, inf); fclose (inf); @@ -273,69 +259,14 @@ int cmd_adm_import(char *arg) closedir(dir); return 2; } - -int cmd_adm_import2(char* arg) +#else +int cmd_adm_import(char *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 rectype_buff[32]; - char filename_buff[32]; - FILE* pImportFile = NULL; - - if (sscanf (arg, "%s %s", 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, 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; - } - } - return 2; - } + printf ("not available on WIN32\n"); return 0; } +#endif + /* "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 */ @@ -368,4 +299,12 @@ int cmd_adm_startup(char* arg) sendAdminES(Z_ESAdminOriginPartToKeep_start, NULL); return 2; } -#endif + +/* + * Local variables: + * tab-width: 8 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=8 fdm=marker + * vim<600: sw=4 ts=8 + */