1 //******************************************************************
3 // Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 #include "OCUtilities.h"
25 #include <boost/algorithm/string.hpp>
31 OC::Utilities::QueryParamsKeyVal OC::Utilities::getQueryParams(const std::string& uri)
33 OC::Utilities::QueryParamsKeyVal qp;
39 std::vector<std::string> queryparams;
40 boost::split(queryparams, uri, boost::is_any_of(OC_QUERY_SEPARATOR), boost::token_compress_on);
42 for(std::string& it: queryparams)
44 auto index = it.find('=');
46 if(index == std::string::npos)
52 qp[it.substr(0, index)] = it.substr(index + 1);
60 OCStackResult result_guard(const OCStackResult r)
62 std::ostringstream os;
67 os << "result_guard(): unhandled exception: " << OCException::reason(r);
68 throw OCException(os.str(), r);
70 /* Exceptional conditions: */
71 case OC_STACK_NO_MEMORY:
72 case OC_STACK_COMM_ERROR:
73 case OC_STACK_NOTIMPL:
74 case OC_STACK_INVALID_URI:
75 case OC_STACK_INVALID_QUERY:
76 case OC_STACK_INVALID_IP:
77 case OC_STACK_INVALID_PORT:
78 case OC_STACK_INVALID_CALLBACK:
79 case OC_STACK_INVALID_METHOD:
80 case OC_STACK_INVALID_PARAM:
81 case OC_STACK_INVALID_OBSERVE_PARAM:
82 os << "result_guard(): " << r << ": " << OCException::reason(r);
83 throw OCException(os.str(), r);
85 /* Non-exceptional failures or success: */
87 case OC_STACK_NO_RESOURCE:
88 case OC_STACK_RESOURCE_ERROR:
89 case OC_STACK_SLOW_RESOURCE:
90 case OC_STACK_NO_OBSERVERS:
91 case OC_STACK_OBSERVER_NOT_FOUND:
93 case OC_STACK_PRESENCE_STOPPED:
94 case OC_STACK_PRESENCE_TIMEOUT:
95 case OC_STACK_PRESENCE_DO_NOT_HANDLE: