[asterisk-commits] tilghman: trunk r180259 - /trunk/main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Mar 4 14:49:22 CST 2009
Author: tilghman
Date: Wed Mar 4 14:48:42 2009
New Revision: 180259
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=180259
Log:
Spacing changes only
Modified:
trunk/main/abstract_jb.c
trunk/main/acl.c
trunk/main/aescrypt.c
trunk/main/alaw.c
trunk/main/app.c
Modified: trunk/main/abstract_jb.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/abstract_jb.c?view=diff&rev=180259&r1=180258&r2=180259
==============================================================================
--- trunk/main/abstract_jb.c (original)
+++ trunk/main/abstract_jb.c Wed Mar 4 14:48:42 2009
@@ -23,7 +23,7 @@
/*! \file
*
* \brief Common implementation-independent jitterbuffer stuff.
- *
+ *
* \author Slav Klenov <slav at securax.org>
*
*
@@ -110,7 +110,7 @@
static void jb_empty_and_reset_adaptive(void *jb);
/* Available jb implementations */
-static struct ast_jb_impl avail_impl[] =
+static struct ast_jb_impl avail_impl[] =
{
{
.name = "fixed",
@@ -183,12 +183,13 @@
struct ast_jb_conf *jbconf = &jb->conf;
struct ast_jb_impl *test_impl;
int i, avail_impl_count = ARRAY_LEN(avail_impl);
-
+
jb->impl = &avail_impl[default_impl];
-
- if (ast_strlen_zero(jbconf->impl))
+
+ if (ast_strlen_zero(jbconf->impl)) {
return;
-
+ }
+
for (i = 0; i < avail_impl_count; i++) {
test_impl = &avail_impl[i];
if (!strcasecmp(jbconf->impl, test_impl->name)) {
@@ -229,14 +230,14 @@
}
ast_set_flag(jb0, JB_TIMEBASE_INITIALIZED);
}
-
+
if (!c0_jb_created) {
jb_choose_impl(c0);
}
inuse = 1;
}
-
+
/* Determine whether audio going to c1 needs a jitter buffer */
if (((!c1_wants_jitter && c0_creates_jitter) || (c1_force_jb && c0_creates_jitter)) && c1_jb_enabled) {
ast_set_flag(jb1, JB_USE);
@@ -248,7 +249,7 @@
}
ast_set_flag(jb1, JB_TIMEBASE_INITIALIZED);
}
-
+
if (!c1_jb_created) {
jb_choose_impl(c1);
}
@@ -269,32 +270,32 @@
int c1_jb_is_created = ast_test_flag(jb1, JB_CREATED);
int wait, wait0, wait1;
struct timeval tv_now;
-
+
if (time_left == 0) {
/* No time left - the bridge will be retried */
/* TODO: Test disable this */
/*return 0;*/
}
-
+
if (time_left < 0) {
time_left = INT_MAX;
}
-
+
gettimeofday(&tv_now, NULL);
-
+
wait0 = (c0_use_jb && c0_jb_is_created) ? jb0->next - get_now(jb0, &tv_now) : time_left;
wait1 = (c1_use_jb && c1_jb_is_created) ? jb1->next - get_now(jb1, &tv_now) : time_left;
-
+
wait = wait0 < wait1 ? wait0 : wait1;
wait = wait < time_left ? wait : time_left;
-
+
if (wait == INT_MAX) {
wait = -1;
} else if (wait < 1) {
/* don't let wait=0, because this can cause the pbx thread to loop without any sleeping at all */
wait = 1;
}
-
+
return wait;
}
@@ -306,7 +307,7 @@
void *jbobj = jb->jbobj;
struct ast_frame *frr;
long now = 0;
-
+
if (!ast_test_flag(jb, JB_USE))
return -1;
@@ -315,7 +316,7 @@
jb_framelog("JB_PUT {now=%ld}: Received DTMF frame. Force resynching jb...\n", now);
jbimpl->force_resync(jbobj);
}
-
+
return -1;
}
@@ -350,7 +351,7 @@
jb_framelog("JB_PUT {now=%ld}: Dropped frame with ts=%ld and len=%ld\n", now, frr->ts, frr->len);
ast_frfree(frr);
/*return -1;*/
- /* TODO: Check this fix - should return 0 here, because the dropped frame shouldn't
+ /* TODO: Check this fix - should return 0 here, because the dropped frame shouldn't
be delivered at all */
return 0;
}
@@ -372,10 +373,10 @@
int c0_jb_is_created = ast_test_flag(jb0, JB_CREATED);
int c1_use_jb = ast_test_flag(jb1, JB_USE);
int c1_jb_is_created = ast_test_flag(jb1, JB_CREATED);
-
+
if (c0_use_jb && c0_jb_is_created)
jb_get_and_deliver(c0);
-
+
if (c1_use_jb && c1_jb_is_created)
jb_get_and_deliver(c1);
}
@@ -389,19 +390,19 @@
struct ast_frame *f, finterp;
long now;
int interpolation_len, res;
-
+
now = get_now(jb, NULL);
jb->next = jbimpl->next(jbobj);
if (now < jb->next) {
jb_framelog("\tJB_GET {now=%ld}: now < next=%ld\n", now, jb->next);
return;
}
-
+
while (now >= jb->next) {
interpolation_len = ast_codec_interp_len(jb->last_format);
-
+
res = jbimpl->get(jbobj, &f, now, interpolation_len);
-
+
switch (res) {
case JB_IMPL_OK:
/* deliver the frame */
@@ -439,7 +440,7 @@
ast_assert("JB type unknown" == NULL);
break;
}
-
+
jb->next = jbimpl->next(jbobj);
}
}
@@ -462,10 +463,10 @@
ast_log(LOG_WARNING, "Failed to create jitterbuffer on channel '%s'\n", chan->name);
return -1;
}
-
+
now = get_now(jb, NULL);
res = jbimpl->put_first(jbobj, frr, now);
-
+
/* The result of putting the first frame should not differ from OK. However, its possible
some implementations (i.e. adaptive's when resynch_threshold is specified) to drop it. */
if (res != JB_IMPL_OK) {
@@ -475,30 +476,30 @@
return -1;
*/
}
-
+
/* Init next */
jb->next = jbimpl->next(jbobj);
-
+
/* Init last format for a first time. */
jb->last_format = frr->subclass;
-
+
/* Create a frame log file */
if (ast_test_flag(jbconf, AST_JB_LOG)) {
char safe_logfile[30] = "/tmp/logfile-XXXXXX";
int safe_fd;
snprintf(name2, sizeof(name2), "%s", chan->name);
- tmp = strchr(name2, '/');
- if (tmp)
+ if ((tmp = strchr(name2, '/'))) {
*tmp = '#';
-
+ }
+
bridged = ast_bridged_channel(chan);
/* We should always have bridged chan if a jitterbuffer is in use */
ast_assert(bridged != NULL);
snprintf(name1, sizeof(name1), "%s", bridged->name);
- tmp = strchr(name1, '/');
- if (tmp)
+ if ((tmp = strchr(name1, '/'))) {
*tmp = '#';
+ }
snprintf(logfile_pathname, sizeof(logfile_pathname),
"/tmp/ast_%s_jb_%s--%s.log", jbimpl->name, name1, name2);
@@ -510,20 +511,22 @@
ast_log(LOG_ERROR, "Failed to create frame log file with pathname '%s': %s\n", logfile_pathname, strerror(errno));
}
- if (res == JB_IMPL_OK)
+ if (res == JB_IMPL_OK) {
jb_framelog("JB_PUT_FIRST {now=%ld}: Queued frame with ts=%ld and len=%ld\n",
now, frr->ts, frr->len);
- else
+ } else {
jb_framelog("JB_PUT_FIRST {now=%ld}: Dropped frame with ts=%ld and len=%ld\n",
now, frr->ts, frr->len);
+ }
}
ast_verb(3, "%s jitterbuffer created on channel %s\n", jbimpl->name, chan->name);
-
+
/* Free the frame if it has not been queued in the jb */
- if (res != JB_IMPL_OK)
+ if (res != JB_IMPL_OK) {
ast_frfree(frr);
-
+ }
+
return 0;
}
@@ -539,16 +542,16 @@
fclose(jb->logfile);
jb->logfile = NULL;
}
-
+
if (ast_test_flag(jb, JB_CREATED)) {
/* Remove and free all frames still queued in jb */
while (jbimpl->remove(jbobj, &f) == JB_IMPL_OK) {
ast_frfree(f);
}
-
+
jbimpl->destroy(jbobj);
jb->jbobj = NULL;
-
+
ast_clear_flag(jb, JB_CREATED);
ast_verb(3, "%s jitterbuffer destroyed on channel %s\n", jbimpl->name, chan->name);
@@ -574,12 +577,13 @@
int prefixlen = sizeof(AST_JB_CONF_PREFIX) - 1;
const char *name;
int tmp;
-
- if (strncasecmp(AST_JB_CONF_PREFIX, varname, prefixlen))
+
+ if (strncasecmp(AST_JB_CONF_PREFIX, varname, prefixlen)) {
return -1;
-
+ }
+
name = varname + prefixlen;
-
+
if (!strcasecmp(name, AST_JB_CONF_ENABLE)) {
ast_set2_flag(conf, ast_true(value), AST_JB_ENABLED);
} else if (!strcasecmp(name, AST_JB_CONF_FORCE)) {
@@ -598,7 +602,7 @@
} else {
return -1;
}
-
+
return 0;
}
@@ -648,7 +652,7 @@
static void jb_destroy_fixed(void *jb)
{
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
-
+
/* destroy the jb */
fixed_jb_destroy(fixedjb);
}
@@ -658,9 +662,9 @@
{
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
int res;
-
+
res = fixed_jb_put_first(fixedjb, fin, fin->len, fin->ts, now);
-
+
return fixed_to_abstract_code[res];
}
@@ -669,9 +673,9 @@
{
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
int res;
-
+
res = fixed_jb_put(fixedjb, fin, fin->len, fin->ts, now);
-
+
return fixed_to_abstract_code[res];
}
@@ -681,10 +685,10 @@
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
struct fixed_jb_frame frame;
int res;
-
+
res = fixed_jb_get(fixedjb, &frame, now, interpl);
*fout = frame.data;
-
+
return fixed_to_abstract_code[res];
}
@@ -692,7 +696,7 @@
static long jb_next_fixed(void *jb)
{
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
-
+
return fixed_jb_next(fixedjb);
}
@@ -702,10 +706,10 @@
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
struct fixed_jb_frame frame;
int res;
-
+
res = fixed_jb_remove(fixedjb, &frame);
*fout = frame.data;
-
+
return fixed_to_abstract_code[res];
}
@@ -713,7 +717,7 @@
static void jb_force_resynch_fixed(void *jb)
{
struct fixed_jb *fixedjb = (struct fixed_jb *) jb;
-
+
fixed_jb_set_force_resynch(fixedjb);
}
@@ -741,7 +745,7 @@
jbconf.max_contig_interp = 10;
jb_setconf(adaptivejb, &jbconf);
}
-
+
return adaptivejb;
}
@@ -749,7 +753,7 @@
static void jb_destroy_adaptive(void *jb)
{
jitterbuf *adaptivejb = (jitterbuf *) jb;
-
+
jb_destroy(adaptivejb);
}
@@ -764,9 +768,9 @@
{
jitterbuf *adaptivejb = (jitterbuf *) jb;
int res;
-
+
res = jb_put(adaptivejb, fin, JB_TYPE_VOICE, fin->len, fin->ts, now);
-
+
return adaptive_to_abstract_code[res];
}
@@ -776,10 +780,10 @@
jitterbuf *adaptivejb = (jitterbuf *) jb;
jb_frame frame;
int res;
-
+
res = jb_get(adaptivejb, &frame, now, interpl);
*fout = frame.data;
-
+
return adaptive_to_abstract_code[res];
}
@@ -787,7 +791,7 @@
static long jb_next_adaptive(void *jb)
{
jitterbuf *adaptivejb = (jitterbuf *) jb;
-
+
return jb_next(adaptivejb);
}
@@ -797,10 +801,10 @@
jitterbuf *adaptivejb = (jitterbuf *) jb;
jb_frame frame;
int res;
-
+
res = jb_getall(adaptivejb, &frame);
*fout = frame.data;
-
+
return adaptive_to_abstract_code[res];
}
Modified: trunk/main/acl.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/acl.c?view=diff&rev=180259&r1=180258&r2=180259
==============================================================================
--- trunk/main/acl.c (original)
+++ trunk/main/acl.c Wed Mar 4 14:48:42 2009
@@ -61,36 +61,37 @@
address = ast_inet_ntoa(sin->sin_addr);
/* RFC 1700 alias for the local network */
- if (address[0] == '0')
+ if (address[0] == '0') {
score = -25;
/* RFC 1700 localnet */
- else if (strncmp(address, "127", 3) == 0)
+ } else if (strncmp(address, "127", 3) == 0) {
score = -20;
/* RFC 1918 non-public address space */
- else if (strncmp(address, "10.", 3) == 0)
+ } else if (strncmp(address, "10.", 3) == 0) {
score = -5;
/* RFC 1918 non-public address space */
- else if (strncmp(address, "172", 3) == 0) {
+ } else if (strncmp(address, "172", 3) == 0) {
/* 172.16.0.0 - 172.19.255.255, but not 172.160.0.0 - 172.169.255.255 */
- if (address[4] == '1' && address[5] >= '6' && address[6] == '.')
+ if (address[4] == '1' && address[5] >= '6' && address[6] == '.') {
score = -5;
/* 172.20.0.0 - 172.29.255.255, but not 172.200.0.0 - 172.255.255.255 nor 172.2.0.0 - 172.2.255.255 */
- else if (address[4] == '2' && address[6] == '.')
+ } else if (address[4] == '2' && address[6] == '.') {
score = -5;
/* 172.30.0.0 - 172.31.255.255 */
- else if (address[4] == '3' && address[5] <= '1')
+ } else if (address[4] == '3' && address[5] <= '1') {
score = -5;
/* All other 172 addresses are public */
- else
+ } else {
score = 0;
- /* RFC 2544 Benchmark test range */
- } else if (strncmp(address, "198.1", 5) == 0 && address[5] >= '8' && address[6] == '.')
+ }
+ /* RFC 2544 Benchmark test range (198.18.0.0 - 198.19.255.255, but not 198.180.0.0 - 198.199.255.255) */
+ } else if (strncmp(address, "198.1", 5) == 0 && address[5] >= '8' && address[6] == '.') {
score = -10;
/* RFC 1918 non-public address space */
- else if (strncmp(address, "192.168", 7) == 0)
+ } else if (strncmp(address, "192.168", 7) == 0) {
score = -5;
/* RFC 3330 Zeroconf network */
- else if (strncmp(address, "169.254", 7) == 0)
+ } else if (strncmp(address, "169.254", 7) == 0) {
/*!\note Better score than a test network, but not quite as good as RFC 1918
* address space. The reason is that some Linux distributions automatically
* configure a Zeroconf address before trying DHCP, so we want to prefer a
@@ -98,11 +99,12 @@
*/
score = -10;
/* RFC 3330 Test network */
- else if (strncmp(address, "192.0.2.", 8) == 0)
+ } else if (strncmp(address, "192.0.2.", 8) == 0) {
score = -15;
/* Every other address should be publically routable */
- else
+ } else {
score = 0;
+ }
if (score > *best_score) {
*best_score = score;
@@ -149,8 +151,9 @@
score_address(sin, &best_addr, &best_score);
res = 0;
- if (best_score == 0)
+ if (best_score == 0) {
break;
+ }
}
}
#endif /* BSD_OR_LINUX */
@@ -189,21 +192,23 @@
score_address(sa, &best_addr, &best_score);
res = 0;
- if (best_score == 0)
+ if (best_score == 0) {
break;
+ }
}
free(buf);
#endif /* SOLARIS */
-
+
close(s);
}
#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(__linux__) || defined(__Darwin__)
freeifaddrs(ifaphead);
#endif /* BSD_OR_LINUX */
- if (res == 0 && ourip)
+ if (res == 0 && ourip) {
memcpy(ourip, &best_addr, sizeof(*ourip));
+ }
return res;
}
#endif /* HAVE_GETIFADDRS */
@@ -250,16 +255,18 @@
while (start) {
current = ast_duplicate_ha(start); /* Create copy of this object */
- if (prev)
- prev->next = current; /* Link previous to this object */
-
- if (!ret)
- ret = current; /* Save starting point */
-
- start = start->next; /* Go to next object */
- prev = current; /* Save pointer to this object */
- }
- return ret; /* Return start of list */
+ if (prev) {
+ prev->next = current; /* Link previous to this object */
+ }
+
+ if (!ret) {
+ ret = current; /* Save starting point */
+ }
+
+ start = start->next; /* Go to next object */
+ prev = current; /* Save pointer to this object */
+ }
+ return ret; /* Return start of list */
}
struct ast_ha *ast_append_ha(const char *sense, const char *stuff, struct ast_ha *path, int *error)
@@ -277,12 +284,11 @@
path = path->next;
}
- ha = ast_malloc(sizeof(*ha));
- if (!ha)
+ if (!(ha = ast_malloc(sizeof(*ha)))) {
return ret;
-
- nm = strchr(tmp, '/');
- if (!nm) {
+ }
+
+ if (!(nm = strchr(tmp, '/'))) {
/* assume /32. Yes, htonl does not do anything for this particular mask
but we better use it to show we remember about byte order */
ha->netmask.s_addr = htonl(0xFFFFFFFF);
@@ -291,20 +297,22 @@
nm++;
if (!strchr(nm, '.')) {
- if ((sscanf(nm, "%d", &x) == 1) && (x >= 0) && (x <= 32))
+ if ((sscanf(nm, "%d", &x) == 1) && (x >= 0) && (x <= 32)) {
ha->netmask.s_addr = htonl(0xFFFFFFFF << (32 - x));
- else {
+ } else {
ast_log(LOG_WARNING, "Invalid CIDR in %s\n", stuff);
ast_free(ha);
- if (error)
+ if (error) {
*error = 1;
+ }
return ret;
}
} else if (!inet_aton(nm, &ha->netmask)) {
ast_log(LOG_WARNING, "Invalid mask in %s\n", stuff);
ast_free(ha);
- if (error)
+ if (error) {
*error = 1;
+ }
return ret;
}
}
@@ -312,8 +320,9 @@
if (!inet_aton(tmp, &ha->netaddr)) {
ast_log(LOG_WARNING, "Invalid IP address in %s\n", stuff);
ast_free(ha);
- if (error)
+ if (error) {
*error = 1;
+ }
return ret;
}
@@ -348,8 +357,9 @@
#endif
/* For each rule, if this address and the netmask = the net address
apply the current rule */
- if ((sin->sin_addr.s_addr & ha->netmask.s_addr) == ha->netaddr.s_addr)
+ if ((sin->sin_addr.s_addr & ha->netmask.s_addr) == ha->netaddr.s_addr) {
res = ha->sense;
+ }
ha = ha->next;
}
return res;
@@ -369,8 +379,7 @@
value = host;
}
}
- hp = ast_gethostbyname(value, &ahp);
- if (hp) {
+ if ((hp = ast_gethostbyname(value, &ahp))) {
memcpy(&sin->sin_addr, hp->h_addr, sizeof(sin->sin_addr));
} else {
ast_log(LOG_WARNING, "Unable to lookup '%s'\n", value);
@@ -410,17 +419,17 @@
{ "EF", 0x2E },
};
-int ast_str2cos(const char *value, unsigned int *cos)
+int ast_str2cos(const char *value, unsigned int *cos)
{
int fval;
-
+
if (sscanf(value, "%d", &fval) == 1) {
if (fval < 8) {
- *cos = fval;
+ *cos = fval;
return 0;
}
}
-
+
return -1;
}
@@ -449,8 +458,9 @@
unsigned int x;
for (x = 0; x < ARRAY_LEN(dscp_pool1); x++) {
- if (dscp_pool1[x].space == (tos >> 2))
+ if (dscp_pool1[x].space == (tos >> 2)) {
return dscp_pool1[x].name;
+ }
}
return "unknown";
@@ -467,8 +477,7 @@
struct sockaddr_in sin;
socklen_t slen;
- s = socket(PF_INET, SOCK_DGRAM, 0);
- if (s < 0) {
+ if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
ast_log(LOG_ERROR, "Cannot create socket\n");
return -1;
}
@@ -509,8 +518,7 @@
if (gethostname(ourhost, sizeof(ourhost) - 1)) {
ast_log(LOG_WARNING, "Unable to get hostname\n");
} else {
- hp = ast_gethostbyname(ourhost, &ahp);
- if (hp) {
+ if ((hp = ast_gethostbyname(ourhost, &ahp))) {
memcpy(ourip, hp->h_addr, sizeof(*ourip));
ast_debug(3, "Found one IP address based on local hostname %s.\n", ourhost);
return 0;
@@ -518,8 +526,9 @@
}
ast_debug(3, "Trying to check A.ROOT-SERVERS.NET and get our IP address for that connection\n");
/* A.ROOT-SERVERS.NET. */
- if (inet_aton("198.41.0.4", &saddr) && !ast_ouraddrfor(&saddr, ourip))
+ if (inet_aton("198.41.0.4", &saddr) && !ast_ouraddrfor(&saddr, ourip)) {
return 0;
+ }
return get_local_address(ourip);
}
Modified: trunk/main/aescrypt.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/aescrypt.c?view=diff&rev=180259&r1=180258&r2=180259
==============================================================================
--- trunk/main/aescrypt.c (original)
+++ trunk/main/aescrypt.c Wed Mar 4 14:48:42 2009
@@ -122,7 +122,7 @@
aes_32t nr = (kp[45] ^ kp[52] ^ kp[53] ? kp[52] : 14);
#ifdef AES_ERR_CHK
- if( (nr != 10 || !(kp[0] | kp[3] | kp[4]))
+ if( (nr != 10 || !(kp[0] | kp[3] | kp[4]))
&& (nr != 12 || !(kp[0] | kp[5] | kp[6]))
&& (nr != 14 || !(kp[0] | kp[7] | kp[8])) )
return aes_error;
@@ -246,7 +246,7 @@
const aes_32t *kp = cx->ks + nr * N_COLS;
#ifdef AES_ERR_CHK
- if( (nr != 10 || !(cx->ks[0] | cx->ks[3] | cx->ks[4]))
+ if( (nr != 10 || !(cx->ks[0] | cx->ks[3] | cx->ks[4]))
&& (nr != 12 || !(cx->ks[0] | cx->ks[5] | cx->ks[6]))
&& (nr != 14 || !(cx->ks[0] | cx->ks[7] | cx->ks[8])) )
return aes_error;
Modified: trunk/main/alaw.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/alaw.c?view=diff&rev=180259&r1=180258&r2=180259
==============================================================================
--- trunk/main/alaw.c (original)
+++ trunk/main/alaw.c Wed Mar 4 14:48:42 2009
@@ -20,7 +20,7 @@
*
* \brief a-Law to Signed linear conversion
*
- * \author Mark Spencer <markster at digium.com>
+ * \author Mark Spencer <markster at digium.com>
*/
#include "asterisk.h"
@@ -83,16 +83,16 @@
7,7,7,7,7,7,7,7 };
unsigned sign, exponent, mantissa, mag;
unsigned char alawbyte;
-
+
ast_alaw_get_sign_mag(sample, &sign, &mag);
if (mag > 32767)
mag = 32767; /* clip the magnitude for -32768 */
-
+
exponent = exp_lut[(mag >> 8) & 0x7f];
mantissa = (mag >> (exponent + 3)) & 0x0f;
if (mag < 0x100)
exponent = 0;
-
+
if (full_coding) {
/* full encoding, with sign and xform */
alawbyte = (unsigned char)(sign | (exponent << 4) | mantissa);
@@ -124,7 +124,7 @@
{
unsigned exponent, mantissa;
short sample;
-
+
alawbyte ^= AST_ALAW_AMI_MASK;
exponent = (alawbyte & 0x70) >> 4;
mantissa = alawbyte & 0x0f;
@@ -149,9 +149,9 @@
void ast_alaw_init(void)
{
int i;
- /*
+ /*
* Set up mu-law conversion table
- */
+ */
#ifndef G711_NEW_ALGORITHM
for (i = 0; i < 256; i++) {
__ast_alaw[i] = alaw2linear(i);
@@ -169,7 +169,7 @@
AST_LIN2A_LOOKUP(i) = linear2alaw(i, 0 /* half-cooked */);
}
#endif
-
+
#ifdef TEST_CODING_TABLES
for (i = -32768; i < 32768; ++i) {
#ifndef G711_NEW_ALGORITHM
@@ -181,7 +181,7 @@
unsigned char e2 = AST_LIN2A(i);
short d2 = alaw2linear(e2);
short d3 = AST_ALAW(e1);
-
+
if (e1 != e2 || d1 != d3 || d2 != d3) {
ast_log(LOG_WARNING, "a-Law coding tables test failed on %d: e1=%u, e2=%u, d1=%d, d2=%d\n",
i, (unsigned)e1, (unsigned)e2, (int)d1, (int)d2);
@@ -189,7 +189,7 @@
}
ast_log(LOG_NOTICE, "a-Law coding tables test complete.\n");
#endif /* TEST_CODING_TABLES */
-
+
#ifdef TEST_TANDEM_TRANSCODING
/* tandem transcoding test */
for (i = -32768; i < 32768; ++i) {
@@ -199,7 +199,7 @@
short d2 = AST_ALAW(e2);
unsigned char e3 = AST_LIN2A(d2);
short d3 = AST_ALAW(e3);
-
+
if (e1 != e2 || e2 != e3 || d1 != d2 || d2 != d3) {
ast_log(LOG_WARNING, "a-Law tandem transcoding test failed on %d: e1=%u, e2=%u, d1=%d, d2=%d, d3=%d\n",
i, (unsigned)e1, (unsigned)e2, (int)d1, (int)d2, (int)d3);
@@ -207,6 +207,6 @@
}
ast_log(LOG_NOTICE, "a-Law tandem transcoding test complete.\n");
#endif /* TEST_TANDEM_TRANSCODING */
-
-}
-
+
+}
+
Modified: trunk/main/app.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/app.c?view=diff&rev=180259&r1=180258&r2=180259
==============================================================================
--- trunk/main/app.c (original)
+++ trunk/main/app.c Wed Mar 4 14:48:42 2009
@@ -20,7 +20,7 @@
*
* \brief Convenient Application Routines
*
- * \author Mark Spencer <markster at digium.com>
+ * \author Mark Spencer <markster at digium.com>
*/
#include "asterisk.h"
@@ -60,27 +60,28 @@
static AST_RWLIST_HEAD_STATIC(groups, ast_group_info);
/*!
- * \brief This function presents a dialtone and reads an extension into 'collect'
- * which must be a pointer to a **pre-initialized** array of char having a
- * size of 'size' suitable for writing to. It will collect no more than the smaller
+ * \brief This function presents a dialtone and reads an extension into 'collect'
+ * which must be a pointer to a **pre-initialized** array of char having a
+ * size of 'size' suitable for writing to. It will collect no more than the smaller
* of 'maxlen' or 'size' minus the original strlen() of collect digits.
* \param chan struct.
- * \param context
- * \param collect
- * \param size
+ * \param context
+ * \param collect
+ * \param size
* \param maxlen
* \param timeout timeout in seconds
*
* \return 0 if extension does not exist, 1 if extension exists
*/
-int ast_app_dtget(struct ast_channel *chan, const char *context, char *collect, size_t size, int maxlen, int timeout)
+int ast_app_dtget(struct ast_channel *chan, const char *context, char *collect, size_t size, int maxlen, int timeout)
{
struct ast_tone_zone_sound *ts;
int res = 0, x = 0;
- if (maxlen > size)
+ if (maxlen > size) {
maxlen = size;
-
+ }
+
if (!timeout && chan->pbx) {
timeout = chan->pbx->dtimeoutms / 1000.0;
} else if (!timeout) {
@@ -93,22 +94,27 @@
} else {
ast_log(LOG_NOTICE, "Huh....? no dial for indications?\n");
}
-
+
for (x = strlen(collect); x < maxlen; ) {
res = ast_waitfordigit(chan, timeout);
- if (!ast_ignore_pattern(context, collect))
+ if (!ast_ignore_pattern(context, collect)) {
ast_playtones_stop(chan);
- if (res < 1)
+ }
+ if (res < 1) {
break;
- if (res == '#')
+ }
+ if (res == '#') {
break;
+ }
collect[x++] = res;
- if (!ast_matchmore_extension(chan, context, collect, 1, chan->cid.cid_num))
+ if (!ast_matchmore_extension(chan, context, collect, 1, chan->cid.cid_num)) {
break;
- }
-
- if (res >= 0)
+ }
+ }
+
+ if (res >= 0) {
res = ast_exists_extension(chan, context, collect, 1, chan->cid.cid_num) ? 1 : 0;
+ }
return res;
}
@@ -127,7 +133,7 @@
char *front, *filename;
/* XXX Merge with full version? XXX */
-
+
if (maxlen)
s[0] = '\0';
@@ -146,14 +152,16 @@
fto = c->pbx ? c->pbx->rtimeoutms : 6000;
to = c->pbx ? c->pbx->dtimeoutms : 2000;
- if (timeout > 0)
+ if (timeout > 0) {
fto = to = timeout;
- if (timeout < 0)
+ }
+ if (timeout < 0) {
fto = to = 1000000000;
+ }
} else {
/* there is more than one prompt, so
- get rid of the long timeout between
- prompts, and make it 50ms */
+ * get rid of the long timeout between
+ * prompts, and make it 50ms */
fto = 50;
to = c->pbx ? c->pbx->dtimeoutms : 2000;
}
@@ -178,14 +186,17 @@
if (!ast_strlen_zero(prompt)) {
res = ast_streamfile(c, prompt, c->language);
- if (res < 0)
+ if (res < 0) {
return res;
- }
-
- if (timeout > 0)
+ }
+ }
+
+ if (timeout > 0) {
fto = to = timeout;
- if (timeout < 0)
+ }
+ if (timeout < 0) {
fto = to = 1000000000;
+ }
res = ast_readstring_full(c, s, maxlen, to, fto, "#", audiofd, ctrlfd);
@@ -223,12 +234,12 @@
int ast_app_has_voicemail(const char *mailbox, const char *folder)
{
static int warned = 0;
- if (ast_has_voicemail_func)
+ if (ast_has_voicemail_func) {
return ast_has_voicemail_func(mailbox, folder);
-
- if (!warned) {
+ }
+
+ if (warned++ % 10 == 0) {
ast_verb(3, "Message check requested for mailbox %s/folder %s but voicemail not loaded.\n", mailbox, folder ? folder : "INBOX");
- warned++;
}
return 0;
}
@@ -247,8 +258,7 @@
return ast_inboxcount_func(mailbox, newmsgs, oldmsgs);
}
- if (!warned) {
- warned++;
+ if (warned++ % 10 == 0) {
ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox);
}
@@ -271,8 +281,7 @@
return ast_inboxcount2_func(mailbox, urgentmsgs, newmsgs, oldmsgs);
}
- if (!warned) {
- warned++;
+ if (warned++ % 10 == 0) {
ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox);
}
@@ -281,16 +290,18 @@
int ast_app_sayname(struct ast_channel *chan, const char *mailbox, const char *context)
{
- if (ast_sayname_func)
+ if (ast_sayname_func) {
return ast_sayname_func(chan, mailbox, context);
+ }
return -1;
}
int ast_app_messagecount(const char *context, const char *mailbox, const char *folder)
{
static int warned = 0;
- if (ast_messagecount_func)
+ if (ast_messagecount_func) {
return ast_messagecount_func(context, mailbox, folder);
+ }
if (!warned) {
warned++;
@@ -306,14 +317,17 @@
int res = 0;
struct ast_silence_generator *silgen = NULL;
- if (!between)
+ if (!between) {
between = 100;
-
- if (peer)
+ }
+
+ if (peer) {
res = ast_autoservice_start(peer);
-
- if (!res)
+ }
+
+ if (!res) {
res = ast_waitfor(chan, 100);
+ }
/* ast_waitfor will return the number of remaining ms on success */
if (res < 0) {
@@ -330,27 +344,32 @@
for (ptr = digits; *ptr; ptr++) {
if (*ptr == 'w') {
/* 'w' -- wait half a second */
- if ((res = ast_safe_sleep(chan, 500)))
+ if ((res = ast_safe_sleep(chan, 500))) {
break;
+ }
} else if (strchr("0123456789*#abcdfABCDF", *ptr)) {
/* Character represents valid DTMF */
if (*ptr == 'f' || *ptr == 'F') {
/* ignore return values if not supported by channel */
ast_indicate(chan, AST_CONTROL_FLASH);
- } else
+ } else {
ast_senddigit(chan, *ptr, duration);
+ }
/* pause between digits */
- if ((res = ast_safe_sleep(chan, between)))
+ if ((res = ast_safe_sleep(chan, between))) {
break;
- } else
+ }
+ } else {
ast_log(LOG_WARNING, "Illegal DTMF character '%c' in string. (0-9*#aAbBcCdD allowed)\n", *ptr);
+ }
}
if (peer) {
- /* Stop autoservice on the peer channel, but don't overwrite any error condition
+ /* Stop autoservice on the peer channel, but don't overwrite any error condition
that has occurred previously while acting on the primary channel */
- if (ast_autoservice_stop(peer) && !res)
+ if (ast_autoservice_stop(peer) && !res) {
res = -1;
+ }
}
if (silgen) {
@@ -370,12 +389,14 @@
static void linear_release(struct ast_channel *chan, void *params)
{
struct linear_state *ls = params;
-
- if (ls->origwfmt && ast_set_write_format(chan, ls->origwfmt))
+
+ if (ls->origwfmt && ast_set_write_format(chan, ls->origwfmt)) {
ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", chan->name, ls->origwfmt);
-
- if (ls->autoclose)
+ }
+
+ if (ls->autoclose) {
close(ls->fd);
+ }
ast_free(params);
}
@@ -402,8 +423,9 @@
f.datalen = res;
f.samples = res / 2;
ast_write(chan, &f);
- if (res == len)
+ if (res == len) {
return 0;
+ }
}
return -1;
}
@@ -412,14 +434,16 @@
{
struct linear_state *ls = params;
- if (!params)
+ if (!params) {
return NULL;
+ }
/* In this case, params is already malloc'd */
- if (ls->allowoverride)
+ if (ls->allowoverride) {
ast_set_flag(chan, AST_FLAG_WRITE_INT);
- else
+ } else {
ast_clear_flag(chan, AST_FLAG_WRITE_INT);
+ }
ls->origwfmt = chan->writeformat;
@@ -432,7 +456,7 @@
return params;
}
-static struct ast_generator linearstream =
+static struct ast_generator linearstream =
{
alloc: linear_alloc,
release: linear_release,
@@ -446,13 +470,15 @@
int res = -1;
int autoclose = 0;
if (fd < 0) {
- if (ast_strlen_zero(filename))
+ if (ast_strlen_zero(filename)) {
return -1;
+ }
autoclose = 1;
- if (filename[0] == '/')
+ if (filename[0] == '/') {
ast_copy_string(tmpf, filename, sizeof(tmpf));
- else
+ } else {
snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", ast_config_AST_DATA_DIR, "sounds", filename);
+ }
if ((fd = open(tmpf, O_RDONLY)) < 0) {
ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno));
return -1;
@@ -470,7 +496,7 @@
int ast_control_streamfile(struct ast_channel *chan, const char *file,
const char *fwd, const char *rev,
const char *stop, const char *suspend,
- const char *restart, int skipms, long *offsetms)
+ const char *restart, int skipms, long *offsetms)
{
char *breaks = NULL;
char *end = NULL;
@@ -479,28 +505,36 @@
long pause_restart_point = 0;
long offset = 0;
- if (offsetms)
+ if (offsetms) {
offset = *offsetms * 8; /* XXX Assumes 8kHz */
-
- if (stop)
+ }
+
+ if (stop) {
blen += strlen(stop);
- if (suspend)
+ }
+ if (suspend) {
blen += strlen(suspend);
- if (restart)
+ }
+ if (restart) {
blen += strlen(restart);
+ }
if (blen > 2) {
breaks = alloca(blen + 1);
breaks[0] = '\0';
- if (stop)
+ if (stop) {
strcat(breaks, stop);
- if (suspend)
+ }
+ if (suspend) {
strcat(breaks, suspend);
- if (restart)
+ }
+ if (restart) {
strcat(breaks, restart);
- }
- if (chan->_state != AST_STATE_UP)
+ }
+ }
+ if (chan->_state != AST_STATE_UP) {
res = ast_answer(chan);
+ }
if (file) {
if ((end = strchr(file, ':'))) {
@@ -520,8 +554,9 @@
pause_restart_point = 0;
}
else if (end || offset < 0) {
- if (offset == -8)
+ if (offset == -8) {
offset = 0;
+ }
ast_verb(3, "ControlPlayback seek to offset %ld from end\n", offset);
ast_seekstream(chan->stream, offset, SEEK_END);
@@ -531,12 +566,13 @@
ast_verb(3, "ControlPlayback seek to offset %ld\n", offset);
ast_seekstream(chan->stream, offset, SEEK_SET);
offset = 0;
- };
+ }
res = ast_waitstream_fr(chan, breaks, fwd, rev, skipms);
}
- if (res < 1)
+ if (res < 1) {
break;
+ }
/* We go at next loop if we got the restart char */
if (restart && strchr(restart, res)) {
@@ -549,11 +585,11 @@
pause_restart_point = ast_tellstream(chan->stream);
for (;;) {
ast_stopstream(chan);
- res = ast_waitfordigit(chan, 1000);
- if (!res)
+ if (!(res = ast_waitfordigit(chan, 1000))) {
continue;
- else if (res == -1 || strchr(suspend, res) || (stop && strchr(stop, res)))
+ } else if (res == -1 || strchr(suspend, res) || (stop && strchr(stop, res))) {
break;
+ }
}
if (res == *suspend) {
res = 0;
@@ -561,12 +597,14 @@
}
}
- if (res == -1)
+ if (res == -1) {
break;
+ }
/* if we get one of our stop chars, return it to the calling function */
- if (stop && strchr(stop, res))
+ if (stop && strchr(stop, res)) {
break;
+ }
}
if (pause_restart_point) {
@@ -579,12 +617,14 @@
}
}
- if (offsetms)
+ if (offsetms) {
*offsetms = offset / 8; /* samples --> ms ... XXX Assumes 8 kHz */
+ }
/* If we are returning a digit cast it as char */
- if (res > 0 || chan->stream)
+ if (res > 0 || chan->stream) {
res = (char)res;
+ }
ast_stopstream(chan);
@@ -595,8 +635,9 @@
{
int d = 0;
- if ((d = ast_streamfile(chan, fn, chan->language)))
+ if ((d = ast_streamfile(chan, fn, chan->language))) {
return d;
+ }
d = ast_waitstream(chan, AST_DIGIT_ANY);
@@ -616,7 +657,7 @@
* \param fmt Format(s) to record message in. Multiple formats may be specified by separating them with a '|'.
* \param duration Where to store actual length of the recorded message (in milliseconds).
* \param beep Whether to play a beep before starting to record.
- * \param silencethreshold
+ * \param silencethreshold
* \param maxsilence Length of silence that will end a recording (in milliseconds).
* \param path Optional filesystem path to unlock.
* \param prepend If true, prepend the recorded audio to an existing file.
@@ -640,11 +681,13 @@
struct ast_silence_generator *silgen = NULL;
char prependfile[80];
- if (silencethreshold < 0)
+ if (silencethreshold < 0) {
silencethreshold = global_silence_threshold;
-
- if (maxsilence < 0)
+ }
+
+ if (maxsilence < 0) {
maxsilence = global_maxsilence;
+ }
/* barf if no pointer passed to store duration in */
if (!duration) {
@@ -656,16 +699,19 @@
snprintf(comment, sizeof(comment), "Playing %s, Recording to: %s on %s\n", playfile ? playfile : "<None>", recordfile, chan->name);
if (playfile || beep) {
- if (!beep)
+ if (!beep) {
d = ast_play_and_wait(chan, playfile);
- if (d > -1)
+ }
+ if (d > -1) {
d = ast_stream_and_wait(chan, "beep", "");
- if (d < 0)
+ }
+ if (d < 0) {
return -1;
+ }
}
if (prepend) {
- ast_copy_string(prependfile, recordfile, sizeof(prependfile));
+ ast_copy_string(prependfile, recordfile, sizeof(prependfile));
strncat(prependfile, "-prepend", sizeof(prependfile) - strlen(prependfile) - 1);
}
@@ -689,12 +735,14 @@
others[x] = ast_writefile(prepend ? prependfile : recordfile, sfmt[x], comment, O_TRUNC, 0, AST_FILE_MODE);
ast_verb(3, "x=%d, open writing: %s format: %s, %p\n", x, prepend ? prependfile : recordfile, sfmt[x], others[x]);
- if (!others[x])
+ if (!others[x]) {
break;
- }
-
- if (path)
+ }
+ }
+
+ if (path) {
ast_unlock_path(path);
+ }
if (maxsilence > 0) {
sildet = ast_dsp_new(); /* Create the silence detector */
@@ -716,8 +764,9 @@
/* Request a video update */
ast_indicate(chan, AST_CONTROL_VIDUPDATE);
- if (ast_opt_transmit_silence)
+ if (ast_opt_transmit_silence) {
silgen = ast_channel_start_silence_generator(chan);
+ }
}
if (x == fmtcnt) {
@@ -725,12 +774,10 @@
we read a digit or get a hangup */
struct ast_frame *f;
for (;;) {
- res = ast_waitfor(chan, 2000);
- if (!res) {
+ if (!(res = ast_waitfor(chan, 2000))) {
ast_debug(1, "One waitfor failed, trying another\n");
/* Try one more time in case of masq */
- res = ast_waitfor(chan, 2000);
- if (!res) {
+ if (!(res = ast_waitfor(chan, 2000))) {
ast_log(LOG_WARNING, "No audio available on %s??\n", chan->name);
res = -1;
}
@@ -740,14 +787,15 @@
f = NULL;
break;
}
- f = ast_read(chan);
- if (!f)
+ if (!(f = ast_read(chan))) {
break;
+ }
if (f->frametype == AST_FRAME_VOICE) {
/* write each format */
for (x = 0; x < fmtcnt; x++) {
- if (prepend && !others[x])
+ if (prepend && !others[x]) {
break;
+ }
res = ast_writestream(others[x], f);
}
@@ -755,10 +803,11 @@
if (maxsilence > 0) {
int dspsilence = 0;
ast_dsp_silence(sildet, f, &dspsilence);
- if (dspsilence)
+ if (dspsilence) {
totalsilence = dspsilence;
- else
+ } else {
totalsilence = 0;
+ }
if (totalsilence > maxsilence) {
/* Ended happily with silence */
@@ -820,8 +869,9 @@
}
if (!prepend) {
- if (silgen)
+ if (silgen) {
ast_channel_stop_silence_generator(chan, silgen);
+ }
}
/*!\note
@@ -837,8 +887,9 @@
if (!prepend) {
for (x = 0; x < fmtcnt; x++) {
- if (!others[x])
+ if (!others[x]) {
break;
+ }
/*!\note
* If we ended with silence, trim all but the first 200ms of silence
* off the recording. However, if we ended with '#', we don't want
@@ -866,11 +917,13 @@
for (x = 0; x < fmtcnt; x++) {
snprintf(comment, sizeof(comment), "Opening the real file %s.%s\n", recordfile, sfmt[x]);
realfiles[x] = ast_readfile(recordfile, sfmt[x], comment, O_RDONLY, 0, 0);
- if (!others[x] || !realfiles[x])
+ if (!others[x] || !realfiles[x]) {
break;
+ }
/*!\note Same logic as above. */
- if (totalsilence)
+ if (totalsilence) {
ast_stream_rewind(others[x], totalsilence - 200);
+ }
ast_truncstream(others[x]);
/* add the original file too */
while ((fr = ast_readframe(realfiles[x]))) {
@@ -890,8 +943,9 @@
if (outmsg == 2) {
ast_stream_and_wait(chan, "auth-thankyou", "");
}
- if (sildet)
+ if (sildet) {
ast_dsp_free(sildet);
+ }
return res;
}
@@ -924,20 +978,20 @@
if (!ast_strlen_zero(data)) {
ast_copy_string(tmp, data, sizeof(tmp));
grp = tmp;
- cat = strchr(tmp, '@');
- if (cat) {
- *cat = '\0';
- cat++;
- }
- }
-
- if (!ast_strlen_zero(grp))
+ if ((cat = strchr(tmp, '@'))) {
+ *cat++ = '\0';
+ }
+ }
+
+ if (!ast_strlen_zero(grp)) {
ast_copy_string(group, grp, group_max);
- else
+ } else {
*group = '\0';
-
- if (!ast_strlen_zero(cat))
+ }
+
+ if (!ast_strlen_zero(cat)) {
ast_copy_string(category, cat, category_max);
+ }
return res;
}
@@ -948,15 +1002,17 @@
char group[80] = "", category[80] = "";
struct ast_group_info *gi = NULL;
size_t len = 0;
-
- if (ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category)))
+
+ if (ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category))) {
return -1;
-
+ }
+
/* Calculate memory we will need if this is new */
len = sizeof(*gi) + strlen(group) + 1;
- if (!ast_strlen_zero(category))
+ if (!ast_strlen_zero(category)) {
len += strlen(category) + 1;
-
+ }
+
AST_RWLIST_WRLOCK(&groups);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) {
if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
@@ -981,9 +1037,9 @@
} else {
res = -1;
}
-
+
AST_RWLIST_UNLOCK(&groups);
-
+
return res;
}
@@ -992,13 +1048,15 @@
struct ast_group_info *gi = NULL;
int count = 0;
- if (ast_strlen_zero(group))
+ if (ast_strlen_zero(group)) {
return 0;
-
+ }
+
AST_RWLIST_RDLOCK(&groups);
AST_RWLIST_TRAVERSE(&groups, gi, list) {
- if (!strcasecmp(gi->group, group) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category))))
+ if (!strcasecmp(gi->group, group) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
count++;
+ }
}
AST_RWLIST_UNLOCK(&groups);
@@ -1011,17 +1069,20 @@
regex_t regexbuf;
int count = 0;
- if (ast_strlen_zero(groupmatch))
+ if (ast_strlen_zero(groupmatch)) {
return 0;
+ }
/* if regex compilation fails, return zero matches */
- if (regcomp(®exbuf, groupmatch, REG_EXTENDED | REG_NOSUB))
+ if (regcomp(®exbuf, groupmatch, REG_EXTENDED | REG_NOSUB)) {
return 0;
+ }
AST_RWLIST_RDLOCK(&groups);
[... 477 lines stripped ...]
More information about the asterisk-commits
mailing list