]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
conf api: use const pointers where possible
authorVictor Julien <victor@inliniac.net>
Tue, 13 Jan 2015 09:46:56 +0000 (10:46 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 27 Jan 2015 08:16:43 +0000 (09:16 +0100)
Use const pointers where possible in the Conf API.

src/conf.c
src/conf.h

index cabde9e36fb99f7c65b445c8d3c377f9cb6b8c5f..c42ff4957542e87eab14a54b6db903c4b445b1ec 100644 (file)
@@ -62,7 +62,7 @@ static ConfNode *root_backup = NULL;
  *   created node for the provided name.  On error, NULL will be returned.
  */
 static ConfNode *
-ConfGetNodeOrCreate(char *name, int final)
+ConfGetNodeOrCreate(const char *name, int final)
 {
     ConfNode *parent = root;
     ConfNode *node = NULL;
@@ -178,7 +178,7 @@ ConfNodeFree(ConfNode *node)
  *    node does not exist.
  */
 ConfNode *
-ConfGetNode(char *name)
+ConfGetNode(const char *name)
 {
     ConfNode *node = root;
     char node_name[NODE_NAME_MAX];
@@ -224,7 +224,7 @@ ConfGetRootNode(void)
  * \retval 1 if the value was set otherwise 0.
  */
 int
-ConfSet(char *name, char *val)
+ConfSet(const char *name, char *val)
 {
     ConfNode *node = ConfGetNodeOrCreate(name, 0);
     if (node == NULL || node->final) {
@@ -254,7 +254,7 @@ ConfSet(char *name, char *val)
  * \retval 1 if the value was set otherwise 0.
  */
 int
-ConfSetFinal(char *name, char *val)
+ConfSetFinal(const char *name, char *val)
 {
     ConfNode *node = ConfGetNodeOrCreate(name, 1);
     if (node == NULL) {
@@ -287,7 +287,7 @@ ConfSetFinal(char *name, char *val)
  *   be returned.
  */
 int
-ConfGet(char *name, char **vptr)
+ConfGet(const char *name, char **vptr)
 {
     ConfNode *node = ConfGetNode(name);
     if (node == NULL) {
@@ -300,7 +300,7 @@ ConfGet(char *name, char **vptr)
     }
 }
 
-int ConfGetChildValue(ConfNode *base, char *name, char **vptr)
+int ConfGetChildValue(const ConfNode *base, const char *name, char **vptr)
 {
     ConfNode *node = ConfNodeLookupChild(base, name);
 
@@ -315,7 +315,7 @@ int ConfGetChildValue(ConfNode *base, char *name, char **vptr)
 }
 
 
-int ConfGetChildValueWithDefault(ConfNode *base, ConfNode *dflt, char *name, char **vptr)
+int ConfGetChildValueWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, char **vptr)
 {
     int ret = ConfGetChildValue(base, name, vptr);
     /* Get 'default' value */
@@ -336,7 +336,7 @@ int ConfGetChildValueWithDefault(ConfNode *base, ConfNode *dflt, char *name, cha
  * converted to an interger, otherwise 0 will be returned.
  */
 int
-ConfGetInt(char *name, intmax_t *val)
+ConfGetInt(const char *name, intmax_t *val)
 {
     char *strval;
     intmax_t tmpint;
@@ -356,7 +356,7 @@ ConfGetInt(char *name, intmax_t *val)
     return 1;
 }
 
-int ConfGetChildValueInt(ConfNode *base, char *name, intmax_t *val)
+int ConfGetChildValueInt(const ConfNode *base, const char *name, intmax_t *val)
 {
     char *strval;
     intmax_t tmpint;
@@ -376,7 +376,7 @@ int ConfGetChildValueInt(ConfNode *base, char *name, intmax_t *val)
 
 }
 
-int ConfGetChildValueIntWithDefault(ConfNode *base, ConfNode *dflt, char *name, intmax_t *val)
+int ConfGetChildValueIntWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, intmax_t *val)
 {
     int ret = ConfGetChildValueInt(base, name, val);
     /* Get 'default' value */
@@ -398,7 +398,7 @@ int ConfGetChildValueIntWithDefault(ConfNode *base, ConfNode *dflt, char *name,
  * converted to a boolean, otherwise 0 will be returned.
  */
 int
-ConfGetBool(char *name, int *val)
+ConfGetBool(const char *name, int *val)
 {
     char *strval;
 
@@ -411,7 +411,7 @@ ConfGetBool(char *name, int *val)
     return 1;
 }
 
-int ConfGetChildValueBool(ConfNode *base, char *name, int *val)
+int ConfGetChildValueBool(const ConfNode *base, const char *name, int *val)
 {
     char *strval;
 
@@ -424,7 +424,7 @@ int ConfGetChildValueBool(ConfNode *base, char *name, int *val)
     return 1;
 }
 
-int ConfGetChildValueBoolWithDefault(ConfNode *base, ConfNode *dflt, char *name, int *val)
+int ConfGetChildValueBoolWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, int *val)
 {
     int ret = ConfGetChildValueBool(base, name, val);
     /* Get 'default' value */
@@ -498,7 +498,7 @@ ConfValIsFalse(const char *val)
  * converted to a double, otherwise 0 will be returned.
  */
 int
-ConfGetDouble(char *name, double *val)
+ConfGetDouble(const char *name, double *val)
 {
     char *strval;
     double tmpdo;
@@ -529,7 +529,7 @@ ConfGetDouble(char *name, double *val)
  * converted to a double, otherwise 0 will be returned.
  */
 int
-ConfGetFloat(char *name, float *val)
+ConfGetFloat(const char *name, float *val)
 {
     char *strval;
     double tmpfl;
@@ -569,7 +569,7 @@ ConfNodeRemove(ConfNode *node)
  *   most likely indicating the parameter was not set.
  */
 int
-ConfRemove(char *name)
+ConfRemove(const char *name)
 {
     ConfNode *node;
 
@@ -641,7 +641,7 @@ ConfPrintNameArray(char **name_arr, int level)
  * \brief Dump a configuration node and all its children.
  */
 void
-ConfNodeDump(ConfNode *node, const char *prefix)
+ConfNodeDump(const ConfNode *node, const char *prefix)
 {
     ConfNode *child;
 
@@ -689,7 +689,7 @@ ConfDump(void)
  * \retval A pointer the child ConfNode if found otherwise NULL.
  */
 ConfNode *
-ConfNodeLookupChild(ConfNode *node, const char *name)
+ConfNodeLookupChild(const ConfNode *node, const char *name)
 {
     ConfNode *child;
 
@@ -714,7 +714,7 @@ ConfNodeLookupChild(ConfNode *node, const char *name)
  * \retval A pointer the child ConfNodes value if found otherwise NULL.
  */
 const char *
-ConfNodeLookupChildValue(ConfNode *node, const char *name)
+ConfNodeLookupChildValue(const ConfNode *node, const char *name)
 {
     ConfNode *child;
 
@@ -731,7 +731,7 @@ ConfNodeLookupChildValue(ConfNode *node, const char *name)
  * \return the ConfNode matching or NULL
  */
 
-ConfNode *ConfNodeLookupKeyValue(ConfNode *base, const char *key, const char *value)
+ConfNode *ConfNodeLookupKeyValue(const ConfNode *base, const char *key, const char *value)
 {
     ConfNode *child;
 
@@ -759,7 +759,7 @@ ConfNode *ConfNodeLookupKeyValue(ConfNode *base, const char *key, const char *va
  *     returned, even if the child node does not exist.
  */
 int
-ConfNodeChildValueIsTrue(ConfNode *node, const char *key)
+ConfNodeChildValueIsTrue(const ConfNode *node, const char *key)
 {
     const char *val;
 
@@ -773,7 +773,7 @@ ConfNodeChildValueIsTrue(ConfNode *node, const char *key)
  *  \param file The name of the file
  *  \retval str Pointer to the string path + sig_file
  */
-char *ConfLoadCompleteIncludePath(char *file)
+char *ConfLoadCompleteIncludePath(const char *file)
 {
     char *defaultpath = NULL;
     char *path = NULL;
index c819eb049361adba0cf9e3a481b0a6f691fda8a6..6bc7414e6aadb6e485c19ec51d04aad677902581 100644 (file)
@@ -56,36 +56,36 @@ typedef struct ConfNode_ {
 void ConfInit(void);
 void ConfDeInit(void);
 ConfNode *ConfGetRootNode(void);
-int ConfGet(char *name, char **vptr);
-int ConfGetInt(char *name, intmax_t *val);
-int ConfGetBool(char *name, int *val);
-int ConfGetDouble(char *name, double *val);
-int ConfGetFloat(char *name, float *val);
-int ConfSet(char *name, char *val);
-int ConfSetFinal(char *name, char *val);
+int ConfGet(const char *name, char **vptr);
+int ConfGetInt(const char *name, intmax_t *val);
+int ConfGetBool(const char *name, int *val);
+int ConfGetDouble(const char *name, double *val);
+int ConfGetFloat(const char *name, float *val);
+int ConfSet(const char *name, char *val);
+int ConfSetFinal(const char *name, char *val);
 void ConfDump(void);
-void ConfNodeDump(ConfNode *node, const char *prefix);
+void ConfNodeDump(const ConfNode *node, const char *prefix);
 ConfNode *ConfNodeNew(void);
 void ConfNodeFree(ConfNode *);
-ConfNode *ConfGetNode(char *key);
+ConfNode *ConfGetNode(const char *key);
 void ConfCreateContextBackup(void);
 void ConfRestoreContextBackup(void);
-ConfNode *ConfNodeLookupChild(ConfNode *node, const char *key);
-const char *ConfNodeLookupChildValue(ConfNode *node, const char *key);
+ConfNode *ConfNodeLookupChild(const ConfNode *node, const char *key);
+const char *ConfNodeLookupChildValue(const ConfNode *node, const char *key);
 void ConfNodeRemove(ConfNode *);
 void ConfRegisterTests();
-int ConfNodeChildValueIsTrue(ConfNode *node, const char *key);
+int ConfNodeChildValueIsTrue(const ConfNode *node, const char *key);
 int ConfValIsTrue(const char *val);
 int ConfValIsFalse(const char *val);
 void ConfNodePrune(ConfNode *node);
 
-ConfNode *ConfNodeLookupKeyValue(ConfNode *base, const char *key, const char *value);
-int ConfGetChildValue(ConfNode *base, char *name, char **vptr);
-int ConfGetChildValueInt(ConfNode *base, char *name, intmax_t *val);
-int ConfGetChildValueBool(ConfNode *base, char *name, int *val);
-int ConfGetChildValueWithDefault(ConfNode *base, ConfNode *dflt, char *name, char **vptr);
-int ConfGetChildValueIntWithDefault(ConfNode *base, ConfNode *dflt, char *name, intmax_t *val);
-int ConfGetChildValueBoolWithDefault(ConfNode *base, ConfNode *dflt, char *name, int *val);
-char *ConfLoadCompleteIncludePath(char *);
+ConfNode *ConfNodeLookupKeyValue(const ConfNode *base, const char *key, const char *value);
+int ConfGetChildValue(const ConfNode *base, const char *name, char **vptr);
+int ConfGetChildValueInt(const ConfNode *base, const char *name, intmax_t *val);
+int ConfGetChildValueBool(const ConfNode *base, const char *name, int *val);
+int ConfGetChildValueWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, char **vptr);
+int ConfGetChildValueIntWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, intmax_t *val);
+int ConfGetChildValueBoolWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, int *val);
+char *ConfLoadCompleteIncludePath(const char *);
 
 #endif /* ! __CONF_H__ */