[asterisk-commits] tilghman: branch group/ast_storage r74743 - in /team/group/ast_storage: ./ ch...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 11 16:28:25 CDT 2007


Author: tilghman
Date: Wed Jul 11 16:28:24 2007
New Revision: 74743

URL: http://svn.digium.com/view/asterisk?view=rev&rev=74743
Log:
Merged revisions 74703-74705,74713,74726 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
r74703 | file | 2007-07-11 15:07:07 -0500 (Wed, 11 Jul 2007) | 2 lines

Use linkedlist macros for UDPTL protocol list.

................
r74704 | file | 2007-07-11 15:40:33 -0500 (Wed, 11 Jul 2007) | 2 lines

Clean up pbx_spool. So many nested if statements...

................
r74705 | file | 2007-07-11 15:57:25 -0500 (Wed, 11 Jul 2007) | 2 lines

Code cleanup of res_smdi

................
r74713 | file | 2007-07-11 16:09:42 -0500 (Wed, 11 Jul 2007) | 2 lines

Code cleanup of res_agi

................
r74726 | mmichelson | 2007-07-11 16:15:47 -0500 (Wed, 11 Jul 2007) | 21 lines

Merged revisions 74722 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

................
r74722 | mmichelson | 2007-07-11 16:14:09 -0500 (Wed, 11 Jul 2007) | 13 lines

Merged revisions 74719 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r74719 | mmichelson | 2007-07-11 16:12:30 -0500 (Wed, 11 Jul 2007) | 5 lines

The cli command "agent logoff Agent/x soft" did not work...at all. Now it does.

(closes issue #10178, reported and patched by makoto, with slight modification for 1.4 and trunk by me)


........

................

................

Modified:
    team/group/ast_storage/   (props changed)
    team/group/ast_storage/channels/chan_agent.c
    team/group/ast_storage/include/asterisk/udptl.h
    team/group/ast_storage/main/udptl.c
    team/group/ast_storage/pbx/pbx_spool.c
    team/group/ast_storage/res/res_agi.c
    team/group/ast_storage/res/res_smdi.c

Propchange: team/group/ast_storage/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Propchange: team/group/ast_storage/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed Jul 11 16:28:24 2007
@@ -1,1 +1,1 @@
-/trunk:1-74666
+/trunk:1-74728

Modified: team/group/ast_storage/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_storage/channels/chan_agent.c?view=diff&rev=74743&r1=74742&r2=74743
==============================================================================
--- team/group/ast_storage/channels/chan_agent.c (original)
+++ team/group/ast_storage/channels/chan_agent.c Wed Jul 11 16:28:24 2007
@@ -1474,9 +1474,9 @@
 				}
 			} else {
 				logintime = time(NULL) - p->loginstart;
-				p->loginstart = 0;
 				agent_logoff_maintenance(p, p->loginchan, logintime, NULL, "CommandLogoff");
 			}
+			p->loginstart = 0;
 			break;
 		}
 	}
@@ -1901,6 +1901,8 @@
 						ast_device_state_changed("Agent/%s", p->agent);
 						while (res >= 0) {
 							ast_mutex_lock(&p->lock);
+							if (!p->loginstart && p->chan)
+								ast_softhangup(p->chan, AST_SOFTHANGUP_EXPLICIT);
 							if (p->chan != chan)
 								res = -1;
 							ast_mutex_unlock(&p->lock);

Modified: team/group/ast_storage/include/asterisk/udptl.h
URL: http://svn.digium.com/view/asterisk/team/group/ast_storage/include/asterisk/udptl.h?view=diff&rev=74743&r1=74742&r2=74743
==============================================================================
--- team/group/ast_storage/include/asterisk/udptl.h (original)
+++ team/group/ast_storage/include/asterisk/udptl.h Wed Jul 11 16:28:24 2007
@@ -42,7 +42,7 @@
 	/* Set UDPTL peer */
 	int (* const set_udptl_peer)(struct ast_channel *chan, struct ast_udptl *peer);
 	const char * const type;
-	struct ast_udptl_protocol *next;
+	AST_RWLIST_ENTRY(ast_udptl_protocol) list;
 };
 
 struct ast_udptl;

Modified: team/group/ast_storage/main/udptl.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_storage/main/udptl.c?view=diff&rev=74743&r1=74742&r2=74743
==============================================================================
--- team/group/ast_storage/main/udptl.c (original)
+++ team/group/ast_storage/main/udptl.c Wed Jul 11 16:28:24 2007
@@ -170,7 +170,7 @@
 	udptl_fec_rx_buffer_t rx[UDPTL_BUF_MASK + 1];
 };
 
-static struct ast_udptl_protocol *protos;
+static AST_RWLIST_HEAD_STATIC(protos, ast_udptl_protocol);
 
 static int udptl_rx_packet(struct ast_udptl *s, uint8_t *buf, int len);
 static int udptl_build_packet(struct ast_udptl *s, uint8_t *buf, uint8_t *ifp, int ifp_len);
@@ -949,52 +949,40 @@
 
 void ast_udptl_proto_unregister(struct ast_udptl_protocol *proto)
 {
+	AST_RWLIST_WRLOCK(&protos);
+	AST_RWLIST_REMOVE(&protos, proto, list);
+	AST_RWLIST_UNLOCK(&protos);
+}
+
+int ast_udptl_proto_register(struct ast_udptl_protocol *proto)
+{
 	struct ast_udptl_protocol *cur;
-	struct ast_udptl_protocol *prev;
-
-	cur = protos;
-	prev = NULL;
-	while (cur) {
-		if (cur == proto) {
-			if (prev)
-				prev->next = proto->next;
-			else
-				protos = proto->next;
-			return;
-		}
-		prev = cur;
-		cur = cur->next;
-	}
-}
-
-int ast_udptl_proto_register(struct ast_udptl_protocol *proto)
-{
-	struct ast_udptl_protocol *cur;
-
-	cur = protos;
-	while (cur) {
+
+	AST_RWLIST_WRLOCK(&protos);
+	AST_RWLIST_TRAVERSE(&protos, cur, list) {
 		if (cur->type == proto->type) {
 			ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
+			AST_RWLIST_UNLOCK(&protos);
 			return -1;
 		}
-		cur = cur->next;
-	}
-	proto->next = protos;
-	protos = proto;
+	}
+	AST_RWLIST_INSERT_TAIL(&protos, proto, list);
+	AST_RWLIST_UNLOCK(&protos);
 	return 0;
 }
 
 static struct ast_udptl_protocol *get_proto(struct ast_channel *chan)
 {
-	struct ast_udptl_protocol *cur;
-
-	cur = protos;
-	while (cur) {
+	struct ast_udptl_protocol *cur = NULL;
+
+	AST_RWLIST_RDLOCK(&protos);
+	AST_RWLIST_TRAVERSE(&protos, cur, list) {
 		if (cur->type == chan->tech->type)
-			return cur;
-		cur = cur->next;
-	}
-	return NULL;
+			break;
+	}
+	AST_RWLIST_UNLOCK(&protos);
+
+	return cur;
 }
 
 int ast_udptl_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc)

Modified: team/group/ast_storage/pbx/pbx_spool.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_storage/pbx/pbx_spool.c?view=diff&rev=74743&r1=74742&r2=74743
==============================================================================
--- team/group/ast_storage/pbx/pbx_spool.c (original)
+++ team/group/ast_storage/pbx/pbx_spool.c Wed Jul 11 16:28:24 2007
@@ -88,8 +88,8 @@
 	char data[256];
 
 	/* If extension/context/priority */
-	char exten[256];
-	char context[256];
+	char exten[AST_MAX_EXTENSION];
+	char context[AST_MAX_CONTEXT];
 	int priority;
 
 	/* CallerID Information */
@@ -111,7 +111,6 @@
 
 static void init_outgoing(struct outgoing *o)
 {
-	memset(o, 0, sizeof(struct outgoing));
 	o->priority = 1;
 	o->retrytime = 300;
 	o->waittime = 45;
@@ -120,7 +119,7 @@
 
 static void free_outgoing(struct outgoing *o)
 {
-	free(o);
+	ast_free(o);
 }
 
 static int apply_outgoing(struct outgoing *o, char *fn, FILE *f)
@@ -253,20 +252,21 @@
 	int fd;
 	FILE *f;
 	struct utimbuf tbuf;
-	fd = open(o->fn, O_WRONLY|O_APPEND);
-	if (fd > -1) {
-		f = fdopen(fd, "a");
-		if (f) {
-			fprintf(f, "\n%s: %ld %d (%ld)\n", s, (long)ast_mainpid, o->retries, (long) now);
-			fclose(f);
-		} else
-			close(fd);
-		/* Update the file time */
-		tbuf.actime = now;
-		tbuf.modtime = now + o->retrytime;
-		if (utime(o->fn, &tbuf))
-			ast_log(LOG_WARNING, "Unable to set utime on %s: %s\n", o->fn, strerror(errno));
-	}
+
+	if ((fd = open(o->fn, O_WRONLY | O_APPEND)) < 0)
+		return;
+
+	if ((f = fdopen(fd, "a"))) {
+		fprintf(f, "\n%s: %ld %d (%ld)\n", s, (long)ast_mainpid, o->retries, (long) now);
+		fclose(f);
+	} else
+		close(fd);
+
+	/* Update the file time */
+	tbuf.actime = now;
+	tbuf.modtime = now + o->retrytime;
+	if (utime(o->fn, &tbuf))
+		ast_log(LOG_WARNING, "Unable to set utime on %s: %s\n", o->fn, strerror(errno));
 }
 
 /*!
@@ -285,34 +285,34 @@
 	if (!ast_test_flag(&o->options, SPOOL_FLAG_ALWAYS_DELETE)) {
 		struct stat current_file_status;
 
-		if (!stat(o->fn, &current_file_status))
+		if (!stat(o->fn, &current_file_status)) {
 			if (time(NULL) < current_file_status.st_mtime)
 				return 0;
+		}
 	}
 
 	if (!ast_test_flag(&o->options, SPOOL_FLAG_ARCHIVE)) {
 		unlink(o->fn);
 		return 0;
 	}
+
 	if (ast_mkdir(qdonedir, 0777)) {
 		ast_log(LOG_WARNING, "Unable to create queue directory %s -- outgoing spool archiving disabled\n", qdonedir);
 		unlink(o->fn);
 		return -1;
 	}
-	fd = open(o->fn, O_WRONLY|O_APPEND);
-	if (fd > -1) {
-		f = fdopen(fd, "a");
-		if (f) {
+
+	if ((fd = open(o->fn, O_WRONLY | O_APPEND))) {
+		if ((f = fdopen(fd, "a"))) {
 			fprintf(f, "Status: %s\n", status);
 			fclose(f);
 		} else
 			close(fd);
 	}
 
-	bname = strrchr(o->fn,'/');
-	if (bname == NULL) 
+	if (!(bname = strrchr(o->fn, '/')))
 		bname = o->fn;
-	else 
+	else
 		bname++;	
 	snprintf(newfn, sizeof(newfn), "%s/%s", qdonedir, bname);
 	/* a existing call file the archive dir is overwritten */
@@ -369,56 +369,64 @@
 
 static int scan_service(char *fn, time_t now, time_t atime)
 {
-	struct outgoing *o;
+	struct outgoing *o = NULL;
 	FILE *f;
-	o = malloc(sizeof(struct outgoing));
-	if (o) {
-		init_outgoing(o);
-		f = fopen(fn, "r+");
-		if (f) {
-			if (!apply_outgoing(o, fn, f)) {
+	int res = 0;
+
+	if (!(o = ast_calloc(1, sizeof(*o)))) {
+		ast_log(LOG_WARNING, "Out of memory ;(\n");
+		return -1;
+	}
+	
+	init_outgoing(o);
+
+	/* Attempt to open the file */
+	if (!(f = fopen(fn, "r+"))) {
+		remove_from_queue(o, "Failed");
+		free_outgoing(o);
+		ast_log(LOG_WARNING, "Unable to open %s: %s, deleting\n", fn, strerror(errno));
+		return -1;
+	}
+
+	/* Read in and verify the contents */
+	if (apply_outgoing(o, fn, f)) {
+		remove_from_queue(o, "Failed");
+		free_outgoing(o);
+		ast_log(LOG_WARNING, "Invalid file contents in %s, deleting\n", fn);
+		fclose(f);
+		return -1;
+	}
+	
 #if 0
-				printf("Filename: %s, Retries: %d, max: %d\n", fn, o->retries, o->maxretries);
+	printf("Filename: %s, Retries: %d, max: %d\n", fn, o->retries, o->maxretries);
 #endif
-				fclose(f);
-				if (o->retries <= o->maxretries) {
-					now += o->retrytime;
-					if (o->callingpid && (o->callingpid == ast_mainpid)) {
-						safe_append(o, time(NULL), "DelayedRetry");
-						free_outgoing(o);
-						ast_log(LOG_DEBUG, "Delaying retry since we're currently running '%s'\n", o->fn);
-					} else {
-						/* Increment retries */
-						o->retries++;
-						/* If someone else was calling, they're presumably gone now
-						   so abort their retry and continue as we were... */
-						if (o->callingpid)
-							safe_append(o, time(NULL), "AbortRetry");
-
-						safe_append(o, now, "StartRetry");
-						launch_service(o);
-					}
-					return now;
-				} else {
-					ast_log(LOG_EVENT, "Queued call to %s/%s expired without completion after %d attempt%s\n", o->tech, o->dest, o->retries - 1, ((o->retries - 1) != 1) ? "s" : "");
-					free_outgoing(o);
-					remove_from_queue(o, "Expired");
-					return 0;
-				}
-			} else {
-				free_outgoing(o);
-				ast_log(LOG_WARNING, "Invalid file contents in %s, deleting\n", fn);
-				fclose(f);
-				remove_from_queue(o, "Failed");
-			}
+	fclose(f);
+	if (o->retries <= o->maxretries) {
+		now += o->retrytime;
+		if (o->callingpid && (o->callingpid == ast_mainpid)) {
+			safe_append(o, time(NULL), "DelayedRetry");
+			ast_log(LOG_DEBUG, "Delaying retry since we're currently running '%s'\n", o->fn);
+			free_outgoing(o);
 		} else {
-			free_outgoing(o);
-			ast_log(LOG_WARNING, "Unable to open %s: %s, deleting\n", fn, strerror(errno));
+			/* Increment retries */
+			o->retries++;
+			/* If someone else was calling, they're presumably gone now
+			   so abort their retry and continue as we were... */
+			if (o->callingpid)
+				safe_append(o, time(NULL), "AbortRetry");
+			
+			safe_append(o, now, "StartRetry");
+			launch_service(o);
 			remove_from_queue(o, "Failed");
 		}
-	} else
-		ast_log(LOG_WARNING, "Out of memory :(\n");
-	return -1;
+		res = now;
+	} else {
+		ast_log(LOG_EVENT, "Queued call to %s/%s expired without completion after %d attempt%s\n", o->tech, o->dest, o->retries - 1, ((o->retries - 1) != 1) ? "s" : "");
+		remove_from_queue(o, "Expired");
+		free_outgoing(o);
+	}
+
+	return res;
 }
 
 static void *scan_thread(void *unused)
@@ -429,48 +437,57 @@
 	char fn[256];
 	int res;
 	time_t last = 0, next = 0, now;
+
 	for(;;) {
 		/* Wait a sec */
 		sleep(1);
 		time(&now);
-		if (!stat(qdir, &st)) {
-			if ((st.st_mtime != last) || (next && (now > next))) {
+
+		if (stat(qdir, &st)) {
+			ast_log(LOG_WARNING, "Unable to stat %s\n", qdir);
+			continue;
+		}
+
+		/* Make sure it is time for us to execute our check */
+		if ((st.st_mtime == last) && (next && (next > now)))
+			continue;
+		
 #if 0
-				printf("atime: %ld, mtime: %ld, ctime: %ld\n", st.st_atime, st.st_mtime, st.st_ctime);
-				printf("Ooh, something changed / timeout\n");
+		printf("atime: %ld, mtime: %ld, ctime: %ld\n", st.st_atime, st.st_mtime, st.st_ctime);
+		printf("Ooh, something changed / timeout\n");
 #endif				
-				next = 0;
-				last = st.st_mtime;
-				dir = opendir(qdir);
-				if (dir) {
-					while((de = readdir(dir))) {
-						snprintf(fn, sizeof(fn), "%s/%s", qdir, de->d_name);
-						if (!stat(fn, &st)) {
-							if (S_ISREG(st.st_mode)) {
-								if (st.st_mtime <= now) {
-									res = scan_service(fn, now, st.st_atime);
-									if (res > 0) {
-										/* Update next service time */
-										if (!next || (res < next)) {
-											next = res;
-										}
-									} else if (res)
-										ast_log(LOG_WARNING, "Failed to scan service '%s'\n", fn);
-								} else {
-									/* Update "next" update if necessary */
-									if (!next || (st.st_mtime < next))
-										next = st.st_mtime;
-								}
-							}
-						} else
-							ast_log(LOG_WARNING, "Unable to stat %s: %s\n", fn, strerror(errno));
-					}
-					closedir(dir);
-				} else
-					ast_log(LOG_WARNING, "Unable to open directory %s: %s\n", qdir, strerror(errno));
+		next = 0;
+		last = st.st_mtime;
+
+		if (!(dir = opendir(qdir))) {
+			ast_log(LOG_WARNING, "Unable to open directory %s: %s\n", qdir, strerror(errno));
+			continue;
+		}
+
+		while ((de = readdir(dir))) {
+			snprintf(fn, sizeof(fn), "%s/%s", qdir, de->d_name);
+			if (stat(fn, &st)) {
+				ast_log(LOG_WARNING, "Unable to stat %s: %s\n", fn, strerror(errno));
+				continue;
 			}
-		} else
-			ast_log(LOG_WARNING, "Unable to stat %s\n", qdir);
+			if (!S_ISREG(st.st_mode))
+				continue;
+			if (st.st_mtime <= now) {
+				res = scan_service(fn, now, st.st_atime);
+				if (res > 0) {
+					/* Update next service time */
+					if (!next || (res < next)) {
+						next = res;
+					}
+				} else if (res)
+					ast_log(LOG_WARNING, "Failed to scan service '%s'\n", fn);
+			} else {
+				/* Update "next" update if necessary */
+				if (!next || (st.st_mtime < next))
+					next = st.st_mtime;
+			}
+		}
+		closedir(dir);
 	}
 	return NULL;
 }

Modified: team/group/ast_storage/res/res_agi.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_storage/res/res_agi.c?view=diff&rev=74743&r1=74742&r2=74743
==============================================================================
--- team/group/ast_storage/res/res_agi.c (original)
+++ team/group/ast_storage/res/res_agi.c Wed Jul 11 16:28:24 2007
@@ -126,30 +126,28 @@
 	va_start(ap, fmt);
 	res = vasprintf(&stuff, fmt, ap);
 	va_end(ap);
+
 	if (res == -1) {
 		ast_log(LOG_ERROR, "Out of memory\n");
-	} else {
-		if (agidebug)
-			ast_verbose("AGI Tx >> %s\n", stuff);
-		ast_carefulwrite(fd, stuff, strlen(stuff), 100);
-		ast_free(stuff);
-	}
+		return;
+	}
+
+	if (agidebug)
+		ast_verbose("AGI Tx >> %s\n", stuff);
+	ast_carefulwrite(fd, stuff, strlen(stuff), 100);
+	ast_free(stuff);
 }
 
 /* launch_netscript: The fastagi handler.
 	FastAGI defaults to port 4573 */
 static enum agi_result launch_netscript(char *agiurl, char *argv[], int *fds, int *efd, int *opid)
 {
-	int s;
-	int flags;
+	int s, flags, res, port = AGI_PORT;
 	struct pollfd pfds[1];
-	char *host;
-	char *c; int port = AGI_PORT;
-	char *script="";
+	char *host, *c, *script = "";
 	struct sockaddr_in sin;
 	struct hostent *hp;
 	struct ast_hostent ahp;
-	int res;
 
 	/* agiusl is "agi://host.domain[:port][/script/name]" */
 	host = ast_strdupa(agiurl + 6);	/* Remove agi:// */
@@ -168,18 +166,15 @@
 		ast_log(LOG_WARNING, "AGI URI's don't support Enhanced AGI yet\n");
 		return -1;
 	}
-	hp = ast_gethostbyname(host, &ahp);
-	if (!hp) {
+	if (!(hp = ast_gethostbyname(host, &ahp))) {
 		ast_log(LOG_WARNING, "Unable to locate host '%s'\n", host);
 		return -1;
 	}
-	s = socket(AF_INET, SOCK_STREAM, 0);
-	if (s < 0) {
+	if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
 		ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno));
 		return -1;
 	}
-	flags = fcntl(s, F_GETFL);
-	if (flags < 0) {
+	if ((flags = fcntl(s, F_GETFL)) < 0) {
 		ast_log(LOG_WARNING, "Fcntl(F_GETFL) failed: %s\n", strerror(errno));
 		close(s);
 		return -1;
@@ -236,12 +231,7 @@
 static enum agi_result launch_script(char *script, char *argv[], int *fds, int *efd, int *opid)
 {
 	char tmp[256];
-	int pid;
-	int toast[2];
-	int fromast[2];
-	int audio[2];
-	int x;
-	int res;
+	int pid, toast[2], fromast[2], audio[2], x, res;
 	sigset_t signal_set, old_set;
 	struct stat st;
 
@@ -296,8 +286,7 @@
 	/* Block SIGHUP during the fork - prevents a race */
 	sigfillset(&signal_set);
 	pthread_sigmask(SIG_BLOCK, &signal_set, &old_set);
-	pid = fork();
-	if (pid < 0) {
+	if ((pid = fork()) < 0) {
 		ast_log(LOG_WARNING, "Failed to fork(): %s\n", strerror(errno));
 		pthread_sigmask(SIG_SETMASK, &old_set, NULL);
 		return AGI_RESULT_FAILURE;
@@ -322,11 +311,10 @@
 		/* Redirect stdin and out, provide enhanced audio channel if desired */
 		dup2(fromast[0], STDIN_FILENO);
 		dup2(toast[1], STDOUT_FILENO);
-		if (efd) {
+		if (efd)
 			dup2(audio[0], STDERR_FILENO + 1);
-		} else {
+		else
 			close(STDERR_FILENO + 1);
-		}
 
 		/* Before we unblock our signals, return our trapped signals back to the defaults */
 		signal(SIGHUP, SIG_DFL);
@@ -344,7 +332,7 @@
 		}
 
 		/* Close everything but stdin/out/error */
-		for (x=STDERR_FILENO + 2;x<1024;x++) 
+		for (x = STDERR_FILENO + 2; x < 1024; x++) 
 			close(x);
 
 		/* Execute script */
@@ -360,9 +348,8 @@
 		ast_verbose(VERBOSE_PREFIX_3 "Launched AGI Script %s\n", script);
 	fds[0] = toast[0];
 	fds[1] = fromast[1];
-	if (efd) {
+	if (efd)
 		*efd = audio[1];
-	}
 	/* close what we're not using in the parent */
 	close(toast[1]);
 	close(fromast[0]);
@@ -416,20 +403,20 @@
 
 static int handle_answer(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
-	int res;
-	res = 0;
-	if (chan->_state != AST_STATE_UP) {
-		/* Answer the chan */
+	int res = 0;
+
+	/* Answer the channel */
+	if (chan->_state != AST_STATE_UP)
 		res = ast_answer(chan);
-	}
+
 	fdprintf(agi->fd, "200 result=%d\n", res);
 	return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
 }
 
 static int handle_waitfordigit(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
-	int res;
-	int to;
+	int res, to;
+
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
 	if (sscanf(argv[3], "%d", &to) != 1)
@@ -442,8 +429,10 @@
 static int handle_sendtext(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
 	int res;
+
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
+
 	/* At the moment, the parser (perhaps broken) returns with
 	   the last argument PLUS the newline at the end of the input
 	   buffer. This probably needs to be fixed, but I wont do that
@@ -459,8 +448,10 @@
 static int handle_recvchar(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
 	int res;
+
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
+
 	res = ast_recvchar(chan,atoi(argv[2]));
 	if (res == 0) {
 		fdprintf(agi->fd, "200 result=%d (timeout)\n", res);
@@ -482,6 +473,7 @@
 	
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
+
 	buf = ast_recvtext(chan,atoi(argv[2]));
 	if (buf) {
 		fdprintf(agi->fd, "200 result=1 (%s)\n", buf);
@@ -494,9 +486,11 @@
 
 static int handle_tddmode(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
-	int res,x;
+	int res, x;
+
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
+
 	if (!strncasecmp(argv[2],"on",2)) 
 		x = 1; 
 	else 
@@ -516,8 +510,10 @@
 static int handle_sendimage(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
 	int res;
+
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
+
 	res = ast_send_image(chan, argv[2]);
 	if (!ast_check_hangup(chan))
 		res = 0;
@@ -527,12 +523,8 @@
 
 static int handle_controlstreamfile(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
-	int res = 0;
-	int skipms = 3000;
-	char *fwd = NULL;
-	char *rev = NULL;
-	char *pause = NULL;
-	char *stop = NULL;
+	int res = 0, skipms = 3000;
+	char *fwd = NULL, *rev = NULL, *pause = NULL, *stop = NULL;
 
 	if (argc < 5 || argc > 9)
 		return RESULT_SHOWUSAGE;
@@ -569,12 +561,9 @@
 
 static int handle_streamfile(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
-	int res;
-	int vres;	
-	struct ast_filestream *fs;
-	struct ast_filestream *vfs;
-	long sample_offset = 0;
-	long max_length;
+	int res, vres;
+	struct ast_filestream *fs, *vfs;
+	long sample_offset = 0, max_length;
 	char *edigits = "";
 
 	if (argc < 4 || argc > 5)
@@ -585,10 +574,8 @@
 
 	if ((argc > 4) && (sscanf(argv[4], "%ld", &sample_offset) != 1))
 		return RESULT_SHOWUSAGE;
-	
-	fs = ast_openstream(chan, argv[2], chan->language);	
-	
-	if (!fs) {
+
+	if (!(fs = ast_openstream(chan, argv[2], chan->language))) {
 		fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset);
 		return RESULT_SUCCESS;
 	}	
@@ -624,12 +611,9 @@
 /* get option - really similar to the handle_streamfile, but with a timeout */
 static int handle_getoption(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
-	int res;
-	int vres;	
-	struct ast_filestream *fs;
-	struct ast_filestream *vfs;
-	long sample_offset = 0;
-	long max_length;
+	int res, vres;
+	struct ast_filestream *fs, *vfs;
+	long sample_offset = 0, max_length;
 	int timeout = 0;
 	char *edigits = "";
 
@@ -646,8 +630,7 @@
 		timeout = chan->pbx->dtimeout * 1000; /* in msec */
 	}
 
-	fs = ast_openstream(chan, argv[2], chan->language);
-	if (!fs) {
+	if (!(fs = ast_openstream(chan, argv[2], chan->language))) {
 		fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset);
 		ast_log(LOG_WARNING, "Unable to open %s\n", argv[2]);
 		return RESULT_SUCCESS;
@@ -697,8 +680,8 @@
 /* While waiting, we're sending a NULL.  */
 static int handle_saynumber(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
-	int res;
-	int num;
+	int res, num;
+
 	if (argc < 4 || argc > 5)
 		return RESULT_SHOWUSAGE;
 	if (sscanf(argv[2], "%d", &num) != 1)
@@ -712,8 +695,7 @@
 
 static int handle_saydigits(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
-	int res;
-	int num;
+	int res, num;
 
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
@@ -743,8 +725,8 @@
 
 static int handle_saydate(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
-	int res;
-	int num;
+	int res, num;
+
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
 	if (sscanf(argv[2], "%d", &num) != 1)
@@ -758,8 +740,8 @@
 
 static int handle_saytime(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
-	int res;
-	int num;
+	int res, num;
+
 	if (argc != 4)
 		return RESULT_SHOWUSAGE;
 	if (sscanf(argv[2], "%d", &num) != 1)
@@ -773,9 +755,9 @@
 
 static int handle_saydatetime(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
-	int res=0;
+	int res = 0;
 	time_t unixtime;
-	char *format, *zone=NULL;
+	char *format, *zone = NULL;
 	
 	if (argc < 4)
 		return RESULT_SHOWUSAGE;
@@ -821,10 +803,8 @@
 
 static int handle_getdata(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
 {
-	int res;
+	int res, max, timeout;
 	char data[1024];
-	int max;
-	int timeout;
 
 	if (argc < 3)
 		return RESULT_SHOWUSAGE;
@@ -870,6 +850,7 @@
 static int handle_setpriority(struct ast_channel *chan, AGI *agi, int argc, char **argv)
 {
 	int pri;
+
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;	
 
@@ -1081,6 +1062,7 @@
 static int handle_hangup(struct ast_channel *chan, AGI *agi, int argc, char **argv)
 {
 	struct ast_channel *c;
+
 	if (argc == 1) {
 		/* no argument: hangup the current channel */
 		ast_softhangup(chan,AST_SOFTHANGUP_EXPLICIT);
@@ -1115,9 +1097,7 @@
 	if (option_verbose > 2)
 		ast_verbose(VERBOSE_PREFIX_3 "AGI Script Executing Application: (%s) Options: (%s)\n", argv[1], argv[2]);
 
-	app = pbx_findapp(argv[1]);
-
-	if (app) {
+	if ((app = pbx_findapp(argv[1]))) {
 		res = pbx_exec(chan, app, argv[2]);
 	} else {
 		ast_log(LOG_WARNING, "Could not find application (%s)\n", argv[1]);
@@ -1303,6 +1283,7 @@
 static int handle_dbdeltree(struct ast_channel *chan, AGI *agi, int argc, char **argv)
 {
 	int res;
+
 	if ((argc < 3) || (argc > 4))
 		return RESULT_SHOWUSAGE;
 	if (argc == 4)
@@ -1652,13 +1633,14 @@
 
 static int help_workhorse(int fd, char *match[])
 {
-	char fullcmd[80];
-	char matchstr[80];
+	char fullcmd[80], matchstr[80];
 	int x;
 	struct agi_command *e;
+
 	if (match)
 		ast_join(matchstr, sizeof(matchstr), match);
-	for (x=0;x<sizeof(commands)/sizeof(commands[0]);x++) {
+
+	for (x = 0; x < sizeof(commands) / sizeof(commands[0]); x++) {
 		e = &commands[x]; 
 		if (!e->cmda[0])
 			break;
@@ -1676,13 +1658,14 @@
 int ast_agi_register(agi_command *agi)
 {
 	int x;
-	for (x=0; x<MAX_COMMANDS - 1; x++) {
+
+	for (x = 0; x < MAX_COMMANDS - 1; x++) {
 		if (commands[x].cmda[0] == agi->cmda[0]) {
 			ast_log(LOG_WARNING, "Command already registered!\n");
 			return -1;
 		}
 	}
-	for (x=0; x<MAX_COMMANDS - 1; x++) {
+	for (x = 0; x < MAX_COMMANDS - 1; x++) {
 		if (!commands[x].cmda[0]) {
 			commands[x] = *agi;
 			return 0;
@@ -1695,7 +1678,7 @@
 void ast_agi_unregister(agi_command *agi)
 {
 	int x;
-	for (x=0; x<MAX_COMMANDS - 1; x++) {
+	for (x = 0; x < MAX_COMMANDS - 1; x++) {
 		if (commands[x].cmda[0] == agi->cmda[0]) {
 			memset(&commands[x], 0, sizeof(agi_command));
 		}
@@ -1704,16 +1687,14 @@
 
 static agi_command *find_command(char *cmds[], int exact)
 {
-	int x;
-	int y;
-	int match;
-
-	for (x=0; x < sizeof(commands) / sizeof(commands[0]); x++) {
+	int x, y, match;
+
+	for (x = 0; x < sizeof(commands) / sizeof(commands[0]); x++) {
 		if (!commands[x].cmda[0])
 			break;
 		/* start optimistic */
 		match = 1;
-		for (y=0; match && cmds[y]; y++) {
+		for (y = 0; match && cmds[y]; y++) {
 			/* If there are no more words in the command (and we're looking for
 			   an exact match) or there is a difference between the two words,
 			   then this is not a match */
@@ -1738,10 +1719,7 @@
 
 static int parse_args(char *s, int *max, char *argv[])
 {
-	int x=0;
-	int quoted=0;
-	int escaped=0;
-	int whitespace=1;
+	int x = 0, quoted = 0, escaped = 0, whitespace = 1;
 	char *cur;
 
 	cur = s;
@@ -1805,13 +1783,11 @@
 static int agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf)
 {
 	char *argv[MAX_ARGS];
-	int argc = MAX_ARGS;
-	int res;
+	int argc = MAX_ARGS, res;
 	agi_command *c;
 
 	parse_args(buf, &argc, argv);
-	c = find_command(argv, 0);
-	if (c) {
+	if ((c = find_command(argv, 0))) {
 		res = c->handler(chan, agi, argc, argv);
 		switch(res) {
 		case RESULT_SHOWUSAGE:
@@ -1837,8 +1813,7 @@
 static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid, int *status, int dead, int argc, char *argv[])
 {
 	struct ast_channel *c;
-	int outfd;
-	int ms;
+	int outfd, ms;
 	enum agi_result returnstatus = AGI_RESULT_SUCCESS;
 	struct ast_frame *f;
 	char buf[2048];
@@ -1923,8 +1898,10 @@
 {
 	struct agi_command *e;
 	char fullcmd[80];
+
 	if ((argc < 2))
 		return RESULT_SHOWUSAGE;
+
 	if (argc > 2) {
 		e = find_command(argv + 2, 1);
 		if (e) 
@@ -1995,7 +1972,7 @@
 
 	fprintf(htmlfile, "<TABLE BORDER=\"0\" CELLSPACING=\"10\">\n");
 
-	for (x=0;x<sizeof(commands)/sizeof(commands[0]);x++) {
+	for (x = 0; x < sizeof(commands) / sizeof(commands[0]); x++) {
 		char *stringp, *tempstr;
 
 		e = &commands[x]; 
@@ -2037,14 +2014,8 @@
 {
 	enum agi_result res;
 	struct ast_module_user *u;
-	char *argv[MAX_ARGS];
-	char buf[2048]="";
-	char *tmp = buf;
-	int argc = 0;
-	int fds[2];
-	int efd = -1;
-	int pid;
-        char *stringp;
+	char *argv[MAX_ARGS], buf[2048] = "", *tmp = buf, *stringp;
+	int argc = 0, fds[2], efd = -1, pid;
 	AGI agi;
 
 	if (ast_strlen_zero(data)) {
@@ -2113,8 +2084,7 @@
 
 static int eagi_exec(struct ast_channel *chan, void *data)
 {
-	int readformat;
-	int res;
+	int readformat, res;
 
 	if (chan->_softhangup)
 		ast_log(LOG_WARNING, "If you want to run AGI on hungup channels you should use DeadAGI!\n");

Modified: team/group/ast_storage/res/res_smdi.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_storage/res/res_smdi.c?view=diff&rev=74743&r1=74742&r2=74743
==============================================================================
--- team/group/ast_storage/res/res_smdi.c (original)
+++ team/group/ast_storage/res/res_smdi.c Wed Jul 11 16:28:24 2007
@@ -94,18 +94,17 @@
 	FILE *file;
 	int i;
 	
-	file = fopen(iface->name, "w");
-	if(!file) {
+	if (!(file = fopen(iface->name, "w"))) {
 		ast_log(LOG_ERROR, "Error opening SMDI interface %s (%s) for writing\n", iface->name, strerror(errno));
 		return 1;
 	}	
-
+	
 	ASTOBJ_WRLOCK(iface);
-
+	
 	fprintf(file, "OP:MWI ");
-
-	for(i = 0; i < iface->msdstrip; i++)
-	   fprintf(file, "0");
+	
+	for (i = 0; i < iface->msdstrip; i++)
+		fprintf(file, "0");
 
 	fprintf(file, "%s!\x04", mailbox);
 	fclose(file);
@@ -124,19 +123,18 @@
 {
 	FILE *file;
 	int i;
-	
-	file = fopen(iface->name, "w");
-	if(!file) {
+
+	if (!(file = fopen(iface->name, "w"))) {
 		ast_log(LOG_ERROR, "Error opening SMDI interface %s (%s) for writing\n", iface->name, strerror(errno));
 		return 1;
 	}	
-
+	
 	ASTOBJ_WRLOCK(iface);
-
+	
 	fprintf(file, "RMV:MWI ");
-
-	for(i = 0; i < iface->msdstrip; i++)
-	   fprintf(file, "0");
+	
+	for (i = 0; i < iface->msdstrip; i++)
+		fprintf(file, "0");
 
 	fprintf(file, "%s!\x04", mailbox);
 	fclose(file);
@@ -225,11 +223,10 @@
  */
 extern struct ast_smdi_md_message *ast_smdi_md_message_wait(struct ast_smdi_interface *iface, int timeout)
 {
-	struct timeval start;
+	struct timeval start = ast_tvnow();
 	long diff = 0;
 	struct ast_smdi_md_message *msg;
 
-	start = ast_tvnow();
 	while (diff < timeout) {
 
 		if ((msg = ast_smdi_md_message_pop(iface)))
@@ -255,11 +252,10 @@
 extern struct ast_smdi_mwi_message *ast_smdi_mwi_message_pop(struct ast_smdi_interface *iface)
 {
 	struct ast_smdi_mwi_message *mwi_msg = ASTOBJ_CONTAINER_UNLINK_START(&iface->mwi_q);
-	struct timeval now;
+	struct timeval now = ast_tvnow();
 	long elapsed = 0;
 
 	/* purge old messages */
-	now = ast_tvnow();
 	while (mwi_msg)	{
 		elapsed = ast_tvdiff_ms(now, mwi_msg->timestamp);
 
@@ -293,11 +289,10 @@
  */
 extern struct ast_smdi_mwi_message *ast_smdi_mwi_message_wait(struct ast_smdi_interface *iface, int timeout)
 {
-	struct timeval start;
+	struct timeval start = ast_tvnow();
 	long diff = 0;
 	struct ast_smdi_mwi_message *msg;
 
-	start = ast_tvnow();
 	while (diff < timeout) {
 
 		if ((msg = ast_smdi_mwi_message_pop(iface)))
@@ -528,10 +523,8 @@
 	
 	int msdstrip = 0;              /* strip zero digits */
 	long msg_expiry = SMDI_MSG_EXPIRY_TIME;
-	
-	conf = ast_config_load(config_file);
-
-	if (!conf) {
+
+	if (!(conf = ast_config_load(config_file))) {
 		if (reload)
 			ast_log(LOG_NOTICE, "Unable to reload config %s: SMDI untouched\n", config_file);
 		else
@@ -651,13 +644,13 @@
 			
 			/* set the stop bits */
 			if (stopbits)
-			   iface->mode.c_cflag = iface->mode.c_cflag | CSTOPB;   /* set two stop bits */
+				iface->mode.c_cflag = iface->mode.c_cflag | CSTOPB;   /* set two stop bits */
 			else
-			   iface->mode.c_cflag = iface->mode.c_cflag & ~CSTOPB;  /* set one stop bit */
-
+				iface->mode.c_cflag = iface->mode.c_cflag & ~CSTOPB;  /* set one stop bit */
+			
 			/* set the parity */
 			iface->mode.c_cflag = (iface->mode.c_cflag & ~PARENB & ~PARODD) | paritybit;
-
+			
 			/* set the character size */
 			iface->mode.c_cflag = (iface->mode.c_cflag & ~CSIZE) | charsize;
 			
@@ -691,7 +684,7 @@
 		}
 	}
 	ast_config_destroy(conf);
-
+	
 	/* Prune any interfaces we should no longer monitor. */
 	if (reload)
 		ASTOBJ_CONTAINER_PRUNE_MARKED(&smdi_ifaces, ast_smdi_interface_destroy);
@@ -701,18 +694,18 @@
 	if (!smdi_ifaces.head)
 		res = 1;
 	ASTOBJ_CONTAINER_UNLOCK(&smdi_ifaces);
-			
+	
 	return res;
 }
 
 static int load_module(void)
 {
 	int res;
-
+	
 	/* initialize our containers */
 	memset(&smdi_ifaces, 0, sizeof(smdi_ifaces));
 	ASTOBJ_CONTAINER_INIT(&smdi_ifaces);
-
+	
 	/* load the config and start the listener threads*/
 	res = smdi_load(0);
 	if (res < 0) {




More information about the asterisk-commits mailing list