added web and fix some problems
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 9s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 14s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Failing after 8s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Successful in 9s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Successful in 14s
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Failing after 8s
This commit is contained in:
1 parent
ccfc8b535e
commit
155c259ea9
29 files changed
+946
-119
No files matched your search
+61
-14
@@ -6,26 +6,72 @@ void change_password(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
request_with_token *requestdata = check_body(hm);
|
||||
const bool valid = jwt_verifyJWT(requestdata->token, JWT_DEFAULT_SECRET);
|
||||
if (!valid) {
|
||||
mg_http_reply(c, 403, "Content-Type: application/json\r\n", "{%m:%m}", MG_ESC("error"),
|
||||
MG_ESC("invalid token"));
|
||||
mg_http_reply(c, 403, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"), MG_ESC("invalid token"));
|
||||
return;
|
||||
}
|
||||
cJSON *jsonbody = cJSON_Parse(hm->body.buf);
|
||||
cJSON *old_password = cJSON_GetObjectItem(jsonbody, "old_password");
|
||||
cJSON *new_password = cJSON_GetObjectItem(jsonbody, "new_password");
|
||||
if (old_password == nullptr || new_password == nullptr) {
|
||||
mg_http_reply(c, 400, "Content-Type: application/json\r\n", "{%m:%m}", MG_ESC("error"),
|
||||
cJSON *userid = cJSON_GetObjectItem(jsonbody, "userid");
|
||||
if ((old_password == nullptr || new_password == nullptr) &&
|
||||
userid == nullptr) {
|
||||
mg_http_reply(c, 400, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"),
|
||||
MG_ESC("must have <old_password>, <new_password>"));
|
||||
return;
|
||||
}
|
||||
cJSON *payload = jwt_get_payload(requestdata->token);
|
||||
char *username = cJSON_GetObjectItem(payload, "username")->valuestring;
|
||||
User *old_user_data = db_get_user_by_username(username);
|
||||
char *password = old_user_data->password;
|
||||
|
||||
if (strcmp(password, old_password->valuestring)) {
|
||||
mg_http_reply(c, 400, "Content-Type: application/json\r\n", "{%m:%m}", MG_ESC("error"),
|
||||
MG_ESC("invalid old password"));
|
||||
if (!userid) {
|
||||
char *username = cJSON_GetObjectItem(payload, "username")->valuestring;
|
||||
User *old_user_data = db_get_user_by_username(username);
|
||||
if (!old_user_data) {
|
||||
mg_http_reply(c, 500, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"),
|
||||
MG_ESC("failed to update user can't get old_user_data"));
|
||||
cJSON_Delete(payload);
|
||||
}
|
||||
char *password = old_user_data->password;
|
||||
|
||||
if (strcmp(password, old_password->valuestring)) {
|
||||
mg_http_reply(c, 400, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"), MG_ESC("invalid old password"));
|
||||
return;
|
||||
}
|
||||
const bool old_is_superuser = old_user_data->is_superuser;
|
||||
User *new_user_data = db_update_user(
|
||||
old_user_data->id, old_user_data->username, old_user_data->email,
|
||||
new_password->valuestring, old_user_data->group, &old_is_superuser);
|
||||
if (!new_user_data) {
|
||||
mg_http_reply(c, 500, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"), MG_ESC("failed to update user can't update database"));
|
||||
free_user(old_user_data);
|
||||
cJSON_Delete(payload);
|
||||
return;
|
||||
}
|
||||
|
||||
char responsedata[64] = {0};
|
||||
snprintf(responsedata, sizeof(responsedata), "{\"success\": true}");
|
||||
|
||||
mg_http_reply(c, 200, "Content-Type: application/json\r\n", responsedata);
|
||||
free_user(old_user_data);
|
||||
cJSON_Delete(payload);
|
||||
return;
|
||||
}
|
||||
bool is_superuser = cJSON_GetObjectItem(payload, "is_superuser")->valueint;
|
||||
if (!is_superuser) {
|
||||
mg_http_reply(c, 403, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"), MG_ESC("user is not superuser"));
|
||||
cJSON_Delete(payload);
|
||||
return;
|
||||
}
|
||||
User *old_user_data = db_get_user_by_id(userid->valueint);
|
||||
if (!old_user_data) {
|
||||
mg_http_reply(c, 500, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"),
|
||||
MG_ESC("failed to update user can't get old_user_data"));
|
||||
cJSON_Delete(payload);
|
||||
return;
|
||||
}
|
||||
const bool old_is_superuser = old_user_data->is_superuser;
|
||||
@@ -33,16 +79,17 @@ void change_password(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
old_user_data->id, old_user_data->username, old_user_data->email,
|
||||
new_password->valuestring, old_user_data->group, &old_is_superuser);
|
||||
if (!new_user_data) {
|
||||
mg_http_reply(c, 500, "Content-Type: application/json\r\n", "{%m:%m}", MG_ESC("error"),
|
||||
MG_ESC("failed to update user"));
|
||||
mg_http_reply(c, 500, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"), MG_ESC("failed to update user can't create new_user_data from root"));
|
||||
free_user(old_user_data);
|
||||
cJSON_Delete(payload);
|
||||
return;
|
||||
}
|
||||
|
||||
char responsedata[64] = {0};
|
||||
snprintf(responsedata, sizeof(responsedata), "{\"success\": true}");
|
||||
|
||||
mg_http_reply(c, 200, "Content-Type: application/json\r\n", responsedata);
|
||||
// free(username);
|
||||
free_user(old_user_data);
|
||||
free_user(new_user_data);
|
||||
cJSON_Delete(payload);
|
||||
}
|
||||
+56
-17
@@ -6,8 +6,8 @@ void change_user(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
request_with_token *requestdata = check_body(hm);
|
||||
const bool valid = jwt_verifyJWT(requestdata->token, JWT_DEFAULT_SECRET);
|
||||
if (!valid) {
|
||||
mg_http_reply(c, 403, "Content-Type: application/json\r\n", "{%m:%m}", MG_ESC("error"),
|
||||
MG_ESC("invalid token"));
|
||||
mg_http_reply(c, 403, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"), MG_ESC("invalid token"));
|
||||
return;
|
||||
}
|
||||
cJSON *jsonbody = cJSON_Parse(hm->body.buf);
|
||||
@@ -15,21 +15,28 @@ void change_user(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
cJSON *email = cJSON_GetObjectItem(jsonbody, "email");
|
||||
cJSON *group = cJSON_GetObjectItem(jsonbody, "group");
|
||||
cJSON *is_superuser = cJSON_GetObjectItem(jsonbody, "is_superuser");
|
||||
User *old_user_data = db_get_user_by_username(username->valuestring);
|
||||
cJSON *userid = cJSON_GetObjectItem(jsonbody, "userid");
|
||||
User *old_user_data = nullptr;
|
||||
if (!userid) {
|
||||
old_user_data = db_get_user_by_username(username->valuestring);
|
||||
} else {
|
||||
old_user_data = db_get_user_by_id(userid->valueint);
|
||||
}
|
||||
if (!old_user_data) {
|
||||
mg_http_reply(c, 404, "Content-Type: application/json\r\n", "{%m:%m}", MG_ESC("error"),
|
||||
MG_ESC("user not found"));
|
||||
mg_http_reply(c, 404, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"), MG_ESC("user not found"));
|
||||
return;
|
||||
}
|
||||
char *password = old_user_data->password;
|
||||
if (!password) {
|
||||
mg_http_reply(c, 400, "Content-Type: application/json\r\n", "{%m:%m}", MG_ESC("error"),
|
||||
MG_ESC("password is required"));
|
||||
mg_http_reply(c, 400, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"), MG_ESC("password is required"));
|
||||
return;
|
||||
}
|
||||
if (username == nullptr || email == nullptr ||
|
||||
is_superuser == nullptr || group == nullptr) {
|
||||
mg_http_reply(c, 400, "Content-Type: application/json\r\n", "{%m:%m}", MG_ESC("error"),
|
||||
if (username == nullptr || email == nullptr || is_superuser == nullptr ||
|
||||
group == nullptr) {
|
||||
mg_http_reply(c, 400, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"),
|
||||
MG_ESC("must have <username>, <email>, <group, "
|
||||
"optional>, <is_superuser, optional>"));
|
||||
free_user(old_user_data);
|
||||
@@ -39,16 +46,49 @@ void change_user(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
cJSON *payload = jwt_get_payload(requestdata->token);
|
||||
int id = cJSON_GetObjectItem(payload, "id")->valueint;
|
||||
const bool user_is_superuser = is_superuser->valueint ? true : false;
|
||||
User *updated_user_data = db_update_user(
|
||||
id, username->valuestring, email->valuestring, password,
|
||||
group->valuestring, &user_is_superuser);
|
||||
if (!userid) {
|
||||
User *updated_user_data =
|
||||
db_update_user(id, username->valuestring, email->valuestring, password,
|
||||
group->valuestring, &user_is_superuser);
|
||||
|
||||
if (!updated_user_data) {
|
||||
mg_http_reply(c, 500, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"), MG_ESC("failed to update user change user request"));
|
||||
cJSON_Delete(payload);
|
||||
free_user(old_user_data);
|
||||
return;
|
||||
}
|
||||
|
||||
char responsedata[2048] = {0};
|
||||
snprintf(responsedata, sizeof(responsedata),
|
||||
"{\"username\":\"%s\",\"email\":\"%s\",\"group\":\"%s\",\"is_"
|
||||
"superuser\":%s}",
|
||||
username->valuestring, email->valuestring, group->valuestring,
|
||||
is_superuser->valueint ? "true" : "false");
|
||||
|
||||
mg_http_reply(c, 200, "Content-Type: application/json\r\n", responsedata);
|
||||
free_user(updated_user_data);
|
||||
free_user(old_user_data);
|
||||
cJSON_Delete(payload);
|
||||
return;
|
||||
}
|
||||
bool req_is_superuser =
|
||||
cJSON_GetObjectItem(payload, "is_superuser")->valueint;
|
||||
if (!req_is_superuser) {
|
||||
mg_http_reply(c, 403, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"), MG_ESC("user is not superuser"));
|
||||
cJSON_Delete(payload);
|
||||
free_user(old_user_data);
|
||||
return;
|
||||
}
|
||||
User *updated_user_data = db_update_user(
|
||||
userid->valueint, username->valuestring, email->valuestring, password,
|
||||
group->valuestring, &user_is_superuser);
|
||||
if (!updated_user_data) {
|
||||
mg_http_reply(c, 500, "Content-Type: application/json\r\n", "{%m:%m}", MG_ESC("error"),
|
||||
MG_ESC("failed to update user"));
|
||||
mg_http_reply(c, 500, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"), MG_ESC("failed to update user can't change userdata"));
|
||||
cJSON_Delete(payload);
|
||||
free_user(old_user_data);
|
||||
free(password);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -63,5 +103,4 @@ void change_user(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
free_user(updated_user_data);
|
||||
free_user(old_user_data);
|
||||
cJSON_Delete(payload);
|
||||
//free(password);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "user.h"
|
||||
#include "database.h"
|
||||
#include "sql.h"
|
||||
|
||||
User *db_get_user_by_id(const int id) {
|
||||
User *user = nullptr;
|
||||
pthread_mutex_lock(&db_mutex);
|
||||
if (!db) {
|
||||
fprintf(stderr, "Database not initialized\n");
|
||||
pthread_mutex_unlock(&db_mutex);
|
||||
return nullptr;
|
||||
}
|
||||
sqlite3_stmt *stmt;
|
||||
int rc =
|
||||
sqlite3_prepare_v2(db, SELECT_USER_BY_ID_SQL, -1, &stmt, nullptr);
|
||||
if (rc != SQLITE_OK) {
|
||||
fprintf(stderr, "Cannot prepare statement: %s\n", sqlite3_errmsg(db));
|
||||
sqlite3_close(db);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
sqlite3_bind_int(stmt, 1, id);
|
||||
|
||||
while ((rc = sqlite3_step(stmt)) == SQLITE_ROW) {
|
||||
int id = sqlite3_column_int(stmt, 0);
|
||||
const unsigned char *db_username = sqlite3_column_text(stmt, 1);
|
||||
const unsigned char *db_email = sqlite3_column_text(stmt, 2);
|
||||
const unsigned char *db_password = sqlite3_column_text(stmt, 3);
|
||||
const unsigned char *db_group = sqlite3_column_text(stmt, 4);
|
||||
int db_is_superuser = sqlite3_column_int(stmt, 5);
|
||||
user = new_user(id, (char *) db_username, (char *) db_password,
|
||||
(char *) db_email, (char *) db_group, db_is_superuser);
|
||||
}
|
||||
|
||||
if (rc != SQLITE_DONE) {
|
||||
fprintf(stderr, "Error reading data: %s\n", sqlite3_errmsg(db));
|
||||
free_user(user);
|
||||
sqlite3_finalize(stmt);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&db_mutex);
|
||||
return user;
|
||||
}
|
||||
+20
-2
@@ -12,7 +12,6 @@ void delete_user(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
if (requestdata->error != NULL) {
|
||||
mg_http_reply(c, 403, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"), MG_ESC(requestdata->error));
|
||||
// free_request_with_token(requestdata);
|
||||
return;
|
||||
}
|
||||
const bool valid = jwt_verifyJWT(requestdata->token, JWT_DEFAULT_SECRET);
|
||||
@@ -24,7 +23,26 @@ void delete_user(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
}
|
||||
cJSON *payload = jwt_get_payload(requestdata->token);
|
||||
int id = cJSON_GetObjectItem(payload, "id")->valueint;
|
||||
bool user_deleted = db_delete_user(id);
|
||||
cJSON *useridfromjson = cJSON_GetObjectItem(requestdata->body, "userid");
|
||||
cJSON_Print(useridfromjson);
|
||||
if (useridfromjson == NULL) {
|
||||
bool user_deleted = db_delete_user(id);
|
||||
char responsedata[2048] = {0};
|
||||
snprintf(responsedata, sizeof(responsedata), "{\"success\": %s}",
|
||||
user_deleted ? "true" : "false");
|
||||
|
||||
mg_http_reply(c, 200, "Content-Type: application/json\r\n", responsedata);
|
||||
free_request_with_token(requestdata);
|
||||
cJSON_Delete(payload);
|
||||
return;
|
||||
}
|
||||
bool is_superuser = cJSON_GetObjectItem(payload, "is_superuser")->valueint;
|
||||
if (!is_superuser) {
|
||||
mg_http_reply(c, 403, "Content-Type: application/json\r\n", "{%m:%m}",
|
||||
MG_ESC("error"), MG_ESC("user is not superuser"));
|
||||
return;
|
||||
}
|
||||
bool user_deleted = db_delete_user(useridfromjson->valueint);
|
||||
char responsedata[2048] = {0};
|
||||
snprintf(responsedata, sizeof(responsedata), "{\"success\": %s}",
|
||||
user_deleted ? "true" : "false");
|
||||
|
||||
+78
-11
@@ -4739,7 +4739,7 @@ static size_t tx_tcp_pkt(struct mg_tcpip_if *ifp, struct pkt *pkt,
|
||||
}
|
||||
|
||||
static struct mg_connection *accept_conn(struct mg_connection *lsn,
|
||||
struct pkt *pkt) {
|
||||
struct pkt *pkt, uint16_t mss) {
|
||||
struct mg_connection *c = mg_alloc_conn(lsn->mgr);
|
||||
struct connstate *s;
|
||||
if (c == NULL) {
|
||||
@@ -4747,7 +4747,7 @@ static struct mg_connection *accept_conn(struct mg_connection *lsn,
|
||||
return NULL;
|
||||
}
|
||||
s = (struct connstate *) (c + 1);
|
||||
s->dmss = 536; // assume default, RFC-9293 3.7.1
|
||||
s->dmss = mss; // from options in client SYN
|
||||
s->seq = mg_ntohl(pkt->tcp->ack), s->ack = mg_ntohl(pkt->tcp->seq);
|
||||
memcpy(s->mac, pkt->eth->src, sizeof(s->mac));
|
||||
settmout(c, MIP_TTYPE_KEEPALIVE);
|
||||
@@ -4851,7 +4851,7 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
|
||||
if (pkt->tcp->flags & TH_FIN) {
|
||||
uint8_t flags = TH_ACK;
|
||||
if (mg_ntohl(pkt->tcp->seq) != s->ack) {
|
||||
MG_VERBOSE(("ignoring FIN, SEQ != ACK: %x %x", mg_ntohl(pkt->tcp->seq), s->ack));
|
||||
MG_VERBOSE(("ignoring FIN, %x != %x", mg_ntohl(pkt->tcp->seq), s->ack));
|
||||
tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_ACK, c->loc.port, c->rem.port,
|
||||
mg_htonl(s->seq), mg_htonl(s->ack), "", 0);
|
||||
return;
|
||||
@@ -4934,6 +4934,57 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TCP backlog
|
||||
struct mg_backlog {
|
||||
uint16_t port, mss; // use port=0 for available entries
|
||||
uint8_t age;
|
||||
};
|
||||
|
||||
static int backlog_insert(struct mg_connection *c, uint16_t port,
|
||||
uint16_t mss) {
|
||||
struct mg_backlog *p = (struct mg_backlog *) c->data;
|
||||
size_t i;
|
||||
for (i = 0; i < sizeof(c->data) / sizeof(*p); i++) {
|
||||
if (p[i].port != 0) continue;
|
||||
p[i].age = 2; // remove after two calls, average 1.5 call rate
|
||||
p[i].port = port, p[i].mss = mss;
|
||||
return (int) i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static struct mg_backlog *backlog_retrieve(struct mg_connection *c,
|
||||
uint16_t key, uint16_t port) {
|
||||
struct mg_backlog *p = (struct mg_backlog *) c->data;
|
||||
if (key >= sizeof(c->data) / sizeof(*p)) return NULL;
|
||||
if (p[key].port != port) return NULL;
|
||||
p += key;
|
||||
return p;
|
||||
}
|
||||
|
||||
static void backlog_remove(struct mg_connection *c, uint16_t key) {
|
||||
struct mg_backlog *p = (struct mg_backlog *) c->data;
|
||||
p[key].port = 0;
|
||||
}
|
||||
|
||||
static void backlog_maintain(struct mg_connection *c) {
|
||||
struct mg_backlog *p = (struct mg_backlog *) c->data;
|
||||
size_t i; // dec age and remove those where it reaches 0
|
||||
for (i = 0; i < sizeof(c->data) / sizeof(*p); i++) {
|
||||
if (p[i].port == 0) continue;
|
||||
if (p[i].age != 0) --p[i].age;
|
||||
if (p[i].age == 0) p[i].port = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void backlog_poll(struct mg_mgr *mgr) {
|
||||
struct mg_connection *c = NULL;
|
||||
for (c = mgr->conns; c != NULL; c = c->next) {
|
||||
if (!c->is_udp && c->is_listening) backlog_maintain(c);
|
||||
}
|
||||
}
|
||||
|
||||
// process options (MSS)
|
||||
static void handle_opt(struct connstate *s, struct tcp *tcp) {
|
||||
uint8_t *opts = (uint8_t *) (tcp + 1);
|
||||
@@ -4991,15 +5042,30 @@ static void rx_tcp(struct mg_tcpip_if *ifp, struct pkt *pkt) {
|
||||
if (c->is_accepted) mg_error(c, "peer RST"); // RFC-1122 4.2.2.13
|
||||
// ignore RST if not connected
|
||||
} else if (pkt->tcp->flags & TH_SYN) {
|
||||
// TODO(): handle_opt(s, pkt->tcp); // process options (MSS)
|
||||
// At this point, s = NULL, there is no connection.
|
||||
// Use peer's source port as ISN, in order to recognise the handshake
|
||||
uint32_t isn = mg_htonl((uint32_t) mg_ntohs(pkt->tcp->sport));
|
||||
tx_tcp_pkt(ifp, pkt, TH_SYN | TH_ACK, isn, NULL, 0);
|
||||
struct connstate cs; // At this point, s = NULL, there is no connection
|
||||
int key;
|
||||
uint32_t isn;
|
||||
if (pkt->tcp->sport != 0) {
|
||||
handle_opt(&cs, pkt->tcp); // process options (MSS)
|
||||
key = backlog_insert(c, pkt->tcp->sport, cs.dmss); // backlog options (MSS)
|
||||
if (key < 0) return; // no room in backlog, discard SYN, client retries
|
||||
// Use peer's src port and bl key as ISN, to later identify the handshake
|
||||
isn = (mg_htonl(((uint32_t)key << 16) | mg_ntohs(pkt->tcp->sport)));
|
||||
tx_tcp_pkt(ifp, pkt, TH_SYN | TH_ACK, isn, NULL, 0);
|
||||
} // what should we do when port=0 ? Linux takes port 0 as any other port
|
||||
} else if (pkt->tcp->flags & TH_FIN) {
|
||||
tx_tcp_pkt(ifp, pkt, TH_FIN | TH_ACK, pkt->tcp->ack, NULL, 0);
|
||||
} else if (mg_htonl(pkt->tcp->ack) == mg_htons(pkt->tcp->sport) + 1U) {
|
||||
accept_conn(c, pkt);
|
||||
} else if ((uint16_t) (mg_htonl(pkt->tcp->ack) - 1) ==
|
||||
mg_htons(pkt->tcp->sport)) {
|
||||
uint16_t key = (uint16_t) ((mg_htonl(pkt->tcp->ack) - 1) >> 16);
|
||||
struct mg_backlog *b = backlog_retrieve(c, key, pkt->tcp->sport);
|
||||
if (b != NULL) {
|
||||
accept_conn(c, pkt, b->mss); // pass options
|
||||
backlog_remove(c, key);
|
||||
} else if (!c->is_accepted) { // not an actual match, reset
|
||||
tx_tcp_pkt(ifp, pkt, TH_RST | TH_ACK, pkt->tcp->ack, NULL, 0);
|
||||
// TODO(scaprile): revisit this and below, weird scenarios
|
||||
}
|
||||
} else if (!c->is_accepted) { // no peer
|
||||
tx_tcp_pkt(ifp, pkt, TH_RST | TH_ACK, pkt->tcp->ack, NULL, 0);
|
||||
} else {
|
||||
@@ -5127,6 +5193,7 @@ static void mg_tcpip_poll(struct mg_tcpip_if *ifp, uint64_t now) {
|
||||
names[ifp->state], mg_print_ip4, &ifp->ip, ifp->nrecv, ifp->nsent,
|
||||
ifp->ndrop, ifp->nerr));
|
||||
#endif
|
||||
backlog_poll(ifp->mgr);
|
||||
}
|
||||
// Handle gw ARP request timeout, order is important
|
||||
if (expired_1000ms && ifp->state == MG_TCPIP_STATE_IP) {
|
||||
@@ -5460,7 +5527,7 @@ static void setdns4(struct mg_tcpip_if *ifp, uint32_t *ip) {
|
||||
MG_DEBUG(("Set DNS URL to %s", dnsc->url));
|
||||
if (ifp->mgr->use_dns6) return;
|
||||
if (dnsc->c != NULL) mg_close_conn(dnsc->c);
|
||||
if (!mg_dnsc_init(ifp->mgr, dnsc)) // create DNS connection
|
||||
if (!mg_dnsc_init(ifp->mgr, dnsc)) // create DNS connection
|
||||
MG_ERROR(("DNS connection creation failed"));
|
||||
}
|
||||
|
||||
|
||||
+36
-36
@@ -20,7 +20,7 @@
|
||||
#ifndef MONGOOSE_H
|
||||
#define MONGOOSE_H
|
||||
|
||||
#define MG_VERSION "7.18"
|
||||
#define MG_VERSION "7.19"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -3693,6 +3693,41 @@ struct mg_tcpip_driver_tms570_data {
|
||||
|
||||
|
||||
|
||||
#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_XMC7) && MG_ENABLE_DRIVER_XMC7
|
||||
|
||||
struct mg_tcpip_driver_xmc7_data {
|
||||
int mdc_cr; // Valid values: -1, 0, 1, 2, 3, 4, 5
|
||||
uint8_t phy_addr;
|
||||
};
|
||||
|
||||
#ifndef MG_TCPIP_PHY_ADDR
|
||||
#define MG_TCPIP_PHY_ADDR 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_DRIVER_MDC_CR
|
||||
#define MG_DRIVER_MDC_CR 3
|
||||
#endif
|
||||
|
||||
#define MG_TCPIP_DRIVER_INIT(mgr) \
|
||||
do { \
|
||||
static struct mg_tcpip_driver_xmc7_data driver_data_; \
|
||||
static struct mg_tcpip_if mif_; \
|
||||
driver_data_.mdc_cr = MG_DRIVER_MDC_CR; \
|
||||
driver_data_.phy_addr = MG_TCPIP_PHY_ADDR; \
|
||||
mif_.ip = MG_TCPIP_IP; \
|
||||
mif_.mask = MG_TCPIP_MASK; \
|
||||
mif_.gw = MG_TCPIP_GW; \
|
||||
mif_.driver = &mg_tcpip_driver_xmc7; \
|
||||
mif_.driver_data = &driver_data_; \
|
||||
MG_SET_MAC_ADDRESS(mif_.mac); \
|
||||
mg_tcpip_init(mgr, &mif_); \
|
||||
MG_INFO(("Driver: xmc7, MAC: %M", mg_print_mac, mif_.mac)); \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_XMC) && MG_ENABLE_DRIVER_XMC
|
||||
|
||||
struct mg_tcpip_driver_xmc_data {
|
||||
@@ -3739,41 +3774,6 @@ struct mg_tcpip_driver_xmc_data {
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_XMC7) && MG_ENABLE_DRIVER_XMC7
|
||||
|
||||
struct mg_tcpip_driver_xmc7_data {
|
||||
int mdc_cr; // Valid values: -1, 0, 1, 2, 3, 4, 5
|
||||
uint8_t phy_addr;
|
||||
};
|
||||
|
||||
#ifndef MG_TCPIP_PHY_ADDR
|
||||
#define MG_TCPIP_PHY_ADDR 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_DRIVER_MDC_CR
|
||||
#define MG_DRIVER_MDC_CR 3
|
||||
#endif
|
||||
|
||||
#define MG_TCPIP_DRIVER_INIT(mgr) \
|
||||
do { \
|
||||
static struct mg_tcpip_driver_xmc7_data driver_data_; \
|
||||
static struct mg_tcpip_if mif_; \
|
||||
driver_data_.mdc_cr = MG_DRIVER_MDC_CR; \
|
||||
driver_data_.phy_addr = MG_TCPIP_PHY_ADDR; \
|
||||
mif_.ip = MG_TCPIP_IP; \
|
||||
mif_.mask = MG_TCPIP_MASK; \
|
||||
mif_.gw = MG_TCPIP_GW; \
|
||||
mif_.driver = &mg_tcpip_driver_xmc7; \
|
||||
mif_.driver_data = &driver_data_; \
|
||||
MG_SET_MAC_ADDRESS(mif_.mac); \
|
||||
mg_tcpip_init(mgr, &mif_); \
|
||||
MG_INFO(("Driver: xmc7, MAC: %M", mg_print_mac, mif_.mac)); \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ static void root_handler(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
}
|
||||
|
||||
static const struct route routes[] = {
|
||||
{"GET", "/", root_handler},
|
||||
{"GET", "/#", root_handler},
|
||||
{"POST", "/api/token", get_token},
|
||||
{"POST", "/api/token/verify", verify_token},
|
||||
{"POST", "/api/users", get_all_users},
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#define SELECT_ALL_USERS_SQL "select * from users"
|
||||
#define SELECT_USER_BY_USERNAME_SQL "select * from users where username = ?"
|
||||
#define SELECT_USER_BY_ID_SQL "select * from users where id = ?"
|
||||
#define INSERT_USER_USERNAME_EMAIL_PASSWORD_SQL \
|
||||
"insert into users (username, email, password) values (?, ?, ?)"
|
||||
#define INSERT_USER_USERNAME_EMAIL_PASSWORD_GROUP_SQL \
|
||||
|
||||
@@ -62,3 +62,4 @@ User *db_update_user(const int userid, const char *username, const char *email,
|
||||
const char *password, const char *group,
|
||||
const bool *is_superuser);
|
||||
bool db_delete_user(const int id);
|
||||
User *db_get_user_by_id(const int id);
|
||||
+1
-1
@@ -14,5 +14,5 @@ void verify_token(struct mg_connection *c, struct mg_http_message *hm) {
|
||||
MG_ESC("invalid token"));
|
||||
return;
|
||||
}
|
||||
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "{%m:%m}", MG_ESC("valid"), MG_ESC("true"));
|
||||
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "{%m:true}", MG_ESC("valid"));
|
||||
}
|
||||
Reference in new issue
Block a user