tizen 2.3.1 release
[framework/web/wearable/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
24 namespace RPC {
25
26 using namespace WrtSecurity;
27
28 OcspServerDBusInterface::OcspServerDBusInterface():
29     DPL::DBus::InterfaceDispatcher(OcspServerApi::INTERFACE_NAME())
30 {
31     setXmlSignature("<node>"
32         "  <interface name='" + OcspServerApi::INTERFACE_NAME() + "'>"
33         "    <method name='" + OcspServerApi::ECHO_METHOD() + "'>"
34         "      <arg type='s' name='input' direction='in'/>"
35         "      <arg type='s' name='output' direction='out'/>"
36         "    </method>"
37         "    <method name='" + OcspServerApi::CHECK_ACCESS_METHOD() + "'>"
38         "      <arg type='i' name='input' direction='in'/>"
39         "      <arg type='i' name='output' direction='out'/>"
40         "    </method>"
41         "  </interface>"
42         "</node>");
43 }
44
45
46 void OcspServerDBusInterface::onMethodCall(
47         const gchar* argMethodName,
48         GVariant* argParameters,
49         GDBusMethodInvocation* argInvocation)
50 {
51     if (OcspServerApi::ECHO_METHOD() == argMethodName){
52         // TODO: Deserialization should use
53         // DBus::SErverDeserialization::deserialize()
54         const gchar* arg = NULL;
55         g_variant_get(argParameters, "(&s)", &arg);
56         // TODO: Serialization should use
57         // DBus::SErverDeserialization::serialize()
58         gchar* response = g_strdup_printf(arg);
59         g_dbus_method_invocation_return_value(argInvocation,
60                                               g_variant_new ("(s)", response));
61         g_free (response);
62     } else if (OcspServerApi::CHECK_ACCESS_METHOD() == argMethodName) {
63         gint32 value;
64         g_variant_get(argParameters, "(i)", &value);
65
66         // TODO: this is making OCSP service a stub! this HAS to be moved
67         // with proper implementation to cert-svc daemon
68         gint32 response = 0; // Certificates are valid for now
69
70         GVariant* varResponse = g_variant_new ("(i)", response);
71                 //This function will unref invocation and it will be freed
72         LogDebug("OCSP dbus interface tries to send result");
73         g_dbus_method_invocation_return_value(argInvocation, varResponse);
74     }
75 }
76
77 } // namespace RPC