mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-14 12:19:43 +03:00
uri.[hc]: improved support for 'coaps' URI scheme
This commit is contained in:
1 parent
5180ae3753
commit
3a127a3816
2 files changed
+24
No files matched your search
@@ -13,6 +13,18 @@
|
||||
#include "hashkey.h"
|
||||
#include "str.h"
|
||||
|
||||
/**
|
||||
* The scheme specifiers. Secure schemes have an odd numeric value,
|
||||
* others are even.
|
||||
*/
|
||||
enum coap_uri_scheme_t {
|
||||
COAP_URI_SCHEME_COAP=0,
|
||||
COAP_URI_SCHEME_COAPS=1
|
||||
};
|
||||
|
||||
/** This mask can be used to check if a parsed URI scheme is secure. */
|
||||
#define COAP_URI_SCHEME_SECURE_MASK 0x01
|
||||
|
||||
/**
|
||||
* Representation of parsed URI. Components may be filled from a string with
|
||||
* coap_split_uri() and can be used as input for option-creation functions.
|
||||
@@ -23,8 +35,16 @@ typedef struct {
|
||||
str path; /**< Beginning of the first path segment.
|
||||
Use coap_split_path() to create Uri-Path options */
|
||||
str query; /**< The query part if present */
|
||||
|
||||
/** The parsed scheme specifier. */
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new coap_uri_t object from the specified URI. Returns the new
|
||||
* object or NULL on error. The memory allocated by the new coap_uri_t
|
||||
|
||||
@@ -74,6 +74,10 @@ coap_split_uri(unsigned char *str_var, size_t len, coap_uri_t *uri) {
|
||||
/* There might be an additional 's', indicating the secure version: */
|
||||
if (len && (secure = tolower(*p) == 's')) {
|
||||
++p; --len;
|
||||
uri->scheme = COAP_URI_SCHEME_COAPS;
|
||||
uri->port = COAPS_DEFAULT_PORT;
|
||||
} else {
|
||||
uri->scheme = COAP_URI_SCHEME_COAP;
|
||||
}
|
||||
|
||||
q = (unsigned char *)"://";
|
||||
|
||||
Reference in new issue
Block a user