Fixed error response element construction. Add received element's children, not the element itself.
git-svn-id: http://voip.null.ro/svn/yate@2189 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
parent
d7f7b4a01f
commit
1cb2ec4b44
|
@ -868,10 +868,7 @@ bool JBEngine::processCommand(JBEvent* event)
|
|||
return false;
|
||||
|
||||
// Send error
|
||||
XMLElement* err = XMPPUtils::createIq(XMPPUtils::IqError,event->to(),event->from(),event->id());
|
||||
err->addChild(event->releaseXML());
|
||||
err->addChild(XMPPUtils::createError(XMPPError::TypeCancel,XMPPError::SFeatureNotImpl));
|
||||
stream->sendStanza(err);
|
||||
stream->sendStanza(event->createError(XMPPError::TypeCancel,XMPPError::SFeatureNotImpl));
|
||||
TelEngine::destruct(event);
|
||||
return true;
|
||||
}
|
||||
|
@ -1029,23 +1026,19 @@ XMLElement* JBEvent::createError(XMPPError::ErrorType type, XMPPError::Type erro
|
|||
case IqCommandSet:
|
||||
case IqJingleGet:
|
||||
case IqJingleSet:
|
||||
xml = XMPPUtils::createIq(XMPPUtils::IqError,to(),from(),id());
|
||||
break;
|
||||
case Message:
|
||||
if (JBMessage::Error == JBMessage::msgType(element()->getAttribute("type")))
|
||||
return 0;
|
||||
xml = JBMessage::createMessage(JBMessage::Error,to(),from(),id(),0);
|
||||
break;
|
||||
case Presence:
|
||||
if (JBPresence::Error == JBPresence::presenceType(element()->getAttribute("type")))
|
||||
return 0;
|
||||
xml = JBPresence::createPresence(to(),from(),JBPresence::Error);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
xml->addChild(releaseXML());
|
||||
xml->addChild(XMPPUtils::createError(type,error,text));
|
||||
xml = XMPPUtils::createError(releaseXML(),type,error,text);
|
||||
return xml;
|
||||
}
|
||||
|
||||
|
@ -2002,11 +1995,8 @@ bool JBPresence::accept(JBEvent* event, bool& processed, bool& insert)
|
|||
Debug(this,DebugNote,"Received element with invalid domain '%s' [%p]",
|
||||
jid.domain().c_str(),this);
|
||||
// Respond only if stanza is not a response
|
||||
if (event->stanzaType() != "error" && event->stanzaType() != "result") {
|
||||
const String* id = event->id().null() ? 0 : &(event->id());
|
||||
sendError(XMPPError::SNoRemote,event->to(),event->from(),
|
||||
event->releaseXML(),event->stream(),id);
|
||||
}
|
||||
if (event->stanzaType() != "error" && event->stanzaType() != "result")
|
||||
sendStanza(event->createError(XMPPError::TypeModify,XMPPError::SNoRemote),event->stream());
|
||||
}
|
||||
processed = true;
|
||||
return true;
|
||||
|
@ -2063,8 +2053,8 @@ bool JBPresence::process()
|
|||
"Received unexpected presence type=%s from=%s to=%s [%p]",
|
||||
event->element()->getAttribute("type"),event->from().c_str(),
|
||||
event->to().c_str(),this);
|
||||
sendError(XMPPError::SFeatureNotImpl,event->to(),event->from(),
|
||||
event->releaseXML(),event->stream());
|
||||
sendStanza(event->createError(XMPPError::TypeModify,XMPPError::SFeatureNotImpl),
|
||||
event->stream());
|
||||
break;
|
||||
}
|
||||
processPresence(event);
|
||||
|
@ -2175,8 +2165,8 @@ void JBPresence::processProbe(JBEvent* event)
|
|||
TelEngine::destruct(stanza);
|
||||
}
|
||||
else if (!notifyProbe(event) && !m_ignoreNonRoster)
|
||||
sendError(XMPPError::SItemNotFound,event->to(),event->from(),
|
||||
event->releaseXML(),event->stream());
|
||||
sendStanza(event->createError(XMPPError::TypeModify,XMPPError::SItemNotFound),
|
||||
event->stream());
|
||||
return;
|
||||
}
|
||||
if (newUser)
|
||||
|
@ -2203,8 +2193,8 @@ void JBPresence::processSubscribe(JBEvent* event, Presence presence)
|
|||
if (!notifySubscribe(event,presence) &&
|
||||
(presence != Subscribed && presence != Unsubscribed) &&
|
||||
!m_ignoreNonRoster)
|
||||
sendError(XMPPError::SItemNotFound,event->to(),event->from(),
|
||||
event->releaseXML(),event->stream());
|
||||
sendStanza(event->createError(XMPPError::TypeModify,XMPPError::SItemNotFound),
|
||||
event->stream());
|
||||
return;
|
||||
}
|
||||
if (newUser)
|
||||
|
@ -2244,8 +2234,8 @@ void JBPresence::processUnavailable(JBEvent* event)
|
|||
addLocal,0,addLocal,&newUser);
|
||||
if (!user) {
|
||||
if (!notifyPresence(event,false) && !m_ignoreNonRoster)
|
||||
sendError(XMPPError::SItemNotFound,event->to(),event->from(),
|
||||
event->releaseXML(),event->stream());
|
||||
sendStanza(event->createError(XMPPError::TypeModify,XMPPError::SItemNotFound),
|
||||
event->stream());
|
||||
return;
|
||||
}
|
||||
if (newUser)
|
||||
|
@ -2283,8 +2273,8 @@ void JBPresence::processPresence(JBEvent* event)
|
|||
m_addOnPresence.from(),0,m_addOnPresence.from(),&newUser);
|
||||
if (!user) {
|
||||
if (!notifyPresence(event,true) && !m_ignoreNonRoster)
|
||||
sendError(XMPPError::SItemNotFound,event->to(),event->from(),
|
||||
event->releaseXML(),event->stream());
|
||||
sendStanza(event->createError(XMPPError::TypeModify,XMPPError::SItemNotFound),
|
||||
event->stream());
|
||||
return;
|
||||
}
|
||||
if (newUser)
|
||||
|
@ -2415,23 +2405,6 @@ bool JBPresence::sendStanza(XMLElement* element, JBStream* stream)
|
|||
return true;
|
||||
}
|
||||
|
||||
// Send an error stanza
|
||||
bool JBPresence::sendError(XMPPError::Type type,
|
||||
const String& from, const String& to,
|
||||
XMLElement* element, JBStream* stream, const String* id)
|
||||
{
|
||||
XMLElement* xml = 0;
|
||||
XMLElement::Type t = element ? element->type() : XMLElement::Invalid;
|
||||
if (t == XMLElement::Iq)
|
||||
xml = XMPPUtils::createIq(XMPPUtils::IqError,from,to,
|
||||
id ? id->c_str() : element->getAttribute("id"));
|
||||
else
|
||||
xml = createPresence(from,to,Error);
|
||||
xml->addChild(element);
|
||||
xml->addChild(XMPPUtils::createError(XMPPError::TypeModify,type));
|
||||
return sendStanza(xml,stream);
|
||||
}
|
||||
|
||||
// Create a presence stanza
|
||||
XMLElement* JBPresence::createPresence(const char* from,
|
||||
const char* to, Presence type)
|
||||
|
|
|
@ -300,9 +300,9 @@ bool JGSession::confirm(XMLElement* xml, XMPPError::Type error,
|
|||
{
|
||||
if (!xml)
|
||||
return false;
|
||||
String id = xml->getAttribute("id");
|
||||
XMLElement* iq = 0;
|
||||
if (error == XMPPError::NoError) {
|
||||
String id = xml->getAttribute("id");
|
||||
iq = XMPPUtils::createIq(XMPPUtils::IqResult,m_localJID,m_remoteJID,id);
|
||||
// The receiver will detect which stanza is confirmed by id
|
||||
// If missing, make a copy of the received element and attach it to the error
|
||||
|
@ -311,11 +311,8 @@ bool JGSession::confirm(XMLElement* xml, XMPPError::Type error,
|
|||
iq->addChild(copy);
|
||||
}
|
||||
}
|
||||
else {
|
||||
iq = XMPPUtils::createIq(XMPPUtils::IqError,m_localJID,m_remoteJID,id);
|
||||
iq->addChild(xml);
|
||||
iq->addChild(XMPPUtils::createError(type,error,text));
|
||||
}
|
||||
else
|
||||
iq = XMPPUtils::createError(xml,type,error,text);
|
||||
return sendStanza(iq,0,false);
|
||||
}
|
||||
|
||||
|
|
|
@ -443,7 +443,12 @@ XMLElement* XMPPUtils::createError(XMLElement* xml, XMPPError::ErrorType type,
|
|||
if (!xml)
|
||||
return 0;
|
||||
XMLElement* err = new XMLElement(*xml,true,false);
|
||||
err->addChild(xml);
|
||||
// Copy children from xml to the error element
|
||||
XMLElement* child = 0;
|
||||
while (0 != (child = xml->removeChild()))
|
||||
err->addChild(child);
|
||||
TelEngine::destruct(xml);
|
||||
// Create the error
|
||||
err->addChild(createError(type,error,text));
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -1907,20 +1907,6 @@ public:
|
|||
*/
|
||||
bool sendStanza(XMLElement* element, JBStream* stream);
|
||||
|
||||
/**
|
||||
* Send an error. Error type is 'modify'.
|
||||
* If id is 0 sent element will be of type 'presence'. Otherwise: 'iq'
|
||||
* @param type The error
|
||||
* @param from The from attribute
|
||||
* @param to The to attribute
|
||||
* @param element The element that generated the error
|
||||
* @param stream Optional stream to use
|
||||
* @param id Optional id. If present (even if empty) the error element will be of type 'iq'
|
||||
* @return The result of send operation
|
||||
*/
|
||||
bool sendError(XMPPError::Type type, const String& from, const String& to,
|
||||
XMLElement* element, JBStream* stream = 0, const String* id = 0);
|
||||
|
||||
/**
|
||||
* Create an 'presence' element
|
||||
* @param from The 'from' attribute
|
||||
|
|
Loading…
Reference in New Issue