~ubuntu-branches/ubuntu/karmic/gnome-user-share/karmic

« back to all changes in this revision

Viewing changes to src/obexftp.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2008-04-18 12:42:37 UTC
  • mfrom: (1.1.8 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080418124237-t3gk3ftrzpkl3wwv
Tags: 0.31-3
* debian/preinst:
  + Remove obsolete conffile.
* debian/01_apache-config.patch:
  + Fix apache config even more.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
 
2
 
 
3
/*
 
4
 *  Copyright (C) 2004-2008 Red Hat, Inc.
 
5
 *
 
6
 *  Nautilus is free software; you can redistribute it and/or
 
7
 *  modify it under the terms of the GNU General Public License as
 
8
 *  published by the Free Software Foundation; either version 2 of the
 
9
 *  License, or (at your option) any later version.
 
10
 *
 
11
 *  Nautilus is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 *  General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 *
 
20
 *  Authors: Bastien Nocera <hadess@hadess.net>
 
21
 *
 
22
 */
 
23
 
 
24
#include "config.h"
 
25
 
 
26
#include <dbus/dbus-glib.h>
 
27
#include <dbus/dbus-glib-lowlevel.h>
 
28
#include <gconf/gconf-client.h>
 
29
 
 
30
#include <string.h>
 
31
 
 
32
#include "obexftp.h"
 
33
#include "user_share.h"
 
34
#include "user_share-private.h"
 
35
 
 
36
static DBusGConnection *connection = NULL;
 
37
static DBusGProxy *manager_proxy = NULL;
 
38
static DBusGProxy *server_proxy = NULL;
 
39
 
 
40
void
 
41
obexftp_up (void)
 
42
{
 
43
        GError *err = NULL;
 
44
        GConfClient *client;
 
45
        char *public_dir, *server;
 
46
        gboolean allow_write, require_pairing;
 
47
 
 
48
        client = gconf_client_get_default ();
 
49
        require_pairing = gconf_client_get_bool (client, FILE_SHARING_BLUETOOTH_REQUIRE_PAIRING, NULL);
 
50
 
 
51
        server = NULL;
 
52
        if (manager_proxy == NULL) {
 
53
                manager_proxy = dbus_g_proxy_new_for_name (connection,
 
54
                                                           "org.openobex",
 
55
                                                           "/org/openobex",
 
56
                                                           "org.openobex.Manager");
 
57
                if (dbus_g_proxy_call (manager_proxy, "CreateBluetoothServer",
 
58
                                       &err, G_TYPE_STRING, "00:00:00:00:00:00", G_TYPE_STRING, "ftp", G_TYPE_BOOLEAN, require_pairing, G_TYPE_INVALID,
 
59
                                       DBUS_TYPE_G_OBJECT_PATH, &server, G_TYPE_INVALID) == FALSE) {
 
60
                        g_printerr ("Creating Bluetooth ObexFTP server failed: %s\n",
 
61
                                    err->message);
 
62
                        g_error_free (err);
 
63
                        g_object_unref (manager_proxy);
 
64
                        manager_proxy = NULL;
 
65
                        return;
 
66
                }
 
67
        }
 
68
 
 
69
        public_dir = lookup_public_dir ();
 
70
        allow_write = gconf_client_get_bool (client, FILE_SHARING_BLUETOOTH_ALLOW_WRITE, NULL);
 
71
        g_object_unref (client);
 
72
 
 
73
        if (server_proxy == NULL) {
 
74
                server_proxy = dbus_g_proxy_new_for_name (connection,
 
75
                                                           "org.openobex",
 
76
                                                           server,
 
77
                                                           "org.openobex.Server");
 
78
                g_free (server);
 
79
        }
 
80
        if (dbus_g_proxy_call (server_proxy, "Start", &err,
 
81
                           G_TYPE_STRING, public_dir, G_TYPE_BOOLEAN, allow_write, G_TYPE_BOOLEAN, TRUE, G_TYPE_INVALID,
 
82
                           G_TYPE_INVALID) == FALSE) {
 
83
                g_printerr ("Starting Bluetooth ObexFTP server failed: %s\n",
 
84
                            err->message);
 
85
                g_error_free (err);
 
86
                g_free (public_dir);
 
87
                g_object_unref (server_proxy);
 
88
                server_proxy = NULL;
 
89
                g_object_unref (manager_proxy);
 
90
                manager_proxy = NULL;
 
91
                return;
 
92
        }
 
93
 
 
94
        g_free (public_dir);
 
95
}
 
96
 
 
97
static void
 
98
obexftp_stop (gboolean stop_manager)
 
99
{
 
100
        GError *err = NULL;
 
101
 
 
102
        if (server_proxy == NULL)
 
103
                return;
 
104
 
 
105
        if (dbus_g_proxy_call (server_proxy, "Close", &err, G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
 
106
                const gchar *error_name = NULL;
 
107
 
 
108
                if (err != NULL && err->code == DBUS_GERROR_REMOTE_EXCEPTION)
 
109
                        error_name = dbus_g_error_get_name (err);
 
110
                if (error_name == NULL ||
 
111
                    (error_name != NULL && strcmp (error_name, "org.openobex.Error.NotStarted") != 0)) {
 
112
                        g_printerr ("Stopping Bluetooth ObexFTP server failed: %s\n",
 
113
                                    err->message);
 
114
                        g_error_free (err);
 
115
                        return;
 
116
                }
 
117
                g_error_free (err);
 
118
        }
 
119
 
 
120
        if (stop_manager != FALSE) {
 
121
                g_object_unref (server_proxy);
 
122
                server_proxy = NULL;
 
123
                g_object_unref (manager_proxy);
 
124
                manager_proxy = NULL;
 
125
        }
 
126
}
 
127
 
 
128
void
 
129
obexftp_down (void)
 
130
{
 
131
        obexftp_stop (TRUE);
 
132
}
 
133
 
 
134
void
 
135
obexftp_restart (void)
 
136
{
 
137
        obexftp_stop (FALSE);
 
138
        obexftp_up ();
 
139
}
 
140
 
 
141
gboolean
 
142
obexftp_init (void)
 
143
{
 
144
        GError *err = NULL;
 
145
 
 
146
        connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err);
 
147
        if (connection == NULL) {
 
148
                g_printerr ("Connecting to session bus failed: %s\n",
 
149
                            err->message);
 
150
                g_error_free (err);
 
151
                return FALSE;
 
152
        }
 
153
 
 
154
        dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE);
 
155
        return TRUE;
 
156
}
 
157