Dependencies:   MMA7660 LM75B

Committer:
MACRUM
Date:
Sat Jun 30 01:40:30 2018 +0000
Revision:
0:119624335925
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 0:119624335925 1 // ----------------------------------------------------------------------------
MACRUM 0:119624335925 2 // Copyright 2016-2017 ARM Ltd.
MACRUM 0:119624335925 3 //
MACRUM 0:119624335925 4 // SPDX-License-Identifier: Apache-2.0
MACRUM 0:119624335925 5 //
MACRUM 0:119624335925 6 // Licensed under the Apache License, Version 2.0 (the "License");
MACRUM 0:119624335925 7 // you may not use this file except in compliance with the License.
MACRUM 0:119624335925 8 // You may obtain a copy of the License at
MACRUM 0:119624335925 9 //
MACRUM 0:119624335925 10 // http://www.apache.org/licenses/LICENSE-2.0
MACRUM 0:119624335925 11 //
MACRUM 0:119624335925 12 // Unless required by applicable law or agreed to in writing, software
MACRUM 0:119624335925 13 // distributed under the License is distributed on an "AS IS" BASIS,
MACRUM 0:119624335925 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MACRUM 0:119624335925 15 // See the License for the specific language governing permissions and
MACRUM 0:119624335925 16 // limitations under the License.
MACRUM 0:119624335925 17 // ----------------------------------------------------------------------------
MACRUM 0:119624335925 18
MACRUM 0:119624335925 19 #include <string.h>
MACRUM 0:119624335925 20 #include "include/uriqueryparser.h"
MACRUM 0:119624335925 21
MACRUM 0:119624335925 22 char* query_string(char* uri)
MACRUM 0:119624335925 23 {
MACRUM 0:119624335925 24 char* query = strchr((char*)uri, '?');
MACRUM 0:119624335925 25 if (query != NULL) {
MACRUM 0:119624335925 26 query++;
MACRUM 0:119624335925 27 if (*query == '\0') {
MACRUM 0:119624335925 28 return NULL;
MACRUM 0:119624335925 29 } else {
MACRUM 0:119624335925 30 return query;
MACRUM 0:119624335925 31 }
MACRUM 0:119624335925 32 } else {
MACRUM 0:119624335925 33 return NULL;
MACRUM 0:119624335925 34 }
MACRUM 0:119624335925 35 }
MACRUM 0:119624335925 36
MACRUM 0:119624335925 37 int8_t query_param_count(char* query)
MACRUM 0:119624335925 38 {
MACRUM 0:119624335925 39 int param_count = 0;
MACRUM 0:119624335925 40 while (NULL != (query = strchr(query, '='))) {
MACRUM 0:119624335925 41 param_count++;
MACRUM 0:119624335925 42 ++query;
MACRUM 0:119624335925 43 }
MACRUM 0:119624335925 44 return param_count;
MACRUM 0:119624335925 45 }
MACRUM 0:119624335925 46
MACRUM 0:119624335925 47 bool uri_query_parameters(char* query, char *uri_query_parameters[], int index)
MACRUM 0:119624335925 48 {
MACRUM 0:119624335925 49 if (query == NULL || *query == '\0' || index < 0) {
MACRUM 0:119624335925 50 return false;
MACRUM 0:119624335925 51 }
MACRUM 0:119624335925 52
MACRUM 0:119624335925 53 uri_query_parameters[index++] = query;
MACRUM 0:119624335925 54 while (NULL != (query = strchr(query, '&'))) {
MACRUM 0:119624335925 55 *query = '\0';
MACRUM 0:119624335925 56 uri_query_parameters[index] = ++query;
MACRUM 0:119624335925 57 index++;
MACRUM 0:119624335925 58 }
MACRUM 0:119624335925 59
MACRUM 0:119624335925 60 return true;
MACRUM 0:119624335925 61 }