summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2014-05-15 23:11:54 +0200
committerJakub Hrozek <jhrozek@redhat.com>2014-05-22 17:36:27 +0200
commit5de968e80ade1c02d1907834dcff95e9fc9ad10a (patch)
treed8f66b2e8ba3a330afb823db80b51ba3527c0fc4 /src
parent58229439447d5617913a5a2e173b78105c694842 (diff)
downloadsssd-5de968e80ade1c02d1907834dcff95e9fc9ad10a.tar.gz
sssd-5de968e80ade1c02d1907834dcff95e9fc9ad10a.tar.xz
sssd-5de968e80ade1c02d1907834dcff95e9fc9ad10a.zip
SBUS: Return / if an object path getter returns NULL
Reviewed-by: Stef Walter <stefw@redhat.com> Reviewed-by: Pavel Březina <pbrezina@redhat.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/sbus/sbus_codegen2
-rw-r--r--src/tests/sbus_codegen_tests.c14
-rwxr-xr-xsrc/tests/sbus_codegen_tests.xml1
-rw-r--r--src/tests/sbus_codegen_tests_generated.c11
-rw-r--r--src/tests/sbus_codegen_tests_generated.h2
5 files changed, 29 insertions, 1 deletions
diff --git a/src/sbus/sbus_codegen b/src/sbus/sbus_codegen
index b671e939f..6507753f2 100755
--- a/src/sbus/sbus_codegen
+++ b/src/sbus/sbus_codegen
@@ -320,6 +320,8 @@ def source_getter_invoker(prop):
out("")
if prop.type == "s":
out(" out_val = prop_val == NULL ? \"\" : prop_val;")
+ elif prop.type == "o":
+ out(" out_val = prop_val == NULL ? \"/\" : prop_val;")
else:
out(" out_val = prop_val;")
if prop.is_array:
diff --git a/src/tests/sbus_codegen_tests.c b/src/tests/sbus_codegen_tests.c
index e92c5f784..c7da414fe 100644
--- a/src/tests/sbus_codegen_tests.c
+++ b/src/tests/sbus_codegen_tests.c
@@ -441,6 +441,13 @@ void pilot_get_null_string_handler(struct sbus_request *dbus_req,
*string_val = NULL;
}
+void pilot_get_null_path_handler(struct sbus_request *dbus_req,
+ void *instance_data,
+ const char **path_val)
+{
+ *path_val = NULL;
+}
+
#define array_getter_body(in, out, outlen) do { \
ck_assert(dbus_req != NULL); \
ck_assert(out != NULL); \
@@ -548,6 +555,7 @@ struct test_pilot pilot_iface = {
.test_pilot_get_string = pilot_get_string_handler,
.test_pilot_get_object_path = pilot_get_objpath_handler,
.test_pilot_get_null_string = pilot_get_null_string_handler,
+ .test_pilot_get_null_path = pilot_get_null_path_handler,
.test_pilot_get_byte_array = pilot_get_byte_array_handler,
.test_pilot_get_int16_array = pilot_get_int16_array_handler,
@@ -857,6 +865,12 @@ START_TEST(test_get_basic_types)
call_get(client, "/test/leela", test_pilot_meta.name, "null_string",
DBUS_TYPE_STRING, &string_val);
ck_assert_str_eq(string_val, "");
+
+ /* If a string getter returns NULL, the caller should receive "/" */
+ call_get(client, "/test/leela", test_pilot_meta.name, "null_path",
+ DBUS_TYPE_OBJECT_PATH, &path_val);
+ ck_assert_str_eq(path_val, "/");
+
}
END_TEST
diff --git a/src/tests/sbus_codegen_tests.xml b/src/tests/sbus_codegen_tests.xml
index c44f38305..90e274254 100755
--- a/src/tests/sbus_codegen_tests.xml
+++ b/src/tests/sbus_codegen_tests.xml
@@ -122,6 +122,7 @@
<!-- Special properties to test error codes -->
<property name="null_string" type="s" access="read"/>
+ <property name="null_path" type="o" access="read"/>
<!-- Property arrays with every type of basic argument except boolean
which we can't do (yet) -->
diff --git a/src/tests/sbus_codegen_tests_generated.c b/src/tests/sbus_codegen_tests_generated.c
index 211ad8967..70302daff 100644
--- a/src/tests/sbus_codegen_tests_generated.c
+++ b/src/tests/sbus_codegen_tests_generated.c
@@ -372,6 +372,15 @@ const struct sbus_property_meta test_pilot__properties[] = {
NULL, /* no invoker */
},
{
+ "null_path", /* name */
+ "o", /* type */
+ SBUS_PROPERTY_READABLE,
+ offsetof(struct test_pilot, test_pilot_get_null_path),
+ invoke_get_o,
+ 0, /* not writable */
+ NULL, /* no invoker */
+ },
+ {
"byte_array", /* name */
"ay", /* type */
SBUS_PROPERTY_READABLE,
@@ -716,7 +725,7 @@ static int invoke_get_o(struct sbus_request *dbus_req, void *function_ptr)
(handler)(dbus_req, dbus_req->intf->instance_data, &prop_val);
- out_val = prop_val;
+ out_val = prop_val == NULL ? "/" : prop_val;
return sbus_request_return_as_variant(dbus_req, DBUS_TYPE_OBJECT_PATH, &out_val);
}
diff --git a/src/tests/sbus_codegen_tests_generated.h b/src/tests/sbus_codegen_tests_generated.h
index 7dc817edf..e6fb10c5e 100644
--- a/src/tests/sbus_codegen_tests_generated.h
+++ b/src/tests/sbus_codegen_tests_generated.h
@@ -36,6 +36,7 @@
#define TEST_PILOT_STRING "string"
#define TEST_PILOT_OBJECT_PATH "object_path"
#define TEST_PILOT_NULL_STRING "null_string"
+#define TEST_PILOT_NULL_PATH "null_path"
#define TEST_PILOT_BYTE_ARRAY "byte_array"
#define TEST_PILOT_INT16_ARRAY "int16_array"
#define TEST_PILOT_UINT16_ARRAY "uint16_array"
@@ -98,6 +99,7 @@ struct test_pilot {
void (*test_pilot_get_string)(struct sbus_request *, void *data, const char * *);
void (*test_pilot_get_object_path)(struct sbus_request *, void *data, const char * *);
void (*test_pilot_get_null_string)(struct sbus_request *, void *data, const char * *);
+ void (*test_pilot_get_null_path)(struct sbus_request *, void *data, const char * *);
void (*test_pilot_get_byte_array)(struct sbus_request *, void *data, uint8_t * *, int *);
void (*test_pilot_get_int16_array)(struct sbus_request *, void *data, int16_t * *, int *);
void (*test_pilot_get_uint16_array)(struct sbus_request *, void *data, uint16_t * *, int *);