Ejemplo n.º 1
0
void Util::addErrorToStanza(XmlElement& stanza,
                            const std::string& errorType,
                            const std::string& condition,
                            const std::string& ns,
                            const std::string& appSpecificCondition,
                            const std::string& appSpecificNs)
{
    xmpp_stanza_t* stanzaPtr {stanza.getStanzaPtr()};
    xmpp_ctx_t* ctx {stanzaPtr->ctx};
    xmpp_stanza_t* errorElem {xmpp_stanza_new(ctx)};
    xmpp_stanza_t* cond {xmpp_stanza_new(ctx)};
    
    xmpp_stanza_set_name(errorElem, "error");
    xmpp_stanza_set_type(errorElem, errorType.c_str());
    xmpp_stanza_set_name(cond, condition.c_str());
    xmpp_stanza_set_ns(cond, ns.c_str());
    xmpp_stanza_add_child(errorElem, cond);

    if(not appSpecificCondition.empty() and not appSpecificNs.empty())
    {
        xmpp_stanza_t* otherCond {xmpp_stanza_new(ctx)};

        xmpp_stanza_set_name(otherCond, appSpecificCondition.c_str());
        xmpp_stanza_set_ns(otherCond, appSpecificNs.c_str());
        xmpp_stanza_add_child(errorElem, otherCond);
    }

    xmpp_stanza_set_attribute(stanzaPtr, "type", "error");
    xmpp_stanza_add_child(stanzaPtr, errorElem);
}
Ejemplo n.º 2
0
void Util::switchFromTo(XmlElement& stanza)
{
    xmpp_stanza_t* stanzaPtr {stanza.getStanzaPtr()};
    std::string from {makeString(xmpp_stanza_get_attribute(stanzaPtr, "from"))};
    std::string to {makeString(xmpp_stanza_get_attribute(stanzaPtr, "to"))};
    xmpp_stanza_set_attribute(stanzaPtr, "from", to.c_str());
    xmpp_stanza_set_attribute(stanzaPtr, "to", from.c_str());
}
Ejemplo n.º 3
0
XData Util::parseXData(const XmlElement& el)
{
    xmpp_stanza_t* elPtr {el.getStanzaPtr()};
    xmpp_stanza_t* field {xmpp_stanza_get_children(elPtr)};  

    std::string type {makeString(xmpp_stanza_get_type(elPtr))};
     
    XData ret {type};

    while(field)
    {
        if(makeString(xmpp_stanza_get_name(field)) == "field")
        {
            std::string fieldType {makeString(xmpp_stanza_get_type(field))};
            std::string var {makeString(xmpp_stanza_get_attribute(field, "var"))};

            std::vector<std::string> values;

            xmpp_stanza_t* value {xmpp_stanza_get_children(field)};

            while(value)
            {
                if(makeString(xmpp_stanza_get_name(value)) == "value")
                {
                    char* text {xmpp_stanza_get_text(value)};
                    values.emplace_back(makeString(text));
                    xmpp_free(value->ctx, text);
                }

                value = xmpp_stanza_get_next(value);
            }

            XData::Field newField {fieldType, var, values};

            if(not newField.isValid())
            {
                throw std::runtime_error {""};
            }

            ret.addField(newField);
        }

        field = xmpp_stanza_get_next(field);
    }

    return ret;
}