mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-28 09:01:24 +02:00
@@ -72,13 +72,14 @@ typedef enum {
|
||||
REST_PARAM_STRING
|
||||
} rest_param_type_t;
|
||||
|
||||
PACK(
|
||||
typedef struct {
|
||||
union {
|
||||
int32_t int_param;
|
||||
char *str_param;
|
||||
} param;
|
||||
rest_param_type_t type;
|
||||
} rest_param_t;
|
||||
}) rest_param_t;
|
||||
|
||||
typedef enum {
|
||||
REST_ROUTE_NONE = 0x0,
|
||||
@@ -110,6 +111,7 @@ typedef enum {
|
||||
REST_SESSION_TERMINATED = 0x6,
|
||||
} rest_session_status_t;
|
||||
|
||||
PACK(
|
||||
typedef struct {
|
||||
uint8_t public_key[32];
|
||||
uint8_t id[16];
|
||||
@@ -121,13 +123,14 @@ typedef struct {
|
||||
rest_session_status_t status;
|
||||
uint8_t token[32];
|
||||
uint8_t user_id;
|
||||
} rest_session_t;
|
||||
}) rest_session_t;
|
||||
|
||||
typedef struct {
|
||||
const char *key;
|
||||
const char *value;
|
||||
} rest_query_t;
|
||||
|
||||
PACK(
|
||||
typedef struct {
|
||||
rest_http_method_t method;
|
||||
char path[REST_MAX_PATH_SIZE];
|
||||
@@ -140,19 +143,23 @@ typedef struct {
|
||||
uint8_t query_count;
|
||||
rest_session_t *session;
|
||||
rest_request_conn_type_t conn_type;
|
||||
} rest_request_t;
|
||||
}) rest_request_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t status_code;
|
||||
const char *content_type;
|
||||
char *body; // heap !
|
||||
size_t body_len;
|
||||
cJSON *json;
|
||||
char *headers[REST_HEADER_TOTAL_COUNT];
|
||||
uint16_t status_code;
|
||||
#ifdef _MSC_VER
|
||||
char _padding[6];
|
||||
#endif
|
||||
} rest_response_t;
|
||||
|
||||
typedef int (*rest_route_handler_t)(const rest_request_t *request, rest_response_t *response);
|
||||
|
||||
PACK(
|
||||
typedef struct {
|
||||
rest_http_method_t method;
|
||||
const char *path;
|
||||
@@ -160,7 +167,7 @@ typedef struct {
|
||||
rest_route_flags_t flags;
|
||||
rest_route_param_parser_t param_parser;
|
||||
rest_session_role_t role; // Minimum required role to access this route (only relevant if REST_ROUTE_REQUIRE_AUTH flag is set)
|
||||
} rest_route_t;
|
||||
}) rest_route_t;
|
||||
|
||||
typedef struct {
|
||||
rest_route_handler_t handler;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#endif
|
||||
typedef SOCKET socket_t;
|
||||
typedef int socklen_t;
|
||||
typedef SSIZE_T ssize_t;
|
||||
#define close closesocket
|
||||
#include <string.h>
|
||||
#define strcasecmp _stricmp
|
||||
@@ -70,16 +71,20 @@ static pthread_t rest_thread;
|
||||
#endif
|
||||
static rest_conn_t conns[REST_MAX_CONNS];
|
||||
|
||||
PACK(
|
||||
typedef struct {
|
||||
volatile long pending;
|
||||
rest_conn_t *conn;
|
||||
rest_route_handler_t handler;
|
||||
rest_request_t request;
|
||||
} rest_core1_job_t;
|
||||
}) rest_core1_job_t;
|
||||
|
||||
typedef struct {
|
||||
bool ready;
|
||||
rest_response_t response;
|
||||
bool ready;
|
||||
#ifdef _MSC_VER
|
||||
char _padding[sizeof(void *) - sizeof(bool)];
|
||||
#endif
|
||||
} rest_core1_result_t;
|
||||
|
||||
static rest_core1_job_t rest_core1_job = {0};
|
||||
@@ -110,10 +115,11 @@ static void rest_core1_job_pending_store(bool pending) {
|
||||
#endif
|
||||
}
|
||||
|
||||
PACK(
|
||||
typedef struct {
|
||||
rest_header_id_t id;
|
||||
const char *name;
|
||||
} rest_header_descriptor_t;
|
||||
}) rest_header_descriptor_t;
|
||||
|
||||
static const rest_header_descriptor_t rest_http_headers[REST_HEADER_TOTAL_COUNT] = {
|
||||
{ REST_HEADER_USER_AGENT, "User-Agent" },
|
||||
|
||||
@@ -51,24 +51,31 @@ typedef enum {
|
||||
} rest_conn_type_t;
|
||||
|
||||
typedef struct {
|
||||
bool in_use;
|
||||
#ifdef ENABLE_EMULATION
|
||||
intptr_t sock;
|
||||
#else
|
||||
struct tcp_pcb *pcb;
|
||||
#endif
|
||||
char request[REST_MAX_REQUEST_SIZE + 1];
|
||||
size_t request_len;
|
||||
rest_conn_type_t conn_type;
|
||||
#ifdef _MSC_VER
|
||||
char _padding[sizeof(void *) - sizeof(rest_conn_type_t)];
|
||||
#endif
|
||||
mbedtls_ssl_context ssl;
|
||||
unsigned char rx_cipher[REST_MAX_REQUEST_SIZE];
|
||||
size_t rx_cipher_len;
|
||||
size_t request_headers_size;
|
||||
size_t request_content_length;
|
||||
bool in_use;
|
||||
bool handshake_done;
|
||||
bool request_complete;
|
||||
bool request_dispatched;
|
||||
bool request_headers_parsed;
|
||||
size_t request_headers_size;
|
||||
size_t request_content_length;
|
||||
char request[REST_MAX_REQUEST_SIZE + 1];
|
||||
#ifdef ENABLE_EMULATION
|
||||
char _padding2[2];
|
||||
#endif
|
||||
|
||||
} rest_conn_t;
|
||||
|
||||
err_t rest_server_init(rest_conn_type_t conn_type);
|
||||
|
||||
@@ -20,8 +20,10 @@
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <string.h>
|
||||
#include <BaseTsd.h>
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
typedef SSIZE_T ssize_t;
|
||||
#else
|
||||
#include <strings.h>
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user