[Asterisk-cvs] asterisk-addons/res_perl AstAPIBase.c, 1.3,
1.4 AstAPIBase_wrap.c, 1.2, 1.3 res_perl.c, 1.4, 1.5
anthm at lists.digium.com
anthm at lists.digium.com
Mon Nov 15 09:28:38 CST 2004
Update of /usr/cvsroot/asterisk-addons/res_perl
In directory mongoose.digium.com:/tmp/cvs-serv9040
Modified Files:
AstAPIBase.c AstAPIBase_wrap.c res_perl.c
Log Message:
merge in HEAD compat code
Index: AstAPIBase.c
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/res_perl/AstAPIBase.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- AstAPIBase.c 26 Sep 2004 18:13:54 -0000 1.3
+++ AstAPIBase.c 15 Nov 2004 14:29:21 -0000 1.4
@@ -85,6 +85,15 @@
return chan->priority;
}
+
+char *asterisk_get_account_code(struct ast_channel *chan) {
+ if(!chan) {
+ ast_log(LOG_WARNING, "No Channel!\n");
+ return 0;
+ }
+ return chan->accountcode;
+}
+
int asterisk_run_app(struct ast_channel *chan,char *app_name,char *data,int fork) {
pthread_attr_t attr;
@@ -218,7 +227,7 @@
struct ast_filestream *fs;
long max_length;
int input;
- char blank[2] = "";
+ char *blank = "";
if(!chan) {
@@ -235,7 +244,6 @@
digits=blank;
}
-
res = ast_waitfor(chan, -1);
input = ast_waitfordigit(chan,100);
if(input < 0)
@@ -247,6 +255,7 @@
return -1;
}
ast_seekstream(fs, 0, SEEK_END);
+
max_length = ast_tellstream(fs);
ast_seekstream(fs, sample_offset, SEEK_SET);
res = ast_applystream(chan, fs);
@@ -255,9 +264,9 @@
return -1;
}
res = ast_waitstream(chan,digits);
- sample_offset = (chan->stream)?ast_tellstream(fs):max_length;
+ sample_offset = (chan->stream == fs)?ast_tellstream(fs):max_length;
ast_stopstream(chan);
- return res;
+ return sample_offset;
}
@@ -499,7 +508,7 @@
return ast_hangup(chan);
}
-void asterisk_setcallerid(struct ast_channel *chan,char *callerid) {
+void asterisk_setcallerid(struct ast_channel *chan,char *cid_name, char *cid_num, char *ani) {
if(!chan) {
ast_log(LOG_WARNING, "No Channel!\n");
@@ -507,7 +516,7 @@
}
- ast_set_callerid(chan, callerid, 0);
+ ast_set_callerid(chan, cid_name, cid_num, ani);
}
int asterisk_channelstatus(struct ast_channel *chan) {
@@ -565,7 +574,7 @@
}
if (level <= option_verbose)
- ast_verbose("%s%s", prefix,msg);
+ ast_verbose("%s%s\n", prefix,msg);
}
@@ -701,10 +710,10 @@
}
-struct ast_channel *asterisk_request_and_dial(char *type,char *data,int format,char *callerid, int timeout) {
+struct ast_channel *asterisk_request_and_dial(char *type,char *data,int format,char *cid_name, char *cid_num, int timeout) {
int reason;
struct ast_channel *chan;
- chan = ast_request_and_dial(type,AST_FORMAT_ULAW, data, timeout, &reason,callerid);
+ chan = ast_request_and_dial(type,format, data, timeout, &reason,cid_name,cid_num);
return chan;
}
@@ -743,9 +752,10 @@
struct ast_channel *asterisk_request(int format,char *type,char *data,char *callerid) {
struct ast_channel *chan=NULL;
- chan = ast_request(type, format, data);
+ int cause=0;
+ chan = ast_request(type, format, data, &cause);
if (callerid && strlen(callerid))
- ast_set_callerid(chan, callerid, 1);
+ ast_set_callerid(chan, callerid,callerid,callerid);
return chan;
}
Index: AstAPIBase_wrap.c
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/res_perl/AstAPIBase_wrap.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- AstAPIBase_wrap.c 26 Sep 2004 18:14:55 -0000 1.2
+++ AstAPIBase_wrap.c 15 Nov 2004 14:29:21 -0000 1.3
@@ -790,6 +790,7 @@
extern struct ast_channel *asterisk_get_channel_by_name(char *);
extern int asterisk_chanlist(int);
extern int asterisk_chan_priority(struct ast_channel *,int);
+extern char *asterisk_get_account_code(struct ast_channel *);
extern int asterisk_run_app(struct ast_channel *,char *,char *,int);
extern int asterisk_exec(struct ast_channel *,char *,char *);
extern int asterisk_control_streamfile(struct ast_channel *,char *,char *,char *,char *,char *,int);
@@ -810,7 +811,7 @@
extern int asterisk_autohangup(struct ast_channel *,int);
extern int asterisk_soft_hangup(struct ast_channel *);
extern int asterisk_hangup(struct ast_channel *);
-extern void asterisk_setcallerid(struct ast_channel *,char *);
+extern void asterisk_setcallerid(struct ast_channel *,char *,char *,char *);
extern int asterisk_channelstatus(struct ast_channel *);
extern int asterisk_setvariable(struct ast_channel *,char *,char *);
extern char *asterisk_getvariable(struct ast_channel *,char *);
@@ -823,7 +824,7 @@
extern void asterisk_moh_stop(struct ast_channel *);
extern int asterisk_bridge_call(struct ast_channel *,struct ast_channel *,int,int,int);
extern int asterisk_bridge_call_long(struct ast_channel *,struct ast_channel *,int,int,int,int,long,long,long,char *,char *,char *);
-extern struct ast_channel *asterisk_request_and_dial(char *,char *,int,char *,int);
+extern struct ast_channel *asterisk_request_and_dial(char *,char *,int,char *,char *,int);
extern int asterisk_manager_command(int,char *);
extern int asterisk_cli(int,char *);
extern int asterisk_best_format(struct ast_channel *);
@@ -959,6 +960,37 @@
}
+XS(_wrap_asterisk_get_account_code) {
+ {
+ struct ast_channel *arg1 = (struct ast_channel *) 0 ;
+ char *result;
+ int argvi = 0;
+ dXSARGS;
+
+ if ((items < 1) || (items > 1)) {
+ SWIG_croak("Usage: asterisk_get_account_code(chan);");
+ }
+ {
+ if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_ast_channel,0) < 0) {
+ SWIG_croak("Type error in argument 1 of asterisk_get_account_code. Expected _p_ast_channel");
+ }
+ }
+ result = (char *)asterisk_get_account_code(arg1);
+
+ ST(argvi) = sv_newmortal();
+ if (result) {
+ sv_setpv((SV*)ST(argvi++), (char *) result);
+ } else {
+ sv_setsv((SV*)ST(argvi++), &PL_sv_undef);
+ }
+ XSRETURN(argvi);
+ fail:
+ ;
+ }
+ croak(Nullch);
+}
+
+
XS(_wrap_asterisk_run_app) {
{
struct ast_channel *arg1 = (struct ast_channel *) 0 ;
@@ -1596,11 +1628,13 @@
{
struct ast_channel *arg1 = (struct ast_channel *) 0 ;
char *arg2 ;
+ char *arg3 ;
+ char *arg4 ;
int argvi = 0;
dXSARGS;
- if ((items < 2) || (items > 2)) {
- SWIG_croak("Usage: asterisk_setcallerid(chan,callerid);");
+ if ((items < 4) || (items > 4)) {
+ SWIG_croak("Usage: asterisk_setcallerid(chan,cid_name,cid_num,ani);");
}
{
if (SWIG_ConvertPtr(ST(0), (void **) &arg1, SWIGTYPE_p_ast_channel,0) < 0) {
@@ -1609,7 +1643,11 @@
}
if (!SvOK((SV*) ST(1))) arg2 = 0;
else arg2 = (char *) SvPV(ST(1), PL_na);
- asterisk_setcallerid(arg1,arg2);
+ if (!SvOK((SV*) ST(2))) arg3 = 0;
+ else arg3 = (char *) SvPV(ST(2), PL_na);
+ if (!SvOK((SV*) ST(3))) arg4 = 0;
+ else arg4 = (char *) SvPV(ST(3), PL_na);
+ asterisk_setcallerid(arg1,arg2,arg3,arg4);
XSRETURN(argvi);
@@ -2031,13 +2069,14 @@
char *arg2 ;
int arg3 ;
char *arg4 ;
- int arg5 ;
+ char *arg5 ;
+ int arg6 ;
struct ast_channel *result;
int argvi = 0;
dXSARGS;
- if ((items < 5) || (items > 5)) {
- SWIG_croak("Usage: asterisk_request_and_dial(type,data,format,callerid,timeout);");
+ if ((items < 6) || (items > 6)) {
+ SWIG_croak("Usage: asterisk_request_and_dial(type,data,format,cid_name,cid_num,timeout);");
}
if (!SvOK((SV*) ST(0))) arg1 = 0;
else arg1 = (char *) SvPV(ST(0), PL_na);
@@ -2046,8 +2085,10 @@
arg3 = (int) SvIV(ST(2));
if (!SvOK((SV*) ST(3))) arg4 = 0;
else arg4 = (char *) SvPV(ST(3), PL_na);
- arg5 = (int) SvIV(ST(4));
- result = (struct ast_channel *)asterisk_request_and_dial(arg1,arg2,arg3,arg4,arg5);
+ if (!SvOK((SV*) ST(4))) arg5 = 0;
+ else arg5 = (char *) SvPV(ST(4), PL_na);
+ arg6 = (int) SvIV(ST(5));
+ result = (struct ast_channel *)asterisk_request_and_dial(arg1,arg2,arg3,arg4,arg5,arg6);
ST(argvi) = sv_newmortal();
SWIG_MakePtr(ST(argvi++), (void *) result, SWIGTYPE_p_ast_channel, 0|0);
@@ -2423,6 +2464,7 @@
{"AstAPIBasec::asterisk_get_channel_by_name", _wrap_asterisk_get_channel_by_name},
{"AstAPIBasec::asterisk_chanlist", _wrap_asterisk_chanlist},
{"AstAPIBasec::asterisk_chan_priority", _wrap_asterisk_chan_priority},
+{"AstAPIBasec::asterisk_get_account_code", _wrap_asterisk_get_account_code},
{"AstAPIBasec::asterisk_run_app", _wrap_asterisk_run_app},
{"AstAPIBasec::asterisk_exec", _wrap_asterisk_exec},
{"AstAPIBasec::asterisk_control_streamfile", _wrap_asterisk_control_streamfile},
Index: res_perl.c
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/res_perl/res_perl.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- res_perl.c 27 Sep 2004 20:21:13 -0000 1.4
+++ res_perl.c 15 Nov 2004 14:29:21 -0000 1.5
@@ -18,9 +18,9 @@
#define RES_PERL_VERSION "1.0"
#define CREATE_STRING(name,size) char name[size];
+//#define CHAN_INFO
// <PERL SPECIFIC MUMBO JUMBO>
-
static PerlInterpreter *global_perl;
static char *embedding[] = { "", "-e",""};
static STRLEN n_a;
@@ -64,7 +64,6 @@
return ret;
}
-
static void init_perl(PerlInterpreter **new_perl) {
char code[100];
//ast_log(LOG_WARNING,"CREATING PERL INTREPRETER\n");
@@ -79,7 +78,6 @@
}
-
static void dest_perl(PerlInterpreter **old_perl) {
if (*old_perl != NULL) {
//ast_log(LOG_WARNING,"DESTROYING PERL INTREPRETER\n");
@@ -89,7 +87,6 @@
}
}
-
static void users_inc() {
ast_mutex_lock(&users_lock);
users++;
@@ -110,14 +107,11 @@
struct threadlist*next;
} *threads;
-
static char *tdesc = "Perl Interface";
static char *app = "Perl";
static char *synopsis = "Use Perl in Asterisk";
static char *descrip = "Use Perl in Asterisk";
-
-
STANDARD_LOCAL_USER;
LOCAL_USER_DECL;
@@ -132,13 +126,8 @@
ast_cli(fd,"\n\n");
}
-
-
-
-
static void rem_thread(struct threadlist *tl) {
struct threadlist *ptr,*prev;
-
for (ptr=threads;ptr;ptr=ptr->next) {
if ((long)ptr->thread == (long)tl->thread) {
@@ -150,27 +139,22 @@
prev->next = ptr->next;
}
}
-
}
-
prev=ptr;
}
}
static void add_thread(struct threadlist *tl) {
struct threadlist *ptr;
-
+ tl->next = NULL;
if (threads)
for (ptr=threads;ptr->next;ptr=ptr->next);
-
if (ptr)
ptr->next = tl;
else
threads = tl;
-
}
-
static void end_thread(char *thread_in) {
struct threadlist *ptr;
pthread_t thread;
@@ -180,8 +164,6 @@
thread_id=0;
else
thread_id=atol(thread_in);
-
-
for (ptr=threads;ptr;ptr=ptr->next) {
if (((long) ptr->thread == thread_id) || thread_id==0) {
thread = ptr->thread;
@@ -189,16 +171,9 @@
pthread_kill(thread,SIGQUIT);
rem_thread(ptr);
}
-
}
-
-
-
}
-
-
-
void launch_perl_thread(char *function) {
pthread_t thread;
pthread_attr_t attr;
@@ -214,8 +189,6 @@
}
-
-
void *perl_thread(void *function) {
AV *array;
int x,i,exit;
@@ -223,7 +196,6 @@
pthread_t thread;
struct threadlist tl;
-
x = i = 0;
exit = 1;
ast_log(LOG_WARNING,"Started Thread\n");
@@ -232,11 +204,13 @@
func=strsep(&stringp,":");
arg=strsep(&stringp,"\0");
thread = pthread_self();
+ memset(&tl,0,sizeof(tl));
tl.thread = thread;
+ tl.next = NULL;
strncpy(tl.func,func,sizeof(tl.func));
/* clone perl for this thread */
PerlInterpreter *my_perl=perl_clone(global_perl,CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
-
+
add_thread(&tl);
array=eval_some_perl(my_perl,func,arg);
rem_thread(&tl);
@@ -246,17 +220,20 @@
return((void *) 1);
}
-
AV *eval_some_perl(PerlInterpreter *my_perl,char *func,char *arg) {
char *callfunc;
char *fmt = "eval{\n$SIG{QUIT} = sub {die q|SIGQUIT! Exit Requested.\n|};\nmy @args=split(chr 129,q`%s`);\nforeach (@args) {s/\\\\n/\\n/g};\n@%s=&Asterisk::Embed::%s(@args)};\nif($@) {Asterisk::Embed::asterisk_verbose(0,\"ERROR:\n$@\n\")\n};\n ";
- size_t size = (strlen(func) * 2) + strlen(arg) + strlen(fmt) + 128;
+ size_t size = 0;
+ size = func ? (strlen(func) * 2) : 0;
+ if(arg)
+ size += strlen(arg);
+ size += strlen(fmt) + 128;
+
callfunc=alloca(size);
snprintf(callfunc,size,fmt,arg ? arg : "",func,func);
PERL_SET_CONTEXT(my_perl);
eval_pv(callfunc, TRUE);
return get_av(func, FALSE);
-
}
int can_run_nochan(char *test) {
@@ -277,19 +254,12 @@
if (!ret)
return 0;
-
-
-
-
stringp=strdup(ret);
func=strsep(&stringp,":");
arg=strsep(&stringp,"\0");
if (func && arg) {
-
-
ast_log(LOG_WARNING,"call function [%s]\n",func);
-
if (func && ! chan && can_run_nochan(func) == 0) {
ast_log(LOG_WARNING, "cannot use function [%s] from here,skipping...\n",func);
return 1;
@@ -298,12 +268,9 @@
launch_perl_thread(arg);
}
}
-
return 0;
}
-
-
static int perl_exec(struct ast_channel *chan, void *data)
{
char *func;
@@ -318,12 +285,10 @@
PerlInterpreter *my_perl;
int retme=0;
-
if (!data || !strlen(data)) {
ast_log(LOG_WARNING, "Ignoring blank arg\n");
return -1;
}
-
/* clone perl for this execution */
my_perl=perl_clone(global_perl,CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
users_inc();
@@ -333,7 +298,6 @@
func=strsep(&stringp,":");
arg=strsep(&stringp,"\0");
-
if (chan && chan->name && arg) {
sprintf(buf,"%s%c%s",chan->name,':',arg);
arg=buf + strlen(chan->name);
@@ -345,7 +309,6 @@
return -1;
}
-
ast_log(LOG_WARNING, "Calling Perl Sub [%s] [%s]\n",func,buf);
replace_delim(arg,':',delim);
@@ -363,22 +326,15 @@
}
}
}
-
users_dec();
dest_perl(&my_perl);
return(retme);
}
-
-
-
-
static int perl_reload(int fd) {
-
ast_log(LOG_WARNING, "This wont work yet\n");
return 0;
-
if (users) {
ast_log(LOG_WARNING, "Too Busy for reload wait for %d users first.\n",users);
return 0;
@@ -387,7 +343,6 @@
ast_log(LOG_WARNING, "Not done reloading from last time yet!\n");
}
-
ast_mutex_lock(&perl_lock);
reloading = 1;
_unload_module();
@@ -399,8 +354,6 @@
return 0;
}
-
-
static int perl_cli(int fd, int argc, char *argv[]) {
AV *array;
int i;
@@ -433,19 +386,18 @@
return 0;
} else if(argv[1] && !strcmp(argv[1],"call")) {
if (!argv[2]) {
- ast_cli(fd,"\nusage perlcall <args>\n");
+ ast_cli(fd,"\nusage perl call func:<args>\n");
return 0;
}
-
if (argv[2] && argv[3]) {
strncpy(arg1,argv[2],255);
strncpy(arg2,argv[3],255);
- replace_delim(arg1,':',delim);
+ //replace_delim(arg1,':',delim);
replace_delim(arg2,':',delim);
array=eval_some_perl(my_perl,arg1,arg2);
} else if(argv[2]) {
strncpy(arg1,argv[2],255);
- replace_delim(arg1,':',delim);
+ //replace_delim(arg1,':',delim);
array=eval_some_perl(my_perl,arg1,"");
}
if (array) {
@@ -455,8 +407,6 @@
process_perl_return_value(NULL,rval);
}
}
-
-
return 0;
}
@@ -464,14 +414,11 @@
ast_cli(fd,"\nUnknown Command: %s\n",argv[1]);
else
ast_cli(fd,"\nusage perl <command> <args>\n");
-
return 0;
}
/* <SWITCH> */
-
-
-static int perl_switch_handler(char *func,struct ast_channel *chan, char *context, char *exten, int priority, char *callerid, char *data,int clone) {
+static int perl_switch_handler(const char *func,struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data,int clone) {
AV *array;
int array_size=0,i=0,ret=0;
@@ -493,34 +440,30 @@
if (ret >= 0)
break;
}
-
} else {
ret = 0;
}
-
if (clone)
dest_perl(&my_perl);
-
return ret;
}
-static int perl_switch_exists(struct ast_channel *chan, char *context, char *exten, int priority, char *callerid, char *data) {
+static int perl_switch_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data) {
return perl_switch_handler("exists",chan,context,exten,priority,callerid,data,0);
}
-static int perl_switch_canmatch(struct ast_channel *chan, char *context, char *exten, int priority, char *callerid, char *data) {
+static int perl_switch_canmatch(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data) {
return perl_switch_handler("canmatch",chan,context,exten,priority,callerid,data,0);
}
-static int perl_switch_exec(struct ast_channel *chan, char *context, char *exten, int priority, char *callerid, int newstack, char *data) {
+static int perl_switch_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, int newstack, const char *data) {
return perl_switch_handler("exec",chan,context,exten,priority,callerid,data,1);
}
-static int perl_switch_matchmore(struct ast_channel *chan, char *context, char *exten, int priority, char *callerid, char *data) {
+static int perl_switch_matchmore(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data) {
return perl_switch_handler("matchmore",chan,context,exten,priority,callerid,data,0);
}
-
static struct ast_switch perl_switch =
{
name: "Perl",
@@ -531,51 +474,33 @@
matchmore: perl_switch_matchmore,
};
-
-
-
-
-
/* </SWITCH> */
-
static struct ast_cli_entry cli_perl = { { "perl", NULL }, perl_cli, "Perl", "Perl" };
int _unload_module(void) {
-
if (use_switch) {
ast_unregister_switch(&perl_switch);
}
-
if (use_cdr) {
ast_cdr_unregister("perl");
}
-
-
eval_some_perl(global_perl,"shutdown","");
end_thread(NULL);
-
dest_perl(&global_perl);
-
if (reloading)
return 0;
-
-
-
#ifdef HAVE_AST_CUST_CONFIG
if (use_config) {
ast_log(LOG_NOTICE,"unloading perl config engine.\n");
ast_cust_config_deregister(®1);
}
#endif
-
STANDARD_HANGUP_LOCALUSERS;
ast_cli_unregister(&cli_perl);
ast_unregister_application(app);
return 0;
-
}
-
static int append_string(char *buf, char *s, int len)
{
int pos = strlen(buf);
@@ -625,8 +550,6 @@
return 0;
}
-
-
static int append_tv_diff(char *buf,struct timeval *ended,struct timeval *started, int len)
{
char tmp[32];
@@ -645,7 +568,6 @@
static int build_csv_record(char *buf, int len, struct ast_cdr *cdr)
{
-
buf[0] = '\0';
/* Account code */
append_string(buf,"accountcode", len);
@@ -690,7 +612,6 @@
append_string(buf,"duration_ms", len);
append_tv_diff(buf, &cdr->end,&cdr->start, len);
-
/* Billable seconds */
append_string(buf,"billable", len);
append_int(buf, cdr->billsec, len);
@@ -698,7 +619,6 @@
append_string(buf,"billable_ms", len);
append_tv_diff(buf,&cdr->end,&cdr->answer, len);
-
/* Disposition */
append_string(buf,"disposition", len);
append_string(buf, ast_cdr_disp2str(cdr->disposition), len);
@@ -725,15 +645,103 @@
return -1;
}
+#ifdef CHAN_INFO
+static int ast_serialize_showchan(struct ast_channel *c, char *buf, size_t size)
+{
+ struct timeval now;
+ long elapsed_seconds=0;
+ int hour=0, min=0, sec=0;
+ gettimeofday(&now, NULL);
+ memset(buf,0,size);
+ if(!c)
+ return 0;
+
+ if(c->cdr) {
+ elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
+ hour = elapsed_seconds / 3600;
+ min = (elapsed_seconds % 3600) / 60;
+ sec = elapsed_seconds % 60;
+ }
+ ast_mutex_lock(&c->lock);
+ snprintf(buf,size,
+ "Name=%s\n"
+ "Type=%s\n"
+ "UniqueID=%s\n"
+ "CallerID=%s\n"
+ "CallerIDName=%s\n"
+ "DNIDDigits=%s\n"
+ "State=%s(%d)\n"
+ "Rings=%d\n"
+ "NativeFormat=%d\n"
+ "WriteFormat=%d\n"
+ "ReadFormat=%d\n"
+ "1stFileDescriptor=%d\n"
+ "Framesin=%d%s\n"
+ "Framesout=%d%s\n"
+ "TimetoHangup=%ld\n"
+ "ElapsedTime=%dh%dm%ds\n"
+ "Context=%s\n"
+ "Extension=%s\n"
+ "Priority=%d\n"
+ "CallGroup=%d\n"
+ "PickupGroup=%d\n"
+ "Application=%s\n"
+ "Data=%s\n"
+ "Stack=%d\n"
+ "Blocking_in=%s\n",
+ c->name, c->type, c->uniqueid,
+ (c->cid.cid_num ? c->cid.cid_num : "(N/A)"),
+ (c->cid.cid_name ? c->cid.cid_name : "(N/A)"),
+ (c->cid.cid_dnid ? c->cid.cid_dnid : "(N/A)" ), ast_state2str(c->_state), c->_state, c->rings, c->nativeformats, c->writeformat, c->readformat,
+ c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "",
+ c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup,
+ hour, min, sec,
+ c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ),
+ ( c-> data ? (!ast_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"),
+ c->stack, (c->blocking ? c->blockproc : "(Not Blocking)"));
+
+ ast_mutex_unlock(&c->lock);
+
+ return 1;
+}
+#endif
static int perl_log(struct ast_cdr *cdr) {
char buf[1024];
+ char varbuf[1024];
PerlInterpreter *my_perl;
-
- my_perl=perl_clone(global_perl,CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
- if (build_csv_record(buf,1024, cdr)) {
- ast_log(LOG_WARNING, "Unable to create CSV record in 1024 bytes. CDR not recorded!\n");
+ SV *sv;
+ struct ast_channel *chan=NULL;
+ static char *code =
+ "eval{for my $k (split(/\n/,$Asterisk::Embed::CHAN_VARS_RAW)) {"
+ "if(my($var,$val) = $k =~ /^([^=]+)=(.*)/) {$Asterisk::Embed::CHAN_VARS{$var} = $val;}}};";
+#ifdef CHAN_INFO
+ static char *code2 =
+ "eval{for my $k (split(/\n/,$Asterisk::Embed::CHAN_INFO_RAW)) {"
+ "if(my($var,$val) = $k =~ /^([^=]+)=(.*)/) {$Asterisk::Embed::CHAN_INFO{$var} = $val;}}};";
+#endif
+ my_perl=perl_clone(global_perl,CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
+ if (build_csv_record(buf,sizeof(buf), cdr)) {
+ ast_log(LOG_WARNING, "Unable to create CSV record in %d bytes. CDR not recorded!\n",sizeof(buf));
} else {
+ if((chan = ast_get_channel_by_name_locked(cdr->channel))) {
+ if(pbx_builtin_serialize_variables(chan,varbuf,sizeof(varbuf))) {
+ if((sv = get_sv("Asterisk::Embed::CHAN_VARS_RAW", TRUE))) {
+ sv_setpvn(sv,varbuf,sizeof(varbuf));
+ eval_pv(code,TRUE);
+ }
+ }
+#ifdef CHAN_INFO
+ if(ast_serialize_showchan(chan,varbuf,sizeof(varbuf))) {
+ if((sv = get_sv("Asterisk::Embed::CHAN_INFO_RAW", TRUE))) {
+ sv_setpvn(sv,varbuf,sizeof(varbuf));
+ eval_pv(code2,TRUE);
+ }
+ }
+#endif
+ ast_mutex_unlock(&chan->lock);
+ }
+
eval_some_perl(my_perl,"perl_cdr",buf);
}
dest_perl(&my_perl);
@@ -741,15 +749,98 @@
}
#ifdef HAVE_AST_CUST_CONFIG
-struct ast_config *perl_config(char *file, struct ast_config *new_config_s,struct ast_category **new_cat_p,struct ast_variable **new_v_p,int recur
-#ifdef PRESERVE_COMMENTS
- ,struct ast_comment_struct *acs
-#endif
- ) {
+static struct ast_variable *realtime_perl(const char *database, const char *table, va_list ap) {
+ AV *array;
+ PerlInterpreter *my_perl;
+ SV *var, *val;
+ I32 array_size = 0;
+ int i = 0;
+ size_t len;
+ char *args; struct ast_variable *new_v=NULL,*vars=NULL,*next=NULL;
+ const char *newparam,*newval;
- PerlInterpreter *my_perl;
+ va_list aq;
+ va_copy(aq, ap);
+ if (clone_on_config)
+ my_perl=perl_clone(global_perl,CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
+ else
+ my_perl = global_perl;
+ len = strlen(database) + strlen(table) + 512;
+ args = alloca(len);
+ snprintf(args,len,"%s:%s",database,table);
+ while((newparam = va_arg(aq, const char *))) {
+ if((newval = va_arg(aq, const char *))) {
+ if(option_verbose > 10)
+ ast_verbose("DEBUG: %s=%s\n",newparam,newval);
+ snprintf((char *) args + strlen(args), len - strlen(args), ":%s:%s", newparam,newval);
+ }
+ else {
+ if(aq)
+ va_end(aq);
+ return NULL;
+ }
+ }
+ replace_delim(args,':',delim);
+ if((array = eval_some_perl(my_perl,"perl_realtime",(char *)args))) {
+ array_size = av_len(array) + 1;
+ if(array_size % 2 == 0) {
+ for (i = 0; i+1 <= array_size; i++) {
+ if((var = *av_fetch(array, i++, FALSE)) &&
+ (val = *av_fetch(array, i, FALSE)) ) {
+ if((new_v = ast_new_variable(SvPV_nolen(var),SvPV_nolen(val)))) {
+ if(vars) {
+ next->next = new_v;
+ next = new_v;
+ }
+ else
+ vars = next = new_v;
+ }
+ }
+ }
+ } else
+ ast_log(LOG_WARNING,"Not a hash!\n");
+ }
+ if(aq)
+ va_end(aq);
+ return vars;
+}
+static int update_perl(const char *database, const char *table, const char *keyfield, const char *lookup, va_list ap) {
+ va_list aq;
+ va_copy(aq, ap);
+ PerlInterpreter *my_perl;
+ const char *str,*newparam,*newval;
+ size_t len;
+
+ if (clone_on_config)
+ my_perl=perl_clone(global_perl,CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
+ else
+ my_perl = global_perl;
+
+ len = strlen(database) + strlen(table) + strlen(keyfield) + strlen(lookup) + 512;
+ str = alloca(len);
+ snprintf((char *)str,len,"%s:%s:%s:%s",database,table,keyfield,lookup);
+
+ while((newparam = va_arg(aq, const char *))) {
+ if((newval = va_arg(aq, const char *)))
+ snprintf((char *) str + strlen(str), len - strlen(str), ":%s:%s", newparam,newval);
+ else {
+ if(aq)
+ va_end(aq);
+ return -1;
+ }
+ }
+ eval_some_perl(my_perl,"perl_update",(char *)str);
+ if(aq)
+ va_end(aq);
+
+ return 0;
+}
+
+static struct ast_config *perl_config(const char *database, const char *table, const char *file, struct ast_config *new_config_s, struct ast_category **new_cat_p, struct ast_variable **new_v_p, int recur)
+{
+ PerlInterpreter *my_perl;
if (clone_on_config)
my_perl=perl_clone(global_perl,CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
else
@@ -761,11 +852,13 @@
char last[80];
int cat_started=0;
int var_started=0;
+ int len=0;
AV *array;
int i=0,ii=0;
I32 array_size,vars_size;
HV *hash;
char *category=NULL;
+ char *args;
AV *vars;
HV *varshash;
@@ -793,8 +886,12 @@
if (cur_v)
var_started=1;
- array=eval_some_perl(my_perl,"perl_config",file);
-
+ len = strlen(database) + strlen(table) + strlen(file) + 10;
+ args = alloca(len);
+ snprintf(args,len,"%s:%s:%s",database,table,file);
+ replace_delim(args,':',delim);
+ array=eval_some_perl(my_perl,"perl_config",args);
+
if (array) {
array_size = av_len(array) + 1;
} else {
@@ -827,8 +924,6 @@
}
var_started=0;
}
-
-
if (name && vars && SvTYPE(vars) == SVt_PVAV) {
if (vars)
vars_size = av_len(vars) + 1;
@@ -855,8 +950,6 @@
}
}
}
-
-
}
}
}
@@ -867,8 +960,6 @@
dest_perl(&my_perl);
return new;
-
-
}
#endif
@@ -880,12 +971,9 @@
users = 0;
PerlInterpreter *my_perl;
-
if (global_perl == NULL)
init_perl(&global_perl);
-
-
/* perl has hard coded macros on my_perl, need it */
my_perl = global_perl;
@@ -901,7 +989,6 @@
process_perl_return_value((struct ast_channel *) NULL,rval);
}
-
if (reloading)
return 0;
@@ -919,7 +1006,9 @@
ast_log(LOG_NOTICE,"loading perl config engine.\n");
memset(®1,0,sizeof(struct ast_config_reg));
strcpy(reg1.name,"perl");
- reg1.func = perl_config;
+ reg1.static_func = perl_config;
+ reg1.realtime_func = realtime_perl;
+ reg1.update_func = update_perl;
ast_cust_config_register(®1);
} else
@@ -927,8 +1016,6 @@
} else
ast_log(LOG_NOTICE,"perl config engine disabled.\n");
-
-
#endif
if (hv_exists(PERL_CONFIG,"CLONE_ON_CONFIG",strlen("CLONE_ON_CONFIG"))) {
@@ -938,7 +1025,6 @@
clone_on_config=1;
}
}
-
if (hv_exists(PERL_CONFIG,"USE_CDR",strlen("USE_CDR"))) {
rval = get_hash_val(my_perl,PERL_CONFIG,"USE_CDR");
if (rval && ast_true(rval)) {
@@ -950,7 +1036,6 @@
ast_log(LOG_NOTICE, "Perl CDR Disabled.\n");
} else
ast_log(LOG_NOTICE, "Perl CDR Disabled.\n");
-
if (hv_exists(PERL_CONFIG,"USE_SWITCH",strlen("USE_SWITCH"))) {
rval = get_hash_val(my_perl,PERL_CONFIG,"USE_SWITCH");
if (rval && ast_true(rval)) {
@@ -963,17 +1048,11 @@
ast_log(LOG_NOTICE, "Perl Switch Disabled.\n");
} else
ast_log(LOG_NOTICE, "Perl Switch Disabled.\n");
-
-
} else
ast_log(LOG_WARNING,"CONFIG HASH TABLE %%PERL_CONFIG NOT FOUND MANY FEATURES DISABLED!\n");
-
return ast_register_application(app, perl_exec, synopsis, descrip);
}
-
-
-
char *description(void) {
return tdesc;
}
More information about the svn-commits
mailing list