rusmpp_core/pdus/owned/
cancel_sm.rs

1use rusmpp_macros::Rusmpp;
2
3use crate::{
4    pdus::owned::Pdu,
5    types::owned::COctetString,
6    values::{owned::*, *},
7};
8
9/// This command is issued by the ESME to cancel one or more previously submitted short
10/// messages that are pending delivery. The command may specify a particular message to
11/// cancel, or all messages matching a particular source, destination and service_type.
12///
13/// If the message_id is set to the ID of a previously submitted message, then provided the
14/// source address supplied by the ESME matches that of the stored message, that message
15/// will be cancelled.
16///
17/// If the message_id is NULL, all outstanding undelivered messages with matching source and
18/// destination addresses (and service_type if specified) are cancelled.
19/// Where the original submit_sm, data_sm or submit_multi ‘source address’ is defaulted to
20/// NULL, then the source address in the cancel_sm command should also be NULL.
21#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Rusmpp)]
22#[rusmpp(decode = owned, test = skip)]
23#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
24#[cfg_attr(feature = "serde", derive(::serde::Serialize))]
25#[cfg_attr(feature = "serde-deserialize-unchecked", derive(::serde::Deserialize))]
26pub struct CancelSm {
27    /// Set to indicate SMS Application service,
28    /// if cancellation of a group of application
29    /// service messages is desired.
30    /// Otherwise set to NULL.
31    pub service_type: ServiceType,
32    /// Message ID of the message to be
33    /// cancelled. This must be the MC
34    /// assigned Message ID of the original
35    /// message.
36    ///
37    /// Set to NULL if cancelling a group of
38    /// messages.
39    pub message_id: COctetString<1, 65>,
40    /// Type of Number of message originator.
41    /// This is used for verification purposes,
42    /// and must match that supplied in the
43    /// original message submission request PDU.
44    ///
45    /// If not known, set to NULL.
46    pub source_addr_ton: Ton,
47    /// Numbering Plan Identity of message
48    /// originator.
49    ///
50    /// This is used for verification purposes,
51    /// and must match that supplied in the
52    /// original message submission request PDU.
53    ///
54    /// If not known, set to NULL.
55    pub source_addr_npi: Npi,
56    /// Source address of message(s) to be
57    /// cancelled. This is used for verification
58    /// purposes, and must match that supplied
59    /// in the original message submission
60    /// request PDU(s).
61    ///
62    /// If not known, set to NULL.
63    pub source_addr: COctetString<1, 21>,
64    /// Type of number of destination SME
65    /// address of the message(s) to be cancelled.
66    ///
67    /// This is used for verification purposes,
68    /// and must match that supplied in the
69    /// original message submission request
70    /// PDU (e.g. submit_sm).
71    ///
72    /// May be set to NULL when the
73    /// message_id is provided.
74    pub dest_addr_ton: Ton,
75    /// Numbering Plan Indicator of destination
76    /// SME address of the message(s) to be
77    /// cancelled.
78    ///
79    /// This is used for verification purposes,
80    /// and must match that supplied in the
81    /// original message submission request
82    /// PDU.
83    ///
84    /// May be set to NULL when the
85    /// message_id is provided.
86    pub dest_addr_npi: Npi,
87    /// Destination address of message(s) to be
88    /// cancelled.
89    ///
90    /// This is used for verification purposes,
91    /// and must match that supplied in the
92    /// original message submission request
93    /// PDU.
94    ///
95    /// May be set to NULL when the
96    /// message_id is provided.
97    pub destination_addr: COctetString<1, 21>,
98}
99
100impl CancelSm {
101    #[allow(clippy::too_many_arguments)]
102    pub fn new(
103        service_type: ServiceType,
104        message_id: COctetString<1, 65>,
105        source_addr_ton: Ton,
106        source_addr_npi: Npi,
107        source_addr: COctetString<1, 21>,
108        dest_addr_ton: Ton,
109        dest_addr_npi: Npi,
110        destination_addr: COctetString<1, 21>,
111    ) -> Self {
112        Self {
113            service_type,
114            message_id,
115            source_addr_ton,
116            source_addr_npi,
117            source_addr,
118            dest_addr_ton,
119            dest_addr_npi,
120            destination_addr,
121        }
122    }
123
124    pub fn builder() -> CancelSmBuilder {
125        CancelSmBuilder::new()
126    }
127}
128
129impl From<CancelSm> for Pdu {
130    fn from(value: CancelSm) -> Self {
131        Self::CancelSm(value)
132    }
133}
134
135#[derive(Debug, Default)]
136pub struct CancelSmBuilder {
137    inner: CancelSm,
138}
139
140impl CancelSmBuilder {
141    pub fn new() -> Self {
142        Self::default()
143    }
144
145    pub fn service_type(mut self, service_type: ServiceType) -> Self {
146        self.inner.service_type = service_type;
147        self
148    }
149
150    pub fn message_id(mut self, message_id: COctetString<1, 65>) -> Self {
151        self.inner.message_id = message_id;
152        self
153    }
154
155    pub fn source_addr_ton(mut self, source_addr_ton: Ton) -> Self {
156        self.inner.source_addr_ton = source_addr_ton;
157        self
158    }
159
160    pub fn source_addr_npi(mut self, source_addr_npi: Npi) -> Self {
161        self.inner.source_addr_npi = source_addr_npi;
162        self
163    }
164
165    pub fn source_addr(mut self, source_addr: COctetString<1, 21>) -> Self {
166        self.inner.source_addr = source_addr;
167        self
168    }
169
170    pub fn dest_addr_ton(mut self, dest_addr_ton: Ton) -> Self {
171        self.inner.dest_addr_ton = dest_addr_ton;
172        self
173    }
174
175    pub fn dest_addr_npi(mut self, dest_addr_npi: Npi) -> Self {
176        self.inner.dest_addr_npi = dest_addr_npi;
177        self
178    }
179
180    pub fn destination_addr(mut self, destination_addr: COctetString<1, 21>) -> Self {
181        self.inner.destination_addr = destination_addr;
182        self
183    }
184
185    pub fn build(self) -> CancelSm {
186        self.inner
187    }
188}
189
190#[cfg(test)]
191mod tests {
192    use std::str::FromStr;
193
194    use crate::tests::TestInstance;
195
196    use super::*;
197
198    impl TestInstance for CancelSm {
199        fn instances() -> alloc::vec::Vec<Self> {
200            alloc::vec![
201                Self::default(),
202                Self::builder()
203                    .service_type(ServiceType::default())
204                    .message_id(COctetString::from_str("message_id").unwrap())
205                    .source_addr_ton(Ton::International)
206                    .source_addr_npi(Npi::Unknown)
207                    .source_addr(COctetString::from_str("source_addr").unwrap())
208                    .dest_addr_ton(Ton::International)
209                    .dest_addr_npi(Npi::Unknown)
210                    .destination_addr(COctetString::from_str("destination_addr").unwrap())
211                    .build(),
212            ]
213        }
214    }
215
216    #[test]
217    fn encode_decode() {
218        crate::tests::owned::encode_decode_test_instances::<CancelSm>();
219    }
220}