summaryrefslogtreecommitdiffstats
path: root/Sluift
diff options
context:
space:
mode:
Diffstat (limited to 'Sluift')
-rw-r--r--Sluift/ElementConvertors/IQConvertor.cpp2
-rw-r--r--Sluift/ElementConvertors/MessageConvertor.cpp2
-rw-r--r--Sluift/ElementConvertors/PresenceConvertor.cpp2
3 files changed, 6 insertions, 0 deletions
diff --git a/Sluift/ElementConvertors/IQConvertor.cpp b/Sluift/ElementConvertors/IQConvertor.cpp
index 8a8e463..d90c864 100644
--- a/Sluift/ElementConvertors/IQConvertor.cpp
+++ b/Sluift/ElementConvertors/IQConvertor.cpp
@@ -25,48 +25,50 @@ boost::shared_ptr<IQ> IQConvertor::doConvertFromLua(lua_State* L) {
boost::shared_ptr<IQ> result = getStanza(L, convertors);
lua_getfield(L, -1, "type");
if (lua_isstring(L, -1)) {
result->setType(IQConvertor::convertIQTypeFromString(lua_tostring(L, -1)));
}
lua_pop(L, 1);
return result;
}
void IQConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<IQ> stanza) {
pushStanza(L, stanza, convertors);
const std::string type = IQConvertor::convertIQTypeToString(stanza->getType());
lua_pushstring(L, type.c_str());
lua_setfield(L, -2, "type");
}
boost::optional<LuaElementConvertor::Documentation> IQConvertor::getDocumentation() const {
return Documentation(
"IQ",
"This table has the following fields:\n\n"
"- `type`: string\n"
"- `id`: string\n"
"- `from`: string\n"
"- `to`: string\n"
"- `payloads`: array<@{Payload}>\n"
);
}
std::string IQConvertor::convertIQTypeToString(IQ::Type type) {
switch (type) {
case IQ::Get: return "get";
case IQ::Set: return "set";
case IQ::Result: return "result";
case IQ::Error: return "error";
}
+ assert(false);
+ return "";
}
IQ::Type IQConvertor::convertIQTypeFromString(const std::string& type) {
if (type == "get") {
return IQ::Get;
}
else if (type == "set") {
return IQ::Set;
}
else {
throw Lua::Exception("Illegal query type: '" + type + "'");
}
}
diff --git a/Sluift/ElementConvertors/MessageConvertor.cpp b/Sluift/ElementConvertors/MessageConvertor.cpp
index 9994bd0..0bc7fbb 100644
--- a/Sluift/ElementConvertors/MessageConvertor.cpp
+++ b/Sluift/ElementConvertors/MessageConvertor.cpp
@@ -26,57 +26,59 @@ boost::shared_ptr<Message> MessageConvertor::doConvertFromLua(lua_State* L) {
lua_getfield(L, -1, "type");
if (lua_isstring(L, -1)) {
result->setType(convertMessageTypeFromString(lua_tostring(L, -1)));
}
lua_pop(L, 1);
return result;
}
void MessageConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<Message> stanza) {
pushStanza(L, stanza, convertors);
const std::string type = convertMessageTypeToString(stanza->getType());
lua_pushstring(L, type.c_str());
lua_setfield(L, -2, "type");
}
boost::optional<LuaElementConvertor::Documentation> MessageConvertor::getDocumentation() const {
return Documentation(
"Message",
"This table has the following fields:\n\n"
"- `type`: string\n"
"- `id`: string\n"
"- `from`: string\n"
"- `to`: string\n"
"- `payloads`: array<@{Payload}>\n"
);
}
std::string MessageConvertor::convertMessageTypeToString(Message::Type type) {
switch (type) {
case Message::Normal: return "normal";
case Message::Chat: return "chat";
case Message::Error: return "error";
case Message::Groupchat: return "groupchat";
case Message::Headline: return "headline";
}
+ assert(false);
+ return "";
}
Message::Type MessageConvertor::convertMessageTypeFromString(const std::string& type) {
if (type == "normal") {
return Message::Normal;
}
else if (type == "chat") {
return Message::Chat;
}
else if (type == "error") {
return Message::Error;
}
else if (type == "groupchat") {
return Message::Groupchat;
}
else if (type == "headline") {
return Message::Headline;
}
else {
throw Lua::Exception("Illegal message type: '" + type + "'");
}
}
diff --git a/Sluift/ElementConvertors/PresenceConvertor.cpp b/Sluift/ElementConvertors/PresenceConvertor.cpp
index ea6bbb8..3725dd2 100644
--- a/Sluift/ElementConvertors/PresenceConvertor.cpp
+++ b/Sluift/ElementConvertors/PresenceConvertor.cpp
@@ -29,66 +29,68 @@ boost::shared_ptr<Presence> PresenceConvertor::doConvertFromLua(lua_State* L) {
}
lua_pop(L, 1);
return result;
}
void PresenceConvertor::doConvertToLua(lua_State* L, boost::shared_ptr<Presence> stanza) {
pushStanza(L, stanza, convertors);
const std::string type = convertPresenceTypeToString(stanza->getType());
lua_pushstring(L, type.c_str());
lua_setfield(L, -2, "type");
}
boost::optional<LuaElementConvertor::Documentation> PresenceConvertor::getDocumentation() const {
return Documentation(
"Presence",
"This table has the following fields:\n\n"
"- `type`: string\n"
"- `id`: string\n"
"- `from`: string\n"
"- `to`: string\n"
"- `payloads`: array<@{Payload}>\n"
);
}
std::string PresenceConvertor::convertPresenceTypeToString(Presence::Type type) {
switch (type) {
case Presence::Available: return "available";
case Presence::Error: return "error";
case Presence::Probe: return "probe";
case Presence::Subscribe: return "subscribe";
case Presence::Subscribed: return "subscribed";
case Presence::Unavailable: return "unavailable";
case Presence::Unsubscribe: return "unsubscribe";
case Presence::Unsubscribed: return "unsubscribed";
}
+ assert(false);
+ return "";
}
Presence::Type PresenceConvertor::convertPresenceTypeFromString(const std::string& type) {
if (type == "available") {
return Presence::Available;
}
else if (type == "error") {
return Presence::Error;
}
else if (type == "probe") {
return Presence::Probe;
}
else if (type == "subscribe") {
return Presence::Subscribe;
}
else if (type == "subscribed") {
return Presence::Subscribed;
}
else if (type == "unavailable") {
return Presence::Unavailable;
}
else if (type == "unsubscribe") {
return Presence::Unsubscribe;
}
else if (type == "unsubscribed") {
return Presence::Unsubscribed;
}
else {
throw Lua::Exception("Illegal presence type: '" + type + "'");
}
}