diff options
author | Samuel Ortiz <sameo@linux.intel.com> | 2012-10-25 18:58:06 +0200 |
---|---|---|
committer | Arron Wang <arron.wang@intel.com> | 2014-11-25 15:27:32 +0800 |
commit | 947a28f4000b4638316f30f88f124d87fbdda218 (patch) | |
tree | 90124a4cb4bde2ecaa01e7ee2d58fce4ee3ee849 /src | |
parent | 453bba444a4e1de8efd4a36aea521ca47f04b53d (diff) | |
download | neard-947a28f4000b4638316f30f88f124d87fbdda218.tar.gz neard-947a28f4000b4638316f30f88f124d87fbdda218.tar.bz2 neard-947a28f4000b4638316f30f88f124d87fbdda218.zip |
ndef: Support RAW ndef writes
Change-Id: I21a341b2482556458e381b4a3033ef3e9313194c
Diffstat (limited to 'src')
-rw-r--r-- | src/ndef.c | 61 |
1 files changed, 61 insertions, 0 deletions
@@ -3618,6 +3618,64 @@ static struct near_ndef_message *build_mime_record(DBusMessage *msg) return NULL; } +static struct near_ndef_message * build_raw_ndef(DBusMessage *msg) +{ + DBusMessageIter iter, arr_iter; + struct near_ndef_message *ndef; + + DBG(""); + + ndef = NULL; + + dbus_message_iter_init(msg, &iter); + dbus_message_iter_recurse(&iter, &arr_iter); + + while (dbus_message_iter_get_arg_type(&arr_iter) != + DBUS_TYPE_INVALID) { + const char *key; + DBusMessageIter ent_iter; + DBusMessageIter var_iter; + + dbus_message_iter_recurse(&arr_iter, &ent_iter); + dbus_message_iter_get_basic(&ent_iter, &key); + dbus_message_iter_next(&ent_iter); + dbus_message_iter_recurse(&ent_iter, &var_iter); + + switch (dbus_message_iter_get_arg_type(&var_iter)) { + case DBUS_TYPE_ARRAY: + if (g_strcmp0(key, "NDEF") == 0) { + DBusMessageIter array; + uint8_t *data; + int data_size; + + dbus_message_iter_recurse(&var_iter, &array); + dbus_message_iter_get_fixed_array(&array, + &data, + &data_size); + + ndef = g_try_malloc0(data_size); + if (ndef == NULL) + break; + + ndef->data = g_try_malloc0(data_size); + if (ndef->data == NULL) { + g_free(ndef); + break; + } + + ndef->length = data_size; + memcpy(ndef->data, data, data_size); + } + + break; + } + + dbus_message_iter_next(&arr_iter); + } + + return ndef; +} + struct near_ndef_message *__ndef_build_from_message(DBusMessage *msg) { DBusMessageIter iter; @@ -3672,6 +3730,9 @@ struct near_ndef_message *__ndef_build_from_message(DBusMessage *msg) } else if (g_strcmp0(value, "MIME") == 0) { ndef = build_mime_record(msg); break; + } else if (g_strcmp0(value, "Raw") == 0) { + ndef = build_raw_ndef(msg); + break; } else { near_error("%s not supported", value); ndef = NULL; |