clang-format *ALL* the things!

PUBLISHED_FROM=faf0beb7545eb426c941fc366b6f87667723eb4c
This commit is contained in:
rojer 2016-06-09 13:13:19 +02:00 committed by Cesanta Bot
parent dcf1cedec9
commit 183fc7ced9
22 changed files with 96 additions and 88 deletions

View File

@ -1,3 +1,4 @@
/* clang-format off */
/*
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.

View File

@ -1,3 +1,4 @@
/* clang-format off */
/*
* Copyright (c) 2015-2016, Texas Instruments Incorporated
* All rights reserved.

View File

@ -1,3 +1,4 @@
/* clang-format off */
/*
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -37,9 +37,10 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
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;

View File

@ -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"

View File

@ -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);

View File

@ -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);

View File

@ -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);
}
@ -94,8 +97,8 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
* 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");
}
@ -124,9 +127,11 @@ 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 (;;) {
int ret = system(cmd);