[asterisk-commits] branch oej/aum - r7410 /team/oej/aum/res/res_aum.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Dec 8 21:46:37 CST 2005


Author: oej
Date: Thu Dec  8 21:46:35 2005
New Revision: 7410

URL: http://svn.digium.com/view/asterisk?rev=7410&view=rev
Log:
Fixing compilation.

Modified:
    team/oej/aum/res/res_aum.c

Modified: team/oej/aum/res/res_aum.c
URL: http://svn.digium.com/view/asterisk/team/oej/aum/res/res_aum.c?rev=7410&r1=7409&r2=7410&view=diff
==============================================================================
--- team/oej/aum/res/res_aum.c (original)
+++ team/oej/aum/res/res_aum.c Thu Dec  8 21:46:35 2005
@@ -256,25 +256,27 @@
 iconv_t	ichandler_utf8_to_iso88591;	/*!< libiconv handler from utf8 to iso8859-1 */
 iconv_t	ichandler_iso88591_to_utf8;	/*!< libiconv handler from iso8859- to utf8 */
 
-/*! \brief the Group list */
+/*! \brief the AUM Group list */
 static struct s_aum_grouplist {
 	ASTOBJ_CONTAINER_COMPONENTS(struct aum_group);
 } aum_grouplist;
 
-/*! \brief the User list */
+/*! \brief the AUM User list */
 static struct s_aum_userlist {
 	ASTOBJ_CONTAINER_COMPONENTS(struct aum_user);
 } aum_userlist;
 
-/*! \brief the realtime user cache */
+/*! \brief The realtime user cache */
 struct aum_usercache_struct {
 	struct aum_user *user;
 	AST_LIST_ENTRY(aum_usercache_struct) list;
 };
 
-static int aum_usercache_count = 0;
-static int aum_usercache_max = 50;
-static AST_LIST_HEAD_STATIC(aum_usercache, aum_usercache_struct);
+static int aum_usercache_count = 0;	/*!< Current number of users in user cache */
+static int aum_usercache_max;		/*!< Maximum number of users in cache */
+#define DEFAULT_USERCACHE_MAX	50
+
+static AST_LIST_HEAD_STATIC(aum_usercache, aum_usercache_struct);	/*!< The user cache for realtime */
 
 /*! brief Different config options for address formats */
 static struct aum_address_config_struct aum_address_config[] = {
@@ -312,15 +314,15 @@
 
 const char *modulereloadreason2txt(enum modulereloadreason reason)
 {
-        switch (reason) {
-        case MODULE__LOAD:       return "LOAD (Channel module load)";
-                                        break;
-        case MODULE__RELOAD:     return "RELOAD (Channel module reload)";
-                                        break;
-        case MODULE_CLI_RELOAD:        return "CLIRELOAD (Channel module reload by CLI command)";
-                                        break;
-        default:        return "MANAGERRELOAD (Channel module reload by manager)";
-                                        break;
+	switch (reason) {
+	case MODULE__LOAD:	return "LOAD (Channel module load)";
+		break;
+	case MODULE__RELOAD:	return "RELOAD (Channel module reload)";
+		break;
+	case MODULE_CLI_RELOAD:	return "CLIRELOAD (Channel module reload by CLI command)";
+		break;
+	default:        	return "MANAGERRELOAD (Channel module reload by manager)";
+		break;
         };
 };
 
@@ -357,7 +359,7 @@
 	if (aum_real_groups_enabled)
 		ast_cli(fd, "  Groups - realtime:     %-10.10d\n", aum_real_groups);
 	if (aum_real_users_enabled)
-		ast_cli(fd, "  Realtime cache:        %d objects (%-10.10d kb) \n", aum_usercache_count, (aum_usercache_count * (sizeof(struct aum_user) + sizeof(struct aum_usercache_struct)) / 1000 ) );
+		ast_cli(fd, "  Realtime cache:        %d objects (%-10.10d kb) %d %% full\n", aum_usercache_count, (aum_usercache_count * (sizeof(struct aum_user) + sizeof(struct aum_usercache_struct)) / 1000), (aum_usercache_count / aum_usercache_max * 100 ) );
 	ast_cli(fd, "\n\n");
 	
 	return RESULT_SUCCESS;
@@ -944,22 +946,52 @@
 	struct aum_usercache_struct *temp;
 	struct aum_usercache_struct *top_of_the_class = (struct aum_usercache_struct *) NULL;
 
+	AST_LIST_LOCK(&aum_usercache);
 	/* Find user in cache */
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&aum_usercache, temp, list) {
 		if (temp->user == user) {
 			top_of_the_class = temp;
 			/* Remove from current position in list */
-			AST_LIST_LOCK(&aum_usercache);
 			AST_LIST_REMOVE_CURRENT(&aum_usercache, list);
 		}
 	};
+	AST_LIST_TRAVERSE_SAFE_END;
 	/* Add her to top */
-	if (top_of_the_class) {
+	if (top_of_the_class) 
 		AST_LIST_INSERT_TAIL(&aum_usercache, top_of_the_class, list);
-		AST_LIST_UNLOCK(&aum_usercache);
-	}
+
+	AST_LIST_UNLOCK(&aum_usercache);
 
 	/* Return */
+}
+
+/*!< Add channel variable to list 
+ * 	\param var	AST_variable, list pointer
+ * 	\param name	Name of variable
+ * 	\param value	Value -	if value is NULL name is supposed to contain both name and value with = sign between them
+ * 	\return 	Head of variable list
+ */
+static struct ast_variable *add_variable_to_list(struct ast_variable *var, char *name, char *value)
+{
+	char *varname = name;
+	char *varval = value;
+	struct ast_variable *tmpvar = (struct ast_variable *) NULL;
+
+	if (!value) {	/* No value, both are to be found in name */
+		varname = ast_strdupa(name);
+		if (varname && (varval = strchr(varname,'='))) {
+			*varval = '\0';
+			varval++;
+		}
+	}
+
+	if (varname && varval)
+	if (!(tmpvar = ast_variable_new(varname, varval))) 
+		return var;
+
+	tmpvar->next = var;
+
+	return tmpvar;
 }
 
 /*! \brief Parse configuration file and build AUM in-memory user
@@ -977,7 +1009,6 @@
 	struct aum_address *address;
 	struct aum_context *context;
 	enum aum_config_options option;
-	char *varname = NULL, *varval = NULL;
 
 	/* Check if username exists already */
 	if (find_aum_user(username)) {
@@ -1094,16 +1125,7 @@
 			break;
 		case AUM_CNF_CHANVAR:
 			/* Set peer channel variable */
-			varname = ast_strdupa(x->value);
-			if (varname && (varval = strchr(varname,'='))) {
-				struct ast_variable *tmpvar;
-				*varval = '\0';
-				varval++;
-				if ((tmpvar = ast_variable_new(varname, varval))) {
-					tmpvar->next = user->chanvars;
-					user->chanvars = tmpvar;
-				}
-			}
+			user->chanvars = add_variable_to_list(user->chanvars, x->value, NULL);
 			break;
 		case AUM_CNF_GROUPVAR:	/* Channel group to set */
 			// chanvars GROUP
@@ -1245,7 +1267,8 @@
 		return (struct aum_user *) NULL;
 
 	/* User found in realtime, now build it in memory */
-	/* Find username */
+
+	/* Find username from realtime if it's not the argument */
 	if (strcasecmp(field, "name")) {
 		text = var;
 		while (text) {
@@ -1275,7 +1298,6 @@
 static struct aum_user *aum_user_realtime_load(char *username)
 {
 	return aum_user_realtime_loadbyfield("name", username);
-
 }
 
 /*! \brief Get user from realtime storage 
@@ -1285,7 +1307,6 @@
 static struct aum_user *aum_user_realtime_load_by_numuserid(char *numuserid)
 {
 	return aum_user_realtime_loadbyfield("numuserid", numuserid);
-
 }
 
 
@@ -1311,6 +1332,7 @@
 static void remove_group_from_user(struct aum_group *group, struct aum_user *user)
 {
 	struct aum_group_member *member;
+
 	if (!group || !user)
 		return;
 
@@ -1434,6 +1456,7 @@
 	aum_static_groups = 0;
 	aum_real_users = 0;
 	aum_static_users = 0;
+	aum_usercache_max = DEFAULT_USERCACHE_MAX;
 	ASTOBJ_CONTAINER_INIT(&aum_grouplist);
 	ASTOBJ_CONTAINER_INIT(&aum_userlist);
 
@@ -1481,6 +1504,7 @@
 	}
 	
 	ast_log(LOG_DEBUG, "===== Starting to read [users] section\n");
+
 	/* Load the rest of the sections - group details and users */
 	cat = ast_category_browse(cfg, NULL);
 	while (cat) {
@@ -1629,9 +1653,9 @@
 	res = ASTOBJ_CONTAINER_FIND(&aum_userlist, userid);	
 	if (!res && aum_real_users_enabled) {
 		res = aum_user_realtime_load(userid);
-	} else if (res && ast_test_flag(user, AUM_USER_FLAG_REALTIME))
+	} else if (res && ast_test_flag(res, AUM_USER_FLAG_REALTIME))
 		/* Move user to top of cache */
-		aum_rtcache_movetotop(user);
+		aum_rtcache_movetotop(res);
 	return res;
 }
 
@@ -1655,7 +1679,8 @@
 	return aum_group_test_full(user, find_group_by_name(groupname));
 }
 
-void initialize_charset_conversion()
+/*! \brief Initialize charset conversion handlers */
+void initialize_charset_conversion(void)
 {
 	ichandler_utf8_to_iso88591 = iconv_open("utf8", "ISO-8859-1");
 	ichandler_iso88591_to_utf8 = iconv_open("ISO-8859-1", "utf8");
@@ -1671,9 +1696,11 @@
 	reload_config(MODULE__LOAD);
 	aum_rtcache_freeall();
 
+	/* Check if realtime is enabled */
+	aum_real_users_enabled = ast_check_realtime("aumusers");
 	aum_real_groups_enabled = ast_check_realtime("aumgroups");
-	aum_real_users_enabled = ast_check_realtime("aumgroups");
-
+
+	/* Register CLI */
 	ast_cli_register_multiple(my_clis, sizeof(my_clis)/ sizeof(my_clis[0]));
 	ast_custom_function_register(&aum_user_function);
 



More information about the asterisk-commits mailing list