[prev in list] [next in list] [prev in thread] [next in thread] 

List:       prelude-cvslog
Subject:    [prelude-cvslog] r10573 -
From:       noreply () prelude-ids ! org
Date:       2008-05-07 7:43:06
Message-ID: 20080507074306.D8E1F8A006D () inferno ! prelude-ids ! com
[Download RAW message or body]

Author: yoann
Date: 2008-05-07 09:43:06 +0200 (Wed, 07 May 2008)
New Revision: 10573

Modified:
   libprelude/branches/libprelude-easy-bindings/src/idmef-value.c
Log:
Ability to cast IDMEF value to string. Move casting to/from
string to separate functions.


Modified: libprelude/branches/libprelude-easy-bindings/src/idmef-value.c
===================================================================
--- libprelude/branches/libprelude-easy-bindings/src/idmef-value.c	2008-05-06 \
                16:34:58 UTC (rev 10572)
+++ libprelude/branches/libprelude-easy-bindings/src/idmef-value.c	2008-05-07 \
07:43:06 UTC (rev 10573) @@ -1016,10 +1016,51 @@
 
 
 
-int _idmef_value_cast(idmef_value_t *value, idmef_value_type_id_t ntype, \
idmef_class_id_t id) +static int cast_to_string(idmef_value_t *value)
 {
         int ret;
+        prelude_string_t *out;
 
+        ret = prelude_string_new(&out);
+        if ( ret < 0 )
+                return ret;
+
+        ret = idmef_value_type_write(&value->type, out);
+        if ( ret < 0 ) {
+                prelude_string_destroy(out);
+                return ret;
+        }
+
+        idmef_value_type_destroy(&value->type);
+        idmef_value_set_string(value, out);
+
+        return 0;
+}
+
+
+
+static int cast_from_string(idmef_value_t *value, idmef_value_type_id_t ntype)
+{
+        int ret;
+        idmef_value_type_t vt;
+        prelude_string_t *str = idmef_value_get_string(value);
+
+        vt.id = ntype;
+
+        ret = idmef_value_type_read(&vt, prelude_string_get_string(str));
+        if ( ret < 0 )
+                return ret;
+
+        idmef_value_type_destroy(&value->type);
+        memcpy(&value->type, &vt, sizeof(value->type));
+
+        return 0;
+}
+
+
+
+int _idmef_value_cast(idmef_value_t *value, idmef_value_type_id_t ntype, \
idmef_class_id_t id) +{
         prelude_return_val_if_fail(value, prelude_error(PRELUDE_ERROR_ASSERTION));
 
         prelude_log_debug(3, "converting '%s' to '%s'.\n",
@@ -1032,6 +1073,9 @@
         else if ( ntype == IDMEF_VALUE_TYPE_TIME )
                 return cast_to_time(value);
 
+        else if ( ntype == IDMEF_VALUE_TYPE_STRING )
+                return cast_to_string(value);
+
         else if ( ntype == IDMEF_VALUE_TYPE_ENUM && idmef_value_get_type(value) == \
IDMEF_VALUE_TYPE_STRING ) {  prelude_string_t *str = idmef_value_get_string(value);
                 return idmef_value_set_enum_from_string(value, id, \
prelude_string_get_string(str)); @@ -1067,20 +1111,9 @@
         else if ( value->type.id == IDMEF_VALUE_TYPE_DOUBLE )
                 VALUE_CAST_CHECK(value, double, double, "f", ntype);
 
-        else if ( value->type.id == IDMEF_VALUE_TYPE_STRING ) {
-                idmef_value_type_t vt;
-                prelude_string_t *str = idmef_value_get_string(value);
+        else if ( value->type.id == IDMEF_VALUE_TYPE_STRING )
+                return cast_from_string(value, ntype);
 
-                vt.id = ntype;
-
-                ret = idmef_value_type_read(&vt, prelude_string_get_string(str));
-                if ( ret < 0 )
-                        return ret;
-
-                idmef_value_type_destroy(&value->type);
-                memcpy(&value->type, &vt, sizeof(value->type));
-        }
-
         else return prelude_error_verbose(PRELUDE_ERROR_GENERIC,
                                           "Unable to cast input type '%s' to '%s'",
                                            \
idmef_value_type_to_string(value->type.id),


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic