| 1 | # |
| 2 | # "Flamethrower" |
| 3 | # |
| 4 | # Copyright (C) 2002 Bald Guy Software |
| 5 | # Brian Elliott Finley <[email protected]> |
| 6 | # |
| 7 | # $Id: Flamethrower.pm 24 2003-06-29 01:04:22Z brianfinley $ |
| 8 | # |
| 9 | |
| 10 | package Flamethrower; |
| 11 | |
| 12 | ################################################################################ |
| 13 | # |
| 14 | # Subroutines in this module include: |
| 15 | # |
| 16 | # process_modules |
| 17 | # read_config |
| 18 | # which |
| 19 | # |
| 20 | # |
| 21 | ################################################################################ |
| 22 | |
| 23 | use strict; |
| 24 | use AppConfig qw(:argcount :expand); |
| 25 | |
| 26 | my $VERSION = 'INS_VERSION'; |
| 27 | |
| 28 | my $ft_config = AppConfig->new(); |
| 29 | |
| 30 | # Usage: Flamethrower->read_config($file); |
| 31 | sub read_config { |
| 32 | |
| 33 | my ($class, $file) = (@_); |
| 34 | |
| 35 | my $ft_config = AppConfig->new( |
| 36 | |
| 37 | { |
| 38 | CREATE => 1, |
| 39 | GLOBAL => { |
| 40 | ARGCOUNT => ARGCOUNT_ONE, |
| 41 | DEFAULT => '', |
| 42 | EXPAND => EXPAND_VAR, |
| 43 | }, |
| 44 | }, |
| 45 | |
| 46 | # No need to define any variables here, unless we come up with one |
| 47 | # that has attributes, such as ARGCOUNT, that are different from |
| 48 | # the GLOBAL default. |
| 49 | # |
| 50 | # Ie: |
| 51 | #'my_other_var' => { ARGCOUNT => 2 }, |
| 52 | |
| 53 | 'modules' => { ARGCOUNT => ARGCOUNT_LIST }, |
| 54 | |
| 55 | 'start_flamethrower_daemon' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 56 | 'flamethrower_directory_portbase' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 57 | 'flamethrower_directory_dir' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 58 | 'flamethrower_state_dir' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 59 | 'min_clients' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 60 | 'max_wait' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 61 | 'min_wait' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 62 | 'async' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 63 | 'autostart' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 64 | 'blocksize' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 65 | 'broadcast' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 66 | 'fec' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 67 | 'interface' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 68 | 'log' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 69 | 'max_bitrate' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 70 | 'full_duplex' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 71 | 'mcast_addr' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 72 | 'mcast_all_addr' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 73 | 'min_slice_size' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 74 | 'slice_size' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 75 | 'pointopoint' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 76 | 'rexmit_hello_interval' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 77 | 'ttl' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 78 | 'nosync' => { ARGCOUNT => ARGCOUNT_ONE }, |
| 79 | |
| 80 | ); |
| 81 | |
| 82 | $ft_config->file($file); |
| 83 | |
| 84 | # |
| 85 | # Get a list of specified modules (don't know how to make appconfig give |
| 86 | # us this.) |
| 87 | # |
| 88 | open(FILE, "<$file") or die("Couldn't open $file"); |
| 89 | while (<FILE>) { |
| 90 | if (m/^[[:space:]]*\[.*\][[:space:]]*$/) { |
| 91 | s/[[:space:]]+//g; |
| 92 | s/\[//g; |
| 93 | s/\]//g; |
| 94 | $ft_config->modules($_); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | # |
| 99 | # Be sure to include the flamethrower_directory in the list. |
| 100 | # This allows us to make the buid_command subroutine more |
| 101 | # generic, as $ft_config->get(${module}_dir) will work for |
| 102 | # flamethrower_directory as well as all the "normal" modules. |
| 103 | # |
| 104 | $ft_config->modules('flamethrower_directory'); |
| 105 | |
| 106 | close(FILE); |
| 107 | |
| 108 | $::main::ft_config = $ft_config; |
| 109 | } |
| 110 | |
| 111 | ## A pure perl which command |
| 112 | # example: SystemImager::Common->which($file,$ENV{PATH}) || croak "$file not found in your path."; |
| 113 | sub which { |
| 114 | my ($class, $file, $path) = @_; |
| 115 | |
| 116 | foreach my $dir (split(/:/,$path)) { |
| 117 | if(-x "$dir/$file") { |
| 118 | return 1; |
| 119 | } |
| 120 | } |
| 121 | return 0; |
| 122 | } |
| 123 |