diff options
author | gitjackolantern <scottjconover@yahoo.com> | 2016-12-12 00:17:44 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-12 00:17:44 -0800 |
commit | 32a06d6429a7c913b74d3d3e30653d52294aee02 (patch) | |
tree | 1286b0922facd66e43768192e35094b7f466ef23 | |
parent | 193ad6bb3db7ed2ba6b93c1ab4e1e592985e5b90 (diff) | |
parent | 6f03a321a7624b98095fbf32699d64ca3697ad34 (diff) | |
download | bluez-tools-32a06d6429a7c913b74d3d3e30653d52294aee02.tar.gz |
Merge pull request #9 from hadess/master
Bug fixes, and AuthorizeService implementation
-rwxr-xr-x | autogen.sh | 1 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/bt-adapter.c | 2 | ||||
-rw-r--r-- | src/bt-agent.c | 46 | ||||
-rw-r--r-- | src/bt-obex.c | 2 | ||||
-rw-r--r-- | src/lib/agent-helper.c | 48 | ||||
-rw-r--r-- | src/lib/helpers.c | 1 | ||||
-rw-r--r-- | src/lib/obex_agent.c | 4 |
8 files changed, 68 insertions, 38 deletions
@@ -1,3 +1,4 @@ #!/bin/sh autoreconf --force --install --verbose +./configure "$@" diff --git a/configure.ac b/configure.ac index 6211624..789140f 100644 --- a/configure.ac +++ b/configure.ac @@ -38,7 +38,7 @@ AC_HEADER_STDC # Check for the availability of dbus and glib libs PKG_PROG_PKG_CONFIG -PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.24.0]) +PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.36.0]) PKG_CHECK_MODULES([GIO], [gio-2.0 >= 2.26.0 gio-unix-2.0 >= 2.26.0]) # Check for the availability of libreadline diff --git a/src/bt-adapter.c b/src/bt-adapter.c index 179e6e1..37a46f6 100644 --- a/src/bt-adapter.c +++ b/src/bt-adapter.c @@ -109,7 +109,7 @@ int main(int argc, char *argv[]) "Set Options:\n" " --set <property> <value>\n" " Where `property` is one of:\n" - " Name\n" + " Alias\n" " Discoverable\n" " DiscoverableTimeout\n" " Pairable\n" diff --git a/src/bt-agent.c b/src/bt-agent.c index feabaa6..95c069c 100644 --- a/src/bt-agent.c +++ b/src/bt-agent.c @@ -35,6 +35,7 @@ #include <glib.h> #include <glib/gstdio.h> #include <gio/gio.h> +#include <glib-unix.h> #include "lib/dbus-common.h" #include "lib/helpers.h" @@ -126,21 +127,28 @@ static void _read_pin_file(const gchar *filename, GHashTable *pin_hash_table, gb return; } -static void signal_handler(int sig) +static gboolean +usr1_signal_handler(gpointer data) { - g_message("%s received", sig == SIGTERM ? "SIGTERM" : (sig == SIGUSR1 ? "SIGUSR1" : "SIGINT")); + g_message("SIGUSR1 received"); - if (sig == SIGUSR1 && pin_arg) - { - /* Re-read PIN's file */ - g_print("Re-reading PIN's file\n"); - _read_pin_file(pin_arg, pin_hash_table, FALSE); - } - else if (sig == SIGTERM || sig == SIGINT) - { - if (g_main_loop_is_running(mainloop)) - g_main_loop_quit(mainloop); - } + if (!pin_arg) + return G_SOURCE_CONTINUE; + + /* Re-read PIN's file */ + g_print("Re-reading PIN's file\n"); + _read_pin_file(pin_arg, pin_hash_table, FALSE); + + return G_SOURCE_CONTINUE; +} + +static gboolean +term_signal_handler(gpointer data) +{ + if (g_main_loop_is_running(mainloop)) + g_main_loop_quit(mainloop); + + return G_SOURCE_REMOVE; } static gchar *capability_arg = NULL; @@ -266,12 +274,9 @@ int main(int argc, char *argv[]) } /* Add SIGTERM/SIGINT/SIGUSR1 handlers */ - struct sigaction sa; - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = signal_handler; - sigaction(SIGTERM, &sa, NULL); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGUSR1, &sa, NULL); + g_unix_signal_add (SIGTERM, usr1_signal_handler, NULL); + g_unix_signal_add (SIGINT, term_signal_handler, NULL); + g_unix_signal_add (SIGUSR1, term_signal_handler, NULL); g_main_loop_run(mainloop); @@ -279,9 +284,6 @@ int main(int argc, char *argv[]) g_print("unregistering agent...\n"); agent_manager_unregister_agent(agent_manager, AGENT_PATH, &error); exit_if_error(error); - - /* Waiting for AgentReleased signal */ - g_main_loop_run(mainloop); } g_main_loop_unref(mainloop); diff --git a/src/bt-obex.c b/src/bt-obex.c index 6bcdce1..a7058d3 100644 --- a/src/bt-obex.c +++ b/src/bt-obex.c @@ -803,7 +803,7 @@ int main(int argc, char *argv[]) // DO NOT FREE THIS GVariant *el = g_ptr_array_index(folders, i); g_print( - "%s\t%llu\t%s\n", + "%s\t%" G_GINT64_FORMAT"\t%s\n", g_variant_get_string(g_variant_lookup_value(el, "Type", G_VARIANT_TYPE("s")), NULL), g_variant_get_uint64(g_variant_lookup_value(el, "Size", G_VARIANT_TYPE("t"))), g_variant_get_string(g_variant_lookup_value(el, "Name", G_VARIANT_TYPE("s")), NULL) diff --git a/src/lib/agent-helper.c b/src/lib/agent-helper.c index a4d1a04..bf50bcc 100644 --- a/src/lib/agent-helper.c +++ b/src/lib/agent-helper.c @@ -29,6 +29,7 @@ #include <gio/gio.h> #include <glib.h> #include <string.h> +#include <stdlib.h> #include "agent-helper.h" @@ -48,8 +49,34 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar if (g_strcmp0(method_name, "AuthorizeService") == 0) { - // Return void - g_dbus_method_invocation_return_value(invocation, NULL); + GError *error = NULL; + Device *device_obj = device_new(g_variant_get_string(g_variant_get_child_value(parameters, 0), NULL)); + const char *uuid = g_variant_get_string(g_variant_get_child_value(parameters, 1), NULL); + + if (_interactive) + g_print("Device: %s (%s) for UUID %s\n", device_get_alias(device_obj, &error), device_get_address(device_obj, &error), uuid); + + if (error) + { + g_critical("Failed to get remote device's MAC address: %s", error->message); + g_error_free(error); + g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Internal error occurred"); + return; + } + + if (device_get_paired (device_obj, &error)) + { + g_dbus_method_invocation_return_value(invocation, NULL); + } + else if (error) + { + g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Internal error occurred"); + g_error_free (error); + } + else + { + g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "Service authorization rejected"); + } } else if (g_strcmp0(method_name, "Cancel") == 0) { @@ -273,9 +300,7 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar 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)); + g_dbus_method_invocation_return_value(invocation, g_variant_new ("(u)", ret)); } else { @@ -287,7 +312,7 @@ 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)); - const gchar ret[16]; + gchar *ret = NULL; gboolean invoke = FALSE; if (_interactive) @@ -306,28 +331,29 @@ static void _bt_agent_method_call_func(GDBusConnection *connection, const gchar { if (_interactive) g_print("Passkey found\n"); - sscanf(pin, "%s", &ret); + sscanf(pin, "%ms", &ret); invoke = TRUE; } else if (_interactive) { g_print("Enter passkey: "); errno = 0; - if (scanf("%s", &ret) == EOF && errno) + if (scanf("%ms", &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)); + g_dbus_method_invocation_return_value(invocation, g_variant_new ("(s)", ret)); } else { g_dbus_method_invocation_return_dbus_error(invocation, "org.bluez.Error.Rejected", "No passkey inputted"); } + + if (ret) + free(ret); } } diff --git a/src/lib/helpers.c b/src/lib/helpers.c index 7402807..bc4c4fd 100644 --- a/src/lib/helpers.c +++ b/src/lib/helpers.c @@ -33,6 +33,7 @@ #include <gio/gio.h> #include <glib.h> +#include <glib/gstdio.h> #include "dbus-common.h" #include "helpers.h" diff --git a/src/lib/obex_agent.c b/src/lib/obex_agent.c index b539a77..1325bc8 100644 --- a/src/lib/obex_agent.c +++ b/src/lib/obex_agent.c @@ -121,7 +121,7 @@ static void obex_agent_class_init(ObexAgentClass *klass) } /* boolean AutoAccept [readwrite, construct only] */ - pspec = g_param_spec_boolean("AutoAccept", "auto_accept", "Automatically accept incoming files", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + pspec = g_param_spec_boolean("AutoAccept", "auto_accept", "Automatically accept incoming files", FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property(gobject_class, PROP_AUTO_ACCPET, pspec); if (pspec) @@ -211,7 +211,7 @@ static void _obex_agent_method_call_func(GDBusConnection *connection, const gcha ObexTransfer *transfer_t = obex_transfer_new(transfer); g_print("[Transfer Request]\n"); g_print(" Name: %s\n", obex_transfer_get_name(transfer_t, NULL)); - g_print(" Size: %llu bytes\n", obex_transfer_get_size(transfer_t, NULL)); + g_print(" Size: %" G_GINT64_FORMAT " bytes\n", obex_transfer_get_size(transfer_t, NULL)); // Filename seems to be always NULL // g_print(" Filename: %s\n", obex_transfer_get_filename(transfer_t, NULL)); const gchar *filename = obex_transfer_get_name(transfer_t, NULL); |