Skip to content

Commit

Permalink
Modernize XMPPBindResult enum
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisballinger committed Oct 9, 2017
1 parent 4535d6f commit a5b473d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
24 changes: 15 additions & 9 deletions Authentication/XMPPCustomBinding.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@

typedef NS_ENUM(NSInteger, XMPPBindResult) {

XMPP_BIND_CONTINUE, // The custom binding process is still ongoing.
XMPPBindResultContinue, // The custom binding process is still ongoing.

XMPP_BIND_SUCCESS, // Custom binding succeeded.
XMPPBindResultSuccess, // Custom binding succeeded.
// The stream should continue normal post-binding operation.

XMPP_BIND_FAIL_FALLBACK, // Custom binding failed.
XMPPBindResultFailFallback, // Custom binding failed.
// The stream should fallback to the standard binding protocol.

XMPP_BIND_FAIL_ABORT // Custom binding failed.
XMPPBindResultFailAbort // Custom binding failed.
// The stream must abort the binding process.
// Further, because the stream is in a bad state (authenticated, but
// unable to complete the full handshake) it must immediately disconnect.
// The given NSError will be reported via xmppStreamDidDisconnect:withError:
};

// Legacy fallback for external modules
#define XMPP_BIND_CONTINUE XMPPBindResultContinue
#define XMPP_BIND_SUCCESS XMPPBindResultSuccess
#define XMPP_BIND_FAIL_FALLBACK XMPPBindResultFailFallback
#define XMPP_BIND_FAIL_ABORT XMPPBindResultFailAbort

/**
* Binding a JID resource is a standard part of the authentication process,
* and occurs after SASL authentication completes (which generally authenticates the JID username).
Expand All @@ -39,16 +45,16 @@ typedef NS_ENUM(NSInteger, XMPPBindResult) {
* Attempts to start the custom binding process.
*
* If it isn't possible to start the process (perhaps due to missing information),
* this method should return XMPP_BIND_FAIL_FALLBACK or XMPP_BIND_FAIL_ABORT.
* this method should return XMPPBindResultFailFallback or XMPPBindResultFailAbort.
*
* (The error message is only used by xmppStream if this method returns XMPP_BIND_FAIL_ABORT.)
* (The error message is only used by xmppStream if this method returns XMPPBindResultFailAbort.)
*
* If binding isn't needed (for example, because custom SASL authentication already handled it),
* this method should return XMPP_BIND_SUCCESS.
* this method should return XMPPBindResultSuccess.
* In this case, xmppStream will immediately move to its post-binding operations.
*
* Otherwise this method should send whatever stanzas are needed to begin the binding process.
* And then return XMPP_BIND_CONTINUE.
* And then return XMPPBindResultContinue.
*
* This method is called by automatically XMPPStream.
* You MUST NOT invoke this method manually.
Expand All @@ -58,7 +64,7 @@ typedef NS_ENUM(NSInteger, XMPPBindResult) {
/**
* After the custom binding process has started, all incoming xmpp stanzas are routed to this method.
* The method should process the stanza as appropriate, and return the coresponding result.
* If the process is not yet complete, it should return XMPP_BIND_CONTINUE,
* If the process is not yet complete, it should return XMPPBindResultContinue,
* meaning the xmpp stream will continue to forward all incoming xmpp stanzas to this method.
*
* This method is called automatically by XMPPStream.
Expand Down
16 changes: 8 additions & 8 deletions Core/XMPPStream.m
Original file line number Diff line number Diff line change
Expand Up @@ -3749,14 +3749,14 @@ - (void)startCustomBinding:(id <XMPPCustomBinding>)delegateCustomBinding
NSError *bindError = nil;
XMPPBindResult result = [customBinding start:&bindError];

if (result == XMPP_BIND_CONTINUE)
if (result == XMPPBindResultContinue)
{
// Expected result
// Wait for reply from server, and forward to customBinding module.
}
else
{
if (result == XMPP_BIND_SUCCESS)
if (result == XMPPBindResultSuccess)
{
// It appears binding isn't needed (perhaps handled via auth)

Expand All @@ -3767,14 +3767,14 @@ - (void)startCustomBinding:(id <XMPPCustomBinding>)delegateCustomBinding

[self continuePostBinding:skipStartSessionOverride];
}
else if (result == XMPP_BIND_FAIL_FALLBACK)
else if (result == XMPPBindResultFailFallback)
{
// Custom binding isn't available for whatever reason,
// but the module has requested we fallback to standard binding.

[self startStandardBinding];
}
else if (result == XMPP_BIND_FAIL_ABORT)
else if (result == XMPPBindResultFailAbort)
{
// Custom binding failed,
// and the module requested we abort.
Expand All @@ -3794,13 +3794,13 @@ - (void)handleCustomBinding:(NSXMLElement *)response
NSError *bindError = nil;
XMPPBindResult result = [customBinding handleBind:response withError:&bindError];

if (result == XMPP_BIND_CONTINUE)
if (result == XMPPBindResultContinue)
{
// Binding still in progress
}
else
{
if (result == XMPP_BIND_SUCCESS)
if (result == XMPPBindResultSuccess)
{
// Binding complete. Continue.

Expand All @@ -3811,14 +3811,14 @@ - (void)handleCustomBinding:(NSXMLElement *)response

[self continuePostBinding:skipStartSessionOverride];
}
else if (result == XMPP_BIND_FAIL_FALLBACK)
else if (result == XMPPBindResultFailFallback)
{
// Custom binding failed for whatever reason,
// but the module has requested we fallback to standard binding.

[self startStandardBinding];
}
else if (result == XMPP_BIND_FAIL_ABORT)
else if (result == XMPPBindResultFailAbort)
{
// Custom binding failed,
// and the module requested we abort.
Expand Down
14 changes: 7 additions & 7 deletions Extensions/XEP-0198/XMPPStreamManagement.m
Original file line number Diff line number Diff line change
Expand Up @@ -684,11 +684,11 @@ - (BOOL)didResumeWithAckedStanzaIds:(NSArray **)stanzaIdsPtr
* this method should return XMPP_BIND_FAIL and set an appropriate error message.
*
* If binding isn't needed (for example, because custom SASL authentication already handled it),
* this method should return XMPP_BIND_SUCCESS.
* this method should return XMPPBindResultSuccess.
* In this case, xmppStream will immediately move to its post-binding operations.
*
* Otherwise this method should send whatever stanzas are needed to begin the binding process.
* And then return XMPP_BIND_CONTINUE.
* And then return XMPPBindResultContinue.
*
* This method is called by automatically XMPPStream.
* You MUST NOT invoke this method manually.
Expand All @@ -711,19 +711,19 @@ - (XMPPBindResult)start:(NSError **)errPtr

if (![self canResumeStreamWithResumptionId:resumptionId timeout:timeout lastDisconnect:lastDisconnect])
{
return XMPP_BIND_FAIL_FALLBACK;
return XMPPBindResultFailFallback;
}

// Start the resume proces
[self sendResumeRequestWithResumptionId:resumptionId];

return XMPP_BIND_CONTINUE;
return XMPPBindResultContinue;
}

/**
* After the custom binding process has started, all incoming xmpp stanzas are routed to this method.
* The method should process the stanza as appropriate, and return the coresponding result.
* If the process is not yet complete, it should return XMPP_BIND_CONTINUE,
* If the process is not yet complete, it should return XMPPBindResultContinue,
* meaning the xmpp stream will continue to forward all incoming xmpp stanzas to this method.
*
* This method is called automatically by XMPPStream.
Expand All @@ -739,7 +739,7 @@ - (XMPPBindResult)handleBind:(NSXMLElement *)element withError:(NSError **)errPt
{
[self processResumed:element];

return XMPP_BIND_SUCCESS;
return XMPPBindResultSuccess;
}
else
{
Expand All @@ -755,7 +755,7 @@ - (XMPPBindResult)handleBind:(NSXMLElement *)element withError:(NSError **)errPt
prev_unackedByServer = nil;
}});

return XMPP_BIND_FAIL_FALLBACK;
return XMPPBindResultFailFallback;
}
}

Expand Down

0 comments on commit a5b473d

Please sign in to comment.