libcoap  4.3.0
pdu.c File Reference
#include "coap3/coap_internal.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
+ Include dependency graph for pdu.c:

Go to the source code of this file.

Data Structures

struct  error_desc_t
 

Macros

#define min(a, b)   ((a) < (b) ? (a) : (b))
 
#define max(a, b)   ((a) > (b) ? (a) : (b))
 

Functions

void coap_pdu_clear (coap_pdu_t *pdu, size_t size)
 Clears any contents from pdu and resets used_size, and data pointers. More...
 
coap_pdu_tcoap_pdu_init (coap_pdu_type_t type, coap_pdu_code_t code, coap_mid_t mid, size_t size)
 Creates a new CoAP PDU with at least enough storage space for the given size maximum message size. More...
 
coap_pdu_tcoap_new_pdu (coap_pdu_type_t type, coap_pdu_code_t code, coap_session_t *session)
 Creates a new CoAP PDU. More...
 
void coap_delete_pdu (coap_pdu_t *pdu)
 Dispose of an CoAP PDU and frees associated storage. More...
 
coap_pdu_tcoap_pdu_duplicate (const coap_pdu_t *old_pdu, coap_session_t *session, size_t token_length, const uint8_t *token, coap_opt_filter_t *drop_options)
 Duplicate an existing PDU. More...
 
int coap_pdu_resize (coap_pdu_t *pdu, size_t new_size)
 Dynamically grows the size of pdu to new_size. More...
 
int coap_pdu_check_resize (coap_pdu_t *pdu, size_t size)
 Dynamically grows the size of pdu to new_size if needed. More...
 
int coap_add_token (coap_pdu_t *pdu, size_t len, const uint8_t *data)
 Adds token of length len to pdu. More...
 
int coap_update_token (coap_pdu_t *pdu, size_t len, const uint8_t *data)
 Updates token in pdu with length len and data. More...
 
int coap_remove_option (coap_pdu_t *pdu, coap_option_num_t number)
 Removes (first) option of given number from the pdu. More...
 
size_t coap_insert_option (coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
 Inserts option of given number in the pdu with the appropriate data. More...
 
size_t coap_update_option (coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
 Updates existing first option of given number in the pdu with the new data. More...
 
size_t coap_add_option (coap_pdu_t *pdu, coap_option_num_t number, size_t len, const uint8_t *data)
 Adds option of given number to pdu that is passed as first parameter. More...
 
int coap_add_data (coap_pdu_t *pdu, size_t len, const uint8_t *data)
 Adds given data to the pdu that is passed as first parameter. More...
 
uint8_t * coap_add_data_after (coap_pdu_t *pdu, size_t len)
 Adds given data to the pdu that is passed as first parameter but does not copy it. More...
 
int coap_get_data (const coap_pdu_t *pdu, size_t *len, const uint8_t **data)
 Retrieves the length and data pointer of specified PDU. More...
 
int coap_get_data_large (const coap_pdu_t *pdu, size_t *len, const uint8_t **data, size_t *offset, size_t *total)
 Retrieves the data from a PDU, with support for large bodies of data that spans multiple PDUs. More...
 
const char * coap_response_phrase (unsigned char code)
 Returns a human-readable response phrase for the specified CoAP response code. More...
 
static size_t next_option_safe (coap_opt_t **optp, size_t *length, uint16_t *max_opt)
 Advances *optp to next option if still in PDU. More...
 
size_t coap_pdu_parse_header_size (coap_proto_t proto, const uint8_t *data)
 Interprets data to determine the number of bytes in the header. More...
 
size_t coap_pdu_parse_size (coap_proto_t proto, const uint8_t *data, size_t length)
 Parses data to extract the message size. More...
 
int coap_pdu_parse_header (coap_pdu_t *pdu, coap_proto_t proto)
 Decode the protocol specific header for the specified PDU. More...
 
static int coap_pdu_parse_opt_csm (coap_pdu_t *pdu, uint16_t len)
 
static int coap_pdu_parse_opt_base (coap_pdu_t *pdu, uint16_t len)
 
static int write_prefix (char **obp, size_t *len, const char *prf, size_t prflen)
 
static int write_char (char **obp, size_t *len, char c, int printable)
 
int coap_pdu_parse_opt (coap_pdu_t *pdu)
 Verify consistency in the given CoAP PDU structure and locate the data. More...
 
int coap_pdu_parse (coap_proto_t proto, const uint8_t *data, size_t length, coap_pdu_t *pdu)
 Parses data into the CoAP PDU structure given in result. More...
 
size_t coap_pdu_encode_header (coap_pdu_t *pdu, coap_proto_t proto)
 Compose the protocol specific header for the specified PDU. More...
 
coap_pdu_code_t coap_pdu_get_code (const coap_pdu_t *pdu)
 Gets the PDU code associated with pdu. More...
 
void coap_pdu_set_code (coap_pdu_t *pdu, coap_pdu_code_t code)
 Sets the PDU code in the pdu. More...
 
coap_pdu_type_t coap_pdu_get_type (const coap_pdu_t *pdu)
 Gets the PDU type associated with pdu. More...
 
void coap_pdu_set_type (coap_pdu_t *pdu, coap_pdu_type_t type)
 Sets the PDU type in the pdu. More...
 
coap_bin_const_t coap_pdu_get_token (const coap_pdu_t *pdu)
 Gets the token associated with pdu. More...
 
coap_mid_t coap_pdu_get_mid (const coap_pdu_t *pdu)
 Gets the message id associated with pdu. More...
 
void coap_pdu_set_mid (coap_pdu_t *pdu, coap_mid_t mid)
 Sets the message id in the pdu. More...
 

Variables

error_desc_t coap_error []
 

Macro Definition Documentation

◆ max

#define max (   a,
 
)    ((a) > (b) ? (a) : (b))

Definition at line 33 of file pdu.c.

◆ min

#define min (   a,
 
)    ((a) < (b) ? (a) : (b))

Definition at line 29 of file pdu.c.

Function Documentation

◆ coap_pdu_parse_opt_base()

static int coap_pdu_parse_opt_base ( coap_pdu_t pdu,
uint16_t  len 
)
static

Definition at line 911 of file pdu.c.

+ Here is the caller graph for this function:

◆ coap_pdu_parse_opt_csm()

static int coap_pdu_parse_opt_csm ( coap_pdu_t pdu,
uint16_t  len 
)
static

Definition at line 857 of file pdu.c.

+ Here is the caller graph for this function:

◆ next_option_safe()

static size_t next_option_safe ( coap_opt_t **  optp,
size_t *  length,
uint16_t *  max_opt 
)
static

Advances *optp to next option if still in PDU.

This function returns the number of bytes opt has been advanced or 0 on error.

Definition at line 745 of file pdu.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write_char()

static int write_char ( char **  obp,
size_t *  len,
char  c,
int  printable 
)
static

Definition at line 957 of file pdu.c.

+ Here is the caller graph for this function:

◆ write_prefix()

static int write_prefix ( char **  obp,
size_t *  len,
const char *  prf,
size_t  prflen 
)
static

Definition at line 944 of file pdu.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ coap_error

error_desc_t coap_error[]
Initial value:
= {
{ COAP_RESPONSE_CODE(201), "Created" },
{ COAP_RESPONSE_CODE(202), "Deleted" },
{ COAP_RESPONSE_CODE(203), "Valid" },
{ COAP_RESPONSE_CODE(204), "Changed" },
{ COAP_RESPONSE_CODE(205), "Content" },
{ COAP_RESPONSE_CODE(231), "Continue" },
{ COAP_RESPONSE_CODE(400), "Bad Request" },
{ COAP_RESPONSE_CODE(401), "Unauthorized" },
{ COAP_RESPONSE_CODE(402), "Bad Option" },
{ COAP_RESPONSE_CODE(403), "Forbidden" },
{ COAP_RESPONSE_CODE(404), "Not Found" },
{ COAP_RESPONSE_CODE(405), "Method Not Allowed" },
{ COAP_RESPONSE_CODE(406), "Not Acceptable" },
{ COAP_RESPONSE_CODE(408), "Request Entity Incomplete" },
{ COAP_RESPONSE_CODE(409), "Conflict" },
{ COAP_RESPONSE_CODE(412), "Precondition Failed" },
{ COAP_RESPONSE_CODE(413), "Request Entity Too Large" },
{ COAP_RESPONSE_CODE(415), "Unsupported Content-Format" },
{ COAP_RESPONSE_CODE(422), "Unprocessable" },
{ COAP_RESPONSE_CODE(429), "Too Many Requests" },
{ COAP_RESPONSE_CODE(500), "Internal Server Error" },
{ COAP_RESPONSE_CODE(501), "Not Implemented" },
{ COAP_RESPONSE_CODE(502), "Bad Gateway" },
{ COAP_RESPONSE_CODE(503), "Service Unavailable" },
{ COAP_RESPONSE_CODE(504), "Gateway Timeout" },
{ COAP_RESPONSE_CODE(505), "Proxying Not Supported" },
{ COAP_RESPONSE_CODE(508), "Hop Limit Reached" },
{ 0, NULL }
}
#define COAP_RESPONSE_CODE(N)
Definition: pdu.h:140

Definition at line 697 of file pdu.c.