mbpfan-josie

Almost done with #38.

d14c7107e871a01a5ad565a16b39677ce04fff5c
Daniel Graziotin <daniel@ineed.coffee> · 2014-06-22T16:48 · browse files at this commit

parents: f3bbf97

diff --git a/src/daemon.c b/src/daemon.c
index 9b33b61..18b01fa 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -74,22 +74,26 @@ void signal_handler(int signal)
         syslog(LOG_WARNING, "Received SIGHUP signal.");
         retrieve_settings(NULL);
         break;
+
     case SIGTERM:
         syslog(LOG_WARNING, "Received SIGTERM signal.");
         delete_pid();
         //TODO: free resources
         exit(0);
         break;
+
     case SIGINT:
         syslog(LOG_WARNING, "Received SIGINT signal.");
         delete_pid();
         //TODO: free resources
         exit(0);
+
     case SIGSTOP:
         syslog(LOG_WARNING, "Received SIGSTOP signal.");
         delete_pid();
         //TODO: free resources
         exit(0);
+
     default:
         syslog(LOG_WARNING, "Unhandled signal (%d) %s", signal, strsignal(signal));
         break;
diff --git a/src/main.c b/src/main.c
index 067e933..2c690d8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -116,16 +116,20 @@ int main(int argc, char *argv[])
             print_usage(argc, argv);
             exit(0);
             break;
+
         case 'f':
             daemonize = 0;
             break;
+
         case 't':
             tests();
             exit(0);
             break;
+
         case 'v':
             verbose = 1;
             break;
+
         default:
             print_usage(argc, argv);
             exit(0);
diff --git a/src/mbpfan.c b/src/mbpfan.c
index 86cdbe5..9f09aad 100644
--- a/src/mbpfan.c
+++ b/src/mbpfan.c
@@ -2,7 +2,7 @@
  *  mbpfan.c - automatically control fan for MacBook Pro
  *  Copyright (C) 2010  Allan McRae <allan@archlinux.org>
  *  Modifications by Rafael Vega <rvega@elsoftwarehamuerto.org>
- *  Modifications (2012) by Daniel Graziotin <dgraziotin@task3.cc>
+ *  Modifications (2012) by Daniel Graziotin <daniel@ineed.coffee>
  *  Modifications (2012) by Ismail Khatib <ikhatib@gmail.com>
  *
  *  This program is free software: you can redistribute it and/or modify
@@ -36,6 +36,8 @@
 #include <string.h>
 #include <math.h>
 #include <syslog.h>
+#include <sys/utsname.h>
+#include <sys/errno.h>
 #include "mbpfan.h"
 #include "global.h"
 #include "settings.h"
@@ -60,6 +62,29 @@ int polling_interval = 7;
 typedef struct s_sensors t_sensors;
 typedef struct s_fans t_fans;
 
+bool is_legacy_kernel()
+{
+    struct utsname kernel;
+    uname(&kernel);
+
+    char *str_kernel_version;
+    str_kernel_version = strndup(kernel.release + 2, 2);
+
+    if(verbose) {
+        printf("Detected kernel version: %s\n", kernel.release);
+        printf("Detected kernel minor revision: %s\n", str_kernel_version);
+
+        if(daemonize) {
+            syslog(LOG_INFO, "Kernel version: %s", kernel.release);
+            syslog(LOG_INFO, "Detected kernel minor revision: %sn", str_kernel_version);
+        }
+    }
+
+    int kernel_version = atoi(str_kernel_version);
+
+    return (kernel_version < 15);
+}
+
 t_sensors *retrieve_sensors()
 {
 
@@ -67,7 +92,62 @@ t_sensors *retrieve_sensors()
     t_sensors *s = NULL;
 
     char *path = NULL;
-    const char *path_begin = "/sys/devices/platform/coretemp.0/temp";
+    char *path_begin = NULL;
+
+    if (is_legacy_kernel()) {
+        if(verbose) {
+            printf("Using legacy sensor path for kernel < 3.15.0\n");
+
+            if(daemonize) {
+                syslog(LOG_INFO, "Using legacy path for kernel < 3.15.0");
+            }
+        }
+
+        path_begin = "/sys/devices/platform/coretemp.0/temp";
+
+    } else {
+
+        if(verbose) {
+            printf("Using new sensor path for kernel >= 3.0.15\n");
+
+            if(daemonize) {
+                syslog(LOG_INFO, "Using new sensor path for kernel >= 3.0.15");
+            }
+        }
+
+        path_begin = "/sys/devices/platform/coretemp.0/hwmon/hwmon";
+
+        int counter;
+
+        for (counter = 0; counter < 10; counter++) {
+
+            char hwmon_path[strlen(path_begin)+1];
+
+            sprintf(hwmon_path, "%s%d", path_begin, counter);
+
+            // thanks http://stackoverflow.com/questions/18192998/plain-c-opening-a-directory-with-fopen
+            fopen(hwmon_path, "wb");
+
+            if (errno == EISDIR) {
+
+                path_begin = (char*) malloc(sizeof( char ) * (strlen(hwmon_path) + strlen("/temp") + 1));
+                strcpy(path_begin, hwmon_path);
+                strcat(path_begin, "/temp");
+
+                if(verbose) {
+                    printf("Found hwmon path at %s\n", path_begin);
+
+                    if(daemonize) {
+                        syslog(LOG_INFO, "Found hwmon path at %s\n", path_begin);
+                    }
+
+                }
+
+                break;
+            }
+        }
+    }
+
     const char *path_end = "_input";
 
     int path_size = strlen(path_begin) + strlen(path_end) + 2;
diff --git a/src/mbpfan.h b/src/mbpfan.h
index 27cba96..a7aef3d 100644
--- a/src/mbpfan.h
+++ b/src/mbpfan.h
@@ -43,6 +43,11 @@ typedef struct s_sensors t_sensors;
 struct s_fans;
 typedef struct s_fans t_fans;
 
+/**
+ * Return true if the kernel is < 3.15.0
+ */
+bool is_legacy_kernel();
+
 /**
  * Tries to use the settings located in
  * /etc/mbpfan.conf
diff --git a/src/minunit.c b/src/minunit.c
index 01ba082..3ada62e 100644
--- a/src/minunit.c
+++ b/src/minunit.c
@@ -146,6 +146,7 @@ static void handler(int signal)
         received = 1;
         retrieve_settings("./mbpfan.conf.test1");
         break;
+
     default:
         received = 0;
         break;
diff --git a/src/settings.c b/src/settings.c
index ae108f2..20d18f3 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -773,9 +773,11 @@ static int get_converted_value(const Settings *settings, const char *section, co
     case CONVERT_MODE_INT:
         *((int *)out) = atoi(value);
         return 1;
+
     case CONVERT_MODE_LONG:
         *((long *)out) = atol(value);
         return 1;
+
     case CONVERT_MODE_DOUBLE:
         *((double *)out) = atof(value);
         return 1;
@@ -821,12 +823,15 @@ static int get_converted_tuple(const Settings *settings, const char *section, co
         case CONVERT_MODE_INT:
             ((int *)out)[count] = atoi(token);
             break;
+
         case CONVERT_MODE_LONG:
             ((long *)out)[count] = atol(token);
             break;
+
         case CONVERT_MODE_DOUBLE:
             ((double *)out)[count] = atof(token);
             break;
+
         default:
             return 0;
         }
diff --git a/src/settings.h b/src/settings.h
index dde66de..4b3ada8 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -43,292 +43,292 @@ extern "C"
 {
 #endif
 
-    typedef struct Settings Settings;
-
-    /*
-     * This callback function is called once per key-value when enumerating
-     * all keys inside a section.
-     *
-     * Parameters:
-     *
-     * key: A pointer to a null-terminated C string. The string must not
-     * be modified by the client.
-     *
-     * value: A pointer to a null-terminated C string. The string must
-     * not be modified by the client.
-     *
-     * obj: A pointer to a client-specific object. This parameter may be
-     * null.
-     *
-     * Return value: None.
-     */
-    typedef void(*settings_section_enum_func)(const char *key, const char *value, const void *obj);
-
-    /*
-     * Creates a settings object.
-     *
-     * Return value: A pointer to a settings object,
-     * or null if a new settings object could not be allocated.
-     */
-    Settings * settings_new();
-
-    /*
-     * Releases all memory held by a settings object.
-     *
-     * Parameters:
-     *
-     * settings: A pointer to a settings object. This parameter cannot be null.
-     * If the supplied settings object has been previously released, the
-     * behaviour of this function is undefined.
-     *
-     * Return value: None.
-     */
-    void settings_delete(Settings *settings);
-
-    /*
-     * Constructs a settings object by loading settings in textual form
-     * from the given stream.
-     *
-     * Parameters:
-     *
-     * settings: A pointer to a settings object. This parameter cannot be null.
-     *
-     * stream: A pointer to a stream. This parameter cannot be null.
-     *
-     * Return value: A pointer to a settings object,
-     * or null if an error occurred.
-     */
-    Settings * settings_open(FILE *stream);
-
-    /*
-     * Saves the current settings object in textual form to the given stream.
-     *
-     * Parameters:
-     *
-     * settings: A pointer to a settings object. This parameter cannot be null.
-     *
-     * stream: A pointer to a stream. This parameter cannot be null.
-     *
-     * Return value: 1 if the operation succeeded, 0 otherwise.
-     */
-    int settings_save(const Settings *settings, FILE *stream);
-
-    /*
-     * Returns the value associated with the supplied key in the
-     * provided section.
-     *
-     * Parameters:
-     *
-     * settings: A pointer to a settings object. This parameter cannot be null.
-     *
-     * section: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * key: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * out_buf: A pointer to an output buffer which will contain the value,
-     * if it exists and fits into the buffer.
-     *
-     * n_out_buf: The size of the output buffer in bytes.
-     *
-     * Return value: If out_buf is set to null and n_out_buf is set to 0 the return
-     * value will be the number of bytes required to store the value (if it exists)
-     * and its null-terminator. For all other parameter configurations the return value
-     * is 1 if an associated value was found and completely copied into the output buffer,
-     * 0 otherwise.
-     */
-    int settings_get(const Settings *settings, const char *section, const char *key, char *out_buf, unsigned int n_out_buf);
-
-    /*
-     * Returns the integer value associated with the supplied key in the
-     * provided section.
-     *
-     * Parameters:
-     *
-     * settings: A pointer to a settings object. This parameter cannot be null.
-     *
-     * section: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * key: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * Return value: The integer value associated to the provided section and
-     * key, or 0 if no such value exists.
-     */
-    int settings_get_int(const Settings *settings, const char *section, const char *key);
-
-    /*
-     * Returns the long integer value associated with the supplied key in the
-     * provided section.
-     *
-     * Parameters:
-     *
-     * settings: A pointer to a settings object. This parameter cannot be null.
-     *
-     * section: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * key: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * Return value: The long integer value associated to the provided section and
-     * key, or 0 if no such value exists.
-     */
-    long settings_get_long(const Settings *settings, const char *section, const char *key);
-
-    /*
-     * Returns the double value associated with the supplied key in the
-     * provided section.
-     *
-     * Parameters:
-     *
-     * settings: A pointer to a settings object. This parameter cannot be null.
-     *
-     * section: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * key: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * Return value: The double value associated to the provided section and
-     * key, or 0 if no such value exists.
-     */
-    double settings_get_double(const Settings *settings, const char *section, const char *key);
-
-    /*
-     * Returns the integer tuple associated with the supplied key in the
-     * provided section.
-     *
-     * Parameters:
-     *
-     * settings: A pointer to a settings object. This parameter cannot be null.
-     *
-     * section: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * key: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * out: A pointer to an output buffer.
-     *
-     * n_out: The maximum number of elements the output buffer can hold.
-     *
-     * Return value: 1 if the entire tuple was copied into the output buffer,
-     * 0 otherwise.
-     */
-    int settings_get_int_tuple(const Settings *settings, const char *section, const char *key, int *out, unsigned int n_out);
-
-    /*
-     * Returns the long tuple associated with the supplied key in the
-     * provided section.
-     *
-     * Parameters:
-     *
-     * settings: A pointer to a settings object. This parameter cannot be null.
-     *
-     * section: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * key: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * out: A pointer to an output buffer.
-     *
-     * n_out: The maximum number of elements the output buffer can hold.
-     *
-     * Return value: 1 if the entire tuple was copied into the output buffer,
-     * 0 otherwise.
-     */
-    long settings_get_long_tuple(const Settings *settings, const char *section, const char *key, long *out, unsigned int n_out);
-
-    /*
-     * Returns the double tuple associated with the supplied key in the
-     * provided section.
-     *
-     * Parameters:
-     *
-     * settings: A pointer to a settings object. This parameter cannot be null.
-     *
-     * section: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * key: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * out: A pointer to an output buffer.
-     *
-     * n_out: The maximum number of elements the output buffer can hold.
-     *
-     * Return value: 1 if the entire tuple was copied into the output buffer,
-     * 0 otherwise.
-     */
-    double settings_get_double_tuple(const Settings *settings, const char *section, const char *key, double *out, unsigned int n_out);
-
-    /*
-     * Associates a value with the supplied key in the provided section.
-     * If the key is already associated with a value, the previous value
-     * is replaced.
-     *
-     * Parameters:
-     *
-     * settings: A pointer to a settings object. This parameter cannot be null.
-     *
-     * section: A pointer to a null-terminated C string. This parameter cannot
-     * be null. The string must have a string length > 0. The string will
-     * be copied.
-     *
-     * key: A pointer to a null-terminated C string. This parameter
-     * cannot be null. The string must have a string length > 0. The
-     * string will be copied.
-     *
-     * value: A pointer to a null-terminated C string. This parameter
-     * cannot be null. The string must have a string length > 0. The
-     * string will be copied.
-     *
-     * Return value: 1 if the association succeeded, 0 otherwise.
-     */
-    int settings_set(Settings *setting, const char *section, const char *key, const char *value);
-
-    /*
-     * Returns the number of associations between keys and values that exist
-     * in the provided section.
-     *
-     * Parameters:
-     *
-     * settings: A pointer to a settings object. This parameter cannot be null.
-     *
-     * section: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * Return value: The number of associations between keys and values in
-     * the provided section.
-     */
-    int settings_section_get_count(const Settings *settings, const char *section);
-
-    /*
-     * Enumerates all associations between keys and values in the provided
-     * section.
-     *
-     * Parameters:
-     *
-     * settings: A pointer to a settings object. This parameter cannot be null.
-     *
-     * section: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * enum_func: A pointer to a callback function that will be
-     * called by this procedure once for every key associated
-     * with a value. This parameter cannot be null.
-     *
-     * obj: A pointer to a client-specific object. This parameter will be
-     * passed back to the client's callback function. This parameter can
-     * be null.
-     *
-     * Return value: 1 if enumeration completed, 0 otherwise.
-     */
-    int settings_section_enum(const Settings *settings, const char *section, settings_section_enum_func enum_func, const void *obj);
+typedef struct Settings Settings;
+
+/*
+ * This callback function is called once per key-value when enumerating
+ * all keys inside a section.
+ *
+ * Parameters:
+ *
+ * key: A pointer to a null-terminated C string. The string must not
+ * be modified by the client.
+ *
+ * value: A pointer to a null-terminated C string. The string must
+ * not be modified by the client.
+ *
+ * obj: A pointer to a client-specific object. This parameter may be
+ * null.
+ *
+ * Return value: None.
+ */
+typedef void(*settings_section_enum_func)(const char *key, const char *value, const void *obj);
+
+/*
+ * Creates a settings object.
+ *
+ * Return value: A pointer to a settings object,
+ * or null if a new settings object could not be allocated.
+ */
+Settings * settings_new();
+
+/*
+ * Releases all memory held by a settings object.
+ *
+ * Parameters:
+ *
+ * settings: A pointer to a settings object. This parameter cannot be null.
+ * If the supplied settings object has been previously released, the
+ * behaviour of this function is undefined.
+ *
+ * Return value: None.
+ */
+void settings_delete(Settings *settings);
+
+/*
+ * Constructs a settings object by loading settings in textual form
+ * from the given stream.
+ *
+ * Parameters:
+ *
+ * settings: A pointer to a settings object. This parameter cannot be null.
+ *
+ * stream: A pointer to a stream. This parameter cannot be null.
+ *
+ * Return value: A pointer to a settings object,
+ * or null if an error occurred.
+ */
+Settings * settings_open(FILE *stream);
+
+/*
+ * Saves the current settings object in textual form to the given stream.
+ *
+ * Parameters:
+ *
+ * settings: A pointer to a settings object. This parameter cannot be null.
+ *
+ * stream: A pointer to a stream. This parameter cannot be null.
+ *
+ * Return value: 1 if the operation succeeded, 0 otherwise.
+ */
+int settings_save(const Settings *settings, FILE *stream);
+
+/*
+ * Returns the value associated with the supplied key in the
+ * provided section.
+ *
+ * Parameters:
+ *
+ * settings: A pointer to a settings object. This parameter cannot be null.
+ *
+ * section: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * key: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * out_buf: A pointer to an output buffer which will contain the value,
+ * if it exists and fits into the buffer.
+ *
+ * n_out_buf: The size of the output buffer in bytes.
+ *
+ * Return value: If out_buf is set to null and n_out_buf is set to 0 the return
+ * value will be the number of bytes required to store the value (if it exists)
+ * and its null-terminator. For all other parameter configurations the return value
+ * is 1 if an associated value was found and completely copied into the output buffer,
+ * 0 otherwise.
+ */
+int settings_get(const Settings *settings, const char *section, const char *key, char *out_buf, unsigned int n_out_buf);
+
+/*
+ * Returns the integer value associated with the supplied key in the
+ * provided section.
+ *
+ * Parameters:
+ *
+ * settings: A pointer to a settings object. This parameter cannot be null.
+ *
+ * section: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * key: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * Return value: The integer value associated to the provided section and
+ * key, or 0 if no such value exists.
+ */
+int settings_get_int(const Settings *settings, const char *section, const char *key);
+
+/*
+ * Returns the long integer value associated with the supplied key in the
+ * provided section.
+ *
+ * Parameters:
+ *
+ * settings: A pointer to a settings object. This parameter cannot be null.
+ *
+ * section: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * key: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * Return value: The long integer value associated to the provided section and
+ * key, or 0 if no such value exists.
+ */
+long settings_get_long(const Settings *settings, const char *section, const char *key);
+
+/*
+ * Returns the double value associated with the supplied key in the
+ * provided section.
+ *
+ * Parameters:
+ *
+ * settings: A pointer to a settings object. This parameter cannot be null.
+ *
+ * section: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * key: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * Return value: The double value associated to the provided section and
+ * key, or 0 if no such value exists.
+ */
+double settings_get_double(const Settings *settings, const char *section, const char *key);
+
+/*
+ * Returns the integer tuple associated with the supplied key in the
+ * provided section.
+ *
+ * Parameters:
+ *
+ * settings: A pointer to a settings object. This parameter cannot be null.
+ *
+ * section: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * key: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * out: A pointer to an output buffer.
+ *
+ * n_out: The maximum number of elements the output buffer can hold.
+ *
+ * Return value: 1 if the entire tuple was copied into the output buffer,
+ * 0 otherwise.
+ */
+int settings_get_int_tuple(const Settings *settings, const char *section, const char *key, int *out, unsigned int n_out);
+
+/*
+ * Returns the long tuple associated with the supplied key in the
+ * provided section.
+ *
+ * Parameters:
+ *
+ * settings: A pointer to a settings object. This parameter cannot be null.
+ *
+ * section: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * key: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * out: A pointer to an output buffer.
+ *
+ * n_out: The maximum number of elements the output buffer can hold.
+ *
+ * Return value: 1 if the entire tuple was copied into the output buffer,
+ * 0 otherwise.
+ */
+long settings_get_long_tuple(const Settings *settings, const char *section, const char *key, long *out, unsigned int n_out);
+
+/*
+ * Returns the double tuple associated with the supplied key in the
+ * provided section.
+ *
+ * Parameters:
+ *
+ * settings: A pointer to a settings object. This parameter cannot be null.
+ *
+ * section: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * key: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * out: A pointer to an output buffer.
+ *
+ * n_out: The maximum number of elements the output buffer can hold.
+ *
+ * Return value: 1 if the entire tuple was copied into the output buffer,
+ * 0 otherwise.
+ */
+double settings_get_double_tuple(const Settings *settings, const char *section, const char *key, double *out, unsigned int n_out);
+
+/*
+ * Associates a value with the supplied key in the provided section.
+ * If the key is already associated with a value, the previous value
+ * is replaced.
+ *
+ * Parameters:
+ *
+ * settings: A pointer to a settings object. This parameter cannot be null.
+ *
+ * section: A pointer to a null-terminated C string. This parameter cannot
+ * be null. The string must have a string length > 0. The string will
+ * be copied.
+ *
+ * key: A pointer to a null-terminated C string. This parameter
+ * cannot be null. The string must have a string length > 0. The
+ * string will be copied.
+ *
+ * value: A pointer to a null-terminated C string. This parameter
+ * cannot be null. The string must have a string length > 0. The
+ * string will be copied.
+ *
+ * Return value: 1 if the association succeeded, 0 otherwise.
+ */
+int settings_set(Settings *setting, const char *section, const char *key, const char *value);
+
+/*
+ * Returns the number of associations between keys and values that exist
+ * in the provided section.
+ *
+ * Parameters:
+ *
+ * settings: A pointer to a settings object. This parameter cannot be null.
+ *
+ * section: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * Return value: The number of associations between keys and values in
+ * the provided section.
+ */
+int settings_section_get_count(const Settings *settings, const char *section);
+
+/*
+ * Enumerates all associations between keys and values in the provided
+ * section.
+ *
+ * Parameters:
+ *
+ * settings: A pointer to a settings object. This parameter cannot be null.
+ *
+ * section: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * enum_func: A pointer to a callback function that will be
+ * called by this procedure once for every key associated
+ * with a value. This parameter cannot be null.
+ *
+ * obj: A pointer to a client-specific object. This parameter will be
+ * passed back to the client's callback function. This parameter can
+ * be null.
+ *
+ * Return value: 1 if enumeration completed, 0 otherwise.
+ */
+int settings_section_enum(const Settings *settings, const char *section, settings_section_enum_func enum_func, const void *obj);
 
 #ifdef __cplusplus
 }
diff --git a/src/strmap.h b/src/strmap.h
index 367f43c..416a1ce 100644
--- a/src/strmap.h
+++ b/src/strmap.h
@@ -44,139 +44,139 @@ extern "C"
 #include <stdlib.h>
 #include <string.h>
 
-    typedef struct StrMap StrMap;
-
-    /*
-     * This callback function is called once per key-value when enumerating
-     * all keys associated to values.
-     *
-     * Parameters:
-     *
-     * key: A pointer to a null-terminated C string. The string must not
-     * be modified by the client.
-     *
-     * value: A pointer to a null-terminated C string. The string must
-     * not be modified by the client.
-     *
-     * obj: A pointer to a client-specific object. This parameter may be
-     * null.
-     *
-     * Return value: None.
-     */
-    typedef void(*sm_enum_func)(const char *key, const char *value, const void *obj);
-
-    /*
-     * Creates a string map.
-     *
-     * Parameters:
-     *
-     * capacity: The number of top-level slots this string map
-     * should allocate. This parameter must be > 0.
-     *
-     * Return value: A pointer to a string map object,
-     * or null if a new string map could not be allocated.
-     */
-    StrMap * sm_new(unsigned int capacity);
-
-    /*
-     * Releases all memory held by a string map object.
-     *
-     * Parameters:
-     *
-     * map: A pointer to a string map. This parameter cannot be null.
-     * If the supplied string map has been previously released, the
-     * behaviour of this function is undefined.
-     *
-     * Return value: None.
-     */
-    void sm_delete(StrMap *map);
-
-    /*
-     * Returns the value associated with the supplied key.
-     *
-     * Parameters:
-     *
-     * map: A pointer to a string map. This parameter cannot be null.
-     *
-     * key: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * out_buf: A pointer to an output buffer which will contain the value,
-     * if it exists and fits into the buffer.
-     *
-     * n_out_buf: The size of the output buffer in bytes.
-     *
-     * Return value: If out_buf is set to null and n_out_buf is set to 0 the return
-     * value will be the number of bytes required to store the value (if it exists)
-     * and its null-terminator. For all other parameter configurations the return value
-     * is 1 if an associated value was found and completely copied into the output buffer,
-     * 0 otherwise.
-     */
-    int sm_get(const StrMap *map, const char *key, char *out_buf, unsigned int n_out_buf);
-
-    /*
-     * Queries the existence of a key.
-     *
-     * Parameters:
-     *
-     * map: A pointer to a string map. This parameter cannot be null.
-     *
-     * key: A pointer to a null-terminated C string. This parameter cannot
-     * be null.
-     *
-     * Return value: 1 if the key exists, 0 otherwise.
-     */
-    int sm_exists(const StrMap *map, const char *key);
-
-    /*
-     * Associates a value with the supplied key. If the key is already
-     * associated with a value, the previous value is replaced.
-     *
-     * Parameters:
-     *
-     * map: A pointer to a string map. This parameter cannot be null.
-     *
-     * key: A pointer to a null-terminated C string. This parameter
-     * cannot be null. The string must have a string length > 0. The
-     * string will be copied.
-     *
-     * value: A pointer to a null-terminated C string. This parameter
-     * cannot be null. The string must have a string length > 0. The
-     * string will be copied.
-     *
-     * Return value: 1 if the association succeeded, 0 otherwise.
-     */
-    int sm_put(StrMap *map, const char *key, const char *value);
-
-    /*
-     * Returns the number of associations between keys and values.
-     *
-     * Parameters:
-     *
-     * map: A pointer to a string map. This parameter cannot be null.
-     *
-     * Return value: The number of associations between keys and values.
-     */
-    int sm_get_count(const StrMap *map);
-
-    /*
-     * Enumerates all associations between keys and values.
-     *
-     * Parameters:
-     *
-     * map: A pointer to a string map. This parameter cannot be null.
-     *
-     * enum_func: A pointer to a callback function that will be
-     * called by this procedure once for every key associated
-     * with a value. This parameter cannot be null.
-     *
-     * obj: A pointer to a client-specific object. This parameter will be
-     * passed back to the client's callback function. This parameter can
-     * be null.
-     *
-     * Return value: 1 if enumeration completed, 0 otherwise.
-     */
-    int sm_enum(const StrMap *map, sm_enum_func enum_func, const void *obj);
+typedef struct StrMap StrMap;
+
+/*
+ * This callback function is called once per key-value when enumerating
+ * all keys associated to values.
+ *
+ * Parameters:
+ *
+ * key: A pointer to a null-terminated C string. The string must not
+ * be modified by the client.
+ *
+ * value: A pointer to a null-terminated C string. The string must
+ * not be modified by the client.
+ *
+ * obj: A pointer to a client-specific object. This parameter may be
+ * null.
+ *
+ * Return value: None.
+ */
+typedef void(*sm_enum_func)(const char *key, const char *value, const void *obj);
+
+/*
+ * Creates a string map.
+ *
+ * Parameters:
+ *
+ * capacity: The number of top-level slots this string map
+ * should allocate. This parameter must be > 0.
+ *
+ * Return value: A pointer to a string map object,
+ * or null if a new string map could not be allocated.
+ */
+StrMap * sm_new(unsigned int capacity);
+
+/*
+ * Releases all memory held by a string map object.
+ *
+ * Parameters:
+ *
+ * map: A pointer to a string map. This parameter cannot be null.
+ * If the supplied string map has been previously released, the
+ * behaviour of this function is undefined.
+ *
+ * Return value: None.
+ */
+void sm_delete(StrMap *map);
+
+/*
+ * Returns the value associated with the supplied key.
+ *
+ * Parameters:
+ *
+ * map: A pointer to a string map. This parameter cannot be null.
+ *
+ * key: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * out_buf: A pointer to an output buffer which will contain the value,
+ * if it exists and fits into the buffer.
+ *
+ * n_out_buf: The size of the output buffer in bytes.
+ *
+ * Return value: If out_buf is set to null and n_out_buf is set to 0 the return
+ * value will be the number of bytes required to store the value (if it exists)
+ * and its null-terminator. For all other parameter configurations the return value
+ * is 1 if an associated value was found and completely copied into the output buffer,
+ * 0 otherwise.
+ */
+int sm_get(const StrMap *map, const char *key, char *out_buf, unsigned int n_out_buf);
+
+/*
+ * Queries the existence of a key.
+ *
+ * Parameters:
+ *
+ * map: A pointer to a string map. This parameter cannot be null.
+ *
+ * key: A pointer to a null-terminated C string. This parameter cannot
+ * be null.
+ *
+ * Return value: 1 if the key exists, 0 otherwise.
+ */
+int sm_exists(const StrMap *map, const char *key);
+
+/*
+ * Associates a value with the supplied key. If the key is already
+ * associated with a value, the previous value is replaced.
+ *
+ * Parameters:
+ *
+ * map: A pointer to a string map. This parameter cannot be null.
+ *
+ * key: A pointer to a null-terminated C string. This parameter
+ * cannot be null. The string must have a string length > 0. The
+ * string will be copied.
+ *
+ * value: A pointer to a null-terminated C string. This parameter
+ * cannot be null. The string must have a string length > 0. The
+ * string will be copied.
+ *
+ * Return value: 1 if the association succeeded, 0 otherwise.
+ */
+int sm_put(StrMap *map, const char *key, const char *value);
+
+/*
+ * Returns the number of associations between keys and values.
+ *
+ * Parameters:
+ *
+ * map: A pointer to a string map. This parameter cannot be null.
+ *
+ * Return value: The number of associations between keys and values.
+ */
+int sm_get_count(const StrMap *map);
+
+/*
+ * Enumerates all associations between keys and values.
+ *
+ * Parameters:
+ *
+ * map: A pointer to a string map. This parameter cannot be null.
+ *
+ * enum_func: A pointer to a callback function that will be
+ * called by this procedure once for every key associated
+ * with a value. This parameter cannot be null.
+ *
+ * obj: A pointer to a client-specific object. This parameter will be
+ * passed back to the client's callback function. This parameter can
+ * be null.
+ *
+ * Return value: 1 if enumeration completed, 0 otherwise.
+ */
+int sm_enum(const StrMap *map, sm_enum_func enum_func, const void *obj);
 
 #ifdef __cplusplus
 }