mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-27 12:26:24 +00:00
Fix clang formatting
PUBLISHED_FROM=ea64670e42ae58bbe26abee5d928f2afcd83bd46
This commit is contained in:
1 parent
3a61186491
commit
39b0b8e2fd
9 files changed
+80
-68
No files matched your search
@@ -8,7 +8,8 @@
|
||||
#pragma comment(linker, "/nodefaultlib:libc.lib")
|
||||
#pragma comment(linker, "/nodefaultlib:libcd.lib")
|
||||
|
||||
// NOTE - this value is not strongly correlated to the Windows CE OS version being targeted
|
||||
// NOTE - this value is not strongly correlated to the Windows CE OS version
|
||||
// being targeted
|
||||
#define WINVER _WIN32_WCE
|
||||
|
||||
#include <ceconfig.h>
|
||||
@@ -23,9 +24,7 @@
|
||||
#include <windows.h>
|
||||
|
||||
#include <aygshell.h>
|
||||
#pragma comment(lib, "aygshell.lib")
|
||||
|
||||
|
||||
#pragma comment(lib, "aygshell.lib")
|
||||
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
@@ -40,15 +39,16 @@
|
||||
#include "DeviceResolutionAware.h"
|
||||
#endif
|
||||
|
||||
#if _WIN32_WCE < 0x500 && ( defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP) )
|
||||
#pragma comment(lib, "ccrtrtti.lib")
|
||||
#ifdef _X86_
|
||||
#if defined(_DEBUG)
|
||||
#pragma comment(lib, "libcmtx86d.lib")
|
||||
#else
|
||||
#pragma comment(lib, "libcmtx86.lib")
|
||||
#endif
|
||||
#endif
|
||||
#if _WIN32_WCE < 0x500 && \
|
||||
(defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP))
|
||||
#pragma comment(lib, "ccrtrtti.lib")
|
||||
#ifdef _X86_
|
||||
#if defined(_DEBUG)
|
||||
#pragma comment(lib, "libcmtx86d.lib")
|
||||
#else
|
||||
#pragma comment(lib, "libcmtx86.lib")
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <altcecrt.h>
|
||||
|
||||
@@ -8,10 +8,11 @@
|
||||
|
||||
void *db_open(const char *db_path) {
|
||||
sqlite3 *db = NULL;
|
||||
if (sqlite3_open_v2(db_path, &db, SQLITE_OPEN_READWRITE |
|
||||
SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK) {
|
||||
sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS kv(key PRIMARY KEY, val);",
|
||||
0, 0, 0);
|
||||
if (sqlite3_open_v2(db_path, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
|
||||
SQLITE_OPEN_FULLMUTEX,
|
||||
NULL) == SQLITE_OK) {
|
||||
sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS kv(key PRIMARY KEY, val);", 0,
|
||||
0, 0);
|
||||
}
|
||||
return db;
|
||||
}
|
||||
@@ -27,12 +28,12 @@ static void op_set(struct mg_connection *nc, const struct http_message *hm,
|
||||
const struct mg_str *key, void *db) {
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
char value[200];
|
||||
const struct mg_str *body = hm->query_string.len > 0 ?
|
||||
&hm->query_string : &hm->body;
|
||||
const struct mg_str *body =
|
||||
hm->query_string.len > 0 ? &hm->query_string : &hm->body;
|
||||
|
||||
mg_get_http_var(body, "value", value, sizeof(value));
|
||||
if (sqlite3_prepare_v2(db, "INSERT OR REPLACE INTO kv VALUES (?, ?);",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_prepare_v2(db, "INSERT OR REPLACE INTO kv VALUES (?, ?);", -1,
|
||||
&stmt, NULL) == SQLITE_OK) {
|
||||
sqlite3_bind_text(stmt, 1, key->p, key->len, SQLITE_STATIC);
|
||||
sqlite3_bind_text(stmt, 2, value, strlen(value), SQLITE_STATIC);
|
||||
sqlite3_step(stmt);
|
||||
@@ -48,23 +49,26 @@ static void op_get(struct mg_connection *nc, const struct http_message *hm,
|
||||
int result;
|
||||
(void) hm;
|
||||
|
||||
if (sqlite3_prepare_v2(db, "SELECT val FROM kv WHERE key = ?;",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_prepare_v2(db, "SELECT val FROM kv WHERE key = ?;", -1, &stmt,
|
||||
NULL) == SQLITE_OK) {
|
||||
sqlite3_bind_text(stmt, 1, key->p, key->len, SQLITE_STATIC);
|
||||
result = sqlite3_step(stmt);
|
||||
data = (char *) sqlite3_column_text(stmt, 0);
|
||||
if ((result == SQLITE_OK || result == SQLITE_ROW) && data != NULL) {
|
||||
mg_printf(nc, "HTTP/1.1 200 OK\r\n"
|
||||
mg_printf(nc,
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Content-Length: %d\r\n\r\n%s",
|
||||
(int) strlen(data), data);
|
||||
} else {
|
||||
mg_printf(nc, "%s", "HTTP/1.1 404 Not Found\r\n"
|
||||
mg_printf(nc, "%s",
|
||||
"HTTP/1.1 404 Not Found\r\n"
|
||||
"Content-Length: 0\r\n\r\n");
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
} else {
|
||||
mg_printf(nc, "%s", "HTTP/1.1 500 Server Error\r\n"
|
||||
mg_printf(nc, "%s",
|
||||
"HTTP/1.1 500 Server Error\r\n"
|
||||
"Content-Length: 0\r\n\r\n");
|
||||
}
|
||||
}
|
||||
@@ -75,19 +79,21 @@ static void op_del(struct mg_connection *nc, const struct http_message *hm,
|
||||
int result;
|
||||
(void) hm;
|
||||
|
||||
if (sqlite3_prepare_v2(db, "DELETE FROM kv WHERE key = ?;",
|
||||
-1, &stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_prepare_v2(db, "DELETE FROM kv WHERE key = ?;", -1, &stmt,
|
||||
NULL) == SQLITE_OK) {
|
||||
sqlite3_bind_text(stmt, 1, key->p, key->len, SQLITE_STATIC);
|
||||
result = sqlite3_step(stmt);
|
||||
if (result == SQLITE_OK || result == SQLITE_ROW) {
|
||||
mg_printf(nc, "%s", "HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
|
||||
} else {
|
||||
mg_printf(nc, "%s", "HTTP/1.1 404 Not Found\r\n"
|
||||
mg_printf(nc, "%s",
|
||||
"HTTP/1.1 404 Not Found\r\n"
|
||||
"Content-Length: 0\r\n\r\n");
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
} else {
|
||||
mg_printf(nc, "%s", "HTTP/1.1 500 Server Error\r\n"
|
||||
mg_printf(nc, "%s",
|
||||
"HTTP/1.1 500 Server Error\r\n"
|
||||
"Content-Length: 0\r\n\r\n");
|
||||
}
|
||||
}
|
||||
@@ -95,13 +101,19 @@ static void op_del(struct mg_connection *nc, const struct http_message *hm,
|
||||
void db_op(struct mg_connection *nc, const struct http_message *hm,
|
||||
const struct mg_str *key, void *db, int op) {
|
||||
switch (op) {
|
||||
case API_OP_GET: op_get(nc, hm, key, db); break;
|
||||
case API_OP_SET: op_set(nc, hm, key, db); break;
|
||||
case API_OP_DEL: op_del(nc, hm, key, db); break;
|
||||
case API_OP_GET:
|
||||
op_get(nc, hm, key, db);
|
||||
break;
|
||||
case API_OP_SET:
|
||||
op_set(nc, hm, key, db);
|
||||
break;
|
||||
case API_OP_DEL:
|
||||
op_del(nc, hm, key, db);
|
||||
break;
|
||||
default:
|
||||
mg_printf(nc, "%s", "HTTP/1.0 501 Not Implemented\r\n"
|
||||
mg_printf(nc, "%s",
|
||||
"HTTP/1.0 501 Not Implemented\r\n"
|
||||
"Content-Length: 0\r\n\r\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
s_exit_flag = 1;
|
||||
break;
|
||||
case MG_EV_CLOSE:
|
||||
if(s_exit_flag == 0) {
|
||||
if (s_exit_flag == 0) {
|
||||
printf("Server closed connection\n");
|
||||
s_exit_flag = 1;
|
||||
}
|
||||
|
||||
@@ -65,8 +65,8 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
|
||||
mg_hexdump(nc->recv_mbuf.buf, msg->payload.len, hex, sizeof(hex));
|
||||
printf("Got incoming message %.*s:\n%s", (int)msg->topic.len, msg->topic.p, hex);
|
||||
#else
|
||||
printf("Got incoming message %.*s: %.*s\n", (int)msg->topic.len,
|
||||
msg->topic.p, (int) msg->payload.len, msg->payload.p);
|
||||
printf("Got incoming message %.*s: %.*s\n", (int) msg->topic.len,
|
||||
msg->topic.p, (int) msg->payload.len, msg->payload.p);
|
||||
#endif
|
||||
|
||||
printf("Forwarding to /test\n");
|
||||
|
||||
@@ -5,4 +5,3 @@
|
||||
|
||||
void bleconfig_init(void);
|
||||
void bleconfig_poll(void);
|
||||
|
||||
@@ -10,12 +10,12 @@
|
||||
|
||||
/*
|
||||
* This is a callback invoked by Mongoose to signal that a poll is needed soon.
|
||||
* Since we're in a tight polling loop anyway (see below), we don't need to do anything.
|
||||
* Since we're in a tight polling loop anyway (see below), we don't need to do
|
||||
* anything.
|
||||
*/
|
||||
void mg_lwip_mgr_schedule_poll(struct mg_mgr *mgr) {
|
||||
}
|
||||
|
||||
|
||||
// Define an event handler function
|
||||
void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_POLL) return;
|
||||
@@ -53,13 +53,10 @@ void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for application main entry.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
|
||||
int main(void) {
|
||||
cs_log_set_file(stdout);
|
||||
|
||||
bleconfig_init();
|
||||
@@ -76,7 +73,9 @@ int main(void)
|
||||
struct mg_connection *nc = NULL;
|
||||
memset(&opts, 0x00, sizeof(opts));
|
||||
opts.error_string = &err;
|
||||
nc = mg_bind_opt(&mgr, "80", ev_handler, opts); // Create listening connection and add it to the event manager
|
||||
nc = mg_bind_opt(
|
||||
&mgr, "80", ev_handler,
|
||||
opts); // Create listening connection and add it to the event manager
|
||||
if (nc == NULL) {
|
||||
printf("Failed to create listener: %s\n", err);
|
||||
return 1;
|
||||
@@ -88,5 +87,4 @@ int main(void)
|
||||
mg_mgr_poll(&mgr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,12 +10,12 @@
|
||||
|
||||
/*
|
||||
* This is a callback invoked by Mongoose to signal that a poll is needed soon.
|
||||
* Since we're in a tight polling loop anyway (see below), we don't need to do anything.
|
||||
* Since we're in a tight polling loop anyway (see below), we don't need to do
|
||||
* anything.
|
||||
*/
|
||||
void mg_lwip_mgr_schedule_poll(struct mg_mgr *mgr) {
|
||||
}
|
||||
|
||||
|
||||
// Define an event handler function
|
||||
void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_POLL) return;
|
||||
@@ -53,13 +53,10 @@ void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function for application main entry.
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
|
||||
int main(void) {
|
||||
cs_log_set_file(stdout);
|
||||
|
||||
bleconfig_init();
|
||||
@@ -76,7 +73,9 @@ int main(void)
|
||||
struct mg_connection *nc = NULL;
|
||||
memset(&opts, 0x00, sizeof(opts));
|
||||
opts.error_string = &err;
|
||||
nc = mg_bind_opt(&mgr, "80", ev_handler, opts); // Create listening connection and add it to the event manager
|
||||
nc = mg_bind_opt(
|
||||
&mgr, "80", ev_handler,
|
||||
opts); // Create listening connection and add it to the event manager
|
||||
if (nc == NULL) {
|
||||
printf("Failed to create listener: %s\n", err);
|
||||
return 1;
|
||||
@@ -91,5 +90,4 @@ int main(void)
|
||||
mg_mgr_free(&mgr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user