static void test_apparam_set_multi(void) { GObexApparam *apparam; guint8 buf[1024]; gsize len; apparam = g_obex_apparam_set_uint8(NULL, TAG_U8, 0x01); g_assert(apparam != NULL); apparam = g_obex_apparam_set_uint16(apparam, TAG_U16, 0x0102); g_assert(apparam != NULL); apparam = g_obex_apparam_set_uint32(apparam, TAG_U32, 0x01020304); g_assert(apparam != NULL); apparam = g_obex_apparam_set_uint64(apparam, TAG_U64, 0x0102030405060708); g_assert(apparam != NULL); apparam = g_obex_apparam_set_string(apparam, TAG_STRING, "ABC"); g_assert(apparam != NULL); len = g_obex_apparam_encode(apparam, buf, sizeof(buf)); g_assert_cmpuint(len, ==, sizeof(tag_multi)); g_obex_apparam_free(apparam); }
GObexHeader *g_obex_header_new_apparam(GObexApparam *apparam) { guint8 buf[1024]; gssize len; len = g_obex_apparam_encode(apparam, buf, sizeof(buf)); if (len < 0) return NULL; return g_obex_header_new_bytes(G_OBEX_HDR_APPARAM, buf, len); }
static void test_apparam_set_bytes(void) { GObexApparam *apparam; guint8 buf[1024]; gsize len; apparam = g_obex_apparam_set_bytes(NULL, TAG_BYTES, tag_bytes + 2, 255); g_assert(apparam != NULL); len = g_obex_apparam_encode(apparam, buf, sizeof(buf)); assert_memequal(tag_bytes, sizeof(tag_bytes), buf, len); g_obex_apparam_free(apparam); }
static void test_apparam_set_string(void) { GObexApparam *apparam; guint8 buf[1024]; gsize len; apparam = g_obex_apparam_set_string(NULL, TAG_STRING, "ABC"); g_assert(apparam != NULL); len = g_obex_apparam_encode(apparam, buf, sizeof(buf)); assert_memequal(tag_string, sizeof(tag_string), buf, len); g_obex_apparam_free(apparam); }
static void test_apparam_set_uint64(void) { GObexApparam *apparam; guint8 buf[1024]; gsize len; apparam = g_obex_apparam_set_uint64(NULL, TAG_U64, 0x0102030405060708); g_assert(apparam != NULL); len = g_obex_apparam_encode(apparam, buf, sizeof(buf)); assert_memequal(tag_uint64, sizeof(tag_uint64), buf, len); g_obex_apparam_free(apparam); }
static GObexApparam *parse_and_decode(const void *data, gsize size) { GObexApparam *apparam; guint8 encoded[1024]; gsize len; apparam = g_obex_apparam_decode(data, size); g_assert(apparam != NULL); len = g_obex_apparam_encode(apparam, encoded, sizeof(encoded)); assert_memequal(data, size, encoded, len); return apparam; }
static ssize_t vobject_list_get_next_header(void *object, void *buf, size_t mtu, uint8_t *hi) { struct pbap_object *obj = object; struct pbap_session *pbap = obj->session; /* Backend still busy reading contacts */ if (!pbap->cache.valid) return -EAGAIN; *hi = G_OBEX_HDR_APPARAM; if (pbap->params->maxlistcount == 0) return g_obex_apparam_encode(obj->apparam, buf, mtu); return 0; }
static ssize_t vobject_pull_get_next_header(void *object, void *buf, size_t mtu, uint8_t *hi) { struct pbap_object *obj = object; if (!obj->buffer && !obj->apparam) return -EAGAIN; *hi = G_OBEX_HDR_APPARAM; if (obj->firstpacket) { obj->firstpacket = FALSE; return g_obex_apparam_encode(obj->apparam, buf, mtu); } return 0; }
static ssize_t any_get_next_header(void *object, void *buf, size_t mtu, uint8_t *hi) { struct mas_session *mas = object; DBG(""); if (mas->buffer->len == 0 && !mas->finished) return -EAGAIN; *hi = G_OBEX_HDR_APPARAM; if (mas->ap_sent) return 0; mas->ap_sent = TRUE; if (!mas->outparams) return 0; return g_obex_apparam_encode(mas->outparams, buf, mtu); }
static void transport_func(GIOChannel *io, GError *err, gpointer user_data) { struct callback_data *callback = user_data; struct obc_session *session = callback->session; struct obc_driver *driver = session->driver; struct obc_transport *transport = session->transport; GObex *obex; GObexApparam *apparam; GObexTransportType type; int tx_mtu = -1; int rx_mtu = -1; DBG(""); if (err != NULL) { error("%s", err->message); goto done; } g_io_channel_set_close_on_unref(io, FALSE); if (transport->getpacketopt && transport->getpacketopt(io, &tx_mtu, &rx_mtu) == 0) type = G_OBEX_TRANSPORT_PACKET; else type = G_OBEX_TRANSPORT_STREAM; obex = g_obex_new(io, type, tx_mtu, rx_mtu); if (obex == NULL) goto done; g_io_channel_set_close_on_unref(io, TRUE); apparam = NULL; if (driver->supported_features) apparam = driver->supported_features(session); if (apparam) { uint8_t buf[1024]; ssize_t len; len = g_obex_apparam_encode(apparam, buf, sizeof(buf)); if (driver->target) g_obex_connect(obex, connect_cb, callback, &err, G_OBEX_HDR_TARGET, driver->target, driver->target_len, G_OBEX_HDR_APPARAM, buf, len, G_OBEX_HDR_INVALID); else g_obex_connect(obex, connect_cb, callback, &err, G_OBEX_HDR_APPARAM, buf, len, G_OBEX_HDR_INVALID); g_obex_apparam_free(apparam); } else if (driver->target) g_obex_connect(obex, connect_cb, callback, &err, G_OBEX_HDR_TARGET, driver->target, driver->target_len, G_OBEX_HDR_INVALID); else g_obex_connect(obex, connect_cb, callback, &err, G_OBEX_HDR_INVALID); if (err != NULL) { error("%s", err->message); g_obex_unref(obex); goto done; } session->obex = obex; sessions = g_slist_prepend(sessions, session); g_obex_set_disconnect_function(obex, session_disconnected, session); return; done: callback_destroy(callback, err); }