+ printf ("not available on WIN32\n");
+ return 0;
+}
+
+#else
+
+int cmd_adm_import(char *arg)
+{
+ char type_str[20], dir_str[1024], pattern_str[1024];
+ char *cp;
+ char *sep = "/";
+ DIR *dir;
+ 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,
+ dir_str, pattern_str) != 3)
+ return 0;
+ if (num_databaseNames != 1)
+ return 0;
+ dir = opendir(dir_str);
+ if (!dir)
+ return 0;
+
+ sendAdminES(Z_ESAdminOriginPartToKeep_import, type_str);
+
+ printf ("sent es request\n");
+ if ((cp=strrchr(dir_str, '/')) && cp[1] == 0)
+ 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 (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 (segment->num_segmentRecords == chunk)
+ {
+ send_apdu (apdu);
+ apdu = 0;
+ }
+ }
+ }
+ }
+ if (apdu)
+ send_apdu(apdu);
+ apdu = zget_APDU(out, Z_APDU_segmentRequest);
+ send_apdu (apdu);
+ closedir(dir);
+ return 2;
+}
+#endif
+
+int cmd_adm_import2(char* arg)
+{
+ /* Buffer for reading chunks of data from import file */
+ char chunk_buffer[8192];
+
+ 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;
+ }
+ return 0;