5 * Copyright (C) 2007-2010 Nokia Corporation
6 * Copyright (C) 2007-2010 Marcel Holtmann <marcel@holtmann.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
42 #include "filesystem.h"
44 #define VCARD_TYPE "text/x-vcard"
45 #define VCARD_FILE CONFIGDIR "/vcard.vcf"
48 #define OPP_RECORD "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> \
50 <attribute id=\"0x0001\"> \
52 <uuid value=\"0x1105\"/> \
56 <attribute id=\"0x0004\"> \
59 <uuid value=\"0x0100\"/> \
62 <uuid value=\"0x0003\"/> \
63 <uint8 value=\"%u\" name=\"channel\"/> \
66 <uuid value=\"0x0008\"/> \
71 <attribute id=\"0x0009\"> \
74 <uuid value=\"0x1105\"/> \
75 <uint16 value=\"0x0102\" name=\"version\"/> \
80 <attribute id=\"0x0100\"> \
81 <text value=\"%s\" name=\"name\"/> \
84 <attribute id=\"0x0303\"> \
86 <uint8 value=\"0x01\"/> \
87 <uint8 value=\"0x02\"/> \
88 <uint8 value=\"0x03\"/> \
89 <uint8 value=\"0x04\"/> \
90 <uint8 value=\"0x05\"/> \
91 <uint8 value=\"0x06\"/> \
92 <uint8 value=\"0xff\"/> \
95 <attribute id=\"0x0200\"> \
96 <uint16 value=\"%u\" name=\"psm\"/> \
100 static void *opp_connect(struct obex_session *os, int *err)
102 manager_register_transfer(os);
110 static void opp_progress(struct obex_session *os, void *user_data)
112 manager_emit_transfer_progress(os);
115 static int opp_chkput(struct obex_session *os, void *user_data)
117 char *folder, *name, *path;
122 if (obex_get_size(os) == OBJECT_SIZE_DELETE)
125 t = obex_get_name(os);
126 if (t != NULL && !is_filename(t))
129 if (obex_option_auto_accept()) {
130 folder = g_strdup(obex_option_root_folder());
131 name = g_strdup(obex_get_name(os));
136 err = manager_request_authorization(os, time, &folder, &name);
141 folder = g_strdup(obex_option_root_folder());
144 name = g_strdup(obex_get_name(os));
147 if (name == NULL || strlen(name) == 0) {
152 if (g_strcmp0(name, obex_get_name(os)) != 0)
153 obex_set_name(os, name);
155 path = g_build_filename(folder, name, NULL);
157 err = obex_put_stream_start(os, path);
164 manager_emit_transfer_started(os);
173 static int opp_put(struct obex_session *os, void *user_data)
175 const char *name = obex_get_name(os);
176 const char *folder = obex_option_root_folder();
187 static int opp_get(struct obex_session *os, void *user_data)
191 if (obex_get_name(os))
194 type = obex_get_type(os);
199 if (g_ascii_strcasecmp(type, VCARD_TYPE) == 0) {
200 if (obex_get_stream_start(os, VCARD_FILE) < 0)
209 static void opp_disconnect(struct obex_session *os, void *user_data)
211 manager_unregister_transfer(os);
214 static void opp_reset(struct obex_session *os, void *user_data)
216 manager_emit_transfer_completed(os);
219 static struct obex_service_driver driver = {
220 .name = "Object Push server",
222 .channel = OPP_CHANNEL,
223 .port = OBEX_PORT_RANDOM,
224 .record = OPP_RECORD,
225 .connect = opp_connect,
226 .progress = opp_progress,
227 .disconnect = opp_disconnect,
230 .chkput = opp_chkput,
234 static int opp_init(void)
236 return obex_service_driver_register(&driver);
239 static void opp_exit(void)
241 obex_service_driver_unregister(&driver);
244 OBEX_PLUGIN_DEFINE(opp, opp_init, opp_exit)