From 58cd14d209ae86ee99e909f034d14c52bdef1d1a Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sun, 10 Jul 2011 21:47:49 +0300 Subject: [PATCH] gobex: Remove _ID_ from header type definitions --- gobex/gobex-header.c | 68 +++++++++++++++++++------------------- gobex/gobex-header.h | 52 ++++++++++++++--------------- gobex/gobex-packet.c | 6 ++-- gobex/gobex-transfer.c | 34 +++++++++---------- gobex/gobex.c | 32 +++++++++--------- tools/obex-server-tool.c | 7 ++-- unit/test-gobex-header.c | 33 +++++++++--------- unit/test-gobex-packet.c | 38 ++++++++++----------- unit/test-gobex-transfer.c | 18 +++++----- unit/test-gobex.c | 23 ++++++------- 10 files changed, 150 insertions(+), 161 deletions(-) diff --git a/gobex/gobex-header.c b/gobex/gobex-header.c index bf7dc9d7c..d4351cb4f 100644 --- a/gobex/gobex-header.c +++ b/gobex/gobex-header.c @@ -24,12 +24,12 @@ #include "gobex-header.h" /* Header types */ -#define G_OBEX_HDR_TYPE_UNICODE (0 << 6) -#define G_OBEX_HDR_TYPE_BYTES (1 << 6) -#define G_OBEX_HDR_TYPE_UINT8 (2 << 6) -#define G_OBEX_HDR_TYPE_UINT32 (3 << 6) +#define G_OBEX_HDR_ENC_UNICODE (0 << 6) +#define G_OBEX_HDR_ENC_BYTES (1 << 6) +#define G_OBEX_HDR_ENC_UINT8 (2 << 6) +#define G_OBEX_HDR_ENC_UINT32 (3 << 6) -#define G_OBEX_HDR_TYPE(id) ((id) & 0xc0) +#define G_OBEX_HDR_ENC(id) ((id) & 0xc0) struct _GObexHeader { guint8 id; @@ -93,8 +93,8 @@ gssize g_obex_header_encode(GObexHeader *header, void *buf, gsize buf_len) ptr = put_bytes(ptr, &header->id, sizeof(header->id)); - switch (G_OBEX_HDR_TYPE(header->id)) { - case G_OBEX_HDR_TYPE_UNICODE: + switch (G_OBEX_HDR_ENC(header->id)) { + case G_OBEX_HDR_ENC_UNICODE: utf16_len = utf8_to_utf16(&utf16, header->v.string); if (utf16_len < 0 || (guint16) utf16_len > buf_len) return -1; @@ -104,7 +104,7 @@ gssize g_obex_header_encode(GObexHeader *header, void *buf, gsize buf_len) ptr = put_bytes(ptr, utf16, utf16_len); g_free(utf16); break; - case G_OBEX_HDR_TYPE_BYTES: + case G_OBEX_HDR_ENC_BYTES: u16 = g_htons(header->hlen); ptr = put_bytes(ptr, &u16, sizeof(u16)); if (header->extdata) @@ -112,10 +112,10 @@ gssize g_obex_header_encode(GObexHeader *header, void *buf, gsize buf_len) else ptr = put_bytes(ptr, header->v.data, header->vlen); break; - case G_OBEX_HDR_TYPE_UINT8: + case G_OBEX_HDR_ENC_UINT8: *ptr = header->v.u8; break; - case G_OBEX_HDR_TYPE_UINT32: + case G_OBEX_HDR_ENC_UINT32: u32 = g_htonl(header->v.u32); ptr = put_bytes(ptr, &u32, sizeof(u32)); break; @@ -146,8 +146,8 @@ GObexHeader *g_obex_header_decode(const void *data, gsize len, ptr = get_bytes(&header->id, ptr, sizeof(header->id)); - switch (G_OBEX_HDR_TYPE(header->id)) { - case G_OBEX_HDR_TYPE_UNICODE: + switch (G_OBEX_HDR_ENC(header->id)) { + case G_OBEX_HDR_ENC_UNICODE: if (len < 3) { g_set_error(err, G_OBEX_ERROR, G_OBEX_ERROR_PARSE_ERROR, @@ -183,7 +183,7 @@ GObexHeader *g_obex_header_decode(const void *data, gsize len, *parsed = hdr_len; break; - case G_OBEX_HDR_TYPE_BYTES: + case G_OBEX_HDR_ENC_BYTES: if (len < 3) { g_set_error(err, G_OBEX_ERROR, G_OBEX_ERROR_PARSE_ERROR, @@ -220,13 +220,13 @@ GObexHeader *g_obex_header_decode(const void *data, gsize len, *parsed = hdr_len; break; - case G_OBEX_HDR_TYPE_UINT8: + case G_OBEX_HDR_ENC_UINT8: header->vlen = 1; header->hlen = 2; header->v.u8 = *ptr; *parsed = 2; break; - case G_OBEX_HDR_TYPE_UINT32: + case G_OBEX_HDR_ENC_UINT32: if (len < 5) { g_set_error(err, G_OBEX_ERROR, G_OBEX_ERROR_PARSE_ERROR, @@ -252,16 +252,16 @@ failed: void g_obex_header_free(GObexHeader *header) { - switch (G_OBEX_HDR_TYPE(header->id)) { - case G_OBEX_HDR_TYPE_UNICODE: + switch (G_OBEX_HDR_ENC(header->id)) { + case G_OBEX_HDR_ENC_UNICODE: g_free(header->v.string); break; - case G_OBEX_HDR_TYPE_BYTES: + case G_OBEX_HDR_ENC_BYTES: if (!header->extdata) g_free(header->v.data); break; - case G_OBEX_HDR_TYPE_UINT8: - case G_OBEX_HDR_TYPE_UINT32: + case G_OBEX_HDR_ENC_UINT8: + case G_OBEX_HDR_ENC_UINT32: break; default: g_assert_not_reached(); @@ -272,7 +272,7 @@ void g_obex_header_free(GObexHeader *header) gboolean g_obex_header_get_unicode(GObexHeader *header, const char **str) { - if (G_OBEX_HDR_TYPE(header->id) != G_OBEX_HDR_TYPE_UNICODE) + if (G_OBEX_HDR_ENC(header->id) != G_OBEX_HDR_ENC_UNICODE) return FALSE; *str = header->v.string; @@ -283,7 +283,7 @@ gboolean g_obex_header_get_unicode(GObexHeader *header, const char **str) gboolean g_obex_header_get_bytes(GObexHeader *header, const guint8 **val, gsize *len) { - if (G_OBEX_HDR_TYPE(header->id) != G_OBEX_HDR_TYPE_BYTES) + if (G_OBEX_HDR_ENC(header->id) != G_OBEX_HDR_ENC_BYTES) return FALSE; *len = header->vlen; @@ -298,7 +298,7 @@ gboolean g_obex_header_get_bytes(GObexHeader *header, const guint8 **val, gboolean g_obex_header_get_uint8(GObexHeader *header, guint8 *val) { - if (G_OBEX_HDR_TYPE(header->id) != G_OBEX_HDR_TYPE_UINT8) + if (G_OBEX_HDR_ENC(header->id) != G_OBEX_HDR_ENC_UINT8) return FALSE; *val = header->v.u8; @@ -308,7 +308,7 @@ gboolean g_obex_header_get_uint8(GObexHeader *header, guint8 *val) gboolean g_obex_header_get_uint32(GObexHeader *header, guint32 *val) { - if (G_OBEX_HDR_TYPE(header->id) != G_OBEX_HDR_TYPE_UINT32) + if (G_OBEX_HDR_ENC(header->id) != G_OBEX_HDR_ENC_UINT32) return FALSE; *val = header->v.u32; @@ -321,7 +321,7 @@ GObexHeader *g_obex_header_new_unicode(guint8 id, const char *str) GObexHeader *header; gsize len; - if (G_OBEX_HDR_TYPE(id) != G_OBEX_HDR_TYPE_UNICODE) + if (G_OBEX_HDR_ENC(id) != G_OBEX_HDR_ENC_UNICODE) return NULL; header = g_new0(GObexHeader, 1); @@ -341,7 +341,7 @@ GObexHeader *g_obex_header_new_bytes(guint8 id, const void *data, gsize len) { GObexHeader *header; - if (G_OBEX_HDR_TYPE(id) != G_OBEX_HDR_TYPE_BYTES) + if (G_OBEX_HDR_ENC(id) != G_OBEX_HDR_ENC_BYTES) return NULL; header = g_new0(GObexHeader, 1); @@ -358,7 +358,7 @@ GObexHeader *g_obex_header_new_uint8(guint8 id, guint8 val) { GObexHeader *header; - if (G_OBEX_HDR_TYPE(id) != G_OBEX_HDR_TYPE_UINT8) + if (G_OBEX_HDR_ENC(id) != G_OBEX_HDR_ENC_UINT8) return NULL; header = g_new0(GObexHeader, 1); @@ -375,7 +375,7 @@ GObexHeader *g_obex_header_new_uint32(guint8 id, guint32 val) { GObexHeader *header; - if (G_OBEX_HDR_TYPE(id) != G_OBEX_HDR_TYPE_UINT32) + if (G_OBEX_HDR_ENC(id) != G_OBEX_HDR_ENC_UINT32) return NULL; header = g_new0(GObexHeader, 1); @@ -406,28 +406,28 @@ GSList *g_obex_header_create_list(guint8 first_hdr_id, va_list args, *total_len = 0; - while (id != G_OBEX_HDR_ID_INVALID) { + while (id != G_OBEX_HDR_INVALID) { GObexHeader *hdr; const char *str; const void *bytes; unsigned int val; gsize len; - switch (G_OBEX_HDR_TYPE(id)) { - case G_OBEX_HDR_TYPE_UNICODE: + switch (G_OBEX_HDR_ENC(id)) { + case G_OBEX_HDR_ENC_UNICODE: str = va_arg(args, const char *); hdr = g_obex_header_new_unicode(id, str); break; - case G_OBEX_HDR_TYPE_BYTES: + case G_OBEX_HDR_ENC_BYTES: bytes = va_arg(args, void *); len = va_arg(args, gsize); hdr = g_obex_header_new_bytes(id, bytes, len); break; - case G_OBEX_HDR_TYPE_UINT8: + case G_OBEX_HDR_ENC_UINT8: val = va_arg(args, unsigned int); hdr = g_obex_header_new_uint8(id, val); break; - case G_OBEX_HDR_TYPE_UINT32: + case G_OBEX_HDR_ENC_UINT32: val = va_arg(args, unsigned int); hdr = g_obex_header_new_uint32(id, val); break; diff --git a/gobex/gobex-header.h b/gobex/gobex-header.h index 0a8ff3386..b7d23eb82 100644 --- a/gobex/gobex-header.h +++ b/gobex/gobex-header.h @@ -27,33 +27,33 @@ #include /* Header ID's */ -#define G_OBEX_HDR_ID_INVALID 0x00 +#define G_OBEX_HDR_INVALID 0x00 -#define G_OBEX_HDR_ID_COUNT 0xc0 -#define G_OBEX_HDR_ID_NAME 0x01 -#define G_OBEX_HDR_ID_TYPE 0x42 -#define G_OBEX_HDR_ID_LENGTH 0xc3 -#define G_OBEX_HDR_ID_TIME 0x44 -#define G_OBEX_HDR_ID_DESCRIPTION 0x05 -#define G_OBEX_HDR_ID_TARGET 0x46 -#define G_OBEX_HDR_ID_HTTP 0x47 -#define G_OBEX_HDR_ID_BODY 0x48 -#define G_OBEX_HDR_ID_BODY_END 0x49 -#define G_OBEX_HDR_ID_WHO 0x4a -#define G_OBEX_HDR_ID_CONNECTION 0xcb -#define G_OBEX_HDR_ID_APPARAM 0x4c -#define G_OBEX_HDR_ID_AUTHCHAL 0x4d -#define G_OBEX_HDR_ID_AUTHRESP 0x4e -#define G_OBEX_HDR_ID_CREATOR 0xcf -#define G_OBEX_HDR_ID_WANUUID 0x50 -#define G_OBEX_HDR_ID_OBJECTCLASS 0x51 -#define G_OBEX_HDR_ID_SESSIONPARAM 0x52 -#define G_OBEX_HDR_ID_SESSIONSEQ 0x93 -#define G_OBEX_HDR_ID_ACTION 0x94 -#define G_OBEX_HDR_ID_DESTNAME 0x15 -#define G_OBEX_HDR_ID_PERMISSIONS 0xd6 -#define G_OBEX_HDR_ID_SRM 0x97 -#define G_OBEX_HDR_ID_SRM_PARAMETERS 0x98 +#define G_OBEX_HDR_COUNT 0xc0 +#define G_OBEX_HDR_NAME 0x01 +#define G_OBEX_HDR_TYPE 0x42 +#define G_OBEX_HDR_LENGTH 0xc3 +#define G_OBEX_HDR_TIME 0x44 +#define G_OBEX_HDR_DESCRIPTION 0x05 +#define G_OBEX_HDR_TARGET 0x46 +#define G_OBEX_HDR_HTTP 0x47 +#define G_OBEX_HDR_BODY 0x48 +#define G_OBEX_HDR_BODY_END 0x49 +#define G_OBEX_HDR_WHO 0x4a +#define G_OBEX_HDR_CONNECTION 0xcb +#define G_OBEX_HDR_APPARAM 0x4c +#define G_OBEX_HDR_AUTHCHAL 0x4d +#define G_OBEX_HDR_AUTHRESP 0x4e +#define G_OBEX_HDR_CREATOR 0xcf +#define G_OBEX_HDR_WANUUID 0x50 +#define G_OBEX_HDR_OBJECTCLASS 0x51 +#define G_OBEX_HDR_SESSIONPARAM 0x52 +#define G_OBEX_HDR_SESSIONSEQ 0x93 +#define G_OBEX_HDR_ACTION 0x94 +#define G_OBEX_HDR_DESTNAME 0x15 +#define G_OBEX_HDR_PERMISSIONS 0xd6 +#define G_OBEX_HDR_SRM 0x97 +#define G_OBEX_HDR_SRM_PARAMETERS 0x98 typedef struct _GObexHeader GObexHeader; diff --git a/gobex/gobex-packet.c b/gobex/gobex-packet.c index 10c1cf70a..679a2dd9f 100644 --- a/gobex/gobex-packet.c +++ b/gobex/gobex-packet.c @@ -267,7 +267,7 @@ GObexPacket *g_obex_packet_decode(const void *data, gsize len, final = (opcode & FINAL_BIT) ? TRUE : FALSE; opcode &= ~FINAL_BIT; - pkt = g_obex_packet_new(opcode, final, G_OBEX_HDR_ID_INVALID); + pkt = g_obex_packet_new(opcode, final, G_OBEX_HDR_INVALID); if (header_offset == 0) goto headers; @@ -300,9 +300,9 @@ static gssize get_body(GObexPacket *pkt, guint8 *buf, gsize len) return ret; if (ret > 0) - buf[0] = G_OBEX_HDR_ID_BODY; + buf[0] = G_OBEX_HDR_BODY; else - buf[0] = G_OBEX_HDR_ID_BODY_END; + buf[0] = G_OBEX_HDR_BODY_END; u16 = g_htons(ret + 3); memcpy(&buf[1], &u16, sizeof(u16)); diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c index 75fa50ef0..c66411892 100644 --- a/gobex/gobex-transfer.c +++ b/gobex/gobex-transfer.c @@ -100,7 +100,7 @@ static gssize put_get_data(void *buf, gsize len, gpointer user_data) if (ret >= 0) return ret; - req = g_obex_packet_new(G_OBEX_OP_ABORT, TRUE, G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(G_OBEX_OP_ABORT, TRUE, G_OBEX_HDR_INVALID); transfer->req_id = g_obex_send_req(transfer->obex, req, -1, transfer_abort_response, transfer, &err); @@ -138,10 +138,10 @@ static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp, if (transfer->opcode == G_OBEX_OP_GET) { GObexHeader *body; - body = g_obex_packet_get_header(rsp, G_OBEX_HDR_ID_BODY); + body = g_obex_packet_get_header(rsp, G_OBEX_HDR_BODY); if (body == NULL) body = g_obex_packet_get_header(rsp, - G_OBEX_HDR_ID_BODY_END); + G_OBEX_HDR_BODY_END); if (body != NULL) { const guint8 *buf; gsize len; @@ -159,7 +159,7 @@ static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp, return; } - req = g_obex_packet_new(transfer->opcode, TRUE, G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(transfer->opcode, TRUE, G_OBEX_HDR_INVALID); if (transfer->opcode == G_OBEX_OP_PUT) g_obex_packet_add_body(req, put_get_data, transfer); @@ -201,16 +201,16 @@ guint g_obex_put_req(GObex *obex, const char *type, const char *name, transfer = transfer_new(obex, G_OBEX_OP_PUT, complete_func, user_data); transfer->data_producer = data_func; - req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_INVALID); if (type) { - hdr = g_obex_header_new_bytes(G_OBEX_HDR_ID_TYPE, + hdr = g_obex_header_new_bytes(G_OBEX_HDR_TYPE, (char *) type, strlen(type) + 1); g_obex_packet_add_header(req, hdr); } if (name) { - hdr = g_obex_header_new_unicode(G_OBEX_HDR_ID_NAME, name); + hdr = g_obex_header_new_unicode(G_OBEX_HDR_NAME, name); g_obex_packet_add_header(req, hdr); } @@ -234,9 +234,9 @@ static void transfer_put_req(GObex *obex, GObexPacket *req, gpointer user_data) GObexPacket *rsp; GObexHeader *body; - body = g_obex_packet_get_header(req, G_OBEX_HDR_ID_BODY); + body = g_obex_packet_get_header(req, G_OBEX_HDR_BODY); if (body == NULL) { - body = g_obex_packet_get_header(req, G_OBEX_HDR_ID_BODY_END); + body = g_obex_packet_get_header(req, G_OBEX_HDR_BODY_END); rspcode = G_OBEX_RSP_SUCCESS; } @@ -250,7 +250,7 @@ static void transfer_put_req(GObex *obex, GObexPacket *req, gpointer user_data) transfer->data_consumer(buf, len, transfer->user_data); } - rsp = g_obex_packet_new(rspcode, TRUE, G_OBEX_HDR_ID_INVALID); + rsp = g_obex_packet_new(rspcode, TRUE, G_OBEX_HDR_INVALID); if (!g_obex_send(obex, rsp, &err)) { transfer_complete(transfer, err); g_error_free(err); @@ -268,8 +268,7 @@ static void transfer_abort_req(GObex *obex, GObexPacket *req, gpointer user_data err = g_error_new(G_OBEX_ERROR, G_OBEX_ERROR_CANCELLED, "Request was aborted"); - rsp = g_obex_packet_new(G_OBEX_RSP_SUCCESS, TRUE, - G_OBEX_HDR_ID_INVALID); + rsp = g_obex_packet_new(G_OBEX_RSP_SUCCESS, TRUE, G_OBEX_HDR_INVALID); g_obex_send(obex, rsp, NULL); transfer_complete(transfer, err); @@ -312,16 +311,16 @@ guint g_obex_get_req(GObex *obex, const char *type, const char *name, transfer = transfer_new(obex, G_OBEX_OP_GET, complete_func, user_data); transfer->data_consumer = data_func; - req = g_obex_packet_new(G_OBEX_OP_GET, TRUE, G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(G_OBEX_OP_GET, TRUE, G_OBEX_HDR_INVALID); if (type) { - hdr = g_obex_header_new_bytes(G_OBEX_HDR_ID_TYPE, + hdr = g_obex_header_new_bytes(G_OBEX_HDR_TYPE, (char *) type, strlen(type) + 1); g_obex_packet_add_header(req, hdr); } if (name) { - hdr = g_obex_header_new_unicode(G_OBEX_HDR_ID_NAME, name); + hdr = g_obex_header_new_unicode(G_OBEX_HDR_NAME, name); g_obex_packet_add_header(req, hdr); } @@ -352,7 +351,7 @@ static gssize get_get_data(void *buf, gsize len, gpointer user_data) } req = g_obex_packet_new(G_OBEX_RSP_INTERNAL_SERVER_ERROR, TRUE, - G_OBEX_HDR_ID_INVALID); + G_OBEX_HDR_INVALID); g_obex_send(transfer->obex, req, NULL); err = g_error_new(G_OBEX_ERROR, G_OBEX_ERROR_CANCELLED, @@ -385,8 +384,7 @@ static void transfer_get_req(GObex *obex, GObexPacket *req, gpointer user_data) GError *err = NULL; GObexPacket *rsp; - rsp = g_obex_packet_new(G_OBEX_RSP_CONTINUE, TRUE, - G_OBEX_HDR_ID_INVALID); + rsp = g_obex_packet_new(G_OBEX_RSP_CONTINUE, TRUE, G_OBEX_HDR_INVALID); g_obex_packet_add_body(rsp, get_get_data, transfer); if (!g_obex_send(obex, rsp, &err)) { diff --git a/gobex/gobex.c b/gobex/gobex.c index b0d21ea14..f98551ecb 100644 --- a/gobex/gobex.c +++ b/gobex/gobex.c @@ -328,7 +328,7 @@ static void prepare_connect_rsp(GObex *obex, GObexPacket *rsp) init_connect_data(obex, &data); g_obex_packet_set_data(rsp, &data, sizeof(data), G_OBEX_DATA_COPY); - connid = g_obex_packet_find_header(rsp, G_OBEX_HDR_ID_CONNECTION); + connid = g_obex_packet_find_header(rsp, G_OBEX_HDR_CONNECTION); if (connid != NULL) { g_obex_header_get_uint32(connid, &obex->conn_id); return; @@ -336,7 +336,7 @@ static void prepare_connect_rsp(GObex *obex, GObexPacket *rsp) obex->conn_id = next_connid++; - connid = g_obex_header_new_uint32(G_OBEX_HDR_ID_CONNECTION, + connid = g_obex_header_new_uint32(G_OBEX_HDR_CONNECTION, obex->conn_id); g_obex_packet_prepend_header(rsp, connid); } @@ -376,11 +376,11 @@ guint g_obex_send_req(GObex *obex, GObexPacket *req, gint timeout, if (obex->conn_id == CONNID_INVALID) goto create_pending; - connid = g_obex_packet_find_header(req, G_OBEX_HDR_ID_CONNECTION); + connid = g_obex_packet_find_header(req, G_OBEX_HDR_CONNECTION); if (connid != NULL) goto create_pending; - connid = g_obex_header_new_uint32(G_OBEX_HDR_ID_CONNECTION, + connid = g_obex_header_new_uint32(G_OBEX_HDR_CONNECTION, obex->conn_id); g_obex_packet_prepend_header(req, connid); @@ -422,7 +422,7 @@ static gboolean pending_req_abort(GObex *obex, GError **err) obex->pending_req->cancelled = TRUE; - pkt = g_obex_packet_new(G_OBEX_OP_ABORT, TRUE, G_OBEX_HDR_ID_INVALID); + pkt = g_obex_packet_new(G_OBEX_OP_ABORT, TRUE, G_OBEX_HDR_INVALID); return g_obex_send(obex, pkt, err); } @@ -558,7 +558,7 @@ static void parse_connect_data(GObex *obex, GObexPacket *pkt) obex->tx_mtu = obex->io_tx_mtu; obex->tx_buf = g_realloc(obex->tx_buf, obex->tx_mtu); - connid = g_obex_packet_find_header(pkt, G_OBEX_HDR_ID_CONNECTION); + connid = g_obex_packet_find_header(pkt, G_OBEX_HDR_CONNECTION); if (connid != NULL) g_obex_header_get_uint32(connid, &obex->conn_id); } @@ -625,7 +625,7 @@ static void handle_request(GObex *obex, GObexPacket *req) } rsp = g_obex_packet_new(G_OBEX_RSP_NOT_IMPLEMENTED, TRUE, - G_OBEX_HDR_ID_INVALID); + G_OBEX_HDR_INVALID); g_obex_send(obex, rsp, NULL); } @@ -914,15 +914,14 @@ guint g_obex_connect(GObex *obex, void *target, gsize target_len, GObexPacket *req; struct connect_data data; - req = g_obex_packet_new(G_OBEX_OP_CONNECT, TRUE, - G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(G_OBEX_OP_CONNECT, TRUE, G_OBEX_HDR_INVALID); init_connect_data(obex, &data); g_obex_packet_set_data(req, &data, sizeof(data), G_OBEX_DATA_COPY); if (target != NULL) { GObexHeader *hdr; - hdr = g_obex_header_new_bytes(G_OBEX_HDR_ID_TARGET, + hdr = g_obex_header_new_bytes(G_OBEX_HDR_TARGET, target, target_len); g_obex_packet_add_header(req, hdr); } @@ -936,7 +935,7 @@ guint g_obex_setpath(GObex *obex, const char *path, GObexResponseFunc func, GObexPacket *req; struct setpath_data data; - req = g_obex_packet_new(G_OBEX_OP_SETPATH, TRUE, G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(G_OBEX_OP_SETPATH, TRUE, G_OBEX_HDR_INVALID); memset(&data, 0, sizeof(data)); @@ -945,7 +944,7 @@ guint g_obex_setpath(GObex *obex, const char *path, GObexResponseFunc func, else { GObexHeader *hdr; data.flags = 0x02; - hdr = g_obex_header_new_unicode(G_OBEX_HDR_ID_NAME, path); + hdr = g_obex_header_new_unicode(G_OBEX_HDR_NAME, path); g_obex_packet_add_header(req, hdr); } @@ -961,11 +960,10 @@ guint g_obex_mkdir(GObex *obex, const char *path, GObexResponseFunc func, GObexHeader *hdr; struct setpath_data data; - req = g_obex_packet_new(G_OBEX_OP_SETPATH, TRUE, - G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(G_OBEX_OP_SETPATH, TRUE, G_OBEX_HDR_INVALID); memset(&data, 0, sizeof(data)); - hdr = g_obex_header_new_unicode(G_OBEX_HDR_ID_NAME, path); + hdr = g_obex_header_new_unicode(G_OBEX_HDR_NAME, path); g_obex_packet_add_header(req, hdr); g_obex_packet_set_data(req, &data, sizeof(data), G_OBEX_DATA_COPY); @@ -979,9 +977,9 @@ guint g_obex_delete(GObex *obex, const char *name, GObexResponseFunc func, GObexPacket *req; GObexHeader *hdr; - req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_INVALID); - hdr = g_obex_header_new_unicode(G_OBEX_HDR_ID_NAME, name); + hdr = g_obex_header_new_unicode(G_OBEX_HDR_NAME, name); g_obex_packet_add_header(req, hdr); return g_obex_send_req(obex, req, -1, func, user_data, err); diff --git a/tools/obex-server-tool.c b/tools/obex-server-tool.c index bfb6877ae..6d2e75b92 100644 --- a/tools/obex-server-tool.c +++ b/tools/obex-server-tool.c @@ -83,7 +83,7 @@ static void handle_put(GObex *obex, GObexPacket *req, gpointer user_data) const char *type, *name; gsize type_len; - hdr = g_obex_packet_find_header(req, G_OBEX_HDR_ID_TYPE); + hdr = g_obex_packet_find_header(req, G_OBEX_HDR_TYPE); if (hdr != NULL) { g_obex_header_get_bytes(hdr, (const guint8 **) &type, &type_len); @@ -94,7 +94,7 @@ static void handle_put(GObex *obex, GObexPacket *req, gpointer user_data) } else type = NULL; - hdr = g_obex_packet_find_header(req, G_OBEX_HDR_ID_NAME); + hdr = g_obex_packet_find_header(req, G_OBEX_HDR_NAME); if (hdr != NULL) g_obex_header_get_unicode(hdr, &name); else @@ -116,8 +116,7 @@ static void handle_connect(GObex *obex, GObexPacket *req, gpointer user_data) g_print("connect\n"); - rsp = g_obex_packet_new(G_OBEX_RSP_SUCCESS, TRUE, - G_OBEX_HDR_ID_INVALID); + rsp = g_obex_packet_new(G_OBEX_RSP_SUCCESS, TRUE, G_OBEX_HDR_INVALID); g_obex_send(obex, rsp, NULL); } diff --git a/unit/test-gobex-header.c b/unit/test-gobex-header.c index 27a2ab5e1..f67b3a860 100644 --- a/unit/test-gobex-header.c +++ b/unit/test-gobex-header.c @@ -26,25 +26,25 @@ #include "util.h" -static uint8_t hdr_connid[] = { G_OBEX_HDR_ID_CONNECTION, 1, 2, 3, 4 }; -static uint8_t hdr_name_ascii[] = { G_OBEX_HDR_ID_NAME, 0x00, 0x0b, +static uint8_t hdr_connid[] = { G_OBEX_HDR_CONNECTION, 1, 2, 3, 4 }; +static uint8_t hdr_name_ascii[] = { G_OBEX_HDR_NAME, 0x00, 0x0b, 0x00, 'f', 0x00, 'o', 0x00, 'o', 0x00, 0x00 }; -static uint8_t hdr_name_umlaut[] = { G_OBEX_HDR_ID_NAME, 0x00, 0x0b, +static uint8_t hdr_name_umlaut[] = { G_OBEX_HDR_NAME, 0x00, 0x0b, 0x00, 0xe5, 0x00, 0xe4, 0x00, 0xf6, 0x00, 0x00 }; -static uint8_t hdr_body[] = { G_OBEX_HDR_ID_BODY, 0x00, 0x07, 1, 2, 3, 4 }; -static uint8_t hdr_actionid[] = { G_OBEX_HDR_ID_ACTION, 0xab }; +static uint8_t hdr_body[] = { G_OBEX_HDR_BODY, 0x00, 0x07, 1, 2, 3, 4 }; +static uint8_t hdr_actionid[] = { G_OBEX_HDR_ACTION, 0xab }; -static uint8_t hdr_uint32_nval[] = { G_OBEX_HDR_ID_CONNECTION, 1, 2 }; -static uint8_t hdr_unicode_nval_short[] = { G_OBEX_HDR_ID_NAME, 0x12, 0x34, +static uint8_t hdr_uint32_nval[] = { G_OBEX_HDR_CONNECTION, 1, 2 }; +static uint8_t hdr_unicode_nval_short[] = { G_OBEX_HDR_NAME, 0x12, 0x34, 0x00, 'a', 0x00, 'b', 0x00, 0x00 }; -static uint8_t hdr_unicode_nval_data[] = { G_OBEX_HDR_ID_NAME, 0x00, 0x01, +static uint8_t hdr_unicode_nval_data[] = { G_OBEX_HDR_NAME, 0x00, 0x01, 0x00, 'a', 0x00, 'b' }; -static uint8_t hdr_bytes_nval_short[] = { G_OBEX_HDR_ID_BODY, 0xab, 0xcd, +static uint8_t hdr_bytes_nval_short[] = { G_OBEX_HDR_BODY, 0xab, 0xcd, 0x01, 0x02, 0x03 }; -static uint8_t hdr_bytes_nval_data[] = { G_OBEX_HDR_ID_BODY, 0xab }; +static uint8_t hdr_bytes_nval_data[] = { G_OBEX_HDR_BODY, 0xab }; static void test_header_name_ascii(void) { @@ -52,7 +52,7 @@ static void test_header_name_ascii(void) uint8_t buf[1024]; size_t len; - header = g_obex_header_new_unicode(G_OBEX_HDR_ID_NAME, "foo"); + header = g_obex_header_new_unicode(G_OBEX_HDR_NAME, "foo"); g_assert(header != NULL); @@ -69,7 +69,7 @@ static void test_header_name_umlaut(void) uint8_t buf[1024]; size_t len; - header = g_obex_header_new_unicode(G_OBEX_HDR_ID_NAME, "åäö"); + header = g_obex_header_new_unicode(G_OBEX_HDR_NAME, "åäö"); g_assert(header != NULL); @@ -86,8 +86,7 @@ static void test_header_bytes(void) uint8_t buf[1024], data[] = { 1, 2, 3, 4 }; size_t len; - header = g_obex_header_new_bytes(G_OBEX_HDR_ID_BODY, data, - sizeof(data)); + header = g_obex_header_new_bytes(G_OBEX_HDR_BODY, data, sizeof(data)); g_assert(header != NULL); len = g_obex_header_encode(header, buf, sizeof(buf)); @@ -103,7 +102,7 @@ static void test_header_uint8(void) uint8_t buf[1024]; size_t len; - header = g_obex_header_new_uint8(G_OBEX_HDR_ID_ACTION, 0xab); + header = g_obex_header_new_uint8(G_OBEX_HDR_ACTION, 0xab); g_assert(header != NULL); @@ -120,9 +119,7 @@ static void test_header_uint32(void) uint8_t buf[1024]; size_t len; - header = g_obex_header_new_uint32(G_OBEX_HDR_ID_CONNECTION, - 0x01020304); - + header = g_obex_header_new_uint32(G_OBEX_HDR_CONNECTION, 0x01020304); len = g_obex_header_encode(header, buf, sizeof(buf)); assert_memequal(hdr_connid, sizeof(hdr_connid), buf, len); diff --git a/unit/test-gobex-packet.c b/unit/test-gobex-packet.c index d3e482537..20d4804c8 100644 --- a/unit/test-gobex-packet.c +++ b/unit/test-gobex-packet.c @@ -28,32 +28,32 @@ static uint8_t pkt_connect[] = { G_OBEX_OP_CONNECT, 0x00, 0x0c, 0x10, 0x00, 0x10, 0x00, - G_OBEX_HDR_ID_TARGET, + G_OBEX_HDR_TARGET, 0x00, 0x05, 0xab, 0xcd }; static uint8_t pkt_put_action[] = { G_OBEX_OP_PUT, 0x00, 0x05, - G_OBEX_HDR_ID_ACTION, 0xab }; + G_OBEX_HDR_ACTION, 0xab }; static uint8_t pkt_put_body[] = { G_OBEX_OP_PUT, 0x00, 0x0a, - G_OBEX_HDR_ID_BODY, 0x00, 0x07, + G_OBEX_HDR_BODY, 0x00, 0x07, 1, 2, 3, 4 }; static uint8_t pkt_put[] = { G_OBEX_OP_PUT, 0x00, 0x03 }; static uint8_t pkt_nval_len[] = { G_OBEX_OP_PUT, 0xab, 0xcd, 0x12 }; static guint8 pkt_put_long[] = { G_OBEX_OP_PUT, 0x00, 0x32, - G_OBEX_HDR_ID_CONNECTION, 0x01, 0x02, 0x03, 0x04, - G_OBEX_HDR_ID_TYPE, 0x00, 0x0b, + G_OBEX_HDR_CONNECTION, 0x01, 0x02, 0x03, 0x04, + G_OBEX_HDR_TYPE, 0x00, 0x0b, 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0', - G_OBEX_HDR_ID_NAME, 0x00, 0x15, + G_OBEX_HDR_NAME, 0x00, 0x15, 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0, - G_OBEX_HDR_ID_ACTION, 0xab, - G_OBEX_HDR_ID_BODY, 0x00, 0x08, + G_OBEX_HDR_ACTION, 0xab, + G_OBEX_HDR_BODY, 0x00, 0x08, 0, 1, 2, 3, 4 }; static void test_pkt(void) { GObexPacket *pkt; - pkt = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_ID_INVALID); + pkt = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_INVALID); g_assert(pkt != NULL); @@ -84,7 +84,7 @@ static void test_decode_pkt_header(void) 0, G_OBEX_DATA_REF, &err); g_assert_no_error(err); - header = g_obex_packet_get_header(pkt, G_OBEX_HDR_ID_ACTION); + header = g_obex_packet_get_header(pkt, G_OBEX_HDR_ACTION); g_assert(header != NULL); ret = g_obex_header_get_uint8(header, &val); @@ -109,7 +109,7 @@ static void test_decode_connect(void) g_assert_no_error(err); g_assert(pkt != NULL); - header = g_obex_packet_get_header(pkt, G_OBEX_HDR_ID_TARGET); + header = g_obex_packet_get_header(pkt, G_OBEX_HDR_TARGET); g_assert(header != NULL); ret = g_obex_header_get_bytes(header, &buf, &len); @@ -169,7 +169,7 @@ static void test_encode_on_demand(void) uint8_t buf[255]; gssize len; - pkt = g_obex_packet_new(G_OBEX_OP_PUT, FALSE, G_OBEX_HDR_ID_INVALID); + pkt = g_obex_packet_new(G_OBEX_OP_PUT, FALSE, G_OBEX_HDR_INVALID); g_obex_packet_add_body(pkt, get_body_data, NULL); len = g_obex_packet_encode(pkt, buf, sizeof(buf)); @@ -194,7 +194,7 @@ static void test_encode_on_demand_fail(void) uint8_t buf[255]; gssize len; - pkt = g_obex_packet_new(G_OBEX_OP_PUT, FALSE, G_OBEX_HDR_ID_INVALID); + pkt = g_obex_packet_new(G_OBEX_OP_PUT, FALSE, G_OBEX_HDR_INVALID); g_obex_packet_add_body(pkt, get_body_data_fail, NULL); len = g_obex_packet_encode(pkt, buf, sizeof(buf)); @@ -211,12 +211,12 @@ static void test_create_args(void) gssize len; pkt = g_obex_packet_new(G_OBEX_OP_PUT, FALSE, - G_OBEX_HDR_ID_CONNECTION, 0x01020304, - G_OBEX_HDR_ID_TYPE, "foo/bar", strlen("foo/bar") + 1, - G_OBEX_HDR_ID_NAME, "file.txt", - G_OBEX_HDR_ID_ACTION, 0xab, - G_OBEX_HDR_ID_BODY, body, sizeof(body), - G_OBEX_HDR_ID_INVALID); + G_OBEX_HDR_CONNECTION, 0x01020304, + G_OBEX_HDR_TYPE, "foo/bar", strlen("foo/bar") + 1, + G_OBEX_HDR_NAME, "file.txt", + G_OBEX_HDR_ACTION, 0xab, + G_OBEX_HDR_BODY, body, sizeof(body), + G_OBEX_HDR_INVALID); g_assert(pkt != NULL); diff --git a/unit/test-gobex-transfer.c b/unit/test-gobex-transfer.c index cf391f098..595a49ced 100644 --- a/unit/test-gobex-transfer.c +++ b/unit/test-gobex-transfer.c @@ -35,33 +35,33 @@ #define FINAL_BIT 0x80 static guint8 put_req_first[] = { G_OBEX_OP_PUT | FINAL_BIT, 0x00, 0x30, - G_OBEX_HDR_ID_TYPE, 0x00, 0x0b, + G_OBEX_HDR_TYPE, 0x00, 0x0b, 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0', - G_OBEX_HDR_ID_NAME, 0x00, 0x15, + G_OBEX_HDR_NAME, 0x00, 0x15, 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0, - G_OBEX_HDR_ID_BODY, 0x00, 0x0d, + G_OBEX_HDR_BODY, 0x00, 0x0d, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; static guint8 put_req_last[] = { G_OBEX_OP_PUT | FINAL_BIT, 0x00, 0x06, - G_OBEX_HDR_ID_BODY_END, 0x00, 0x03 }; + G_OBEX_HDR_BODY_END, 0x00, 0x03 }; static guint8 put_rsp_first[] = { G_OBEX_RSP_CONTINUE | FINAL_BIT, 0x00, 0x03 }; static guint8 put_rsp_last[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00, 0x03 }; static guint8 get_req_first[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x23, - G_OBEX_HDR_ID_TYPE, 0x00, 0x0b, + G_OBEX_HDR_TYPE, 0x00, 0x0b, 'f', 'o', 'o', '/', 'b', 'a', 'r', '\0', - G_OBEX_HDR_ID_NAME, 0x00, 0x15, + G_OBEX_HDR_NAME, 0x00, 0x15, 0, 'f', 0, 'i', 0, 'l', 0, 'e', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0 }; static guint8 get_req_last[] = { G_OBEX_OP_GET | FINAL_BIT, 0x00, 0x03, }; static guint8 get_rsp_first[] = { G_OBEX_RSP_CONTINUE | FINAL_BIT, 0x00, 0x10, - G_OBEX_HDR_ID_BODY, 0x00, 0x0d, + G_OBEX_HDR_BODY, 0x00, 0x0d, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; static guint8 get_rsp_last[] = { G_OBEX_RSP_SUCCESS | FINAL_BIT, 0x00, 0x06, - G_OBEX_HDR_ID_BODY_END, 0x00, 0x03 }; + G_OBEX_HDR_BODY_END, 0x00, 0x03 }; static guint8 body_data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; @@ -274,7 +274,7 @@ static void handle_get(GObex *obex, GObexPacket *req, gpointer user_data) } id = g_obex_get_rsp(obex, provide_data, transfer_complete, d, &d->err, - G_OBEX_HDR_ID_INVALID); + G_OBEX_HDR_INVALID); if (id == 0) g_main_loop_quit(d->mainloop); } diff --git a/unit/test-gobex.c b/unit/test-gobex.c index ce40bf609..eda624621 100644 --- a/unit/test-gobex.c +++ b/unit/test-gobex.c @@ -42,7 +42,7 @@ static uint8_t pkt_connect_rsp[] = { 0x20 | FINAL_BIT, 0x00, 0x07, static uint8_t pkt_setpath_req[] = { G_OBEX_OP_SETPATH | FINAL_BIT, 0x00, 0x10, 0x02, 0x00, - G_OBEX_HDR_ID_NAME, 0x00, 0x0b, + G_OBEX_HDR_NAME, 0x00, 0x0b, 0, 'd', 0, 'i', 0, 'r', 0, 0 }; static uint8_t pkt_setpath_up_req[] = { G_OBEX_OP_SETPATH | FINAL_BIT, 0x00, 0x05, 0x03, 0x00 }; @@ -50,11 +50,11 @@ static uint8_t pkt_success_rsp[] = { 0x20 | FINAL_BIT, 0x00, 0x03 }; static uint8_t pkt_mkdir_req[] = { G_OBEX_OP_SETPATH | FINAL_BIT, 0x00, 0x10, 0x00, 0x00, - G_OBEX_HDR_ID_NAME, 0x00, 0x0b, + G_OBEX_HDR_NAME, 0x00, 0x0b, 0, 'd', 0, 'i', 0, 'r', 0, 0 }; static uint8_t pkt_delete_req[] = { G_OBEX_OP_PUT | FINAL_BIT, 0x00, 0x16, - G_OBEX_HDR_ID_NAME, 0x00, 0x13, + G_OBEX_HDR_NAME, 0x00, 0x13, 0, 'f', 0, 'o', 0, 'o', 0, '.', 0, 't', 0, 'x', 0, 't', 0, 0 }; static uint8_t pkt_nval_connect_rsp[] = { 0x10 | FINAL_BIT, 0x00, 0x05, @@ -62,7 +62,7 @@ static uint8_t pkt_nval_connect_rsp[] = { 0x10 | FINAL_BIT, 0x00, 0x05, static uint8_t pkt_abort_rsp[] = { 0x90, 0x00, 0x03 }; static uint8_t pkt_nval_short_rsp[] = { 0x10 | FINAL_BIT, 0x12 }; static uint8_t pkt_put_body[] = { G_OBEX_OP_PUT, 0x00, 0x0a, - G_OBEX_HDR_ID_BODY, 0x00, 0x07, + G_OBEX_HDR_BODY, 0x00, 0x07, 1, 2, 3, 4 }; static gboolean timeout(gpointer user_data) @@ -252,8 +252,7 @@ static void send_connect(GObexResponseFunc rsp_func, GIOFunc send_rsp_func, GObexPacket *req; guint8 connect_data[] = { 0x10, 0x00, 0x10, 0x00 }; - req = g_obex_packet_new(G_OBEX_OP_CONNECT, TRUE, - G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(G_OBEX_OP_CONNECT, TRUE, G_OBEX_HDR_INVALID); g_assert(req != NULL); g_obex_packet_set_data(req, connect_data, sizeof(connect_data), @@ -327,7 +326,7 @@ static void test_cancel_req_immediate(void) r.err = NULL; - req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_INVALID); r.id = g_obex_send_req(r.obex, req, -1, req_done, &r, &r.err); g_assert_no_error(r.err); g_assert(r.id != 0); @@ -408,7 +407,7 @@ static void test_cancel_req_delay(int transport_type) r.err = NULL; - req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(G_OBEX_OP_PUT, TRUE, G_OBEX_HDR_INVALID); r.id = g_obex_send_req(r.obex, req, -1, req_done, &r, &r.err); g_assert_no_error(r.err); g_assert(r.id != 0); @@ -503,8 +502,7 @@ static void test_send_connect(int transport_type) r.buf = pkt_connect_req; r.len = sizeof(pkt_connect_req); - req = g_obex_packet_new(G_OBEX_OP_CONNECT, TRUE, - G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(G_OBEX_OP_CONNECT, TRUE, G_OBEX_HDR_INVALID); g_assert(req != NULL); g_obex_packet_set_data(req, connect_data, sizeof(connect_data), @@ -567,8 +565,7 @@ static void test_recv_unexpected(void) g_obex_set_disconnect_function(obex, unexpected_disconn, &err); - req = g_obex_packet_new(G_OBEX_RSP_CONTINUE, TRUE, - G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(G_OBEX_RSP_CONTINUE, TRUE, G_OBEX_HDR_INVALID); len = g_obex_packet_encode(req, buf, sizeof(buf)); g_assert_cmpint(len, >=, 0); @@ -621,7 +618,7 @@ static void test_send_on_demand(int transport_type, GObexDataProducer func) r.buf = pkt_put_body; r.len = sizeof(pkt_put_body); - req = g_obex_packet_new(G_OBEX_OP_PUT, FALSE, G_OBEX_HDR_ID_INVALID); + req = g_obex_packet_new(G_OBEX_OP_PUT, FALSE, G_OBEX_HDR_INVALID); g_obex_packet_add_body(req, func, &r); g_obex_send(obex, req, &r.err); -- 2.47.3