tizen 2.3 release
[framework/web/wearable/wrt-security.git] / src / services / popup / socket / popup_service_callbacks.cpp
1 /*
2  * Copyright (c) 2012 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_service_callbacks.cpp
18  * @author      Zofia Abramowska (z.abramowska@samsung.com)
19  * @version     1.0
20  * @brief       Implementation of Popup Service callbacks
21  */
22
23 #include "popup_service_callbacks.h"
24 #include <callback_api.h>
25 #include <ace/Request.h>
26 #include <ace-dao-ro/PromptModel.h>
27 #include <dpl/log/log.h>
28 #include "attribute_facade.h"
29 #include "popup_ace_data_types.h"
30 #include "security_controller.h"
31 #include <security_caller.h>
32
33 namespace RPC {
34
35 void PopupServiceCallbacks::validate(SocketConnection * connector){
36
37     bool allowed = false;
38     int serializedValidity = 0;
39
40     AceUserdata acedata;
41
42     Try {
43         connector->read(&allowed,
44                         &serializedValidity,
45                         &(acedata.handle),
46                         &(acedata.subject),
47                         &(acedata.resource),
48                         &(acedata.paramKeys),
49                         &(acedata.paramValues),
50                         &(acedata.sessionId));
51     } Catch (SocketConnection::Exception::SocketConnectionException){
52         LogError("Socket connection read error");
53         ReThrowMsg(ServiceCallbackApi::Exception::ServiceCallbackException,
54                    "Socket connection read error");
55     }
56
57     if (acedata.paramKeys.size() != acedata.paramValues.size()) {
58         ThrowMsg(ServiceCallbackApi::Exception::ServiceCallbackException,
59                  "Varying sizes of parameter names vector and parameter values vector");
60     }
61     FunctionParamImpl params;
62     for (size_t i = 0; i < acedata.paramKeys.size(); ++i) {
63         params.addAttribute(acedata.paramKeys[i], acedata.paramValues[i]);
64     }
65     Request request(acedata.handle,
66                     WidgetExecutionPhase_Invoke,
67                     &params);
68     request.addDeviceCapability(acedata.resource);
69
70     Prompt::Validity validity = static_cast<Prompt::Validity>(serializedValidity);
71
72     bool response = false;
73     SecurityControllerEvents::ValidatePopupResponseEvent ev(
74         &request,
75         allowed,
76         validity,
77         acedata.sessionId,
78         &response);
79     SecurityCallerSingleton::Instance().SendSyncEvent(ev);
80
81     Try {
82         connector->write(response);
83     } Catch (SocketConnection::Exception::SocketConnectionException){
84         LogError("Socket connection write error");
85         ReThrowMsg(ServiceCallbackApi::Exception::ServiceCallbackException,
86                    "Socket connection write error");
87     }
88 }
89
90 } // namespace RPC