1 /*********************************************************************
3 * Filename: obex_common.c
5 * Description: Utility-functions to act as a PUT server and client
6 * Status: Experimental.
7 * Author: Pontus Fuchs <pontus.fuchs@tactel.se>
8 * Created at: Sat Nov 20 10:54:14 1999
9 * Modified at: Sun Aug 13 01:54:05 PM CEST 2000
10 * Modified by: Pontus Fuchs <pontus.fuchs@tactel.se>
11 * Modified at: Sun Oct 06 10:00:00 2001
12 * Modified by: Ben Moore <ben@netjunki.org>
14 * Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 ********************************************************************/
36 #include <openobex/obex.h>
37 #include "obex_put_common.h"
39 #include "wmcapshare.h"
41 extern obex_t
*handle
;
42 extern volatile int finished
;
43 extern volatile int state
;
44 extern gchar
*savedir
; /*= "/home/bento/Work/Capture/";*/
47 volatile int last_rsp
= OBEX_RSP_BAD_REQUEST
;
52 * Parse what we got from a PUT
55 void put_done(obex_object_t
*object
)
61 const guint8
*body
= NULL
;
64 gchar
*namebuf
= NULL
;
66 while(OBEX_ObjectGetNextHeader(handle
, object
, &hi
, &hv
, &hlen
)) {
73 if( (namebuf
= g_malloc(hlen
/ 2))) {
74 OBEX_UnicodeToChar(namebuf
, hv
.bs
, hlen
);
80 g_print("HEADER_LENGTH = %d\n", hv
.bq4
);
83 case HEADER_CREATOR_ID
:
84 g_print("CREATORID = %#x\n", hv
.bq4
);
88 g_print(G_GNUC_FUNCTION
"() Skipped header %02x\n", hi
);
92 g_print("Got a PUT without a body\n");
96 g_print("Got a PUT without a name. Setting name to %s\n", name
);
97 name
= "OBEX_PUT_Unknown_object";
100 safe_save_file(name
, body
, body_len
, savedir
);
106 * Function server_indication()
108 * Called when a request is about to come or has come.
111 void server_request(obex_object_t
*object
, gint event
, gint cmd
)
114 case OBEX_CMD_SETPATH
:
115 g_print("Received SETPATH command\n");
116 OBEX_ObjectSetRsp(object
, OBEX_RSP_CONTINUE
, OBEX_RSP_SUCCESS
);
119 OBEX_ObjectSetRsp(object
, OBEX_RSP_CONTINUE
, OBEX_RSP_SUCCESS
);
122 case OBEX_CMD_CONNECT
:
123 OBEX_ObjectSetRsp(object
, OBEX_RSP_SUCCESS
, OBEX_RSP_SUCCESS
);
125 case OBEX_CMD_DISCONNECT
:
126 OBEX_ObjectSetRsp(object
, OBEX_RSP_SUCCESS
, OBEX_RSP_SUCCESS
);
129 g_print(G_GNUC_FUNCTION
"() Denied %02x request\n", cmd
);
130 OBEX_ObjectSetRsp(object
, OBEX_RSP_NOT_IMPLEMENTED
, OBEX_RSP_NOT_IMPLEMENTED
);
137 * Function client_done_indication()
139 * Called when a server-operation has finished
142 void server_done(obex_object_t
*object
, gint obex_cmd
)
144 /* Quit if DISCONNECT has finished */
145 if(obex_cmd
== OBEX_CMD_DISCONNECT
)
151 * Function client_done()
153 * Called when a client-operation has finished
156 void client_done(obex_object_t
*object
, gint obex_cmd
, gint obex_rsp
)
163 * Function obex_event ()
165 * Called by the obex-layer when some event occurs.
168 void obex_event(obex_t
*handle
, obex_object_t
*object
, gint mode
, gint event
, gint obex_cmd
, gint obex_rsp
)
171 case OBEX_EV_PROGRESS
:
175 case OBEX_EV_REQDONE
:
177 /* Comes when a command has finished. */
178 if(mode
== OBEX_CLIENT
)
179 client_done(object
, obex_cmd
, obex_rsp
);
181 server_done(object
, obex_cmd
);
183 case OBEX_EV_REQHINT
:
184 /* Comes BEFORE the lib parses anything. */
190 OBEX_ObjectSetRsp(object
, OBEX_RSP_CONTINUE
, OBEX_RSP_SUCCESS
);
192 case OBEX_CMD_CONNECT
:
193 g_print("connect\n");
196 OBEX_ObjectSetRsp(object
, OBEX_RSP_CONTINUE
, OBEX_RSP_SUCCESS
);
198 case OBEX_CMD_DISCONNECT
:
199 g_print("disconnect\n");
202 OBEX_ObjectSetRsp(object
, OBEX_RSP_CONTINUE
, OBEX_RSP_SUCCESS
);
205 OBEX_ObjectSetRsp(object
, OBEX_RSP_NOT_IMPLEMENTED
, OBEX_RSP_NOT_IMPLEMENTED
);
210 /* Comes when a server-request has been received. */
211 g_print("server request\n");
212 server_request(object
, event
, obex_cmd
);
214 case OBEX_EV_LINKERR
:
215 g_print("Link broken (this does not have to be an error)!\n");
219 g_print("Unknown event!\n");
225 * Function wait_for_rsp()
227 * Wait for a request to finish!
235 ret
= OBEX_HandleInput(handle
, 1);
243 * Function do_sync_request()
245 * Execute an OBEX-request synchronously.
248 int do_sync_request(obex_t
*handle
, obex_object_t
*object
, gint async
)
251 OBEX_Request(handle
, object
);
252 ret
= wait_for_rsp();