libprelude/master: Improve retrieval of list of IDMEF object

[email protected] Sat, 16 Jan 2010 19:58:34 +0100 (CET)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit 5c0053dd8ac606040e10a9a489e0d36e3ea52e44
Author: Yoann Vandoorselaere <[email protected]>
Date:   Wed Jan 13 17:37:51 2010 +0100

    Improve retrieval of list of IDMEF object
    
    When retrieving a list of IDMEF object, return a Python list containing
    one IDMEFValue for each object.
    
    This behavior is more consistant than retrieving a single IDMEFValue
    carrying the whole list, and might permit the user to play with the
    object directly if we extand the API in the future.
    
    Compatibility with the old implementation for setting whole list is
    achived by converting back the list of IDMEFValue to an IDMEFValue
    of the list type on Set().


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

 bindings/c++/idmef-path.cxx          |   11 +++++++++++
 bindings/c++/idmef-value.cxx         |   13 +++++++++++++
 bindings/c++/idmef.cxx               |    6 ++++++
 bindings/c++/include/idmef-path.hxx  |    1 +
 bindings/c++/include/idmef-value.hxx |    1 +
 bindings/c++/include/idmef.hxx       |    1 +
 bindings/libpreludecpp.i             |   24 ++----------------------
 7 files changed, 35 insertions(+), 22 deletions(-)

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

diff --git a/bindings/c++/idmef-path.cxx b/bindings/c++/idmef-path.cxx
index 6454766..2ab5a4d 100644
--- a/bindings/c++/idmef-path.cxx
+++ b/bindings/c++/idmef-path.cxx
@@ -113,6 +113,17 @@ void IDMEFPath::Set(IDMEF &message, IDMEFValue *value)
 }
 
 
+void IDMEFPath::Set(IDMEF &message, std::vector<IDMEFValue> value)
+{
+        int ret;
+        IDMEFValue v = value;
+
+        ret = idmef_path_set(_path, message, v);
+        if ( ret < 0 )
+                throw PreludeError(ret);
+}
+
+
 void IDMEFPath::Set(IDMEF &message, IDMEFValue &value)
 {
         int ret;
diff --git a/bindings/c++/idmef-value.cxx b/bindings/c++/idmef-value.cxx
index 4e5161c..1b91949 100644
--- a/bindings/c++/idmef-value.cxx
+++ b/bindings/c++/idmef-value.cxx
@@ -183,6 +183,19 @@ IDMEFValue::IDMEFValue(IDMEFTime &time)
 }
 
 
+IDMEFValue::IDMEFValue(std::vector<IDMEFValue> value)
+{
+        int ret;
+        std::vector<Prelude::IDMEFValue>::const_iterator i;
+
+        ret = idmef_value_new_list(&_value);
+        if ( ret < 0 )
+                throw PreludeError(ret);
+
+        for ( i = value.begin(); i != value.end(); i++ )
+                idmef_value_list_add(_value, idmef_value_ref(*i));
+}
+
 IDMEFValue::IDMEFValue(idmef_value_t *value)
 {
         _value = value;
diff --git a/bindings/c++/idmef.cxx b/bindings/c++/idmef.cxx
index 4eb31f0..a468c3a 100644
--- a/bindings/c++/idmef.cxx
+++ b/bindings/c++/idmef.cxx
@@ -42,6 +42,12 @@ IDMEF::~IDMEF()
 }
 
 
+void IDMEF::Set(const char *path, std::vector<IDMEFValue> value)
+{
+        IDMEFPath(path).Set(*this, value);
+}
+
+
 void IDMEF::Set(const char *path, IDMEFValue *value)
 {
         IDMEFPath(path).Set(*this, value);
diff --git a/bindings/c++/include/idmef-path.hxx b/bindings/c++/include/idmef-path.hxx
index cc5262a..3724818 100644
--- a/bindings/c++/include/idmef-path.hxx
+++ b/bindings/c++/include/idmef-path.hxx
@@ -44,6 +44,7 @@ namespace Prelude {
                 ~IDMEFPath();
 
                 Prelude::IDMEFValue Get(Prelude::IDMEF &message);
+                void Set(Prelude::IDMEF &message, std::vector<Prelude::IDMEFValue> value);
                 void Set(Prelude::IDMEF &message, Prelude::IDMEFValue *value);
                 void Set(Prelude::IDMEF &message, Prelude::IDMEFValue &value);
                 void Set(Prelude::IDMEF &message, Prelude::IDMEFTime &time);
diff --git a/bindings/c++/include/idmef-value.hxx b/bindings/c++/include/idmef-value.hxx
index 145c87b..0de533a 100644
--- a/bindings/c++/include/idmef-value.hxx
+++ b/bindings/c++/include/idmef-value.hxx
@@ -44,6 +44,7 @@ namespace Prelude {
                 IDMEFValue();
                 ~IDMEFValue();
                 IDMEFValue(const IDMEFValue &value);
+                IDMEFValue(std::vector<IDMEFValue> value);
                 IDMEFValue(idmef_value_t *value);
                 IDMEFValue(std::string value);
                 IDMEFValue(const char *value);
diff --git a/bindings/c++/include/idmef.hxx b/bindings/c++/include/idmef.hxx
index 17fd955..5b8a0dd 100644
--- a/bindings/c++/include/idmef.hxx
+++ b/bindings/c++/include/idmef.hxx
@@ -30,6 +30,7 @@ namespace Prelude {
                 IDMEF(const IDMEF &idmef);
                 IDMEF(idmef_message_t *message);
 
+                void Set(const char *path, std::vector<Prelude::IDMEFValue> value);
                 void Set(const char *path, Prelude::IDMEFValue *value);
                 void Set(const char *path, Prelude::IDMEFValue &value);
                 void Set(const char *path, Prelude::IDMEFTime &value);
diff --git a/bindings/libpreludecpp.i b/bindings/libpreludecpp.i
index 80ea5fb..f930a9f 100644
--- a/bindings/libpreludecpp.i
+++ b/bindings/libpreludecpp.i
@@ -75,26 +75,6 @@ typedef signed int prelude_error_t;
 %fragment("IDMEFValue_to_SWIG", "header", fragment="IDMEFValueList_to_SWIG", fragment="SWIG_From_float") {
 
 
-static int iterate_cb(idmef_value_t *value, void *extra)
-{
-        prelude_bool_t *is_class = (prelude_bool_t *) extra;
-
-        if ( idmef_value_is_list(value) )
-                return idmef_value_iterate(value, iterate_cb, extra);
-
-        *is_class = (prelude_bool_t) (idmef_value_get_type(value) == IDMEF_VALUE_TYPE_CLASS);
-
-        return -1;
-}
-
-static prelude_bool_t is_class_list(idmef_value_t *value)
-{
-        prelude_bool_t is_class;
-
-        idmef_value_iterate(value, iterate_cb, &is_class);
-        return is_class;
-}
-
 int IDMEFValue_to_SWIG(const IDMEFValue &result, TARGET_LANGUAGE_OUTPUT_TYPE ret)
 {
         std::stringstream s;
@@ -146,7 +126,7 @@ int IDMEFValue_to_SWIG(const IDMEFValue &result, TARGET_LANGUAGE_OUTPUT_TYPE ret
                 *ret = SWIG_NewPointerObj(new IDMEFTime(time), SWIGTYPE_p_Prelude__IDMEFTime, 1);
         }
 
-        else if ( type == IDMEF_VALUE_TYPE_LIST && ! is_class_list(value) )
+        else if ( type == IDMEF_VALUE_TYPE_LIST )
                 *ret = IDMEFValueList_to_SWIG(result);
 
         else if ( type == IDMEF_VALUE_TYPE_DATA ) {
@@ -170,7 +150,7 @@ int IDMEFValue_to_SWIG(const IDMEFValue &result, TARGET_LANGUAGE_OUTPUT_TYPE ret
                         *ret = SWIG_From_unsigned_SS_long_SS_long(idmef_data_get_uint64(d));
         }
 
-        else if ( type == IDMEF_VALUE_TYPE_CLASS || type == IDMEF_VALUE_TYPE_LIST )
+        else if ( type == IDMEF_VALUE_TYPE_CLASS )
                 *ret = SWIG_NewPointerObj(new IDMEFValue(idmef_value_ref(value)), SWIGTYPE_p_Prelude__IDMEFValue, 1);
 
         else return -1;
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog