r11145 - libprelude/trunk/bindings

[email protected]
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
Author: yoann
Date: 2009-04-15 15:34:05 +0200 (Wed, 15 Apr 2009)
New Revision: 11145

Modified:
   libprelude/trunk/bindings/libpreludecpp.i
Log:
Old behavior when returning an IDMEFValue was to map it's internal type
to a type understood by the target language.

We preserve this behavior unless the IDMEFValue is a list of "class"
value (class value can't be mapped back to the target language). In this
case we return the raw IDMEFValue object, which can be used directly from
the target language.

Modified: libprelude/trunk/bindings/libpreludecpp.i
===================================================================
--- libprelude/trunk/bindings/libpreludecpp.i	2009-04-14 16:18:39 UTC (rev 11144)
+++ libprelude/trunk/bindings/libpreludecpp.i	2009-04-15 13:34:05 UTC (rev 11145)
@@ -61,7 +61,30 @@
 %ignore operator >>(std::istream &is, const Prelude::IDMEF &idmef);
 
 
+
 %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;
@@ -113,7 +136,7 @@
                 *ret = SWIG_NewPointerObj(new IDMEFTime(time), SWIGTYPE_p_Prelude__IDMEFTime, 1);
         }
 
-        else if ( type == IDMEF_VALUE_TYPE_LIST )
+        else if ( type == IDMEF_VALUE_TYPE_LIST && ! is_class_list(value) )
                 *ret = IDMEFValueList_to_SWIG(result);
 
         else if ( type == IDMEF_VALUE_TYPE_DATA ) {
@@ -134,9 +157,9 @@
                         *ret = SWIG_From_unsigned_SS_long_SS_long(idmef_data_get_uint64(d));
         }
 
-        else if ( type == IDMEF_VALUE_TYPE_CLASS )
-                *ret = SWIG_NewPointerObj(new IDMEFValue(value), SWIGTYPE_p_Prelude__IDMEFValue, 1);
-        
+        else if ( type == IDMEF_VALUE_TYPE_CLASS || type == IDMEF_VALUE_TYPE_LIST )
+                *ret = SWIG_NewPointerObj(new IDMEFValue(idmef_value_ref(value)), SWIGTYPE_p_Prelude__IDMEFValue, 1);
+
         else return -1;
 
         return 0;

_______________________________________________
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.