1
- use std:: { fmt :: Error , net:: SocketAddr } ;
1
+ use std:: net:: SocketAddr ;
2
2
use std:: time:: SystemTime ;
3
3
4
4
use super :: {
5
5
MTPManagerActions ,
6
6
MTPHeaders ,
7
7
MTPStorage ,
8
- MTPMessage
8
+ MTPMessage ,
9
+
10
+ error:: ProtocolError
9
11
} ;
10
12
13
+
11
14
/// [`MessageTransferProtocol`] defines the main interface for a message transfer protocol system.
12
15
/// It includes methods for subscribing to queues, unsubscribing, publishing messages,
13
16
/// pulling messages, pinging the server, and managing actions.
@@ -24,13 +27,13 @@ pub trait MessageTransferProtocol {
24
27
///
25
28
/// # Returns
26
29
/// A result containing a response or an error.
27
- fn subscribe ( & self , queue : String ) -> Result < Self :: Response , Error > ;
30
+ fn subscribe ( & self , queue : String ) -> Result < Self :: Response , ProtocolError > ;
28
31
29
32
/// Unsubscribes from the queue with the passed identifier.
30
33
///
31
34
/// # Returns
32
35
/// A result containing a response or an error.
33
- fn unsubscribe ( & self , queue : String ) -> Result < Self :: Response , Error > ;
36
+ fn unsubscribe ( & self , queue : String ) -> Result < Self :: Response , ProtocolError > ;
34
37
35
38
/// Publishes a message to the queue.
36
39
///
@@ -39,19 +42,19 @@ pub trait MessageTransferProtocol {
39
42
///
40
43
/// # Returns
41
44
/// A result containing a response or an error.
42
- fn publish ( & self , message : Self :: Message ) -> Result < Self :: Response , Error > ;
45
+ fn publish ( & self , message : Self :: Message ) -> Result < Self :: Response , ProtocolError > ;
43
46
44
47
/// Pulls a message from the queue.
45
48
///
46
49
/// # Returns
47
50
/// A result containing a response or an error.
48
- fn pull ( & self ) -> Result < Self :: Response , Error > ;
51
+ fn pull ( & self ) -> Result < Self :: Response , ProtocolError > ;
49
52
50
53
/// Pings the server to check status
51
54
///
52
55
/// # Returns
53
56
/// A result containing a response or an error.
54
- fn ping ( & self ) -> Result < Self :: Response , Error > ;
57
+ fn ping ( & self ) -> Result < Self :: Response , ProtocolError > ;
55
58
56
59
/// Manages the protocol actions.
57
60
///
@@ -60,7 +63,7 @@ pub trait MessageTransferProtocol {
60
63
///
61
64
/// # Returns
62
65
/// A result containing a response or an error.
63
- fn manage ( & self , actions : MTPManagerActions ) -> Result < Self :: Response , Error > ;
66
+ fn manage ( & self , actions : MTPManagerActions ) -> Result < Self :: Response , ProtocolError > ;
64
67
}
65
68
66
69
/// [`MessageTransferProtocolResponse`] represents the response returned by methods of the [`MessageTransferProtocol`] trait.
@@ -283,7 +286,7 @@ pub enum MTPRequestType {
283
286
/// `MTPStatusCode` represents the various status codes that can be returned in a protocol response.
284
287
pub enum MTPStatusCode {
285
288
Success0 ,
286
- Error1 ( Error )
289
+ Error1 ( ProtocolError )
287
290
}
288
291
289
292
/// `MTPHeaderUnit` represents individual units within the protocol's header.
@@ -389,7 +392,7 @@ pub enum MTPHeaderUnit {
389
392
/// - Content format defined in the type [`ContentType`]
390
393
Message {
391
394
id : String ,
392
- timestamp : SystemTime ,
395
+ timestamp : Option < SystemTime > ,
393
396
priority : MessagePriority ,
394
397
category : MessageCategory ,
395
398
content_type : ContentType ,
@@ -402,6 +405,10 @@ pub enum MTPHeaderUnit {
402
405
queue : String ,
403
406
to : MessagePublish ,
404
407
} ,
408
+
409
+ QueueCreation {
410
+
411
+ }
405
412
}
406
413
407
414
/// `MTPAuth` represents different authentication methods that can be used within the protocol's header.
@@ -647,19 +654,47 @@ pub enum AuthSchemes {
647
654
/// based on the `MTPManagerAction` variant, performing appropriate operations for each action.
648
655
pub enum MTPManagerAction {
649
656
/// Rename an existing resource specifically the queue in the which the moderator is operating
650
- Rename ,
657
+ Rename ( String ) ,
651
658
652
659
/// Authorize user requesting persmissions to the queue
653
- Authorize , // On user invites (private)
660
+ Authorize ( String ) , // On user invites (private)
654
661
655
662
/// Reject user requesting permissions to the queue
656
663
Reject , // Access permission
657
664
658
665
/// Dispose an exising client from the queue
659
- Dispose , // Dispose of existing clients
666
+ Dispose ( String ) , // Dispose of existing clients
660
667
661
668
/// Modify the roles/permissions of existing client
662
- AccessorModify , // Change the permission of the access of the queue
669
+ AccessorModify ( QueueAccess ) , // Change the permission of the access of the queue
670
+ }
671
+
672
+ /// [`QueueAccess`] defines an access of a client to a particular queue.
673
+ ///
674
+ /// ## Variants
675
+ ///
676
+ /// ### `Public`
677
+ ///
678
+ /// A queue to be public. Anyone with the queue identifier can join the queue to receive messages
679
+ /// This is the default queue accessor.
680
+ ///
681
+ /// - **Usage**: A public queue to publish messages to all who join the queue wihtout needing to wait for authorization
682
+ ///
683
+ /// /// ### `Private`
684
+ ///
685
+ /// A queue to be private can only be joined if the admin authorizes the request.
686
+ /// A client waits for admin aprroval and then joins the queue to receive published messages
687
+ ///
688
+ /// - **Usage**: A private queue to restrict information acccess
689
+ ///
690
+ /// ### `Protected`
691
+ ///
692
+ /// A queue to be protected.
693
+ ///
694
+ pub enum QueueAccess {
695
+ Public ,
696
+ Private ,
697
+ Protected
663
698
}
664
699
665
700
/// `MessagePriority` defines the priority levels of messages within the protocol.
@@ -901,6 +936,16 @@ pub enum ContentType {
901
936
XML ,
902
937
}
903
938
939
+ /// [`QueueRoles`] for the queue
940
+ /// Roles that are defined for each client in the queue
941
+ pub enum QueueRoles {
942
+ Moderator ,
943
+ Manager ,
944
+ Producer ,
945
+ Consumer ,
946
+ Couple
947
+ }
948
+
904
949
905
950
906
951
/// `MessagePublish` defines the different ways a message can be published within the protocol.
@@ -1059,3 +1104,28 @@ impl Clone for MessagePublish{
1059
1104
}
1060
1105
}
1061
1106
}
1107
+
1108
+ /// Clone implementation for [MTPRequestType]
1109
+ impl Clone for MTPRequestType {
1110
+ fn clone ( & self ) -> Self {
1111
+ match self {
1112
+ Self :: Subscribe => Self :: Subscribe ,
1113
+ Self :: Unsubscribe => Self :: Unsubscribe ,
1114
+ Self :: Publish => Self :: Publish ,
1115
+ Self :: Pull => Self :: Pull ,
1116
+ Self :: Ping => Self :: Ping ,
1117
+ Self :: Manage => Self :: Manage ,
1118
+ }
1119
+ }
1120
+ }
1121
+
1122
+ /// Clone implementation for [QueueAccess]
1123
+ impl Clone for QueueAccess {
1124
+ fn clone ( & self ) -> Self {
1125
+ match self {
1126
+ Self :: Public => Self :: Public ,
1127
+ Self :: Private => Self :: Private ,
1128
+ Self :: Protected => Self :: Protected ,
1129
+ }
1130
+ }
1131
+ }
0 commit comments