diff options
Diffstat (limited to 'Swiften/Serializer/XMPPSerializer.cpp')
-rw-r--r-- | Swiften/Serializer/XMPPSerializer.cpp | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/Swiften/Serializer/XMPPSerializer.cpp b/Swiften/Serializer/XMPPSerializer.cpp index 7130e51..b17e31b 100644 --- a/Swiften/Serializer/XMPPSerializer.cpp +++ b/Swiften/Serializer/XMPPSerializer.cpp @@ -41,72 +41,72 @@ namespace Swift { XMPPSerializer::XMPPSerializer(PayloadSerializerCollection* payloadSerializers, StreamType type, bool setExplictNSonTopLevelElements) : type_(type) { - serializers_.push_back(boost::make_shared<PresenceSerializer>(payloadSerializers, setExplictNSonTopLevelElements ? getDefaultNamespace() : boost::optional<std::string>())); - serializers_.push_back(boost::make_shared<IQSerializer>(payloadSerializers, setExplictNSonTopLevelElements ? getDefaultNamespace() : boost::optional<std::string>())); - serializers_.push_back(boost::make_shared<MessageSerializer>(payloadSerializers, setExplictNSonTopLevelElements ? getDefaultNamespace() : boost::optional<std::string>())); - serializers_.push_back(boost::make_shared<CompressRequestSerializer>()); - serializers_.push_back(boost::make_shared<CompressFailureSerializer>()); - serializers_.push_back(boost::make_shared<AuthRequestSerializer>()); - serializers_.push_back(boost::make_shared<AuthFailureSerializer>()); - serializers_.push_back(boost::make_shared<AuthSuccessSerializer>()); - serializers_.push_back(boost::make_shared<AuthChallengeSerializer>()); - serializers_.push_back(boost::make_shared<AuthResponseSerializer>()); - serializers_.push_back(boost::make_shared<StartTLSRequestSerializer>()); - serializers_.push_back(boost::make_shared<StartTLSFailureSerializer>()); - serializers_.push_back(boost::make_shared<TLSProceedSerializer>()); - serializers_.push_back(boost::make_shared<StreamFeaturesSerializer>()); - serializers_.push_back(boost::make_shared<StreamErrorSerializer>()); - serializers_.push_back(boost::make_shared<EnableStreamManagementSerializer>()); - serializers_.push_back(boost::make_shared<StreamManagementEnabledSerializer>()); - serializers_.push_back(boost::make_shared<StreamManagementFailedSerializer>()); - serializers_.push_back(boost::make_shared<StreamResumeSerializer>()); - serializers_.push_back(boost::make_shared<StreamResumedSerializer>()); - serializers_.push_back(boost::make_shared<StanzaAckSerializer>()); - serializers_.push_back(boost::make_shared<StanzaAckRequestSerializer>()); - serializers_.push_back(boost::make_shared<ComponentHandshakeSerializer>()); + serializers_.push_back(boost::make_shared<PresenceSerializer>(payloadSerializers, setExplictNSonTopLevelElements ? getDefaultNamespace() : boost::optional<std::string>())); + serializers_.push_back(boost::make_shared<IQSerializer>(payloadSerializers, setExplictNSonTopLevelElements ? getDefaultNamespace() : boost::optional<std::string>())); + serializers_.push_back(boost::make_shared<MessageSerializer>(payloadSerializers, setExplictNSonTopLevelElements ? getDefaultNamespace() : boost::optional<std::string>())); + serializers_.push_back(boost::make_shared<CompressRequestSerializer>()); + serializers_.push_back(boost::make_shared<CompressFailureSerializer>()); + serializers_.push_back(boost::make_shared<AuthRequestSerializer>()); + serializers_.push_back(boost::make_shared<AuthFailureSerializer>()); + serializers_.push_back(boost::make_shared<AuthSuccessSerializer>()); + serializers_.push_back(boost::make_shared<AuthChallengeSerializer>()); + serializers_.push_back(boost::make_shared<AuthResponseSerializer>()); + serializers_.push_back(boost::make_shared<StartTLSRequestSerializer>()); + serializers_.push_back(boost::make_shared<StartTLSFailureSerializer>()); + serializers_.push_back(boost::make_shared<TLSProceedSerializer>()); + serializers_.push_back(boost::make_shared<StreamFeaturesSerializer>()); + serializers_.push_back(boost::make_shared<StreamErrorSerializer>()); + serializers_.push_back(boost::make_shared<EnableStreamManagementSerializer>()); + serializers_.push_back(boost::make_shared<StreamManagementEnabledSerializer>()); + serializers_.push_back(boost::make_shared<StreamManagementFailedSerializer>()); + serializers_.push_back(boost::make_shared<StreamResumeSerializer>()); + serializers_.push_back(boost::make_shared<StreamResumedSerializer>()); + serializers_.push_back(boost::make_shared<StanzaAckSerializer>()); + serializers_.push_back(boost::make_shared<StanzaAckRequestSerializer>()); + serializers_.push_back(boost::make_shared<ComponentHandshakeSerializer>()); } std::string XMPPSerializer::serializeHeader(const ProtocolHeader& header) const { - std::string result = "<?xml version=\"1.0\"?><stream:stream xmlns=\"" + getDefaultNamespace() + "\" xmlns:stream=\"http://etherx.jabber.org/streams\""; - if (!header.getFrom().empty()) { - result += " from=\"" + header.getFrom() + "\""; - } - if (!header.getTo().empty()) { - result += " to=\"" + header.getTo() + "\""; - } - if (!header.getID().empty()) { - result += " id=\"" + header.getID() + "\""; - } - if (!header.getVersion().empty()) { - result += " version=\"" + header.getVersion() + "\""; - } - result += ">"; - return result; + std::string result = "<?xml version=\"1.0\"?><stream:stream xmlns=\"" + getDefaultNamespace() + "\" xmlns:stream=\"http://etherx.jabber.org/streams\""; + if (!header.getFrom().empty()) { + result += " from=\"" + header.getFrom() + "\""; + } + if (!header.getTo().empty()) { + result += " to=\"" + header.getTo() + "\""; + } + if (!header.getID().empty()) { + result += " id=\"" + header.getID() + "\""; + } + if (!header.getVersion().empty()) { + result += " version=\"" + header.getVersion() + "\""; + } + result += ">"; + return result; } SafeByteArray XMPPSerializer::serializeElement(boost::shared_ptr<ToplevelElement> element) const { - std::vector< boost::shared_ptr<ElementSerializer> >::const_iterator i = std::find_if(serializers_.begin(), serializers_.end(), boost::bind(&ElementSerializer::canSerialize, _1, element)); - if (i != serializers_.end()) { - return (*i)->serialize(element); - } - else { - std::cerr << "Could not find serializer for " << typeid(*(element.get())).name() << std::endl; - return createSafeByteArray(""); - } + std::vector< boost::shared_ptr<ElementSerializer> >::const_iterator i = std::find_if(serializers_.begin(), serializers_.end(), boost::bind(&ElementSerializer::canSerialize, _1, element)); + if (i != serializers_.end()) { + return (*i)->serialize(element); + } + else { + std::cerr << "Could not find serializer for " << typeid(*(element.get())).name() << std::endl; + return createSafeByteArray(""); + } } std::string XMPPSerializer::serializeFooter() const { - return "</stream:stream>"; + return "</stream:stream>"; } std::string XMPPSerializer::getDefaultNamespace() const { - switch (type_) { - case ClientStreamType: return "jabber:client"; - case ServerStreamType: return "jabber:server"; - case ComponentStreamType: return "jabber:component:accept"; - } - assert(false); - return ""; + switch (type_) { + case ClientStreamType: return "jabber:client"; + case ServerStreamType: return "jabber:server"; + case ComponentStreamType: return "jabber:component:accept"; + } + assert(false); + return ""; } } |