@@ -36,11 +36,11 @@ internal class PushServiceSocket
36
36
private static readonly string CREATE_ACCOUNT_SMS_PATH = "/v1/accounts/sms/code/{0}" ;
37
37
private static readonly string CREATE_ACCOUNT_VOICE_PATH = "/v1/accounts/voice/code/{0}" ;
38
38
private static readonly string VERIFY_ACCOUNT_CODE_PATH = "/v1/accounts/code/{0}" ;
39
- private static readonly string VERIFY_ACCOUNT_TOKEN_PATH = "/v1/accounts/token/{0}" ;
40
39
private static readonly string REGISTER_GCM_PATH = "/v1/accounts/gcm/" ;
41
40
private static readonly string REQUEST_TOKEN_PATH = "/v1/accounts/token" ;
42
41
private static readonly string TURN_SERVER_INFO = "/v1/accounts/turn" ;
43
42
private static readonly string SET_ACCOUNT_ATTRIBUTES = "/v1/accounts/attributes" ;
43
+ private static readonly String PIN_PATH = "/v1/accounts/pin/" ;
44
44
45
45
private static readonly string PREKEY_METADATA_PATH = "/v2/keys/" ;
46
46
private static readonly string PREKEY_PATH = "/v2/keys/{0}" ;
@@ -77,26 +77,20 @@ public bool CreateAccount(bool voice)
77
77
return true ;
78
78
}
79
79
80
- public bool VerifyAccountCode ( string verificationCode , string signalingKey , uint registrationId , bool fetchesMessages )
80
+ public bool VerifyAccountCode ( string verificationCode , string signalingKey , uint registrationId , bool fetchesMessages , string pin )
81
81
{
82
- AccountAttributes signalingKeyEntity = new AccountAttributes ( signalingKey , registrationId , fetchesMessages ) ;
82
+ AccountAttributes signalingKeyEntity = new AccountAttributes ( signalingKey , registrationId , fetchesMessages , pin ) ;
83
83
MakeServiceRequest ( string . Format ( VERIFY_ACCOUNT_CODE_PATH , verificationCode ) , "PUT" , JsonUtil . toJson ( signalingKeyEntity ) ) ;
84
84
return true ;
85
85
}
86
86
87
- public bool SetAccountAttributes ( string signalingKey , uint registrationId , bool fetchesMessages )
87
+ public bool SetAccountAttributes ( string signalingKey , uint registrationId , bool fetchesMessages , string pin )
88
88
{
89
- AccountAttributes accountAttributesEntity = new AccountAttributes ( signalingKey , registrationId , fetchesMessages ) ;
89
+ AccountAttributes accountAttributesEntity = new AccountAttributes ( signalingKey , registrationId , fetchesMessages , pin ) ;
90
90
MakeServiceRequest ( SET_ACCOUNT_ATTRIBUTES , "PUT" , JsonUtil . toJson ( accountAttributesEntity ) ) ;
91
91
return true ;
92
92
}
93
93
94
- public string GetAccountVerificationToken ( ) // throws IOException
95
- {
96
- string responseText = MakeServiceRequest ( REQUEST_TOKEN_PATH , "GET" , null ) ;
97
- return JsonUtil . fromJson < AuthorizationToken > ( responseText ) . Token ;
98
- }
99
-
100
94
public int FinishNewDeviceRegistration ( String code , String signalingKey , bool supportsSms , bool fetchesMessages , int registrationId , String deviceName )
101
95
{
102
96
ConfirmCodeMessage javaJson = new ConfirmCodeMessage ( signalingKey , supportsSms , fetchesMessages , registrationId , deviceName ) ;
@@ -142,6 +136,17 @@ public void UnregisterGcmId()
142
136
MakeServiceRequest ( REGISTER_GCM_PATH , "DELETE" , null ) ;
143
137
}
144
138
139
+ public void SetPin ( string pin )
140
+ {
141
+ RegistrationLock accountLock = new RegistrationLock ( pin ) ;
142
+ MakeServiceRequest ( PIN_PATH , "PUT" , JsonUtil . toJson ( accountLock ) ) ;
143
+ }
144
+
145
+ public void RemovePin ( )
146
+ {
147
+ MakeServiceRequest ( PIN_PATH , "PUT" , null ) ;
148
+ }
149
+
145
150
public SendMessageResponse SendMessage ( OutgoingPushMessageList bundle )
146
151
{
147
152
try
@@ -350,13 +355,13 @@ public bool SetCurrentSignedPreKey(SignedPreKeyRecord signedPreKey)// throws IOE
350
355
string response = MakeServiceRequest ( string . Format ( ATTACHMENT_PATH , "" ) , "GET" , null ) ;
351
356
AttachmentDescriptor attachmentKey = JsonUtil . fromJson < AttachmentDescriptor > ( response ) ;
352
357
353
- if ( attachmentKey == null || attachmentKey . getLocation ( ) == null )
358
+ if ( attachmentKey == null || attachmentKey . Location == null )
354
359
{
355
360
throw new Exception ( "Server failed to allocate an attachment key!" ) ;
356
361
}
357
362
358
- Debug . WriteLine ( "Got attachment content location: " + attachmentKey . getLocation ( ) , TAG ) ;
359
- return ( attachmentKey . getId ( ) , attachmentKey . getLocation ( ) ) ;
363
+ Debug . WriteLine ( "Got attachment content location: " + attachmentKey . Location , TAG ) ;
364
+ return ( attachmentKey . Id , attachmentKey . Location ) ;
360
365
}
361
366
362
367
public void RetrieveAttachment ( string relay , ulong attachmentId , Stream tmpDestination , int maxSizeBytes )
@@ -383,8 +388,8 @@ public string RetrieveAttachmentDownloadUrl(string relay, ulong attachmentId)
383
388
string response = MakeServiceRequest ( path , "GET" , null ) ;
384
389
Debug . WriteLine ( "PushServiceSocket: Received resp " + response ) ;
385
390
AttachmentDescriptor descriptor = JsonUtil . fromJson < AttachmentDescriptor > ( response ) ;
386
- Debug . WriteLine ( "PushServiceSocket: Attachment: " + attachmentId + " is at: " + descriptor . getLocation ( ) ) ;
387
- return descriptor . getLocation ( ) ;
391
+ Debug . WriteLine ( "PushServiceSocket: Attachment: " + attachmentId + " is at: " + descriptor . Location ) ;
392
+ return descriptor . Location ;
388
393
}
389
394
390
395
public SignalServiceProfile RetrieveProfile ( SignalServiceAddress target )
@@ -627,16 +632,16 @@ private string MakeServiceRequest(string urlFragment, string method, string body
627
632
throw new PushNetworkException ( ioe ) ;
628
633
}
629
634
630
- switch ( responseCode )
635
+ switch ( ( uint ) responseCode )
631
636
{
632
- case HttpStatusCode . RequestEntityTooLarge : // 413
637
+ case 413 : // HttpStatusCode.RequestEntityTooLarge
633
638
throw new RateLimitException ( "Rate limit exceeded: " + responseCode ) ;
634
- case HttpStatusCode . Unauthorized : // 401
635
- case HttpStatusCode . Forbidden : // 403
639
+ case 401 : // HttpStatusCode.Unauthorized
640
+ case 403 : // HttpStatusCode.Forbidden
636
641
throw new AuthorizationFailedException ( "Authorization failed!" ) ;
637
- case HttpStatusCode . NotFound : // 404
642
+ case 404 : // HttpStatusCode.NotFound
638
643
throw new NotFoundException ( "Not found" ) ;
639
- case HttpStatusCode . Conflict : // 409
644
+ case 409 : // HttpStatusCode.Conflict
640
645
MismatchedDevices mismatchedDevices = null ;
641
646
try
642
647
{
@@ -649,7 +654,7 @@ private string MakeServiceRequest(string urlFragment, string method, string body
649
654
throw new PushNetworkException ( e ) ;
650
655
}
651
656
throw new MismatchedDevicesException ( mismatchedDevices ) ;
652
- case HttpStatusCode . Gone : // 410
657
+ case 410 : // HttpStatusCode.Gone
653
658
StaleDevices staleDevices = null ;
654
659
try
655
660
{
@@ -662,21 +667,30 @@ private string MakeServiceRequest(string urlFragment, string method, string body
662
667
throw new PushNetworkException ( e ) ;
663
668
}
664
669
throw new StaleDevicesException ( staleDevices ) ;
665
- case HttpStatusCode . LengthRequired : //411:
670
+ case 411 : //HttpStatusCode.LengthRequired
666
671
DeviceLimit deviceLimit = null ;
667
672
try
668
673
{
669
674
deviceLimit = JsonUtil . fromJson < DeviceLimit > ( responseBody ) ;
670
675
}
671
676
catch ( Exception e )
672
677
{
673
- Debug . WriteLine ( e ) ;
674
- Debug . WriteLine ( e . StackTrace ) ;
675
678
throw new PushNetworkException ( e ) ;
676
679
}
677
680
throw new DeviceLimitExceededException ( deviceLimit ) ;
678
- case HttpStatusCode . ExpectationFailed : // 417
681
+ case 417 : // HttpStatusCode.ExpectationFailed
679
682
throw new ExpectationFailedException ( ) ;
683
+ case 423 :
684
+ RegistrationLockFailure accountLockFailure ;
685
+ try
686
+ {
687
+ accountLockFailure = JsonUtil . fromJson < RegistrationLockFailure > ( responseBody ) ;
688
+ }
689
+ catch ( Exception e )
690
+ {
691
+ throw new PushNetworkException ( e ) ;
692
+ }
693
+ throw new LockedException ( accountLockFailure . Length , accountLockFailure . TimeRemaining ) ;
680
694
}
681
695
682
696
if ( responseCode != HttpStatusCode . OK && responseCode != HttpStatusCode . NoContent ) // 200 & 204
@@ -780,39 +794,44 @@ private SignalUrl GetRandom(SignalUrl[] connections)
780
794
781
795
internal class GcmRegistrationId
782
796
{
783
- [ JsonProperty ]
784
- private string wnsRegistrationId ;
797
+ [ JsonProperty ( "wnsRegistrationId" ) ]
798
+ public string WnsRegistrationId { get ; }
785
799
786
- [ JsonProperty ]
787
- private bool webSocketChannel ;
788
-
789
- public GcmRegistrationId ( )
790
- {
791
- }
800
+ [ JsonProperty ( "webSocketChannel" ) ]
801
+ public bool WebSocketChannel { get ; }
792
802
793
803
public GcmRegistrationId ( string wnsRegistrationId , bool webSocketChannel )
794
804
{
795
- this . wnsRegistrationId = wnsRegistrationId ;
796
- this . webSocketChannel = webSocketChannel ;
805
+ WnsRegistrationId = wnsRegistrationId ;
806
+ WebSocketChannel = webSocketChannel ;
797
807
}
798
808
}
799
809
800
- internal class AttachmentDescriptor
810
+ internal class RegistrationLock
801
811
{
802
- [ JsonProperty ]
803
- private ulong id ;
812
+ [ JsonProperty ( "pin" ) ]
813
+ public string Pin { get ; }
804
814
805
- [ JsonProperty ]
806
- private string location ;
807
-
808
- public ulong getId ( )
815
+ public RegistrationLock ( string pin )
809
816
{
810
- return id ;
817
+ Pin = pin ;
811
818
}
819
+ }
812
820
813
- public string getLocation ( )
814
- {
815
- return location ;
816
- }
821
+ internal class RegistrationLockFailure
822
+ {
823
+ [ JsonProperty ( "length" ) ]
824
+ public int Length { get ; }
825
+ [ JsonProperty ( "timeRemaining" ) ]
826
+ public long TimeRemaining { get ; }
827
+ }
828
+
829
+ internal class AttachmentDescriptor
830
+ {
831
+ [ JsonProperty ( "id" ) ]
832
+ public ulong Id { get ; }
833
+
834
+ [ JsonProperty ( "location" ) ]
835
+ public string Location { get ; }
817
836
}
818
837
}
0 commit comments