[Asterisk-cvs] asterisk-addons/res_perl AstAPIBase_wrap.c, 1.3, 1.4 Makefile, 1.2, 1.3 res_perl.c, 1.5, 1.6

anthm at lists.digium.com anthm at lists.digium.com
Sun Dec 19 11:08:06 CST 2004


Update of /usr/cvsroot/asterisk-addons/res_perl
In directory mongoose.digium.com:/tmp/cvs-serv4762

Modified Files:
	AstAPIBase_wrap.c Makefile res_perl.c 
Log Message:
cleanup / keep up with CVS HEAD


Index: Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/res_perl/Makefile,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- Makefile	26 Sep 2004 18:13:54 -0000	1.2
+++ Makefile	19 Dec 2004 16:04:10 -0000	1.3
@@ -117,8 +117,8 @@
 	/bin/mv AstAPIBase.pm INC 
 
 
-AstAPIBase.so: AstAPIBase_wrap.c AstAPIBase.o AstAPIBase_wrap.o  $(ASTLIBDIR)/modules/res_musiconhold.so perlxsi.o
-	$(CC) -fPIC -shared -Xlinker -x apihelp.o AstAPIBase.o AstAPIBase_wrap.o res_perl.o perlxsi.o $(ASTLIBDIR)/modules/res_musiconhold.so $(LDFLAGS) -o AstAPIBase.so
+AstAPIBase.so: AstAPIBase_wrap.c AstAPIBase.o AstAPIBase_wrap.o  perlxsi.o
+	$(CC) -fPIC -shared -Xlinker -x apihelp.o AstAPIBase.o AstAPIBase_wrap.o res_perl.o perlxsi.o  $(LDFLAGS) -o AstAPIBase.so
 
 
 api: AstAPIBase.so 
@@ -139,3 +139,6 @@
 	@cd $(ASTSRC) && /bin/rm -f asterisk && make install
 
 
+update:
+	@echo "Updating from CVS"
+	@cvs update -d

Index: res_perl.c
===================================================================
RCS file: /usr/cvsroot/asterisk-addons/res_perl/res_perl.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- res_perl.c	15 Nov 2004 14:29:21 -0000	1.5
+++ res_perl.c	19 Dec 2004 16:04:10 -0000	1.6
@@ -30,7 +30,7 @@
 static char delim=129;
 
 AST_MUTEX_DEFINE_STATIC(perl_lock);
-AST_MUTEX_DEFINE_STATIC(users_lock);
+
 static int reloading=0;
 static int users=0;
 int _unload_module(void);
@@ -43,7 +43,7 @@
 
 static int use_switch=0;
 static int use_cdr=0;
-static int clone_on_config=0;
+static int clone_on_config=1;
 
 static void replace_delim(char *arg,char a,char b) {
 	int i;
@@ -67,6 +67,7 @@
 static void init_perl(PerlInterpreter **new_perl) {
     char code[100];
     //ast_log(LOG_WARNING,"CREATING PERL INTREPRETER\n");
+	ast_mutex_lock(&perl_lock);
     *new_perl = perl_alloc();
     PERL_SET_CONTEXT(*new_perl);
     perl_construct(*new_perl);
@@ -74,31 +75,28 @@
     perl_run(*new_perl);
     sprintf(code,"use lib '%s/perl';package Asterisk::Embed;use asterisk_init;\n",ASTETCDIR);
     Perl_eval_pv(*new_perl,code, TRUE);
+	ast_mutex_unlock(&perl_lock);
     return;
     
 }
 
 static void dest_perl(PerlInterpreter **old_perl) {
     if (*old_perl != NULL) {
+		ast_mutex_lock(&perl_lock);
 		//ast_log(LOG_WARNING,"DESTROYING PERL INTREPRETER\n");
 		perl_destruct(*old_perl);
 		perl_free(*old_perl);
 		*old_perl=NULL;
+		ast_mutex_unlock(&perl_lock);
     }
 }
 
-static void users_inc() {
-    ast_mutex_lock(&users_lock);
-    users++;
-    ast_mutex_unlock(&users_lock);
-}
-
-static void users_dec() {
-    ast_mutex_lock(&users_lock);
-    users--;
-    if (users < 0)
-		users = 0;
-    ast_mutex_unlock(&users_lock);
+static PerlInterpreter *clone_perl(PerlInterpreter *parent) {
+	PerlInterpreter *new = NULL;
+	ast_mutex_lock(&perl_lock);
+	new=perl_clone(parent,CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
+	ast_mutex_unlock(&perl_lock);
+	return new;
 }
 
 static struct threadlist {
@@ -112,8 +110,8 @@
 static char *synopsis = "Use Perl in Asterisk";
 static char *descrip = "Use Perl in Asterisk";
 
-STANDARD_LOCAL_USER;
-LOCAL_USER_DECL;
+//STANDARD_LOCAL_USER;
+//LOCAL_USER_DECL;
 
 static void list_threads(int fd) {
     struct threadlist *ptr;
@@ -192,7 +190,7 @@
 void *perl_thread(void *function) {
     AV *array;
     int x,i,exit;
-    char *stringp,*func,*arg;
+    char *stringp = NULL, *func = NULL, *arg = NULL;
     pthread_t thread;
     struct threadlist tl;
 
@@ -200,16 +198,18 @@
     exit = 1;
     ast_log(LOG_WARNING,"Started Thread\n");  
 
-    stringp=strdup(function);
-    func=strsep(&stringp,":");
-    arg=strsep(&stringp,"\0");
+    if((stringp=ast_strdupa(function))) {
+		if((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);
+	PerlInterpreter *my_perl=clone_perl(global_perl);
+	
 	
     add_thread(&tl);
     array=eval_some_perl(my_perl,func,arg);
@@ -249,15 +249,16 @@
     return(ret);
 }
 
-int process_perl_return_value(struct ast_channel *chan,char *ret) {
-    char *arg,*stringp,*func;
-
-    if (!ret)
+int process_perl_return_value(struct ast_channel *chan, char *ret) {
+    char *arg=NULL, *stringp=NULL, *func=NULL;
+	
+    if (!ret || ast_strlen_zero(ret))
 		return 0;
-    stringp=strdup(ret);
-    func=strsep(&stringp,":");
-    arg=strsep(&stringp,"\0");
-
+    if((stringp=ast_strdupa(ret))) {
+		if((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) {
@@ -290,13 +291,13 @@
 		return -1;
     }
     /* clone perl for this execution */
-	my_perl=perl_clone(global_perl,CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
-    users_inc();
+	my_perl=clone_perl(global_perl);
 
-	info=ast_strdupa(data);
-    stringp=info;
-    func=strsep(&stringp,":");
-    arg=strsep(&stringp,"\0");
+	if((info=ast_strdupa(data))) {
+		stringp=info;
+		if((func=strsep(&stringp,":")))
+			arg=strsep(&stringp,"\0");
+	}
 
     if (chan && chan->name && arg) {
 		sprintf(buf,"%s%c%s",chan->name,':',arg);
@@ -320,37 +321,17 @@
 			rval = SvPV(*av_fetch(array, i, FALSE),n_a);
 			retme = atoi(rval);
 			if (! process_perl_return_value(chan,rval)) {
-				users_dec();
 				dest_perl(&my_perl);
 				return retme;
 			}
 		}
     }
-    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;
-    }
-    if (reloading) {
-		ast_log(LOG_WARNING, "Not done reloading from last time yet!\n");
-    }
-
-    ast_mutex_lock(&perl_lock);
-    reloading = 1;
-    _unload_module();
-    _load_module();
-    reloading = 0;
-    users = 0;
-    ast_mutex_unlock(&perl_lock);
-
+    ast_cli(fd, "This wont work yet\n");
     return 0;
 }
 
@@ -380,8 +361,10 @@
 		ast_cli(fd,"OK\n\n");
 		return 0;
     } else if(argv[1] && !strcmp(argv[1],"labotomy")) {
+		ast_mutex_lock(&perl_lock);
 		dest_perl(&global_perl);
 		init_perl(&global_perl);
+		ast_mutex_unlock(&perl_lock);
 		ast_cli(fd,"OK, One Flew Over The KooKoo's Nest!.....\n");
 		return 0;
     } else if(argv[1] && !strcmp(argv[1],"call")) {
@@ -425,7 +408,7 @@
 	char args[256],*rval=NULL;
 	PerlInterpreter *my_perl;
 	if (clone) {
-	    my_perl=perl_clone(global_perl,CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
+		my_perl=clone_perl(global_perl);
 	} else {
 	    my_perl = global_perl;
 	}
@@ -477,6 +460,8 @@
 /* </SWITCH> */
 static struct ast_cli_entry  cli_perl = { { "perl", NULL }, perl_cli, "Perl", "Perl" };
 
+int _unload_module(void) {return -1;}
+/*
 int _unload_module(void) {
     if (use_switch) {
 		ast_unregister_switch(&perl_switch);
@@ -500,6 +485,7 @@
     ast_unregister_application(app);
     return 0;
 }
+*/
 
 static int append_string(char *buf, char *s, int len)
 {
@@ -720,7 +706,7 @@
 		"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);
+	my_perl=clone_perl(global_perl);
     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 {
@@ -763,7 +749,7 @@
 	va_list aq;
     va_copy(aq, ap);
 	if (clone_on_config)
-		my_perl=perl_clone(global_perl,CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
+		my_perl=clone_perl(global_perl);
 	else
 		my_perl = global_perl;
 	len = strlen(database) + strlen(table) + 512;
@@ -814,7 +800,7 @@
 	size_t len;
 
 	if (clone_on_config)
-        my_perl=perl_clone(global_perl,CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
+		my_perl=clone_perl(global_perl);
     else
         my_perl = global_perl;
 
@@ -842,7 +828,7 @@
 {
     PerlInterpreter *my_perl;
     if (clone_on_config)
-		my_perl=perl_clone(global_perl,CLONEf_COPY_STACKS|CLONEf_KEEP_PTR_TABLE);
+		my_perl=clone_perl(global_perl);
     else 
 		my_perl = global_perl;
     
@@ -1058,9 +1044,9 @@
 }
 
 int usecount(void) {
-    int res;
-    STANDARD_USECOUNT(res);
-    return res;
+    //int res;
+    return 1;
+    //STANDARD_USECOUNT(res);
 }
 
 char *key() {




More information about the svn-commits mailing list