diff options
Diffstat (limited to 'src/lib/util/gnunet_time_dbus_lib_pop.c')
-rw-r--r-- | src/lib/util/gnunet_time_dbus_lib_pop.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/lib/util/gnunet_time_dbus_lib_pop.c b/src/lib/util/gnunet_time_dbus_lib_pop.c new file mode 100644 index 0000000..10322c6 --- /dev/null +++ b/src/lib/util/gnunet_time_dbus_lib_pop.c | |||
@@ -0,0 +1,52 @@ | |||
1 | #include "config.h" | ||
2 | |||
3 | #include <gnunet/platform.h> | ||
4 | #include <gnunet/gnunet_common.h> | ||
5 | #include <gnunet/gnunet_strings_lib.h> | ||
6 | |||
7 | #include "gnunet_time_dbus_lib.h" | ||
8 | |||
9 | DBusMessage * | ||
10 | GNUNET_TIME_DBUS_pop_absolute ( | ||
11 | DBusMessage *message, | ||
12 | DBusMessageIter *iter, | ||
13 | const char *arg_name, | ||
14 | struct GNUNET_TIME_Absolute *value) | ||
15 | { | ||
16 | DBusMessageIter iter_sub; | ||
17 | DBusMessage *ret = GNUNET_DBUS_pop_enter_variant (message, iter, &iter_sub, arg_name); | ||
18 | if (ret) | ||
19 | return ret; | ||
20 | |||
21 | int arg_type = dbus_message_iter_get_arg_type (&iter_sub); | ||
22 | switch (arg_type) | ||
23 | { | ||
24 | case DBUS_TYPE_STRING: { | ||
25 | const char *time; | ||
26 | dbus_message_iter_get_basic (&iter_sub, &time); | ||
27 | int err = GNUNET_STRINGS_fancy_time_to_absolute (time, value); | ||
28 | if (GNUNET_OK != err) | ||
29 | { | ||
30 | return dbus_message_new_error_printf ( | ||
31 | message, | ||
32 | DBUS_ERROR_INVALID_ARGS, | ||
33 | "Bad argument for '%s'. Malformed time string. GNUNET_STRINGS_fancy_time_to_absolute returned %d", | ||
34 | arg_name, | ||
35 | err); | ||
36 | }; | ||
37 | return NULL; | ||
38 | }; | ||
39 | case DBUS_TYPE_UINT64: | ||
40 | dbus_message_iter_get_basic (&iter_sub, &value->abs_value_us); | ||
41 | return NULL; | ||
42 | default: | ||
43 | return dbus_message_new_error_printf ( | ||
44 | message, | ||
45 | DBUS_ERROR_INVALID_ARGS, | ||
46 | "Bad argument for '%s'. Variant must contain a time encoded as a human readable string or a uint64 representing the number of microseconds since epoch. Contains %s.", | ||
47 | arg_name, | ||
48 | GNUNET_DBUS_signature_typecode_to_string (arg_type)); | ||
49 | }; | ||
50 | }; | ||
51 | |||
52 | |||