[Asterisk-cvs] asterisk-addons/res_perl/INC AstAPIBase.pm, 1.2,
1.3 AstConfig.pm, 1.1, 1.2
anthm at lists.digium.com
anthm at lists.digium.com
Wed Feb 9 09:51:00 CST 2005
Update of /usr/cvsroot/asterisk-addons/res_perl/INC
In directory mongoose.digium.com:/tmp/cvs-serv25523/INC
Modified Files:
AstAPIBase.pm AstConfig.pm
Log Message:
minor updates
Index: AstAPIBase.pm
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/res_perl/INC/AstAPIBase.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- AstAPIBase.pm 15 Nov 2004 14:29:21 -0000 1.2
+++ AstAPIBase.pm 9 Feb 2005 15:51:15 -0000 1.3
@@ -71,6 +71,7 @@
*asterisk_soft_hangup = *AstAPIBasec::asterisk_soft_hangup;
*asterisk_hangup = *AstAPIBasec::asterisk_hangup;
*asterisk_setcallerid = *AstAPIBasec::asterisk_setcallerid;
+*asterisk_getcallerid = *AstAPIBasec::asterisk_getcallerid;
*asterisk_channelstatus = *AstAPIBasec::asterisk_channelstatus;
*asterisk_setvariable = *AstAPIBasec::asterisk_setvariable;
*asterisk_getvariable = *AstAPIBasec::asterisk_getvariable;
Index: AstConfig.pm
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/res_perl/INC/AstConfig.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- AstConfig.pm 24 Sep 2004 21:44:07 -0000 1.1
+++ AstConfig.pm 9 Feb 2005 15:51:15 -0000 1.2
@@ -1,5 +1,6 @@
package AstConfig;
use strict;
+use Data::Dumper;
sub _create_new_cat($) {
my $name = shift;
@@ -15,20 +16,78 @@
sub init(;) {
my $proto = shift;
my $class = ref($proto) || $proto;
- my $self = [];
+ my $self = { entries => [] };
bless ($self, $class);
}
+sub render($;$) {
+ my($self) = shift;
+ my $out = shift || *STDOUT;
+ select $out;
+ print ";OK;\n\n";
+ foreach my $cat (@{$self->{entries}}) {
+ next if($cat->{prune});
+ print "[$cat->{name}]\n";
+ foreach my $var (@{$cat->{vars}}) {
+ if($var) {
+ print "$var->{var} => $var->{val}\n";
+ }
+ }
+ print "\n";
+ }
+
+}
+
+sub render_sql($;$$) {
+ my($self) = shift;
+ my $out = shift || *STDOUT;
+ my $file = shift || "asterisk_config.conf";
+ my $table = shift || "asterisk";
+ my $sql_a = shift;
+ my $sql_b = shift;
+
+ select $out;
+ my $cm = -1;
+ foreach my $cat (@{$self->{entries}}) {
+ $cm++;
+ next if($cat->{prune});
+ if($sql_a) {
+ my $sql = $sql_a;
+ $sql =~ s/\%table/$table/g;
+ $sql =~ s/\%cat_name/$cat->{name}/g;
+ print $sql;
+ }
+
+ my $vm = -1;
+ foreach my $var (@{$cat->{vars}}) {
+ if($var) {
+ $vm++;
+ if($sql_b) {
+ my $sql = $sql_b;
+ $sql =~ s/\%table/$table/g;
+ $sql =~ s/\%cat_name/$cat->{name}/g;
+ $sql =~ s/\%var_name/$var->{var}/g;
+ $sql =~ s/\%var_val/$var->{val}/g;
+ print $sql;
+ }
+ print "insert into $table values(null,$cm,$vm,0,'$file','$cat->{name}','$var->{var}','$var->{val}');\n";
+ }
+ }
+ }
+
+}
+
+
sub return_data($) {
my($self) = @_;
- return @{$self};
+ return @{$self->{entries}};
}
sub get_cat($$) {
my($self,$cat_name) = @_;
- foreach(@{$self}) {
+ foreach(@{$self->{entries}}) {
if($_->{name} eq $cat_name) {
return $_;
}
@@ -41,22 +100,91 @@
my $self = shift;
my $cat_name = shift;
my $cat = _create_new_cat($cat_name);
- push @{$self},$cat;
+ push @{$self->{entries}},$cat;
return $cat;
}
-sub add_var($$$$;$) {
- my($self,$cat_name,$var,$val,$pop) = @_;
+sub add_var($$$$) {
+ my($self,$cat_name,$var,$val) = @_;
my $cat = $self->get_cat($cat_name);
unless($cat) {
$cat = $self->add_cat($cat_name);
}
- pop @{$cat->{vars}} if($pop);
push @{$cat->{vars}},{var => $var, val => $val};
}
+sub del_cat($$) {
+ my($self,$cat_name) = @_;
+ my $cat = $self->get_cat($cat_name);
+ if($cat) {
+ $cat->{prune} = 1;
+ }
+}
+
+sub prune($) {
+ my($self) = shift;
+ my $old = $self->{entries};
+ $self->{entries} = [];
+ foreach my $cat (@{$old}) {
+ unless($cat->{prune}) {
+ push @{$self->{entries}},$cat;
+ }
+ }
+
+}
+
+sub save_raw($$) {
+ my($self,$file) = @_;
+ $self->prune;
+ open O, ">$file";
+ print O Dumper $self->{entries};
+ close O;
+}
+
+sub load_raw($$) {
+ my($self,$file) = @_;
+ open I, $file;
+ my $VAR1;
+ $/ = undef;
+ eval <I>;
+ $self->{entries} = $VAR1;
+ close I;
+ $/ = "\n";
+}
+
+sub save_conf($$) {
+ my($self,$file) = @_;
+ $self->prune;
+ open O, ">$file";
+ $self->render(*O);
+ close O;
+}
+
+sub save_sql($$$$;$$) {
+ my($self,$file,$filename,$tablename,$sql_a,$sql_b) = @_;
+ $self->prune;
+ open O, ">$file";
+ $self->render_sql(*O,$filename,$tablename,$sql_a,$sql_b);
+ close O;
+}
+
+sub load_conf($$) {
+ my($self,$file) = @_;
+ open I, "$file";
+ my $cat_name = undef;
+ while(<I>) {
+ if(/\[([^\]]+)\]/) {
+ $cat_name = $1;
+ } else {
+ if($cat_name and /^\s*([^\s\=]+)\s*\=\>{0,1}\s*(\S+)/) {
+ $self->add_var($cat_name,$1,$2);
+ }
+ }
+ }
+ close (I);
+}
1;
More information about the svn-commits
mailing list