]> sjero.net Git - linphone/commitdiff
Add handling of ranges in the config file.
authorGhislain MARY <ghislain.mary@belledonne-communications.com>
Thu, 11 Oct 2012 13:35:08 +0000 (15:35 +0200)
committerGhislain MARY <ghislain.mary@belledonne-communications.com>
Thu, 11 Oct 2012 13:39:12 +0000 (15:39 +0200)
coreapi/lpconfig.c
coreapi/lpconfig.h

index 0efdc335e529e77777e369503b95801a1d1e3edc..46d683c59027aeadb40183dff22123e37074b6d5 100644 (file)
@@ -271,6 +271,25 @@ const char *lp_config_get_string(LpConfig *lpconfig, const char *section, const
        return default_string;
 }
 
+bool_t lp_config_get_range(LpConfig *lpconfig, const char *section, const char *key, int *min, int *max, int default_min, int default_max) {
+       const char *str = lp_config_get_string(lpconfig, section, key, NULL);
+       if (str != NULL) {
+               char *minusptr = strchr(str, '-');
+               if ((minusptr == NULL) || (minusptr == str)) {
+                       *min = default_min;
+                       *max = default_max;
+                       return FALSE;
+               }
+               *min = atoi(str);
+               *max = atoi(minusptr + 1);
+               return TRUE;
+       } else {
+               *min = default_min;
+               *max = default_max;
+               return TRUE;
+       }
+}
+
 int lp_config_get_int(LpConfig *lpconfig,const char *section, const char *key, int default_value){
        const char *str=lp_config_get_string(lpconfig,section,key,NULL);
        if (str!=NULL) {
@@ -324,6 +343,12 @@ void lp_config_set_string(LpConfig *lpconfig,const char *section, const char *ke
        lpconfig->modified++;
 }
 
+void lp_config_set_range(LpConfig *lpconfig, const char *section, const char *key, int min_value, int max_value) {
+       char tmp[30];
+       snprintf(tmp, sizeof(tmp), "%i-%i", min_value, max_value);
+       lp_config_set_string(lpconfig, section, key, tmp);
+}
+
 void lp_config_set_int(LpConfig *lpconfig,const char *section, const char *key, int value){
        char tmp[30];
        snprintf(tmp,sizeof(tmp),"%i",value);
index a27f7e39a28327ed54fd12ea34f6b6b02a26434f..b672e4cbfceef6754d0c881ba3742e2baac83054 100644 (file)
@@ -59,6 +59,14 @@ int lp_config_read_file(LpConfig *lpconfig, const char *filename);
 **/
 const char *lp_config_get_string(LpConfig *lpconfig, const char *section, const char *key, const char *default_string);
 int lp_config_read_file(LpConfig *lpconfig, const char *filename);
+/**
+ * Retrieves a configuration item as a range, given its section, key, and default min and max values.
+ *
+ * @ingroup misc
+ * @return TRUE if the value is successfully parsed as a range, FALSE otherwise.
+ * If FALSE is returned, min and max are filled respectively with default_min and default_max values.
+ */
+bool_t lp_config_get_range(LpConfig *lpconfig, const char *section, const char *key, int *min, int *max, int default_min, int default_max);
 /**
  * Retrieves a configuration item as an integer, given its section, key, and default value.
  * 
@@ -90,6 +98,12 @@ float lp_config_get_float(LpConfig *lpconfig,const char *section, const char *ke
  * @ingroup misc
 **/
 void lp_config_set_string(LpConfig *lpconfig,const char *section, const char *key, const char *value);
+/**
+ * Sets a range config item
+ *
+ * @ingroup misc
+ */
+void lp_config_set_range(LpConfig *lpconfig, const char *section, const char *key, int min_value, int max_value);
 /**
  * Sets an integer config item
  *