changeset 114:447a7abee6c7

Merged
author Sascha Wilde <wilde@intevation.de>
date Fri, 21 Mar 2014 17:13:24 +0100
parents 02ad0922c01f (diff) 16f37460b2e1 (current diff)
children 5ed770c41a73 c602d8cfa619
files
diffstat 1 files changed, 18 insertions(+), 159 deletions(-) [+]
line wrap: on
line diff
--- a/cinst/mozilla.c	Fri Mar 21 16:07:35 2014 +0000
+++ b/cinst/mozilla.c	Fri Mar 21 17:13:24 2014 +0100
@@ -1,12 +1,3 @@
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-
 /* @file Mozilla installation process
  *
  * Reads from stdin a list of instructions in the form:
@@ -40,7 +31,7 @@
 
 /* @brief IniParser for mozilla profiles.ini
  *
- * Parse data to find values formed in 
+ * Parse data to find values formed in
  *
  * [Profile99]
  * IsRelative=1
@@ -55,164 +46,32 @@
  * encoded.
  * */
 
+#include <errorcodes.h>
+#include <stdlib.h>
+
+#ifndef _WIN32
+#define UNIX 1
+#else
+#define UNIX 0
+#endif
+
 
 /**
- *  @brief Read a file into memory.
- *
- * @param[in] fileName Name of the file (UTF-8 encoded).
- * @param[out] data Newly allocated pointer to the file content.
- * @param[out] size Size in Bytes of the file content.
- * @param[in] maxSize the maximum size to read.
- *
- * @return 0 on success an error code otherwise.
- */
-
-#define RAF_UNKNOWN -1
-#define RAF_UNREADABLE -2
-#define RAF_STATFAILED -3
-#define RAF_TOOLARGE -4
-#define RAF_OUTOFCORE -5
-int readFile(const char *fileName, char **data, size_t *size,
-             const size_t maxSize)
-{
-    /* TODO
-     * split out the read file from common/listutil.c and use that. */
-    int fd = -1;
-    struct stat fileStat;
-    int rc = 0;
-    ssize_t bRead = 0;
-    int retval = -1;
-
-    memset(&fileStat, 0, sizeof(fileStat));
-
-    fd = open(fileName, O_RDONLY);
-    if (fd == -1) {
-        retval = RAF_UNREADABLE;
-        goto cleanup;
-    }
-
-    rc = fstat(fd, &fileStat);
-    if (rc < 0) {
-        retval = RAF_STATFAILED;
-        goto cleanup;
-    }
-
-    // Check the size of the file
-    if (!fileStat.st_size) {
-        retval = RAF_STATFAILED;
-        goto cleanup;
-    }
-
-    if (fileStat.st_size > maxSize &&
-            fileStat.st_size > 0) {
-        retval = RAF_TOOLARGE;
-        goto cleanup;
-    }
-
-    *size = (size_t) fileStat.st_size;
-
-    *data = (char*) malloc(*size);
-
-    if (*data == NULL) {
-        retval = RAF_OUTOFCORE;
-        goto cleanup;
-    }
-
-    bRead = read(fd, *data, *size);
-
-    if (bRead < 0 || (size_t) bRead != *size) {
-        if (bRead == -1) {
-            printf("Error: %s \n", strerror(errno));
-        }
-        retval = RAF_UNKNOWN;
-        *size = 0;
-        if (*data) {
-            free(*data);
-            *data = NULL;
-        }
-        goto cleanup;
-    }
-
-cleanup:
-
-    if (fd && fd != -1) {
-        close(fd);
-        fd = -1;
-    }
-
-    return retval;
-}
-
-
-#ifndef _WIN32
-
-#define INI_LOCATIONS {                   \
-    "/.mozilla/firefox/profiles.ini",     \
-    "/.mozilla/thunderbird/profiles.ini", \
-    NULL }
-
-/**
- * @brief Get a list of all mozilla profile directories for this user
+ * @brief Get a list of all mozilla profile directories 
  *
  * Read the profiles.ini and extract all profile paths from that.
  *
+ * @param[inifile] path of the profile.ini to read.
  * @return NULL terminated array of strings containing containing the
  * absolute path of the profile directories. The array needs to
  * be freed by the caller.
  */
-char **getProfilePaths() {
-    char *homedir = NULL,
-        **retval = NULL;
-    const char* const iniLocations[] = INI_LOCATIONS;
-    int i = 0;
-
-    homedir = getenv ("HOME");
-
-    if (!homedir) {
-        printf ("Could not get HOME\n");
-        return NULL;
-    }
-
-    for (i = 0; iniLocations[i] != NULL; i++) {
-        char *candidate[MAX_PATH_LEN],
-             *fileContent = NULL;
-        const size_t needed = strnlen (homedir, MAX_PATH_LEN) +
-                        strnlen (iniLocations[i], MAX_PATH_LEN);
-               fileSize = 0;
-        int err = 0;
-
-        memset (candidate, 0, MAX_PATH_LEN);
+//char**
+//get_profile_dirs(char* inifile)
 
-        /* Verify that addition of strlen did not overflow and
-         * that the buffer is large enough */
-        if (needed < strnlen (homedir, MAX_PATH_LEN_LEN) || needed >= MAX_PATH - 1) {
-            printf ("Error invalid HOME environment variable");
-            return NULL;
-        }
-
-        strncpy (candidate, homedir, MAX_PATH_LEN);
-        /* Environment might have been modified */
-        if (candidate[MAX_PATH_LEN - 1] != '\0') {
-            printf ("Error invalid HOME");
-            return NULL;
-        }
-        strncat (candidate, iniLocations[i], MAX_PATH_LEN - strnlen(candidate,
-                    MAX_PATH_LEN) - 1);
 
-        rc = readFile (candidate, &fileContent, &fileSize, MAX_FILESIZE);
-
-        if (err) {
-            printf ("Failed to read file.\n");
-            continue;
-        }
-        parseIni (fileContent, &retval);
-    }
+int
+main()
+{
+  exit(0);
 }
-#else /* _WIN32 */
-char **getProfilePaths() {
-    return NULL;
-}
-#endif
-
-int main(int argc, char *argv) {
-}

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