ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationManagerServant.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationManagerServant.java (file contents):
Revision 1.8 by ajm, Thu Mar 1 19:18:38 2001 UTC vs.
Revision 1.15 by ajm, Sat Mar 3 14:52:56 2001 UTC

# Line 4 | Line 4 | package uk.ac.ukc.iscream.core;
4   //---IMPORTS---
5   import uk.ac.ukc.iscream.util.*;
6   import uk.ac.ukc.iscream.componentmanager.*;
7 + import java.net.InetAddress;
8 + import java.net.UnknownHostException;
9   import java.util.*;
10   import java.io.*;
11  
# Line 91 | Line 93 | class ConfigurationManagerServant extends Configuratio
93  
94          // search config for group membership
95          LinkedList groups = getGroupMembership(source);
96 +        
97 +        // if we are dealing with a Host.<hostname> request, then we also
98 +        // want to look for ip address details, as configuration entries may relate to it
99 +        // if we can't resolve it, we don't look.
100 +        if (source.startsWith("Host.")) {
101 +            // hostname is after Host.
102 +            String hostname = source.substring(5);
103 +            try {
104 +                String ip = "Host." + InetAddress.getByName(hostname).getHostAddress();
105 +                LinkedList ipGroups = getGroupMembership(ip);
106 +                groups.addFirst(ip);
107 +                groups.addAll(ipGroups);
108 +            } catch (UnknownHostException e) {
109 +                _logger.write(toString(), Logger.ERROR, "could not resolve hostname - " + hostname);
110 +            }
111 +        }
112  
113          // add the hosts individual config to the start of the list
114          groups.addFirst(source);
# Line 99 | Line 117 | class ConfigurationManagerServant extends Configuratio
117          String fileList = "";
118          while (i.hasNext()) {
119              String groupName = (String) i.next();
120 <
120 >            _logger.write(toString(), Logger.DEBUG, "looking for config entry for - " + groupName);
121              // we look for this entry in the systemConfig
122              String configFile = _systemConfig.getProperty("config." + groupName);
123 <            _logger.write(toString(), Logger.DEBUG, "looking for config tree in - " + configFile);
124 <
125 <            // get the file list of includes etc + the system config
126 <            try {
127 <                fileList += getIncludedFiles(configFile, "");
128 <            } catch (Exception e) {
129 <                // not sure what to do here
130 <                // so we just log the error
131 <                _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage());
123 >            // if there is a config entry then
124 >            if (configFile != null) {
125 >                _logger.write(toString(), Logger.DEBUG, "looking for config tree in - " + configFile);
126 >    
127 >                // get the file list of includes etc + the system config
128 >                String groupFileList = null;
129 >                try {
130 >                    groupFileList = getIncludedFiles(configFile, "") + ";";
131 >                } catch (Exception e) {
132 >                    // not sure what to do here
133 >                    // so we just log the error
134 >                    _logger.write(toString(), Logger.ERROR, "ERROR - " + e);
135 >                }
136 >                if (groupFileList != null) {
137 >                    fileList += groupFileList;
138 >                }
139 >            } else {
140 >                _logger.write(toString(), Logger.DEBUG, "no config entry for - " + groupName);
141              }
142          }
143          // add the system config as the final check
144 <        fileList += _systemConfigFile + ";";
144 >        fileList = _systemConfigFile + ";" + fileList;
145          _logger.write(toString(), Logger.DEBUG, "config tree - " + fileList);
146          
147          // build the configuration
# Line 272 | Line 299 | class ConfigurationManagerServant extends Configuratio
299       * @return the list of groups that this source is a member of
300       */
301      private LinkedList getGroupMembership(String source) {
302 +        _logger.write(toString(), Logger.DEBUG, "searching group members for - " + source);
303          LinkedList groupMembership = new LinkedList();        
304          Iterator i = new TreeSet(_systemConfigHolder.keySet()).iterator();
305          while(i.hasNext()) {
306              String key = (String) i.next();
307              if (key.startsWith("group.")) {
308                  String group = _systemConfig.getProperty(key);
309 +                // if it is in the group
310                  if (group.indexOf(source) != -1) {
311                      groupMembership.add(key.substring(6));
312 +                
313 +                // if there are wildcards in the group
314 +                } else if (group.indexOf("*") != -1) {
315 +                    // check the wildcards apply to this srce
316 +                    if( wildcardCheck(source, group)) {
317 +                        groupMembership.add(key.substring(6));
318 +                    }
319                  }
320 +                
321              }  
322          }
323          return groupMembership;
324      }    
325  
326      /**
327 +     * Checks that a given string is not matched within the
328 +     * given list of strings. eg:<br>
329 +     * <br>
330 +     * Given "stue5de.ukc.ac.uk"<br>
331 +     * And   "raptor.ukc.ac.uk;stue*.ukc.ac.uk<br>
332 +     * <br>
333 +     * This method would return true as there is a match
334 +     *
335 +     * @param source the string to look for
336 +     * @param group the group to search for a wilcard entry
337 +     *
338 +     * @return if there is a match
339 +     */
340 +    private boolean wildcardCheck(String source, String group) {
341 +        boolean foundMatch = false;
342 +        StringTokenizer st = new StringTokenizer(group, ";");
343 +        // go through all the hosts in the group
344 +        while (st.hasMoreTokens()) {
345 +            String host = st.nextToken();
346 +            // this host has wildcards
347 +            if(host.indexOf("*") != -1) {
348 +                StringTokenizer hostst = new StringTokenizer(host, "*");
349 +                String part = "";
350 +                int index = 0;
351 +                // the first token will be everything at the start
352 +                // unless it starts with a wildcard
353 +                if(!host.startsWith("*")) {
354 +                    part = hostst.nextToken();
355 +                    if (source.startsWith(part)) {
356 +                        foundMatch = true;
357 +                        index = part.length();
358 +                    }
359 +                // all of the start of the string is matched
360 +                } else {
361 +                    foundMatch = true;
362 +                }
363 +                // if the start matched, we want to check the rest...
364 +                if (foundMatch) {
365 +                    while (hostst.hasMoreTokens()) {
366 +                        part = hostst.nextToken();
367 +                        // if the next section can't be matched
368 +                        // then this isn't in the source
369 +                        if(source.substring(index).indexOf(part) == -1) {
370 +                            foundMatch = false;
371 +                            // we don't want to look through any more of it
372 +                            break;
373 +                        } else {
374 +                            foundMatch = true;
375 +                            index += source.substring(index).indexOf(part) + part.length();
376 +                        }
377 +                    }
378 +                    // if we reach here and we've found a match
379 +                    // we want to check that the last part
380 +                    // of the wildcard string is the last part
381 +                    // of the source, if it is, we break out
382 +                    // and finish as we've found a match.
383 +                    // if the end of the wildcard is a *, then
384 +                    // we don't care
385 +                    if (!host.endsWith("*") && foundMatch) {
386 +                        if ((source.endsWith(part))) {
387 +                            _logger.write(toString(), Logger.DEBUG, "wildcard match found for - " + source + " in - " + host);
388 +                            break;
389 +                        // if there is no match, say so so we go round again
390 +                        } else {
391 +                            foundMatch = false;
392 +                        }
393 +                    } else if (foundMatch) {
394 +                        _logger.write(toString(), Logger.DEBUG, "wildcard match found for - " + source + " in - " + host);
395 +                        break;
396 +                    }
397 +                }
398 +            }
399 +        }
400 +        return foundMatch;
401 +    }
402 +
403 +
404 +    /**
405       * Build the properties as a Configuration to be
406       * returned to the caller
407       *
# Line 298 | Line 413 | class ConfigurationManagerServant extends Configuratio
413          Configuration config = null;
414  
415          // if there is an entry
416 <        if (fileList != null) {
416 >        if (!fileList.equals("")) {
417              try {
418                  
419                  // build the properites here from the filelist....
# Line 306 | Line 421 | class ConfigurationManagerServant extends Configuratio
421                  
422                  // some holders for variables
423                  File currentFile;
424 <                long lastModified, newLastModified;
425 <                Properties properties, prevProperties;
424 >                long lastModified = 0, newLastModified = 0;
425 >                Properties properties = null, prevProperties = null;
426                  
427                  // the root of all configurations will be the system config
428                  // so we need to open the properties of that
429                  Properties defaultProperties = new Properties();
315                currentFile = new File(_configPath, _systemConfigFile);
316                lastModified = currentFile.lastModified();
317                defaultProperties.load(new FileInputStream(currentFile));
430                  
431                  // This loop then iterates over the file list
432                  // creates the properties to be passed to the
433                  // Configuration constructor
434 <                do {
434 >                while (st.hasMoreTokens()) {
435                      properties = new Properties(defaultProperties);
436                      currentFile = new File(_configPath, st.nextToken());
437                      newLastModified = currentFile.lastModified();
# Line 328 | Line 440 | class ConfigurationManagerServant extends Configuratio
440                      }
441                      properties.load(new FileInputStream(currentFile));
442                      defaultProperties = properties;
443 <                } while (st.hasMoreTokens());
443 >                }
444  
445                  // this creates the configuration, all nice, ready to be returned
446                  ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified);
447                  org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref);
448                  config = ConfigurationHelper.narrow(objRef);
449 <
449 >                _logger.write(toString(), Logger.DEBUG, "returning built configuration");
450              } catch (Exception e) {
451                  // not sure what to do here
452                  // so we just log the error
453 <                _logger.write(toString(), Logger.ERROR, "ERROR - " + e.getMessage());
453 >                _logger.write(toString(), Logger.ERROR, "ERROR - " + e);
454              }
455              
456          // if there isn't an entry for the requested config

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines