Tizen 2.1 base
[platform/framework/web/wrt-security.git] / src / services / ocsp / dbus / ocsp_server_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        ocsp_service_dbus_interface.cpp
18  * @author      Piotr Marcinkiewicz (p.marcinkiew@samsung.com)
19  * @version     1.0
20  * @brief       Implementation of OCSP server API.
21  */
22 #include "ocsp_server_dbus_interface.h"
23 #include <vcore/VerificationStatus.h>
24 #include <dpl/foreach.h>
25 #include <vcore/CertificateVerifier.h>
26 #include <vcore/VerificationStatus.h>
27 #include <dpl/wrt-dao-ro/global_config.h>
28 #include <dpl/ace-dao-ro/common_dao_types.h>
29 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
30 #include "ocsp_controller.h"
31
32
33
34 namespace RPC {
35
36 using namespace WrtSecurity;
37
38 OcspServerDBusInterface::OcspServerDBusInterface():
39     DPL::DBus::InterfaceDispatcher(OcspServerApi::INTERFACE_NAME())
40 {
41     setXmlSignature("<node>"
42         "  <interface name='" + OcspServerApi::INTERFACE_NAME() + "'>"
43         "    <method name='" + OcspServerApi::ECHO_METHOD() + "'>"
44         "      <arg type='s' name='input' direction='in'/>"
45         "      <arg type='s' name='output' direction='out'/>"
46         "    </method>"
47         "    <method name='" + OcspServerApi::CHECK_ACCESS_METHOD() + "'>"
48         "      <arg type='i' name='input' direction='in'/>"
49         "      <arg type='i' name='output' direction='out'/>"
50         "    </method>"
51         "  </interface>"
52         "</node>");
53 }
54
55 void OcspServerDBusInterface::onResponse(
56         OCSPControllerEvents::ErrorCode argError,
57         ValidationCore::WidgetVerificationStatus argState)
58 {
59     Assert(!m_invocationFifo.empty());
60     GDBusMethodInvocation* invocation = m_invocationFifo.front();
61     m_invocationFifo.pop_front();
62
63     if (OCSPControllerEvents::ErrorOK == argError) {
64
65         gint32 response = static_cast<gint32>(argState);
66
67         //Ownership is transferred to return value function
68         GVariant* varResponse = g_variant_new ("(i)", response);
69         //This function will unref invocation and it will be freed
70         LogDebug("OCSP dbus interface tries to send result");
71         g_dbus_method_invocation_return_value(invocation,
72                                               varResponse);
73     } else if (OCSPControllerEvents::ErrorNoWidget == argError) {
74         g_dbus_method_invocation_return_dbus_error(
75                 invocation,
76                 "org.tizen.OcspCheck.WidgetNotFound",
77                 "WidgetDAOReadOnly returned error WidgetNotFound");
78     } else if (OCSPControllerEvents::ErrorUnknown == argError) {
79         g_dbus_method_invocation_return_dbus_error(
80                 invocation,
81                 "org.tizen.OcspCheck.UnknownError",
82                 "WidgetDAOReadOnly returned unknown error");
83     } else {
84         Assert(false && "Not supported error code");
85     }
86 }
87
88 void OcspServerDBusInterface::onMethodCall(
89         const gchar* argMethodName,
90         GVariant* argParameters,
91         GDBusMethodInvocation* argInvocation)
92 {
93     if (OcspServerApi::ECHO_METHOD() == argMethodName){
94         // TODO: Deserialization should use
95         // DBus::SErverDeserialization::deserialize()
96         const gchar* arg = NULL;
97         g_variant_get(argParameters, "(&s)", &arg);
98         // TODO: Serialization should use
99         // DBus::SErverDeserialization::serialize()
100         gchar* response = g_strdup_printf(arg);
101         g_dbus_method_invocation_return_value(argInvocation,
102                                               g_variant_new ("(s)", response));
103         g_free (response);
104     } else if (OcspServerApi::CHECK_ACCESS_METHOD() == argMethodName) {
105         gint32 value;
106         //TODO: Check if argument is valid and report error for invalid
107         g_variant_get(argParameters, "(i)", &value);
108         WrtDB::DbWidgetHandle handle = static_cast<WrtDB::DbWidgetHandle>(
109                 value);
110
111         m_invocationFifo.push_back(argInvocation);
112         CONTROLLER_POST_EVENT(
113                 OCSPController,
114                 OCSPControllerEvents::OCSPCheckEvent(
115                         handle,
116                         makeICDelegate(&OcspServerDBusInterface::onResponse)
117                 )
118         );
119     }
120 }
121
122 } // namespace RPC