Skip to content

Commit 53f97ce

Browse files
committed
Added documentation
1 parent 1cea842 commit 53f97ce

File tree

2 files changed

+104
-5
lines changed

2 files changed

+104
-5
lines changed

Extensions/XEP-0077/XMPPRegistration.h

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,40 @@
1010

1111
#define _XMPP_REGISTRATION_H
1212

13-
@interface XMPPRegistration : XMPPModule
14-
{
13+
@interface XMPPRegistration : XMPPModule {
1514
XMPPIDTracker *xmppIDTracker;
1615
}
1716

17+
/**
18+
* This method will attempt to change the current user's password to the new one provided. The
19+
* user *MUST* be authenticated for this to work successfully.
20+
*
21+
* @see passwordChangeSuccessful:
22+
* @see passwordChangeFailed:withError:
23+
*
24+
* @param newPassword The new password for the user
25+
*/
1826
- (BOOL)changePassword:(NSString *)newPassword;
27+
28+
/**
29+
* This method will attempt to cancel the current user's registration. Later implementations
30+
* will provide support for handling authentication challenges by the server. For now,
31+
* simply pass a value of 'nil' in for password, or preferably, use the other cancellation
32+
* method.
33+
*
34+
* @see cancelRegistration
35+
*/
1936
- (BOOL)cancelRegistrationUsingPassword:(NSString *)password;
2037

38+
/**
39+
* This method will attempt to cancel the current user's registration. The user *MUST* be
40+
* already authenticated for this to work successfully.
41+
*
42+
* @see cancelRegistrationSuccessful:
43+
* @see cancelRegistrationFailed:withError:
44+
*/
45+
- (BOOL)cancelRegistration;
46+
2147
@end
2248

2349
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -27,10 +53,42 @@
2753
@protocol XMPPRegistrationDelegate
2854
@optional
2955

56+
/**
57+
* Implement this method when calling [regInstance changePassword:]. It will be invoked
58+
* if the request for changing the user's password is successfully executed and receives a
59+
* successful response.
60+
*
61+
* @param sender XMPPRegistration object invoking this delegate method.
62+
*/
3063
- (void)passwordChangeSuccessful:(XMPPRegistration *)sender;
64+
65+
/**
66+
* Implement this method when calling [regInstance changePassword:]. It will be invoked
67+
* if the request for changing the user's password is unsuccessfully executed or receives
68+
* an unsuccessful response.
69+
*
70+
* @param sender XMPPRegistration object invoking this delegate method.
71+
* @param error NSError containing more details of the failure.
72+
*/
3173
- (void)passwordChangeFailed:(XMPPRegistration *)sender withError:(NSError *)error;
3274

75+
/**
76+
* Implement this method when calling [regInstance cancelRegistration] or a variation. It
77+
* is invoked if the request for canceling the user's registration is successfully
78+
* executed and receives a successful response.
79+
*
80+
* @param sender XMPPRegistration object invoking this delegate method.
81+
*/
3382
- (void)cancelRegistrationSuccessful:(XMPPRegistration *)sender;
83+
84+
/**
85+
* Implement this method when calling [regInstance cancelRegistration] or a variation. It
86+
* is invoked if the request for canceling the user's registration is unsuccessfully
87+
* executed or receives an unsuccessful response.
88+
*
89+
* @param sender XMPPRegistration object invoking this delegate method.
90+
* @param error NSError containing more details of the failure.
91+
*/
3492
- (void)cancelRegistrationFailed:(XMPPRegistration *)sender withError:(NSError *)error;
3593

3694
@end

Extensions/XEP-0077/XMPPRegistration.m

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ - (void)willDeactivate
2828
#pragma mark Public API
2929
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3030

31+
/**
32+
* This method provides functionality of XEP-0077 3.3 User Changes Password.
33+
*
34+
* @link {http://xmpp.org/extensions/xep-0077.html#usecases-changepw}
35+
*
36+
* Example 18. Password Change
37+
*
38+
* <iq type='set' to='shakespeare.lit' id='change1'>
39+
* <query xmlns='jabber:iq:register'>
40+
* <username>bill</username>
41+
* <password>newpass</password>
42+
* </query>
43+
* </iq>
44+
*
45+
*/
3146
- (BOOL)changePassword:(NSString *)newPassword
3247
{
3348
if (![xmppStream isAuthenticated])
@@ -51,9 +66,9 @@ - (BOOL)changePassword:(NSString *)newPassword
5166
child:query];
5267

5368
[xmppIDTracker addID:[iq elementID]
54-
target:self
55-
selector:@selector(handlePasswordChangeQueryIQ:withInfo:)
56-
timeout:60];
69+
target:self
70+
selector:@selector(handlePasswordChangeQueryIQ:withInfo:)
71+
timeout:60];
5772

5873
[xmppStream sendElement:iq];
5974
}
@@ -67,6 +82,26 @@ - (BOOL)changePassword:(NSString *)newPassword
6782
return YES;
6883
}
6984

85+
/**
86+
* This method provides functionality of XEP-0077 3.2 Entity Cancels an Existing Registration.
87+
*
88+
* @link {http://xmpp.org/extensions/xep-0077.html#usecases-cancel}
89+
*
90+
* <iq type='set' from='[email protected]/globe' id='unreg1'>
91+
* <query xmlns='jabber:iq:register'>
92+
* <remove/>
93+
* </query>
94+
* </iq>
95+
*
96+
*/
97+
- (BOOL)cancelRegistration
98+
{
99+
return [self cancelRegistrationUsingPassword:nil];
100+
}
101+
102+
/**
103+
* Same as cancelRegistration. Handling authentication challenges is not yet implemented.
104+
*/
70105
- (BOOL)cancelRegistrationUsingPassword:(NSString *)password
71106
{
72107
// TODO: Handle the scenario of using password
@@ -102,6 +137,9 @@ - (BOOL)cancelRegistrationUsingPassword:(NSString *)password
102137
#pragma mark - XMPPIDTracker
103138
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
104139

140+
/**
141+
* This method handles the response received (or not received) after calling changePassword.
142+
*/
105143
- (void)handlePasswordChangeQueryIQ:(XMPPIQ *)iq withInfo:(XMPPBasicTrackingInfo *)info
106144
{
107145
dispatch_block_t block = ^{
@@ -140,6 +178,9 @@ - (void)handlePasswordChangeQueryIQ:(XMPPIQ *)iq withInfo:(XMPPBasicTrackingInfo
140178
dispatch_async(moduleQueue, block);
141179
}
142180

181+
/**
182+
* This method handles the response received (or not received) after calling cancelRegistration.
183+
*/
143184
- (void)handleRegistrationCancelQueryIQ:(XMPPIQ *)iq withInfo:(XMPPBasicTrackingInfo *)info
144185
{
145186
dispatch_block_t block = ^{

0 commit comments

Comments
 (0)