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