changeset 231:c342b93c5bd1

Refactoring.
author Sascha Wilde <wilde@intevation.de>
date Fri, 28 Mar 2014 10:45:55 +0100 (2014-03-28)
parents 92b1e5ed2d5f
children 774e944c395b
files cinst/mozilla.c
diffstat 1 files changed, 43 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/cinst/mozilla.c	Fri Mar 28 10:32:55 2014 +0100
+++ b/cinst/mozilla.c	Fri Mar 28 10:45:55 2014 +0100
@@ -265,6 +265,37 @@
 }
 
 /**
+ * @brief Collect all mozilla profile directories of current user.
+ * @return NULL terminated array of strings containing the absolute
+ * path of the profile directories.  The array needs to be freed by the
+ * caller.
+ */
+static char**
+get_all_profile_dirs()
+{
+  char **mozinis, **pdirs;
+  char **alldirs = NULL;
+  if ((mozinis = get_profile_inis()) != NULL)
+    {
+      for (int i=0; mozinis[i] != NULL; i++)
+        {
+          pdirs =
+            get_profile_dirs(mozinis[i]);
+          if (pdirs != NULL)
+            {
+              for (int i=0; pdirs[i] != NULL; i++)
+                {
+                  strv_append(&alldirs, pdirs[i], strlen(pdirs[i]));
+                }
+              strv_free(pdirs);
+            }
+        }
+      strv_free(mozinis);
+    }
+  return alldirs;
+}
+
+/**
  * @brief list certificates from nss certificate store
  * @param[in] confdir the directory with the certificate store
  */
@@ -296,22 +327,17 @@
 int
 main ()
 {
-  int y = 0;
-  char **mozinis, **pdirs;
-  if ((mozinis = get_profile_inis()) != NULL)
-    while (mozinis[y] != NULL)
-      {
-        pdirs =
-          get_profile_dirs(mozinis[y++]);
-        if (pdirs != NULL)
-          {
-            for (int x=0; pdirs[x] != NULL; x++)
-              {
-                puts(pdirs[x]);
-                nss_list_certs(pdirs[x]);
-              }
-            strv_free(pdirs);
-          }
-      }
+  char **pdirs;
+  pdirs =
+    get_all_profile_dirs();
+  if (pdirs != NULL)
+    {
+      for (int i=0; pdirs[i] != NULL; i++)
+        {
+          puts(pdirs[i]);
+          nss_list_certs(pdirs[i]);
+        }
+      strv_free(pdirs);
+    }
   exit(return_code);
 }

http://wald.intevation.org/projects/trustbridge/