* Add application header support to gwobex
@ 2008-10-19 8:28 Marcel Holtmann
2008-10-19 12:36 ` Johan Hedberg
0 siblings, 1 reply; 3+ messages in thread
From: Marcel Holtmann @ 2008-10-19 8:28 UTC (permalink / raw)
To: BlueZ development
[-- Attachment #1: Type: text/plain, Size: 203 bytes --]
Hi Johan,
for the PBAP support, we need to handle the application header and for
our client/test applications, I extended gwobex to allow us to specify
this header. What do you think?
Regards
Marcel
[-- Attachment #2: patch-gwobex-apparam-support --]
[-- Type: text/x-patch, Size: 11541 bytes --]
diff --git a/gwobex/gw-obex.c b/gwobex/gw-obex.c
index 061e9e9..e656692 100644
--- a/gwobex/gw-obex.c
+++ b/gwobex/gw-obex.c
@@ -44,7 +44,7 @@ gboolean gw_obex_get_file(GwObex *ctx,
gboolean ret;
GW_OBEX_LOCK(ctx);
CHECK_DISCONNECT(FALSE, error, ctx);
- ret = gw_obex_get(ctx, local, remote, type, NULL, NULL, -1, FALSE);
+ ret = gw_obex_get(ctx, local, remote, type, NULL, 0, NULL, NULL, -1, FALSE);
if (ret == FALSE)
gw_obex_get_error(ctx, error);
GW_OBEX_UNLOCK(ctx);
@@ -59,7 +59,7 @@ gboolean gw_obex_get_fd(GwObex *ctx,
gboolean ret;
GW_OBEX_LOCK(ctx);
CHECK_DISCONNECT(FALSE, error, ctx);
- ret = gw_obex_get(ctx, NULL, remote, type, NULL, NULL, fd, FALSE);
+ ret = gw_obex_get(ctx, NULL, remote, type, NULL, 0, NULL, NULL, fd, FALSE);
if (ret == FALSE)
gw_obex_get_error(ctx, error);
GW_OBEX_UNLOCK(ctx);
@@ -74,7 +74,7 @@ gboolean gw_obex_put_fd(GwObex *ctx,
gboolean ret;
GW_OBEX_LOCK(ctx);
CHECK_DISCONNECT(FALSE, error, ctx);
- ret = gw_obex_put(ctx, NULL, remote, type, NULL, 0, -1, fd, FALSE);
+ ret = gw_obex_put(ctx, NULL, remote, type, NULL, 0, NULL, 0, -1, fd, FALSE);
if (ret == FALSE)
gw_obex_get_error(ctx, error);
GW_OBEX_UNLOCK(ctx);
@@ -89,7 +89,7 @@ gboolean gw_obex_put_file(GwObex *ctx,
gboolean ret;
GW_OBEX_LOCK(ctx);
CHECK_DISCONNECT(FALSE, error, ctx);
- ret = gw_obex_put(ctx, local, remote, type, NULL, 0, -1, -1, FALSE);
+ ret = gw_obex_put(ctx, local, remote, type, NULL, 0, NULL, 0, -1, -1, FALSE);
if (ret == FALSE)
gw_obex_get_error(ctx, error);
GW_OBEX_UNLOCK(ctx);
@@ -105,7 +105,7 @@ gboolean gw_obex_get_buf(GwObex *ctx,
gboolean ret;
GW_OBEX_LOCK(ctx);
CHECK_DISCONNECT(FALSE, error, ctx);
- ret = gw_obex_get(ctx, NULL, remote, type, buf, buf_size, -1, FALSE);
+ ret = gw_obex_get(ctx, NULL, remote, type, NULL, 0, buf, buf_size, -1, FALSE);
if (ret == FALSE)
gw_obex_get_error(ctx, error);
GW_OBEX_UNLOCK(ctx);
@@ -122,7 +122,44 @@ gboolean gw_obex_put_buf(GwObex *ctx,
gboolean ret;
GW_OBEX_LOCK(ctx);
CHECK_DISCONNECT(FALSE, error, ctx);
- ret = gw_obex_put(ctx, NULL, remote, type, buf, buf_size, time, -1, FALSE);
+ ret = gw_obex_put(ctx, NULL, remote, type, NULL, 0, buf, buf_size, time, -1, FALSE);
+ if (ret == FALSE)
+ gw_obex_get_error(ctx, error);
+ GW_OBEX_UNLOCK(ctx);
+ return ret;
+}
+
+gboolean gw_obex_get_buf_with_apparam(GwObex *ctx,
+ const gchar *remote,
+ const gchar *type,
+ const guint8 *apparam,
+ gint apparam_size,
+ gchar **buf,
+ gint *buf_size,
+ gint *error) {
+ gboolean ret;
+ GW_OBEX_LOCK(ctx);
+ CHECK_DISCONNECT(FALSE, error, ctx);
+ ret = gw_obex_get(ctx, NULL, remote, type, apparam, apparam_size, buf, buf_size, -1, FALSE);
+ if (ret == FALSE)
+ gw_obex_get_error(ctx, error);
+ GW_OBEX_UNLOCK(ctx);
+ return ret;
+}
+
+gboolean gw_obex_put_buf_with_apparam(GwObex *ctx,
+ const gchar *remote,
+ const gchar *type,
+ const guint8 *apparam,
+ gint apparam_size,
+ const gchar *buf,
+ gint buf_size,
+ gint time,
+ gint *error) {
+ gboolean ret;
+ GW_OBEX_LOCK(ctx);
+ CHECK_DISCONNECT(FALSE, error, ctx);
+ ret = gw_obex_put(ctx, NULL, remote, type, apparam, apparam_size, buf, buf_size, time, -1, FALSE);
if (ret == FALSE)
gw_obex_get_error(ctx, error);
GW_OBEX_UNLOCK(ctx);
@@ -158,7 +195,7 @@ gboolean gw_obex_read_dir(GwObex *ctx, const gchar *dir,
gboolean ret;
GW_OBEX_LOCK(ctx);
CHECK_DISCONNECT(FALSE, error, ctx);
- ret = gw_obex_get(ctx, NULL, dir ? dir : "", LST_TYPE, buf, buf_size, -1, FALSE);
+ ret = gw_obex_get(ctx, NULL, dir ? dir : "", LST_TYPE, NULL, 0, buf, buf_size, -1, FALSE);
if (ret == FALSE)
gw_obex_get_error(ctx, error);
else if (*buf_size > 0) {
@@ -181,7 +218,7 @@ gboolean gw_obex_delete(GwObex *ctx, const gchar *name, gint *error) {
gboolean ret;
GW_OBEX_LOCK(ctx);
CHECK_DISCONNECT(FALSE, error, ctx);
- ret = gw_obex_put(ctx, NULL, name, NULL, NULL, 0, -1, -1, FALSE);
+ ret = gw_obex_put(ctx, NULL, name, NULL, NULL, 0, NULL, 0, -1, -1, FALSE);
if (ret == FALSE)
gw_obex_get_error(ctx, error);
GW_OBEX_UNLOCK(ctx);
@@ -214,7 +251,7 @@ gboolean gw_obex_get_capability(GwObex *ctx, gchar **cap, gint *cap_len, gint *e
gboolean ret;
GW_OBEX_LOCK(ctx);
CHECK_DISCONNECT(FALSE, error, ctx);
- ret = gw_obex_get(ctx, NULL, NULL, CAP_TYPE, cap, cap_len, -1, FALSE);
+ ret = gw_obex_get(ctx, NULL, NULL, CAP_TYPE, NULL, 0, cap, cap_len, -1, FALSE);
if (ret == FALSE) {
*cap = NULL;
*cap_len = 0;
diff --git a/gwobex/gw-obex.h b/gwobex/gw-obex.h
index c1be103..d810d1c 100644
--- a/gwobex/gw-obex.h
+++ b/gwobex/gw-obex.h
@@ -365,6 +365,48 @@ gboolean gw_obex_put_buf(GwObex *ctx, const gchar *remote, const gchar *type,
const gchar *buf, gint buf_size, gint time, gint *error);
+/** Get an object from the remote device and store it in a memory buffer.
+ * Either remote filename or type must be supplied (or both).
+ *
+ * @param ctx Pointer returned by gw_obex_setup()
+ * @param remote Remote filename (null terminated UTF-8)
+ * @param type MIME-type of the object
+ * @param apparam Application Parameter of the object
+ * @param apparam_size Application Paramter size
+ * @param buf Buffer to store the object in.
+ * g_free() when not needed anymore.
+ * @param buf_size Place to store length of fetched object
+ * @param error Place to store error code on failure
+ * (NULL if not interested)
+ *
+ * @returns TRUE on success, FALSE on failure
+ */
+gboolean gw_obex_get_buf_with_apparam(GwObex *ctx, const gchar *remote, const gchar *type,
+ const guint8 *apparam, gint apparam_size,
+ gchar **buf, gint *buf_size, gint *error);
+
+
+/** Send a object located in a memory buffer to the remote device.
+ * Either remote filename or type must be supplied (or both)
+ *
+ * @param ctx Pointer returned by gw_obex_setup()
+ * @param remote Remote filename (null terminated UTF-8)
+ * @param type MIME-type of the object
+ * @param apparam Application Parameter of the object
+ * @param apparam_size Application Paramter size
+ * @param buf Buffer containing the object
+ * @param buf_size Buffer (object) size
+ * @param time Last modification time of object (or -1 if not known)
+ * @param error Place to store error code on failure
+ * (NULL if not interested)
+ *
+ * @returns TRUE on success, FALSE on failure
+ */
+gboolean gw_obex_put_buf_wit_apparam(GwObex *ctx, const gchar *remote, const gchar *type,
+ const guint8 *apparam, gint apparam_size,
+ const gchar *buf, gint buf_size, gint time, gint *error);
+
+
/** Change directory (relative to the current one).
*
* @param ctx Pointer returned by gw_obex_setup()
diff --git a/gwobex/obex-priv.c b/gwobex/obex-priv.c
index 792cb4f..013e55a 100644
--- a/gwobex/obex-priv.c
+++ b/gwobex/obex-priv.c
@@ -828,6 +828,7 @@ out:
gboolean gw_obex_get(GwObex *ctx,
const gchar *local, const gchar *remote, const gchar *type,
+ const guint8 *apparam, gint apparam_size,
gchar **buf, gint *buf_size, int stream_fd,
gboolean async) {
gboolean ret = FALSE;
@@ -853,6 +854,11 @@ gboolean gw_obex_get(GwObex *ctx,
OBEX_ObjectAddHeader(ctx->handle, object, OBEX_HDR_CONNECTION, hv, 4, 0);
}
+ if (apparam && apparam_size > 0) {
+ hv.bs = (unsigned char *)apparam;
+ OBEX_ObjectAddHeader(ctx->handle, object, OBEX_HDR_APPARAM, hv, apparam_size, 0);
+ }
+
if (type) {
hv.bs = (unsigned char *)type;
OBEX_ObjectAddHeader(ctx->handle, object, OBEX_HDR_TYPE, hv, strlen(type) + 1, 0);
@@ -939,6 +945,7 @@ out:
gboolean gw_obex_put(GwObex *ctx,
const gchar *local, const gchar *remote, const gchar *type,
+ const guint8 *apparam, gint apparam_size,
const gchar *buf, gint object_size, time_t object_time,
int stream_fd, gboolean async) {
gboolean ret = FALSE;
@@ -1015,6 +1022,11 @@ gboolean gw_obex_put(GwObex *ctx,
OBEX_ObjectAddHeader(ctx->handle, object, OBEX_HDR_TYPE, hv, strlen(type) + 1, 0);
}
+ if (apparam && apparam_size > 0) {
+ hv.bs = (unsigned char *)apparam;
+ OBEX_ObjectAddHeader(ctx->handle, object, OBEX_HDR_APPARAM, hv, apparam_size, 0);
+ }
+
/* Try to figure out modification time if none was given */
if (ctx->xfer->stream_fd >= 0) {
struct stat stats;
diff --git a/gwobex/obex-priv.h b/gwobex/obex-priv.h
index b6cbbf6..01d7b8b 100644
--- a/gwobex/obex-priv.h
+++ b/gwobex/obex-priv.h
@@ -197,6 +197,7 @@ gboolean gw_obex_setpath(GwObex *ctx, const gchar *path, int flags);
*/
gboolean gw_obex_get(GwObex *ctx,
const gchar *local, const gchar *remote, const gchar *type,
+ const guint8 *apparam, gint apparam_size,
gchar **buf, gint *buf_size, int stream_fd,
gboolean async);
@@ -209,6 +210,7 @@ gboolean gw_obex_get(GwObex *ctx,
*/
gboolean gw_obex_put(GwObex *ctx,
const gchar *local, const gchar *remote, const gchar *type,
+ const guint8 *apparam, gint apparam_size,
const gchar *buf, gint buf_size, time_t object_time,
int stream_fd, gboolean async);
diff --git a/gwobex/obex-xfer.c b/gwobex/obex-xfer.c
index 1cce005..4edaa41 100644
--- a/gwobex/obex-xfer.c
+++ b/gwobex/obex-xfer.c
@@ -117,7 +117,7 @@ GwObexXfer *gw_obex_put_async(GwObex *ctx, const char *name, const char *type,
gboolean ret;
GW_OBEX_LOCK(ctx);
CHECK_DISCONNECT(NULL, error, ctx);
- ret = gw_obex_put(ctx, NULL, name, type, NULL, size, time, -1, TRUE);
+ ret = gw_obex_put(ctx, NULL, name, type, NULL, 0, NULL, size, time, -1, TRUE);
if (ret == FALSE)
gw_obex_get_error(ctx, error);
GW_OBEX_UNLOCK(ctx);
@@ -128,7 +128,7 @@ GwObexXfer *gw_obex_get_async(GwObex *ctx, const char *name, const char *type, g
gboolean ret;
GW_OBEX_LOCK(ctx);
CHECK_DISCONNECT(NULL, error, ctx);
- ret = gw_obex_get(ctx, NULL, name, type, NULL, NULL, -1, TRUE);
+ ret = gw_obex_get(ctx, NULL, name, type, NULL, 0, NULL, NULL, -1, TRUE);
if (ret == FALSE)
gw_obex_get_error(ctx, error);
GW_OBEX_UNLOCK(ctx);
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: Add application header support to gwobex
2008-10-19 8:28 Add application header support to gwobex Marcel Holtmann
@ 2008-10-19 12:36 ` Johan Hedberg
2008-10-19 17:00 ` Marcel Holtmann
0 siblings, 1 reply; 3+ messages in thread
From: Johan Hedberg @ 2008-10-19 12:36 UTC (permalink / raw)
To: BlueZ development
Hi Marcel,
On Oct 19, 2008, at 11:28, Marcel Holtmann wrote:
> for the PBAP support, we need to handle the application header and for
> our client/test applications, I extended gwobex to allow us to specify
> this header. What do you think?
Looks good to me, though the parameter lists to the _get and_put
functions are starting to grow pretty long. In general it'd be nice to
get the same functionality into libopenobex-glib soonish since I'm not
particularly enjoying looking at this ancient code and coding style
that should just die away ;)
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Add application header support to gwobex
2008-10-19 12:36 ` Johan Hedberg
@ 2008-10-19 17:00 ` Marcel Holtmann
0 siblings, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2008-10-19 17:00 UTC (permalink / raw)
To: Johan Hedberg; +Cc: BlueZ development
Hi Johan,
> > for the PBAP support, we need to handle the application header and for
> > our client/test applications, I extended gwobex to allow us to specify
> > this header. What do you think?
>
> Looks good to me, though the parameter lists to the _get and_put
> functions are starting to grow pretty long. In general it'd be nice to
> get the same functionality into libopenobex-glib soonish since I'm not
> particularly enjoying looking at this ancient code and coding style
> that should just die away ;)
I agree on that one, but currently it is more important to get this
functionality working and then later we can do the cleanups. Main
problem with libopenobex-glib at the moment is that I based it around
GObject which does make sense for GTK+ programs, but will not make sense
for obex-client. So parts of gwobex might be still living a long life.
After actually working with the PBAP details, I realized that besides
giving the application parameters in the command, so we do have another
pair of buf+size for the response.
Regards
Marcel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-10-19 17:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-19 8:28 Add application header support to gwobex Marcel Holtmann
2008-10-19 12:36 ` Johan Hedberg
2008-10-19 17:00 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox