coap_client_request.h File Reference

CoAP request handling. More...

#include "core/net.h"
#include "coap/coap_client.h"
#include "coap/coap_option.h"

Go to the source code of this file.

Data Structures

struct  _CoapClientRequest
 CoAP request. More...
 

Typedefs

typedef error_t(* CoapRequestCallback) (CoapClientContext *context, CoapClientRequest *request, CoapRequestStatus status, void *param)
 Request completed callback. More...
 

Enumerations

enum  CoapRequestState {
  COAP_REQ_STATE_UNUSED = 0, COAP_REQ_STATE_INIT = 1, COAP_REQ_STATE_TRANSMIT = 2, COAP_REQ_STATE_RECEIVE = 3,
  COAP_REQ_STATE_SEPARATE = 4, COAP_REQ_STATE_OBSERVE = 5, COAP_REQ_STATE_DONE = 6, COAP_REQ_STATE_RESET = 7,
  COAP_REQ_STATE_TIMEOUT = 8, COAP_REQ_STATE_CANCELED = 9
}
 CoAP request states. More...
 
enum  CoapRequestStatus {
  COAP_REQUEST_STATUS_SUCCESS = 0, COAP_REQUEST_STATUS_FAILURE = 1, COAP_REQUEST_STATUS_RESET = 2, COAP_REQUEST_STATUS_TIMEOUT = 3,
  COAP_REQUEST_STATUS_CANCELED = 4
}
 Request status. More...
 

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

Copyright (C) 2010-2018 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
1.9.0

Definition in file coap_client_request.h.

Typedef Documentation

◆ CoapRequestCallback

typedef error_t(* CoapRequestCallback) (CoapClientContext *context, CoapClientRequest *request, CoapRequestStatus status, void *param)

Request completed callback.

Definition at line 80 of file coap_client_request.h.

Enumeration Type Documentation

◆ CoapRequestState

CoAP request states.

Enumerator
COAP_REQ_STATE_UNUSED 
COAP_REQ_STATE_INIT 
COAP_REQ_STATE_TRANSMIT 
COAP_REQ_STATE_RECEIVE 
COAP_REQ_STATE_SEPARATE 
COAP_REQ_STATE_OBSERVE 
COAP_REQ_STATE_DONE 
COAP_REQ_STATE_RESET 
COAP_REQ_STATE_TIMEOUT 
COAP_REQ_STATE_CANCELED 

Definition at line 47 of file coap_client_request.h.

◆ CoapRequestStatus

Request status.

Enumerator
COAP_REQUEST_STATUS_SUCCESS 
COAP_REQUEST_STATUS_FAILURE 
COAP_REQUEST_STATUS_RESET 
COAP_REQUEST_STATUS_TIMEOUT 
COAP_REQUEST_STATUS_CANCELED 

Definition at line 66 of file coap_client_request.h.

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 258 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 51 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 790 of file coap_client_request.c.

◆ coapClientDeleteRequest()

void coapClientDeleteRequest ( CoapClientRequest request)

Release the resources associated with a CoAP request.

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

Definition at line 331 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 606 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 627 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 490 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 725 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 834 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 352 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 508 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 396 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 748 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 454 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 770 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 545 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 585 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 875 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 155 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 472 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 650 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 810 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 128 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 676 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 436 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 703 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 526 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 565 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 854 of file coap_client_request.c.