⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 config.pm

📁 Astercon2 开源软交换 2.2.0
💻 PM
📖 第 1 页 / 共 2 页
字号:
			} elsif ($one_case->{'section'} eq $section_name & $one_case->{'point'} eq 'down') {				push(@NEW,$one_line);	$one_line=&format_convert($one_case->{'data'});		$auto_save=1;			# for foot 发现匹配的section			} elsif ($one_case->{'section'} eq $section_name & $one_case->{'point'} eq 'foot') {				$save_tmpmem=1;			# for foot 发现要从匹配的section换成新section			} elsif ($save_tmpmem == 1 && $section_name && $one_case->{'section'} ne $section_name) {				push(@NEW,&format_convert($one_case->{'data'}));	$auto_save=1;	$save_tmpmem=0;			# for foot 发现匹配的section已经到达整个结尾			} 			if ($save_tmpmem == 1 && $offset==$#{$data}) {				push(@NEW,$one_line);	$one_line=&format_convert($one_case->{'data'});				$auto_save=1;	$save_tmpmem=0;			}			push(@NEW,$one_line);			$offset++;		}	} else {		my $last_section_name='[unsection]';	#当前是默认的section		my $auto_save=0;		foreach my $one_line (@$data) {			#tune on auto save			if ($auto_save) {			push(@NEW,$one_line);			next;		}			my $line_sp=&clean_string($one_line);			#检查当前是不是进入了新的section			if ($line_sp =~ /^\[(.+)\]/) {				$last_section_name = $1;			} elsif ($last_section_name eq $one_case->{'section'} & $line_sp =~ /\=/) {				#split data and key				my ($key,$value)=&clean_keyvalue($line_sp);				if ($key eq $one_case->{comkey}[0] & $value eq $one_case->{comkey}[1] & $one_case->{'point'} eq 'up') {					push(@NEW,&format_convert($one_case->{'data'}));	$auto_save=1;				} elsif ($key eq $one_case->{comkey}[0] & $value eq $one_case->{comkey}[1] & $one_case->{'point'} eq 'down') {#0.7-					push(@NEW,$one_line);	push(@NEW,&format_convert($one_case->{'data'}));#0.7-					$one_line=undef;		$auto_save=1;					push(@NEW,$one_line);	$one_line=&format_convert($one_case->{'data'});					$auto_save=1;				} elsif ($key eq $one_case->{comkey}[0] & $value eq $one_case->{comkey}[1] & $one_case->{'point'} eq 'over') {#0.7-					push(@NEW,&format_convert($one_case->{'data'}));#0.7-					$one_line=undef;		$auto_save=1;					$one_line=&format_convert($one_case->{'data'});		$auto_save=1;				}			}			push(@NEW,$one_line) #0.7-	if ($one_line);		}	}return(\@NEW);}sub do_delsection {	my $one_case = shift;	my $data = shift;	my @NEW;	my $last_section_name='[unsection]';	#当前是默认的section	my $auto_save=0;	push(@NEW,&format_convert($one_case->{'data'})) if ($one_case->{'section'} eq '[unsection]' and $one_case->{'action'} eq 'replacesection');	foreach my $one_line (@$data) {		#tune on auto save		if ($auto_save) {			push(@NEW,$one_line);			next;		}		my $line_sp=&clean_string($one_line);		if ($last_section_name eq $one_case->{'section'} & $line_sp =~ /^\[(.+)\]/) {			#when end of compared section and come new different section			$auto_save = 1;		} elsif ($last_section_name eq $one_case->{'section'}) {			next;		} elsif ($line_sp =~ /^\[(.+)\]/) {			#is this new section?			if ($one_case->{'section'} eq $1) {				$last_section_name = $1;				next if ($one_case->{'action'} eq 'delsection');				push(@NEW,$one_line);#0.7-				push(@NEW,&format_convert($one_case->{'data'}));#0.7-				$one_line=undef;				$one_line=&format_convert($one_case->{'data'});			}		}		push(@NEW,$one_line);	}return(\@NEW);}sub do_addsection {	my $one_case = shift;	my $data = shift;	my $exists = 0;	my $section = '[' . $one_case->{section} . ']';		foreach my $one_line(@$data) {		my $line_sp=&clean_string($one_line);		if($line_sp =~ /^\[.+\]/) {			if ($section eq $line_sp) {				$exists = 1;				last;			}		}	}	unless($exists) {		push(@$data, $section);	}	return $data;}sub do_editkey {	my $one_case = shift;	my $data = shift;	my @NEW;	my $last_section_name='[unsection]';	#当前是默认的section	my $auto_save=0;	foreach my $one_line (@$data) {		#tune on auto save		if ($auto_save) {			push(@NEW,$one_line);			next;		}		my $line_sp=&clean_string($one_line);		#检查当前是不是进入了新的section		if ($line_sp =~ /^\[(.+)\]/) {			$last_section_name = $1;		} elsif ($last_section_name eq $one_case->{section} & $line_sp =~ /\=/) {			#split data and key			my ($key,$value)=&clean_keyvalue($line_sp);			if ($key eq $one_case->{'key'} && !$one_case->{'value'}) {			#处理全部匹配的key的value值				$one_line = "$key=".$one_case->{'new_value'};				undef($one_line) if ($one_case->{'action'} eq 'delkey');			} elsif ($key eq $one_case->{'key'} && $one_case->{'value'} eq $value) {	#处理唯一匹配的key的value值				$one_line = "$key=".$one_case->{'new_value'};				undef($one_line) if ($one_case->{'action'} eq 'delkey');				$auto_save = 1;			}		}		push(@NEW,$one_line) if ($one_line);	}return(\@NEW);}=head1 NAMEAsterisk::config - the Asterisk config read and write module.=head1 SYNOPSIS	use Asterisk::config;	my $rc = new Asterisk::config;	my ($ref_hash,$ref_array,$ref_hashchunk) = $rc->load_config(filename=>[configfile],stream_data=>[strings]);	print $ref_hash->{'[unsection]'}{'test'}[0];	print $ref_hash->{'[global]'}{'allow'}[1];	$rc->assign_append(point=>'down',data=>$user_data);	$rc->save_file(filename=>[filename],resource=>$ref_array);=head1 DESCRIPTIONAsterisk::config know how Asterisk config difference with standard ini config. this moudle make interface for read andwrite Asterisk config files and Asterisk extension configs.=head1 NOTEplease use = instand of => in your config files.=head1 METHOD=head2 new	my $rc = new Asterisk::config;Instantiates a new object.=head2 load_config	$rc->(filename=>[configfile],stream_data=>[strings]);load config from file or from stream data.=over 2=item * configfile -> config file path and name.=item * stream_data -> instead of C<filename>, data from strings.=back=head2 assign_cleanfile	$rc->assign_cleanfile();	be sure clean all data from current file.=head2 assign_matchreplace	$rc->assign_matchreplace(match=>,replace=>);replace new data when matched.=over 2=item * match -> string of matched data.=item * replace -> new data.=back=head2 assign_append	$rc->assign_append(point=>['up'|'down'|'foot'],		section=>[section],		data=>[key=value,key=value]|{key=>value,key=>value}|'key=value'		);append data around with section name.=over 3=item * point -> append data C<up> / C<down> / C<foot> with section.=item * section -> matched section name, except [unsection].=item * data -> new replace data in string/array/hash.=back	$rc->assign_append(point=>['up'|'down'|'over'],		section=>[section],		comkey=>[key,value],		data=>[key=value,key=value]|{key=>value,key=>value}|'key=value'		);append data around with section name and key/value in same section.=over 2=item * point -> C<over> will overwrite with key/value matched.=item * comkey -> match key and value.=back	$rc->assign_append(point=>'up'|'down',		data=>[key=value,key=value]|{key=>value,key=>value}|'key=value'		);simple append data without any section.=head2 assign_replacesection	$rc->assign_replacesection(section=>[section],		data=>[key=value,key=value]|{key=>value,key=>value}|'key=value'		);replace the section body data,except "#" in body.=over 1=item * section -> all section and [unsection].=back=head2 assign_delsection	$rc->assign_delsection(section=>[section]);erase section name and section data.=over 1=item * section -> all section and [unsection].=back=head2 assign_addsection	$rc->assign_addsection(section=>[section]);add section with name.=over 1=item * section -> name of new section.=back=head2 assign_editkey	$rc->assign_editkey(section=>[section],key=>[keyname],value=>[value],new_value=>[new_value]);modify value with matched section.if don't assign value=> will replace all matched key. exp script:	$rc->assign_editkey(section=>'990001',key=>'all',new_value=>'gsm');data:	all=g711	all=ilbcwill convert to:	all=gsm	all=gsm=head2 assign_delkey	$rc->assign_delkey(section=>[section],key=>[keyname],value=>[value]);erase all matched C<keyname> in section or in [unsection].=head2 save_file	$rc->save_file(filename=>[filename],resource=>[resource]);process assign rules and save to file.=over 2=item * filename -> save to file name.=item * resource -> instand of filename must resource return load_config orfile handle.=back=head2 clean_assign	$rc->clean_assign();clean all assign rules.=head1 EXAMPLESbe come soon...=head1 AUTHORSAsterisk::config by hoowa sun.Version 0.7 patch by Liu Hailong.=head1 COPYRIGHTThe Asterisk::config module is Copyright (c) 2005-2006 hoowa sun. P.R.China.All rights reserved.You may distribute under the terms of either the GNU General PublicLicense or the Artistic License, as specified in the Perl README file.=head1 WARRANTYThe Asterisk::config is free Open Source software.IT COMES WITHOUT WARRANTY OF ANY KIND.=head1 SUPPORTEmail(Chinese & English) hoowa.sun@gmail.comChinese OpenPBX technology Forum http://www.openpbx.cnChinese Perl Forum http://bbs.perlchina.org=cut1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -