Author: lslezak
Date: Tue Feb 10 12:57:13 2009
New Revision: 55383
URL: http://svn.opensuse.org/viewcvs/yast?rev=55383&view=rev
Log:
- DBus service - added type checking
Modified:
branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc
branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.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=55383&r1=55382&r2=55383&view=diff
==============================================================================
--- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc (original)
+++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.cc Tue Feb 10 12:57:13 2009
@@ -16,7 +16,7 @@
#include
#include
-#include
+#include
#include
#include <functional>
@@ -237,6 +237,37 @@
return DBusServerBase::connect(SYSTEM, "org.opensuse.yast.modules");
}
+/*
+ convert string starting with '`' to YCPSymbol
+ convert string starting with '.' to YCPPath
+*/
+YCPValue DBusModulesServer::AutoCast(const YCPValue &value, constTypePtr requested_type)
+{
+ if (value->isString())
+ {
+ std::string value_str(value->asString()->value());
+
+ if (requested_type->isSymbol())
+ {
+ if (!value_str.empty() && value_str[0] == '`')
+ {
+ y2milestone("Automatic cast: string -> YCPSymbol");
+ return YCPSymbol(value_str);
+ }
+ }
+ else if (requested_type->isPath())
+ {
+ if (!value_str.empty() && value_str[0] == '.')
+ {
+ y2milestone("Automatic cast: string -> YCPPath");
+ return YCPPath(value_str);
+ }
+ }
+ }
+
+ return value;
+}
+
DBusMsg DBusModulesServer::handler(const DBusMsg &request)
{
YCPValue ret;
@@ -274,15 +305,44 @@
if (y2func)
{
int index = 0;
+ bool valid_arguments = true;
while(index < reqarg)
{
YCPValue arg = request.getYCPValue(index);
+
+ // check the data type compatibility
+ constTypePtr argtype(fptr->parameterType(index));
+
+ if (argtype->matchvalue(arg) < 0)
+ {
+ if (interface == "org.opensuse.yast.modules.Values")
+ {
+ // try converting DBus types to YCPValues in the raw interface
+ arg = AutoCast(arg, argtype);
+ // do the typecheck again
+ valid_arguments = argtype->matchvalue(arg) < 0;
+ }
+ else
+ {
+ valid_arguments = false;
+ }
+
+ if (!valid_arguments)
+ {
+ y2error("Invalid argument %d (%s): Function %s::%s() requires type '%s' instead of '%s'",
+ index, arg->toString().c_str(), object.c_str(), method.c_str(),
+ argtype->toString().c_str(), Type::vt2type(arg->valuetype())->toString().c_str()
+ );
+ break;
+ }
+ }
+
y2func->appendParameter(arg);
index ++;
}
- if (y2func->finishParameters())
+ if (valid_arguments && y2func->finishParameters())
{
// call the function
ret = y2func->evaluateCall();
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=55383&r1=55382&r2=55383&view=diff
==============================================================================
--- branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h (original)
+++ branches/tmp/lslezak/core/dbus/namespace_service/DBusModulesServer.h Tue Feb 10 12:57:13 2009
@@ -45,6 +45,9 @@
constTypePtr searchFuncType(const std::string &objname, const std::string &fname) const;
std::string Y2Dtype(constTypePtr type) const;
+ // try to cast from a DBus value to the expected YCPValue
+ YCPValue AutoCast(const YCPValue &value, constTypePtr requested_type);
+
// register the functions from the namespace to DBus service
void registerFunctions(const std::string &interface_prefix, bool do_marshalling);
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org