~ubuntu-branches/ubuntu/trusty/obexd/trusty-proposed

« back to all changes in this revision

Viewing changes to plugins/syncevolution.c

  • Committer: Bazaar Package Importer
  • Author(s): Baptiste Mille-Mathias
  • Date: 2010-03-15 20:43:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100315204306-0jq3qj7q1jiybpxr
Tags: 0.22-0ubuntu1
* New upstream release (LP: #539914):
  - Fix file corruption during PUT operation. (LP: #421684]
  - Fix the response of PUT requests for PBAP.
  - Fix blocking while waiting capability script to exit.
  - Fix compilation issues with driver and plugin options.
  - Fix service driver selection when WHO header is informed.
  - Fix issue with PC-Suite WHO header.
  - Fix issue when mime type exists but is unknown.
  - Fix issue when opening file fails during SendFiles.
  - Fix error code response when there is no default vCard.
  - Fix a memory leak when opening a folder for listing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *
3
3
 *  OBEX Server
4
4
 *
5
 
 *  Copyright (C) 2007-2008  Intel Corporation
6
 
 *  Copyright (C) 2007-2009  Marcel Holtmann <marcel@holtmann.org>
 
5
 *  Copyright (C) 2007-2010  Intel Corporation
 
6
 *  Copyright (C) 2007-2010  Marcel Holtmann <marcel@holtmann.org>
7
7
 *
8
8
 *
9
9
 *  This program is free software; you can redistribute it and/or modify
43
43
#include "dbus.h"
44
44
#include "btio.h"
45
45
#include "obexd.h"
 
46
#include "gdbus.h"
46
47
 
47
48
#define SYNCML_TARGET_SIZE 11
48
49
 
85
86
#define SYNCE_SERVER_INTERFACE  "org.syncevolution.Server"
86
87
#define SYNCE_CONN_INTERFACE    "org.syncevolution.Connection"
87
88
 
88
 
static char match_string[256];
89
 
 
90
89
struct synce_context {
91
90
        struct obex_session *os;
92
91
        DBusConnection *dbus_conn;
93
92
        gchar *conn_obj;
94
93
        gboolean reply_received;
 
94
        guint reply_watch;
 
95
        guint abort_watch;
95
96
};
96
97
 
97
98
struct callback_data {
115
116
        return NULL;
116
117
}
117
118
 
118
 
static struct synce_context *find_context_by_conn_obj(const char *path)
119
 
{
120
 
        GSList *l;
121
 
 
122
 
        for (l = context_list; l != NULL; l = l->next) {
123
 
                struct synce_context *context = l->data;
124
 
 
125
 
                if (strcmp(context->conn_obj, path) == 0)
126
 
                        return context;
127
 
        }
128
 
 
129
 
        return NULL;
130
 
}
131
 
 
132
119
static void append_dict_entry(DBusMessageIter *dict, const char *key,
133
120
                                                        int type, void *val)
134
121
{
141
128
        dbus_message_iter_close_container(dict, &entry);
142
129
}
143
130
 
144
 
static void handle_connection_reply_signal(DBusMessage *msg,
145
 
                                const char *obj_path, void *data)
 
131
static gboolean reply_signal(DBusConnection *conn, DBusMessage *msg,
 
132
                                void *data)
146
133
{
147
134
        struct synce_context *context = data;
148
135
        struct obex_session *os = context->os;
 
136
        const char *path = dbus_message_get_path(msg);
149
137
        DBusMessageIter iter, array_iter;
150
138
        gchar *value;
151
139
        gint length;
152
140
 
153
 
        if (strcmp(context->conn_obj, obj_path) != 0)
154
 
                return;
 
141
        if (strcmp(context->conn_obj, path) != 0)
 
142
                return FALSE;
155
143
 
156
144
        dbus_message_iter_init(msg, &iter);
157
145
 
159
147
        dbus_message_iter_get_fixed_array(&array_iter, &value, &length);
160
148
 
161
149
        if (length == 0)
162
 
                return;
 
150
                return TRUE;
163
151
 
164
152
        os->buf = g_malloc(length);
165
153
        memcpy(os->buf, value, length);
167
155
        os->finished = TRUE;
168
156
        context->reply_received = TRUE;
169
157
        OBEX_ResumeRequest(os->obex);
 
158
 
 
159
        return TRUE;
170
160
}
171
161
 
172
 
static void handle_connection_abort_signal(DBusMessage *msg,
173
 
                                const char *obj_path, void *data)
 
162
static gboolean abort_signal(DBusConnection *conn, DBusMessage *msg,
 
163
                                void *data)
174
164
{
175
165
        struct synce_context *context = data;
176
166
        struct obex_session *os = context->os;
179
169
        os->finished = TRUE;
180
170
        OBEX_ResumeRequest(os->obex);
181
171
        OBEX_TransportDisconnect(os->obex);
182
 
}
183
 
 
184
 
static DBusHandlerResult signal_filter(DBusConnection *conn,
185
 
                                DBusMessage *msg, void *data)
186
 
{
187
 
        const char *path = dbus_message_get_path(msg);
188
 
        struct synce_context *context;
189
 
 
190
 
        if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
191
 
                return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
192
 
 
193
 
        context = find_context_by_conn_obj(path);
194
 
        if (!context)
195
 
                return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
196
 
 
197
 
        if (dbus_message_is_signal(msg, SYNCE_CONN_INTERFACE, "Reply")) {
198
 
                debug("Reply signal is received.");
199
 
                handle_connection_reply_signal(msg, path, context);
200
 
        } else if (dbus_message_is_signal(msg, SYNCE_CONN_INTERFACE, "Abort")) {
201
 
                debug("Abort signal is received.");
202
 
                handle_connection_abort_signal(msg, path, context);
203
 
        }
204
 
 
205
 
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 
172
 
 
173
        return TRUE;
206
174
}
207
175
 
208
176
static void connect_cb(DBusPendingCall *call, void *user_data)
209
177
{
210
 
        static gboolean signal_filter_added = FALSE;
211
178
        struct callback_data *cb_data = user_data;
212
179
        obex_t *obex = cb_data->obex;
213
180
        obex_object_t *obj = cb_data->obj;
240
207
        debug("Got conn object %s from syncevolution", path);
241
208
        context->conn_obj = g_strdup(path);
242
209
 
243
 
        /* add signal filter */
244
 
        if (!signal_filter_added) {
245
 
                if (!dbus_connection_add_filter(conn, signal_filter,
246
 
                                                        os, NULL)) {
247
 
                        error("Can't add signal filter");
248
 
                        dbus_message_unref(reply);
249
 
                        g_free(cb_data);
250
 
                        goto failed;
251
 
                }
252
 
                signal_filter_added = TRUE;
253
 
        }
 
210
        context->reply_watch = g_dbus_add_signal_watch(conn, NULL, path,
 
211
                                                SYNCE_CONN_INTERFACE, "Reply",
 
212
                                                reply_signal, context, NULL);
254
213
 
255
 
        snprintf(match_string, sizeof(match_string), "type=signal,interface=%s,"
256
 
                        "path=%s", SYNCE_CONN_INTERFACE, context->conn_obj);
257
 
        dbus_bus_add_match(conn, match_string, NULL);
258
 
        dbus_connection_flush(conn);
 
214
        context->abort_watch = g_dbus_add_signal_watch(conn, NULL, path,
 
215
                                                SYNCE_CONN_INTERFACE, "Abort",
 
216
                                                abort_signal, context, NULL);
259
217
 
260
218
        dbus_message_unref(reply);
261
219
        g_free(cb_data);
311
269
        struct callback_data *cb_data;
312
270
        struct synce_context *context;
313
271
 
314
 
        conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
 
272
        conn = obex_dbus_get_connection();
315
273
        if (!conn)
316
274
                goto failed;
317
275
 
507
465
        dbus_pending_call_unref(call);
508
466
 
509
467
failed:
510
 
        snprintf(match_string, sizeof(match_string),
511
 
                                "type=signal,interface=%s,path=%s",
512
 
                                SYNCE_CONN_INTERFACE, context->conn_obj);
513
 
        dbus_bus_remove_match(context->dbus_conn, match_string, NULL);
 
468
        g_dbus_remove_watch(context->dbus_conn, context->reply_watch);
 
469
        context->reply_watch = 0;
 
470
        g_dbus_remove_watch(context->dbus_conn, context->abort_watch);
 
471
        context->abort_watch = 0;
 
472
 
514
473
        g_free(context->conn_obj);
515
474
        context->conn_obj = NULL;
516
475