/*
- * Copyright (c) 1995-2003, Index Data
+ * Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: admin.c,v 1.16 2003-03-11 11:07:47 adam Exp $
+ * $Id: admin.c,v 1.26 2007-05-08 08:22:35 adam Exp $
*/
#include <stdio.h>
#include <time.h>
#include <assert.h>
-#if HAVE_FNMATCH_H
+#if HAVE_DIRENT_H
#include <dirent.h>
+#endif
+#if HAVE_FNMATCH_H
#include <fnmatch.h>
+#endif
+#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#include <yaz/proto.h>
#include <yaz/marcdisp.h>
#include <yaz/diagbib1.h>
-
+#include <yaz/oid_db.h>
#include <yaz/pquery.h>
#include "admin.h"
/* Helper functions to get to various statics in the client */
-ODR getODROutputStream();
+ODR getODROutputStream(void);
extern char *databaseNames[];
extern int num_databaseNames;
Z_APDU *apdu = zget_APDU(out, Z_APDU_extendedServicesRequest );
Z_ExtendedServicesRequest *req = apdu->u.extendedServicesRequest;
Z_External *r;
- int oid[OID_SIZE];
+ Odr_oid *oid;
Z_ESAdminOriginPartToKeep *toKeep;
Z_ESAdminOriginPartNotToKeep *notToKeep;
- oident update_oid;
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;
+ oid = odr_oiddup(out, yaz_oid_extserv_admin);
- oid_ent_to_oid (&update_oid, oid);
- req->packageType = odr_oiddup(out,oid);
+ req->packageType = oid;
req->packageName = "1.Extendedserveq";
/* Allocate the external */
switch ( type )
{
case Z_ESAdminOriginPartToKeep_reIndex:
- toKeep->u.reIndex=odr_nullval();
- break;
-
+ toKeep->u.reIndex=odr_nullval();
+ break;
+
case Z_ESAdminOriginPartToKeep_truncate:
- toKeep->u.truncate=odr_nullval();
- break;
+ toKeep->u.truncate=odr_nullval();
+ break;
case Z_ESAdminOriginPartToKeep_drop:
- toKeep->u.drop=odr_nullval();
- break;
+ toKeep->u.drop=odr_nullval();
+ break;
case Z_ESAdminOriginPartToKeep_create:
- toKeep->u.create=odr_nullval();
- break;
+ toKeep->u.create=odr_nullval();
+ break;
case Z_ESAdminOriginPartToKeep_import:
- toKeep->u.import = (Z_ImportParameters*)
+ 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;
+ toKeep->u.import->recordType=param1;
+ /* Need to add additional setup of records here */
+ break;
case Z_ESAdminOriginPartToKeep_refresh:
- toKeep->u.refresh=odr_nullval();
- break;
+ toKeep->u.refresh=odr_nullval();
+ break;
case Z_ESAdminOriginPartToKeep_commit:
- toKeep->u.commit=odr_nullval();
- break;
+ toKeep->u.commit=odr_nullval();
+ break;
case Z_ESAdminOriginPartToKeep_shutdown:
- toKeep->u.commit=odr_nullval();
- break;
+ toKeep->u.commit=odr_nullval();
+ break;
case Z_ESAdminOriginPartToKeep_start:
- toKeep->u.commit=odr_nullval();
- break;
+ toKeep->u.commit=odr_nullval();
+ break;
default:
- /* Unknown admin service */
- break;
+ /* Unknown admin service */
+ break;
}
notToKeep = r->u.adminService->u.esRequest->notToKeep =
- (Z_ESAdminOriginPartNotToKeep *)
- odr_malloc(out, sizeof(*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=odr_nullval();
if ( arg )
{
sendAdminES(Z_ESAdminOriginPartToKeep_truncate, NULL);
- return 2;
+ return 2;
}
return 0;
}
if ( arg )
{
sendAdminES(Z_ESAdminOriginPartToKeep_create, NULL);
- return 2;
+ return 2;
}
return 0;
}
if ( arg )
{
sendAdminES(Z_ESAdminOriginPartToKeep_drop, NULL);
- return 2;
+ return 2;
}
return 0;
}
ODR out = getODROutputStream();
if (arg && sscanf (arg, "%19s %1023s %1023s", type_str,
- dir_str, pattern_str) != 3)
- return 0;
+ dir_str, pattern_str) != 3)
+ return 0;
if (num_databaseNames != 1)
- return 0;
+ return 0;
dir = opendir(dir_str);
if (!dir)
- return 0;
+ return 0;
sendAdminES(Z_ESAdminOriginPartToKeep_import, type_str);
printf ("sent es request\n");
if ((cp=strrchr(dir_str, '/')) && cp[1] == 0)
- sep="";
-
+ sep="";
+
while ((ent = readdir(dir)))
{
- if (fnmatch (pattern_str, ent->d_name, 0) == 0)
- {
- char fname[1024];
- struct stat status;
- FILE *inf;
-
- sprintf (fname, "%s%s%s", dir_str, sep, ent->d_name);
- stat (fname, &status);
+ if (fnmatch (pattern_str, ent->d_name, 0) == 0)
+ {
+ char fname[1024];
+ struct stat status;
+ FILE *inf;
+
+ sprintf (fname, "%s%s%s", dir_str, sep, ent->d_name);
+ stat (fname, &status);
- if (S_ISREG(status.st_mode) && (inf = fopen(fname, "r")))
- {
- Z_NamePlusRecord *rec;
- Odr_oct *oct = (Odr_oct *) odr_malloc (out, sizeof(*oct));
+ if (S_ISREG(status.st_mode) && (inf = fopen(fname, "r")))
+ {
+ Z_NamePlusRecord *rec;
+ Odr_oct *oct = (Odr_oct *) odr_malloc (out, sizeof(*oct));
- if (!apdu)
- {
- apdu = zget_APDU(out, Z_APDU_segmentRequest);
- segment = apdu->u.segmentRequest;
- segment->segmentRecords = (Z_NamePlusRecord **)
- odr_malloc (out, chunk * sizeof(*segment->segmentRecords));
- }
- rec = (Z_NamePlusRecord *) odr_malloc (out, sizeof(*rec));
- rec->databaseName = 0;
- rec->which = Z_NamePlusRecord_intermediateFragment;
- rec->u.intermediateFragment = (Z_FragmentSyntax *)
- odr_malloc (out, sizeof(*rec->u.intermediateFragment));
- rec->u.intermediateFragment->which =
- Z_FragmentSyntax_notExternallyTagged;
- rec->u.intermediateFragment->u.notExternallyTagged = oct;
-
- oct->len = oct->size = status.st_size;
- oct->buf = (unsigned char *) odr_malloc (out, oct->size);
- fread (oct->buf, 1, oct->size, inf);
- fclose (inf);
-
- segment->segmentRecords[segment->num_segmentRecords++] = rec;
+ if (!apdu)
+ {
+ apdu = zget_APDU(out, Z_APDU_segmentRequest);
+ segment = apdu->u.segmentRequest;
+ segment->segmentRecords = (Z_NamePlusRecord **)
+ odr_malloc (out, chunk * sizeof(*segment->segmentRecords));
+ }
+ rec = (Z_NamePlusRecord *) odr_malloc (out, sizeof(*rec));
+ rec->databaseName = 0;
+ rec->which = Z_NamePlusRecord_intermediateFragment;
+ rec->u.intermediateFragment = (Z_FragmentSyntax *)
+ odr_malloc (out, sizeof(*rec->u.intermediateFragment));
+ rec->u.intermediateFragment->which =
+ Z_FragmentSyntax_notExternallyTagged;
+ rec->u.intermediateFragment->u.notExternallyTagged = oct;
+
+ oct->len = oct->size = status.st_size;
+ oct->buf = (unsigned char *) odr_malloc (out, oct->size);
+ fread (oct->buf, 1, oct->size, inf);
+ fclose (inf);
+
+ segment->segmentRecords[segment->num_segmentRecords++] = rec;
- if (segment->num_segmentRecords == chunk)
- {
- send_apdu (apdu);
- apdu = 0;
- }
- }
- }
+ if (segment->num_segmentRecords == chunk)
+ {
+ send_apdu (apdu);
+ apdu = 0;
+ }
+ }
+ }
}
if (apdu)
- send_apdu(apdu);
+ send_apdu(apdu);
apdu = zget_APDU(out, Z_APDU_segmentRequest);
send_apdu (apdu);
closedir(dir);
return 2;
}
#else
-int cmd_adm_import(char *arg)
+int cmd_adm_import(const char *arg)
{
printf ("not available on WIN32\n");
return 0;
if ( arg )
{
sendAdminES(Z_ESAdminOriginPartToKeep_refresh, NULL);
- return 2;
+ return 2;
}
return 0;
}
sendAdminES(Z_ESAdminOriginPartToKeep_start, NULL);
return 2;
}
-
/*
* Local variables:
- * tab-width: 8
* c-basic-offset: 4
+ * indent-tabs-mode: nil
* End:
- * vim600: sw=4 ts=8 fdm=marker
- * vim<600: sw=4 ts=8
+ * vim: shiftwidth=4 tabstop=8 expandtab
*/
+