#include <errno.h>
#include "gobex-apparam.h"
+#include "gobex-debug.h"
struct _GObexApparam {
GHashTable *tags;
GObexApparam *g_obex_apparam_set_uint8(GObexApparam *apparam, guint8 id,
guint8 value)
{
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "tag 0x%02x value %u", id, value);
+
return g_obex_apparam_set_bytes(apparam, id, &value, 1);
}
{
guint16 num = g_htons(value);
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "tag 0x%02x value %u", id, value);
+
return g_obex_apparam_set_bytes(apparam, id, &num, 2);
}
{
guint32 num = g_htonl(value);
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "tag 0x%02x value %u", id, value);
+
return g_obex_apparam_set_bytes(apparam, id, &num, 4);
}
{
guint64 num = GUINT64_TO_BE(value);
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "tag 0x%02x value %"
+ G_GUINT64_FORMAT, id, value);
+
return g_obex_apparam_set_bytes(apparam, id, &num, 8);
}
{
gsize len;
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "tag 0x%02x value %s", id, value);
+
len = strlen(value) + 1;
if (len > G_MAXUINT8) {
((char *) value)[G_MAXUINT8 - 1] = '\0';
{
struct apparam_tag *tag;
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "tag 0x%02x", id);
+
tag = g_hash_table_lookup(apparam->tags, GUINT_TO_POINTER(id));
if (tag == NULL)
return FALSE;
*dest = tag->value.u8;
+
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "%u", *dest);
+
return TRUE;
}
{
struct apparam_tag *tag;
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "tag 0x%02x", id);
+
tag = g_hash_table_lookup(apparam->tags, GUINT_TO_POINTER(id));
if (tag == NULL)
return FALSE;
return FALSE;
*dest = g_ntohs(tag->value.u16);
+
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "%u", *dest);
+
return TRUE;
}
{
struct apparam_tag *tag;
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "tag 0x%02x", id);
+
tag = g_hash_table_lookup(apparam->tags, GUINT_TO_POINTER(id));
if (tag == NULL)
return FALSE;
return FALSE;
*dest = g_ntohl(tag->value.u32);
+
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "%u", *dest);
+
return TRUE;
}
{
struct apparam_tag *tag;
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "tag 0x%02x", id);
+
tag = g_hash_table_lookup(apparam->tags, GUINT_TO_POINTER(id));
if (tag == NULL)
return FALSE;
return FALSE;
*dest = GUINT64_FROM_BE(tag->value.u64);
+
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "%" G_GUINT64_FORMAT, *dest);
+
return TRUE;
}
char *g_obex_apparam_get_string(GObexApparam *apparam, guint8 id)
{
struct apparam_tag *tag;
+ char *string;
+
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "tag 0x%02x", id);
tag = g_hash_table_lookup(apparam->tags, GUINT_TO_POINTER(id));
if (tag == NULL)
return NULL;
- return g_strndup(tag->value.string, tag->len);
+ string = g_strndup(tag->value.string, tag->len);
+
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "%s", string);
+
+ return string;
}
gboolean g_obex_apparam_get_bytes(GObexApparam *apparam, guint8 id,
{
struct apparam_tag *tag;
+ g_obex_debug(G_OBEX_DEBUG_APPARAM, "tag 0x%02x", id);
+
tag = g_hash_table_lookup(apparam->tags, GUINT_TO_POINTER(id));
if (tag == NULL)
return FALSE;
#define G_OBEX_DEBUG_HEADER (1 << 4)
#define G_OBEX_DEBUG_PACKET (1 << 5)
#define G_OBEX_DEBUG_DATA (1 << 6)
+#define G_OBEX_DEBUG_APPARAM (1 << 7)
extern guint gobex_debug;
g_log("gobex", G_LOG_LEVEL_DEBUG, "%s:%s() " format, __FILE__, \
__FUNCTION__, ## __VA_ARGS__)
-static inline void g_obex_dump(const char *prefix, const void *buf,
- gsize len)
+static inline void g_obex_dump(guint level, const char *prefix,
+ const void *buf, gsize len)
{
const guint8 *data = buf;
int n = 0;
- if (!(gobex_debug & G_OBEX_DEBUG_DATA))
+ if (!(gobex_debug & level))
return;
while (len > 0) {
if (status != G_IO_STATUS_NORMAL)
return FALSE;
- g_obex_dump("<", buf, bytes_written);
+ g_obex_dump(G_OBEX_DEBUG_DATA, "<", buf, bytes_written);
obex->tx_sent += bytes_written;
obex->tx_data -= bytes_written;
if (bytes_written != obex->tx_data)
return FALSE;
- g_obex_dump("<", buf, bytes_written);
+ g_obex_dump(G_OBEX_DEBUG_DATA, "<", buf, bytes_written);
obex->tx_sent += bytes_written;
obex->tx_data -= bytes_written;
} while (rbytes > 0 && obex->rx_data < obex->rx_pkt_len);
done:
- g_obex_dump(">", obex->rx_buf, obex->rx_data);
+ g_obex_dump(G_OBEX_DEBUG_DATA, ">", obex->rx_buf, obex->rx_data);
return TRUE;
}
return FALSE;
}
- g_obex_dump(">", obex->rx_buf, obex->rx_data);
+ g_obex_dump(G_OBEX_DEBUG_DATA, ">", obex->rx_buf, obex->rx_data);
return TRUE;
fail:
{ "header", G_OBEX_DEBUG_HEADER },
{ "packet", G_OBEX_DEBUG_PACKET },
{ "data", G_OBEX_DEBUG_DATA },
+ { "apparam", G_OBEX_DEBUG_APPARAM },
};
GObex *g_obex_new(GIOChannel *io, GObexTransportType transport_type,
const char *env = g_getenv("GOBEX_DEBUG");
if (env) {
- gobex_debug = g_parse_debug_string(env, keys, 6);
+ gobex_debug = g_parse_debug_string(env, keys, 7);
g_setenv("G_MESSAGES_DEBUG", "gobex", FALSE);
} else
gobex_debug = G_OBEX_DEBUG_NONE;