Commit Graph

205 Commits

Author SHA1 Message Date
Johan Hedberg
66a85a3191 gobex: Minor coding style (whitespace) fix 2015-07-08 12:38:01 +03:00
Marcel Holtmann
7bd86b5b9e gobex: Fix includes for gobex.h header 2015-03-01 00:27:37 -08:00
Szymon Janc
29bdc7df4c gobex: List all enum values in switch
As described in coding style M10.
2014-12-08 14:00:28 +01:00
Luiz Augusto von Dentz
31d69f8ecf gobex: Abort if there is no request to cancel
If there is no request to cancel send an abort since otherwise the remote
may hang waiting.
2014-08-29 10:32:27 +03:00
Luiz Augusto von Dentz
3ff1f6b5e8 gobex: Add g_obex_abort 2014-08-29 10:32:26 +03:00
Luiz Augusto von Dentz
82c524e4d0 gobex: Fix crash when debug is enabled
GError can be NULL thus causing invalid read when trying to a message
member such as bellow:

Invalid read of size 8
   at 0x41190F: g_obex_send_internal (gobex.c:531)
   by 0x4130A6: g_obex_send_req (gobex.c:756)
   by 0x4268A5: obc_session_unref (session.c:289)
   by 0x41396A: incoming_data (gobex.c:1397)
   by 0x59712A5: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3800.2)
   by 0x5971627: ??? (in /usr/lib64/libglib-2.0.so.0.3800.2)
   by 0x5971A39: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3800.2)
   by 0x40D78C: main (main.c:320)
 Address 0x0 is not stack'd, malloc'd or (recently) free'd
2014-08-29 10:32:26 +03:00
Luiz Augusto von Dentz
867ca173d6 gobex: Fix warning if g_obex_resume is called when disconnected 2014-08-29 10:32:26 +03:00
Andrei Emeltchenko
cfdb4b82de gobex: Fix use after free
Refactor function transfer_get_req_first() to avoid use after free.
2014-08-11 16:27:56 +03:00
Andrei Emeltchenko
4830f41e03 gobex: Fix use after free 2014-08-11 16:26:37 +03:00
Andrei Emeltchenko
662b5e4d57 gobex: Fix use after free
It is better not to dereference freed pointer
2014-08-11 16:26:09 +03:00
Andrei Emeltchenko
6df15b5415 gobex: Fix use after free
transfer_complete() frees transfer pointer.
2014-08-05 17:09:14 +03:00
Szymon Janc
87dc59894d gobex: Fix removing invalid source
Since GLib 2.39 calling g_source_remove on already removed source
is causing critical warning.

This was affecting unit/test-gobex-transfer when running with
GLib 2.40.

/gobex/test_packet_get_req_suspend_resume:
(./unit/test-gobex-transfer:28879): GLib-CRITICAL **: Source ID 263 was
    not found when attempting to remove it
Trace/breakpoint trap
2014-04-25 11:15:15 +03:00
Luiz Augusto von Dentz
021712264c gobex: Fix asserting one more time
This fixes a regression caused by 35938b779d
where the current pending_req is set to NULL while processing the
response but cause the request to timeout since it is no longer removed
properly.
2014-04-09 14:28:47 +03:00
Luiz Augusto von Dentz
35938b779d gobex: Fix being able to cancel completed requests
This fixes bogus responses when rsp_func calls g_obex_cancel_req for
responses with final bit set.
2014-04-08 16:27:49 +03:00
Luiz Augusto von Dentz
28ef9c48c2 gobex: Really fix assert this time 2014-04-02 16:48:43 +03:00
Luiz Augusto von Dentz
17e6a27958 gobex: Fix memory leak
This fixes the following leak introduced by the authentication patches:

16 bytes in 1 blocks are definitely lost in loss record 62 of 158
   at 0x4C291D4: calloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E7FEC6: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.3800.2)
   by 0x403226: prepare_auth_rsp.isra.4 (gobex.c:564)
   by 0x404DE4: handle_response (gobex.c:1015)
   by 0x405C7B: incoming_data (gobex.c:1351)
   by 0x4E7A2A5: g_main_context_dispatch (in
/usr/lib64/libglib-2.0.so.0.3800.2)
   by 0x4E7A627: ??? (in /usr/lib64/libglib-2.0.so.0.3800.2)
   by 0x4E7AA39: g_main_loop_run (in
/usr/lib64/libglib-2.0.so.0.3800.2)
   by 0x40DC34: test_auth (test-gobex.c:966)
   by 0x4E9E5E0: ??? (in /usr/lib64/libglib-2.0.so.0.3800.2)
   by 0x4E9E7A5: ??? (in /usr/lib64/libglib-2.0.so.0.3800.2)
   by 0x4E9EB1A: g_test_run_suite (in
/usr/lib64/libglib-2.0.so.0.3800.2)
2014-04-02 16:48:43 +03:00
Luiz Augusto von Dentz
ac93ba0e44 gobex: Fix asserting when resending connect request
In case connect requests needs to be resent to authenticate the timeout
handle should be removed otherwise it may end up asserting:

ERROR:gobex/gobex.c:251:req_timeout: assertion failed: (p != NULL)
2014-04-02 14:25:39 +03:00
Luiz Augusto von Dentz
774aae64e8 gobex: Respond to authentication challenge
This implements authentication response as defined in OBEX specification
since it is a mandatory feature for many Bluetooth profiles.
2014-03-31 17:30:59 +03:00
Luiz Augusto von Dentz
ab22fce6bb gobex/header: Add g_obex_header_new_tag function
This function can be used to set tag using GObexApparam as argument but
for arbritary headers.
2014-03-31 17:30:58 +03:00
Luiz Augusto von Dentz
c447292799 gobex: Add g_obex_disconnect
This adds g_obex_disconnect function which can be used to send OBEX
Disconnect command.
2014-03-21 16:13:45 +02:00
Luiz Augusto von Dentz
0246b2d6bd gobex/transfer: Keep request id for GET when SRM is active
In case a GET operation is in progress with SRM the same request id is
valid for the whole transfer otherwise it is not possible to cancel the
transfer after the first response.
2014-03-21 16:13:44 +02:00
Luiz Augusto von Dentz
4b873ec8af gobex: Fix not resetting SRM setup
If SRM is not confirmed by both ends the setup should be disregarded and
the data associated to it can be freed otherwise the next command may
reuse the same setup assuming it is still valid and probably cause SRM
to be enabled without remote consent.
2014-03-21 16:13:44 +02:00
Luiz Augusto von Dentz
8a0fb5f525 gobex: Handle suspending/resuming for GET when SRM is active
This adds support for suspending/resuming GET requests GET when SRM is
active, in this case suspending the TX queue wont stop the remote
to continue sending packets, to do that SRMP header should be set to wait
so the remote should wait.
2014-02-20 13:43:08 +02:00
Luiz Augusto von Dentz
7b43cc9e4f gobex: Fix not handling SRM properly
SRM can be enabled but while not active with use of SRMP header so the
handling of this states needs to be separated.
2014-02-20 13:43:08 +02:00
Luiz Augusto von Dentz
df65753b0a gobex: Revert g_obex_pending_req_abort to static pending_req_abort
This reverts the changes introduced in
9095deb825 that made pending_req_abort
public which is not necessary considering g_obex_cancel_req can do the
same and is safe to call even if the request is not pending.
2013-09-29 17:01:07 +03:00
Luiz Augusto von Dentz
c9f3b81d07 gobex: Fix crash on g_obex_pending_req_abort
It is not safe to call g_obex_pending_req_abort directly as pending_req
can be NULL:
Invalid read of size 4
   at 0x41231E: g_obex_pending_req_abort (gobex.c:693)
   by 0x416A8A: g_obex_cancel_transfer (gobex-transfer.c:647)
   by 0x42DEF2: obc_transfer_cancel (transfer.c:180)
   by 0x43D833: process_message.isra.5 (object.c:259)
   by 0x3B0701CE85: ??? (in /usr/lib64/libdbus-1.so.3.7.4)
   by 0x3B0700FA30: dbus_connection_dispatch (in /usr/lib64/libdbus-1.so.3.7.4)
   by 0x43A5B7: message_dispatch (mainloop.c:76)
   by 0x3B03C48962: ??? (in /usr/lib64/libglib-2.0.so.0.3600.3)
   by 0x3B03C47E05: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.3600.3)
   by 0x3B03C48157: ??? (in /usr/lib64/libglib-2.0.so.0.3600.3)
   by 0x3B03C48559: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.3600.3)
   by 0x40D53C: main (main.c:319)
 Address 0x30 is not stack'd, malloc'd or (recently) free'd
2013-09-29 17:01:07 +03:00
Andrei Emeltchenko
c64fd37802 codingstyle: Change __FUNCTION__ to __func__
The __func__ macro is part of the C99 standard whereas __FUNCTION__ is a
legacy gcc specific alias for it:

	http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html

Additionally, checkpatch.pl that's commonly used to verify coding style
also recommends to use __func__ instead of __FUNCTION__.
2013-09-11 13:22:08 +03:00
Luiz Augusto von Dentz
0c6df3bb9b gobex: Add proper message to transfer errors
This improve the error message when a transfer fails by using
g_obex_strerror to decode the response code to a human readable string.
2013-08-12 11:13:51 +03:00
Lucas De Marchi
f946c9e445 gobex: Get rid of gchar
Use plain char instead of gchar.
2013-05-02 09:02:31 +03:00
Lucas De Marchi
c1e4e183b5 gobex: Get rid of gint
Use plain int instead of gint. In glib gint is always a typedef to int,
so it's safe to use it even for callbacks with glib.
2013-05-01 09:04:21 +03:00
Lucas De Marchi
d073af52ea gobex: Use gcc builtin instead of g_atomic
g_atomic_* end up using G_STATIC_ASSERT, causing gcc 4.8 to yell due to
-Wunused-local-typedefs.

/usr/include/glib-2.0/glib/gmacros.h:162:53: error: typedef ‘_GStaticAssertCompileTimeAssertion_2’ locally defined but not used [-Werror=unused-local-typedefs]
 #define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1]

Most of the uses of atomic operations were wrong. They were fixed as
well. If we are using atomic operations, reading the variable again
later for logging is not an option, we should use the return of the
atomic function used to fetch the variable.
2013-04-09 07:01:58 +09:00
Johan Hedberg
30e2aaa3f8 gobex: Fix GPL version reference
These files (like everything else in the tree) should be GPL 2 or later
instead of GPL 2 only.
2013-02-15 16:25:29 +02:00
Johan Hedberg
b8779d2202 Revert "Ensure config.h is included by using CPPFLAGS"
This reverts commit 8a03376544.

The patch needs to be split up and the gdbus/ changes were bogus
compared to the original commit message.

Conflicts:
	Makefile.am
	Makefile.obexd
	profiles/cyclingspeed/cyclingspeed.c
	profiles/heartrate/heartrate.c
	src/error.c
2012-12-07 12:46:04 +02:00
Lucas De Marchi
8a03376544 Ensure config.h is included by using CPPFLAGS
Instead of trying to include config.h in each file over the tree and
possibly forgetting to include it, give a "-include config.h" argument
to the compiler so it's guaranteed that a) it will be included for all
source files and b) it will be the first header included.

gdbus/ directory is left out, since it would break other projects using
it.
2012-12-05 17:18:07 +02:00
Luiz Augusto von Dentz
c5cab062fc gobex: Fix build on 32 bits systems
GUINT_TO_POINTER does not cast properly in older version of GLib (< 2.31)
causing the following errors:

cc1: warnings being treated as errors
gobex/gobex-apparam.c: In function ‘g_obex_apparam_set_bytes’:
gobex/gobex-apparam.c:176:38: error: cast to pointer from integer of
different size
gobex/gobex-apparam.c: In function ‘g_obex_apparam_get_uint8’:
gobex/gobex-apparam.c:243:43: error: cast to pointer from integer of
different size
gobex/gobex-apparam.c: In function ‘g_obex_apparam_get_uint16’:
gobex/gobex-apparam.c:261:43: error: cast to pointer from integer of
different size
gobex/gobex-apparam.c: In function ‘g_obex_apparam_get_uint32’:
gobex/gobex-apparam.c:282:43: error: cast to pointer from integer of
different size
gobex/gobex-apparam.c: In function ‘g_obex_apparam_get_uint64’:
gobex/gobex-apparam.c:303:43: error: cast to pointer from integer of
different size
gobex/gobex-apparam.c: In function ‘g_obex_apparam_get_string’:
gobex/gobex-apparam.c:324:43: error: cast to pointer from integer of
different size
gobex/gobex-apparam.c: In function ‘g_obex_apparam_get_bytes’:
gobex/gobex-apparam.c:342:43: error: cast to pointer from integer of
different size
make[1]: *** [gobex/gobex-apparam.o] Error 1
make: *** [all] Error 2
2012-12-04 22:22:06 +01:00
Luiz Augusto von Dentz
696fad1853 gobex: Add debug option to apparam
This adds "apparam" to the debug options of GOBEX_DEBUG
2012-12-04 22:22:06 +01:00
Luiz Augusto von Dentz
63d1b60c8c gobex: Integrate GObexApparam with GObexHeader
This introduce 2 new convenient functions: g_obex_header_get_apparam
which parses and decode an header into GObexApparam and
gobex_header_new_apparam that encode GObexApparam into GObexHeader.
2012-12-04 22:22:06 +01:00
Luiz Augusto von Dentz
32ffe8f9d6 gobex: Introduce GObexApparam API
GObexApparam abstract the handling of application parameter tags, it
can be used to read/parse application parameter header data using
g_obex_apparam_get_* functions or to generate the data using
g_obex_apparam_set_*.
2012-12-04 22:22:06 +01:00
Luiz Augusto von Dentz
4621a3573c gobex: Fix not printing debug messages when GOBEX_DEBUG is set
g_debug doesn't print anything if domain is not present in
G_MESSAGES_DEBUG.
2012-12-04 22:22:06 +01:00
Neal Peacock
a3bb0a6dc5 gobex: Change UTF name to standard 2012-12-04 22:22:06 +01:00
Szymon Janc
55626b774e gobex: Fix dead assignments in gobex-header.c
Values stored are never read.
2012-12-04 22:22:06 +01:00
Jaganath Kanakkassery
9095deb825 gobex: Add callback and userdata parameter to g_obex_cancel_transfer()
If callback is provided in g_obex_cancel_transfer() current complete
callback will be replaced by the new one and user will be informed
when abort completes.
2012-12-04 22:22:06 +01:00
Marcel Holtmann
cd8a24b9fa gobex: build: Remove glib-helper.h support 2012-12-04 22:22:06 +01:00
Mikel Astiz
45df7c0fe3 gobex: fix callback remove when canceling transfer
This code path could lead to situations where the callback is later
used, making the daemon crash.
2012-12-04 22:22:06 +01:00
Luiz Augusto von Dentz
75e50f781b gobex: Use ENOSYS to correspond to OBEX not implemented
ENOSYS correspond to function not implemented which is exactly what the
OBEX error code means.

Also since EINVAL means invalid argument that now map to OBEX bad request
2012-12-04 22:22:06 +01:00
Luiz Augusto von Dentz
faac92a4cb gobex: Translate posix error code to proper OBEX response opcode
This patch create a map between posix errors code and OBEX response
opcode and use it to generate a proper response in case a transfer
failed instead of always responding with internal error.
2012-12-04 22:22:05 +01:00
Jaganath Kanakkassery
b53a70510f gobex: Fix ABORT request not processing
G_OBEX_OP_ABORT is defined as 0x7f but error checking of opcode is
done for greater than 0x1f. So abort request is simply ignored.
2012-12-04 22:22:05 +01:00
Luiz Augusto von Dentz
a4f6139e72 gobex: fix automatically including SRM header in CONNECT responses
GOEP 2.0 test specification forbids the server to include SRM headers in
CONNECT response:

  "3.16 TP/SRM/BI-03-C Process an OBEX CONNECT request (incorrectly)
  containing a SRM header:

  • Expected Outcome
  Pass Verdict:
  – On receiving the invalid SRM header in the OBEX_CONNECT request, the
  IUT responds with a SUCCESS without a SRM header.
  – OBEX/L2CAP channel is established.
  Fail Verdict:
  – On receiving the invalid SRM header in the OBEX_CONNECT request, the
  IUT does not respond with a SUCCESS and/or includes a SRM header in the
  response.
  – OBEX/L2CAP channel is not established or OBEX/RFCOMM channel is
  established."
2012-12-04 22:22:05 +01:00
Luiz Augusto von Dentz
f55ddf7376 gobex: fix not disabling SRM when dealing with GET responses
While sending the final bit can be changed during encoding.
2012-12-04 22:22:05 +01:00
Jaganath Kanakkassery
7099bdd9ea gobex: Remove reduntant NULL assignment 2012-12-04 22:22:05 +01:00