uri.h
Go to the documentation of this file.
/*
* uri.h -- helper functions for URI treatment
*
* Copyright (C) 2010-2011,2016 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef COAP_URI_H_
#define COAP_URI_H_
#include <stdint.h>
#include "str.h"
struct coap_pdu_t;
enum coap_uri_scheme_t {
COAP_URI_SCHEME_COAP=0,
COAP_URI_SCHEME_COAPS=1,
COAP_URI_SCHEME_COAP_TCP=2,
COAP_URI_SCHEME_COAPS_TCP=3
};
#define COAP_URI_SCHEME_SECURE_MASK 0x01
typedef struct {
coap_str_const_t host;
uint16_t port;
coap_str_const_t path;
coap_str_const_t query;
enum coap_uri_scheme_t scheme;
} coap_uri_t;
static inline int
coap_uri_scheme_is_secure(const coap_uri_t *uri) {
return uri && ((uri->scheme & COAP_URI_SCHEME_SECURE_MASK) != 0);
}
coap_uri_t *coap_new_uri(const uint8_t *uri, unsigned int length);
coap_uri_t *coap_clone_uri(const coap_uri_t *uri);
int coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri);
int coap_split_path(const uint8_t *s,
size_t length,
unsigned char *buf,
size_t *buflen);
int coap_split_query(const uint8_t *s,
size_t length,
unsigned char *buf,
size_t *buflen);
coap_string_t *coap_get_query(const struct coap_pdu_t *request);
coap_string_t *coap_get_uri_path(const struct coap_pdu_t *request);
#endif /* COAP_URI_H_ */
coap_uri_t
Representation of parsed URI.
Definition: uri.h:36
COAP_URI_SCHEME_COAPS
Definition: uri.h:24
coap_clone_uri
coap_uri_t * coap_clone_uri(const coap_uri_t *uri)
Clones the specified coap_uri_t object.
Definition: uri.c:447
coap_get_uri_path
coap_string_t * coap_get_uri_path(const struct coap_pdu_t *request)
Extract uri_path string from request PDU.
coap_split_query
int coap_split_query(const uint8_t *s, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI query into segments.
Definition: uri.c:402
COAP_URI_SCHEME_COAP_TCP
Definition: uri.h:25
COAP_URI_SCHEME_COAPS_TCP
Definition: uri.h:26
str.h
coap_uri_t::host
coap_str_const_t host
host part of the URI
Definition: uri.h:37
COAP_URI_SCHEME_COAP
Definition: uri.h:23
coap_string_t
Coap string data definition.
Definition: str.h:25
coap_str_const_t
Coap string data definition with const data.
Definition: str.h:33
coap_split_path
int coap_split_path(const uint8_t *s, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI path into segments.
Definition: uri.c:390
coap_pdu_t
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Definition: pdu.h:287
coap_uri_scheme_is_secure
static int coap_uri_scheme_is_secure(const coap_uri_t *uri)
Definition: uri.h:48
coap_uri_t::scheme
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
Definition: uri.h:44
coap_uri_scheme_t
coap_uri_scheme_t
The scheme specifiers.
Definition: uri.h:22
coap_uri_t::port
uint16_t port
The port in host byte order.
Definition: uri.h:38
coap_get_query
coap_string_t * coap_get_query(const struct coap_pdu_t *request)
Extract query string from request PDU according to escape rules in 6.5.8.
coap_new_uri
coap_uri_t * coap_new_uri(const uint8_t *uri, unsigned int length)
Creates a new coap_uri_t object from the specified URI.
Definition: uri.c:428
coap_uri_t::query
coap_str_const_t query
The query part if present.
Definition: uri.h:41
coap_split_uri
int coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
Definition: uri.c:43
COAP_URI_SCHEME_SECURE_MASK
#define COAP_URI_SCHEME_SECURE_MASK
This mask can be used to check if a parsed URI scheme is secure.
Definition: uri.h:30
uint8_t
unsigned char uint8_t
Definition: uthash.h:79
coap_uri_t::path
coap_str_const_t path
Beginning of the first path segment.
Definition: uri.h:39