[libgda/LIBGDA_5.0] GdaSql: removed the ldap_attributes command



commit ee81adcf1d63459ff33225e891763b2449baf482
Author: Vivien Malerba <malerba gnome-db org>
Date:   Thu Mar 1 20:52:47 2012 +0100

    GdaSql: removed the ldap_attributes command
    
    and replaced it with the "ldap_attributes" option

 tools/gda-sql.c               |   69 +++++++++++++----------------------------
 tools/help/C/gda-sql-help.xml |   22 +++++--------
 2 files changed, 30 insertions(+), 61 deletions(-)
---
diff --git a/tools/gda-sql.c b/tools/gda-sql.c
index 611bdc6..01f3173 100644
--- a/tools/gda-sql.c
+++ b/tools/gda-sql.c
@@ -126,7 +126,6 @@ typedef struct {
 
 	GdaSet *options;
 	GHashTable *parameters; /* key = name, value = G_TYPE_STRING GdaHolder */
-	gchar *ldap_attributes; /* default LDAP attributes */
 #define LAST_DATA_MODEL_NAME "_"
 	GHashTable *mem_data_models; /* key = name, value = the named GdaDataModel, ref# kept in hash table */
 
@@ -197,13 +196,15 @@ main (int argc, char *argv[])
 	setlocale (LC_ALL, "");
         gda_init ();
 
+#define DEFAULT_LDAP_ATTRIBUTES "cn"
 	has_threads = g_thread_supported ();
 	data = g_new0 (MainData, 1);
-	data->options = gda_set_new_inline (4,
+	data->options = gda_set_new_inline (5,
 					    "csv_names_on_first_line", G_TYPE_BOOLEAN, FALSE,
 					    "csv_quote", G_TYPE_STRING, "\"",
 					    "csv_separator", G_TYPE_STRING, ",",
-					    "ldap_dn", G_TYPE_STRING, "dn");
+					    "ldap_dn", G_TYPE_STRING, "dn",
+					    "ldap_attributes", G_TYPE_STRING, DEFAULT_LDAP_ATTRIBUTES);
 	value = gda_value_new (G_TYPE_STRING);
 	g_value_set_string (value, _("Set to TRUE when the 1st line of a CSV file holds column names"));
 	opt = gda_set_get_holder (data->options, "csv_names_on_first_line");
@@ -226,11 +227,14 @@ main (int argc, char *argv[])
 	g_value_set_string (value, _("Defines how the DN column is handled for LDAP searched (among \"dn\", \"rdn\" and \"none\")"));
 	opt = gda_set_get_holder (data->options, "ldap_dn");
 	gda_holder_set_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION, value, NULL);
+
+	g_value_set_string (value, _("Defines the LDAP attributes which are fetched by default by LDAP commands"));
+	opt = gda_set_get_holder (data->options, "ldap_attributes");
+	gda_holder_set_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION, value, NULL);
 	gda_value_free (value);
 
 	data->parameters = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
 	data->mem_data_models = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
-	data->ldap_attributes = g_strdup ("cn");
 	main_data = data;
 
 	/* output file */
@@ -2262,9 +2266,6 @@ static GdaInternalCommandResult *extra_command_undeclare_fk (SqlConsole *console
 static GdaInternalCommandResult *extra_command_ldap_search (SqlConsole *console, GdaConnection *cnc,
 							    const gchar **args,
 							    GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_ldap_attributes (SqlConsole *console, GdaConnection *cnc,
-								const gchar **args,
-								GError **error, gpointer data);
 static GdaInternalCommandResult *extra_command_ldap_descr (SqlConsole *console, GdaConnection *cnc,
 							   const gchar **args,
 							   GError **error, gpointer data);
@@ -2907,21 +2908,8 @@ build_internal_commands_list (void)
 	c = g_new0 (GdaInternalCommand, 1);
 	c->group = _("LDAP");
 	c->group_id = "LDAP";
-	c->name = g_strdup_printf (_("%s [attribute,[attribute],...]"), "ldap_attributes");
-	c->description = _("Set or get the default attributes manipulated by LDAP commands");
-	c->args = NULL;
-	c->command_func = (GdaInternalCommandFunc) extra_command_ldap_attributes;
-	c->user_data = NULL;
-	c->arguments_delimiter_func = NULL;
-	c->unquote_args = TRUE;
-	c->limit_to_main = TRUE;
-	commands->commands = g_slist_prepend (commands->commands, c);
-
-	c = g_new0 (GdaInternalCommand, 1);
-	c->group = _("LDAP");
-	c->group_id = "LDAP";
 	c->name = g_strdup_printf (_("%s <DN> [\"all\"|\"set\"|\"unset\"]"), "ldap_descr");
-	c->description = _("Shows all the attributes for the entry identified by its DN. If the "
+	c->description = _("Shows attributes for the entry identified by its DN. If the "
 			   "\"set\" 2nd parameter is passed, then all set attributes are show, if "
 			   "the \"all\" 2nd parameter is passed, then the unset attributes are "
 			   "also shown, and if the \"unset\" 2nd parameter "
@@ -4794,7 +4782,8 @@ extra_command_data_set_show (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
 		}
 
 		GdaDataModel *model;
-		model = gda_data_model_array_copy_model_ext (src, cols->len, (gint*) cols->data, error);
+		model = (GdaDataModel*) gda_data_model_array_copy_model_ext (src, cols->len, (gint*) cols->data,
+									     error);
 		g_array_free (cols, TRUE);
 		if (model) {
 			res = g_new0 (GdaInternalCommandResult, 1);
@@ -5640,9 +5629,13 @@ extra_command_ldap_search (SqlConsole *console, GdaConnection *cnc, const gchar
 		lfilter = g_strdup_printf ("(%s)", filter);
 
 	GdaHolder *param;
-	param = gda_set_get_holder (main_data->options, "ldap_dn");
-	model = gda_data_model_ldap_new (cs->cnc, base_dn, lfilter ? lfilter : filter, main_data->ldap_attributes, lscope);
+	const gchar *ldap_attributes;
+	ldap_attributes = g_value_get_string (gda_set_get_holder_value (main_data->options, "ldap_attributes"));
+	model = gda_data_model_ldap_new (cs->cnc, base_dn, lfilter ? lfilter : filter,
+					 ldap_attributes ? ldap_attributes : DEFAULT_LDAP_ATTRIBUTES,
+					 lscope);
 	g_free (lfilter);
+	param = gda_set_get_holder (main_data->options, "ldap_dn");
 	wrapper = gda_data_access_wrapper_new (model);
 	g_object_unref (model);
 
@@ -5678,26 +5671,6 @@ extra_command_ldap_search (SqlConsole *console, GdaConnection *cnc, const gchar
 	return res;
 }
 
-static GdaInternalCommandResult *
-extra_command_ldap_attributes (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
-			       GError **error, gpointer data)
-{
-	GdaInternalCommandResult *res = NULL;
-
-        if (args[0] && *args[0]) {
-		g_free (main_data->ldap_attributes);
-		main_data->ldap_attributes = g_strdup (args[0]);
-		res = g_new0 (GdaInternalCommandResult, 1);
-		res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
-        }
-	else {
-		res = g_new0 (GdaInternalCommandResult, 1);
-		res->type = GDA_INTERNAL_COMMAND_RESULT_TXT;
-		res->u.txt = g_string_new (main_data->ldap_attributes);
-	}
-	return res;
-}
-
 typedef struct {
 	GValue *attr_name;
 	GValue *req;
@@ -5732,7 +5705,7 @@ extra_command_ldap_descr (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
 
 	const gchar *dn = NULL;
 	GHashTable *attrs_hash = NULL;
-	gint options = 0; /* 0 => show attributes specified with .ldap_attributes
+	gint options = 0; /* 0 => show attributes specified with ".option ldap_attributes"
 			   * 1 => show all attributes
 			   * 2 => show non set attributes only
 			   * 3 => show all set attributes only
@@ -5778,10 +5751,12 @@ extra_command_ldap_descr (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
 	g_object_set_data (G_OBJECT (model), "name", _("LDAP entry's Attributes"));
 
 	/* parse attributes to use */
-	if ((options == 0) && main_data->ldap_attributes) {
+	const gchar *ldap_attributes;
+	ldap_attributes = g_value_get_string (gda_set_get_holder_value (main_data->options, "ldap_attributes"));
+	if ((options == 0) && ldap_attributes) {
 		gchar **array;
 		guint i;
-		array = g_strsplit (main_data->ldap_attributes, ",", 0);
+		array = g_strsplit (ldap_attributes, ",", 0);
 		for (i = 0; array [i]; i++) {
 			gchar *tmp;
 			for (tmp = array [i]; *tmp && (*tmp != ':'); tmp++);
diff --git a/tools/help/C/gda-sql-help.xml b/tools/help/C/gda-sql-help.xml
index 3f10605..de60e84 100644
--- a/tools/help/C/gda-sql-help.xml
+++ b/tools/help/C/gda-sql-help.xml
@@ -350,13 +350,12 @@ SCOPE      â SUBTREE
   </section>
 
   <!-- ".ldap_attributes" command -->
-  <command name="ldap_attributes">
-    <shortdescription>Set or show the list of attributes take into account by LDAP commands
+  <option name="ldap_attributes">
+    <shortdescription>Defines the list of attributes taken into account by LDAP commands
     </shortdescription>
     <usage>
-      <synopsis>.ldap_attributes [attribute,[attribute],...]</synopsis>
-      <comment>Use this command to specify or display which attributes the LDAP commands operate on; if no
-      argument is passed, then the current list of attributes is shown</comment>
+      <synopsis>.option ldap_attributes [attribute,[attribute],...]</synopsis>
+      <comment>Use this option to specify or display which attributes the LDAP commands operate on</comment>
       <comment>The attributes list is a CVS separated list of individual LDAP attributes, for example "cn,uid,email"</comment>
       <comment>LDAP allows some attributes to be multi valued (e.g. the "objectClass" attribute). When dealing with multi
       valued attributes, the default behaviour is to return an error for the corresponding value. This default behaviour can
@@ -366,16 +365,11 @@ SCOPE      â SUBTREE
       </comment>
     </usage>
     <example>
-      <synopsis>.ldap_attributes</synopsis>
-      <comment>Shows the current attributes (by default the "cn" attribute)</comment>
-      <raw>cn</raw>
-    </example>
-    <example>
-      <synopsis>.ldap_attributes cn,objectClass::*</synopsis>
+      <synopsis>.option ldap_attributes cn,objectClass::*</synopsis>
       <comment>Define the attibutes as "cn" and "objectClass", and because "objectClass" is generally multi valued,
       specify that a new row be created in the output for each value of "objectClass" for each entry</comment>
     </example>
-  </command>
+  </option>
 
   <!-- ".ldap_search" command -->
   <command name="ldap_search">
@@ -387,7 +381,7 @@ SCOPE      â SUBTREE
       other arguments, if present are in order the search scope (among "base", "onelevel" and "subtree"), and the
       base DN (which is the starting point of the search)</comment>
       <comment>The results of the search will be a table where the first column is the DN of the entry, and
-      the other columns are mapped to the LDAP attributes (see the "ldap_attributes" command)</comment>
+      the other columns are mapped to the LDAP attributes (see the "ldap_attributes" option)</comment>
       <comment>LDAP filters must respect the RFC 2254 (see http://www.faqs.org/rfcs/rfc2254.html) and what the
       actual LDAP server understands. Note that if the outer most opening and cloding parenthesis are omitted, they
       will be automatically added. Examples of LDAP search filter are: "(objectClass=*)" to fetch all objects,
@@ -399,7 +393,7 @@ SCOPE      â SUBTREE
       behaviour), "rdn" (the DN is replaced by the RND) and "none" (the DN column is not shown).</comment>
     </usage>
     <example>
-      <synopsis>.ldap_attributes cn,uid,mail</synopsis>
+      <synopsis>.option ldap_attributes cn,uid,mail</synopsis>
       <synopsis>.ldap_search cn=* onelevel "ou=People,dc=example,dc=gnome-db"</synopsis>
       <comment></comment>
       <raw>Distinguished name                              | cn                 | uid        | mail                  



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]