From b832721fd077834ceff662b18c62dda0fa67db8e Mon Sep 17 00:00:00 2001 From: Ossama Othman Date: Tue, 10 Dec 2013 13:43:58 -0800 Subject: [PATCH] Added missing RequestInput dictionary return value construction. Change-Id: I575ac857d03f5e4317e69bf57bd8e46c48e5f5fe Signed-off-by: Ossama Othman --- plugins/connman/agent.cpp | 54 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/plugins/connman/agent.cpp b/plugins/connman/agent.cpp index 07d5576..cbb5267 100644 --- a/plugins/connman/agent.cpp +++ b/plugins/connman/agent.cpp @@ -204,9 +204,17 @@ namespace agent_operation_handler( service, user_data, - [fields, invocation](agent::connect_data const & d){ + [object, invocation, fields](agent::connect_data const & d){ using ivi::settings::unique_ptr; + // Prepare to build a dictionary, i.e. an array of + // dictionary entries, "a{sv}". + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); + + bool error_occurred = false; + bool found_field = false; + // Extract requested mandatory and alternate fields. GVariantIter * vi = nullptr; g_variant_get(fields, "(a{sv})", &vi); @@ -242,7 +250,25 @@ namespace // Check if we were supplied the required field, and add // it to the dictionary result. auto const i = d.info.find(fname); - if (i == d.info.end()) { + if (i != d.info.end()) { + // Note that the dictionary is of the form a{sv} so + // we wrap the dictionary string value in a variant. + g_variant_builder_add_value( + &builder, + g_variant_new_dict_entry( + g_variant_new_string(fname), + g_variant_new_variant( + g_variant_new_string(i->second.c_str())))); + + /** + * @todo Is there any way to tell if an entry was + * added to the indefinite array being + * constructed through the glib GVariant builder + * interface? We can't get rid of this flag if + * that is the case. + */ + found_field = true; + } else { std::string err( std::string("Required connection field \"") + fname @@ -264,19 +290,29 @@ namespace invocation, "net.connman.Agent.Error.Canceled", err.c_str()); - break; /// @todo Is this correct? + + error_occurred = true; + + return; } } } - } - }); - GVariant * dictionary = nullptr; + if (!error_occurred) { + GVariant * dictionary = nullptr; - // The method return value will contain a dictionary of the - // requested input fields. - agent_complete_request_input(object, invocation, dictionary); + // We can't call g_variant_builder_end() if no children + // (dictionary entries) were added to the indefinite array + // being construction through the builder. + if (found_field) + dictionary = g_variant_builder_end(&builder); + + // The method return value will contain a dictionary of the + // requested input fields. + agent_complete_request_input(object, invocation, dictionary); + } + }); return true; } -- 2.7.4