rusmpp_core/pdus/owned/
cancel_broadcast_sm.rs

1use rusmpp_macros::Rusmpp;
2
3use crate::{
4    pdus::owned::Pdu,
5    tlvs::owned::{CancelBroadcastTlvValue, Tlv},
6    types::owned::COctetString,
7    values::{owned::*, *},
8};
9/// This command is issued by the ESME to cancel a broadcast message which has been
10/// previously submitted to the Message Centre for broadcast via broadcast_sm and which is still
11/// pending delivery.
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///
20/// If the user_message_reference is set to the ESME-assigned reference of a previously
21/// submitted message, then provided the source address supplied by the ESME matches that of
22/// the stored message, that message will be cancelled.
23///
24/// Where the original broadcast_sm ‘source address’ was defaulted to NULL, then the source
25/// address in the cancel_broadcast_sm command should also be NULL.
26#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Default, Rusmpp)]
27#[rusmpp(decode = owned, test = skip)]
28#[cfg_attr(feature = "arbitrary", derive(::arbitrary::Arbitrary))]
29#[cfg_attr(feature = "serde", derive(::serde::Serialize))]
30#[cfg_attr(feature = "serde-deserialize-unchecked", derive(::serde::Deserialize))]
31pub struct CancelBroadcastSm {
32    /// Set to indicate CBS Application service, if
33    /// cancellation of a group of application service
34    /// messages is desired.
35    ///
36    /// Otherwise set to NULL.
37    pub service_type: ServiceType,
38    /// Message ID of the message to be cancelled. This must
39    /// be the MC assigned Message ID of the original message.
40    ///
41    /// Set to NULL if setting user_message_reference.
42    pub message_id: COctetString<1, 65>,
43    /// Type of Number of message originator. This is used for
44    /// verification purposes, and must match that supplied in
45    /// the original message submission request PDU.
46    ///
47    /// If not known, set to NULL (Unknown).
48    pub source_addr_ton: Ton,
49    /// Numbering Plan Identity of message originator.
50    ///
51    /// This is used for verification purposes, and must match
52    /// that supplied in the original message submission
53    /// request PDU.
54    ///
55    /// If not known, set to NULL (Unknown).
56    pub source_addr_npi: Npi,
57    /// Source address of message to be cancelled. This is used
58    /// for verification purposes, and must match that supplied in
59    /// the original message submission request PDU.
60    ///
61    /// If not known, set to NULL (Unknown).
62    pub source_addr: COctetString<1, 21>,
63    /// Cancel broadcast  TLVs ([`CancelBroadcastTlvValue`]).
64    #[rusmpp(length = "unchecked")]
65    tlvs: alloc::vec::Vec<Tlv>,
66}
67
68impl CancelBroadcastSm {
69    pub fn new(
70        service_type: ServiceType,
71        message_id: COctetString<1, 65>,
72        source_addr_ton: Ton,
73        source_addr_npi: Npi,
74        source_addr: COctetString<1, 21>,
75        tlvs: alloc::vec::Vec<CancelBroadcastTlvValue>,
76    ) -> Self {
77        let tlvs = tlvs.into_iter().map(From::from).collect();
78
79        Self {
80            service_type,
81            message_id,
82            source_addr_ton,
83            source_addr_npi,
84            source_addr,
85            tlvs,
86        }
87    }
88
89    pub fn tlvs(&self) -> &[Tlv] {
90        &self.tlvs
91    }
92
93    pub fn set_tlvs(&mut self, tlvs: alloc::vec::Vec<CancelBroadcastTlvValue>) {
94        self.tlvs = tlvs.into_iter().map(From::from).collect();
95    }
96
97    pub fn clear_tlvs(&mut self) {
98        self.tlvs.clear();
99    }
100
101    pub fn push_tlv(&mut self, tlv: impl Into<CancelBroadcastTlvValue>) {
102        self.tlvs.push(Tlv::from(tlv.into()));
103    }
104
105    pub fn builder() -> CancelBroadcastSmBuilder {
106        CancelBroadcastSmBuilder::new()
107    }
108}
109
110impl From<CancelBroadcastSm> for Pdu {
111    fn from(value: CancelBroadcastSm) -> Self {
112        Self::CancelBroadcastSm(value)
113    }
114}
115
116#[derive(Debug, Default)]
117pub struct CancelBroadcastSmBuilder {
118    inner: CancelBroadcastSm,
119}
120
121impl CancelBroadcastSmBuilder {
122    pub fn new() -> Self {
123        Self::default()
124    }
125
126    pub fn service_type(mut self, service_type: ServiceType) -> Self {
127        self.inner.service_type = service_type;
128        self
129    }
130
131    pub fn message_id(mut self, message_id: COctetString<1, 65>) -> Self {
132        self.inner.message_id = message_id;
133        self
134    }
135
136    pub fn source_addr_ton(mut self, source_addr_ton: Ton) -> Self {
137        self.inner.source_addr_ton = source_addr_ton;
138        self
139    }
140
141    pub fn source_addr_npi(mut self, source_addr_npi: Npi) -> Self {
142        self.inner.source_addr_npi = source_addr_npi;
143        self
144    }
145
146    pub fn source_addr(mut self, source_addr: COctetString<1, 21>) -> Self {
147        self.inner.source_addr = source_addr;
148        self
149    }
150
151    pub fn tlvs(mut self, tlvs: alloc::vec::Vec<CancelBroadcastTlvValue>) -> Self {
152        self.inner.set_tlvs(tlvs);
153        self
154    }
155
156    pub fn clear_tlvs(mut self) -> Self {
157        self.inner.clear_tlvs();
158        self
159    }
160
161    pub fn push_tlv(mut self, tlv: impl Into<CancelBroadcastTlvValue>) -> Self {
162        self.inner.push_tlv(tlv);
163        self
164    }
165
166    pub fn build(self) -> CancelBroadcastSm {
167        self.inner
168    }
169}
170
171#[cfg(test)]
172mod tests {
173    use std::str::FromStr;
174
175    use crate::tests::TestInstance;
176
177    use super::*;
178
179    impl TestInstance for CancelBroadcastSm {
180        fn instances() -> alloc::vec::Vec<Self> {
181            alloc::vec![
182                Self::default(),
183                Self::builder()
184                    .service_type(ServiceType::default())
185                    .message_id(COctetString::from_str("1234567890").unwrap())
186                    .source_addr_ton(Ton::International)
187                    .source_addr_npi(Npi::Ermes)
188                    .source_addr(COctetString::from_str("1234567890").unwrap())
189                    .build(),
190                Self::builder()
191                    .message_id(COctetString::from_str("1234567890").unwrap())
192                    .source_addr(COctetString::from_str("1234567890").unwrap())
193                    .tlvs(alloc::vec![
194                        CancelBroadcastTlvValue::BroadcastContentType(BroadcastContentType::new(
195                            TypeOfNetwork::Gsm,
196                            EncodingContentType::BusinessFinancialNewsInternational,
197                        )),
198                        CancelBroadcastTlvValue::UserMessageReference(UserMessageReference::new(
199                            16,
200                        )),
201                    ])
202                    .build(),
203            ]
204        }
205    }
206
207    #[test]
208    fn encode_decode() {
209        crate::tests::owned::encode_decode_with_length_test_instances::<CancelBroadcastSm>();
210    }
211}