* amd/sun_map.c (sun_entry2amd) : Wipe out any trailing white
authorDaniel Ottavio <ottavio@fsl.cs.sunysb.edu>
Mon, 29 Aug 2005 03:24:25 +0000 (03:24 +0000)
committerDaniel Ottavio <ottavio@fsl.cs.sunysb.edu>
Mon, 29 Aug 2005 03:24:25 +0000 (03:24 +0000)
spaces or 'n' before passing strings to the parser.

ChangeLog
amd/amd.h
amd/info_file.c
amd/mapc.c
amd/sun_map.c
amd/sun_map_parse.y

index 286eac514374e8018bbea9627dfa21fa82103470..e98a6167185817eb1704a783fdd6462dcf47b898 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-08-28  Daniel P. Ottavio  <dottavio@ic.sunysb.edu>
+
+       * amd/sun_map.c (sun_entry2amd) : Wipe out any trailing white
+       spaces or '\n' before passing strings to the parser.
+       
 2005-08-27  Erez Zadok  <ezk@cs.sunysb.edu>
 
        * libamu/xutil.c: amd_program_number is a u_long now.
index 8967323c014e22764382a23b5d94550312835454..b2b891502c824961323226350c8dd7986d9e0911 100644 (file)
--- a/amd/amd.h
+++ b/amd/amd.h
@@ -351,6 +351,7 @@ struct mnt_map {
   kv *kvhash[NKVHASH];          /* Cached data */
   cf_map_t *cfm;               /* pointer to per-map amd.conf opts, if any */
   void *map_data;               /* Map data black box */
+  mnt_map *include;             /* list of included maps */            
 };
 
 /*
@@ -572,6 +573,7 @@ extern int  background(void);
 extern void deslashify(char *);
 extern void do_task_notify(void);
 extern int  eval_fs_opts(am_opts *, char *, char *, char *, char *, char *);
+extern char **file_search_include(char *);
 extern int  file_read_line(char *, int, FILE *);
 extern void forcibly_timeout_mp(am_node *);
 extern void free_map(am_node *);
index c672509349862f938f1f478455709029f2a0388a..44cd5e28bca7f50f25aa2482641acbe001369f9e 100644 (file)
 #include <sun_map.h>
 
 
+/* max number of include lines a map file can have */
+#define MAX_INCLUDE_LINES   16
+
+
 /* forward declarations */
 int file_init_or_mtime(mnt_map *m, char *map, time_t *tp);
 int file_reload(mnt_map *m, char *map, void (*fn) (mnt_map *, char *, char *));
 int file_search(mnt_map *m, char *map, char *key, char **pval, time_t *tp);
+static FILE *file_open(char *map, time_t *tp);
 
 
 int
@@ -90,6 +95,55 @@ file_read_line(char *buf, int size, FILE *fp)
   return done;
 }
 
+char **
+file_search_include(char *map) {
+  
+  char line_buff[INFO_MAX_LINE_LEN];
+  FILE *mapf = NULL;
+  char **retval = NULL, *tmp;
+  int count = 0;
+  size_t len = 0;
+
+  if ((mapf = fopen(map, "r")) == NULL) {
+    plog(XLOG_ERROR, "could not read file %s", map);
+    goto err;
+  }
+  
+  len = MAX_INCLUDE_LINES * sizeof(char*);
+  retval = (char **)xmalloc(len);
+  memset(retval, 0, len);
+  
+  memset(line_buff, 0, sizeof(line_buff));  
+  
+  while ((len = file_read_line(line_buff, sizeof(line_buff), mapf)) > 0) {
+    if (line_buff[0] == '+') {
+      if(count <= MAX_INCLUDE_LINES) {
+       tmp = &line_buff[1];
+       if(*tmp) {
+         /* remove any trailing white spaces and '\n' */
+         int ws = strlen(tmp) - 1;
+         while (ws >= 0 && (isspace(tmp[ws]) || tmp[ws] == '\n')) {
+           tmp[ws--] = '\0';
+         } 
+         
+         retval[count++] = strdup(tmp);
+       }
+      }
+      else {
+       plog(XLOG_WARNING, "too many include lines in map %s", map);
+      }
+    }
+    memset(line_buff, 0, sizeof(line_buff));
+  }
+  
+  if(count == 0) {
+    /* If there are no include lines, pass back NULL */
+    XFREE(retval);
+  }
+  
+ err:
+  return retval;
+}
 
 /*
  * Try to locate a key in a file
@@ -160,6 +214,7 @@ file_search_or_reload(mnt_map *m,
         * Return a copy of the data
         */
        char *dc;
+       printf("key :%s\n", kp);
        if (m->cfm->cfm_flags & CFM_SUN_MAP_SYNTAX)
          dc = sun_entry2amd(kp, cp);
        else
index 206287c4727b73fc7137d972d69e49d6a8bb2bed..51557876a8659b4d29d83cdc57541f3210cc4c7f 100644 (file)
@@ -541,6 +541,16 @@ search_map(mnt_map *m, char *key, char **valp)
       plog(XLOG_MAP, "Re-synchronizing cache for map %s", m->map_name);
       mapc_sync(m);
     }
+    if (rc < 0) {
+      /* Try to search any included maps. */
+      mnt_map *inc;
+      for (inc = m->include; inc != NULL; inc = NEXT(mnt_map, inc)) {
+       rc = (*inc->search) (m, m->map_name, key, valp, &m->modify);
+       if (rc > 0) {
+         break;
+       }
+      }
+    }
   } while (rc < 0);
 
   return rc;
@@ -575,7 +585,7 @@ mapc_reload_map(mnt_map *m)
   int error;
   kv *maphash[NKVHASH], *tmphash[NKVHASH];
   time_t t;
-
+  
   error = (*m->mtime) (m, m->map_name, &t);
   if (error) {
     t = m->modify;
@@ -1001,6 +1011,35 @@ mapc_sync(mnt_map *m)
        */
       mapc_find_wildcard(m);
     }
+
+    if (strchr(m->map_name, (int)'/') != NULL) {
+      /*
+       * Look for include lines in the map file.  If the map name
+       * contains a '/' than we assume that it is a file map type.
+       */
+      char **include;
+      int k;
+      
+      /* serch for a list of include lines */
+      include = file_search_include(m->map_name);
+      if (include != NULL) {
+       /* 
+        * For each include line create a mnt_map and add it to the
+        * list of included maps.
+        */
+       mnt_map *map;
+       for (k = 0; include[k] != NULL; k++) {
+         map = mapc_create(include[k], 
+                           "mapdefault", 
+                           "file", 
+                           m->cfm->cfm_dir);
+         /* Add the new map to the list of included maps. */
+         ((qelem *)map)->q_forw = (qelem *)(m->include);
+         m->include = map;
+       }
+       XFREE(include);
+      } 
+    }
   }
 }
 
index 8c1d69d32dbd592e912b0d3277f6d26bbe2be7c9..d71d41cc8115e37dea28dc16155c0e6522e57e1b 100644 (file)
@@ -516,6 +516,7 @@ sun_entry2amd(const char *key, const char *s_entry_str)
 {
   char *retval = NULL;
   char line_buff[INFO_MAX_LINE_LEN];
+  int ws;
   struct sun_entry *s_entry = NULL;
 
   /* For now the key should no be NULL. */
@@ -528,9 +529,16 @@ sun_entry2amd(const char *key, const char *s_entry_str)
     plog(XLOG_ERROR,"Sun entry value was null");
     goto err;
   }
-
+  
+  /* Make sure there are no trailing white spaces or '\n'. */
+  xstrlcpy(line_buff, s_entry_str, sizeof(line_buff));
+  ws = strlen(line_buff) - 1;
+  while (ws >= 0 && (isspace(line_buff[ws]) || line_buff[ws] == '\n')) {
+    line_buff[ws--] = '\0';
+  }
+  
   /* Parse the sun entry line. */
-  s_entry = sun_map_parse_read(s_entry_str);
+  s_entry = sun_map_parse_read(line_buff);
   if (s_entry == NULL) {
     plog(XLOG_ERROR,"could not parse Sun style map");
     goto err;
index 2ee7a8aef9ad3e1fcbe56de22b97118a2fdc102d..0ec34125b9ed3a2c797e0451a63f29a78b1acb2d 100644 (file)
@@ -219,6 +219,9 @@ entry : locations {
   /* Add this entry to the entry list. */
   sun_list_add(get_sun_entry_list(), (qelem *)entry);
 }
+
+/* We need to allow include lines, but we do not handle them here. */
+| '+' WORD
 ;
 
 mountpoints : mountpoint