[Freeswitch-svn] [commit] r3252 - freeswitch/branches/knhor/wip/mod_conference

Freeswitch SVN knhor at freeswitch.org
Wed Nov 1 19:11:09 EST 2006


Author: knhor
Date: Wed Nov  1 19:11:08 2006
New Revision: 3252

Modified:
   freeswitch/branches/knhor/wip/mod_conference/mod_conference.c

Log:
finish command parser

Modified: freeswitch/branches/knhor/wip/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/branches/knhor/wip/mod_conference/mod_conference.c	(original)
+++ freeswitch/branches/knhor/wip/mod_conference/mod_conference.c	Wed Nov  1 19:11:08 2006
@@ -1490,7 +1490,7 @@
 	return SWITCH_STATUS_SUCCESS;
 }
 
-static void conference_member_itterator(conference_obj_t *conference, switch_stream_handle_t *stream, int (*pfncallback)(conference_obj_t*, conference_member_t*, int, switch_stream_handle_t*, void*), void *data)
+static void conference_member_itterator(conference_obj_t *conference, switch_stream_handle_t *stream, conf_api_member_cmd_t pfncallback, void *data)
 {
 	conference_member_t *member = NULL;
 
@@ -1856,7 +1856,7 @@
 
 		stream->write_function(stream, "Conference %s (%u members)\n", conference->name, conference->count);
 		conference_list(conference, stream, d);
-		stream->write_function(stream, "\n");
+//		stream->write_function(stream, "\n");
 	}
 
 	return 0;
@@ -2292,7 +2292,6 @@
 	}
 
 	if (buf != NULL && (lbuf = strdup(buf))) {
-		conference_obj_t *conference = NULL;
 		int argc;
 		char *argv[25];
 
@@ -2302,62 +2301,72 @@
 		// find a command to execute
 		if (argc) {
 			int i,found=0;
+			uint32_t cnum = atoi(argv[0]);
+			conference_obj_t *conference = (cnum != 0 ? (conference_obj_t *) switch_core_hash_find(globals.conference_hash, argv[0]) : NULL);
 
-			for (i=0; i<CONFFUNCAPISIZE && !found; i++) {
-				if (strcasecmp(argv[i],conf_function_api_commands[i].pname) == 0) {
-					found = 1;
-					switch(conf_function_api_commands[i].fntype) {
-						case 0:	// commands that we've broken the command line into arguments for
-							{	conf_api_args_cmd_t pfn = (conf_api_args_cmd_t)conf_function_api_commands[i].pfnapicmd;
+			if(cnum == 0 || (cnum != 0 && conference != NULL)) {
+				int argn = (cnum != 0 ? 1 : 0);
 
-								if (pfn(conference, stream, argc, &argv[0]) != 0) {
-									// command returned error, so show syntax usage
-									stream->write_function(stream,conf_function_api_commands[i].psyntax);
-									}
-							}
-							break;
-						case 1: // member specific command that can be itteratted
-							{
-								uint32_t id = atoi(argv[2]);
-								int all = ( id == 0 && strcasecmp(argv[2], "all") == 0 );
+				for (i=0; i<CONFFUNCAPISIZE && !found; i++) {
+					if (strcasecmp(argv[argn],conf_function_api_commands[i].pname) == 0) {
+						found = 1;
+						switch(conf_function_api_commands[i].fntype) {
+							case 0:	// commands that we've broken the command line into arguments for
+								{	conf_api_args_cmd_t pfn = (conf_api_args_cmd_t)conf_function_api_commands[i].pfnapicmd;
 
-								if(all) {
-									 conference_member_itterator(conference, stream, conf_function_api_commands[i].pfnapicmd, argv[3]);
-								} else {
-									conf_api_member_cmd_t pfn = (conf_api_member_cmd_t)conf_function_api_commands[i].pfnapicmd;
-
-									if (pfn(conference, NULL, id, stream, argv[3]) != 0) {
+									if (pfn(conference, stream, argc, &argv[0]) != 0) {
 										// command returned error, so show syntax usage
 										stream->write_function(stream,conf_function_api_commands[i].psyntax);
 										}
 								}
+								break;
+							case 1: // member specific command that can be itteratted
+								{
+									uint32_t id = atoi(argv[argn+1]);
+									int all = ( id == 0 && strcasecmp(argv[argn+1], "all") == 0 );
 
-							}
-							break;
-						case 2:	// commands that deals with all text after command
-							{	conf_api_text_cmd_t pfn = (conf_api_text_cmd_t)conf_function_api_commands[i].pfnapicmd;
-								char *pstr = lbuf+strlen(conf_function_api_commands[i].pname)+1;
+									if(all) {
+										 conference_member_itterator(conference, stream, conf_function_api_commands[i].pfnapicmd, argv[argn+2]);
+									} else {
+										conf_api_member_cmd_t pfn = (conf_api_member_cmd_t)conf_function_api_commands[i].pfnapicmd;
 
-								// advance past all leading white space after command
-								while(*pstr == ' ' || *pstr == '\t') {
-									pstr++;
+										if (pfn(conference, NULL, id, stream, argv[argn+2]) != 0) {
+											// command returned error, so show syntax usage
+											stream->write_function(stream,conf_function_api_commands[i].psyntax);
+											}
+									}
+
 								}
+								break;
+							case 2:	// commands that deals with all text after command
+								{	conf_api_text_cmd_t pfn = (conf_api_text_cmd_t)conf_function_api_commands[i].pfnapicmd;
+									char *pstr = lbuf+strlen(conf_function_api_commands[i].pname)+1;
 
-								if (pfn(conference, stream, pstr) != 0) {
-									// command returned error, so show syntax usage
-									stream->write_function(stream,conf_function_api_commands[i].psyntax);
+									// advance past all leading white space after command
+									while(*pstr == ' ' || *pstr == '\t') {
+										pstr++;
 									}
-							}
-							break;
+
+									if (pfn(conference, stream, pstr) != 0) {
+										// command returned error, so show syntax usage
+										stream->write_function(stream,conf_function_api_commands[i].psyntax);
+										}
+								}
+								break;
+						}
 					}
 				}
+				if(!found) {
+					stream->write_function(stream, "Confernece command '%s' not found.\nTry 'help conference'\n", argv[argn]);
+//					stream->write_function(stream,(char *)conf_api_interface.syntax);
+				}
+			} else {
+				stream->write_function(stream,"No Conference called %s found.\n",argv[0]);
 			}
 
-			if(!found) {
-				stream->write_function(stream,(char *)conf_api_interface.syntax);
-			}
 		} else {
-			stream->write_function(stream,(char *)conf_api_interface.syntax);
+			stream->write_function(stream, "Command not specified.\nTry 'help conference'\n");
+//			stream->write_function(stream,(char *)conf_api_interface.syntax);
 		}
 	}
 
@@ -3329,7 +3338,7 @@
 	// build api interface help ".syntax" field string
 	p=strdup("list\n");
 	for (i=0; i<CONFFUNCAPISIZE; i++) {
-		nl=strlen(conf_function_api_commands[i].psyntax)+2;
+		nl=strlen(conf_function_api_commands[i].psyntax)+4;
 		if(p != NULL)
 			ol = strlen(p);
 		p = realloc(p,ol+nl);



More information about the Freeswitch-svn mailing list