summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgitjackolantern <scottjconover@yahoo.com>2015-09-09 15:26:13 -0700
committergitjackolantern <scottjconover@yahoo.com>2015-09-09 15:26:13 -0700
commit193ad6bb3db7ed2ba6b93c1ab4e1e592985e5b90 (patch)
treea9e23b073ff160bf9d61c97e9b3c250db14a4eb9
parentdcd05464ebfa1caa4f5c09cfb0fe0b7350d0ad2f (diff)
parentda4e1004a998416991536172b51f74b89d0b2b00 (diff)
downloadbluez-tools-193ad6bb3db7ed2ba6b93c1ab4e1e592985e5b90.tar.gz
Merge pull request #8 from syntheticpp/variant
dbus needs a tuple of variants
-rw-r--r--src/lib/agent-helper.c134
1 files changed, 74 insertions, 60 deletions
diff --git a/src/lib/agent-helper.c b/src/lib/agent-helper.c
index 740a8ed..a4d1a04 100644
--- a/src/lib/agent-helper.c
+++ b/src/lib/agent-helper.c
@@ -45,7 +45,7 @@ static const gchar *_find_device_pin(const gchar *device_path);
static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data)
{
// g_print("%s%s\n", method_name, g_variant_print(parameters, FALSE));
-
+
if (g_strcmp0(method_name, "AuthorizeService") == 0)
{
// Return void
@@ -63,18 +63,18 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar
GError *error = NULL;
Device *device_obj = device_new(g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL));
const gchar *pin = _find_device_pin(device_get_dbus_object_path(device_obj));
-
+
if (_interactive)
g_print("Device: %s (%s)\n", device_get_alias(device_obj, &error), device_get_address(device_obj, &error));
-
+
if (error)
{
g_critical("Failed to get remote device's MAC address: %s", error->message);
g_error_free(error);
}
-
+
g_object_unref(device_obj);
-
+
if (_interactive)
{
g_print("Passkey: %u, entered: %u\n", g_variant_get_uint32(g_variant_get_child_value(parameters, 1)), g_variant_get_uint16(g_variant_get_child_value(parameters, 2)));
@@ -87,7 +87,7 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar
g_dbus_method_invocation_return_value(invocation, NULL);
return;
}
-
+
g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Pairing rejected");
}
else if (g_strcmp0(method_name, "DisplayPinCode") == 0)
@@ -96,20 +96,20 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar
Device *device_obj = device_new(g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL));
const gchar *pin = _find_device_pin(device_get_dbus_object_path(device_obj));
const gchar *pincode = g_variant_get_string(g_variant_get_child_value(parameters, 1), NULL);
-
+
if (_interactive)
g_print("Device: %s (%s)\n", device_get_alias(device_obj, &error), device_get_address(device_obj, &error));
-
+
if (error)
{
g_critical("Failed to get remote device's MAC address: %s", error->message);
g_error_free(error);
}
-
+
g_object_unref(device_obj);
-
+
/* Try to use found PIN */
- if (pin != NULL)
+ if (pin != NULL)
{
if (g_strcmp0(pin, "*") == 0 || g_strcmp0(pin, pincode) == 0)
{
@@ -119,13 +119,13 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar
}
else
g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Passkey does not match");
-
+
return;
}
else if (_interactive)
{
g_print("Confirm pin code: %s (yes/no)? ", pincode);
-
+
gchar yn[4] = {0,};
errno = 0;
if (scanf("%3s", yn) == EOF && errno)
@@ -136,19 +136,19 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar
g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Passkey does not match");
return;
}
-
+
g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Pairing rejected");
}
else if (g_strcmp0(method_name, "Release") == 0)
{
agent_need_unregister = FALSE;
-
+
if(_mainloop)
if (g_main_loop_is_running(_mainloop))
g_main_loop_quit(_mainloop);
-
- g_print("Agent released\n");
-
+
+ g_print("Agent released\n");
+
// Return void
g_dbus_method_invocation_return_value(invocation, NULL);
}
@@ -156,18 +156,18 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar
{
GError *error = NULL;
Device *device_obj = device_new(g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL));
-
+
if (_interactive)
g_print("Device: %s (%s)\n", device_get_alias(device_obj, &error), device_get_address(device_obj, &error));
-
+
if(error)
{
g_critical("Failed to get remote device's MAC address: %s", error->message);
g_error_free(error);
}
-
+
g_object_unref(device_obj);
-
+
if (_interactive)
{
g_print("Authorize this device pairing (yes/no)? ");
@@ -181,7 +181,7 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar
g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Pairing rejected");
return;
}
-
+
g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Pairing rejected");
}
else if (g_strcmp0(method_name, "RequestConfirmation") == 0)
@@ -190,24 +190,24 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar
Device *device_obj = device_new(g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL));
guint32 passkey = g_variant_get_uint32(g_variant_get_child_value(parameters, 1));
const gchar *pin = _find_device_pin(device_get_dbus_object_path(device_obj));
-
+
if (_interactive)
g_print("Device: %s (%s)\n", device_get_alias(device_obj, &error), device_get_address(device_obj, &error));
-
+
if(error)
{
g_critical("Failed to get remote device's MAC address: %s", error->message);
g_error_free(error);
}
-
+
g_object_unref(device_obj);
-
+
/* Try to use found PIN */
- if (pin != NULL)
+ if (pin != NULL)
{
guint32 passkey_t;
sscanf(pin, "%u", &passkey_t);
-
+
if (g_strcmp0(pin, "*") == 0 || passkey_t == passkey)
{
if (_interactive)
@@ -216,7 +216,7 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar
}
else
g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Passkey does not match");
-
+
return;
}
else if (_interactive)
@@ -232,7 +232,7 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar
g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Passkey does not match");
return;
}
-
+
g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Passkey does not match");
}
else if (g_strcmp0(method_name, "RequestPasskey") == 0)
@@ -241,38 +241,46 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar
Device *device_obj = device_new(g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL));
const gchar *pin = _find_device_pin(device_get_dbus_object_path(device_obj));
guint32 ret = 0;
-
+ gboolean invoke = FALSE;
+
if (_interactive)
g_print("Device: %s (%s)\n", device_get_alias(device_obj, &error), device_get_address(device_obj, &error));
-
+
if(error)
{
g_critical("Failed to get remote device's MAC address: %s", error->message);
g_error_free(error);
}
-
+
g_object_unref(device_obj);
-
+
/* Try to use found PIN */
- if (pin != NULL)
+ if (pin != NULL)
{
if (_interactive)
g_print("Passkey found\n");
sscanf(pin, "%u", &ret);
- g_dbus_method_invocation_return_value(invocation, g_variant_new_uint32(ret));
- return;
- }
+ invoke = TRUE;
+ }
else if (_interactive)
{
g_print("Enter passkey: ");
errno = 0;
if (scanf("%u", &ret) == EOF && errno)
g_warning("%s\n", strerror(errno));
- g_dbus_method_invocation_return_value(invocation, g_variant_new_uint32(ret));
- return;
- }
-
- g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "No passkey inputted");
+ invoke = TRUE;
+ }
+
+ if (invoke)
+ {
+ GVariant* vars[1];
+ vars[0] = g_variant_new_uint32(ret);
+ g_dbus_method_invocation_return_value(invocation, g_variant_new_tuple(vars, 1));
+ }
+ else
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "No passkey inputted");
+ }
}
else if (g_strcmp0(method_name, "RequestPinCode") == 0)
{
@@ -280,40 +288,46 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar
Device *device_obj = device_new(g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL));
const gchar *pin = _find_device_pin(device_get_dbus_object_path(device_obj));
const gchar ret[16];
-
+ gboolean invoke = FALSE;
+
if (_interactive)
g_print("Device: %s (%s)\n", device_get_alias(device_obj, &error), device_get_address(device_obj, &error));
-
+
if(error)
{
g_critical("Failed to get remote device's MAC address: %s", error->message);
g_error_free(error);
}
-
+
g_object_unref(device_obj);
-
+
/* Try to use found PIN */
- if (pin != NULL)
+ if (pin != NULL)
{
if (_interactive)
g_print("Passkey found\n");
sscanf(pin, "%s", &ret);
- g_dbus_method_invocation_return_value(invocation, g_variant_new_string(ret));
- return;
- }
+ invoke = TRUE;
+ }
else if (_interactive)
{
g_print("Enter passkey: ");
errno = 0;
if (scanf("%s", &ret) == EOF && errno)
g_warning("%s\n", strerror(errno));
+ invoke = TRUE;
+ }
+
+ if (invoke)
+ {
GVariant* vars[1];
vars[0] = g_variant_new_string(ret);
g_dbus_method_invocation_return_value(invocation, g_variant_new_tuple(vars, 1));
- return;
- }
-
- g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "No passkey inputted");
+ }
+ else
+ {
+ g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "No passkey inputted");
+ }
}
}
@@ -351,14 +365,14 @@ void register_agent_callbacks(gboolean interactive_console, GHashTable *pin_dict
{
GDBusInterfaceVTable bt_agent_table;
memset(&bt_agent_table, 0x0, sizeof(bt_agent_table));
-
+
if(pin_dictonary)
_pin_hash_table = pin_dictonary;
if(main_loop_object)
_mainloop = (GMainLoop *) main_loop_object;
-
+
_interactive = interactive_console;
-
+
GDBusNodeInfo *bt_agent_node_info = g_dbus_node_info_new_for_xml(_bt_agent_introspect_xml, error);
GDBusInterfaceInfo *bt_agent_interface_info = g_dbus_node_info_lookup_interface(bt_agent_node_info, AGENT_DBUS_INTERFACE);
bt_agent_table.method_call = _bt_agent_method_call_func;
@@ -370,4 +384,4 @@ void unregister_agent_callbacks(GError **error)
{
if (_bt_agent_registration_id)
g_dbus_connection_unregister_object(g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error), _bt_agent_registration_id);
-} \ No newline at end of file
+}