Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add property to automatically accept incoming files #3

Merged
merged 1 commit into from
Sep 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/bt-obex.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ void _agent_approved_callback(ObexAgent *obex_agent, const gchar* obex_transfer_
/* Main arguments */
static gchar *adapter_arg = NULL;
static gboolean server_arg = FALSE;
static gboolean auto_accept = FALSE;
static gchar *server_path_arg = NULL;
static gboolean opp_arg = FALSE;
static gchar *opp_device_arg = NULL;
Expand All @@ -386,6 +387,7 @@ static gchar *ftp_arg = NULL;
static GOptionEntry entries[] = {
{"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter name or MAC", "<name|mac>"},
{"server", 's', 0, G_OPTION_ARG_NONE, &server_arg, "Register self at OBEX server", NULL},
{"auto-accept", 'y', 0, G_OPTION_ARG_NONE, &auto_accept, "Automatically accept incoming files", NULL},
{"opp", 'p', 0, G_OPTION_ARG_NONE, &opp_arg, "Send file to remote device", NULL},
{"ftp", 'f', 0, G_OPTION_ARG_STRING, &ftp_arg, "Start FTP session with remote device", "<name|mac>"},
{NULL}
Expand Down Expand Up @@ -496,7 +498,7 @@ int main(int argc, char *argv[])
guint obex_server_object_id = g_dbus_connection_signal_subscribe(session_conn, "org.bluez.obex", "org.freedesktop.DBus.ObjectManager", NULL, NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, _obex_server_object_manager_handler, NULL, NULL);
guint obex_server_properties_id = g_dbus_connection_signal_subscribe(session_conn, "org.bluez.obex", "org.freedesktop.DBus.Properties", "PropertiesChanged", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE, _obex_server_properties_handler, NULL, NULL);

ObexAgent *agent = obex_agent_new(root_folder);
ObexAgent *agent = obex_agent_new(root_folder, auto_accept);
_root_path = g_strdup(root_folder);
g_free(root_folder);
obex_agent_set_approved_callback(agent, _agent_approved_callback, NULL);
Expand Down
42 changes: 33 additions & 9 deletions src/lib/obex_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

struct _ObexAgentPrivate {
gchar *root_folder;
gboolean auto_accept;
gchar *current_name;
guint registration_id;
void (*agent_released_callback)(ObexAgent *, gpointer);
Expand All @@ -54,6 +55,7 @@ G_DEFINE_TYPE_WITH_PRIVATE(ObexAgent, obex_agent, G_TYPE_OBJECT);
enum {
PROP_0,
PROP_ROOT_FOLDER, /* readwrite, construct only */
PROP_AUTO_ACCPET, /* readwrite, construct only */
};

static const gchar *_obex_agent_introspect_xml = "<node name=\"/org/blueztools/obex\">\n\t<interface name=\"org.bluez.obex.Agent1\">\n\t\t<method name=\"Release\">\n\t\t</method>\n\t\t<method name=\"AuthorizePush\">\n\t\t\t<arg name=\"transfer\" direction=\"in\" type=\"o\"/>\n\t\t\t<arg name=\"filepath\" direction=\"out\" type=\"s\"/>\n\t\t</method>\n\t\t<method name=\"Cancel\">\n\t\t</method>\n\t</interface>\n</node>\n";
Expand Down Expand Up @@ -112,7 +114,16 @@ static void obex_agent_class_init(ObexAgentClass *klass)
/* string RootFolder [readwrite, construct only] */
pspec = g_param_spec_string("RootFolder", "root_folder", "Root folder location", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property(gobject_class, PROP_ROOT_FOLDER, pspec);


if (pspec) {
g_param_spec_unref(pspec);
pspec = NULL;
}

/* 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);
g_object_class_install_property(gobject_class, PROP_AUTO_ACCPET, pspec);

if (pspec)
g_param_spec_unref(pspec);
}
Expand All @@ -127,6 +138,7 @@ static void obex_agent_init(ObexAgent *self)
self->priv->user_data = NULL;
self->priv->agent_approved_callback = NULL;
self->priv->approved_user_data = NULL;
self->priv->auto_accept = FALSE;

GError *error = NULL;
GDBusInterfaceVTable obex_agent_table;
Expand All @@ -151,6 +163,10 @@ static void _obex_agent_get_property(GObject *object, guint property_id, GValue
g_value_set_string(value, self->priv->root_folder);
break;

case PROP_AUTO_ACCPET:
g_value_set_boolean(value, self->priv->auto_accept);
break;

default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
Expand All @@ -166,16 +182,20 @@ static void _obex_agent_set_property(GObject *object, guint property_id, const G
self->priv->root_folder = g_value_dup_string(value);
break;

case PROP_AUTO_ACCPET:
self->priv->auto_accept = g_value_get_boolean(value);
break;

default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
}
}

/* Constructor */
ObexAgent *obex_agent_new(const gchar *root_folder)
ObexAgent *obex_agent_new(const gchar *root_folder, const gboolean auto_accept)
{
return g_object_new(OBEX_AGENT_TYPE, "RootFolder", root_folder, NULL);
return g_object_new(OBEX_AGENT_TYPE, "RootFolder", root_folder, "AutoAccept", auto_accept, NULL);
}
/* Methods */
static void _obex_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)
Expand All @@ -199,12 +219,16 @@ static void _obex_agent_method_call_func(GDBusConnection *connection, const gcha
g_object_unref(transfer_t);

gchar yn[4] = {0,};
g_print("Accept (yes/no)? ");
errno = 0;
if (scanf("%3s", yn) == EOF && errno)
{
g_warning("%s\n", strerror(errno));
}
if (TRUE == self->priv->auto_accept)
yn[0] = 'y';
else {
g_print("Accept (yes/no)? ");
errno = 0;
if (scanf("%3s", yn) == EOF && errno)
{
g_warning("%s\n", strerror(errno));
}
}
if (g_strcmp0(yn, "y") == 0 || g_strcmp0(yn, "yes") == 0)
{
// IMPORTANT NOTE!
Expand Down
2 changes: 1 addition & 1 deletion src/lib/obex_agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ typedef void (*ObexAgentApprovedCallback)(ObexAgent *obex_agent, const gchar* ob
/*
* Constructor
*/
ObexAgent *obex_agent_new(const gchar *root_folder);
ObexAgent *obex_agent_new(const gchar *root_folder, const gboolean auto_accept);

/*
* Method definitions
Expand Down