2 #include "avrsupport.h" 21 #define NS_FOSSA_VERSION "2.0.0" 27 #ifndef OSDEP_HEADER_INCLUDED 28 #define OSDEP_HEADER_INCLUDED 30 #if !defined(NS_DISABLE_FILESYSTEM) && defined(AVR_NOFS) 31 #define NS_DISABLE_FILESYSTEM 37 #define _INTEGRAL_MAX_BITS 64 38 #define _CRT_SECURE_NO_WARNINGS 39 #undef WIN32_LEAN_AND_MEAN 41 #define _XOPEN_SOURCE 600 42 #define __STDC_FORMAT_MACROS 43 #define __STDC_LIMIT_MACROS 44 #ifndef _LARGEFILE_SOURCE 45 #define _LARGEFILE_SOURCE 47 #define _FILE_OFFSET_BITS 64 49 #if !(defined(AVR_LIBC) || defined(PICOTCP)) 50 #include <sys/types.h> 58 #define LITTLE_ENDIAN 0x41424344 59 #define BIG_ENDIAN 0x44434241 60 #define PDP_ENDIAN 0x42414443 63 #define BYTE_ORDER LITTLE_ENDIAN 78 #pragma warning(disable : 4127) 79 #pragma warning(disable : 4204) 83 #define time(x) PICO_TIME() 85 #define SOMAXCONN (16) 103 #define va_copy __va_copy 105 #define va_copy(x, y) (x) = (y) 111 #pragma comment(lib, "ws2_32.lib") 116 #define EINPROGRESS WSAEINPROGRESS 119 #define EWOULDBLOCK WSAEWOULDBLOCK 123 #define STR(x) STRX(x) 124 #define __func__ __FILE__ ":" STR(__LINE__) 126 #define snprintf _snprintf 127 #define vsnprintf _vsnprintf 128 #define sleep(x) Sleep((x) *1000) 129 #define to64(x) _atoi64(x) 130 #define popen(x, y) _popen((x), (y)) 131 #define pclose(x) _pclose(x) 132 #if defined(_MSC_VER) && _MSC_VER >= 1400 133 #define fseeko(x, y, z) _fseeki64((x), (y), (z)) 135 #define fseeko(x, y, z) fseek((x), (y), (z)) 137 typedef int socklen_t;
138 typedef unsigned char uint8_t;
139 typedef unsigned int uint32_t;
140 typedef unsigned short uint16_t;
141 typedef unsigned __int64 uint64_t;
142 typedef __int64 int64_t;
143 typedef SOCKET sock_t;
144 typedef uint32_t in_addr_t;
148 #define INT64_FMT "I64d" 150 typedef struct stat ns_stat_t;
152 typedef struct _stati64 ns_stat_t;
155 #define S_ISDIR(x) ((x) &_S_IFDIR) 161 char d_name[MAX_PATH];
166 WIN32_FIND_DATAW info;
167 struct dirent result;
170 DIR *opendir(
const char *name);
171 int closedir(DIR *dir);
172 struct dirent *readdir(DIR *dir);
181 #include <arpa/inet.h> 182 #include <netinet/in.h> 183 #include <sys/socket.h> 184 #include <sys/select.h> 187 #include <inttypes.h> 190 #define closesocket(x) close(x) 194 #define INVALID_SOCKET (-1) 195 #define INT64_FMT PRId64 196 #define to64(x) strtoll(x, NULL, 10) 198 typedef struct stat ns_stat_t;
202 int64_t strtoll(
const char *str,
char **endptr,
int base);
206 #ifdef NS_ENABLE_DEBUG 209 printf("%-20s ", __func__); \ 219 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) 222 #if !defined(NO_LIBC) && !defined(NS_DISABLE_FILESYSTEM) 223 typedef FILE *c_file_t;
230 #define c_fopen fopen 231 #define c_fread fread 232 #define c_fwrite fwrite 233 #define c_fclose fclose 234 #define c_rename rename 235 #define c_remove remove 236 #define c_fseek fseek 237 #define c_ftell ftell 238 #define c_rewind rewind 239 #define c_ferror ferror 240 #define INVALID_FILE NULL 245 c_file_t c_fopen(
const char *filename,
const char *mode);
246 size_t c_fread(
void *ptr,
size_t size,
size_t count, c_file_t fd);
247 size_t c_fwrite(
const void *ptr,
size_t size,
size_t count, c_file_t fd);
248 int c_fclose(c_file_t fd);
249 int c_rename(
const char *oldname,
const char *newname);
250 int c_remove(
const char *filename);
251 void c_rewind(c_file_t fd);
252 int c_ferror(c_file_t fd);
270 #ifndef MBUF_H_INCLUDED 271 #define MBUF_H_INCLUDED 273 #if defined(__cplusplus) 279 #ifndef MBUF_SIZE_MULTIPLIER 280 #define MBUF_SIZE_MULTIPLIER 1.5 294 void mbuf_init(
struct mbuf *,
size_t initial_capacity);
297 void mbuf_free(
struct mbuf *);
304 size_t mbuf_append(
struct mbuf *,
const void *data,
size_t data_size);
313 size_t mbuf_insert(
struct mbuf *,
size_t,
const void *,
size_t);
316 void mbuf_remove(
struct mbuf *,
size_t data_size);
324 void mbuf_resize(
struct mbuf *,
size_t new_size);
327 void mbuf_trim(
struct mbuf *);
329 #if defined(__cplusplus) 339 #if !defined(NS_SHA1_HEADER_INCLUDED) && !defined(DISABLE_SHA1) 340 #define NS_SHA1_HEADER_INCLUDED 350 unsigned char buffer[64];
354 void SHA1Update(
SHA1_CTX *,
const unsigned char *data, uint32_t len);
355 void SHA1Final(
unsigned char digest[20],
SHA1_CTX *);
356 void hmac_sha1(
const unsigned char *key,
size_t key_len,
357 const unsigned char *text,
size_t text_len,
358 unsigned char out[20]);
368 #ifndef MD5_HEADER_DEFINED 369 #define MD5_HEADER_DEFINED 379 unsigned char in[64];
383 void MD5_Update(
MD5_CTX *c,
const unsigned char *data,
size_t len);
384 void MD5_Final(
unsigned char *md,
MD5_CTX *c);
396 #if !defined(BASE64_H_INCLUDED) && !defined(DISABLE_BASE64) 397 #define BASE64_H_INCLUDED 403 void cs_base64_encode(
const unsigned char *src,
int src_len,
char *dst);
404 int cs_base64_decode(
const unsigned char *s,
int len,
char *dst);
425 int c_snprintf(
char *buf,
size_t buf_size,
const char *format, ...);
426 int c_vsnprintf(
char *buf,
size_t buf_size,
const char *format, va_list ap);
451 #ifndef FROZEN_HEADER_INCLUDED 452 #define FROZEN_HEADER_INCLUDED 462 JSON_TYPE_STRING = 1,
463 JSON_TYPE_NUMBER = 2,
464 JSON_TYPE_OBJECT = 3,
479 #define JSON_STRING_INVALID -1 480 #define JSON_STRING_INCOMPLETE -2 481 #define JSON_TOKEN_ARRAY_TOO_SMALL -3 483 int parse_json(
const char *json_string,
int json_string_length,
484 struct json_token *tokens_array,
int size_of_tokens_array);
485 struct json_token *parse_json2(
const char *json_string,
int string_length);
488 int json_emit_long(
char *buf,
int buf_len,
long value);
489 int json_emit_double(
char *buf,
int buf_len,
double value);
490 int json_emit_quoted_str(
char *buf,
int buf_len,
const char *str,
int len);
491 int json_emit_unquoted_str(
char *buf,
int buf_len,
const char *str,
int len);
492 int json_emit(
char *buf,
int buf_len,
const char *fmt, ...);
493 int json_emit_va(
char *buf,
int buf_len,
const char *fmt, va_list);
527 #ifndef NS_NET_HEADER_INCLUDED 528 #define NS_NET_HEADER_INCLUDED 533 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 535 #include <openssl/ssl.h> 538 typedef void *SSL_CTX;
541 #ifdef NS_USE_READ_WRITE 542 #define NS_RECV_FUNC(s, b, l, f) read(s, b, l) 543 #define NS_SEND_FUNC(s, b, l, f) write(s, b, l) 545 #define NS_RECV_FUNC(s, b, l, f) recv(s, b, l, f) 546 #define NS_SEND_FUNC(s, b, l, f) send(s, b, l, f) 555 struct sockaddr_in sin;
556 #ifdef NS_ENABLE_IPV6 557 struct sockaddr_in6 sin6;
559 struct sockaddr sin6;
569 #define NS_STR(str_literal) \ 570 { str_literal, sizeof(str_literal) - 1 } 577 typedef void (*ns_event_handler_t)(
struct ns_connection *,
int ev,
void *);
592 const char *hexdump_file;
608 size_t recv_mbuf_limit;
609 struct mbuf recv_mbuf;
610 struct mbuf send_mbuf;
614 ns_event_handler_t proto_handler;
616 ns_event_handler_t handler;
622 #define NSF_LISTENING (1 << 0) 623 #define NSF_UDP (1 << 1) 624 #define NSF_RESOLVING (1 << 2) 625 #define NSF_CONNECTING (1 << 3) 626 #define NSF_SSL_HANDSHAKE_DONE (1 << 4) 627 #define NSF_WANT_READ (1 << 5) 628 #define NSF_WANT_WRITE (1 << 6) 629 #define NSF_IS_WEBSOCKET (1 << 7) 632 #define NSF_SEND_AND_CLOSE (1 << 10) 633 #define NSF_DONT_SEND (1 << 11) 634 #define NSF_CLOSE_IMMEDIATELY (1 << 12) 635 #define NSF_WEBSOCKET_NO_DEFRAG (1 << 13) 636 #define NSF_DELETE_CHUNK (1 << 14) 638 #define NSF_USER_1 (1 << 20) 639 #define NSF_USER_2 (1 << 21) 640 #define NSF_USER_3 (1 << 22) 641 #define NSF_USER_4 (1 << 23) 642 #define NSF_USER_5 (1 << 24) 643 #define NSF_USER_6 (1 << 25) 654 void ns_mgr_init(
struct ns_mgr *mgr,
void *user_data);
661 void ns_mgr_free(
struct ns_mgr *);
671 time_t ns_mgr_poll(
struct ns_mgr *,
int milli);
685 void ns_broadcast(
struct ns_mgr *, ns_event_handler_t func,
void *,
size_t);
711 const char **error_string;
740 const char **error_string;
774 const char **error_string;
849 const char *ns_set_ssl(
struct ns_connection *nc,
const char *cert,
850 const char *ca_cert);
861 int ns_send(
struct ns_connection *,
const void *buf,
int len);
871 int ns_vprintf(
struct ns_connection *,
const char *fmt, va_list ap);
878 int ns_socketpair(sock_t[2],
int sock_type);
890 int ns_resolve(
const char *domain_name,
char *ip_addr_buf,
size_t buf_len);
912 int ns_check_ip_acl(
const char *acl, uint32_t remote_ip);
928 #ifndef NS_UTIL_HEADER_DEFINED 929 #define NS_UTIL_HEADER_DEFINED 938 #ifndef MAX_PATH_SIZE 939 #define MAX_PATH_SIZE 500 951 const char *ns_skip(
const char *s,
const char *end_string,
952 const char *delimiters,
struct ns_str *v);
957 int ns_ncasecmp(
const char *s1,
const char *s2,
size_t len);
962 int ns_casecmp(
const char *s1,
const char *s2);
968 int ns_vcmp(
const struct ns_str *str2,
const char *str1);
974 int ns_vcasecmp(
const struct ns_str *str2,
const char *str1);
985 int ns_base64_decode(
const unsigned char *s,
int len,
char *dst);
992 void ns_base64_encode(
const unsigned char *src,
int src_len,
char *dst);
994 #ifndef NS_DISABLE_FILESYSTEM 1002 int ns_stat(
const char *path, ns_stat_t *st);
1011 FILE *ns_fopen(
const char *path,
const char *mode);
1020 int ns_open(
const char *path,
int flag,
int mode);
1023 #ifdef NS_ENABLE_THREADS 1030 void *ns_start_thread(
void *(*thread_func)(
void *),
void *thread_func_param);
1033 void ns_set_close_on_exec(sock_t);
1035 #define NS_SOCK_STRINGIFY_IP 1 1036 #define NS_SOCK_STRINGIFY_PORT 2 1037 #define NS_SOCK_STRINGIFY_REMOTE 4 1051 void ns_sock_to_str(sock_t sock,
char *buf,
size_t len,
int flags);
1058 void ns_sock_addr_to_str(
const union socket_address *sa,
char *buf,
size_t len,
1069 int ns_hexdump(
const void *buf,
int len,
char *dst,
int dst_len);
1078 void ns_hexdump_connection(
struct ns_connection *nc,
const char *path,
1079 int num_bytes,
int ev);
1095 int ns_avprintf(
char **buf,
size_t size,
const char *fmt, va_list ap);
1100 int ns_is_big_endian(
void);
1115 const char *ns_next_comma_list_entry(
const char *list,
struct ns_str *val,
1122 int ns_match_prefix(
const char *pattern,
int pattern_len,
const char *str);
1137 #ifndef NS_HTTP_HEADER_DEFINED 1138 #define NS_HTTP_HEADER_DEFINED 1145 #ifndef NS_MAX_HTTP_HEADERS 1146 #define NS_MAX_HTTP_HEADERS 40 1149 #ifndef NS_MAX_HTTP_REQUEST_SIZE 1150 #define NS_MAX_HTTP_REQUEST_SIZE 8192 1154 #define NS_MAX_PATH 1024 1157 #ifndef NS_MAX_HTTP_SEND_IOBUF 1158 #define NS_MAX_HTTP_SEND_IOBUF 4096 1161 #ifndef NS_WEBSOCKET_PING_INTERVAL_SECONDS 1162 #define NS_WEBSOCKET_PING_INTERVAL_SECONDS 5 1165 #ifndef NS_CGI_ENVIRONMENT_SIZE 1166 #define NS_CGI_ENVIRONMENT_SIZE 8192 1169 #ifndef NS_MAX_CGI_ENVIR_VARS 1170 #define NS_MAX_CGI_ENVIR_VARS 64 1173 #ifndef NS_ENV_EXPORT_TO_CGI 1174 #define NS_ENV_EXPORT_TO_CGI "FOSSA_CGI" 1187 struct ns_str resp_status_msg;
1197 struct ns_str query_string;
1200 struct ns_str header_names[NS_MAX_HTTP_HEADERS];
1201 struct ns_str header_values[NS_MAX_HTTP_HEADERS];
1208 unsigned char *data;
1210 unsigned char flags;
1214 #define NS_HTTP_REQUEST 100 1215 #define NS_HTTP_REPLY 101 1216 #define NS_HTTP_CHUNK 102 1217 #define NS_SSI_CALL 105 1219 #define NS_WEBSOCKET_HANDSHAKE_REQUEST 111 1220 #define NS_WEBSOCKET_HANDSHAKE_DONE 112 1221 #define NS_WEBSOCKET_FRAME 113 1222 #define NS_WEBSOCKET_CONTROL_FRAME 114 1250 void ns_set_protocol_http_websocket(
struct ns_connection *nc);
1260 void ns_send_websocket_handshake(
struct ns_connection *nc,
const char *uri,
1261 const char *extra_headers);
1276 void ns_send_websocket_frame(
struct ns_connection *nc,
int op,
const void *data,
1284 void ns_send_websocket_framev(
struct ns_connection *nc,
int op,
1285 const struct ns_str *strings,
int num_strings);
1293 void ns_printf_websocket_frame(
struct ns_connection *nc,
int op,
1294 const char *fmt, ...);
1314 void ns_send_http_chunk(
struct ns_connection *nc,
const char *buf,
size_t len);
1320 void ns_printf_http_chunk(
struct ns_connection *,
const char *, ...);
1325 void ns_printf_html_escape(
struct ns_connection *,
const char *, ...);
1328 #define WEBSOCKET_OP_CONTINUE 0 1329 #define WEBSOCKET_OP_TEXT 1 1330 #define WEBSOCKET_OP_BINARY 2 1331 #define WEBSOCKET_OP_CLOSE 8 1332 #define WEBSOCKET_OP_PING 9 1333 #define WEBSOCKET_OP_PONG 10 1343 int ns_parse_http(
const char *s,
int n,
struct http_message *hm,
int is_req);
1368 int ns_http_parse_header(
struct ns_str *hdr,
const char *var_name,
char *buf,
1406 size_t ns_parse_multipart(
const char *buf,
size_t buf_len,
char *var_name,
1407 size_t var_name_len,
char *file_name,
1408 size_t file_name_len,
const char **chunk,
1419 int ns_get_http_var(
const struct ns_str *,
const char *,
char *dst,
size_t);
1422 int ns_http_create_digest_auth_header(
char *buf,
size_t buf_len,
1423 const char *method,
const char *uri,
1424 const char *auth_domain,
const char *user,
1425 const char *passwd);
1446 ns_event_handler_t event_handler,
1448 const char *extra_headers,
1449 const char *post_data);
1457 const char *document_root;
1460 const char *index_files;
1471 const char *per_directory_auth_file;
1474 const char *auth_domain;
1484 const char *global_auth_file;
1487 const char *enable_directory_listing;
1490 const char *ssi_pattern;
1510 const char *url_rewrites;
1513 const char *dav_document_root;
1516 const char *hidden_file_pattern;
1519 const char *cgi_file_pattern;
1522 const char *cgi_interpreter;
1528 const char *custom_mime_types;
1569 #ifndef NS_JSON_RPC_HEADER_DEFINED 1570 #define NS_JSON_RPC_HEADER_DEFINED 1615 int ns_rpc_parse_reply(
const char *buf,
int len,
struct json_token *toks,
1627 int ns_rpc_create_request(
char *buf,
int len,
const char *method,
1628 const char *
id,
const char *params_fmt, ...);
1638 int ns_rpc_create_reply(
char *buf,
int len,
const struct ns_rpc_request *req,
1639 const char *result_fmt, ...);
1649 int ns_rpc_create_error(
char *buf,
int len,
struct ns_rpc_request *req,
1650 int code,
const char *message,
const char *fmt, ...);
1653 #define JSON_RPC_PARSE_ERROR (-32700) 1654 #define JSON_RPC_INVALID_REQUEST_ERROR (-32600) 1655 #define JSON_RPC_METHOD_NOT_FOUND_ERROR (-32601) 1656 #define JSON_RPC_INVALID_PARAMS_ERROR (-32602) 1657 #define JSON_RPC_INTERNAL_ERROR (-32603) 1658 #define JSON_RPC_SERVER_ERROR (-32000) 1674 int ns_rpc_create_std_error(
char *,
int,
struct ns_rpc_request *,
int code);
1676 typedef int (*ns_rpc_handler_t)(
char *buf,
int len,
struct ns_rpc_request *);
1690 int ns_rpc_dispatch(
const char *buf,
int,
char *dst,
int dst_len,
1691 const char **methods, ns_rpc_handler_t *handlers);
1718 #ifndef NS_MQTT_HEADER_INCLUDED 1719 #define NS_MQTT_HEADER_INCLUDED 1726 uint8_t connack_ret_code;
1727 uint16_t message_id;
1737 unsigned char flags;
1738 uint16_t keep_alive;
1739 const char *will_topic;
1740 const char *will_message;
1741 const char *user_name;
1742 const char *password;
1746 #define NS_MQTT_CMD_CONNECT 1 1747 #define NS_MQTT_CMD_CONNACK 2 1748 #define NS_MQTT_CMD_PUBLISH 3 1749 #define NS_MQTT_CMD_PUBACK 4 1750 #define NS_MQTT_CMD_PUBREC 5 1751 #define NS_MQTT_CMD_PUBREL 6 1752 #define NS_MQTT_CMD_PUBCOMP 7 1753 #define NS_MQTT_CMD_SUBSCRIBE 8 1754 #define NS_MQTT_CMD_SUBACK 9 1755 #define NS_MQTT_CMD_UNSUBSCRIBE 10 1756 #define NS_MQTT_CMD_UNSUBACK 11 1757 #define NS_MQTT_CMD_PINGREQ 12 1758 #define NS_MQTT_CMD_PINGRESP 13 1759 #define NS_MQTT_CMD_DISCONNECT 14 1762 #define NS_MQTT_EVENT_BASE 200 1763 #define NS_MQTT_CONNECT (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_CONNECT) 1764 #define NS_MQTT_CONNACK (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_CONNACK) 1765 #define NS_MQTT_PUBLISH (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_PUBLISH) 1766 #define NS_MQTT_PUBACK (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_PUBACK) 1767 #define NS_MQTT_PUBREC (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_PUBREC) 1768 #define NS_MQTT_PUBREL (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_PUBREL) 1769 #define NS_MQTT_PUBCOMP (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_PUBCOMP) 1770 #define NS_MQTT_SUBSCRIBE (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_SUBSCRIBE) 1771 #define NS_MQTT_SUBACK (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_SUBACK) 1772 #define NS_MQTT_UNSUBSCRIBE (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_UNSUBSCRIBE) 1773 #define NS_MQTT_UNSUBACK (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_UNSUBACK) 1774 #define NS_MQTT_PINGREQ (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_PINGREQ) 1775 #define NS_MQTT_PINGRESP (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_PINGRESP) 1776 #define NS_MQTT_DISCONNECT (NS_MQTT_EVENT_BASE + NS_MQTT_CMD_DISCONNECT) 1779 #define NS_MQTT_RETAIN 0x1 1780 #define NS_MQTT_DUP 0x4 1781 #define NS_MQTT_QOS(qos) ((qos) << 1) 1782 #define NS_MQTT_GET_QOS(flags) (((flags) &0x6) >> 1) 1783 #define NS_MQTT_SET_QOS(flags, qos) (flags) = ((flags) & ~0x6) | ((qos) << 1) 1786 #define NS_MQTT_CLEAN_SESSION 0x02 1787 #define NS_MQTT_HAS_WILL 0x04 1788 #define NS_MQTT_WILL_RETAIN 0x20 1789 #define NS_MQTT_HAS_PASSWORD 0x40 1790 #define NS_MQTT_HAS_USER_NAME 0x80 1791 #define NS_MQTT_GET_WILL_QOS(flags) (((flags) &0x18) >> 3) 1792 #define NS_MQTT_SET_WILL_QOS(flags, qos) \ 1793 (flags) = ((flags) & ~0x18) | ((qos) << 3) 1796 #define NS_MQTT_CONNACK_ACCEPTED 0 1797 #define NS_MQTT_CONNACK_UNACCEPTABLE_VERSION 1 1798 #define NS_MQTT_CONNACK_IDENTIFIER_REJECTED 2 1799 #define NS_MQTT_CONNACK_SERVER_UNAVAILABLE 3 1800 #define NS_MQTT_CONNACK_BAD_AUTH 4 1801 #define NS_MQTT_CONNACK_NOT_AUTHORIZED 5 1823 void ns_send_mqtt_handshake(
struct ns_connection *nc,
const char *client_id);
1826 void ns_send_mqtt_handshake_opt(
struct ns_connection *,
const char *client_id,
1830 void ns_mqtt_publish(
struct ns_connection *nc,
const char *topic,
1831 uint16_t message_id,
int flags,
const void *data,
1837 size_t topics_len, uint16_t message_id);
1840 void ns_mqtt_unsubscribe(
struct ns_connection *nc,
char **topics,
1841 size_t topics_len, uint16_t message_id);
1865 void ns_mqtt_suback(
struct ns_connection *, uint8_t *,
size_t, uint16_t);
1912 #ifndef NS_MQTT_BROKER_HEADER_INCLUDED 1913 #define NS_MQTT_BROKER_HEADER_INCLUDED 1915 #ifdef NS_ENABLE_MQTT_BROKER 1922 #define NS_MQTT_MAX_SESSION_SUBSCRIPTIONS 512; 1924 struct ns_mqtt_broker;
1927 struct ns_mqtt_session {
1928 struct ns_mqtt_broker *brk;
1929 struct ns_mqtt_session *next, *prev;
1931 size_t num_subscriptions;
1937 struct ns_mqtt_broker {
1938 struct ns_mqtt_session *sessions;
1943 void ns_mqtt_broker_init(
struct ns_mqtt_broker *,
void *);
1981 struct ns_mqtt_session *ns_mqtt_next(
struct ns_mqtt_broker *,
1982 struct ns_mqtt_session *);
1999 #ifndef NS_DNS_HEADER_DEFINED 2000 #define NS_DNS_HEADER_DEFINED 2007 #define NS_DNS_A_RECORD 0x01 2008 #define NS_DNS_CNAME_RECORD 0x05 2009 #define NS_DNS_AAAA_RECORD 0x1c 2010 #define NS_DNS_MX_RECORD 0x0f 2012 #define NS_MAX_DNS_QUESTIONS 32 2013 #define NS_MAX_DNS_ANSWERS 32 2015 #define NS_DNS_MESSAGE 100 2017 enum ns_dns_resource_record_kind {
2018 NS_DNS_INVALID_RECORD = 0,
2029 enum ns_dns_resource_record_kind kind;
2037 uint16_t transaction_id;
2064 void ns_send_dns_query(
struct ns_connection *,
const char *,
int);
2100 const char *,
size_t,
const void *,
size_t);
2150 #ifndef NS_DNS_SERVER_HEADER_DEFINED 2151 #define NS_DNS_SERVER_HEADER_DEFINED 2153 #ifdef NS_ENABLE_DNS_SERVER 2160 #define NS_DNS_SERVER_DEFAULT_TTL 3600 2162 struct ns_dns_reply {
2197 struct ns_dns_reply ns_dns_create_reply(struct mbuf *,
struct ns_dns_message *);
2208 const char *,
int,
int,
const void *,
size_t);
2222 int ns_dns_send_reply(
struct ns_connection *,
struct ns_dns_reply *);
2239 #ifndef NS_RESOLV_HEADER_DEFINED 2240 #define NS_RESOLV_HEADER_DEFINED 2247 typedef void (*ns_resolve_callback_t)(
struct ns_dns_message *,
void *);
2251 const char *nameserver_url;
2259 int ns_resolve_async(
struct ns_mgr *,
const char *,
int, ns_resolve_callback_t,
2283 int ns_resolve_async_opt(
struct ns_mgr *,
const char *,
int,
2284 ns_resolve_callback_t,
void *data,
2292 int ns_resolve_from_hosts_file(
const char *host,
union socket_address *usa);
2327 #ifndef NS_COAP_HEADER_INCLUDED 2328 #define NS_COAP_HEADER_INCLUDED 2330 #ifdef NS_ENABLE_COAP 2332 #define NS_COAP_MSG_TYPE_FIELD 0x2 2333 #define NS_COAP_CODE_CLASS_FIELD 0x4 2334 #define NS_COAP_CODE_DETAIL_FIELD 0x8 2335 #define NS_COAP_MSG_ID_FIELD 0x10 2336 #define NS_COAP_TOKEN_FIELD 0x20 2337 #define NS_COAP_OPTIONS_FIELD 0x40 2338 #define NS_COAP_PAYLOAD_FIELD 0x80 2340 #define NS_COAP_ERROR 0x10000 2341 #define NS_COAP_FORMAT_ERROR (NS_COAP_ERROR | 0x20000) 2342 #define NS_COAP_IGNORE (NS_COAP_ERROR | 0x40000) 2343 #define NS_COAP_NOT_ENOUGH_DATA (NS_COAP_ERROR | 0x80000) 2344 #define NS_COAP_NETWORK_ERROR (NS_COAP_ERROR | 0x100000) 2346 #define NS_COAP_MSG_CON 0 2347 #define NS_COAP_MSG_NOC 1 2348 #define NS_COAP_MSG_ACK 2 2349 #define NS_COAP_MSG_RST 3 2350 #define NS_COAP_MSG_MAX 3 2352 #define NS_COAP_CODECLASS_REQUEST 0 2353 #define NS_COAP_CODECLASS_RESP_OK 2 2354 #define NS_COAP_CODECLASS_CLIENT_ERR 4 2355 #define NS_COAP_CODECLASS_SRV_ERR 5 2357 #define NS_COAP_EVENT_BASE 300 2358 #define NS_COAP_CON (NS_COAP_EVENT_BASE + NS_COAP_MSG_CON) 2359 #define NS_COAP_NOC (NS_COAP_EVENT_BASE + NS_COAP_MSG_NOC) 2360 #define NS_COAP_ACK (NS_COAP_EVENT_BASE + NS_COAP_MSG_ACK) 2361 #define NS_COAP_RST (NS_COAP_EVENT_BASE + NS_COAP_MSG_RST) 2368 struct ns_coap_option {
2369 struct ns_coap_option *next;
2375 struct ns_coap_message {
2379 uint8_t code_detail;
2382 struct ns_coap_option *options;
2384 struct ns_coap_option *options_tail;
2398 struct ns_coap_option *ns_coap_add_option(
struct ns_coap_message *cm,
2399 uint32_t number,
char *value,
2406 void ns_coap_free_options(
struct ns_coap_message *cm);
2420 struct ns_coap_message *cm);
2427 uint32_t ns_coap_send_ack(
struct ns_connection *nc, uint16_t msg_id);
2444 uint32_t ns_coap_parse(
struct mbuf *io,
struct ns_coap_message *cm);
2451 uint32_t ns_coap_compose(
struct ns_coap_message *cm,
struct mbuf *io);