[asterisk-commits] russell: branch 1.2 r53133 - in /branches/1.2:
./ apps/ include/asterisk/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sat Feb 3 13:38:14 MST 2007
Author: russell
Date: Sat Feb 3 14:38:13 2007
New Revision: 53133
URL: http://svn.digium.com/view/asterisk?view=rev&rev=53133
Log:
set the DIALSTATUS variable to contain "INVALIDARGS" when the dial application
exits early because of invalid arguments instead of just leaving it empty.
(issue #8975)
Modified:
branches/1.2/apps/app_dial.c
branches/1.2/apps/app_meetme.c
branches/1.2/include/asterisk/lock.h
branches/1.2/utils.c
Modified: branches/1.2/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/apps/app_dial.c?view=diff&rev=53133&r1=53132&r2=53133
==============================================================================
--- branches/1.2/apps/app_dial.c (original)
+++ branches/1.2/apps/app_dial.c Sat Feb 3 14:38:13 2007
@@ -80,7 +80,7 @@
" ANSWEREDTIME - This is the amount of time for actual call.\n"
" DIALSTATUS - This is the status of the call:\n"
" CHANUNAVAIL | CONGESTION | NOANSWER | BUSY | ANSWER | CANCEL\n"
-" DONTCALL | TORTURE\n"
+" DONTCALL | TORTURE | INVALIDARGS\n"
" For the Privacy and Screening Modes, the DIALSTATUS variable will be set to\n"
"DONTCALL if the called party chooses to send the calling party to the 'Go Away'\n"
"script. The DIALSTATUS variable will be set to TORTURE if the called party\n"
@@ -759,7 +759,7 @@
char *start_sound=NULL;
char *dtmfcalled=NULL, *dtmfcalling=NULL;
char *var;
- char status[256];
+ char status[256] = "INVALIDARGS";
int play_to_caller=0,play_to_callee=0;
int sentringing=0, moh=0;
char *outbound_group = NULL;
@@ -780,21 +780,19 @@
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
+ pbx_builtin_setvar_helper(chan, "DIALSTATUS", status);
return -1;
}
LOCAL_USER_ADD(u);
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory allocation failure\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
+ parse = ast_strdupa(data);
AST_STANDARD_APP_ARGS(args, parse);
if (!ast_strlen_zero(args.options)) {
if (ast_app_parse_options(dial_exec_options, &opts, opt_args, args.options)) {
+ pbx_builtin_setvar_helper(chan, "DIALSTATUS", status);
LOCAL_USER_REMOVE(u);
return -1;
}
@@ -802,6 +800,7 @@
if (ast_strlen_zero(args.peers)) {
ast_log(LOG_WARNING, "Dial requires an argument (technology/number)\n");
+ pbx_builtin_setvar_helper(chan, "DIALSTATUS", status);
LOCAL_USER_REMOVE(u);
return -1;
}
Modified: branches/1.2/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/apps/app_meetme.c?view=diff&rev=53133&r1=53132&r2=53133
==============================================================================
--- branches/1.2/apps/app_meetme.c (original)
+++ branches/1.2/apps/app_meetme.c Sat Feb 3 14:38:13 2007
@@ -139,6 +139,7 @@
struct ast_conf_user *firstuser; /* Pointer to the first user struct */
struct ast_conf_user *lastuser; /* Pointer to the last user struct */
time_t start; /* Start time (s) */
+ int refcount;
int recording; /* recording status */
int isdynamic; /* Created on the fly? */
int locked; /* Is the conference locked? */
@@ -438,7 +439,7 @@
ast_autoservice_stop(chan);
}
-static struct ast_conference *build_conf(char *confno, char *pin, char *pinadmin, int make, int dynamic)
+static struct ast_conference *build_conf(char *confno, char *pin, char *pinadmin, int make, int dynamic, int refcount)
{
struct ast_conference *cnf;
struct zt_confinfo ztc;
@@ -501,6 +502,8 @@
ast_log(LOG_WARNING, "Out of memory\n");
}
cnfout:
+ if (cnf)
+ ast_atomic_fetchadd_int(&cnf->refcount, refcount);
ast_mutex_unlock(&conflock);
return cnf;
}
@@ -835,6 +838,8 @@
if (!user) {
ast_log(LOG_ERROR, "Out of memory\n");
+ if (ast_atomic_dec_and_test(&conf->refcount))
+ conf_free(conf);
return ret;
}
@@ -1601,9 +1606,10 @@
"Usernum: %d\r\n",
chan->name, chan->uniqueid, conf->confno, user->user_no);
conf->users--;
+ ast_atomic_fetchadd_int(&conf->refcount, -1);
if (confflags & CONFFLAG_MARKEDUSER)
conf->markedusers--;
- if (!conf->users) {
+ if (!conf->users && !conf->refcount) {
/* No more users -- close this one out */
conf_free(conf);
} else {
@@ -1646,7 +1652,7 @@
}
static struct ast_conference *find_conf(struct ast_channel *chan, char *confno, int make, int dynamic, char *dynamic_pin,
- struct ast_flags *confflags)
+ int refcount, struct ast_flags *confflags)
{
struct ast_config *cfg;
struct ast_variable *var;
@@ -1658,6 +1664,8 @@
if (!strcmp(confno, cnf->confno))
break;
}
+ if (cnf)
+ ast_atomic_fetchadd_int(&cnf->refcount, refcount);
ast_mutex_unlock(&conflock);
if (!cnf) {
@@ -1670,9 +1678,9 @@
if (ast_app_getdata(chan, "conf-getpin", dynamic_pin, AST_MAX_EXTENSION - 1, 0) < 0)
return NULL;
}
- cnf = build_conf(confno, dynamic_pin, "", make, dynamic);
+ cnf = build_conf(confno, dynamic_pin, "", make, dynamic, refcount);
} else {
- cnf = build_conf(confno, "", "", make, dynamic);
+ cnf = build_conf(confno, "", "", make, dynamic, refcount);
}
} else {
/* Check the config */
@@ -1694,14 +1702,14 @@
/* Bingo it's a valid conference */
if (pin)
if (pinadmin)
- cnf = build_conf(confno, pin, pinadmin, make, dynamic);
+ cnf = build_conf(confno, pin, pinadmin, make, dynamic, refcount);
else
- cnf = build_conf(confno, pin, "", make, dynamic);
+ cnf = build_conf(confno, pin, "", make, dynamic, refcount);
else
if (pinadmin)
- cnf = build_conf(confno, "", pinadmin, make, dynamic);
+ cnf = build_conf(confno, "", pinadmin, make, dynamic, refcount);
else
- cnf = build_conf(confno, "", "", make, dynamic);
+ cnf = build_conf(confno, "", "", make, dynamic, refcount);
break;
}
}
@@ -1764,10 +1772,11 @@
}
confnum = strsep(&localdata,"|");
- conf = find_conf(chan, confnum, 0, 0, NULL, NULL);
- if (conf)
+ conf = find_conf(chan, confnum, 0, 0, NULL, 1, NULL);
+ if (conf) {
count = conf->users;
- else
+ ast_atomic_fetchadd_int(&conf->refcount, -1);
+ } else
count = 0;
if (!ast_strlen_zero(localdata)){
@@ -1952,7 +1961,7 @@
}
if (!ast_strlen_zero(confno)) {
/* Check the validity of the conference */
- cnf = find_conf(chan, confno, 1, dynamic, the_pin, &confflags);
+ cnf = find_conf(chan, confno, 1, dynamic, the_pin, 1, &confflags);
if (!cnf) {
res = ast_streamfile(chan, "conf-invalid", chan->language);
if (!res)
@@ -1998,8 +2007,13 @@
ast_log(LOG_WARNING, "Couldn't play invalid pin msg!\n");
break;
}
- if (res < 0)
+ if (res < 0) {
+ ast_mutex_lock(&conflock);
+ if (ast_atomic_dec_and_test(&cnf->refcount))
+ conf_free(cnf);
+ ast_mutex_unlock(&conflock);
break;
+ }
pin[0] = res;
pin[1] = '\0';
res = -1;
@@ -2012,9 +2026,8 @@
allowretry = 0;
/* see if we need to get rid of the conference */
ast_mutex_lock(&conflock);
- if (!cnf->users) {
+ if (ast_atomic_dec_and_test(&cnf->refcount))
conf_free(cnf);
- }
ast_mutex_unlock(&conflock);
break;
}
Modified: branches/1.2/include/asterisk/lock.h
URL: http://svn.digium.com/view/asterisk/branches/1.2/include/asterisk/lock.h?view=diff&rev=53133&r1=53132&r2=53133
==============================================================================
--- branches/1.2/include/asterisk/lock.h (original)
+++ branches/1.2/include/asterisk/lock.h Sat Feb 3 14:38:13 2007
@@ -666,4 +666,31 @@
#define pthread_create __use_ast_pthread_create_instead__
#endif
+int ast_atomic_fetchadd_int_slow(volatile int *p, int v);
+
+#include "asterisk/inline_api.h"
+
+#if defined (__i386__)
+AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
+{
+ __asm __volatile (
+ " lock xaddl %0, %1 ; "
+ : "+r" (v), /* 0 (result) */
+ "=m" (*p) /* 1 */
+ : "m" (*p)); /* 2 */
+ return (v);
+})
+#else /* low performance version in utils.c */
+AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
+{
+ return ast_atomic_fetchadd_int_slow(p, v);
+})
+#endif
+
+AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
+{
+ int a = ast_atomic_fetchadd_int(p, -1);
+ return a == 1; /* true if the value is 0 now (so it was 1 previously) */
+})
+
#endif /* _ASTERISK_LOCK_H */
Modified: branches/1.2/utils.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/utils.c?view=diff&rev=53133&r1=53132&r2=53133
==============================================================================
--- branches/1.2/utils.c (original)
+++ branches/1.2/utils.c Sat Feb 3 14:38:13 2007
@@ -907,3 +907,14 @@
#endif
}
+AST_MUTEX_DEFINE_STATIC(fetchadd_m); /* used for all fetc&add ops */
+
+int ast_atomic_fetchadd_int_slow(volatile int *p, int v)
+{
+ int ret;
+ ast_mutex_lock(&fetchadd_m);
+ ret = *p;
+ *p += v;
+ ast_mutex_unlock(&fetchadd_m);
+ return ret;
+}
More information about the asterisk-commits
mailing list