Author: lslezak Date: Mon Jul 14 12:42:34 2008 New Revision: 49029 URL: http://svn.opensuse.org/viewcvs/yast?rev=49029&view=rev Log: - Polkit.cc - convert SCR path to a valid PolicyKit ID (replace invalid characters by '-') - DBusConn::connect() - connection name is optional - DBusMsg - support for DBUS_TYPE_ARRAY Modified: branches/tmp/lslezak/workshop/core/scr/src/DBusConn.cc branches/tmp/lslezak/workshop/core/scr/src/DBusConn.h branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc branches/tmp/lslezak/workshop/core/scr/src/PolKit.cc Modified: branches/tmp/lslezak/workshop/core/scr/src/DBusConn.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/scr/src/DBusConn.cc?rev=49029&r1=49028&r2=49029&view=diff ============================================================================== --- branches/tmp/lslezak/workshop/core/scr/src/DBusConn.cc (original) +++ branches/tmp/lslezak/workshop/core/scr/src/DBusConn.cc Mon Jul 14 12:42:34 2008 @@ -49,25 +49,28 @@ return false; } - y2milestone("Registering service %s", service.c_str()); - - // set the service name, replace the existing owner if it's allowed - int result = dbus_bus_request_name(connection, service.c_str(), DBUS_NAME_FLAG_REPLACE_EXISTING, &dbus_error); - if (dbus_error_is_set(&dbus_error)) + if (!service.empty()) { - y2error("Cannot register service %s: %s", service.c_str(), dbus_error.message); - return false; - } + y2milestone("Registering service %s", service.c_str()); + + // set the service name, replace the existing owner if it's allowed + int result = dbus_bus_request_name(connection, service.c_str(), DBUS_NAME_FLAG_REPLACE_EXISTING, &dbus_error); + if (dbus_error_is_set(&dbus_error)) + { + y2error("Cannot register service %s: %s", service.c_str(), dbus_error.message); + return false; + } + + // primary owner? + if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) + { + y2error("Service %s is already registered", service.c_str()); + return false; + } - // primary owner? - if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) - { - y2error("Service %s is already registered", service.c_str()); - return false; + y2milestone("Service %s successfuly registered", service.c_str()); } - y2milestone("Service %s successfuly registered", service.c_str()); - return true; } @@ -109,3 +112,16 @@ { return connection; } + +DBusMsg DBusConn::call(const DBusMsg &msg) +{ + DBusMessage *reply = dbus_connection_send_with_reply_and_block(connection, msg.getMessage(), -1, &dbus_error); + + DBusMsg ret; + if (reply != NULL) + { + ret.setMessage(reply); + } + + return ret; +} Modified: branches/tmp/lslezak/workshop/core/scr/src/DBusConn.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/scr/src/DBusConn.h?rev=49029&r1=49028&r2=49029&view=diff ============================================================================== --- branches/tmp/lslezak/workshop/core/scr/src/DBusConn.h (original) +++ branches/tmp/lslezak/workshop/core/scr/src/DBusConn.h Mon Jul 14 12:42:34 2008 @@ -27,9 +27,10 @@ DBusConn(); ~DBusConn(); - bool connect(DBusBusType type, const std::string& service); + bool connect(DBusBusType type, const std::string& service = std::string()); void setTimeout(int miliseconds); bool send(const DBusMsg &msg); + DBusMsg call(const DBusMsg &msg); void flush(); DBusMsg receive(); DBusConnection *getConnection() const; Modified: branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc?rev=49029&r1=49028&r2=49029&view=diff ============================================================================== --- branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc (original) +++ branches/tmp/lslezak/workshop/core/scr/src/DBusMsg.cc Mon Jul 14 12:42:34 2008 @@ -375,6 +375,57 @@ // recurse into the variant iterator return getYCPValue(&sub); } + else if (type == DBUS_TYPE_ARRAY) + { + YCPList lst; + YCPMap map; + + bool list_container = true; + + DBusMessageIter sub; + dbus_message_iter_recurse(it, &sub); + + while (dbus_message_iter_get_arg_type (&sub) != DBUS_TYPE_INVALID) + { + // is it a map or a list? + if (dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_DICT_ENTRY) + { + DBusMessageIter mapit; + dbus_message_iter_recurse(&sub, &mapit); + + // it's a map + list_container = false; + + // read the key + YCPValue key = getYCPValue(&mapit); + + dbus_message_iter_next(&mapit); + + // read the value + YCPValue val = getYCPValue(&mapit); + + map->add(key, val); + } + else + { + // it's a list + YCPValue item = getYCPValue(&sub); + + if (!item.isNull()) + { + lst->add(item); + } + } + + dbus_message_iter_next(&sub); + } + + // return the correct result + if (list_container) + return lst; + else + return map; + } else if (type == DBUS_TYPE_DOUBLE) { double d; Modified: branches/tmp/lslezak/workshop/core/scr/src/PolKit.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/workshop/core/scr/src/PolKit.cc?rev=49029&r1=49028&r2=49029&view=diff ============================================================================== --- branches/tmp/lslezak/workshop/core/scr/src/PolKit.cc (original) +++ branches/tmp/lslezak/workshop/core/scr/src/PolKit.cc Mon Jul 14 12:42:34 2008 @@ -62,8 +62,24 @@ std::string ret(s); for (std::string::size_type i = 0; i < ret.length(); ++i) { - if (isupper(ret[i])) - ret[i] = static_cast<char>(tolower(ret[i])); + char ch = ret[i]; + + // skip valid charcters + if (islower(ch) || isdigit(ch) || ch == '.' || ch == '-') + continue; + + // convert uppercase to lowercase + if (isupper(ch)) + ret[i] = static_cast<char>(tolower(ch)); + else + // replace invalid characters + ret[i] = '-'; + } + + // max. length is 255 + if (ret.size() > 255) + { + ret = std::string(ret, 0, 255); } return ret; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org