Update source from tizen 2.3
[platform/core/base/rpm-installer.git] / inc / rpm-installer-util.h
1 /*
2  * rpm-installer
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
7  * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23 #ifndef __RPM_INSTALLER_UTIL_H_
24 #define __RPM_INSTALLER_UTIL_H_
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif                          /* __cplusplus */
29
30 #include <string.h>
31 #include <stdarg.h>
32 #include <sys/wait.h>
33 #include <sys/types.h>
34 #include <unistd.h>
35 #include <libgen.h>
36 #include <wait.h>
37 #include <stdio.h>
38 #include <dirent.h>
39 #include <rpm/header.h>
40 #include <rpm/rpmts.h>
41 #include <rpm/rpmlib.h>
42
43
44 #include <libxml/parser.h>
45 #include <libxml/xmlreader.h>
46 #include <libxml/xmlschemas.h>
47 #include <pkgmgr-info.h>
48
49 #include <dlog.h>
50
51 #ifdef  LOG_TAG
52 #undef  LOG_TAG
53 #define LOG_TAG         "rpm-installer"
54 #endif
55
56 #define _LOGE(fmt, arg...) do { \
57                         fprintf(stderr, "  ## "fmt"\n", ##arg); \
58                         LOGE(fmt, ##arg); \
59                 } while (0)
60
61 #define _LOGD(fmt, arg...) do { \
62                         fprintf(stderr, "  ## "fmt"\n", ##arg); \
63                         LOGD(fmt, ##arg); \
64                 } while (0)
65
66 #define _LOGP(fmt, arg...)      fprintf(stderr, "[coretpk-installer] "fmt"\n", ##arg)
67
68 #define RPM_BACKEND_EXEC        "rpm-backend"
69
70 #define WGT_CONFIG      "config.xml"
71 #define SIGNATURE1_XML                                          "signature1.xml"
72 #define SIGNATURE2_XML                                          "signature2.xml"
73 #define AUTHOR_SIGNATURE_XML                            "author-signature.xml"
74
75 #define ASCII(s) (const char *)s
76 #define XMLCHAR(s) (const xmlChar *)s
77
78 #define PKG_MAX_LEN             128
79 #define VERSION_MAX_LEN 11
80
81 #define DIRECTORY_PERMISSION_755                        0755
82 #define DIRECTORY_PERMISSION_644                        0644
83 #define FILE_PERMISSION_755                                     0755
84 #define FILE_PERMISSION_644                                     0644
85
86 struct pkginfo_t {
87         char package_name[PKG_MAX_LEN];
88         char version[VERSION_MAX_LEN];
89 };
90 typedef struct pkginfo_t pkginfo;
91
92 struct privilegeinfo_t {
93         char package_id[PKG_MAX_LEN];
94         int visibility;
95 };
96 typedef struct privilegeinfo_t privilegeinfo;
97
98 #ifndef PATH_MAX
99 # define PATH_MAX 4096
100 #endif
101
102 #define FREE_AND_STRDUP(from, to) do { \
103                 if (to) free((void *)to); \
104                 if (from) to = strdup(from); \
105         } while (0)
106
107
108 #define FREE_AND_NULL(ptr) do { \
109                 if (ptr) { \
110                         free((void *)ptr); \
111                         ptr = NULL; \
112                 } \
113         } while (0)
114
115
116 /*Error number according to Tizen Native Package Manager Command Specification v1.0*/
117 #define RPM_INSTALLER_SUCCESS                                   0
118 #define RPM_INSTALLER_ERR_WRONG_PARAM                           64
119 #define RPM_INSTALLER_ERR_DBUS_PROBLEM                          102
120 #define RPM_INSTALLER_ERR_PACKAGE_EXIST                         121
121 #define RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED                 104
122 #define RPM_INSTALLER_ERR_RESOURCE_BUSY                         105
123 #define RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY                     63
124 #define RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION                  107
125 #define RPM_INSTALLER_ERR_NO_RPM_FILE                           2
126 #define RPM_INSTALLER_ERR_DB_ACCESS_FAILED                      109
127 #define RPM_INSTALLER_ERR_RPM_OPERATION_FAILED                  110
128 #define RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED                  111
129 #define RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS                 112
130 #define RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION                113
131 #define RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED         114
132 #define RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED       115
133 #define RPM_INSTALLER_ERR_CLEAR_DATA_FAILED                     116
134 #define RPM_INSTALLER_ERR_INTERNAL                              117
135 #define RPM_INSTALLER_ERR_PKG_NOT_FOUND                         1
136 #define RPM_INSTALLER_ERR_UNKNOWN                               119
137 #define RPM_INSTALLER_ERR_NO_MANIFEST                           11
138 #define RPM_INSTALLER_ERR_INVALID_MANIFEST                      12
139 #define RPM_INSTALLER_ERR_SIG_NOT_FOUND                         21
140 #define RPM_INSTALLER_ERR_SIG_INVALID                                   22
141 #define RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED                               23
142 #define RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND                           31
143 #define RPM_INSTALLER_ERR_CERT_INVALID                                  32
144 #define RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED         33
145 #define RPM_INSTALLER_ERR_NO_CONFIG                                         34
146 #define RPM_INSTALLER_ERR_INVALID_CONFIG        35
147 #define RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED     36
148
149 #define RPM_INSTALLER_SUCCESS_STR                       "Success"
150 #define RPM_INSTALLER_ERR_WRONG_PARAM_STR               "Wrong Input Param"
151 #define RPM_INSTALLER_ERR_DBUS_PROBLEM_STR                      "DBUS Error"
152 #define RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY_STR "Not Enough Memory"
153 #define RPM_INSTALLER_ERR_PACKAGE_EXIST_STR     "Package Already Installed"
154 #define RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED_STR     "Package Not Installed"
155 #define RPM_INSTALLER_ERR_RESOURCE_BUSY_STR                     "Resource Busy"
156 #define RPM_INSTALLER_ERR_UNKNOWN_STR                   "Unknown Error"
157 #define RPM_INSTALLER_ERR_PKG_NOT_FOUND_STR             "Package file not found"
158 #define RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION_STR      "Version Not supported"
159 #define RPM_INSTALLER_ERR_NO_RPM_FILE_STR       "No RPM Package"
160 #define RPM_INSTALLER_ERR_DB_ACCESS_FAILED_STR  "DB Access Failed"
161 #define RPM_INSTALLER_ERR_RPM_OPERATION_FAILED_STR      "RPM operation failed"
162 #define RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED_STR      "Package Not Upgraded"
163 #define RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS_STR     "Wrong Args to Script"
164 #define RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED_STR     "Installation Disabled"
165 #define RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED_STR   "Uninstallation Disabled"
166 #define RPM_INSTALLER_ERR_CLEAR_DATA_FAILED_STR         "Clear Data Failed"
167 #define RPM_INSTALLER_ERR_INTERNAL_STR  "Internal Error"
168 #define RPM_INSTALLER_ERR_NO_MANIFEST_STR       "Manifest File Not Found"
169 #define RPM_INSTALLER_ERR_INVALID_MANIFEST_STR  "Manifest Validation Failed"
170 #define RPM_INSTALLER_ERR_SIG_NOT_FOUND_STR             "Signature Not Found"
171 #define RPM_INSTALLER_ERR_SIG_INVALID_STR       "Invalid Signature"
172 #define RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED_STR   "Signature Verification Failed"
173 #define RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND_STR               "Root Cert Not Found"
174 #define RPM_INSTALLER_ERR_CERT_INVALID_STR      "Invalid Certificate"
175 #define RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED_STR     "Certificate Chain Verification Failed"
176 #define RPM_INSTALLER_ERR_NO_CONFIG_STR         "Config file is not present"
177 #define RPM_INSTALLER_ERR_INVALID_CONFIG_STR    "Config file is not valid"
178 #define RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED_STR "Unsupported Command"
179
180 #define DEBUG_ERR               0x0001
181 #define DEBUG_INFO              0x0002
182 #define DEBUG_RESULT    0x0004
183
184 #define RPM_LOG 1
185 #define SIZE_KB 1024
186 #define BUFF_SZE    1024
187 #define RPM_INSTALLER_RW_INSTALL_PATH "/opt/usr"
188 #define DIR_RPM_INSTALLER_APPLICATIONS_TEMP "/tmp/wgt_unzip"
189 #define RPM_UNZIP "/usr/bin/unzip"
190 #define DIR_PERMS (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
191 #define DIR_RPM_WGT_SMACK_RULE_OPT "/opt/usr/.wgt/"
192
193         void _ri_error_no_to_string(int errnumber, char **errstr);
194         int _ri_recursive_delete_dir(char *dirname);
195         int _ri_string_to_error_no(char *errstr);
196         int _ri_get_available_free_memory(const char *opt_path, unsigned long *free_mem);
197         int  _ri_process_wgt_package(char** pkgid);
198         unsigned long  _ri_calculate_file_size(const char *filename);
199         int  _ri_wgt_package_extract(char *pkgid);
200         int  _ri_stream_config_file(const char* filename, pkginfo *info);
201         void _ri_process_config_node(xmlTextReaderPtr reader, pkginfo * info);
202         int _verify_wgt_package_signature_files();
203         void _ri_remove_wgt_unzip_dir();
204         int _ri_xsystem(const char *argv[]);
205
206         int  _get_package_name_from_xml(char* manifest,char** pkgname);
207         int  _get_pkgname_from_rpm_name(char* pkgfile,char** pkgname);
208         int _child_element(xmlTextReaderPtr reader, int depth);
209         char *_ri_basename(char *name);
210         int _ri_verify_sig_and_cert(const char *sigfile, int *visibility);
211         char* _manifest_to_package(const char* manifest);
212         int _rpm_delete_dir(char *dirname);
213         unsigned long  _ri_calculate_rpm_size( char* rpm_file);
214         int _ri_get_attribute(xmlTextReaderPtr reader,char *attribute, const char **xml_attribute);
215 #ifdef __cplusplus
216 }
217 #endif                          /* __cplusplus */
218 #endif                          /* __RPM_INSTALLER_UTIL_H_ */