+#####
+# Usage: &getChanConfList($param)
+# About: gets channels with 'param' enabled, internal use only.
+# Return: hash of channels
+sub getChanConfList {
+ my $param = $_[0];
+ my %chan;
+
+ return unless (defined $param);
+
+ foreach (keys %chanconf) {
+ my $chan = $_;
+ my @array = grep /^$param$/, keys %{ $chanconf{$chan} };
+ #&DEBUG("gCCL param => $param, chan => $chan, keys => " . join(':',keys %{ $chanconf{$chan} }) . " array => " . join(':', @array)) if ($param eq 'whatever');
+
+ next unless (scalar @array);
+
+ if (scalar @array > 1) {
+ &WARN("multiple items found?");
+ }
+
+ if ($chanconf{$chan}{$param} eq "0") {
+ $chan{$chan} = -1;
+ } else {
+ $chan{$chan} = 1;
+ }
+ }
+
+ return %chan;
+}
+
+#####
+# Usage: &IsChanConf($param);
+# About: Check for 'param' on the basis of channel config.
+# Return: 1 for enabled, 0 for passive disable, -1 for active disable.
+sub IsChanConf {
+ my($param) = shift;
+
+ # knocked tons of bugs with this! :)
+ my $debug = 0; # 1 if ($param eq "whatever");
+
+ if (!defined $param) {
+ &WARN("IsChanConf: param == NULL.");
+ return 0;
+ }
+
+ # these should get moved to your .chan file instead of the .config
+ # .config items overide any .chan entries
+ if (&IsParam($param)) {
+ &WARN("ICC: found '$param' option in main config file.");
+ return 1;
+ }
+
+ $chan ||= "_default";
+
+ my $old = $chan;
+ if ($chan =~ tr/A-Z/a-z/) {
+ &WARN("IsChanConf: lowercased chan. ($old)");
+ }
+
+ ### TODO: VERBOSITY on how chanconf returned 1 or 0 or -1.
+ my %chan = &getChanConfList($param);
+ my $nomatch = 0;
+ if (!defined $msgType) {
+ $nomatch++;
+ } else {
+ $nomatch++ if ($msgType eq "");
+ $nomatch++ unless ($msgType =~ /^(public|private)$/i);
+ }
+
+### debug purposes only.
+# if ($debug) {
+# &DEBUG("param => $param, msgType => $msgType.");
+# foreach (keys %chan) {
+# &DEBUG(" $_ => $chan{$_}");
+# }
+# }
+
+ if ($nomatch) {
+ if ($chan{$chan}) {
+ &DEBUG("ICC: other: $chan{$chan} (_default/$param)") if ($debug);
+ } elsif ($chan{_default}) {
+ &DEBUG("ICC: other: $chan{_default} (_default/$param)") if ($debug);
+ } else {
+ &DEBUG("ICC: other: 0 ($param)") if ($debug);
+ }
+ return $chan{$chan} || $chan{_default} || 0;
+ } elsif ($msgType =~ /^(public|private)$/i) {
+ if ($chan{$chan}) {
+ &DEBUG("ICC: $msgType: $chan{$chan} ($chan/$param)") if ($debug);
+ } elsif ($chan{_default}) {
+ &DEBUG("ICC: $msgType: $chan{_default} (_default/$param)") if ($debug);
+ } else {
+ &DEBUG("ICC: $msgType: 0 ($param)") if ($debug);
+ }
+ return $chan{$chan} || $chan{_default} || 0;
+ }
+
+ &DEBUG("ICC: no-match: 0/$param (msgType = $msgType)");
+
+ return 0;
+}
+
+#####
+# Usage: &getChanConf($param);
+# About: Retrieve value for 'param' value in current/default chan.
+# Return: scalar for success, undef for failure.
+sub getChanConf {
+ my($param,$c) = @_;
+
+ if (!defined $param) {
+ &WARN("gCC: param == NULL.");
+ return 0;
+ }
+
+ # this looks evil...
+ if (0 and !defined $chan) {
+ &DEBUG("gCC: ok !chan... doing _default instead.");
+ }
+
+ $c ||= $chan;
+ $c ||= "_default";
+ $c = "_default" if ($c eq "*"); # FIXME
+ my @c = grep /^\Q$c\E$/i, keys %chanconf;
+
+ if (@c) {
+ if (0 and $c[0] ne $c) {
+ &WARN("c ne chan ($c[0] ne $chan)");
+ }
+ if (!defined $chanconf{$c[0]}{$param} and ($c ne '_default')) {
+ return &getChanConf($param, '_default');
+ }
+ #&DEBUG("gCC: $param,$c \"" . $chanconf{$c[0]}{$param} . '"');
+ return $chanconf{$c[0]}{$param};