1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
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 */
15 #include "vcard_sip_data.h"
16
17 #include "telephony_errors.h"
18 #include "telephony_log_wrapper.h"
19 #include "vcard_utils.h"
20
21 namespace OHOS {
22 namespace Telephony {
23
BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket & valuesBucket)24 int32_t VCardSipData::BuildValuesBucket(OHOS::DataShare::DataShareValuesBucket &valuesBucket)
25 {
26 valuesBucket.Put(ContactData::TYPE_ID, TypeId::SIP_ADDRESS);
27 valuesBucket.Put(ContactData::DETAIL_INFO, address_);
28 valuesBucket.Put(ContactData::LABEL_ID, labelId_);
29 valuesBucket.Put(ContactData::LABEL_NAME, labelName_);
30 return TELEPHONY_SUCCESS;
31 }
32
BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)33 int32_t VCardSipData::BuildData(std::shared_ptr<DataShare::DataShareResultSet> resultSet)
34 {
35 if (resultSet == nullptr) {
36 return TELEPHONY_ERROR;
37 }
38 int32_t index;
39 resultSet->GetColumnIndex(ContactData::DETAIL_INFO, index);
40 resultSet->GetString(index, address_);
41 resultSet->GetColumnIndex(ContactData::LABEL_NAME, index);
42 resultSet->GetString(index, labelName_);
43 resultSet->GetColumnIndex(ContactData::LABEL_ID, index);
44 resultSet->GetString(index, labelId_);
45 return TELEPHONY_SUCCESS;
46 }
47
InitSipData(std::string rawSip,int32_t type,std::string label)48 void VCardSipData::InitSipData(std::string rawSip, int32_t type, std::string label)
49 {
50 if (VCardUtils::StartWith(rawSip, "sip:")) {
51 address_ = rawSip.substr(SIP_ADDRESS_VALUE_INDEX);
52 } else {
53 address_ = rawSip;
54 }
55 type_ = type;
56 labelName_ = label;
57 }
58
SetAddress(const std::string & address)59 void VCardSipData::SetAddress(const std::string &address)
60 {
61 address_ = address;
62 }
63
GetAddress()64 std::string VCardSipData::GetAddress()
65 {
66 return address_;
67 }
68
SetLabelId(const std::string & labelId)69 void VCardSipData::SetLabelId(const std::string &labelId)
70 {
71 labelId_ = labelId;
72 }
73
GetLabelId()74 std::string VCardSipData::GetLabelId()
75 {
76 return labelId_;
77 }
78
SetLabelName(const std::string & labelName)79 void VCardSipData::SetLabelName(const std::string &labelName)
80 {
81 labelName_ = labelName;
82 }
83
GetLabelName()84 std::string VCardSipData::GetLabelName()
85 {
86 return labelName_;
87 }
88
SetType(int32_t type)89 void VCardSipData::SetType(int32_t type)
90 {
91 type_ = type;
92 }
93
GetType()94 int32_t VCardSipData::GetType()
95 {
96 return type_;
97 }
98
99 } // namespace Telephony
100 } // namespace OHOS
101