[Freeswitch-branches] [commit] r3876 - freeswitch/branches/knhor/trunk/src/mod/applications/mod_conference

Freeswitch SVN knhor at freeswitch.org
Sun Dec 31 03:20:45 EST 2006


Author: knhor
Date: Sun Dec 31 03:20:45 2006
New Revision: 3876

Modified:
   freeswitch/branches/knhor/trunk/src/mod/applications/mod_conference/mod_conference.c

Log:
add simple chat permissions using the following configuration syntax example;

<configuration name="conference.conf" description="Audio Conference">
 <profiles>
  <profile name="default">
   <param name="chat-permissions" value="default"/>
  </profile>
 </profiles>

 <chat-permissions>
  <profile name="default">
    <!-- both of these users have a functionally equivalent capability set -->
    <user name="bob at somewhere.com" commands="all"/>
    <!-- individually specified commands must be book-end'ed with the | charachter -->
    <user name="harry at somewhere.com" commands="|deaf|dial|energy|kick|list|lock|mute|norecord|play|record|relate|say|saymember|stop|transfer|undeaf|unlock|unmute|volume_in|volume_out|"/>
  </profile>
 </chat-permissions>
</configuration>


Modified: freeswitch/branches/knhor/trunk/src/mod/applications/mod_conference/mod_conference.c
==============================================================================
--- freeswitch/branches/knhor/trunk/src/mod/applications/mod_conference/mod_conference.c	(original)
+++ freeswitch/branches/knhor/trunk/src/mod/applications/mod_conference/mod_conference.c	Sun Dec 31 03:20:45 2006
@@ -184,6 +184,7 @@
 	char *profile_name;
 	char *domain;
 	char *caller_controls;
+	char *chat_permissions;
 	uint32_t flags;
 	switch_call_cause_t bridge_hangup_cause;
 	switch_mutex_t *flag_mutex;
@@ -199,7 +200,7 @@
 	int32_t energy_level;
 	uint8_t min;
 	conf_xml_cfg_t xml_cfg;
-//	switch_hash_t *chat_permissions;
+	switch_hash_t *chat_permissions_map;
 } conference_obj_t;
 
 /* Relationship with another member */
@@ -1477,8 +1478,6 @@
     xml_menus = switch_xml_child(menu_group, "menus");
     xml_menu = (xml_menus != NULL ? switch_xml_find_child(xml_menus, "menu", "name", menu_name) : NULL);
 
-
-
     /* if we found the requested menu in our menu_group */
     if (xml_menu != NULL && xml_menu != NULL) {
         *ctx = (caller_control_menu_ctx_t *)switch_core_alloc(conference->pool, sizeof(caller_control_menu_ctx_t));
@@ -3255,7 +3254,7 @@
 static api_command_t conf_api_sub_commands[] = {
     {"deaf",         (api_cmd_fn_t)&conf_api_sub_deaf,          CONF_API_SUB_MEMBER_TARGET,    "<confname> deaf <[member_id|all]|last>"},
     {"dial",         (api_cmd_fn_t)&conf_api_sub_dial,          CONF_API_SUB_ARGS_SPLIT,       "<confname> dial <endpoint_module_name>/<destination> <callerid number> <callerid name> <flags>"},
-    {"energy",       (api_cmd_fn_t)&conf_api_sub_energy,        CONF_API_SUB_MEMBER_TARGET,    "<confname> energy <member_id|all|last> [<newval>]"},
+    {"energy",       (api_cmd_fn_t)&conf_api_sub_energy,        CONF_API_SUB_MEMBER_TARGET,    "<confname> energy <member_id|all|last> [<newval>]"}, 
     {"kick",         (api_cmd_fn_t)&conf_api_sub_kick,          CONF_API_SUB_MEMBER_TARGET,    "<confname> kick <[member_id|all|last]>"},
     {"list",         (api_cmd_fn_t)&conf_api_sub_list,          CONF_API_SUB_ARGS_SPLIT,       "<confname> list [delim <string>]"},
     {"lock",         (api_cmd_fn_t)&conf_api_sub_lock,          CONF_API_SUB_ARGS_SPLIT,       "<confname> lock"},
@@ -3627,7 +3626,7 @@
 #ifdef OPTION_IVR_MENU_SUPPORT
 		xml_cfg->menus = switch_xml_child(cfg, "menus");
 #endif
-		xml_cfg->chat_permissions = switch_xml_child(cfg, "chat-permisions");
+		xml_cfg->chat_permissions = switch_xml_child(cfg, "chat-permissions");
 		status = SWITCH_STATUS_SUCCESS;
 	    }
 	}
@@ -4093,12 +4092,15 @@
     if (body != NULL && (lbuf = strdup(body))) {
         int argc;
         char *argv[25];
+	char *perm = NULL;
 
         memset(argv, 0, sizeof(argv));
         argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
 
         /* try to find a command to execute */
         if (argc) {
+		char *cmd = switch_mprintf("|%s|",argv[0]);
+
             /* special case list */
             if (strcasecmp(argv[0], "list") == 0) {
 		stream.write_function(&stream, "(%u member%s, %s)\n", 
@@ -4108,12 +4110,16 @@
 				   );
                 conference_list_pretty(conference, &stream);
 #ifdef ENABLE_CHAT_ADMIN
-            /* provide help */
-            } else if (strcasecmp(argv[0], "help") == 0 || strcasecmp(argv[0], "commands") == 0) {
-                    stream.write_function(&stream, "%s\n", conf_api_interface.syntax);
-            /* find a normal command */
-            } else {
-                conf_api_dispatch(conference, &stream, argc, argv, (const char *)body);
+	    } else if (conference->chat_permissions != NULL
+		&& (perm = (char *) switch_core_hash_find(conference->chat_permissions_map, from)) != NULL
+		&& (strcasecmp(perm,"all") == 0 || (cmd != NULL && strstr(perm,cmd) != NULL))) {
+		    /* provide help */
+		    if (strcasecmp(argv[0], "help") == 0 || strcasecmp(argv[0], "commands") == 0) {
+			    stream.write_function(&stream, "%s\n", conf_api_interface.syntax);
+		    /* find a normal command */
+		    } else {
+			conf_api_dispatch(conference, &stream, argc, argv, (const char *)body);
+		    }
 #endif
             }
         } else {
@@ -4148,6 +4154,45 @@
     /*.chat_interface */ &conference_chat_interface
 };
 
+switch_status_t chat_permissions_get(conference_obj_t *conference)
+{
+	switch_status_t status = SWITCH_STATUS_FALSE;
+	int count = 0;
+
+	assert(conference != NULL);
+
+	if (conference->xml_cfg.chat_permissions != NULL && !switch_strlen_zero(conference->chat_permissions)) {
+		switch_xml_t profile = switch_xml_find_child(conference->xml_cfg.chat_permissions, "profile", "name", conference->chat_permissions);
+
+		if (profile != NULL) {
+			switch_xml_t xml_kvp;
+
+			if (conference->chat_permissions_map != NULL) {
+				switch_core_hash_destroy(conference->chat_permissions_map);
+			}
+			switch_core_hash_init(&conference->chat_permissions_map, conference->pool);
+
+			if (conference->chat_permissions_map != NULL) {
+				for (xml_kvp = switch_xml_child(profile, "user"); xml_kvp; xml_kvp = xml_kvp->next) {
+					char *name = (char *) switch_xml_attr(xml_kvp, "name");
+					char *commands = (char *) switch_xml_attr(xml_kvp, "commands");
+
+					if (!switch_strlen_zero(name) && !switch_strlen_zero(commands)) {
+						switch_core_hash_insert(conference->chat_permissions_map, name, commands);
+						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "chat-permissions %s=%s\n",name,commands);
+						count ++;
+					}
+				}
+				if (count != 0) {
+					status = SWITCH_STATUS_SUCCESS;
+				}
+			}
+		}
+	}
+
+	return status;
+}
+
 /* create a new conferene with a specific profile */
 static conference_obj_t *conference_new(char *name, conf_xml_cfg_t *xml_cfg, switch_memory_pool_t *pool)
 {
@@ -4175,6 +4220,7 @@
     char *caller_id_name = NULL;
     char *caller_id_number = NULL;
     char *caller_controls = NULL;
+    char *chat_permissions = NULL;
     uint32_t rate = 8000, interval = 20;
     switch_status_t status;
 
@@ -4245,6 +4291,8 @@
             caller_id_number = val;
         } else if (!strcasecmp(var, "caller-controls")) {
             caller_controls = val;
+        } else if (!strcasecmp(var, "chat-permissions")) {
+            chat_permissions = val;
         }
     }
 
@@ -4362,6 +4410,10 @@
 	conference->caller_controls = switch_core_strdup(conference->pool, caller_controls);
     }
 
+    if (!switch_strlen_zero(chat_permissions)) {
+	conference->chat_permissions = switch_core_strdup(conference->pool, chat_permissions);
+    }
+
     conference->name = switch_core_strdup(conference->pool, name);
     if (domain) {
         conference->domain = switch_core_strdup(conference->pool, domain);
@@ -4374,6 +4426,10 @@
 	/* copy the xml config sections to the new conference */
 	memcpy(&conference->xml_cfg,xml_cfg,sizeof(conf_xml_cfg_t));
 
+	/* build the chat interface permissions map */
+	chat_permissions_get(conference);
+
+
     /* Activate the conference mutex for exclusivity */
     switch_mutex_init(&conference->mutex, SWITCH_MUTEX_NESTED, conference->pool);
     switch_mutex_init(&conference->member_mutex, SWITCH_MUTEX_NESTED, conference->pool);



More information about the Freeswitch-branches mailing list