[commit] r3250 - freeswitch/branches/knhor/wip/mod_conference
Author: knhor Date: Wed Nov 1 17:27:18 2006 New Revision: 3250 Modified: freeswitch/branches/knhor/wip/mod_conference/mod_conference.c Log: progress update - all functions fleshed out 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 17:27:18 2006 @@ -242,7 +242,10 @@ static switch_status_t chat_send(char *proto, char *from, char *to, char *subject, char *body, char *hint); static void launch_conference_record_thread(conference_obj_t *conference, char *path); +typedef int (*conf_api_args_cmd_t)(conference_obj_t*, switch_stream_handle_t*, int, char**); typedef int (*conf_api_member_cmd_t)(conference_obj_t*, conference_member_t*, int, switch_stream_handle_t*, void*); +typedef int (*conf_api_text_cmd_t)(conference_obj_t*, switch_stream_handle_t*, char*); + static void conference_member_itterator(conference_obj_t *conference, switch_stream_handle_t *stream, conf_api_member_cmd_t pfncallback, @@ -1822,12 +1825,44 @@ return err; } -static void conference_function_api_list(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) + +static int conference_function_api_list(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) { -// switch_event_t *event; +//static void conference_list(conference_obj_t *conference, switch_stream_handle_t *stream, char *delim) + switch_hash_index_t *hi; + void *val; + char *d = ";"; + if (argv[1]) { + if (argv[2] && !strcasecmp(argv[1], "delim")) { + d = argv[2]; + + if (*d == '"') { + if (++d) { + char *p; + if ((p = strchr(d, '"'))) { + *p = '\0'; + } + } else { + d = ";"; + } + } + } + } + + for (hi = switch_hash_first(globals.conference_pool, globals.conference_hash); hi; hi = switch_hash_next(hi)) { + switch_hash_this(hi, NULL, NULL, &val); + conference = (conference_obj_t *) val; + + stream->write_function(stream, "Conference %s (%u members)\n", conference->name, conference->count); + conference_list(conference, stream, d); + stream->write_function(stream, "\n"); + } + + return 0; } -static void conference_function_api_play(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) + +static int conference_function_api_play(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) { switch_event_t *event; @@ -1864,97 +1899,84 @@ stream->write_function(stream, "Member: %u not found.\n", id); } } + + return 0; } -static void conference_function_api_say(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) +static int conference_function_api_say(conference_obj_t *conference, switch_stream_handle_t *stream, char *text) { - /* - switch_event_t *event; - char *tbuf = NULL; - char *text; + int err = 0; - if (argc > 2 && (tbuf = strdup(buf))) { - if ((text = strstr(tbuf, "say"))) { - text += 4; - while(*text == ' ') { - text++; + if (text != NULL && !switch_strlen_zero(text)) { + if (conference_say(conference, text, 0) == SWITCH_STATUS_SUCCESS) { + switch_event_t *event; + + stream->write_function(stream, "(say) OK\n"); + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "speak-text"); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Text", text); + switch_event_fire(&event); } - if (!switch_strlen_zero(text) && conference_say(conference, text, 0) == SWITCH_STATUS_SUCCESS) { - stream->write_function(stream, "(say) OK\n"); - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) { - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name); - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "speak-text"); - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Text", text); - switch_event_fire(&event); - } - } else { - stream->write_function(stream, "(say) Error!"); - } + } else { + stream->write_function(stream, "(say) Error!"); } - free(tbuf); } else { stream->write_function(stream, "(say) Error! No text."); + err = 1; } - */ + + return err; } -static void conference_function_api_saymember(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) +static int conference_function_api_saymember(conference_obj_t *conference, switch_stream_handle_t *stream, char *text) { - /* - switch_event_t *event; - char *tbuf = NULL, *text, *name; - uint32_t id; - conference_member_t *member; + int err = 0; - if (argc > 3) { - id = atoi(argv[3]); - } else { - stream->write_function(stream, "(saymember) Syntax Error!"); - goto done; - } + if (text != NULL && !switch_strlen_zero(text)) { + char *name = strdup(text); + uint32_t id = 0; + conference_member_t *member; - if ((tbuf = strdup(buf))) { - if ((name = strstr(tbuf, "saymember "))) { - name += 10; + if (name != NULL && *name) { + text = strchr(name, ' '); + *name = '\0'; + id = atoi(name); + free(name); + } else { + err = 1; + } - if (*name) { - text = strchr(name, ' '); - id = atoi(name); - } else { - stream->write_function(stream, "(saymember) Syntax Error!"); - goto done; - } + if (id != 0 && (member = conference_member_get(conference, id))) { + if (text && conference_member_say(conference, member, text, 0) == SWITCH_STATUS_SUCCESS) { + switch_event_t *event; - if ((member = conference_member_get(conference, id))) { - if (text && conference_member_say(conference, member, text, 0) == SWITCH_STATUS_SUCCESS) { - stream->write_function(stream, "(saymember) OK\n"); - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) { - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name); - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "speak-text-member"); - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id); - switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Text", text); - switch_event_fire(&event); - } - } else { - stream->write_function(stream, "(saymember) Error!"); + stream->write_function(stream, "(saymember) OK\n"); + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, CONF_EVENT_MAINT) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Conference-Name", conference->name); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "speak-text-member"); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Member-ID", "%u", id); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Text", text); + switch_event_fire(&event); } } else { - stream->write_function(stream, "(saymember) Unknown Member %u!", id); + stream->write_function(stream, "(saymember) Error!"); } } else { - stream->write_function(stream, "(saymember) Syntax Error!"); + stream->write_function(stream, "(saymember) Unknown Member %u!", id); + err = 1; } - - free(tbuf); + } else { + err = 1; } - */ + + return err; } -static void conference_function_api_stop(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) +static int conference_function_api_stop(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) { - /* - switch_event_t *event; uint8_t current = 0, all = 0; + int err = 0; if (argc > 2) { current = strcasecmp(argv[2], "current") ? 0 : 1; @@ -1965,6 +1987,7 @@ if (argc == 4) { uint32_t id = atoi(argv[3]); conference_member_t *member; + if ((member = conference_member_get(conference, id))) { uint32_t stopped = conference_member_stop_file(member, current ? FILE_STOP_CURRENT : FILE_STOP_ALL); stream->write_function(stream, "Stopped %u files.\n", stopped); @@ -1976,15 +1999,15 @@ stream->write_function(stream, "Stopped %u files.\n", stopped); } } else { - stream->write_function(stream, "Usage stop [current/all]\n"); + err = 1; } - */ + + return err; } -static void conference_function_api_relate(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) +static int conference_function_api_relate(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) { - /* - switch_event_t *event; + int err = 0; char *relate_usage = "Usage relate <id> <id> [nospeak|nohear|clear]\n"; if (argc > 4) { @@ -2055,10 +2078,12 @@ } else { stream->write_function(stream, relate_usage); } - */ + +done: + return err; } -static void conference_function_api_lock(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) +static int conference_function_api_lock(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) { switch_event_t *event; @@ -2069,9 +2094,11 @@ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "lock"); switch_event_fire(&event); } + + return 0; } -static void conference_function_api_unlock(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) +static int conference_function_api_unlock(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) { switch_event_t *event; @@ -2082,21 +2109,27 @@ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Action", "unlock"); switch_event_fire(&event); } + + return 0; } -static void conference_function_api_dial(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) +static int conference_function_api_dial(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) { + int err = 0; + if (argc > 2) { conference_outcall(conference, NULL, argv[2], 60, argv[3], argv[4], argv[5]); stream->write_function(stream, "OK\n"); } else { - stream->write_function(stream, "Error!\n"); + err = 1; } + + return err; } -static void conference_function_api_transfer(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) +static int conference_function_api_transfer(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) { - char *transfer_usage = "Usage transfer <id> <confname>\n"; + int err = 0; if (argc > 3) { conference_member_t *member = NULL; @@ -2180,23 +2213,24 @@ } } else { - stream->write_function(stream, transfer_usage); + err = 1; } done: - { - } + return err; } -static void conference_function_api_record(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) +static int conference_function_api_record(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) { if (argc > 2) { launch_conference_record_thread(conference, argv[2]); } else { stream->write_function(stream, "usage record <filename>\n"); } + + return 0; } -static void conference_function_api_norecord(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) +static int conference_function_api_norecord(conference_obj_t *conference, switch_stream_handle_t *stream, int argc, char**argv) { if (argc > 2) { int all = (strcasecmp(argv[2], "all") == 0 ); @@ -2207,6 +2241,8 @@ } else { stream->write_function(stream, "usage norecord <[filename | all]>\n"); } + + return 0; } /* API Interface Function sub-commands */ @@ -2216,18 +2252,18 @@ {"volume in", &conference_function_api_volume_in, 1, "<confname> volume_in <member_id|all> [<newval>]"}, {"volume out", &conference_function_api_volume_out, 1, "<confname> volume_out <member_id|all> [<newval>]"}, {"play", &conference_function_api_play, 0, "<confname> play <file_path> [<member_id>]"}, - {"say", &conference_function_api_say, 0, "<confname> say <text>"}, - {"saymember", &conference_function_api_saymember, 0, "<confname> saymember <member_id><text>"}, + {"say", &conference_function_api_say, 2, "<confname> say <text>"}, + {"saymember", &conference_function_api_saymember, 2, "<confname> saymember <member_id><text>"}, {"stop", &conference_function_api_stop, 1, "<confname> stop <[current|all]> [<member_id>]"}, {"kick", &conference_function_api_kick, 1, "<confname> kick <[member_id|all]>"}, {"mute", &conference_function_api_mute, 1, "<confname> mute <[member_id|all]>"}, {"unmute", &conference_function_api_unmute, 1, "<confname> unmute <[member_id|all]>"}, {"deaf", &conference_function_api_deaf, 1, "<confname> deaf <[member_id|all]>"}, {"undeaf", &conference_function_api_undeaf, 1, "<confname> undef <[member_id|all]>"}, - {"relate", &conference_function_api_relate, 0, "<confname> relate <member_id> <other_member_id> [nospeak|nohear]"}, + {"relate", &conference_function_api_relate, 0, "<confname> relate <member_id> <other_member_id> [nospeak|nohear|clear]"}, {"lock", &conference_function_api_lock, 0, "<confname> lock"}, {"unlock", &conference_function_api_unlock, 0, "<confname> unlock"}, - {"dial", &conference_function_api_transfer, 0, "<confname> dial <endpoint_module_name>/<destination>"}, + {"dial", &conference_function_api_dial, 0, "<confname> dial <endpoint_module_name>/<destination>"}, {"transfer", &conference_function_api_transfer, 0, "<confname> transfer <member_id> <conference_name>"}, {"record", &conference_function_api_record, 0, "<confname> record <filename>"}, {"norecord", &conference_function_api_norecord, 0, "<confname> norecord <[filename|all]>"}, @@ -2257,24 +2293,28 @@ if (buf != NULL && (lbuf = strdup(buf))) { conference_obj_t *conference = NULL; - int argc,i; + int argc; char *argv[25]; + memset(argv,0,sizeof(argv)); argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); // find a command to execute - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Conference argc: %u\n",argc); - for (i=0; i<argc; i++) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Conference argv[%u]: '%u'\n",i,argv[i]); - } if (argc) { - int i,found; + int i,found=0; 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: // generic command type + 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 (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 { @@ -2286,18 +2326,38 @@ } 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])) { + if (pfn(conference, NULL, id, stream, argv[3]) != 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; + + // advance past all leading white space after command + while(*pstr == ' ' || *pstr == '\t') { + pstr++; + } + + 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,(char *)conf_api_interface.syntax); + } } else { - stream->write_function(stream,conf_api_interface.syntax); + stream->write_function(stream,(char *)conf_api_interface.syntax); } } @@ -3323,7 +3383,7 @@ // free api interface help ".syntax" field string if (conf_api_interface.syntax != NULL) - free(conf_api_interface.syntax); + free((char *)conf_api_interface.syntax); } return SWITCH_STATUS_SUCCESS;
participants (1)
-
Freeswitch SVN