tizen 2.3.1 release
[framework/web/wearable/wrt-security.git] / src / services / popup / dbus / popup_response_dbus_interface.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    popup_response_dispatcher.cpp
18  * @author  Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
19  * @version 1.0
20  * @brief
21  */
22
23 #include "popup_response_dbus_interface.h"
24 #include <vector>
25 #include <string>
26 #include <dpl/dbus/dbus_server_deserialization.h>
27 #include <dpl/dbus/dbus_server_serialization.h>
28 #include <ace/Request.h>
29 #include <ace-dao-ro/PromptModel.h>
30 #include "popup_ace_data_types.h"
31 //#include "access-control/engine/PromptModel.h"
32 #include "attribute_facade.h"
33 //#include "Request.h"
34 #include "security_controller.h"
35
36 namespace RPC
37 {
38
39 void PopupResponseDBusInterface::onMethodCall(const gchar* methodName,
40                                            GVariant* parameters,
41                                            GDBusMethodInvocation* invocation)
42 {
43     using namespace WrtSecurity;
44 #if 1
45     if (0 == g_strcmp0(methodName,
46             PopupServerApi::VALIDATION_METHOD().c_str()))
47     {
48         // popup answer data
49         bool allowed = false;
50         int serializedValidity = 0;
51
52         // ACE data
53         AceUserdata acedata;
54
55         if (!DPL::DBus::ServerDeserialization::deserialize(
56                 parameters,
57                 &allowed,
58                 &serializedValidity,
59                 &(acedata.handle),
60                 &(acedata.subject),
61                 &(acedata.resource),
62                 &(acedata.paramKeys),
63                 &(acedata.paramValues),
64                 &(acedata.sessionId)))
65         {
66             g_dbus_method_invocation_return_dbus_error(
67                           invocation,
68                           "org.tizen.PopupResponse.UnknownError",
69                           "Error in deserializing input parameters");
70             return;
71         }
72
73         if (acedata.paramKeys.size() != acedata.paramValues.size()) {
74             g_dbus_method_invocation_return_dbus_error(
75                       invocation,
76                       "org.tizen.PopupResponse.UnknownError",
77                       "Varying sizes of parameter names and parameter values");
78             return;
79         }
80
81         FunctionParamImpl params;
82         for (size_t i = 0; i < acedata.paramKeys.size(); ++i) {
83             params.addAttribute(acedata.paramKeys[i], acedata.paramValues[i]);
84         }
85         Request request(acedata.handle,
86                         WidgetExecutionPhase_Invoke,
87                         &params);
88         request.addDeviceCapability(acedata.resource);
89
90         Prompt::Validity validity = static_cast<Prompt::Validity>(serializedValidity);
91
92         bool response = false;
93         SecurityControllerEvents::ValidatePopupResponseEvent ev(
94             &request,
95             allowed,
96             validity,
97             acedata.sessionId,
98             &response);
99         CONTROLLER_POST_SYNC_EVENT(SecurityController, ev);
100
101         g_dbus_method_invocation_return_value(
102             invocation,
103             DPL::DBus::ServerSerialization::serialize(response));
104     }
105 #endif
106 }
107
108 }