Skip to content

Commit

Permalink
#269 parse errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Anurodh Pokharel committed Jan 4, 2020
1 parent 1b8f25b commit 244e8da
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Monal/Classes/XMPPParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
NSString* _resource;
NSString* _idval;

NSString* _errorType;
NSString* _errorReason;

}


Expand Down Expand Up @@ -53,6 +56,16 @@
*/
@property (nonatomic, strong, readonly) NSString* idval;

/**
if error, the type
*/
@property (nonatomic, strong, readonly) NSString* errorType;

/**
if error, the reason
*/
@property (nonatomic, strong, readonly) NSString* errorReason;


- (id) initWithDictionary:(NSDictionary*) dictionary;

Expand Down
13 changes: 13 additions & 0 deletions Monal/Classes/XMPPParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName nam
//remove any resource markers and get user
_user=[[_user lowercaseString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

if([elementName isEqualToString:@"error"])
{
_errorType=[attributeDict objectForKey:@"type"];
return;
}


if([[attributeDict objectForKey:kXMLNS] isEqualToString:@"urn:ietf:params:xml:ns:xmpp-stanzas"])
{
if(!_errorReason) _errorReason=elementName;
return;
}

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
Expand Down
4 changes: 1 addition & 3 deletions Monal/Classes/xmpp.m
Original file line number Diff line number Diff line change
Expand Up @@ -2208,9 +2208,7 @@ -(void) sendMessage:(NSString*) message toContact:(NSString*) contact isMUC:(BOO
}

//for MAM
MLXMLNode *request =[[MLXMLNode alloc] initWithElement:@"store"];
[request.attributes setObject:@"urn:xmpp:hints" forKey:kXMLNS];
[messageNode.children addObject:request];
[messageNode setStoreHint];

if(self.airDrop) {
DDLogInfo(@"Writing to file for Airdop");
Expand Down
19 changes: 19 additions & 0 deletions Monal/Monal Tests/XMPP Tests/MLMessageProcessorTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ - (void)testmucMessage {

}

- (void)testerrorMessage {
NSString *sample= @"<message type='error' from='reject@yax.im' to='anu@yax.im/Monal-iOS.78' id='A2481A6F-8CD8-444F-8190-1BFE312938AE'><error type='cancel'><not-allowed xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>Error handling test</text></error></message>";

NSDictionary *stanzaToParse =@{@"stanzaType":@"message", @"stanzaString":sample};
XCTNSNotificationExpectation *expectation=[[XCTNSNotificationExpectation alloc] initWithName:kMonalNewMessageNotice object:nil];
expectation.handler = ^BOOL(NSNotification * _Nonnull notification) {
MLMessage *message = [[notification userInfo] objectForKey:@"message"];

return YES;
};

ParseMessage* messageNode= [[ParseMessage alloc] initWithDictionary:stanzaToParse];
MLMessageProcessor *processor = [[MLMessageProcessor alloc] initWithAccount:self.accountNo jid:self.jid signalContex:self.signalContext andSignalStore:self.monalSignalStore];

[processor processMessage:messageNode];
// [self waitForExpectations:@[expectation] timeout:5];

}


/*
<message from='monal_muc@chat.yax.im/sim' to='anu@yax.im/Monal-iOS.31' id='4A2BAC34-EF67-4E73-960C-433B3D9E21C6' type='groupchat'><body>Odd</body><store xmlns='urn:xmpp:hints'/><stanza-id id='3j1b3NLEdPyOZDSs' by='monal_muc@chat.yax.im' xmlns='urn:xmpp:sid:0'/></message>
Expand Down

0 comments on commit 244e8da

Please sign in to comment.