tizen beta release
[framework/web/wrt-installer.git] / src / security / 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
431     std::for_each(
432         capSet.begin(),
433         capSet.end(),
434         lambdaCollectionPusher<std::string>(response));
435
436     return response;
437
438     // We should return list of device-caps required by resourceId.
439     //    AttributeHandlerResponse response;
440     //
441     //    FeatureHandleList fHandleList =
442     //        getFeatureHandleList(widgetHandle, resourceId);
443     //    if( !fHandleList.empty() )
444     //    {
445     //        FeatureDAO feature( resourceId );
446     //        std::set<std::string> deviceCapLast =
447     //                feature.GetDeviceCapabilities();
448     //        std::for_each(
449     //                deviceCapList.begin(),
450     //                deviceCapList.end(),
451     //                lambdaCollectionPusher<DeviceCapList::value_type>(
452     //                        response) );
453     //    }
454     //    return response;
455 }
456
457 class lambdaFeatureEquality :
458     public std::binary_function<FeatureHandle, int, bool>
459 {
460   public:
461     bool operator()(const FeatureHandle& wFeature,
462             const int& resurceId) const
463     {
464         return wFeature == resurceId;
465     }
466 };
467
468 class lambdaPushFeatureName :
469     public std::binary_function<WidgetFeature, AttributeHandlerResponse, void>
470 {
471     void operator()(const WidgetFeature& wFeature,
472             AttributeHandlerResponse& response) const
473     {
474         response.push_back(DPL::ToUTF8String(wFeature.name));
475     }
476 };
477
478 AttributeHandlerResponse AttributeApiFeatureHandler(
479         const WidgetExecutionPhase & /* phase */,
480         const WidgetHandle & /* widgetHandle */,
481         const Request & /* request */)
482 {
483     LogDebug("WAC 2.0 does not support api-feature and resource-id in policy.");
484     AttributeHandlerResponse response;
485     return response;
486     // Wrt shouldn't ask about resource which is not listed in
487     // (widget) config.xml file
488     //
489     //    AttributeHandlerResponse response;
490     //    WidgetDAOReadOnly widgetDAO(widgetHandle);
491     //        WidgetFeatureSet wFeatureSet = widgetDAO.GetFeaturesList();
492     //       std::string featureName = resourceId;
493     //        WidgetFeatureSet::iterator foundFeatures =
494     //            std::find_if(wFeatureSet.begin(),
495     //                         wFeatureSet.end(),
496     //                         std::bind2nd(lambdaWidgetPrefixEquality(),
497     //                                      featureName));
498     //
499     //        while( foundFeatures != wFeatureSet.end() )
500     //        {
501     //            response.push_back( foundFeatures->name );
502     //            LogDebug("Found feature: " << foundFeatures->name );
503     //            foundFeatures++;
504     //        }
505     //
506     //        return response;
507 }
508
509 typedef std::string (FeatureDAOReadOnly::*FNMETHOD)() const;
510
511 AttributeHandlerResponse GetFeatureAttributeGroup(const WidgetExecutionPhase & /*phase*/,
512         const WidgetHandle &widgetHandle,
513         const std::string& resourceId,
514         FNMETHOD function)
515 {
516     AttributeHandlerResponse response;
517     FeatureHandleList fHandleList =
518         getFeatureHandleList(widgetHandle, resourceId);
519     if (!fHandleList.empty()) {
520         FeatureDAOReadOnly featureDAO(fHandleList.front());
521         std::string attribute = (featureDAO.*function)();
522         response.push_back(attribute);
523     }
524     return response;
525 }
526
527 AttributeHandlerResponse AttributeFeatureInstallUriHandler(
528         const WidgetExecutionPhase & /* phase */,
529         const WidgetHandle & /* widgetHandle */,
530         const Request & /* request */)
531 {
532     LogDebug("WAC 2.0 does not support feature-install-uri is policy!");
533     AttributeHandlerResponse response;
534     return response;
535 }
536
537 AttributeHandlerResponse AttributeFeatureFeatureKeyCnHandler(
538         const WidgetExecutionPhase & /* phase */,
539         const WidgetHandle & /* widgetHandle */,
540         const Request & /* request */)
541 {
542     LogDebug("WAC 2.0 does not support feature-key-cn is policy!");
543     AttributeHandlerResponse response;
544     return response;
545 }
546
547 AttributeHandlerResponse AttributeFeatureKeyRootCnHandler(
548         const WidgetExecutionPhase & /* phase */,
549         const WidgetHandle & /* widgetHandle */,
550         const Request & /* request */)
551 {
552     LogDebug("WAC 2.0 does not support feature-key-root-cn is policy!");
553     AttributeHandlerResponse response;
554     return response;
555 }
556
557 AttributeHandlerResponse AttributeFeatureKeyRootFingerprintHandler(
558         const WidgetExecutionPhase & /* phase */,
559         const WidgetHandle & /* widgetHandle */,
560         const Request & /* request */)
561 {
562     LogDebug("WAC 2.0 does not support"
563         " feature-key-root-fingerprint is policy!");
564     AttributeHandlerResponse response;
565     return response;
566 }
567
568 struct ResourceAttributeHandlerContext
569 {
570     std::string name;
571     WidgetExecutionPhase allowedPhaseMask;
572     ResourceAttributeHandler handler;
573 };
574
575 #define ALL_PHASE(name, handler) \
576     { # name, WidgetExecutionPhase_All, handler },
577
578 ResourceAttributeHandlerContext HANDLED_RESOURCE_ATTRIBUTES_LIST[] = {
579     ALL_PHASE(device-cap, &AttributeDeviceCapHandler)
580     ALL_PHASE(api-feature, &AttributeApiFeatureHandler)
581     // [P.Fatyga] For compatiblity with older policies we tread resource-id
582     // identically as api-feature
583     ALL_PHASE(resource-id, &AttributeApiFeatureHandler)
584
585     ALL_PHASE(feature-install-uri, &AttributeFeatureInstallUriHandler)
586     ALL_PHASE(feature-key-cn, &AttributeFeatureFeatureKeyCnHandler)
587     ALL_PHASE(feature-key-root-cn, &AttributeFeatureKeyRootCnHandler)
588     ALL_PHASE(feature-key-root-fingerprint,
589               &AttributeFeatureKeyRootFingerprintHandler)
590 };
591
592 #undef ALL_PHASE
593
594 const size_t HANDLED_RESOURCE_ATTRIBUTES_LIST_COUNT =
595     sizeof(HANDLED_RESOURCE_ATTRIBUTES_LIST) /
596     sizeof(HANDLED_RESOURCE_ATTRIBUTES_LIST[0]);
597 } // namespace anonymous
598
599 /*
600  * class WebRuntimeImpl
601  */
602 int WebRuntimeImpl::getAttributesValuesLoop(const Request &request,
603         std::list<ATTRIBUTE>* attributes,
604         WidgetExecutionPhase executionPhase)
605 {
606     UNHANDLED_EXCEPTION_HANDLER_BEGIN
607     {
608         WidgetHandle widgetHandle = request.getWidgetHandle();
609
610         FOREACH(itr, *attributes)
611         {
612             // Get attribute name
613             std::string attribute = *itr->first;
614
615             // Search for attribute handler
616             bool attributeFound = false;
617
618             for (size_t i = 0; i < HANDLED_ATTRIBUTES_LIST_COUNT; ++i) {
619                 if (HANDLED_ATTRIBUTES_LIST[i].name == attribute) {
620                     // Check if execution phase is valid
621                     if ((executionPhase &
622                          HANDLED_ATTRIBUTES_LIST[i].allowedPhaseMask) == 0) {
623                         // Attribute found, but execution state
624                         // forbids to execute handler
625                         LogWarning(
626                             "Request for attribute: '" <<
627                             attribute << "' which is supported " <<
628                             "but forbidden at widget execution phase: "
629                             <<
630                             executionPhase);
631                     } else {
632                         // Execution phase allows handler
633                         AttributeHandlerResponse attributeResponse =
634                             (*HANDLED_ATTRIBUTES_LIST[i].handler)(
635                                 executionPhase,
636                                 widgetHandle);
637                         std::copy(attributeResponse.begin(),
638                                   attributeResponse.end(),
639                                   std::back_inserter(*itr->second));
640                     }
641
642                     attributeFound = true;
643                     break;
644                 }
645             }
646
647             if (!attributeFound) {
648                 LogWarning("Request for attribute: '" <<
649                            attribute << "' which is not supported");
650             }
651         }
652
653         return 0;
654     }
655     UNHANDLED_EXCEPTION_HANDLER_END
656 }
657
658 int WebRuntimeImpl::getAttributesValues(const Request &request,
659         std::list<ATTRIBUTE>* attributes)
660 {
661     UNHANDLED_EXCEPTION_HANDLER_BEGIN
662     {
663         // Get current execution state
664         WidgetExecutionPhase executionPhase =
665             request.getExecutionPhase();
666
667         return getAttributesValuesLoop(request, attributes, executionPhase);
668     }
669     UNHANDLED_EXCEPTION_HANDLER_END
670 }
671
672 std::string WebRuntimeImpl::getSessionId(const Request & /* request */)
673 {
674     std::string result;
675     LogError("Not implemented!");
676     return result;
677 }
678
679 WebRuntimeImpl::WebRuntimeImpl()
680 {
681 }
682
683 /*
684  * class ResourceInformationImpl
685  */
686
687 int ResourceInformationImpl::getAttributesValuesLoop(const Request &request,
688         std::list<ATTRIBUTE>* attributes,
689         WidgetExecutionPhase executionPhase)
690 {
691     // Currently, we assume widgets have internal representation of integer IDs
692     WidgetHandle widgetHandle = request.getWidgetHandle();
693     //TODO add resource id string analyzys
694     FOREACH(itr, *attributes)
695     {
696         // Get attribute name
697         std::string attribute = *itr->first;
698
699         // Search for attribute handler
700         bool attributeFound = false;
701
702         for (size_t i = 0; i < HANDLED_RESOURCE_ATTRIBUTES_LIST_COUNT; ++i) {
703             if (HANDLED_RESOURCE_ATTRIBUTES_LIST[i].name == attribute) {
704                 // Check if execution phase is valid
705                 if ((executionPhase &
706                      HANDLED_RESOURCE_ATTRIBUTES_LIST[i].allowedPhaseMask) ==
707                     0) {
708                     // Attribute found, but execution state
709                     // forbids to execute handler
710                     LogDebug(
711                         "Request for attribute: '" <<
712                         attribute <<
713                         "' which is supported but forbidden " <<
714                         "at widget execution phase: " << executionPhase);
715                     itr->second = NULL;
716                 } else {
717                     // Execution phase allows handler
718                     AttributeHandlerResponse attributeResponse =
719                         (*HANDLED_RESOURCE_ATTRIBUTES_LIST[i].handler)(
720                             executionPhase,
721                             widgetHandle,
722                             request);
723                     std::copy(attributeResponse.begin(),
724                               attributeResponse.end(),
725                               std::back_inserter(*itr->second));
726
727                     std::ostringstream attributeResponseFull;
728
729                     for (AttributeHandlerResponse::const_iterator
730                          it = attributeResponse.begin();
731                          it != attributeResponse.end(); ++it) {
732                         attributeResponseFull <<
733                         (it == attributeResponse.begin() ? "" : ", ") <<
734                         *it;
735                     }
736
737                     LogDebug("Attribute(" << attribute << ") = " <<
738                              attributeResponseFull.str());
739                 }
740
741                 attributeFound = true;
742                 break;
743             }
744         }
745
746         if (!attributeFound) {
747             LogWarning("Request for attribute: '" << attribute <<
748                        "' which is not supported");
749         }
750     }
751     return 0;
752 }
753
754 int ResourceInformationImpl::getAttributesValues(const Request &request,
755         std::list<ATTRIBUTE>* attributes)
756 {
757     UNHANDLED_EXCEPTION_HANDLER_BEGIN
758     {
759         // Get current execution state
760         WidgetExecutionPhase executionPhase =
761             request.getExecutionPhase();
762         return getAttributesValuesLoop(request, attributes, executionPhase);
763     }
764     UNHANDLED_EXCEPTION_HANDLER_END
765 }
766
767 ResourceInformationImpl::ResourceInformationImpl()
768 {
769 }
770
771 /*
772  * class OperationSystemImpl
773  */
774
775 int OperationSystemImpl::getAttributesValues(const Request &request,
776         std::list<ATTRIBUTE>* attributes)
777 {
778     UNHANDLED_EXCEPTION_HANDLER_BEGIN
779     {
780         //FIXME:
781         //GetExecution name without widget name
782         WidgetExecutionPhase executionPhase =
783             request.getExecutionPhase();
784
785         FOREACH(itr, *attributes)
786         {
787             // Get attribute name
788             std::string attribute = *itr->first;
789
790             // Search for attribute handler
791             bool attributeFound = false;
792
793             for (size_t i = 0; i < HANDLED_ATTRIBUTES_LIST_COUNT; ++i) {
794                 if (HANDLED_ATTRIBUTES_LIST[i].name == attribute) {
795                     // Check if execution phase is valid
796                     if ((executionPhase &
797                          HANDLED_ATTRIBUTES_LIST[i].allowedPhaseMask) == 0) {
798                         // Attribute found, but execution state forbids
799                         // to execute handler
800                         LogDebug("Request for attribute: '" << attribute <<
801                                  "' which is supported but forbidden at " <<
802                                  "widget execution phase: " << executionPhase);
803                         itr->second = NULL;
804                     } else {
805                         // Execution phase allows handler
806                         AttributeHandlerResponse attributeResponse =
807                             (*HANDLED_ATTRIBUTES_LIST[i].handler)(
808                                 executionPhase,
809                                 0);
810                         std::copy(attributeResponse.begin(),
811                                   attributeResponse.end(),
812                                   std::back_inserter(*itr->second));
813
814                         std::ostringstream attributeResponseFull;
815
816                         typedef AttributeHandlerResponse::const_iterator Iter;
817                         FOREACH(it, attributeResponse)
818                         {
819                             attributeResponseFull <<
820                             (it == attributeResponse.begin()
821                              ? "" : ", ") << *it;
822                         }
823
824                         LogDebug("Attribute(" << attribute <<
825                                  ") = " << attributeResponseFull.str());
826                     }
827
828                     attributeFound = true;
829                     break;
830                 }
831             }
832
833             if (!attributeFound) {
834                 LogWarning("Request for attribute: '" << attribute <<
835                            "' which is not supported");
836             }
837         }
838
839         return 0;
840     }
841     UNHANDLED_EXCEPTION_HANDLER_END
842 }
843
844 OperationSystemImpl::OperationSystemImpl()
845 {
846 }
847
848 /*
849  * end of class OperationSystemImpl
850  */
851
852 int FunctionParamImpl::getAttributesValues(const Request & /*request*/,
853         std::list<ATTRIBUTE> *attributes)
854 {
855     FOREACH(iter, *attributes)
856     {
857         std::string attributeName = *(iter->first);
858
859         ParamMap::const_iterator i;
860         std::pair<ParamMap::const_iterator, ParamMap::const_iterator> jj =
861             paramMap.equal_range(attributeName);
862
863         for (i = jj.first; i != jj.second; ++i) {
864             iter->second->push_back(i->second);
865             LogDebug("Attribute: " << attributeName << " Value: " <<
866                      i->second);
867         }
868     }
869     return 0;
870 }
871