[Asterisk-cvs] asterisk CREDITS,1.9,1.10 manager.c,1.19,1.20

markster at lists.digium.com markster at lists.digium.com
Mon Sep 8 11:43:27 CDT 2003


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

Modified Files:
	CREDITS manager.c 
Log Message:
First of Jayson's manager patches


Index: CREDITS
===================================================================
RCS file: /usr/cvsroot/asterisk/CREDITS,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** CREDITS	16 May 2003 20:37:02 -0000	1.9
--- CREDITS	8 Sep 2003 16:44:36 -0000	1.10
***************
*** 46,49 ****
--- 46,51 ----
  Tilghman Lesher - Route lookup code, gotoiftime application, and various
         other patches.  http://asterisk.drunkcoder.com/
+ Jayson Vantuyl - Manager protocol changes, various other bugs.
+ 	jvantuyl at computingedge.net
  
  === OTHER CONTRIBUTIONS ===

Index: manager.c
===================================================================
RCS file: /usr/cvsroot/asterisk/manager.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** manager.c	25 Aug 2003 22:40:14 -0000	1.19
--- manager.c	8 Sep 2003 16:44:36 -0000	1.20
***************
*** 146,161 ****
  }
  
! void astman_send_error(struct mansession *s, char *error)
  {
  	ast_mutex_lock(&s->lock);
  	ast_cli(s->fd, "Response: Error\r\n");
  	ast_cli(s->fd, "Message: %s\r\n\r\n", error);
  	ast_mutex_unlock(&s->lock);
  }
  
! void astman_send_response(struct mansession *s, char *resp, char *msg)
  {
  	ast_mutex_lock(&s->lock);
  	ast_cli(s->fd, "Response: %s\r\n", resp);
  	if (msg)
  		ast_cli(s->fd, "Message: %s\r\n\r\n", msg);
--- 146,167 ----
  }
  
! void astman_send_error(struct mansession *s, struct message *m, char *error)
  {
+ 	char *id = astman_get_header(m,"ActionID");
  	ast_mutex_lock(&s->lock);
  	ast_cli(s->fd, "Response: Error\r\n");
+ 	if (id && &id)
+ 		ast_cli(s->fd, "ActionID: %s\r\n",id);
  	ast_cli(s->fd, "Message: %s\r\n\r\n", error);
  	ast_mutex_unlock(&s->lock);
  }
  
! void astman_send_response(struct mansession *s, struct message *m, char *resp, char *msg)
  {
+ 	char *id = astman_get_header(m,"ActionID");
  	ast_mutex_lock(&s->lock);
  	ast_cli(s->fd, "Response: %s\r\n", resp);
+ 	if (id && &id)
+ 		ast_cli(s->fd, "ActionID: %s\r\n",id);
  	if (msg)
  		ast_cli(s->fd, "Message: %s\r\n\r\n", msg);
***************
*** 165,171 ****
  }
  
! void astman_send_ack(struct mansession *s, char *msg)
  {
! 	astman_send_response(s, "Success", msg);
  }
  
--- 171,177 ----
  }
  
! void astman_send_ack(struct mansession *s, struct message *m, char *msg)
  {
! 	astman_send_response(s, m, "Success", msg);
  }
  
***************
*** 274,278 ****
  static int action_ping(struct mansession *s, struct message *m)
  {
! 	astman_send_response(s, "Pong", NULL);
  	return 0;
  }
--- 280,284 ----
  static int action_ping(struct mansession *s, struct message *m)
  {
! 	astman_send_response(s, m, "Pong", NULL);
  	return 0;
  }
***************
*** 280,284 ****
  static int action_logoff(struct mansession *s, struct message *m)
  {
! 	astman_send_response(s, "Goodbye", "Thanks for all the fish.");
  	return -1;
  }
--- 286,290 ----
  static int action_logoff(struct mansession *s, struct message *m)
  {
! 	astman_send_response(s, m, "Goodbye", "Thanks for all the fish.");
  	return -1;
  }
***************
*** 289,293 ****
  	char *name = astman_get_header(m, "Channel");
  	if (!strlen(name)) {
! 		astman_send_error(s, "No channel specified");
  		return 0;
  	}
--- 295,299 ----
  	char *name = astman_get_header(m, "Channel");
  	if (!strlen(name)) {
! 		astman_send_error(s, m, "No channel specified");
  		return 0;
  	}
***************
*** 300,308 ****
  	}
  	if (!c) {
! 		astman_send_error(s, "No such channel");
  		return 0;
  	}
  	ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
! 	astman_send_ack(s, "Channel Hungup");
  	return 0;
  }
--- 306,314 ----
  	}
  	if (!c) {
! 		astman_send_error(s, m, "No such channel");
  		return 0;
  	}
  	ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
! 	astman_send_ack(s, m, "Channel Hungup");
  	return 0;
  }
***************
*** 310,317 ****
  static int action_status(struct mansession *s, struct message *m)
  {
  	struct ast_channel *c;
  	char bridge[256];
! 	astman_send_ack(s, "Channel status will follow");
  	c = ast_channel_walk(NULL);
  	while(c) {
  		if (c->bridge)
--- 316,327 ----
  static int action_status(struct mansession *s, struct message *m)
  {
+ 	char *id = astman_get_header(m,"ActionID");
+ 	char idText[256] = "";
  	struct ast_channel *c;
  	char bridge[256];
! 	astman_send_ack(s, m, "Channel status will follow");
  	c = ast_channel_walk(NULL);
+         if (id && &id)
+                 snprintf(idText,256,"ActionID: %s\r\n",id);
  	while(c) {
  		if (c->bridge)
***************
*** 330,337 ****
  			"%s"
  			"Uniqueid: %s\r\n"
  			"\r\n",
  			c->name, c->callerid ? c->callerid : "<unknown>", 
  			ast_state2str(c->_state), c->context,
! 			c->exten, c->priority, bridge, c->uniqueid);
  		} else {
  			ast_cli(s->fd,
--- 340,348 ----
  			"%s"
  			"Uniqueid: %s\r\n"
+ 			"%s"
  			"\r\n",
  			c->name, c->callerid ? c->callerid : "<unknown>", 
  			ast_state2str(c->_state), c->context,
! 			c->exten, c->priority, bridge, c->uniqueid, idText);
  		} else {
  			ast_cli(s->fd,
***************
*** 342,348 ****
  			"%s"
  			"Uniqueid: %s\r\n"
  			"\r\n",
  			c->name, c->callerid ? c->callerid : "<unknown>", 
! 			ast_state2str(c->_state), bridge, c->uniqueid);
  		}
  		c = ast_channel_walk(c);
--- 353,360 ----
  			"%s"
  			"Uniqueid: %s\r\n"
+ 			"%s"
  			"\r\n",
  			c->name, c->callerid ? c->callerid : "<unknown>", 
! 			ast_state2str(c->_state), bridge, c->uniqueid, idText);
  		}
  		c = ast_channel_walk(c);
***************
*** 361,369 ****
  	int res;
  	if (!name || !strlen(name)) {
! 		astman_send_error(s, "Channel not specified");
  		return 0;
  	}
  	if (strlen(priority) && (sscanf(priority, "%d", &pi) != 1)) {
! 		astman_send_error(s, "Invalid priority\n");
  		return 0;
  	}
--- 373,381 ----
  	int res;
  	if (!name || !strlen(name)) {
! 		astman_send_error(s, m, "Channel not specified");
  		return 0;
  	}
  	if (strlen(priority) && (sscanf(priority, "%d", &pi) != 1)) {
! 		astman_send_error(s, m, "Invalid priority\n");
  		return 0;
  	}
***************
*** 373,383 ****
  			res = ast_async_goto_by_name(name2, context, exten, pi);
  			if (!res)
! 				astman_send_ack(s, "Dual Redirect successful");
  			else
! 				astman_send_error(s, "Secondary redirect failed");
  		} else
! 			astman_send_ack(s, "Redirect successful");
  	} else
! 		astman_send_error(s, "Redirect failed");
  	return 0;
  }
--- 385,395 ----
  			res = ast_async_goto_by_name(name2, context, exten, pi);
  			if (!res)
! 				astman_send_ack(s, m, "Dual Redirect successful");
  			else
! 				astman_send_error(s, m, "Secondary redirect failed");
  		} else
! 			astman_send_ack(s, m, "Redirect successful");
  	} else
! 		astman_send_error(s, m, "Redirect failed");
  	return 0;
  }
***************
*** 390,393 ****
--- 402,406 ----
  	ast_mutex_unlock(&s->lock);
  	ast_cli(s->fd, "Response: Follows\r\n");
+ 	/* FIXME: Wedge a ActionID response in here, waiting for later changes */
  	ast_cli_command(s->fd, cmd);
  	ast_cli(s->fd, "--END COMMAND--\r\n\r\n");
***************
*** 415,427 ****
  	char tmp[256];
  	if (!name) {
! 		astman_send_error(s, "Channel not specified");
  		return 0;
  	}
  	if (strlen(priority) && (sscanf(priority, "%d", &pi) != 1)) {
! 		astman_send_error(s, "Invalid priority\n");
  		return 0;
  	}
  	if (strlen(timeout) && (sscanf(timeout, "%d", &to) != 1)) {
! 		astman_send_error(s, "Invalid timeout\n");
  		return 0;
  	}
--- 428,440 ----
  	char tmp[256];
  	if (!name) {
! 		astman_send_error(s, m, "Channel not specified");
  		return 0;
  	}
  	if (strlen(priority) && (sscanf(priority, "%d", &pi) != 1)) {
! 		astman_send_error(s, m, "Invalid priority\n");
  		return 0;
  	}
  	if (strlen(timeout) && (sscanf(timeout, "%d", &to) != 1)) {
! 		astman_send_error(s, m, "Invalid timeout\n");
  		return 0;
  	}
***************
*** 430,434 ****
  	data = strchr(tmp, '/');
  	if (!data) {
! 		astman_send_error(s, "Invalid channel\n");
  		return 0;
  	}
--- 443,447 ----
  	data = strchr(tmp, '/');
  	if (!data) {
! 		astman_send_error(s, m, "Invalid channel\n");
  		return 0;
  	}
***************
*** 441,447 ****
  	}   
  	if (!res)
! 		astman_send_ack(s, "Originate successfully queued");
  	else
! 		astman_send_error(s, "Originate failed");
  	return 0;
  }
--- 454,460 ----
  	}   
  	if (!res)
! 		astman_send_ack(s, m, "Originate successfully queued");
  	else
! 		astman_send_error(s, m, "Originate failed");
  	return 0;
  }
***************
*** 450,461 ****
  {
  	char *mailbox = astman_get_header(m, "Mailbox");
  	if (!mailbox || !strlen(mailbox)) {
! 		astman_send_error(s, "Mailbox not specified");
  		return 0;
  	}
  	ast_cli(s->fd, "Response: Success\r\n"
  				   "Message: Mailbox Status\r\n"
  				   "Mailbox: %s\r\n"
! 		 		   "Waiting: %d\r\n\r\n", mailbox, ast_app_has_voicemail(mailbox));
  	return 0;
  }
--- 463,479 ----
  {
  	char *mailbox = astman_get_header(m, "Mailbox");
+ 	char *id = astman_get_header(m,"ActionID");
+ 	char idText[256] = "";
  	if (!mailbox || !strlen(mailbox)) {
! 		astman_send_error(s, m, "Mailbox not specified");
  		return 0;
  	}
+         if (id && &id)
+                 snprintf(idText,256,"ActionID: %s\r\n",id);
  	ast_cli(s->fd, "Response: Success\r\n"
+ 				   "%s"
  				   "Message: Mailbox Status\r\n"
  				   "Mailbox: %s\r\n"
! 		 		   "Waiting: %d\r\n\r\n", idText, mailbox, ast_app_has_voicemail(mailbox));
  	return 0;
  }
***************
*** 464,474 ****
  {
  	char *mailbox = astman_get_header(m, "Mailbox");
  	int newmsgs = 0, oldmsgs = 0;
  	if (!mailbox || !strlen(mailbox)) {
! 		astman_send_error(s, "Mailbox not specified");
  		return 0;
  	}
  	ast_app_messagecount(mailbox, &newmsgs, &oldmsgs);
  	ast_cli(s->fd, "Response: Success\r\n"
  				   "Message: Mailbox Message Count\r\n"
  				   "Mailbox: %s\r\n"
--- 482,498 ----
  {
  	char *mailbox = astman_get_header(m, "Mailbox");
+ 	char *id = astman_get_header(m,"ActionID");
+ 	char idText[256] = "";
  	int newmsgs = 0, oldmsgs = 0;
  	if (!mailbox || !strlen(mailbox)) {
! 		astman_send_error(s, m, "Mailbox not specified");
  		return 0;
  	}
  	ast_app_messagecount(mailbox, &newmsgs, &oldmsgs);
+         if (id && &id) {
+                 snprintf(idText,256,"ActionID: %s\r\n",id);
+         }
  	ast_cli(s->fd, "Response: Success\r\n"
+ 				   "%s"
  				   "Message: Mailbox Message Count\r\n"
  				   "Mailbox: %s\r\n"
***************
*** 476,480 ****
  				   "OldMessages: %d\r\n" 
  				   "\r\n",
! 				    mailbox, newmsgs, oldmsgs);
  	return 0;
  }
--- 500,504 ----
  				   "OldMessages: %d\r\n" 
  				   "\r\n",
! 				    idText,mailbox, newmsgs, oldmsgs);
  	return 0;
  }
***************
*** 484,491 ****
  	char *exten = astman_get_header(m, "Exten");
  	char *context = astman_get_header(m, "Context");
  	char hint[256] = "";
  	int status;
  	if (!exten || !strlen(exten)) {
! 		astman_send_error(s, "Extension not specified");
  		return 0;
  	}
--- 508,517 ----
  	char *exten = astman_get_header(m, "Exten");
  	char *context = astman_get_header(m, "Context");
+ 	char *id = astman_get_header(m,"ActionID");
+ 	char idText[256] = "";
  	char hint[256] = "";
  	int status;
  	if (!exten || !strlen(exten)) {
! 		astman_send_error(s, m, "Extension not specified");
  		return 0;
  	}
***************
*** 494,503 ****
  	status = ast_extension_state(NULL, context, exten);
  	ast_get_hint(hint, sizeof(hint) - 1, NULL, context, exten);
  	ast_cli(s->fd, "Response: Success\r\n"
  				   "Message: Extension Status\r\n"
  				   "Exten: %s\r\n"
  				   "Context: %s\r\n"
  				   "Hint: %s\r\n"
! 		 		   "Status: %d\r\n\r\n", exten, context, hint, status);
  	return 0;
  }
--- 520,534 ----
  	status = ast_extension_state(NULL, context, exten);
  	ast_get_hint(hint, sizeof(hint) - 1, NULL, context, exten);
+         if (id && &id) {
+                 snprintf(idText,256,"ActionID: %s\r\n",id);
+         }
  	ast_cli(s->fd, "Response: Success\r\n"
+ 			           "%s"
  				   "Message: Extension Status\r\n"
  				   "Exten: %s\r\n"
  				   "Context: %s\r\n"
  				   "Hint: %s\r\n"
! 		 		   "Status: %d\r\n\r\n",
! 				   idText,exten, context, hint, status);
  	return 0;
  }
***************
*** 509,517 ****
  	int timeout = atoi(astman_get_header(m, "Timeout"));
  	if (!strlen(name)) {
! 		astman_send_error(s, "No channel specified");
  		return 0;
  	}
  	if (!timeout) {
! 		astman_send_error(s, "No timeout specified");
  		return 0;
  	}
--- 540,548 ----
  	int timeout = atoi(astman_get_header(m, "Timeout"));
  	if (!strlen(name)) {
! 		astman_send_error(s, m, "No channel specified");
  		return 0;
  	}
  	if (!timeout) {
! 		astman_send_error(s, m, "No timeout specified");
  		return 0;
  	}
***************
*** 524,532 ****
  	}
  	if (!c) {
! 		astman_send_error(s, "No such channel");
  		return 0;
  	}
  	ast_channel_setwhentohangup(c, timeout);
! 	astman_send_ack(s, "Timeout Set");
  	return 0;
  }
--- 555,563 ----
  	}
  	if (!c) {
! 		astman_send_error(s, m, "No such channel");
  		return 0;
  	}
  	ast_channel_setwhentohangup(c, timeout);
! 	astman_send_ack(s, m, "Timeout Set");
  	return 0;
  }
***************
*** 536,539 ****
--- 567,572 ----
  	char action[80];
  	struct manager_action *tmp = first_action;
+ 	char *id = astman_get_header(m,"ActionID");
+ 	char idText[256] = "";
  
  	strncpy(action, astman_get_header(m, "Action"), sizeof(action));
***************
*** 541,547 ****
  
  	if (!strlen(action)) {
! 		astman_send_error(s, "Missing action in request");
  		return 0;
  	}
  	if (!s->authenticated) {
  		if (!strcasecmp(action, "Challenge")) {
--- 574,583 ----
  
  	if (!strlen(action)) {
! 		astman_send_error(s, m, "Missing action in request");
  		return 0;
  	}
+         if (id && &id) {
+                 snprintf(idText,256,"ActionID: %s\r\n",id);
+         }
  	if (!s->authenticated) {
  		if (!strcasecmp(action, "Challenge")) {
***************
*** 554,561 ****
  					ast_mutex_unlock(&s->lock);
  				}
! 				ast_cli(s->fd, "Response: Success\r\nChallenge: %s\r\n\r\n", s->challenge);
  				return 0;
  			} else {
! 				astman_send_error(s, "Must specify AuthType");
  				return 0;
  			}
--- 590,600 ----
  					ast_mutex_unlock(&s->lock);
  				}
! 				ast_cli(s->fd, "Response: Success\r\n"
! 						"%s"
! 						"Challenge: %s\r\n\r\n",
! 						idText,s->challenge);
  				return 0;
  			} else {
! 				astman_send_error(s, m, "Must specify AuthType");
  				return 0;
  			}
***************
*** 563,567 ****
  			if (authenticate(s, m)) {
  				sleep(1);
! 				astman_send_error(s, "Authentication failed");
  				return -1;
  			} else {
--- 602,606 ----
  			if (authenticate(s, m)) {
  				sleep(1);
! 				astman_send_error(s, m, "Authentication failed");
  				return -1;
  			} else {
***************
*** 570,580 ****
  					ast_verbose(VERBOSE_PREFIX_2 "Manager '%s' logged on from %s\n", s->username, inet_ntoa(s->sin.sin_addr));
  				ast_log(LOG_EVENT, "Manager '%s' logged on from %s\n", s->username, inet_ntoa(s->sin.sin_addr));
! 				astman_send_ack(s, "Authentication accepted");
  			}
  		} else if (!strcasecmp(action, "Logoff")) {
! 			astman_send_ack(s, "See ya");
  			return -1;
  		} else
! 			astman_send_error(s, "Authentication Required");
  	} else {
  		while( tmp ) { 		
--- 609,619 ----
  					ast_verbose(VERBOSE_PREFIX_2 "Manager '%s' logged on from %s\n", s->username, inet_ntoa(s->sin.sin_addr));
  				ast_log(LOG_EVENT, "Manager '%s' logged on from %s\n", s->username, inet_ntoa(s->sin.sin_addr));
! 				astman_send_ack(s, m, "Authentication accepted");
  			}
  		} else if (!strcasecmp(action, "Logoff")) {
! 			astman_send_ack(s, m, "See ya");
  			return -1;
  		} else
! 			astman_send_error(s, m, "Authentication Required");
  	} else {
  		while( tmp ) { 		
***************
*** 584,588 ****
  						return -1;
  				} else {
! 					astman_send_error(s, "Permission denied");
  				}
  				return 0;
--- 623,627 ----
  						return -1;
  				} else {
! 					astman_send_error(s, m, "Permission denied");
  				}
  				return 0;
***************
*** 590,594 ****
  			tmp = tmp->next;
  		}
! 		astman_send_error(s, "Invalid/unknown command");
  	}
  	return 0;
--- 629,633 ----
  			tmp = tmp->next;
  		}
! 		astman_send_error(s, m, "Invalid/unknown command");
  	}
  	return 0;




More information about the svn-commits mailing list