1 //******************************************************************
3 // Copyright 2015 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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 #define _POSIX_C_SOURCE 200112L
23 #include "srmutility.h"
24 #include "srmresourcestrings.h"
27 #define TAG PCF("SRM-UTILITY")
30 * This method initializes the OicParseQueryIter_t struct
32 *@param query - REST query, to be parsed
33 *@param parseIter - OicParseQueryIter_t struct, to be initialized
36 void ParseQueryIterInit(unsigned char * query, OicParseQueryIter_t * parseIter)
38 OC_LOG (INFO, TAG, PCF("Initializing coap iterator"));
39 if((NULL == query) || (NULL == parseIter))
42 parseIter->attrPos = NULL;
43 parseIter->attrLen = 0;
44 parseIter->valPos = NULL;
45 parseIter->valLen = 0;
46 coap_parse_iterator_init(query, strlen((char *)query),
47 (unsigned char *)OIC_SEC_REST_QUERY_SEPARATOR, (unsigned char *) "", 0, &parseIter->pi);
52 * This method fills the OicParseQueryIter_t struct with next REST query's
53 * attribute's and value's information
55 *@param parseIter - OicParseQueryIter_t struct, has next query's attribute's & value's info
58 * OicParseQueryIter_t * - has parsed query info
59 * NULL - has no query to parse
61 OicParseQueryIter_t * GetNextQuery(OicParseQueryIter_t * parseIter)
63 OC_LOG (INFO, TAG, PCF("Getting Next Query"));
67 unsigned char * qrySeg = NULL;
70 //Get the next query. Querys are separated by OIC_SEC_REST_QUERY_SEPARATOR
71 qrySeg = coap_parse_next(&parseIter->pi);
75 delimPos = strchr((char *)qrySeg, OIC_SEC_REST_QUERY_DELIMETER);
78 parseIter->attrPos = parseIter->pi.pos;
79 parseIter->attrLen = (unsigned char *)delimPos - parseIter->pi.pos;
80 parseIter->valPos = (unsigned char *)delimPos + 1;
81 parseIter->valLen = &qrySeg[parseIter->pi.segment_length] - parseIter->valPos;