rust_rcs_client/messaging/cpm/sip/cpm_accept_contact.rs
1// Copyright 2023 宋昊文
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use rust_rcs_core::{internet::HeaderField, util::raw_string::StrFind};
16
17pub trait CPMAcceptContact<'a> {
18 fn contains_icsi_ref(&self, icsi_ref: &[u8]) -> bool;
19 fn contains_iari_ref(&self, iari_ref: &[u8]) -> bool;
20}
21
22impl<'a> CPMAcceptContact<'a> for HeaderField<'a> {
23 fn contains_icsi_ref(&self, icsi_ref: &[u8]) -> bool {
24 for p in self.get_parameter_iterator() {
25 if p.name == b"+g.3gpp.icsi-ref" {
26 if let Some(value) = p.value {
27 if let Some(_) = value.index_of(icsi_ref) {
28 return true;
29 }
30 }
31 }
32 }
33
34 false
35 }
36
37 fn contains_iari_ref(&self, iari_ref: &[u8]) -> bool {
38 for p in self.get_parameter_iterator() {
39 if p.name == b"+g.3gpp.iari-ref" {
40 if let Some(value) = p.value {
41 if let Some(_) = value.index_of(iari_ref) {
42 return true;
43 }
44 }
45 }
46 }
47
48 false
49 }
50}