Author: lslezak Date: Fri Feb 27 14:54:34 2009 New Revision: 55815 URL: http://svn.opensuse.org/viewcvs/yast?rev=55815&view=rev Log: - DBus service - handle unknown requests, added autoimport functionality Modified: branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h Modified: branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc?rev=55815&r1=55814&r2=55815&view=diff ============================================================================== --- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc (original) +++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc Fri Feb 27 14:54:34 2009 @@ -76,7 +76,7 @@ y2milestone("Imported name space: %s, using object name: %s", nspace.c_str(), objname.c_str()); - nsmap[objname] = ns; + nsmap[YAST_DBUS_OBJ_PREFIX"/" + objname] = ns; return registerNamespace(ns); } @@ -131,15 +131,18 @@ parindex++; } + std::string namespace_str(nspace); + MakeValidObjectName(namespace_str); + if (params_ok_raw) { sig_raw.params = p_raw; // register the function: register_function(object, interface, method, signature, handler) - register_method(YAST_DBUS_OBJ_PREFIX"/" + nspace, YAST_DBUS_RAW_INTERFACE, fname, sig_raw, e); + register_method(YAST_DBUS_OBJ_PREFIX"/" + namespace_str, YAST_DBUS_RAW_INTERFACE, fname, sig_raw, e); } sig_marshalled.params = p_marshalled; - register_method(YAST_DBUS_OBJ_PREFIX"/" + nspace, YAST_DBUS_YCP_INTERFACE, fname, sig_marshalled, e); + register_method(YAST_DBUS_OBJ_PREFIX"/" + namespace_str, YAST_DBUS_YCP_INTERFACE, fname, sig_marshalled, e); return true; } @@ -258,6 +261,11 @@ constTypePtr DBusModulesServer::searchFuncType(const std::string &objname, const std::string &fname) const { + if (nsmap.find(objname) == nsmap.end()) + { + y2error("Object: %s not found", objname.c_str()); + return NULL; + } Y2Namespace *ns = nsmap.find(objname)->second; if (ns) @@ -374,12 +382,6 @@ std::string object(request.path()); std::string interface(request.interface()); - // remove the leading slash from the object name - if (!object.empty() && object[0] == '/') - { - object.erase(object.begin()); - } - y2debug("Requested object: %s, interface: %s, method: %s", object.c_str(), interface.c_str(), method.c_str()); constTypePtr t = searchFuncType(object, method); @@ -635,3 +637,47 @@ return retlist; } +// handle unknown requests +DBusMsg DBusModulesServer::unknownRequest(const DBusMsg &request) +{ + y2debug("Unknown request handler called"); + std::string req_path(request.path()); + DBusMsg reply; + + // subtree match + if (req_path.substr(0, sizeof(YAST_DBUS_OBJ_PREFIX) - 1) == YAST_DBUS_OBJ_PREFIX) + { + y2debug("Found object prefix " YAST_DBUS_OBJ_PREFIX " in request"); + std::string req_namespace(req_path, sizeof(YAST_DBUS_OBJ_PREFIX)); + + // hack: replace __ in request to :: to make a valid namespace + // DBus object name cannot contain :: + std::string::size_type pos = req_namespace.find("__"); + if (pos != std::string::npos) + { + req_namespace.replace(pos, 2, "::"); + } + + y2milestone("Autoimporting namespace %s...", req_namespace.c_str()); + + if (importNamespace(req_namespace)) + { + y2milestone("Import succeded, calling the handler again..."); + // call the handler again (polikt has already allowed the access) + reply = handler(request); + y2debug("Request handled"); + } + else + { + reply.createError(request, "Automatic import failed, unknown object", DBUS_ERROR_UNKNOWN_METHOD); + } + } + else + { + reply.createError(request, "Unknown object, interface or method", DBUS_ERROR_UNKNOWN_METHOD); + } + + return reply; +} + + Modified: branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h?rev=55815&r1=55814&r2=55815&view=diff ============================================================================== --- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h (original) +++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h Fri Feb 27 14:54:34 2009 @@ -35,6 +35,8 @@ virtual actionList createActionId(const DBusMsg &msg); + // handle unknown requests + virtual DBusMsg unknownRequest(const DBusMsg &request); private: Modified: branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc?rev=55815&r1=55814&r2=55815&view=diff ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.cc Fri Feb 27 14:54:34 2009 @@ -159,8 +159,8 @@ // create a reply to the message DBusMsg reply; - y2milestone("Received request from %s: interface: %s, method: %s", request.sender().c_str(), - request.interface().c_str(), request.method().c_str()); + y2milestone("Received request from %s: object: %s, interface: %s, method: %s", request.sender().c_str(), + request.path().c_str(), request.interface().c_str(), request.method().c_str()); // handle Introspection request from "org.freedesktop.DBus.Introspectable" "Introspect" if (request.isMethodCall(DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) @@ -247,12 +247,6 @@ // find the registered object std::string objname = request.path(); - // remove the slash at the beginning - if (objname.size() > 0 && objname[0] == '/') - { - objname.erase(objname.begin()); - } - // search the object Objects::const_iterator i = registered_objects.find(objname); @@ -297,14 +291,15 @@ if (!found) { - // report error - reply.createError(request, "Unknown object, interface or method", DBUS_ERROR_UNKNOWN_METHOD); + // call unknown method handler + y2debug("Calling unknownRequest handler..."); + reply = unknownRequest(request); } } else { // report error - reply.createError(request, "Access denied, check PolicyKit priviledges", DBUS_ERROR_ACCESS_DENIED); + reply.createError(request, "Unknown method or access denied (check PolicyKit priviledges)", DBUS_ERROR_ACCESS_DENIED); } } else if (request.type() == DBUS_MESSAGE_TYPE_ERROR) @@ -461,6 +456,7 @@ DBusServerBase::actionList DBusServerBase::createActionId(const DBusMsg &msg) { + y2debug("Using default empty list of action IDs"); // default implementation is empty list // the inherited classes should redefine it return actionList(); @@ -498,3 +494,12 @@ } } } + +DBusMsg DBusServerBase::unknownRequest(const DBusMsg &request) +{ + DBusMsg err_reply; + y2error("Unknown object, interface or method"); + err_reply.createError(request, "Unknown object, interface or method", DBUS_ERROR_UNKNOWN_METHOD); + + return err_reply; +} Modified: branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h?rev=55815&r1=55814&r2=55815&view=diff ============================================================================== --- branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h (original) +++ branches/tmp/lslezak/core/liby2dbus/src/DBusServerBase.h Fri Feb 27 14:54:34 2009 @@ -55,6 +55,9 @@ // create PolicyKit action ID for the received message virtual actionList createActionId(const DBusMsg &msg); + // handle unknown requests + virtual DBusMsg unknownRequest(const DBusMsg &request); + std::string service_name; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org