Change usage of functions
[platform/core/appfw/pkgmgr-info.git] / src / common / parcel / certinfo_parcelable.cc
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "certinfo_parcelable.hh"
17
18 #include <vector>
19
20 #include "pkgmgrinfo_private.h"
21 #include "pkgmgr-info.h"
22
23 namespace pkgmgr_common {
24 namespace parcel {
25
26 CertInfoParcelable::CertInfoParcelable()
27     : AbstractParcelable(0, ParcelableType::CertInfo),
28         cert_info_(nullptr), pkgid_("") {}
29
30 CertInfoParcelable::CertInfoParcelable(uid_t uid, pkgmgr_certinfo_x *cert_info)
31     : AbstractParcelable(uid, ParcelableType::CertInfo),
32         cert_info_(cert_info), pkgid_("") {}
33
34 CertInfoParcelable::CertInfoParcelable(uid_t uid, std::string pkgid)
35     : AbstractParcelable(uid, ParcelableType::CertInfo),
36         cert_info_(nullptr), pkgid_(pkgid) {}
37
38 CertInfoParcelable::~CertInfoParcelable() {
39   pkgmgrinfo_pkginfo_destroy_certinfo(cert_info_);
40 }
41
42 const pkgmgr_certinfo_x *CertInfoParcelable::GetCertInfo() {
43   return cert_info_;
44 }
45
46 const std::string& CertInfoParcelable::GetPkgId() {
47   return pkgid_;
48 }
49
50 void CertInfoParcelable::WriteToParcel(tizen_base::Parcel* parcel) const {
51   AbstractParcelable::WriteToParcel(parcel);
52   WriteCertInfo(parcel, cert_info_);
53 }
54
55 void CertInfoParcelable::ReadFromParcel(tizen_base::Parcel* parcel) {
56   AbstractParcelable::ReadFromParcel(parcel);
57   ReadCertInfo(parcel);
58 }
59
60 bool CertInfoParcelable::WriteCertInfo(tizen_base::Parcel* parcel, pkgmgr_certinfo_x *cert_info) const {
61   if (cert_info == nullptr) {
62     parcel->WriteBool(true);
63     return true;
64   }
65   parcel->WriteBool(false);
66   WriteInt(parcel, cert_info->for_all_users);
67   WriteString(parcel, cert_info->pkgid);
68   WriteString(parcel, cert_info->cert_value);
69   for (int i = 0; i < MAX_CERT_TYPE; ++i)
70     WriteString(parcel, cert_info->cert_info[i]);
71   for (int i = 0; i < MAX_CERT_TYPE; ++i)
72     WriteInt(parcel, cert_info->cert_id[i]);
73
74   return true;
75 }
76
77 void CertInfoParcelable::ReadCertInfo(tizen_base::Parcel* parcel) {
78   bool is_null = false;
79   if (parcel->ReadBool(&is_null) != TIZEN_ERROR_NONE)
80     return;
81
82   if (is_null)
83     return;
84
85   cert_info_ = reinterpret_cast<pkgmgr_certinfo_x *>(calloc(1, sizeof(pkgmgr_certinfo_x)));
86   ReadInt(parcel, &cert_info_->for_all_users);
87   ReadString(parcel, &cert_info_->pkgid);
88   ReadString(parcel, &cert_info_->cert_value);
89   for (int i = 0; i < MAX_CERT_TYPE; ++i)
90     ReadString(parcel, &cert_info_->cert_info[i]);
91   for (int i = 0; i < MAX_CERT_TYPE; ++i)
92     ReadInt(parcel, &cert_info_->cert_id[i]);
93 }
94
95 bool CertInfoParcelable::WritePkgId(tizen_base::Parcel* parcel) {
96   parcel->WriteString(pkgid_);
97
98   return true;
99 }
100
101 void CertInfoParcelable::ReadPkgId(tizen_base::Parcel* parcel) {
102   bool is_null = false;
103   if (parcel->ReadBool(&is_null) != TIZEN_ERROR_NONE || is_null)
104     return;
105   char *tmp_char;
106   ReadString(parcel, &tmp_char);
107   pkgid_ = tmp_char;
108 }
109
110 std::unique_ptr<AbstractParcelable> CertInfoParcelable::Factory::CreateParcel() {
111   return nullptr;
112 }
113
114 }  // namespace parcel
115 }  // namespace pkgmgr_common