2 // Open Service Platform
\r
3 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
\r
5 // Licensed under the Apache License, Version 2.0 (the License);
\r
6 // you may not use this file except in compliance with the License.
\r
7 // You may obtain a copy of the License at
\r
9 // http://www.apache.org/licenses/LICENSE-2.0
\r
11 // Unless required by applicable law or agreed to in writing, software
\r
12 // distributed under the License is distributed on an "AS IS" BASIS,
\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 // See the License for the specific language governing permissions and
\r
15 // limitations under the License.
\r
19 #include <libxml/parser.h>
\r
20 #include <libxml/tree.h>
\r
21 #include <privacy_manager_client.h>
\r
26 static const xmlChar _NODE_PRIVILEGES[] = "privileges";
\r
27 static const xmlChar _NODE_PRIVILEGE[] = "privilege";
\r
30 void destroy_char_list(char** ppList, int size)
\r
33 for (i = 0; i < size; ++i)
\r
42 __attribute__ ((visibility("default")))
\r
43 int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
\r
48 // Node: <privileges>
\r
49 xmlNodePtr curPtr = xmlFirstElementChild(xmlDocGetRootElement(docPtr));
\r
50 LOGD("Node: %s", curPtr->name);
\r
52 curPtr = curPtr->xmlChildrenNode;
\r
55 LOGD("No privileges");
\r
59 std::list <std::string> privilegeList;
\r
60 while (curPtr != NULL)
\r
62 LOGD("Node: %s", curPtr->name);
\r
64 if (xmlStrcmp(curPtr->name, _NODE_PRIVILEGE) == 0)
\r
66 xmlChar* pPrivilege = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);
\r
67 LOGD(" value= %s", reinterpret_cast<char*>(pPrivilege));
\r
68 if (pPrivilege == NULL)
\r
70 LOGE("Failed to get value");
\r
73 privilegeList.push_back(std::string( reinterpret_cast<char*> (pPrivilege)));
\r
75 curPtr = curPtr->next;
\r
78 char** ppPrivilegeList = (char**) calloc(privilegeList.size() + 1, sizeof(char*));
\r
79 std::list <std::string>::iterator iter = privilegeList.begin();
\r
80 for (int i = 0; i < privilegeList.size(); ++i)
\r
82 ppPrivilegeList[i] = (char*)calloc (strlen(iter->c_str()) + 1, sizeof(char));
\r
83 if (ppPrivilegeList[i] == NULL)
\r
85 destroy_char_list(ppPrivilegeList, privilegeList.size() + 1);
\r
88 memcpy(ppPrivilegeList[i], iter->c_str(), strlen(iter->c_str()));
\r
91 for (int i = 0; i < privilegeList.size(); ++i)
\r
92 LOGD(" values : %s", ppPrivilegeList[i]);
\r
94 ppPrivilegeList[privilegeList.size()] = (char*)calloc (2, sizeof(char));
\r
95 memcpy(ppPrivilegeList[privilegeList.size()], "\0", 1);
\r
97 ret = privacy_manager_client_install_privacy(packageId, (const char**) ppPrivilegeList);
\r
98 destroy_char_list(ppPrivilegeList, privilegeList.size() + 1);
\r
99 if (ret != PRIV_MGR_ERROR_SUCCESS)
\r
101 LOGD("Failed to install privacy : %d", ret);
\r
109 __attribute__ ((visibility("default")))
\r
110 int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId)
\r
114 privacy_manager_client_uninstall_privacy(packageId);
\r