Index: src/XMPPConnection.m ================================================================== --- src/XMPPConnection.m +++ src/XMPPConnection.m @@ -572,27 +572,12 @@ handled = [delegate connection: self didReceiveIQ: iq]; if (!handled && ![[iq type] isEqual: @"error"] && ![[iq type] isEqual: @"result"]) { - XMPPJID *from = [iq from]; - XMPPJID *to = [iq to]; - OFXMLElement *error; - - [iq setType: @"error"]; - [iq setTo: from]; - [iq setFrom: to]; - - error = [OFXMLElement elementWithName: @"error"]; - [error addAttributeWithName: @"type" - stringValue: @"cancel"]; - [error addChild: - [OFXMLElement elementWithName: @"service-unavailable" - namespace: XMPP_NS_STANZAS]]; - [iq addChild: error]; - - [self sendStanza: iq]; + [self sendStanza: [iq errorIQWithType: @"cancel" + condition: @"service-unavailable"]]; } } - (void)XMPP_handleMessage: (XMPPMessage*)message { Index: src/XMPPIQ.h ================================================================== --- src/XMPPIQ.h +++ src/XMPPIQ.h @@ -44,6 +44,35 @@ * \param ID The value for the stanza's id attribute * \return A initialized XMPPIQ */ - initWithType: (OFString*)type ID: (OFString*)ID; + +/** + * Generates a result IQ for the receiving object + * + * \return A new autoreleased XMPPIQ + */ +- (XMPPIQ*)resultIQ; + +/** + * Generates a error IQ for the receiving object + * + * \param type A error type as defined by RFC 6120 + * \param condition A error condition as defined by RFC 6120 + * \param text A descriptive text + * \return A new autoreleased XMPPIQ + */ +- (XMPPIQ*)errorIQWithType: (OFString*)type + condition: (OFString*)condition + text: (OFString*)text; + +/** + * Generates a error IQ for the receiving object + * + * \param type A error type as defined by RFC 6120 + * \param condition A defined conditions from RFC 6120 + * \return A new autoreleased XMPPIQ + */ +- (XMPPIQ*)errorIQWithType: (OFString*)type + condition: (OFString*)condition; @end Index: src/XMPPIQ.m ================================================================== --- src/XMPPIQ.m +++ src/XMPPIQ.m @@ -19,10 +19,11 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#import "namespaces.h" #import "XMPPIQ.h" @implementation XMPPIQ + IQWithType: (OFString*)type_ ID: (OFString*)ID_ @@ -48,6 +49,50 @@ @throw e; } return self; } + +- (XMPPIQ*)resultIQ +{ + XMPPIQ *ret = [XMPPIQ IQWithType: @"result" + ID: [self ID]]; + [ret setTo: [self from]]; + [ret setFrom: nil]; + return ret; +} + +- (XMPPIQ*)errorIQWithType: (OFString*)type_ + condition: (OFString*)condition + text: (OFString*)text +{ + XMPPIQ *ret = [XMPPIQ IQWithType: @"error" + ID: [self ID]]; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFXMLElement *error = [OFXMLElement elementWithName: @"error" + namespace: XMPP_NS_CLIENT]; + + [error addAttributeWithName: @"type" + stringValue: type_]; + [error addChild: [OFXMLElement elementWithName: condition + namespace: XMPP_NS_STANZAS]]; + if (text) + [error addChild: [OFXMLElement elementWithName: @"text" + namespace: XMPP_NS_STANZAS + stringValue: text]]; + [ret addChild: error]; + [ret setTo: [self from]]; + [ret setFrom: nil]; + + [pool release]; + + return ret; +} + +- (XMPPIQ*)errorIQWithType: (OFString*)type_ + condition: (OFString*)condition +{ + return [self errorIQWithType: type_ + condition: condition + text: nil]; +} @end Index: src/XMPPRoster.m ================================================================== --- src/XMPPRoster.m +++ src/XMPPRoster.m @@ -160,14 +160,11 @@ [[connection delegate] connection: connection didReceiveRosterItem: rosterItem]; } if (isPush) { - XMPPIQ *response = [XMPPIQ IQWithType: @"result" - ID: [iq ID]]; - [response setTo: [iq from]]; - [connection sendStanza: response]; + [connection sendStanza: [iq resultIQ]]; } else { if ([[connection delegate] respondsToSelector: @selector(connectionDidReceiveRoster:)]) [[connection delegate] connectionDidReceiveRoster: connection];