libprelude/master: Implement functions to retrieve applicable operators.

[email protected]
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit 78255a19a0bfbb8b1a748d7d42a75e241d1d5f6c
Author: Yoann Vandoorselaere <[email protected]>
Date:   Tue May 19 16:56:33 2009 +0200

    Implement functions to retrieve applicable operators.
    
    This implement function to retrieve applicable operatoris for a given
    idmef_path_t, idmef_value_t or idmef_value_type_t. It also add the
    idmef_path_check_operator() function that was previously missing.
    
    New functions:
    - idmef_path_check_operator()
    - idmef_path_get_applicable_operators()
    - idmef_value_get_applicable_operators()
    - idmef_value_type_get_applicable_operators()


========================================

 bindings/c++/idmef-path.cxx         |   19 +++++++++++++++++++
 bindings/c++/include/idmef-path.hxx |    3 +++
 src/idmef-path.c                    |   35 +++++++++++++++++++++++++++++++++++
 src/idmef-value-type.c              |   15 +++++++++++++++
 src/idmef-value.c                   |   19 +++++++++++++++++++
 src/include/idmef-path.h            |   14 +++++++++-----
 src/include/idmef-value-type.h      |    2 ++
 src/include/idmef-value.h           |    2 ++
 8 files changed, 104 insertions(+), 5 deletions(-)

========================================

diff --git a/bindings/c++/idmef-path.cxx b/bindings/c++/idmef-path.cxx
index 10e4b07..6454766 100644
--- a/bindings/c++/idmef-path.cxx
+++ b/bindings/c++/idmef-path.cxx
@@ -79,6 +79,25 @@ idmef_value_type_id_t IDMEFPath::GetValueType(int depth)
 }
 
 
+int IDMEFPath::CheckOperator(idmef_criterion_operator_t op)
+{
+        return idmef_path_check_operator(_path, op);
+}
+
+
+
+idmef_criterion_operator_t IDMEFPath::GetApplicableOperators()
+{
+        int ret;
+        idmef_criterion_operator_t res;
+
+        ret = idmef_path_get_applicable_operators(_path, &res);
+        if ( ret < 0 )
+                throw PreludeError(ret);
+
+        return res;
+}
+
 
 void IDMEFPath::Set(IDMEF &message, IDMEFValue *value)
 {
diff --git a/bindings/c++/include/idmef-path.hxx b/bindings/c++/include/idmef-path.hxx
index 1a0c34b..cc5262a 100644
--- a/bindings/c++/include/idmef-path.hxx
+++ b/bindings/c++/include/idmef-path.hxx
@@ -70,6 +70,9 @@ namespace Prelude {
                 int Compare(IDMEFPath *path, int depth=-1);
                 IDMEFPath Clone();
 
+                int CheckOperator(idmef_criterion_operator_t op);
+                idmef_criterion_operator_t GetApplicableOperators();
+
                 //ref ?
                 const char *GetName(int depth=-1);
                 bool IsAmbiguous();
diff --git a/src/idmef-path.c b/src/idmef-path.c
index 209d4a7..dff2cb4 100644
--- a/src/idmef-path.c
+++ b/src/idmef-path.c
@@ -1133,6 +1133,41 @@ int idmef_path_clone(const idmef_path_t *src, idmef_path_t **dst)
 
 
 /**
+ * idmef_path_check_operator:
+ * @path: Pointer to a #idmef_path_t object.
+ * @operator: Operator to check compatibility with.
+ *
+ * Check whether @operator can apply to value pointed to by @path.
+ *
+ * Returns: 0 on success, a negative value if an error occured.
+ */
+int idmef_path_check_operator(const idmef_path_t *path, idmef_criterion_operator_t operator)
+{
+        prelude_return_val_if_fail(path, prelude_error(PRELUDE_ERROR_ASSERTION));
+        return idmef_value_type_check_operator(idmef_path_get_value_type(path, -1), operator);
+}
+
+
+
+/**
+ * idmef_path_get_applicable_operators:
+ * @path: Pointer to a #idmef_path_t object.
+ * @result: Pointer to storage for applicable operator.
+ *
+ * Retrieve all applicable operator that might be used by the type of
+ * value pointed to by @path.
+ *
+ * Returns: 0 on success, a negative value if an error occured.
+ */
+int idmef_path_get_applicable_operators(const idmef_path_t *path, idmef_criterion_operator_t *result)
+{
+        prelude_return_val_if_fail(path && result, prelude_error(PRELUDE_ERROR_ASSERTION));
+        return idmef_value_type_get_applicable_operators(idmef_path_get_value_type(path, -1), result);
+}
+
+
+
+/**
  * idmef_path_ref:
  * @path: Pointer to an #idmef_path_t object.
  *
diff --git a/src/idmef-value-type.c b/src/idmef-value-type.c
index 161b20f..bfb8823 100644
--- a/src/idmef-value-type.c
+++ b/src/idmef-value-type.c
@@ -747,3 +747,18 @@ int idmef_value_type_check_operator(idmef_value_type_id_t type, idmef_criterion_
                                      "Object type '%s' does not support operator '%s'",
                                      idmef_value_type_to_string(type), idmef_criterion_operator_to_string(op));
 }
+
+
+
+int idmef_value_type_get_applicable_operators(idmef_value_type_id_t type, idmef_criterion_operator_t *result)
+{
+        int ret;
+
+        ret = is_type_valid(type);
+        if ( ret < 0 )
+                return ret;
+
+        *result = ops_tbl[type].operator;
+
+        return 0;
+}
diff --git a/src/idmef-value.c b/src/idmef-value.c
index ff3be40..d9825ed 100644
--- a/src/idmef-value.c
+++ b/src/idmef-value.c
@@ -832,6 +832,25 @@ int idmef_value_check_operator(const idmef_value_t *value, idmef_criterion_opera
 
 
 /**
+ * idmef_value_get_applicable_operators:
+ * @value: Pointer to a #idmef_value_t object.
+ * @result: Pointer where the result will be stored.
+ *
+ * Store all operator supported by @value in @result.
+ *
+ * Returns: 0 on success, a negative value if an error occured.
+ */
+
+int idmef_value_get_applicable_operators(const idmef_value_t *value, idmef_criterion_operator_t *result)
+{
+        prelude_return_val_if_fail(value, prelude_error(PRELUDE_ERROR_ASSERTION));
+
+        return idmef_value_type_get_applicable_operators(value->type.id, result);
+}
+
+
+
+/**
  * idmef_value_destroy:
  * @val: Pointer to a #idmef_value_t object.
  *
diff --git a/src/include/idmef-path.h b/src/include/idmef-path.h
index 7d00fa3..d5e03c5 100644
--- a/src/include/idmef-path.h
+++ b/src/include/idmef-path.h
@@ -59,10 +59,10 @@ int idmef_path_set(const idmef_path_t *path, idmef_message_t *message, idmef_val
 
 int idmef_path_new(idmef_path_t **path, const char *format, ...)
                    __attribute__ ((__format__ (__printf__, 2, 3)));
-                   
+
 int idmef_path_new_v(idmef_path_t **path, const char *format, va_list args)
                      __attribute__ ((__format__ (__printf__, 2, 0)));
-                     
+
 int idmef_path_new_fast(idmef_path_t **path, const char *buffer);
 
 idmef_class_id_t idmef_path_get_class(const idmef_path_t *path, int depth);
@@ -96,10 +96,14 @@ prelude_bool_t idmef_path_is_ambiguous(const idmef_path_t *path);
 int idmef_path_has_lists(const idmef_path_t *path);
 
 prelude_bool_t idmef_path_is_list(const idmef_path_t *path, int depth);
-         
+
 unsigned int idmef_path_get_depth(const idmef_path_t *path);
 
-#ifndef SWIG         
+int idmef_path_check_operator(const idmef_path_t *path, idmef_criterion_operator_t op);
+
+int idmef_path_get_applicable_operators(const idmef_path_t *path, idmef_criterion_operator_t *result);
+
+#ifndef SWIG
 void _idmef_path_cache_lock(void);
 
 void _idmef_path_cache_reinit(void);
@@ -112,5 +116,5 @@ void _idmef_path_cache_destroy(void);
 #ifdef __cplusplus
  }
 #endif
-         
+
 #endif /* _LIBPRELUDE_IDMEF_PATH_H */
diff --git a/src/include/idmef-value-type.h b/src/include/idmef-value-type.h
index 2d29a3f..8851326 100644
--- a/src/include/idmef-value-type.h
+++ b/src/include/idmef-value-type.h
@@ -109,6 +109,8 @@ int idmef_value_type_compare(const idmef_value_type_t *type1, const idmef_value_
 
 int idmef_value_type_check_operator(idmef_value_type_id_t type, idmef_criterion_operator_t op);
 
+int idmef_value_type_get_applicable_operators(idmef_value_type_id_t type, idmef_criterion_operator_t *result);
+
 const char *idmef_value_type_to_string(idmef_value_type_id_t type);
 
 #ifdef __cplusplus
diff --git a/src/include/idmef-value.h b/src/include/idmef-value.h
index 5d31e17..5230b0e 100644
--- a/src/include/idmef-value.h
+++ b/src/include/idmef-value.h
@@ -130,6 +130,8 @@ int idmef_value_match(idmef_value_t *val1, idmef_value_t *val2, idmef_criterion_
 
 int idmef_value_check_operator(const idmef_value_t *value, idmef_criterion_operator_t op);
 
+int idmef_value_get_applicable_operators(const idmef_value_t *value, idmef_criterion_operator_t *result);
+
 void idmef_value_destroy(idmef_value_t *val);
 
 #ifndef SWIG
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.