changeset 757:9e5bc0eedd17

Added project names and defaults files (using volume name). Added process id to log file name. Moved temporary files to subdirectory.
author neelin <neelin>
date Tue, 14 Feb 1995 18:12:26 +0000
parents 28ccfb4e2212
children d2e4d51e1772
files conversion/gcomserver/Makefile conversion/gcomserver/gcom_prototypes.h conversion/gcomserver/gcomserver.c conversion/gcomserver/gcomserver.h conversion/gcomserver/gyro_read.c conversion/gcomserver/gyro_to_minc.c conversion/gcomserver/open_connection.c conversion/gcomserver/reply.c conversion/gcomserver/spi_element_defs.h conversion/gcomserver/use_the_files.c
diffstat 10 files changed, 162 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- a/conversion/gcomserver/Makefile
+++ b/conversion/gcomserver/Makefile
@@ -12,7 +12,7 @@
 EXTRA_OBJS = spi_element_defs.o open_connection.o reply.o spi_message.o \
              save_transferred_object.o use_the_files.o \
              gyro_to_minc.o gyro_read.o minc_file.o \
-             string_to_filename.o
+             string_to_filename.o project_file.o
 HEADERS  = gcomserver.h gcom_prototypes.h spi_element_defs.h gyro_to_minc.h
 MANSECT  = 1
 CDEFINES = -DDEBUG#                        cpp defines
--- a/conversion/gcomserver/gcom_prototypes.h
+++ b/conversion/gcomserver/gcom_prototypes.h
@@ -3,7 +3,8 @@
                       Data_Object_Info *file_info_list);
 public void open_connection(int argc, char *argv[], 
                             Acr_File **afpin, Acr_File **afpout);
-public Acr_Message gcbegin_reply(Acr_Message input_message, int *num_files);
+public Acr_Message gcbegin_reply(Acr_Message input_message, int *num_files,
+                                 char **project_name);
 public Acr_Message ready_reply(Acr_Message input_message);
 public Acr_Message send_reply(Acr_Message input_message);
 public Acr_Message gcend_reply(Acr_Message input_message);
@@ -14,7 +15,8 @@
 public void save_transferred_object(Acr_Group group_list, char *file_prefix,
                                     char **new_file_name,
                                     Data_Object_Info *data_info);
-public void use_the_files(int num_files, char *file_list[], 
+public void use_the_files(char *project_name, 
+                          int num_files, char *file_list[], 
                           Data_Object_Info data_info[]);
 public int gyro_to_minc(int num_files, char *file_list[], 
                         char *minc_file, int clobber,
@@ -60,3 +62,9 @@
                             File_Info *file_info, Image_Data *image);
 public void close_minc_file(int icvid);
 public void string_to_filename(char *string, char *filename, int maxlen);
+public int read_project_file(char *project_name, 
+                             char *file_prefix, 
+                             int *output_uid, int *output_gid,
+                             char *command_line, int maxlen_command);
+public void get_project_option_string(char *project_option_string,
+                                      int maxlen_project_option);
--- a/conversion/gcomserver/gcomserver.c
+++ b/conversion/gcomserver/gcomserver.c
@@ -4,9 +4,14 @@
 @GLOBALS    : 
 @CREATED    : November 22, 1993 (Peter Neelin)
 @MODIFIED   : $Log: gcomserver.c,v $
-@MODIFIED   : Revision 2.2  1995-02-09 13:51:26  neelin
-@MODIFIED   : Mods for irix 5 lint.
+@MODIFIED   : Revision 2.3  1995-02-14 18:12:26  neelin
+@MODIFIED   : Added project names and defaults files (using volume name).
+@MODIFIED   : Added process id to log file name.
+@MODIFIED   : Moved temporary files to subdirectory.
 @MODIFIED   :
+ * Revision 2.2  1995/02/09  13:51:26  neelin
+ * Mods for irix 5 lint.
+ *
  * Revision 2.1  1994/10/20  13:48:02  neelin
  * Write out direction cosines to support rotated volumes.
  * Store single slices as 1-slice volumes (3D instead of 2D).
@@ -82,9 +87,12 @@
 ---------------------------------------------------------------------------- */
 
 #ifndef lint
-static char rcsid[]="$Header: /private-cvsroot/minc/conversion/gcomserver/gcomserver.c,v 2.2 1995-02-09 13:51:26 neelin Exp $";
+static char rcsid[]="$Header: /private-cvsroot/minc/conversion/gcomserver/gcomserver.c,v 2.3 1995-02-14 18:12:26 neelin Exp $";
 #endif
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #include <gcomserver.h>
 
 /* Global for minc history */
@@ -130,11 +138,14 @@
    Data_Object_Info *file_info_list;
    int num_files;
    int cur_file;
-   static char file_prefix_string[256] = "gcomserver";
+   static char file_prefix_string[L_tmpnam+1] = "gcomserver";
    char *file_prefix = file_prefix_string;
+   char *temp_dir;
    int continue_looping;
    FILE *fptemp;
    char last_file_name[256];
+   char *project_name = NULL;
+   char logfilename[256];
 
    /* Create minc history string */
    {
@@ -145,7 +156,8 @@
 
    /* Re-open stderr if we are logging */
    if (Do_logging > NO_LOGGING) {
-      (void) freopen("gcomserver.log", "w", stderr);
+      (void) sprintf(logfilename, "gcomserver-%d.log", (int) getpid());
+      (void) freopen(logfilename, "w", stderr);
       setbuf(stderr, NULL);
    }
 
@@ -167,13 +179,15 @@
       clashes */
    if (! Keep_files) {
       (void) tmpnam(file_prefix);
-      fptemp = fopen(file_prefix, "w");
-      if (fptemp == NULL) {
-         (void) fprintf(stderr, "%s: Unable to create temporary file.\n",
+      if (mkdir(file_prefix, (mode_t) 0777)) {
+         (void) fprintf(stderr, 
+            "%s: Unable to create directory for temporary files.\n",
                         pname);
+         perror(pname);
          exit(EXIT_FAILURE);
       }
-      (void) fclose(fptemp);
+      temp_dir = strdup(file_prefix);
+      (void) strcat(file_prefix, "/gyro");
    }
 
    /* Loop while reading messages */
@@ -222,7 +236,12 @@
                state = DISCONNECTING;
                break;
             }
-            output_message = gcbegin_reply(input_message, &num_files);
+            output_message = gcbegin_reply(input_message, &num_files,
+                                           &project_name);
+            if (project_name == NULL) {
+               num_files = 0;
+               break;
+            }
             file_list = MALLOC((size_t) num_files * sizeof(*file_list));
             for (cur_file=0; cur_file < num_files; cur_file++) {
                file_list[cur_file] = NULL;
@@ -282,7 +301,7 @@
             /* Disable input tracing */
             acr_disable_input_trace();
 #endif
-            use_the_files(num_files, file_list, file_info_list);
+            use_the_files(project_name, num_files, file_list, file_info_list);
 #ifdef DO_INPUT_TRACING
    /* Enable input tracing */
             acr_enable_input_trace();
@@ -382,9 +401,10 @@
       num_files = 0;
    }
    
-   /* Remove the file prefix file */
+   /* Remove the file prefix directory */
    if (! Keep_files) {
-      cleanup_files(1, &file_prefix);
+      cleanup_files(1, &temp_dir);
+      FREE(temp_dir);
    }
 
    /* Print final message */
@@ -438,6 +458,9 @@
       }
    }
 
+   /* Free the project_name string */
+   if (project_name != NULL) FREE(project_name);
+
    exit(exit_status);
 
 }
--- a/conversion/gcomserver/gcomserver.h
+++ b/conversion/gcomserver/gcomserver.h
@@ -5,9 +5,14 @@
 @GLOBALS    : 
 @CREATED    : November 23, 1993 (Peter Neelin)
 @MODIFIED   : $Log: gcomserver.h,v $
-@MODIFIED   : Revision 2.0  1994-09-28 10:35:25  neelin
-@MODIFIED   : Release of minc version 0.2
+@MODIFIED   : Revision 2.1  1995-02-14 18:12:26  neelin
+@MODIFIED   : Added project names and defaults files (using volume name).
+@MODIFIED   : Added process id to log file name.
+@MODIFIED   : Moved temporary files to subdirectory.
 @MODIFIED   :
+ * Revision 2.0  1994/09/28  10:35:25  neelin
+ * Release of minc version 0.2
+ *
  * Revision 1.9  94/09/28  10:34:56  neelin
  * Pre-release
  * 
@@ -94,7 +99,8 @@
 #define HIGH_LOGGING 2
 
 /* File containing defaults for gcomserver */
-#define OUTPUT_DEFAULT_FILE "/usr/local/lib/gcomserver."
+#define OUTPUT_DEFAULT_FILE_DIR "/usr/local/lib"
+#define OUTPUT_DEFAULT_FILE_PREFIX "gcomserver."
 
 /* System log file (set to NULL for no logging of error) */
 #define SYSTEM_LOG "/dev/log"
--- a/conversion/gcomserver/gyro_read.c
+++ b/conversion/gcomserver/gyro_read.c
@@ -6,9 +6,14 @@
 @CALLS      : 
 @CREATED    : November 25, 1993 (Peter Neelin)
 @MODIFIED   : $Log: gyro_read.c,v $
-@MODIFIED   : Revision 2.5  1995-02-08 19:31:47  neelin
-@MODIFIED   : Moved ARGSUSED statements for irix 5 lint.
+@MODIFIED   : Revision 2.6  1995-02-14 18:12:26  neelin
+@MODIFIED   : Added project names and defaults files (using volume name).
+@MODIFIED   : Added process id to log file name.
+@MODIFIED   : Moved temporary files to subdirectory.
 @MODIFIED   :
+ * Revision 2.5  1995/02/08  19:31:47  neelin
+ * Moved ARGSUSED statements for irix 5 lint.
+ *
  * Revision 2.4  1994/12/12  09:05:57  neelin
  * Changed comment in calculate_slice_start (code is the same)
  *
@@ -1011,6 +1016,7 @@
 @CREATED    : November 18, 1994 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
+/* ARGSUSED */
 public void calculate_slice_start(World_Index slice_world,
                                   World_Index row_world,
                                   World_Index column_world,
@@ -1019,7 +1025,6 @@
                                   double step[WORLD_NDIMS],
                                   double dircos[WORLD_NDIMS][WORLD_NDIMS],
                                   double start[WORLD_NDIMS])
-     /* ARGSUSED */
 {
    World_Index iworld;
    double offset[WORLD_NDIMS];
--- a/conversion/gcomserver/gyro_to_minc.c
+++ b/conversion/gcomserver/gyro_to_minc.c
@@ -7,9 +7,14 @@
 @CALLS      : 
 @CREATED    : November 25, 1993 (Peter Neelin)
 @MODIFIED   : $Log: gyro_to_minc.c,v $
-@MODIFIED   : Revision 2.2  1995-02-08 19:31:47  neelin
-@MODIFIED   : Moved ARGSUSED statements for irix 5 lint.
+@MODIFIED   : Revision 2.3  1995-02-14 18:12:26  neelin
+@MODIFIED   : Added project names and defaults files (using volume name).
+@MODIFIED   : Added process id to log file name.
+@MODIFIED   : Moved temporary files to subdirectory.
 @MODIFIED   :
+ * Revision 2.2  1995/02/08  19:31:47  neelin
+ * Moved ARGSUSED statements for irix 5 lint.
+ *
  * Revision 2.1  1994/10/20  13:50:12  neelin
  * Write out direction cosines to support rotated volumes.
  * Store single slices as 1-slice volumes (3D instead of 2D).
@@ -195,9 +200,9 @@
 @CREATED    : November 26, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
+/* ARGSUSED */
 public void free_info(General_Info *general_info, File_Info *file_info, 
                       int num_files)
-     /* ARGSUSED */
 {
    Mri_Index imri;
 
--- a/conversion/gcomserver/open_connection.c
+++ b/conversion/gcomserver/open_connection.c
@@ -4,9 +4,14 @@
 @GLOBALS    : 
 @CREATED    : November 22, 1993 (Peter Neelin)
 @MODIFIED   : $Log: open_connection.c,v $
-@MODIFIED   : Revision 2.4  1995-02-09 13:51:26  neelin
-@MODIFIED   : Mods for irix 5 lint.
+@MODIFIED   : Revision 2.5  1995-02-14 18:12:26  neelin
+@MODIFIED   : Added project names and defaults files (using volume name).
+@MODIFIED   : Added process id to log file name.
+@MODIFIED   : Moved temporary files to subdirectory.
 @MODIFIED   :
+ * Revision 2.4  1995/02/09  13:51:26  neelin
+ * Mods for irix 5 lint.
+ *
  * Revision 2.3  1995/02/08  19:31:47  neelin
  * Moved ARGSUSED statements for irix 5 lint.
  *
@@ -143,9 +148,9 @@
 @CREATED    : November 22, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
+/* ARGSUSED */
 public void open_connection(int argc, char *argv[], 
                             Acr_File **afpin, Acr_File **afpout)
-     /* ARGSUSED */
 {
    SessionData sd;
    Io_data *io_data;
@@ -161,7 +166,6 @@
        (maxlength <= 0)) {
       maxlength = DN_MAX_IO;
    }
-   (void) fprintf(stderr, "Maxlength = %d\n", (int) maxlength);
 
    /* Set up input */
    io_data = MALLOC(sizeof(*io_data));
--- a/conversion/gcomserver/reply.c
+++ b/conversion/gcomserver/reply.c
@@ -4,9 +4,14 @@
 @GLOBALS    : 
 @CREATED    : November 22, 1993 (Peter Neelin)
 @MODIFIED   : $Log: reply.c,v $
-@MODIFIED   : Revision 2.0  1994-09-28 10:35:32  neelin
-@MODIFIED   : Release of minc version 0.2
+@MODIFIED   : Revision 2.1  1995-02-14 18:12:26  neelin
+@MODIFIED   : Added project names and defaults files (using volume name).
+@MODIFIED   : Added process id to log file name.
+@MODIFIED   : Moved temporary files to subdirectory.
 @MODIFIED   :
+ * Revision 2.0  1994/09/28  10:35:32  neelin
+ * Release of minc version 0.2
+ *
  * Revision 1.4  94/09/28  10:34:51  neelin
  * Pre-release
  * 
@@ -184,6 +189,7 @@
 @NAME       : gcbegin_reply
 @INPUT      : input_message
 @OUTPUT     : num_files - number of files needed
+              project_name - name to use for project file
 @RETURNS    : output_message
 @DESCRIPTION: Responds to GCBEGINq message
 @METHOD     : 
@@ -192,10 +198,14 @@
 @CREATED    : November 22, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public Acr_Message gcbegin_reply(Acr_Message input_message, int *num_files)
+public Acr_Message gcbegin_reply(Acr_Message input_message, int *num_files,
+                                 char **project_name)
 {
    Acr_Group group, group_list;
    Acr_Element element;
+   char project_option_string[512];
+   void *ptr;
+   int index;
 
    /* Print log message */
    if (Do_logging >= HIGH_LOGGING) {
@@ -203,16 +213,22 @@
       acr_dump_message(stderr, input_message);
    }
 
+   /* Free project_name string if needed */
+   if (*project_name != NULL) FREE(*project_name);
+
    /* Get the group list */
-   group = acr_get_message_group_list(input_message);
+   group_list = acr_get_message_group_list(input_message);
 
    /* Get the number of files */
-   element = acr_find_group_element(group, SPI_Nr_data_objects);
+   element = acr_find_group_element(group_list, SPI_Nr_data_objects);
    if (element != NULL)
       *num_files = acr_get_element_short(element);
    else
       *num_files = 1;
 
+   /* Get the project name from the volume name */
+   *project_name = strdup(acr_find_string(group_list, SPI_Volume_name, ""));
+
    /* Create the reply */
    group_list = spi_reply(input_message);
 
@@ -247,6 +263,50 @@
    acr_group_add_element(group,
       acr_create_element_numeric(SPI_Perc_space_used, (double) 20));
 
+   /* Check that the project file is okay - if not get a string listing 
+      possible project names and send it back */
+   if (read_project_file(*project_name, NULL, NULL, NULL, NULL, 0)) {
+
+      /* Print an error message */
+      (void) fprintf(stderr, "Unknown project \"%s\"\n", *project_name);
+
+      /* Set the project name to NULL as a signal to the caller */
+      FREE(*project_name);
+      *project_name = NULL;
+
+      /* Set an error status */
+      element = acr_find_group_element(group_list, ACR_Status);
+      if (element != NULL) {
+         ptr = acr_get_element_data(element);
+         *((unsigned short *) ptr) = ACR_REFUSED;
+      }
+      element = acr_find_group_element(group_list, SPI_Status);
+      if (element != NULL) {
+         ptr = acr_get_element_data(element);
+         *((long *) ptr) = SPI_MEDIUM_NOT_AVAIL;
+      }
+
+      /* Set a message for the operator */
+      (void) sprintf(project_option_string, 
+                     "Unknown volume, try remote DOR volume: ");
+      index = strlen(project_option_string);
+      get_project_option_string(&project_option_string[index],
+                                sizeof(project_option_string) - index);
+      index = strlen(project_option_string);
+      if ((index % 2) != 0) {
+         project_option_string[index] = ' ';
+         project_option_string[index+1] = '\0';
+      }
+      element = acr_find_group_element(group_list, SPI_Operator_text);
+      if (element != NULL) {
+         ptr = acr_get_element_data(element);
+         if (ptr != NULL) FREE(ptr);
+         acr_set_element_data(element, strlen(project_option_string),
+                              strdup(project_option_string));
+      }
+   }
+
+
    return make_message(group_list);
 
 }
--- a/conversion/gcomserver/spi_element_defs.h
+++ b/conversion/gcomserver/spi_element_defs.h
@@ -157,6 +157,8 @@
 
 /* Define status codes */
 #define ACR_SUCCESS 0x0000
+#define ACR_REFUSED 0xaf00
+#define SPI_MEDIUM_NOT_AVAIL 0xa0000e10
 
 /* Define data object types */
 #define ACR_IMAGE_OBJECT 0x0000
--- a/conversion/gcomserver/use_the_files.c
+++ b/conversion/gcomserver/use_the_files.c
@@ -6,9 +6,14 @@
 @CALLS      : 
 @CREATED    : November 23, 1993 (Peter Neelin)
 @MODIFIED   : $Log: use_the_files.c,v $
-@MODIFIED   : Revision 2.0  1994-09-28 10:35:37  neelin
-@MODIFIED   : Release of minc version 0.2
+@MODIFIED   : Revision 2.1  1995-02-14 18:12:26  neelin
+@MODIFIED   : Added project names and defaults files (using volume name).
+@MODIFIED   : Added process id to log file name.
+@MODIFIED   : Moved temporary files to subdirectory.
 @MODIFIED   :
+ * Revision 2.0  1994/09/28  10:35:37  neelin
+ * Release of minc version 0.2
+ *
  * Revision 1.9  94/09/28  10:34:53  neelin
  * Pre-release
  * 
@@ -70,7 +75,8 @@
 
 /* ----------------------------- MNI Header -----------------------------------
 @NAME       : use_the_files
-@INPUT      : num_files - number of image files
+@INPUT      : project_name - name to use for project file
+              num_files - number of image files
               file_list - list of file names
 @OUTPUT     : (none)
 @RETURNS    : (nothing)
@@ -81,7 +87,8 @@
 @CREATED    : November 23, 1993 (Peter Neelin)
 @MODIFIED   : 
 ---------------------------------------------------------------------------- */
-public void use_the_files(int num_files, char *file_list[], 
+public void use_the_files(char *project_name, 
+                          int num_files, char *file_list[], 
                           Data_Object_Info data_info[])
 {
    int ifile;
@@ -101,32 +108,15 @@
    int exit_status;
    char *output_file_name;
    char file_prefix[256];
-   char output_default_file[256];
-   char hostname[256];
    int output_uid, output_gid;
    char command_line[512];
    char string[512];
    FILE *fp;
-   int index;
 
    /* Look for defaults file */
-   file_prefix[0] = '\0';
-   command_line[0] = '\0';
-   output_uid = output_gid = INT_MIN;
-   (void) gethostname(hostname, sizeof(hostname) - 1);
-   (void) sprintf(output_default_file, "%s%s", 
-                  OUTPUT_DEFAULT_FILE, hostname);
-   if ((fp=fopen(output_default_file, "r")) != NULL) {
-      if (fgets(string, (int) sizeof(string), fp) != NULL) {
-         (void) sscanf(string, "%s %d %d", 
-                       file_prefix, &output_uid, &output_gid);
-      }
-      (void) fgets(command_line, (int) sizeof(command_line), fp);
-      index = strlen(command_line) - 1;
-      if ((index >= 0) && (command_line[index] == '\n'))
-         command_line[index] = '\0';
-      (void) fclose(fp);
-   }
+   (void) read_project_file(project_name, file_prefix, 
+                            &output_uid, &output_gid,
+                            command_line, (int) sizeof(command_line));
 
    /* Allocate space for acquisition file list */
    acq_file_list = MALLOC(num_files * sizeof(*acq_file_list));
@@ -198,7 +188,7 @@
 
          /* Invoke a command on the file (if requested) and get the 
             returned file name */
-         if (strlen(command_line) > 0) {
+         if (strlen(command_line) > (size_t) 0) {
             (void) sprintf(string, "%s %s", command_line, output_file_name);
             if ((fp=popen(string, "r")) != NULL) {
                (void) fscanf(fp, "%s", output_file_name);