[asterisk-commits] file: branch group/res_config_ldap r99299 - /team/group/res_config_ldap/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 22 10:39:27 CST 2008


Author: file
Date: Mon Jan 21 09:43:24 2008
New Revision: 99299

URL: http://svn.digium.com/view/asterisk?view=rev&rev=99299
Log:
Bring module up to date with latest changes.

Modified:
    team/group/res_config_ldap/res/res_config_ldap.c

Change Statistics:
 team/group/res_config_ldap/res/res_config_ldap.c |   66 ++++++-----
 1 file changed, 36 insertions(+), 30 deletions(-)

Modified: team/group/res_config_ldap/res/res_config_ldap.c
URL: http://svn.digium.com/view/asterisk/team/group/res_config_ldap/res/res_config_ldap.c?view=diff&rev=99299&r1=99298&r2=99299
==============================================================================
--- team/group/res_config_ldap/res/res_config_ldap.c (original)
+++ team/group/res_config_ldap/res/res_config_ldap.c Mon Jan 21 09:43:24 2008
@@ -70,24 +70,14 @@
 
 static int parse_config(void);
 static int ldap_reconnect(void);
-static int realtime_ldap_status(int fd, int argc, char **argv);
+static char *realtime_ldap_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 
 struct category_and_metric {
-	char *name;
+	const char *name;
 	int metric;
-	char *variable_name;
-	char *variable_value;
+	const char *variable_name;
+	const char *variable_value;
 	int var_metric; /*!< For organizing variables (particularly includes and switch statments) within a context */
-};
-
-static char cli_realtime_ldap_status_usage[] =
-	"Usage: realtime ldap status\n"
-	"		Shows connection information for the LDAP RealTime driver\n";
-
-static struct ast_cli_entry cli_realtime_ldap_status = {
-	{ "realtime", "ldap", "status", NULL }, realtime_ldap_status,
-	"Shows connection information for the LDAP RealTime driver",
-	cli_realtime_ldap_status_usage, NULL
 };
 
 /*! \brief Table configuration */
@@ -103,6 +93,10 @@
 static AST_LIST_HEAD_NOLOCK_STATIC(table_configs, ldap_table_config);
 static struct ldap_table_config *base_table_config;
 static struct ldap_table_config *static_table_config;
+
+static struct ast_cli_entry ldap_cli[] = {
+	AST_CLI_DEFINE(realtime_ldap_status, "Shows connection information for the LDAP RealTime driver"),
+};
 
 /*! \brief Create a new table_config */
 static struct ldap_table_config *table_config_new(const char *table_name)
@@ -1014,7 +1008,7 @@
 	int i = 0;
 	struct ast_variable *new_v = NULL;
 	struct ast_category *cur_cat = NULL;
-	char *last_category = NULL;
+	const char *last_category = NULL;
 	int last_category_metric = 0;
 	struct category_and_metric *categories;
 	struct ast_variable **p;
@@ -1322,7 +1316,7 @@
 
 	ast_config_engine_register(&ldap_engine);
 	ast_verb(1, "LDAP RealTime driver loaded.\n");
-	ast_cli_register(&cli_realtime_ldap_status);
+	ast_cli_register_multiple(ldap_cli, sizeof(ldap_cli) / sizeof(struct ast_cli_entry));
 
 	ast_mutex_unlock(&ldap_lock);
 
@@ -1340,7 +1334,7 @@
 		ldap_unbind_ext_s(ldapConn,NULL,NULL);
 		ldapConn = NULL;
 	}
-	ast_cli_unregister(&cli_realtime_ldap_status);
+	ast_cli_unregister_multiple(ldap_cli, sizeof(ldap_cli) / sizeof(struct ast_cli_entry));
 	ast_config_engine_deregister(&ldap_engine);
 	ast_verb(1, "LDAP RealTime unloaded.\n");
 
@@ -1469,7 +1463,7 @@
 		return 1;
 	}
 
-	if (!host) {
+	if (ast_strlen_zero(host)) {
 		ast_log(LOG_ERROR, "Not enough parameters to connect to ldap database\n");
 		return 0;
 	}
@@ -1500,40 +1494,52 @@
 	}
 }
 
-static int realtime_ldap_status(int fd, int argc, char **argv)
+static char *realtime_ldap_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	char status[256], status2[100] = "";
 	int ctime = time(NULL) - connect_time;
 
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "realtime ldap status";
+		e->usage =
+			"Usage: realtime ldap status\n"
+			"               Shows connection information for the LDAP RealTime driver\n";
+		return NULL;
+	case CLI_GENERATE:
+		return NULL;
+	}
+
 	if (!ldapConn)
-		return RESULT_FAILURE;
-	if (host) 
+		return CLI_FAILURE;
+
+	if (!ast_strlen_zero(host)) 
 		snprintf(status, sizeof(status), "Connected to %s, port %d baseDN %s", host, port, basedn);
 
-	if (user && *user)
+	if (!ast_strlen_zero(user))
 		snprintf(status2, sizeof(status2), " with username %s", user);
 
 	if (ctime > 31536000) {
-		ast_cli(fd, "%s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n",
+		ast_cli(a->fd, "%s%s for %d years, %d days, %d hours, %d minutes, %d seconds.\n",
 				status, status2, ctime / 31536000,
 				(ctime % 31536000) / 86400, (ctime % 86400) / 3600,
 				(ctime % 3600) / 60, ctime % 60);
 	} else if (ctime > 86400) {
-		ast_cli(fd, "%s%s for %d days, %d hours, %d minutes, %d seconds.\n",
+		ast_cli(a->fd, "%s%s for %d days, %d hours, %d minutes, %d seconds.\n",
 				status, status2, ctime / 86400, (ctime % 86400) / 3600,
 				(ctime % 3600) / 60, ctime % 60);
 	} else if (ctime > 3600) {
-		ast_cli(fd, "%s%s for %d hours, %d minutes, %d seconds.\n",
+		ast_cli(a->fd, "%s%s for %d hours, %d minutes, %d seconds.\n",
 				status, status2, ctime / 3600, (ctime % 3600) / 60,
 				ctime % 60);
 	} else if (ctime > 60) {
-		ast_cli(fd, "%s%s for %d minutes, %d seconds.\n", status, status2,
+		ast_cli(a->fd, "%s%s for %d minutes, %d seconds.\n", status, status2,
 					ctime / 60, ctime % 60);
 	} else {
-		ast_cli(fd, "%s%s for %d seconds.\n", status, status2, ctime);
-	}
-
-	return RESULT_SUCCESS;
+		ast_cli(a->fd, "%s%s for %d seconds.\n", status, status2, ctime);
+	}
+
+	return CLI_SUCCESS;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "LDAP realtime interface",




More information about the asterisk-commits mailing list