nkjnm
Dependencies: MAX44000 nexpaq_mdk
Fork of LED_Demo by
sn_coap_parser_stub.c
00001 /* 00002 * Copyright (c) 2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 /** 00018 *\file sn_coap_parser.c 00019 * 00020 * \brief CoAP Header parser 00021 * 00022 * Functionality: Parses CoAP Header 00023 * 00024 */ 00025 00026 #include "ns_types.h" 00027 #include "sn_nsdl.h" 00028 #include "sn_coap_header.h" 00029 #include "sn_coap_protocol_internal.h" 00030 #include "sn_coap_parser_stub.h" 00031 00032 sn_coap_parser_def sn_coap_parser_stub; 00033 00034 sn_coap_hdr_s *sn_coap_parser(struct coap_s *handle, uint16_t packet_data_len, uint8_t *packet_data_ptr, coap_version_e *coap_version_ptr) 00035 { 00036 return sn_coap_parser_stub.expectedHeader; 00037 } 00038 00039 void sn_coap_parser_release_allocated_coap_msg_mem(struct coap_s *handle, sn_coap_hdr_s *freed_coap_msg_ptr) 00040 { 00041 if (freed_coap_msg_ptr != NULL) { 00042 if (freed_coap_msg_ptr->uri_path_ptr != NULL) { 00043 free(freed_coap_msg_ptr->uri_path_ptr); 00044 } 00045 00046 if (freed_coap_msg_ptr->token_ptr != NULL) { 00047 free(freed_coap_msg_ptr->token_ptr); 00048 } 00049 00050 if (freed_coap_msg_ptr->content_type_ptr != NULL) { 00051 free(freed_coap_msg_ptr->content_type_ptr); 00052 } 00053 00054 if (freed_coap_msg_ptr->options_list_ptr != NULL) { 00055 if (freed_coap_msg_ptr->options_list_ptr->max_age_ptr != NULL) { 00056 free(freed_coap_msg_ptr->options_list_ptr->max_age_ptr); 00057 } 00058 00059 if (freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr != NULL) { 00060 free(freed_coap_msg_ptr->options_list_ptr->proxy_uri_ptr); 00061 } 00062 00063 if (freed_coap_msg_ptr->options_list_ptr->etag_ptr != NULL) { 00064 free(freed_coap_msg_ptr->options_list_ptr->etag_ptr); 00065 } 00066 00067 if (freed_coap_msg_ptr->options_list_ptr->uri_host_ptr != NULL) { 00068 free(freed_coap_msg_ptr->options_list_ptr->uri_host_ptr); 00069 } 00070 00071 if (freed_coap_msg_ptr->options_list_ptr->location_path_ptr != NULL) { 00072 free(freed_coap_msg_ptr->options_list_ptr->location_path_ptr); 00073 } 00074 00075 if (freed_coap_msg_ptr->options_list_ptr->uri_port_ptr != NULL) { 00076 free(freed_coap_msg_ptr->options_list_ptr->uri_port_ptr); 00077 } 00078 00079 if (freed_coap_msg_ptr->options_list_ptr->location_query_ptr != NULL) { 00080 free(freed_coap_msg_ptr->options_list_ptr->location_query_ptr); 00081 } 00082 00083 if (freed_coap_msg_ptr->options_list_ptr->observe_ptr != NULL) { 00084 free(freed_coap_msg_ptr->options_list_ptr->observe_ptr); 00085 } 00086 00087 if (freed_coap_msg_ptr->options_list_ptr->uri_query_ptr != NULL) { 00088 free(freed_coap_msg_ptr->options_list_ptr->uri_query_ptr); 00089 } 00090 00091 if (freed_coap_msg_ptr->options_list_ptr->block2_ptr != NULL) { 00092 free(freed_coap_msg_ptr->options_list_ptr->block2_ptr); 00093 } 00094 00095 if (freed_coap_msg_ptr->options_list_ptr->block1_ptr != NULL) { 00096 free(freed_coap_msg_ptr->options_list_ptr->block1_ptr); 00097 } 00098 if (freed_coap_msg_ptr->options_list_ptr->accept_ptr != NULL) { 00099 free(freed_coap_msg_ptr->options_list_ptr->accept_ptr); 00100 } 00101 if (freed_coap_msg_ptr->options_list_ptr->size1_ptr != NULL) { 00102 free(freed_coap_msg_ptr->options_list_ptr->size1_ptr); 00103 } 00104 free(freed_coap_msg_ptr->options_list_ptr); 00105 } 00106 00107 free(freed_coap_msg_ptr); 00108 freed_coap_msg_ptr = NULL; 00109 } 00110 } 00111 00112 sn_coap_hdr_s *sn_coap_parser_init_message(sn_coap_hdr_s *coap_msg_ptr) 00113 { 00114 /* * * * Check given pointer * * * */ 00115 if (coap_msg_ptr == NULL) { 00116 return NULL; 00117 } 00118 00119 /* XXX not technically legal to memset pointers to 0 */ 00120 memset(coap_msg_ptr, 0x00, sizeof(sn_coap_hdr_s)); 00121 00122 return coap_msg_ptr; 00123 } 00124 00125 sn_coap_hdr_s *sn_coap_parser_alloc_message(struct coap_s *handle) 00126 { 00127 sn_coap_hdr_s *returned_coap_msg_ptr; 00128 00129 /* * * * Check given pointer * * * */ 00130 if (handle == NULL) { 00131 return NULL; 00132 } 00133 00134 /* * * * Allocate memory for returned CoAP message and initialize allocated memory with with default values * * * */ 00135 returned_coap_msg_ptr = handle->sn_coap_protocol_malloc(sizeof(sn_coap_hdr_s)); 00136 00137 return sn_coap_parser_init_message(returned_coap_msg_ptr); 00138 } 00139 00140 sn_coap_options_list_s *sn_coap_parser_alloc_options(struct coap_s *handle, sn_coap_hdr_s *coap_msg_ptr) 00141 { 00142 /* * * * Check given pointers * * * */ 00143 if (handle == NULL || coap_msg_ptr == NULL) { 00144 return NULL; 00145 } 00146 00147 /* * * * If the message already has options, return them * * * */ 00148 if (coap_msg_ptr->options_list_ptr) { 00149 return coap_msg_ptr->options_list_ptr; 00150 } 00151 00152 /* * * * Allocate memory for options and initialize allocated memory with with default values * * * */ 00153 coap_msg_ptr->options_list_ptr = handle->sn_coap_protocol_malloc(sizeof(sn_coap_options_list_s)); 00154 00155 if (coap_msg_ptr->options_list_ptr == NULL) { 00156 return NULL; 00157 } 00158 00159 /* XXX not technically legal to memset pointers to 0 */ 00160 memset(coap_msg_ptr->options_list_ptr, 0x00, sizeof(sn_coap_options_list_s)); 00161 00162 return coap_msg_ptr->options_list_ptr; 00163 }
Generated on Tue Jul 12 2022 17:03:52 by
1.7.2
