Commit 183fc7ce authored by rojer's avatar rojer Committed by Cesanta Bot

clang-format *ALL* the things!

PUBLISHED_FROM=faf0beb7545eb426c941fc366b6f87667723eb4c
parent dcf1cede
/* clang-format off */
/*
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.
......
/* clang-format off */
/*
* Copyright (c) 2015-2016, Texas Instruments Incorporated
* All rights reserved.
......
/* clang-format off */
/*
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.
......
......@@ -37,7 +37,8 @@
#include "wifi.h"
static const char *upload_form = "\
static const char *upload_form =
"\
<h1>Upload file</h1> \
<form action='/upload' method='POST' enctype='multipart/form-data'> \
<input type='file' name='file'> \
......@@ -75,8 +76,7 @@ void mg_ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
("HTTP request from %s: %.*s %.*s", addr, (int) hm->method.len,
hm->method.p, (int) hm->uri.len, hm->uri.p));
if (mg_vcmp(&hm->uri, "/upload") == 0 ||
(mg_vcmp(&hm->uri, "/") == 0 &&
mg_stat("SL:index.html", &st) != 0)) {
(mg_vcmp(&hm->uri, "/") == 0 && mg_stat("SL:index.html", &st) != 0)) {
mg_send(nc, upload_form, strlen(upload_form));
nc->flags |= MG_F_SEND_AND_CLOSE;
break;
......
......@@ -34,7 +34,7 @@ static void handle_request(struct mg_connection *nc) {
static void handle_upload(struct mg_connection *nc, int ev, void *p) {
struct file_writer_data *data = (struct file_writer_data *) nc->user_data;
struct mg_http_multipart_part *mp = (struct mg_http_multipart_part*)p;
struct mg_http_multipart_part *mp = (struct mg_http_multipart_part *) p;
switch (ev) {
case MG_EV_HTTP_PART_BEGIN: {
......
......@@ -10,7 +10,7 @@ struct device_settings {
static const char *s_http_port = "8000";
static struct mg_serve_http_opts s_http_server_opts;
static struct device_settings s_settings = { "value1", "value2" };
static struct device_settings s_settings = {"value1", "value2"};
static void handle_save(struct mg_connection *nc, struct http_message *hm) {
// Get form variables and store settings values
......
......@@ -10,7 +10,7 @@ struct device_settings {
static const char *s_http_port = "8000";
static struct mg_serve_http_opts s_http_server_opts;
static struct device_settings s_settings = { "value1", "value2" };
static struct device_settings s_settings = {"value1", "value2"};
static void handle_save(struct mg_connection *nc, struct http_message *hm) {
// Get form variables and store settings values
......
......@@ -10,7 +10,7 @@ struct device_settings {
static const char *s_http_port = "8000";
static struct mg_serve_http_opts s_http_server_opts;
static struct device_settings s_settings = { "value1", "value2" };
static struct device_settings s_settings = {"value1", "value2"};
static void handle_save(struct mg_connection *nc, struct http_message *hm) {
// Get form variables and store settings values
......
......@@ -11,16 +11,11 @@ static struct mg_serve_http_opts s_http_server_opts;
static const char *s_login_uri = "/login.html";
static const char *s_secret = ":-)"; // Must be known only to server
static void generate_ssid(const char *user_name, const char *expiration_date,
char *ssid, size_t ssid_size) {
char hash[33];
cs_md5(hash,
user_name, strlen(user_name),
":", (size_t) 1,
expiration_date, strlen(expiration_date),
":", (size_t) 1,
s_secret, strlen(s_secret),
cs_md5(hash, user_name, strlen(user_name), ":", (size_t) 1, expiration_date,
strlen(expiration_date), ":", (size_t) 1, s_secret, strlen(s_secret),
NULL);
snprintf(ssid, ssid_size, "%s|%s|%s", user_name, expiration_date, hash);
}
......@@ -36,8 +31,8 @@ static int check_auth(struct http_message *hm) {
// Look for session ID in the Cookie.
// That session ID can be validated against the database that stores
// current active sessions.
mg_http_parse_header(
mg_get_http_header(hm, "Cookie"), "ssid", ssid, sizeof(ssid));
mg_http_parse_header(mg_get_http_header(hm, "Cookie"), "ssid", ssid,
sizeof(ssid));
if (sscanf(ssid, "%[^|]|%[^|]|", name, expire) == 2) {
generate_ssid(name, expire, calculated_ssid, sizeof(calculated_ssid));
if (strcmp(ssid, calculated_ssid) == 0) {
......@@ -59,7 +54,6 @@ static void check_login_form_submission(struct mg_connection *c,
// A real authentication mechanism should be employed here.
// Also, the whole site should be served through HTTPS.
if (strcmp(name, "Joe") == 0 && strcmp(password, "Doe") == 0) {
// Generate expiry date
time_t t = time(NULL) + 3600; // Valid for 1 hour
snprintf(expire_epoch, sizeof(expire_epoch), "%lu", (unsigned long) t);
......
......@@ -16,8 +16,8 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
switch (ev) {
case MG_EV_CONNECT:
if (* (int *) ev_data != 0) {
fprintf(stderr, "connect() failed: %s\n", strerror(* (int *) ev_data));
if (*(int *) ev_data != 0) {
fprintf(stderr, "connect() failed: %s\n", strerror(*(int *) ev_data));
s_exit_flag = 1;
}
break;
......@@ -54,8 +54,8 @@ int main(int argc, char *argv[]) {
}
if (i + 1 != argc) {
fprintf(stderr, "Usage: %s [%s] [--hexdump <file>] <URL>\n",
argv[0], s_show_headers_opt);
fprintf(stderr, "Usage: %s [%s] [--hexdump <file>] <URL>\n", argv[0],
s_show_headers_opt);
exit(EXIT_FAILURE);
}
......
......@@ -31,15 +31,16 @@ static int rpc_sum(char *buf, int len, struct mg_rpc_request *req) {
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct http_message *hm = (struct http_message *) ev_data;
static const char *methods[] = { "sum", NULL };
static mg_rpc_handler_t handlers[] = { rpc_sum, NULL };
static const char *methods[] = {"sum", NULL};
static mg_rpc_handler_t handlers[] = {rpc_sum, NULL};
char buf[100];
switch (ev) {
case MG_EV_HTTP_REQUEST:
mg_rpc_dispatch(hm->body.p, hm->body.len, buf, sizeof(buf),
methods, handlers);
mg_printf(nc, "HTTP/1.0 200 OK\r\nContent-Length: %d\r\n"
mg_rpc_dispatch(hm->body.p, hm->body.len, buf, sizeof(buf), methods,
handlers);
mg_printf(nc,
"HTTP/1.0 200 OK\r\nContent-Length: %d\r\n"
"Content-Type: application/json\r\n\r\n%s",
(int) strlen(buf), buf);
nc->flags |= MG_F_SEND_AND_CLOSE;
......
......@@ -37,7 +37,7 @@ int main(void) {
* and subscriptions
*/
for(;;) {
for (;;) {
mg_mgr_poll(&mgr, 1000);
}
}
......@@ -20,9 +20,10 @@ static void ev_handler(struct mg_connection *c, int ev, void *p) {
sleep(3);
/* Send the reply */
snprintf(reply, sizeof(reply), "{ \"uri\": \"%.*s\" }\n",
(int) hm->uri.len, hm->uri.p);
mg_printf(c, "HTTP/1.1 200 OK\r\n"
snprintf(reply, sizeof(reply), "{ \"uri\": \"%.*s\" }\n", (int) hm->uri.len,
hm->uri.p);
mg_printf(c,
"HTTP/1.1 200 OK\r\n"
"Content-Type: application/json\r\n"
"Content-Length: %d\r\n"
"\r\n"
......
......@@ -30,7 +30,8 @@ static void signal_handler(int sig_num) {
static void show_usage_and_exit(const char *prog_name) {
fprintf(stderr, "%s\n", "Copyright (c) 2014 CESANTA SOFTWARE");
fprintf(stderr, "%s\n", "Usage:");
fprintf(stderr, " %s\n [-d debug_file] [-l] [tcp|ssl]://[ip:]port[:cert][:ca_cert]",
fprintf(stderr,
" %s\n [-d debug_file] [-l] [tcp|ssl]://[ip:]port[:cert][:ca_cert]",
prog_name);
fprintf(stderr, "%s\n", "Examples:");
fprintf(stderr, " %s\n -d hexdump.txt ssl://google.com:443", prog_name);
......@@ -40,7 +41,7 @@ static void show_usage_and_exit(const char *prog_name) {
}
static void on_stdin_read(struct mg_connection *nc, int ev, void *p) {
int ch = * (int *) p;
int ch = *(int *) p;
(void) ev;
......
......@@ -19,7 +19,7 @@
#include "mongoose.h"
static void *stdin_thread(void *param) {
int ch, sock = * (int *) param;
int ch, sock = *(int *) param;
while ((ch = getchar()) != EOF) {
unsigned char c = (unsigned char) ch;
send(sock, &c, 1, 0); // Forward all types characters to the socketpair
......
......@@ -34,8 +34,10 @@ static void push_frame_to_clients(struct mg_mgr *mgr,
for (nc = mg_next(mgr, NULL); nc != NULL; nc = mg_next(mgr, nc)) {
if (!(nc->flags & MG_F_USER_2)) continue; // Ignore un-marked requests
mg_printf(nc, "--w00t\r\nContent-Type: image/jpeg\r\n"
"Content-Length: %lu\r\n\r\n", (unsigned long) wm->size);
mg_printf(nc,
"--w00t\r\nContent-Type: image/jpeg\r\n"
"Content-Length: %lu\r\n\r\n",
(unsigned long) wm->size);
mg_send(nc, wm->data, wm->size);
mg_send(nc, "\r\n", 2);
printf("Image pushed to %p\n", nc);
......@@ -50,7 +52,8 @@ static void send_command_to_the_device(struct mg_mgr *mgr,
const struct mg_str *cmd) {
struct mg_connection *nc;
for (nc = mg_next(mgr, NULL); nc != NULL; nc = mg_next(mgr, nc)) {
if (!(nc->flags & MG_F_IS_WEBSOCKET)) continue; // Ignore non-websocket requests
if (!(nc->flags & MG_F_IS_WEBSOCKET))
continue; // Ignore non-websocket requests
mg_send_websocket_frame(nc, WEBSOCKET_OP_TEXT, cmd->p, cmd->len);
printf("Sent API command [%.*s] to %p\n", (int) cmd->len, cmd->p, nc);
......@@ -135,7 +138,7 @@ int main(int argc, char *argv[]) {
* We explicitly hand over control to the Mongoose manager
* in this event loop and we can easily multiplex other activities.
*/
for(;;) {
for (;;) {
mg_mgr_poll(&mgr, 1000);
}
......
......@@ -53,7 +53,8 @@ static void send_mjpg_frame(struct mg_connection *nc, const char *file_path) {
/* Send those buffer through the websocket connection */
mg_send_websocket_frame(nc, WEBSOCKET_OP_BINARY, buf, sizeof(buf));
printf("Sent mjpg frame, %lu bytes after skippping %d frames\n", (unsigned long) sizeof(buf), skipped_frames);
printf("Sent mjpg frame, %lu bytes after skippping %d frames\n",
(unsigned long) sizeof(buf), skipped_frames);
skipped_frames = 0;
}
}
......@@ -64,8 +65,10 @@ static void send_mjpg_frame(struct mg_connection *nc, const char *file_path) {
*/
static void set_led(int v) {
char cmd[512];
snprintf(cmd, sizeof(cmd), "for i in 22 23 24; do"
" echo %d >/sys/class/gpio/gpio$i/value; done", v);
snprintf(cmd, sizeof(cmd),
"for i in 22 23 24; do"
" echo %d >/sys/class/gpio/gpio$i/value; done",
v);
system(cmd);
}
......@@ -73,7 +76,7 @@ static void set_led(int v) {
* Parse control JSON and perform command:
* for now only LED on/off is supported.
*/
static void perform_control_command(const char* data, size_t len) {
static void perform_control_command(const char *data, size_t len) {
struct json_token toks[200], *onoff;
parse_json(data, len, toks, sizeof(toks));
onoff = find_json_token(toks, "onoff");
......@@ -86,16 +89,16 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
switch (ev) {
case MG_EV_CONNECT:
printf("Reconnect: %s\n", * (int *) ev_data == 0 ? "ok" : "failed");
if (* (int *) ev_data == 0) {
printf("Reconnect: %s\n", *(int *) ev_data == 0 ? "ok" : "failed");
if (*(int *) ev_data == 0) {
/*
* Tune the tcp send buffer size, so that we can skip frames
* when the connection is congested. This helps maintaining a
* reasonable latency.
*/
int sndbuf_size = 512;
if(setsockopt(nc->sock, SOL_SOCKET, SO_SNDBUF,
(void *) &sndbuf_size, sizeof(int)) == -1) {
if (setsockopt(nc->sock, SOL_SOCKET, SO_SNDBUF, (void *) &sndbuf_size,
sizeof(int)) == -1) {
perror("failed to tune TCP send buffer size\n");
}
......@@ -111,7 +114,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
break;
case MG_EV_WEBSOCKET_FRAME:
printf("Got control command: [%.*s]\n", (int) wm->size, wm->data);
perform_control_command((const char*)wm->data, wm->size);
perform_control_command((const char *) wm->data, wm->size);
break;
}
}
......@@ -124,11 +127,13 @@ static void *generate_mjpg_data_thread_func(void *param) {
char cmd[400];
(void) param;
snprintf(cmd, sizeof(cmd), "raspistill -w %d -h %d -n -q 100 -tl %d "
"-t 999999999 -v %s -o %s >/dev/null 2>&1", s_width, s_height,
s_still_period, s_vertical_flip ? "-vf" : "", s_mjpg_file);
snprintf(cmd, sizeof(cmd),
"raspistill -w %d -h %d -n -q 100 -tl %d "
"-t 999999999 -v %s -o %s >/dev/null 2>&1",
s_width, s_height, s_still_period, s_vertical_flip ? "-vf" : "",
s_mjpg_file);
for(;;) {
for (;;) {
int ret = system(cmd);
if (WIFSIGNALED(ret)) exit(1);
sleep(1);
......@@ -152,7 +157,7 @@ int main(int argc, char *argv[]) {
mg_mgr_init(&mgr, NULL);
for(;;) {
for (;;) {
mg_mgr_poll(&mgr, s_poll_interval_ms);
/* Reconnect if disconnected */
......
......@@ -12,7 +12,7 @@ struct device_settings {
static const char *s_http_port = "8000";
static struct mg_serve_http_opts s_http_server_opts;
static struct device_settings s_settings = { "value1", "value2" };
static struct device_settings s_settings = {"value1", "value2"};
static void handle_save(struct mg_connection *nc, struct http_message *hm) {
/* Get form variables and store settings values */
......@@ -63,11 +63,11 @@ int main(int argc, char *argv[]) {
mg_set_protocol_http_websocket(nc);
s_http_server_opts.document_root = "./web_root";
s_http_server_opts.auth_domain = "example.com";
//mgr.hexdump_file = "/dev/stdout";
// mgr.hexdump_file = "/dev/stdout";
/* If our current directory */
if (argc > 0 && (p = strrchr(argv[0], '/'))) {
snprintf(path, sizeof(path), "%.*s/web_root", (int)(p - argv[0]), argv[0]);
snprintf(path, sizeof(path), "%.*s/web_root", (int) (p - argv[0]), argv[0]);
s_http_server_opts.document_root = path;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment