Merge pull request #744 from psychon/dbus-string

Some dbus.c string-related things.
This commit is contained in:
Daniel Hahler 2016-03-07 00:26:00 +01:00
commit 395a8285e5
1 changed files with 10 additions and 11 deletions

21
dbus.c
View File

@ -315,18 +315,16 @@ a_dbus_convert_value(lua_State *L, int idx, DBusMessageIter *iter)
dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &b);
}
break;
#define DBUS_MSG_RETURN_HANDLE_TYPE_STRING(dbustype) \
case dbustype: \
{ \
const char *s = lua_tostring(L, idx + 1); \
if(!s) \
s = ""; \
dbus_message_iter_append_basic(iter, dbustype, &s); \
} \
case DBUS_TYPE_STRING:
{
const char *s = lua_tostring(L, idx + 1);
if(!s || !dbus_validate_utf8(s, NULL)) {
luaA_warn(L, "Your D-Bus signal handling method returned an invalid string");
return false;
}
dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &s);
}
break;
DBUS_MSG_RETURN_HANDLE_TYPE_STRING(DBUS_TYPE_STRING)
DBUS_MSG_RETURN_HANDLE_TYPE_STRING(DBUS_TYPE_BYTE)
#undef DBUS_MSG_RETURN_HANDLE_TYPE_STRING
#define DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER(type, dbustype) \
case dbustype: \
{ \
@ -334,6 +332,7 @@ a_dbus_convert_value(lua_State *L, int idx, DBusMessageIter *iter)
dbus_message_iter_append_basic(iter, dbustype, &num); \
} \
break;
DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER(uint8_t, DBUS_TYPE_BYTE)
DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER(int16_t, DBUS_TYPE_INT16)
DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER(uint16_t, DBUS_TYPE_UINT16)
DBUS_MSG_RETURN_HANDLE_TYPE_NUMBER(int32_t, DBUS_TYPE_INT32)