coap_client_request.c File Reference

CoAP request handling. More...

#include <stdlib.h>
#include "core/net.h"
#include "coap/coap_client.h"
#include "coap/coap_client_request.h"
#include "coap/coap_client_block.h"
#include "coap/coap_client_misc.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   COAP_TRACE_LEVEL
 

Functions

CoapClientRequestcoapClientCreateRequest (CoapClientContext *context)
 Initialize a new CoAP request. More...
 
error_t coapClientSetRequestTimeout (CoapClientRequest *request, systime_t timeout)
 Set request timeout. More...
 
error_t coapClientSendRequest (CoapClientRequest *request, CoapRequestCallback callback, void *param)
 Send a CoAP request. More...
 
error_t coapClientCancelRequest (CoapClientRequest *request)
 Cancel an outstanding CoAP request. More...
 
void coapClientDeleteRequest (CoapClientRequest *request)
 Release the resources associated with a CoAP request. More...
 
CoapMessagecoapClientGetRequestMessage (CoapClientRequest *request)
 Get request message. More...
 
CoapMessagecoapClientGetResponseMessage (CoapClientRequest *request)
 Get response message. More...
 
error_t coapClientSetType (CoapMessage *message, CoapMessageType type)
 Set message type. More...
 
error_t coapClientGetType (const CoapMessage *message, CoapMessageType *type)
 Get message type. More...
 
error_t coapClientSetMethodCode (CoapMessage *message, CoapCode code)
 Set request method. More...
 
error_t coapClientGetMethodCode (const CoapMessage *message, CoapCode *code)
 Get request method. More...
 
error_t coapClientGetResponseCode (const CoapMessage *message, CoapCode *code)
 Get response code. More...
 
error_t coapClientSetUriPath (CoapMessage *message, const char_t *path)
 Set Uri-Path option. More...
 
error_t coapClientGetUriPath (const CoapMessage *message, char_t *path, size_t maxLen)
 Get Uri-Path option. More...
 
error_t coapClientSetUriQuery (CoapMessage *message, const char_t *queryString)
 Set Uri-Query option. More...
 
error_t coapClientGetUriQuery (const CoapMessage *message, char_t *queryString, size_t maxLen)
 Get Uri-Query option. More...
 
error_t coapClientGetLocationPath (const CoapMessage *message, char_t *path, size_t maxLen)
 Get Location-Path option. More...
 
error_t coapClientGetLocationQuery (const CoapMessage *message, char_t *queryString, size_t maxLen)
 Get Location-Query option. More...
 
error_t coapClientSetOpaqueOption (CoapMessage *message, uint16_t optionNum, uint_t optionIndex, const uint8_t *optionValue, size_t optionLen)
 Add an opaque option to the CoAP message. More...
 
error_t coapClientSetStringOption (CoapMessage *message, uint16_t optionNum, uint_t optionIndex, const char_t *optionValue)
 Add a string option to the CoAP message. More...
 
error_t coapClientSetUintOption (CoapMessage *message, uint16_t optionNum, uint_t optionIndex, uint32_t optionValue)
 Add a uint option to the CoAP message. More...
 
error_t coapClientGetOpaqueOption (const CoapMessage *message, uint16_t optionNum, uint_t optionIndex, const uint8_t **optionValue, size_t *optionLen)
 Read an opaque option from the CoAP message. More...
 
error_t coapClientGetStringOption (const CoapMessage *message, uint16_t optionNum, uint_t optionIndex, const char_t **optionValue, size_t *optionLen)
 Read a string option from the CoAP message. More...
 
error_t coapClientGetUintOption (const CoapMessage *message, uint16_t optionNum, uint_t optionIndex, uint32_t *optionValue)
 Read an uint option from the CoAP message. More...
 
error_t coapClientDeleteOption (CoapMessage *message, uint16_t optionNum, uint_t optionIndex)
 Remove an option from the CoAP message. More...
 
error_t coapClientSetPayload (CoapMessage *message, const void *payload, size_t payloadLen)
 Set message payload. More...
 
error_t coapClientGetPayload (const CoapMessage *message, const uint8_t **payload, size_t *payloadLen)
 Get message payload. More...
 
error_t coapClientWritePayload (CoapMessage *message, const void *data, size_t length)
 Write payload data. More...
 
error_t coapClientReadPayload (CoapMessage *message, void *data, size_t size, size_t *length)
 Read payload data. More...
 

Detailed Description

CoAP request handling.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneTCP Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.0

Definition in file coap_client_request.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   COAP_TRACE_LEVEL

Definition at line 32 of file coap_client_request.c.

Function Documentation

◆ coapClientCancelRequest()

error_t coapClientCancelRequest ( CoapClientRequest request)

Cancel an outstanding CoAP request.

Parameters
[in]requestCoAP request handle
Returns
Pointer to the CoAP request

Definition at line 275 of file coap_client_request.c.

◆ coapClientCreateRequest()

CoapClientRequest* coapClientCreateRequest ( CoapClientContext context)

Initialize a new CoAP request.

Parameters
[in]contextPointer to the CoAP client context
Returns
Pointer to the new CoAP request

Definition at line 53 of file coap_client_request.c.

◆ coapClientDeleteOption()

error_t coapClientDeleteOption ( CoapMessage message,
uint16_t  optionNum,
uint_t  optionIndex 
)

Remove an option from the CoAP message.

Parameters
[in]messagePointer to the CoAP message
[in]optionNumOption number
[in]optionIndexOccurrence index (for repeatable options only)
Returns
Error code

Definition at line 808 of file coap_client_request.c.

◆ coapClientDeleteRequest()

void coapClientDeleteRequest ( CoapClientRequest request)

Release the resources associated with a CoAP request.

Parameters
[in]requestCoAP request handle

Definition at line 349 of file coap_client_request.c.

◆ coapClientGetLocationPath()

error_t coapClientGetLocationPath ( const CoapMessage message,
char_t path,
size_t  maxLen 
)

Get Location-Path option.

Parameters
[in]messagePointer to the CoAP message
[out]pathPointer to the buffer where to copy the path component
[in]maxLenMaximum number of characters the buffer can hold
Returns
Error code

Definition at line 624 of file coap_client_request.c.

◆ coapClientGetLocationQuery()

error_t coapClientGetLocationQuery ( const CoapMessage message,
char_t queryString,
size_t  maxLen 
)

Get Location-Query option.

Parameters
[in]messagePointer to the CoAP message
[out]queryStringPointer to the buffer where to copy the query string
[in]maxLenMaximum number of characters the buffer can hold
Returns
Error code

Definition at line 645 of file coap_client_request.c.

◆ coapClientGetMethodCode()

error_t coapClientGetMethodCode ( const CoapMessage message,
CoapCode code 
)

Get request method.

Parameters
[in]messagePointer to the CoAP message
[out]codeMethod code
Returns
Error code

Definition at line 508 of file coap_client_request.c.

◆ coapClientGetOpaqueOption()

error_t coapClientGetOpaqueOption ( const CoapMessage message,
uint16_t  optionNum,
uint_t  optionIndex,
const uint8_t **  optionValue,
size_t *  optionLen 
)

Read an opaque option from the CoAP message.

Parameters
[in]messagePointer to the CoAP message
[in]optionNumOption number to search for
[in]optionIndexOccurrence index (for repeatable options only)
[out]optionValuePointer to the first byte of the option value
[out]optionLenLength of the option, in bytes
Returns
Error code

Definition at line 743 of file coap_client_request.c.

◆ coapClientGetPayload()

error_t coapClientGetPayload ( const CoapMessage message,
const uint8_t **  payload,
size_t *  payloadLen 
)

Get message payload.

Parameters
[in]messagePointer to the CoAP message
[out]payloadPointer to the first byte of the payload
[out]payloadLenLength of the payload, in bytes
Returns
Error code

Definition at line 852 of file coap_client_request.c.

◆ coapClientGetRequestMessage()

CoapMessage* coapClientGetRequestMessage ( CoapClientRequest request)

Get request message.

Parameters
[in]requestCoAP request handle
Returns
Pointer to the request message

Definition at line 370 of file coap_client_request.c.

◆ coapClientGetResponseCode()

error_t coapClientGetResponseCode ( const CoapMessage message,
CoapCode code 
)

Get response code.

Parameters
[in]messagePointer to the CoAP message
[out]codeResponse code
Returns
Error code

Definition at line 526 of file coap_client_request.c.

◆ coapClientGetResponseMessage()

CoapMessage* coapClientGetResponseMessage ( CoapClientRequest request)

Get response message.

Parameters
[in]requestCoAP request handle
Returns
Pointer to the response message

Definition at line 414 of file coap_client_request.c.

◆ coapClientGetStringOption()

error_t coapClientGetStringOption ( const CoapMessage message,
uint16_t  optionNum,
uint_t  optionIndex,
const char_t **  optionValue,
size_t *  optionLen 
)

Read a string option from the CoAP message.

Parameters
[in]messagePointer to the CoAP message
[in]optionNumOption number to search for
[in]optionIndexOccurrence index (for repeatable options only)
[out]optionValuePointer to the first byte of the option value
[out]optionLenLength of the option, in characters
Returns
Error code

Definition at line 766 of file coap_client_request.c.

◆ coapClientGetType()

error_t coapClientGetType ( const CoapMessage message,
CoapMessageType type 
)

Get message type.

Parameters
[in]messagePointer to the CoAP message
[out]typeMessage type
Returns
Error code

Definition at line 472 of file coap_client_request.c.

◆ coapClientGetUintOption()

error_t coapClientGetUintOption ( const CoapMessage message,
uint16_t  optionNum,
uint_t  optionIndex,
uint32_t *  optionValue 
)

Read an uint option from the CoAP message.

Parameters
[in]messagePointer to the CoAP message
[in]optionNumOption number to search for
[in]optionIndexOccurrence index (for repeatable options only)
[out]optionValueOption value (unsigned integer)
Returns
Error code

Definition at line 788 of file coap_client_request.c.

◆ coapClientGetUriPath()

error_t coapClientGetUriPath ( const CoapMessage message,
char_t path,
size_t  maxLen 
)

Get Uri-Path option.

Parameters
[in]messagePointer to the CoAP message
[out]pathPointer to the buffer where to copy the path component
[in]maxLenMaximum number of characters the buffer can hold
Returns
Error code

Definition at line 563 of file coap_client_request.c.

◆ coapClientGetUriQuery()

error_t coapClientGetUriQuery ( const CoapMessage message,
char_t queryString,
size_t  maxLen 
)

Get Uri-Query option.

Parameters
[in]messagePointer to the CoAP message
[out]queryStringPointer to the buffer where to copy the query string
[in]maxLenMaximum number of characters the buffer can hold
Returns
Error code

Definition at line 603 of file coap_client_request.c.

◆ coapClientReadPayload()

error_t coapClientReadPayload ( CoapMessage message,
void *  data,
size_t  size,
size_t *  length 
)

Read payload data.

Parameters
[in]messagePointer to the CoAP message
[out]dataBuffer into which received data will be placed
[in]sizeMaximum number of bytes that can be received
[out]lengthNumber of bytes that have been received
Returns
Error code

Definition at line 893 of file coap_client_request.c.

◆ coapClientSendRequest()

error_t coapClientSendRequest ( CoapClientRequest request,
CoapRequestCallback  callback,
void *  param 
)

Send a CoAP request.

Parameters
[in]requestCoAP request handle
[in]callbackCallback function to invoke when the request completes
[in]paramCallback function parameter
Returns
Error code

Definition at line 157 of file coap_client_request.c.

◆ coapClientSetMethodCode()

error_t coapClientSetMethodCode ( CoapMessage message,
CoapCode  code 
)

Set request method.

Parameters
[in]messagePointer to the CoAP message
[in]codeMethod code (GET, POST, PUT or DELETE)
Returns
Error code

Definition at line 490 of file coap_client_request.c.

◆ coapClientSetOpaqueOption()

error_t coapClientSetOpaqueOption ( CoapMessage message,
uint16_t  optionNum,
uint_t  optionIndex,
const uint8_t *  optionValue,
size_t  optionLen 
)

Add an opaque option to the CoAP message.

Parameters
[in]messagePointer to the CoAP message
[in]optionNumOption number
[in]optionIndexOccurrence index (for repeatable options only)
[in]optionValuePointer to the first byte of the option value
[in]optionLenLength of the option, in bytes
Returns
Error code

Definition at line 668 of file coap_client_request.c.

◆ coapClientSetPayload()

error_t coapClientSetPayload ( CoapMessage message,
const void *  payload,
size_t  payloadLen 
)

Set message payload.

Parameters
[in]messagePointer to the CoAP message
[out]payloadPointer to request payload
[out]payloadLenLength of the payload, in bytes
Returns
Error code

Definition at line 828 of file coap_client_request.c.

◆ coapClientSetRequestTimeout()

error_t coapClientSetRequestTimeout ( CoapClientRequest request,
systime_t  timeout 
)

Set request timeout.

Parameters
[in]requestCoAP request handle
[in]timeoutTimeout value, in milliseconds
Returns
Error code

Definition at line 130 of file coap_client_request.c.

◆ coapClientSetStringOption()

error_t coapClientSetStringOption ( CoapMessage message,
uint16_t  optionNum,
uint_t  optionIndex,
const char_t optionValue 
)

Add a string option to the CoAP message.

Parameters
[in]messagePointer to the CoAP message
[in]optionNumOption number
[in]optionIndexOccurrence index (for repeatable options only)
[in]optionValueNULL-terminated string that contains the option value
Returns
Error code

Definition at line 694 of file coap_client_request.c.

◆ coapClientSetType()

error_t coapClientSetType ( CoapMessage message,
CoapMessageType  type 
)

Set message type.

Parameters
[in]messagePointer to the CoAP message
[in]typeMessage type (Confirmable or Non-confirmable)
Returns
Error code

Definition at line 454 of file coap_client_request.c.

◆ coapClientSetUintOption()

error_t coapClientSetUintOption ( CoapMessage message,
uint16_t  optionNum,
uint_t  optionIndex,
uint32_t  optionValue 
)

Add a uint option to the CoAP message.

Parameters
[in]messagePointer to the CoAP message
[in]optionNumOption number
[in]optionIndexOccurrence index (for repeatable options only)
[in]optionValueOption value (unsigned integer)
Returns
Error code

Definition at line 721 of file coap_client_request.c.

◆ coapClientSetUriPath()

error_t coapClientSetUriPath ( CoapMessage message,
const char_t path 
)

Set Uri-Path option.

Parameters
[in]messagePointer to the CoAP message
[in]pathNULL-terminated string that contains the path component
Returns
Error code

Definition at line 544 of file coap_client_request.c.

◆ coapClientSetUriQuery()

error_t coapClientSetUriQuery ( CoapMessage message,
const char_t queryString 
)

Set Uri-Query option.

Parameters
[in]messagePointer to the CoAP message
[in]queryStringNULL-terminated string that contains the query string
Returns
Error code

Definition at line 583 of file coap_client_request.c.

◆ coapClientWritePayload()

error_t coapClientWritePayload ( CoapMessage message,
const void *  data,
size_t  length 
)

Write payload data.

Parameters
[in]messagePointer to the CoAP message
[in]dataPointer to a buffer containing the data to be written
[in]lengthNumber of bytes to written
Returns
Error code

Definition at line 872 of file coap_client_request.c.