Add application header support to gwobex
Marcel Holtmann
maintainerHi 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
gwobex/gw-obex.c +46 -9
@@ -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 *egboolean 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 ;
gwobex/gw-obex.h +42 -0
48 lines not on this page · raw message
gwobex/obex-priv.c +12 -0
@@ -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;
gwobex/obex-priv.h +2 -0
@@ -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);
gwobex/obex-xfer.c +2 -2
@@ -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, ggboolean 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);
Hi Marcel,
Quoted 3 lines · Marcel Holtmann
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
Marcel Holtmann
maintainerHi Johan,
Quoted 9 lines
Quoted 3 lines
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
_getand_putfunctions 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