Fix: xml parser + minor fixes 05/72105/1 accepted/tizen/common/20160531.141928 accepted/tizen/ivi/20160602.022635 accepted/tizen/mobile/20160602.022712 accepted/tizen/tv/20160602.022350 accepted/tizen/wearable/20160602.022500 submit/tizen/20160530.143459
authorKazimierz Krosman <k.krosman@samsung.com>
Mon, 30 May 2016 13:43:01 +0000 (15:43 +0200)
committerKazimierz Krosman <k.krosman@samsung.com>
Mon, 30 May 2016 13:43:01 +0000 (15:43 +0200)
Fixed xml parser bug that causes that only first <includedir>
works as it should.

Removed deadlock in init when logs are enabled

Minor refactors

Change-Id: I94c97efff478cf919cc5809f106bca1bb1465889

src/internal/policy.cpp
src/internal/policy.hpp
src/internal/xml_parser.hpp
src/libdbuspolicy1.c

index 021a4be..da65a5c 100644 (file)
@@ -1,6 +1,5 @@
 #include "policy.hpp"
 #include "naive_policy_db.hpp"
-//#include "tslog.hpp"
 #include <cstdlib>
 #include <sys/types.h>
 #include <grp.h>
@@ -192,7 +191,7 @@ void DbAdapter::xmlTraversal(bool bus,
        }
 }
 
-void DbAdapter::updateDb(bool bus, boost::property_tree::ptree& xmlTree) {
+void DbAdapter::updateDb(bool bus, boost::property_tree::ptree& xmlTree, std::vector<std::string>& incl_dirs) {
        const auto& children = xmlTree.get_child("busconfig");
        PolicyType policy_type;
        PolicyTypeValue policy_type_value;
@@ -201,6 +200,8 @@ void DbAdapter::updateDb(bool bus, boost::property_tree::ptree& xmlTree) {
                        __tag_state = POLICY;
                        __attr = false;
                        xmlTraversal(bus, x.second, POLICY, policy_type, policy_type_value);
+               } else if (x.first == "includedir") {
+                       incl_dirs.push_back(x.second.data());
                }
        }
 }
index 4909e4e..aa93cc8 100644 (file)
@@ -186,7 +186,7 @@ namespace ldp_xml_parser
                                                  int level = 0);
        public:
                DbAdapter(NaivePolicyDb& system, NaivePolicyDb& session);
-               void updateDb(bool bus, boost::property_tree::ptree& xmlTree);
+               void updateDb(bool bus, boost::property_tree::ptree& xmlTree, std::vector<std::string>& incl_dirs);
                static uid_t convertToUid(const char* user);
                static gid_t convertToGid(const char* group);
        };
index 26aee38..0dfb668 100644 (file)
@@ -23,7 +23,6 @@
 #include <boost/property_tree/xml_parser.hpp>
 #include <dirent.h>
 #include <libgen.h>
-//#include "xml_policy.hpp"
 #include "libdbuspolicy1-private.hpp"
 #include "tslog.hpp"
 #include "policy.hpp"
@@ -65,13 +64,14 @@ namespace ldp_xml_parser
 
             ErrCode parse(bool bus, bool first, const std::string& filename, std::vector<std::string>& included_files) {
                 std::pair<ErrCode, std::string> errparam;
-
+                               std::vector<std::string> incl_dirs;
                                if (tslog::verbose())
                                        std::cout << "=== XML PARSING BEGIN === : " << filename << '\n';
 
-                errparam = parseXml(bus, filename);
-                               if (first && errparam.first.get() >= 0 && errparam.second != "")
-                                       getIncludedFiles(filename, errparam.second, included_files);
+                errparam = parseXml(bus, filename, incl_dirs);
+                               for (int i = 0; i < incl_dirs.size(); i++) {
+                                       getIncludedFiles(filename, incl_dirs[i], included_files);
+                               }
 
                                if (tslog::enabled()) {
                                        if (tslog::verbose())
@@ -88,7 +88,10 @@ namespace ldp_xml_parser
                                std::string fname;
                                std::copy(filename.begin(), filename.end(), fname.begin());
                                std::string dname = dirname(const_cast<char*>(fname.c_str()));
-                               dname += (std::string("/") + incldir);
+                               if (incldir[0] != '/')
+                                       dname += (std::string("/") + incldir);
+                               else
+                                       dname = incldir;
                                files.clear();
                                if((dir = opendir(dname.c_str())) != NULL) {
                                        while((ent = readdir(dir)) != NULL) {
@@ -108,7 +111,7 @@ namespace ldp_xml_parser
                                        std::cout << "could not open directory " << dname << '\n';
             }
 
-            std::pair<ErrCode, std::string> parseXml(bool bus, const std::string& filename) {
+               std::pair<ErrCode, std::string> parseXml(bool bus, const std::string& filename, std::vector<std::string>& incl_dirs) {
                 std::pair<ErrCode, std::string> ret;
 
                                if (__parsed.insert(filename).second)
@@ -116,8 +119,7 @@ namespace ldp_xml_parser
                                                boost::property_tree::ptree pt;
                                                read_xml(filename, pt);
                                                if (!pt.empty()) {
-                            __adapter->updateDb(bus, pt);
-                                                       ret.second = pt.get("busconfig.includedir", "");
+                            __adapter->updateDb(bus, pt, incl_dirs);
                                                }
                                        } catch(const boost::property_tree::xml_parser::xml_parser_error& ex) {
                                                ret.first = ErrCode::error(ex.what());
index 7ad44dd..c274833 100644 (file)
@@ -219,13 +219,17 @@ DBUSPOLICY1_EXPORT void* dbuspolicy1_init(const char *bus_path)
                goto err_close;
 
        rp = __internal_init(bus_type, (bus_type == SYSTEM_BUS) ? SYSTEM_BUS_CONF_FILE_PRIMARY : SESSION_BUS_CONF_FILE_PRIMARY);
-       rs = __internal_init(bus_type, (bus_type == SYSTEM_BUS) ? SYSTEM_BUS_CONF_FILE_SECONDARY : SESSION_BUS_CONF_FILE_SECONDARY);
+       if (rp < 0)
+               rs = __internal_init(bus_type, (bus_type == SYSTEM_BUS) ? SYSTEM_BUS_CONF_FILE_SECONDARY : SESSION_BUS_CONF_FILE_SECONDARY);
+       else
+               rs = 1;
+
+       pthread_mutex_unlock(&g_mutex);
        __internal_init_flush_logs();
 
-       if ((rp & rs) < 0) /* when both negative */
+       if (rp < 0 && rs < 0) /* when both negative */
                goto err_close;
 
-       pthread_mutex_unlock(&g_mutex);
        return &g_conn[bus_type];
 
 err_close: