c9c45a00acc87300943733f0ac45bedb1341e59a
[platform/framework/web/wrt-security.git] / src / services / ace / logic / attribute_facade.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  *
18  * This file contains classes that implement WRT_INTERFACE.h interfaces,
19  * so that ACE could access  WRT specific and other information during
20  * the decision making.
21  *
22  * @file    attribute_.cpp
23  * @author  Jaroslaw Osmanski (j.osmanski@samsung.com)
24  * @author  Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com)
25  * @author  Ming Jin(ming79.jin@samsung.com)
26  * @version 1.0
27  * @brief   Implementation file for attributes obtaining.
28  */
29
30 #include <dpl/exception.h>
31 #include <sstream>
32 #include <algorithm>
33 #include <list>
34 #include <string>
35 #include <sstream>
36 #include <stdexcept>
37 #include <map>
38 #include <cstdlib>
39 #include <dpl/wrt-dao-rw/widget_dao.h>
40 #include <dpl/wrt-dao-rw/feature_dao.h>
41 #include <dpl/ace/WRT_INTERFACE.h>
42 #include <map>
43 #include <dpl/log/log.h>
44 #include <attribute_facade.h>
45 #include <dpl/ace/Request.h>
46 #include <simple_roaming_agent.h>
47
48 using namespace WrtDB;
49
50 namespace // anonymous
51 {
52 typedef std::list<std::string> AttributeHandlerResponse;
53
54 typedef AttributeHandlerResponse (*AttributeHandler)(
55     const WidgetExecutionPhase &phase,
56     const WidgetHandle &widgetHandle);
57 typedef AttributeHandlerResponse (*ResourceAttributeHandler)(
58     const WidgetExecutionPhase &phase,
59     const WidgetHandle &widgetHandle,
60     const Request &request);
61
62 AttributeHandlerResponse AttributeClassHandler(const WidgetExecutionPhase & /*phase*/,
63         const WidgetHandle & /*widgetHandle*/)
64 {
65     AttributeHandlerResponse response;
66     response.push_back("widget");
67     return response;
68 }
69
70 AttributeHandlerResponse AttributeInstallUriHandler(
71         const WidgetExecutionPhase & /*phase*/,
72         const WidgetHandle &widgetHandle)
73 {
74     AttributeHandlerResponse response;
75     WidgetDAOReadOnly dao(widgetHandle);
76
77     std::string value = dao.getShareHref();
78
79     if (!value.empty()) {
80         response.push_back(value);
81     }
82
83     return response;
84 }
85
86 AttributeHandlerResponse AttributeVersionHandler(const WidgetExecutionPhase & /*phase*/,
87         const WidgetHandle &widgetHandle)
88 {
89     AttributeHandlerResponse response;
90     WidgetDAOReadOnly dao(widgetHandle);
91
92     DPL::Optional<DPL::String> value = dao.getVersion();
93
94     if (!!value) {
95         response.push_back(DPL::ToUTF8String(*value));
96     }
97
98     return response;
99 }
100
101 AttributeHandlerResponse AttributeDistributorKeyCnHandler(
102         const WidgetExecutionPhase & /*phase*/,
103         const WidgetHandle &widgetHandle)
104 {
105     AttributeHandlerResponse response;
106     WidgetDAOReadOnly dao(widgetHandle);
107
108     response = dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
109                                         WidgetCertificateData::ENDENTITY);
110
111     return response;
112 }
113
114 AttributeHandlerResponse AttributeDistributorKeyFingerprintHandler(
115         const WidgetExecutionPhase & /*phase*/,
116         const WidgetHandle &widgetHandle)
117 {
118     AttributeHandlerResponse response;
119     WidgetDAOReadOnly dao(widgetHandle);
120
121     response = dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
122                                       WidgetCertificateData::ENDENTITY);
123
124     return response;
125 }
126
127 AttributeHandlerResponse AttributeDistributorKeyRootCnHandler(
128         const WidgetExecutionPhase & /*phase*/,
129         const WidgetHandle &widgetHandle)
130 {
131     AttributeHandlerResponse response;
132     WidgetDAOReadOnly dao(widgetHandle);
133
134     response = dao.getKeyCommonNameList(WidgetCertificateData::DISTRIBUTOR,
135                                         WidgetCertificateData::ROOT);
136
137     return response;
138 }
139
140 AttributeHandlerResponse AttributeDistributorKeyRootFingerprintHandler(
141         const WidgetExecutionPhase & /*phase*/,
142         const WidgetHandle &widgetHandle)
143 {
144     AttributeHandlerResponse response;
145     WidgetDAOReadOnly dao(widgetHandle);
146
147     response = dao.getKeyFingerprints(WidgetCertificateData::DISTRIBUTOR,
148                                       WidgetCertificateData::ROOT);
149
150     return response;
151 }
152
153 AttributeHandlerResponse AttributeAuthorKeyCnHandler(
154         const WidgetExecutionPhase & /*phase*/,
155         const WidgetHandle &widgetHandle)
156 {
157     AttributeHandlerResponse response;
158     WidgetDAOReadOnly dao(widgetHandle);
159
160     response = dao.getKeyCommonNameList(WidgetCertificateData::AUTHOR,
161                                         WidgetCertificateData::ENDENTITY);
162
163     return response;
164 }
165
166 AttributeHandlerResponse AttributeAuthorKeyFingerprintHandler(
167         const WidgetExecutionPhase & /*phase*/,
168         const WidgetHandle &widgetHandle)
169 {
170     AttributeHandlerResponse response;
171     WidgetDAOReadOnly dao(widgetHandle);
172
173     response = dao.getKeyFingerprints(WidgetCertificateData::AUTHOR,
174                                       WidgetCertificateData::ENDENTITY);
175
176     return response;
177 }
178
179 AttributeHandlerResponse AttributeAuthorKeyRootCnHandler(
180         const WidgetExecutionPhase & /*phase*/,
181         const WidgetHandle &widgetHandle)
182 {
183     AttributeHandlerResponse response;
184     WidgetDAOReadOnly dao(widgetHandle);
185
186     response = dao.getKeyCommonNameList(WidgetCertificateData::AUTHOR,
187                                         WidgetCertificateData::ROOT);
188
189     return response;
190 }
191
192 AttributeHandlerResponse AttributeAuthorKeyRootFingerprintHandler(
193         const WidgetExecutionPhase & /*phase*/,
194         const WidgetHandle &widgetHandle)
195 {
196     AttributeHandlerResponse response;
197     WidgetDAOReadOnly dao(widgetHandle);
198
199     response = dao.getKeyFingerprints(WidgetCertificateData::AUTHOR,
200                                       WidgetCertificateData::ROOT);
201
202     return response;
203 }
204
205 AttributeHandlerResponse AttributeNetworkAccessUriHandler(
206         const WidgetExecutionPhase & /*phase*/,
207         const WidgetHandle & /*widgetHandle*/)
208 {
209     AttributeHandlerResponse response;
210     return response;
211 }
212
213 AttributeHandlerResponse AttributeIdHandler(const WidgetExecutionPhase & /*phase*/,
214         const WidgetHandle &widgetHandle)
215 {
216     AttributeHandlerResponse response;
217     WidgetDAOReadOnly dao(widgetHandle);
218     WidgetGUID wGUID = dao.getGUID();
219
220     if (!!wGUID) {
221         response.push_back(DPL::ToUTF8String(*wGUID));
222     }
223     return response;
224 }
225
226 //AttributeHandlerResponse AttributeNameHandler(const WidgetExecutionPhase & /*phase*/,
227 //        const WidgetHandle &widgetHandle)
228 //{
229 //    AttributeHandlerResponse response;
230 //
231 //    WidgetLocalizedInfo info =
232 //        W3CFileLocalization::getLocalizedInfo(widgetHandle);
233 //
234 //    DPL::Optional<DPL::String> val = info.name;
235 //    std::string value = !!val ? DPL::ToUTF8String(*val) : "";
236 //
237 //    response.push_back(value);
238 //    return response;
239 //}
240 //
241 //AttributeHandlerResponse AttributeWidgetAttrNameHandler(
242 //        const WidgetExecutionPhase & /*phase*/,
243 //        const WidgetHandle &widgetHandle)
244 //{
245 //    AttributeHandlerResponse response;
246 //
247 //    WidgetLocalizedInfo info =
248 //        W3CFileLocalization::getLocalizedInfo(widgetHandle);
249 //
250 //    DPL::Optional<DPL::String> value = info.name;
251 //
252 //    if (!!value) {
253 //        response.push_back(DPL::ToUTF8String(*value));
254 //    }
255 //
256 //    return response;
257 //}
258
259 AttributeHandlerResponse AttributeAuthorNameHandler(
260         const WidgetExecutionPhase & /*phase*/,
261         const WidgetHandle &widgetHandle)
262 {
263     AttributeHandlerResponse response;
264     WidgetDAOReadOnly dao(widgetHandle);
265
266     DPL::Optional<DPL::String> value = dao.getAuthorName();
267
268     if (!!value) {
269         response.push_back(DPL::ToUTF8String(*value));
270     }
271
272     return response;
273 }
274
275 AttributeHandlerResponse AttributeRoamingHandler(
276         const WidgetExecutionPhase &phase,
277         const WidgetHandle & /*widgetHandle*/)
278 {
279     AttributeHandlerResponse response;
280
281     if (WidgetExecutionPhase_WidgetInstall == phase) {
282         // TODO undetermind value
283         response.push_back(std::string(""));
284     } else if (SimpleRoamingAgentSingleton::Instance().IsRoamingOn()) {
285         response.push_back(std::string("true"));
286     } else {
287         response.push_back(std::string("false"));
288     }
289
290     return response;
291 }
292
293 AttributeHandlerResponse AttributeBearerTypeHandler(
294         const WidgetExecutionPhase & /*phase*/,
295         const WidgetHandle & /*widgetHandle*/)
296 {
297     AttributeHandlerResponse response;
298
299     std::string bearerName = "undefined-bearer-name";
300
301     if (bearerName.empty()) {
302         LogWarning("Bearer-type is NOT SET or empty");
303     } else {
304         response.push_back(bearerName);
305     }
306
307     return response;
308 }
309
310 struct AttributeHandlerContext
311 {
312     std::string name;
313     WidgetExecutionPhase allowedPhaseMask;
314     AttributeHandler handler;
315 };
316
317 // Private masks
318 const WidgetExecutionPhase WidgetExecutionPhase_All =
319     static_cast<WidgetExecutionPhase>(
320         WidgetExecutionPhase_WidgetInstall |
321         WidgetExecutionPhase_WidgetInstantiate |
322         WidgetExecutionPhase_WebkitBind |
323         WidgetExecutionPhase_Invoke);
324 const WidgetExecutionPhase WidgetExecutionPhase_NoWidgetInstall =
325     static_cast<WidgetExecutionPhase>(
326         WidgetExecutionPhase_WidgetInstantiate |
327         WidgetExecutionPhase_WebkitBind |
328         WidgetExecutionPhase_Invoke);
329
330 #define ALL_PHASE(name, handler) \
331     { # name, WidgetExecutionPhase_All, handler },
332
333 #define NO_INSTALL(name, handler) \
334     { # name, WidgetExecutionPhase_NoWidgetInstall, handler },
335
336 AttributeHandlerContext HANDLED_ATTRIBUTES_LIST[] = {
337     ALL_PHASE(Class, &AttributeClassHandler)
338     ALL_PHASE(install-uri, &AttributeInstallUriHandler)
339     ALL_PHASE(version, &AttributeVersionHandler)
340     ALL_PHASE(distributor-key-cn, &AttributeDistributorKeyCnHandler)
341     ALL_PHASE(distributor-key-fingerprint,
342               &AttributeDistributorKeyFingerprintHandler)
343     ALL_PHASE(distributor-key-root-cn,
344               &AttributeDistributorKeyRootCnHandler)
345     ALL_PHASE(distributor-key-root-fingerprint,
346               &AttributeDistributorKeyRootFingerprintHandler)
347     ALL_PHASE(author-key-cn, &AttributeAuthorKeyCnHandler)
348     ALL_PHASE(author-key-fingerprint, &AttributeAuthorKeyFingerprintHandler)
349     ALL_PHASE(author-key-root-cn, &AttributeAuthorKeyRootCnHandler)
350     ALL_PHASE(author-key-root-fingerprint,
351               &AttributeAuthorKeyRootFingerprintHandler)
352     ALL_PHASE(network-access-uri, &AttributeNetworkAccessUriHandler)
353     ALL_PHASE(id, &AttributeIdHandler)
354 //    ALL_PHASE(name, &AttributeNameHandler)
355 //    ALL_PHASE(widget-attr:name, &AttributeWidgetAttrNameHandler)
356     ALL_PHASE(author-name, &AttributeAuthorNameHandler)
357     /* Enviroment  attributes*/
358     NO_INSTALL(roaming, &AttributeRoamingHandler)
359     NO_INSTALL(bearer-type, &AttributeBearerTypeHandler)
360 };
361
362 #undef ALL_PHASE
363 #undef NO_INSTALL
364
365 const size_t HANDLED_ATTRIBUTES_LIST_COUNT =
366     sizeof(HANDLED_ATTRIBUTES_LIST) / sizeof(HANDLED_ATTRIBUTES_LIST[0]);
367
368 template<class T>
369 class lambdaCollectionPusher
370 {
371   public:
372     std::list<T>& m_collection;
373     lambdaCollectionPusher(std::list<T>& collection) : m_collection(collection)
374     {
375     }
376     void operator()(const T& element) const
377     {
378         m_collection.push_back(element);
379     }
380 };
381
382 class lambdaWidgetPrefixEquality :
383     public std::binary_function<WidgetFeature, std::string, bool>
384 {
385   public:
386     bool operator()(const WidgetFeature& wFeature,
387             const std::string& prefix) const
388     {
389         return wFeature.name.find(DPL::FromUTF8String(prefix)) !=
390                DPL::String::npos;
391     }
392 };
393
394 class lambdaWidgetNameEquality :
395     public std::binary_function<WidgetFeature, std::string, bool>
396 {
397   public:
398     bool operator()(const WidgetFeature& wFeature,
399             const std::string& prefix) const
400     {
401         return wFeature.name == DPL::FromUTF8String(prefix);
402     }
403 };
404
405 FeatureHandleList getFeatureHandleList(const WidgetHandle& widgetHandle,
406         const std::string& resourceId)
407 {
408     FeatureHandleList featureHandleList;
409     WidgetDAOReadOnly widgetDAO(widgetHandle);
410     WidgetFeatureSet wFeatureSet = widgetDAO.getFeaturesList();
411     WidgetFeatureSet::iterator foundFeatures =
412         std::find_if(wFeatureSet.begin(),
413                      wFeatureSet.end(),
414                      std::bind2nd(lambdaWidgetPrefixEquality(), resourceId));
415
416     if (foundFeatures != wFeatureSet.end()) {
417         FeatureDAOReadOnly featureDAO(resourceId);
418         featureHandleList.push_back(featureDAO.GetFeatureHandle());
419     }
420     return featureHandleList;
421 }
422
423 AttributeHandlerResponse AttributeDeviceCapHandler(const WidgetExecutionPhase & /*phase*/,
424         const WidgetHandle & /*widgetHandle*/,
425         const Request &request)
426 {
427     AttributeHandlerResponse response;
428
429     Request::DeviceCapabilitySet capSet = request.getDeviceCapabilitySet();
430     LogDebug("device caps set contains");
431     FOREACH(dc, capSet)
432     {
433         LogDebug("-> " << *dc);
434     }
435
436     std::for_each(
437         capSet.begin(),
438         capSet.end(),
439         lambdaCollectionPusher<std::string>(response));
440
441     return response;
442
443     // We should return list of device-caps required by resourceId.
444     //    AttributeHandlerResponse response;
445     //
446     //    FeatureHandleList fHandleList =
447     //        getFeatureHandleList(widgetHandle, resourceId);
448     //    if( !fHandleList.empty() )
449     //    {
450     //        FeatureDAO feature( resourceId );
451     //        std::set<std::string> deviceCapLast =
452     //                feature.GetDeviceCapabilities();
453     //        std::for_each(
454     //                deviceCapList.begin(),
455     //                deviceCapList.end(),
456     //                lambdaCollectionPusher<DeviceCapList::value_type>(
457     //                        response) );
458     //    }
459     //    return response;
460 }
461
462 class lambdaFeatureEquality :
463     public std::binary_function<FeatureHandle, int, bool>
464 {
465   public:
466     bool operator()(const FeatureHandle& wFeature,
467             const int& resurceId) const
468     {
469         return wFeature == resurceId;
470     }
471 };
472
473 class lambdaPushFeatureName :
474     public std::binary_function<WidgetFeature, AttributeHandlerResponse, void>
475 {
476     void operator()(const WidgetFeature& wFeature,
477             AttributeHandlerResponse& response) const
478     {
479         response.push_back(DPL::ToUTF8String(wFeature.name));
480     }
481 };
482
483 AttributeHandlerResponse AttributeApiFeatureHandler(
484         const WidgetExecutionPhase & /* phase */,
485         const WidgetHandle & /* widgetHandle */,
486         const Request & /* request */)
487 {
488     LogDebug("WAC 2.0 does not support api-feature and resource-id in policy.");
489     AttributeHandlerResponse response;
490     return response;
491     // Wrt shouldn't ask about resource which is not listed in
492     // (widget) config.xml file
493     //
494     //    AttributeHandlerResponse response;
495     //    WidgetDAOReadOnly widgetDAO(widgetHandle);
496     //        WidgetFeatureSet wFeatureSet = widgetDAO.GetFeaturesList();
497     //       std::string featureName = resourceId;
498     //        WidgetFeatureSet::iterator foundFeatures =
499     //            std::find_if(wFeatureSet.begin(),
500     //                         wFeatureSet.end(),
501     //                         std::bind2nd(lambdaWidgetPrefixEquality(),
502     //                                      featureName));
503     //
504     //        while( foundFeatures != wFeatureSet.end() )
505     //        {
506     //            response.push_back( foundFeatures->name );
507     //            LogDebug("Found feature: " << foundFeatures->name );
508     //            foundFeatures++;
509     //        }
510     //
511     //        return response;
512 }
513
514 typedef std::string (FeatureDAOReadOnly::*FNMETHOD)() const;
515
516 AttributeHandlerResponse GetFeatureAttributeGroup(const WidgetExecutionPhase & /*phase*/,
517         const WidgetHandle &widgetHandle,
518         const std::string& resourceId,
519         FNMETHOD function)
520 {
521     AttributeHandlerResponse response;
522     FeatureHandleList fHandleList =
523         getFeatureHandleList(widgetHandle, resourceId);
524     if (!fHandleList.empty()) {
525         FeatureDAOReadOnly featureDAO(fHandleList.front());
526         std::string attribute = (featureDAO.*function)();
527         response.push_back(attribute);
528     }
529     return response;
530 }
531
532 AttributeHandlerResponse AttributeFeatureInstallUriHandler(
533         const WidgetExecutionPhase & /* phase */,
534         const WidgetHandle & /* widgetHandle */,
535         const Request & /* request */)
536 {
537     LogDebug("WAC 2.0 does not support feature-install-uri is policy!");
538     AttributeHandlerResponse response;
539     return response;
540 }
541
542 AttributeHandlerResponse AttributeFeatureFeatureKeyCnHandler(
543         const WidgetExecutionPhase & /* phase */,
544         const WidgetHandle & /* widgetHandle */,
545         const Request & /* request */)
546 {
547     LogDebug("WAC 2.0 does not support feature-key-cn is policy!");
548     AttributeHandlerResponse response;
549     return response;
550 }
551
552 AttributeHandlerResponse AttributeFeatureKeyRootCnHandler(
553         const WidgetExecutionPhase & /* phase */,
554         const WidgetHandle & /* widgetHandle */,
555         const Request & /* request */)
556 {
557     LogDebug("WAC 2.0 does not support feature-key-root-cn is policy!");
558     AttributeHandlerResponse response;
559     return response;
560 }
561
562 AttributeHandlerResponse AttributeFeatureKeyRootFingerprintHandler(
563         const WidgetExecutionPhase & /* phase */,
564         const WidgetHandle & /* widgetHandle */,
565         const Request & /* request */)
566 {
567     LogDebug("WAC 2.0 does not support"
568         " feature-key-root-fingerprint is policy!");
569     AttributeHandlerResponse response;
570     return response;
571 }
572
573 struct ResourceAttributeHandlerContext
574 {
575     std::string name;
576     WidgetExecutionPhase allowedPhaseMask;
577     ResourceAttributeHandler handler;
578 };
579
580 #define ALL_PHASE(name, handler) \
581     { # name, WidgetExecutionPhase_All, handler },
582
583 ResourceAttributeHandlerContext HANDLED_RESOURCE_ATTRIBUTES_LIST[] = {
584     ALL_PHASE(device-cap, &AttributeDeviceCapHandler)
585     ALL_PHASE(api-feature, &AttributeApiFeatureHandler)
586     // For compatiblity with older policies we tread resource-id
587     // identically as api-feature
588     ALL_PHASE(resource-id, &AttributeApiFeatureHandler)
589
590     ALL_PHASE(feature-install-uri, &AttributeFeatureInstallUriHandler)
591     ALL_PHASE(feature-key-cn, &AttributeFeatureFeatureKeyCnHandler)
592     ALL_PHASE(feature-key-root-cn, &AttributeFeatureKeyRootCnHandler)
593     ALL_PHASE(feature-key-root-fingerprint,
594               &AttributeFeatureKeyRootFingerprintHandler)
595 };
596
597 #undef ALL_PHASE
598
599 const size_t HANDLED_RESOURCE_ATTRIBUTES_LIST_COUNT =
600     sizeof(HANDLED_RESOURCE_ATTRIBUTES_LIST) /
601     sizeof(HANDLED_RESOURCE_ATTRIBUTES_LIST[0]);
602 } // namespace anonymous
603
604 /*
605  * class WebRuntimeImpl
606  */
607 int WebRuntimeImpl::getAttributesValuesLoop(const Request &request,
608         std::list<ATTRIBUTE>* attributes,
609         WidgetExecutionPhase executionPhase)
610 {
611     UNHANDLED_EXCEPTION_HANDLER_BEGIN
612     {
613         WidgetHandle widgetHandle = request.getWidgetHandle();
614
615         FOREACH(itr, *attributes)
616         {
617             // Get attribute name
618             std::string attribute = *itr->first;
619
620             // Search for attribute handler
621             bool attributeFound = false;
622
623             for (size_t i = 0; i < HANDLED_ATTRIBUTES_LIST_COUNT; ++i) {
624                 if (HANDLED_ATTRIBUTES_LIST[i].name == attribute) {
625                     // Check if execution phase is valid
626                     if ((executionPhase &
627                          HANDLED_ATTRIBUTES_LIST[i].allowedPhaseMask) == 0) {
628                         // Attribute found, but execution state
629                         // forbids to execute handler
630                         LogWarning(
631                             "Request for attribute: '" <<
632                             attribute << "' which is supported " <<
633                             "but forbidden at widget execution phase: "
634                             <<
635                             executionPhase);
636                     } else {
637                         // Execution phase allows handler
638                         AttributeHandlerResponse attributeResponse =
639                             (*HANDLED_ATTRIBUTES_LIST[i].handler)(
640                                 executionPhase,
641                                 widgetHandle);
642                         std::copy(attributeResponse.begin(),
643                                   attributeResponse.end(),
644                                   std::back_inserter(*itr->second));
645                     }
646
647                     attributeFound = true;
648                     break;
649                 }
650             }
651
652             if (!attributeFound) {
653                 LogWarning("Request for attribute: '" <<
654                            attribute << "' which is not supported");
655             }
656         }
657
658         return 0;
659     }
660     UNHANDLED_EXCEPTION_HANDLER_END
661 }
662
663 int WebRuntimeImpl::getAttributesValues(const Request &request,
664         std::list<ATTRIBUTE>* attributes)
665 {
666     UNHANDLED_EXCEPTION_HANDLER_BEGIN
667     {
668         // Get current execution state
669         WidgetExecutionPhase executionPhase =
670             request.getExecutionPhase();
671
672         return getAttributesValuesLoop(request, attributes, executionPhase);
673     }
674     UNHANDLED_EXCEPTION_HANDLER_END
675 }
676
677 std::string WebRuntimeImpl::getSessionId(const Request & /* request */)
678 {
679     std::string result;
680     LogError("Not implemented!");
681     return result;
682 }
683
684 WebRuntimeImpl::WebRuntimeImpl()
685 {
686 }
687
688 /*
689  * class ResourceInformationImpl
690  */
691
692 int ResourceInformationImpl::getAttributesValuesLoop(const Request &request,
693         std::list<ATTRIBUTE>* attributes,
694         WidgetExecutionPhase executionPhase)
695 {
696     // Currently, we assume widgets have internal representation of integer IDs
697     WidgetHandle widgetHandle = request.getWidgetHandle();
698     //TODO add resource id string analyzys
699     FOREACH(itr, *attributes)
700     {
701         // Get attribute name
702         std::string attribute = *itr->first;
703         LogDebug("getting attribute value for: " << attribute);
704         FOREACH(aaa, *itr->second)
705         {
706             LogDebug("its value is: " << *aaa);
707         }
708
709         // Search for attribute handler
710         bool attributeFound = false;
711
712         for (size_t i = 0; i < HANDLED_RESOURCE_ATTRIBUTES_LIST_COUNT; ++i) {
713             if (HANDLED_RESOURCE_ATTRIBUTES_LIST[i].name == attribute) {
714                 // Check if execution phase is valid
715                 if ((executionPhase &
716                      HANDLED_RESOURCE_ATTRIBUTES_LIST[i].allowedPhaseMask) ==
717                     0) {
718                     // Attribute found, but execution state
719                     // forbids to execute handler
720                     LogDebug(
721                         "Request for attribute: '" <<
722                         attribute <<
723                         "' which is supported but forbidden " <<
724                         "at widget execution phase: " << executionPhase);
725                     itr->second = NULL;
726                 } else {
727                     // Execution phase allows handler
728                     AttributeHandlerResponse attributeResponse =
729                         (*HANDLED_RESOURCE_ATTRIBUTES_LIST[i].handler)(
730                             executionPhase,
731                             widgetHandle,
732                             request);
733                     std::copy(attributeResponse.begin(),
734                               attributeResponse.end(),
735                               std::back_inserter(*itr->second));
736
737                     std::ostringstream attributeResponseFull;
738
739                     for (AttributeHandlerResponse::const_iterator
740                          it = attributeResponse.begin();
741                          it != attributeResponse.end(); ++it) {
742                         attributeResponseFull <<
743                         (it == attributeResponse.begin() ? "" : ", ") <<
744                         *it;
745                     }
746
747                     LogDebug("Attribute(" << attribute << ") = " <<
748                              attributeResponseFull.str());
749                 }
750
751                 attributeFound = true;
752                 break;
753             }
754         }
755
756         if (!attributeFound) {
757             LogWarning("Request for attribute: '" << attribute <<
758                        "' which is not supported");
759         }
760     }
761     return 0;
762 }
763
764 int ResourceInformationImpl::getAttributesValues(const Request &request,
765         std::list<ATTRIBUTE>* attributes)
766 {
767     UNHANDLED_EXCEPTION_HANDLER_BEGIN
768     {
769         // Get current execution state
770         WidgetExecutionPhase executionPhase =
771             request.getExecutionPhase();
772         return getAttributesValuesLoop(request, attributes, executionPhase);
773     }
774     UNHANDLED_EXCEPTION_HANDLER_END
775 }
776
777 ResourceInformationImpl::ResourceInformationImpl()
778 {
779 }
780
781 /*
782  * class OperationSystemImpl
783  */
784
785 int OperationSystemImpl::getAttributesValues(const Request &request,
786         std::list<ATTRIBUTE>* attributes)
787 {
788     UNHANDLED_EXCEPTION_HANDLER_BEGIN
789     {
790         //FIXME:
791         //GetExecution name without widget name
792         WidgetExecutionPhase executionPhase =
793             request.getExecutionPhase();
794
795         FOREACH(itr, *attributes)
796         {
797             // Get attribute name
798             std::string attribute = *itr->first;
799
800             // Search for attribute handler
801             bool attributeFound = false;
802
803             for (size_t i = 0; i < HANDLED_ATTRIBUTES_LIST_COUNT; ++i) {
804                 if (HANDLED_ATTRIBUTES_LIST[i].name == attribute) {
805                     // Check if execution phase is valid
806                     if ((executionPhase &
807                          HANDLED_ATTRIBUTES_LIST[i].allowedPhaseMask) == 0) {
808                         // Attribute found, but execution state forbids
809                         // to execute handler
810                         LogDebug("Request for attribute: '" << attribute <<
811                                  "' which is supported but forbidden at " <<
812                                  "widget execution phase: " << executionPhase);
813                         itr->second = NULL;
814                     } else {
815                         // Execution phase allows handler
816                         AttributeHandlerResponse attributeResponse =
817                             (*HANDLED_ATTRIBUTES_LIST[i].handler)(
818                                 executionPhase,
819                                 0);
820                         std::copy(attributeResponse.begin(),
821                                   attributeResponse.end(),
822                                   std::back_inserter(*itr->second));
823
824                         std::ostringstream attributeResponseFull;
825
826                         typedef AttributeHandlerResponse::const_iterator Iter;
827                         FOREACH(it, attributeResponse)
828                         {
829                             attributeResponseFull <<
830                             (it == attributeResponse.begin()
831                              ? "" : ", ") << *it;
832                         }
833
834                         LogDebug("Attribute(" << attribute <<
835                                  ") = " << attributeResponseFull.str());
836                     }
837
838                     attributeFound = true;
839                     break;
840                 }
841             }
842
843             if (!attributeFound) {
844                 LogWarning("Request for attribute: '" << attribute <<
845                            "' which is not supported");
846             }
847         }
848
849         return 0;
850     }
851     UNHANDLED_EXCEPTION_HANDLER_END
852 }
853
854 OperationSystemImpl::OperationSystemImpl()
855 {
856 }
857
858 /*
859  * end of class OperationSystemImpl
860  */
861
862 int FunctionParamImpl::getAttributesValues(const Request & /*request*/,
863         std::list<ATTRIBUTE> *attributes)
864 {
865     FOREACH(iter, *attributes)
866     {
867         std::string attributeName = *(iter->first);
868
869         ParamMap::const_iterator i;
870         std::pair<ParamMap::const_iterator, ParamMap::const_iterator> jj =
871             paramMap.equal_range(attributeName);
872
873         for (i = jj.first; i != jj.second; ++i) {
874             iter->second->push_back(i->second);
875             LogDebug("Attribute: " << attributeName << " Value: " <<
876                      i->second);
877         }
878     }
879     return 0;
880 }
881