Author: kkaempf
Date: Fri Feb 6 15:00:52 2009
New Revision: 55302
URL: http://svn.opensuse.org/viewcvs/yast?rev=55302&view=rev
Log:
Cleanup dbus/policykit files
- replace string constants with macros from DBus include files where
applicable
- replace repeatedly used string constants with #defines
- move definition of service name (org.opensuse.yast.SCR) to single
place (configure.in.in)
- replace calls to sed with autoconf macro expansion features where possible
- add test case
Added:
trunk/core/dbus/SCR_service/org.opensuse.yast.SCR.service.in.in
trunk/core/dbus/SCR_service/scr_names.h.in
trunk/core/dbus/SCR_service/test_SCR_dbus_server.rb.in (with props)
Removed:
trunk/core/dbus/SCR_service/org.opensuse.yast.SCR.service.in
Modified:
trunk/core/configure.in.in
trunk/core/dbus/SCR_service/DBusServer.cc
trunk/core/dbus/SCR_service/Makefile.am
trunk/core/dbus/SCR_service/org.opensuse.yast.SCR.conf.in
Modified: trunk/core/configure.in.in
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/configure.in.in?rev=55302&r1=55301&r2=55302&view=diff
==============================================================================
--- trunk/core/configure.in.in (original)
+++ trunk/core/configure.in.in Fri Feb 6 15:00:52 2009
@@ -124,6 +124,28 @@
HAVE_POLKIT=0
fi
+#
+# configuration for dbus/SCR_service
+#
+
+# set access mode according to the PolicyKit status
+# if policykit is disabled only root can access the service
+if test $HAVE_POLKIT -ne 0; then
+ACCESS_MODE=allow
+else
+ACCESS_MODE=deny
+fi
+
+
+YAST_SCR_SERVICE=org.opensuse.yast.SCR
+YAST_SCR_SERVICE_METHODS=$YAST_SCR_SERVICE.Methods
+# @ybindir@ expands to ${prefix}/lib/..., force full expansion here
+YAST_SCR_SERVICE_DIR=$ybindir
+AC_SUBST(YAST_SCR_SERVICE)
+AC_SUBST(YAST_SCR_SERVICE_METHODS)
+AC_SUBST(YAST_SCR_SERVICE_DIR)
+AC_SUBST(ACCESS_MODE)
+
AC_SUBST(POLKIT_CFLAGS)
AC_SUBST(POLKIT_LIBS)
AC_SUBST(HAVE_POLKIT)
@@ -133,5 +155,9 @@
AC_CONFIG_FILES([
scr/doc/SCR.html
scr/doc/intro_to_scr.html
+ dbus/SCR_service/org.opensuse.yast.SCR.conf
+ dbus/SCR_service/org.opensuse.yast.SCR.service.in
+ dbus/SCR_service/scr_names.h
+ dbus/SCR_service/test_SCR_dbus_server.rb
])
@YAST2-OUTPUT@
Modified: trunk/core/dbus/SCR_service/DBusServer.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/dbus/SCR_service/DBusServer.cc?rev=55302&r1=55301&r2=55302&view=diff
==============================================================================
--- trunk/core/dbus/SCR_service/DBusServer.cc (original)
+++ trunk/core/dbus/SCR_service/DBusServer.cc Fri Feb 6 15:00:52 2009
@@ -14,6 +14,10 @@
#include
+#include "scr_names.h"
+
+#define TIMEOUT 5000 /* 5 seconds */
+
extern "C"
{
// nanosleep()
@@ -47,7 +51,7 @@
bool DBusServer::connect()
{
// connect to DBus, request a service name
- return connection.connect(DBUS_BUS_SYSTEM, "org.opensuse.yast.SCR");
+ return connection.connect(DBUS_BUS_SYSTEM, YAST_SCR_SERVICE);
}
// set 30 second timer
@@ -151,7 +155,7 @@
}
// set 5 seconds timeout
- connection.setTimeout(5000);
+ connection.setTimeout(TIMEOUT);
// try reading a message from DBus
DBusMsg request(connection.receive());
@@ -172,7 +176,9 @@
request.interface().c_str(), request.method().c_str());
// check this is a method call for the right object, interface & method
- if (request.type() == DBUS_MESSAGE_TYPE_METHOD_CALL && request.interface() == "org.opensuse.yast.SCR.Methods" && request.path() == "/SCR")
+ if (request.type() == DBUS_MESSAGE_TYPE_METHOD_CALL
+ && request.interface() == YAST_SCR_SERVICE_METHODS
+ && request.path() == SCR_PATH)
{
std::string method(request.method());
@@ -182,9 +188,14 @@
bool check_ok = false;
// check missing arguments
- if (method == "Read" || method == "Write" || method == "Execute" ||
- method == "Dir" || method == "Error" || method == "UnregisterAgent" ||
- method == "UnmountAgent" || method == "RegisterAgent")
+ if (method == METHOD_READ
+ || method == METHOD_WRITE
+ || method == METHOD_EXECUTE
+ || method == METHOD_DIR
+ || method == METHOD_ERROR
+ || method == METHOD_UNREGISTER
+ || method == METHOD_UNMOUNT
+ || method == METHOD_REGISTER)
{
if (request.arguments() == 0)
{
@@ -207,7 +218,7 @@
}
}
}
- else if (method == "UnregisterAllAgents" || method != "RegisterNewAgents")
+ else if (method == METHOD_UNREGISTER_ALL || method != METHOD_REGISTER_NEW)
{
check_ok = true;
}
@@ -254,29 +265,29 @@
YCPValue ret;
- if (method == "Read")
+ if (method == METHOD_READ)
ret = sa->Read(pth, arg, opt);
- else if (method == "Write")
+ else if (method == METHOD_WRITE)
ret = sa->Write(pth, arg, opt);
- else if (method == "Execute")
+ else if (method == METHOD_EXECUTE)
ret = sa->Execute(pth, arg, opt);
- else if (method == "Dir")
+ else if (method == METHOD_DIR)
{
ret = sa->Dir(pth);
if (ret.isNull())
ret = YCPList();
}
- else if (method == "Error")
+ else if (method == METHOD_ERROR)
ret = sa->Error(pth);
- else if (method == "UnregisterAgent")
+ else if (method == METHOD_UNREGISTER)
ret = sa->UnregisterAgent(pth);
- else if (method == "UnregisterAllAgents")
+ else if (method == METHOD_UNREGISTER_ALL)
ret = sa->UnregisterAllAgents();
- else if (method == "UnmountAgent")
+ else if (method == METHOD_UNMOUNT)
ret = sa->UnmountAgent(pth);
- else if (method == "RegisterNewAgents")
+ else if (method == METHOD_REGISTER_NEW)
ret = sa->RegisterNewAgents();
- else if (method == "RegisterAgent")
+ else if (method == METHOD_REGISTER)
ret = sa->RegisterAgent(pth, arg);
else
y2internal("Unhandled method %s", method.c_str());
@@ -298,11 +309,11 @@
{
y2milestone("Requesting path: %s", request.path().c_str());
// define all exported methods here
- const char *introspect = (request.path() != "/SCR") ?
+ const char *introspect = (request.path() != SCR_PATH) ?
// introcpection data for the root node
DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
"<node>"
-" <interface name='org.freedesktop.DBus.Introspectable'>"
+" <interface name='"DBUS_INTERFACE_INTROSPECTABLE"'>"
" <method name='Introspect'>"
" <arg name='xml_data' type='s' direction='out'/>"
" </method>"
@@ -313,53 +324,53 @@
// introcpection data for SCR node
DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE
"<node>"
-" <interface name='org.opensuse.yast.SCR.Methods'>"
-" <method name='Read'>"
+" <interface name='"YAST_SCR_SERVICE_METHODS"'>"
+" <method name='"METHOD_READ"'>"
" <arg name='path' type='(bsv)' direction='in'/>"
" <arg name='arg' type='(bsv)' direction='in'/>"
" <arg name='opt' type='(bsv)' direction='in'/>"
" <arg name='ret' type='(bsv)' direction='out'/>"
" </method>"
-" <method name='Write'>"
+" <method name='"METHOD_WRITE"'>"
" <arg name='path' type='(bsv)' direction='in'/>"
" <arg name='arg' type='(bsv)' direction='in'/>"
" <arg name='opt' type='(bsv)' direction='in'/>"
" <arg name='ret' type='(bsv)' direction='out'/>"
" </method>"
-" <method name='Execute'>"
+" <method name='"METHOD_EXECUTE"'>"
" <arg name='path' type='(bsv)' direction='in'/>"
" <arg name='arg' type='(bsv)' direction='in'/>"
" <arg name='opt' type='(bsv)' direction='in'/>"
" <arg name='ret' type='(bsv)' direction='out'/>"
" </method>"
-" <method name='Dir'>"
+" <method name='"METHOD_DIR"'>"
" <arg name='path' type='(bsv)' direction='in'/>"
" <arg name='ret' type='(bsv)' direction='out'/>"
" </method>"
-" <method name='Error'>"
+" <method name='"METHOD_ERROR"'>"
" <arg name='path' type='(bsv)' direction='in'/>"
" <arg name='ret' type='(bsv)' direction='out'/>"
" </method>"
-" <method name='UnregisterAgent'>"
+" <method name='"METHOD_UNREGISTER"'>"
" <arg name='path' type='(bsv)' direction='in'/>"
" <arg name='ret' type='(bsv)' direction='out'/>"
" </method>"
-" <method name='UnregisterAllAgents'>"
+" <method name='"METHOD_UNREGISTER_ALL"'>"
" <arg name='ret' type='(bsv)' direction='out'/>"
" </method>"
-" <method name='RegisterNewAgents'>"
+" <method name='"METHOD_REGISTER_NEW"'>"
" <arg name='ret' type='(bsv)' direction='out'/>"
" </method>"
-" <method name='RegisterAgent'>"
+" <method name='"METHOD_REGISTER"'>"
" <arg name='path' type='(bsv)' direction='in'/>"
" <arg name='arg' type='(bsv)' direction='in'/>"
" <arg name='ret' type='(bsv)' direction='out'/>"
" </method>"
-" <method name='UnmountAgent'>"
+" <method name='"METHOD_UNMOUNT"'>"
" <arg name='path' type='(bsv)' direction='in'/>"
" <arg name='ret' type='(bsv)' direction='out'/>"
" </method>"
-" <interface name='org.freedesktop.DBus.Introspectable'>"
+" <interface name='"DBUS_INTERFACE_INTROSPECTABLE"'>"
" <method name='Introspect'>"
" <arg name='xml_data' type='s' direction='out'/>"
" </method>"
@@ -425,7 +436,7 @@
const std::string &arg, const std::string &opt)
{
// create actionId
- static const char *polkit_prefix = "org.opensuse.yast.scr";
+ static const char *polkit_prefix = POLKIT_PREFIX;
// check the access right to all methods at first (see bnc#449794)
std::string action_id(PolKit::createActionId(polkit_prefix, "", method, "", ""));
@@ -478,8 +489,8 @@
DBusMsg query;
// ask the DBus server for the PID of the caller
- query.createCall("org.freedesktop.DBus", "/org/freedesktop/DBus/Bus",
- "org.freedesktop.DBus", "GetConnectionUnixProcessID");
+ query.createCall(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS"/Bus",
+ DBUS_SERVICE_DBUS, "GetConnectionUnixProcessID");
query.addString(bus_name);
Modified: trunk/core/dbus/SCR_service/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/dbus/SCR_service/Makefile.am?rev=55302&r1=55301&r2=55302&view=diff
==============================================================================
--- trunk/core/dbus/SCR_service/Makefile.am (original)
+++ trunk/core/dbus/SCR_service/Makefile.am Fri Feb 6 15:00:52 2009
@@ -1,8 +1,12 @@
#
-# Makefile.am for dbus/service
+# Makefile.am for dbus/SCR_service
#
-EXTRA_DIST=org.opensuse.yast.SCR.service.in org.opensuse.yast.SCR.conf.in org.opensuse.yast.scr.policy
+EXTRA_DIST=org.opensuse.yast.SCR.service.in.in \
+ org.opensuse.yast.SCR.conf.in \
+ org.opensuse.yast.scr.policy \
+ scr_names.h.in \
+ test_SCR_dbus_server.rb.in
AM_CXXFLAGS = -DY2LOG=\"SCR-service\" -DSUSEVERSION=\"${SUSEVERSION}\"
@@ -24,35 +28,22 @@
check-local:
polkit-policy-file-validate $(polkit_policies_DATA)
-
# service activation config
# FIXME?? dbus pkgconfig provides only 'session_bus_services_dir'
dbus_servicesdir = `pkg-config --print-errors --variable prefix dbus-1`/share/dbus-1/system-services
-dbus_services_in_files = org.opensuse.yast.SCR.service.in
+# Can't use autoconf only because @ybindir@ expands to '${prefix}/...'.
+# So must use %YBINDIR% and expand it via sed during make
+# Ouch, ouch, ouch
+dbus_services_in_files = org.opensuse.yast.SCR.service.in
dbus_services_DATA = $(dbus_services_in_files:.service.in=.service)
$(dbus_services_DATA): $(dbus_services_in_files)
- sed -e "s|\@YBINDIR\@|$(ybindir)|" $< > $@
+ sed -e "s|\%YBINDIR\%|$(ybindir)|" $< > $@
# service config
dbus_confdir = `pkg-config --print-errors --variable sysconfdir dbus-1`/dbus-1/system.d
-
-dbus_conf_in_files = org.opensuse.yast.SCR.conf.in
-
-dbus_conf_DATA = $(dbus_conf_in_files:.conf.in=.conf)
-
-# set access mode according to the PolicyKit status
-# if policykit is disabled only root can access the service
-if HAVE_POLKIT
-dbus_access_mode=allow
-else
-dbus_access_mode=deny
-endif
-
-$(dbus_conf_DATA): $(dbus_conf_in_files)
- sed -e "s|\@ACCESS_MODE\@|$(dbus_access_mode)|" $< > $@
-
+dbus_conf_DATA = org.opensuse.yast.SCR.conf
Modified: trunk/core/dbus/SCR_service/org.opensuse.yast.SCR.conf.in
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/dbus/SCR_service/org.opensuse.yast.SCR.conf.in?rev=55302&r1=55301&r2=55302&view=diff
==============================================================================
--- trunk/core/dbus/SCR_service/org.opensuse.yast.SCR.conf.in (original)
+++ trunk/core/dbus/SCR_service/org.opensuse.yast.SCR.conf.in Fri Feb 6 15:00:52 2009
@@ -6,15 +6,15 @@
https://bugzilla.novell.com/show_bug.cgi?id=468390
-->
<policy user="root">
- <allow own="org.opensuse.yast.SCR"/>
- <allow send_destination="org.opensuse.yast.SCR"/>
+ <allow own="@YAST_SCR_SERVICE@"/>
+ <allow send_destination="@YAST_SCR_SERVICE@"/>
</policy>
<policy context="default">
<!-- allowed iff compiled with PolicyKit -->
- <@ACCESS_MODE@ send_destination="org.opensuse.yast.SCR"
- send_interface="org.opensuse.yast.SCR.Methods"/>
+ <@ACCESS_MODE@ send_destination="@YAST_SCR_SERVICE@"
+ send_interface="@YAST_SCR_SERVICE_METHODS@"/>
<!-- introspection is allowed -->
- http://svn.opensuse.org/viewcvs/yast/trunk/core/dbus/SCR_service/org.opensuse.yast.SCR.service.in.in?rev=55302&view=auto
==============================================================================
--- trunk/core/dbus/SCR_service/org.opensuse.yast.SCR.service.in.in (added)
+++ trunk/core/dbus/SCR_service/org.opensuse.yast.SCR.service.in.in Fri Feb 6 15:00:52 2009
@@ -0,0 +1,5 @@
+# DBus service activation config
+[D-BUS Service]
+Name=@YAST_SCR_SERVICE@
+Exec=%YBINDIR%/SCR_dbus_server
+User=root
Added: trunk/core/dbus/SCR_service/scr_names.h.in
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/dbus/SCR_service/scr_names.h.in?rev=55302&view=auto
==============================================================================
--- trunk/core/dbus/SCR_service/scr_names.h.in (added)
+++ trunk/core/dbus/SCR_service/scr_names.h.in Fri Feb 6 15:00:52 2009
@@ -0,0 +1,22 @@
+/*
+ * scr_names.h - generated from scr_names.h.in
+ *
+ */
+
+#define YAST_SCR_SERVICE "@YAST_SCR_SERVICE@"
+#define YAST_SCR_SERVICE_METHODS "@YAST_SCR_SERVICE_METHODS@"
+
+#define METHOD_READ "Read"
+#define METHOD_WRITE "Write"
+#define METHOD_EXECUTE "Execute"
+#define METHOD_DIR "Dir"
+#define METHOD_ERROR "Error"
+#define METHOD_REGISTER "RegisterAgent"
+#define METHOD_UNREGISTER "UnregisterAgent"
+#define METHOD_UNMOUNT "UnmountAgent"
+#define METHOD_UNREGISTER_ALL "UnregisterAllAgents"
+#define METHOD_REGISTER_NEW "RegisterNewAgents"
+
+#define SCR_PATH "/SCR"
+
+#define POLKIT_PREFIX "org.opensuse.yast.scr"
Added: trunk/core/dbus/SCR_service/test_SCR_dbus_server.rb.in
URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/dbus/SCR_service/test_SCR_dbus_server.rb.in?rev=55302&view=auto
==============================================================================
--- trunk/core/dbus/SCR_service/test_SCR_dbus_server.rb.in (added)
+++ trunk/core/dbus/SCR_service/test_SCR_dbus_server.rb.in Fri Feb 6 15:00:52 2009
@@ -0,0 +1,33 @@
+#!/usr/bin/env ruby
+
+#
+# Test code for SCR_service
+#
+# test_SCR_dbus_server.rb is generated from test_SCR_dbus_server.rb.in
+#
+require 'test/unit'
+
+begin
+ require "dbus"
+rescue Exception => e
+ $stderr.puts "Please install ruby-dbus"
+ exit
+end
+
+class DBusTest < Test::Unit::TestCase
+ def test_loading
+ system_bus = DBus::SystemBus.instance
+ assert system_bus
+
+ # Get the yast service
+ yast = system_bus.service("@YAST_SCR_SERVICE@")
+ assert yast
+
+ # Get the object from this service
+ objYast = yast.object("/SCR")
+ assert objYast
+
+ poiSCR = DBus::ProxyObjectInterface.new(objYast, "@YAST_SCR_SERVICE_METHODS@")
+ assert poiSCR
+ end
+end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org