Skip to content

Commit

Permalink
Change mg_file_read() signature: return mg_str
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Feb 16, 2024
1 parent d128d21 commit 0e2f3de
Show file tree
Hide file tree
Showing 24 changed files with 97 additions and 1,054 deletions.
8 changes: 4 additions & 4 deletions examples/device-dashboard/packed_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ static const unsigned char v1[] = {
0, 0 // .
};
static const unsigned char v2[] = {
31, 139, 8, 8, 87, 102, 129, 101, 0, 3, 99, 111, // ....Wf.e..co
31, 139, 8, 8, 7, 115, 132, 101, 0, 3, 99, 111, // .....s.e..co
109, 112, 111, 110, 101, 110, 116, 115, 46, 106, 115, 0, // mponents.js.
237, 93, 235, 115, 219, 70, 146, 255, 238, 191, 98, 162, // .].s.F....b.
242, 45, 169, 181, 0, 225, 77, 64, 182, 148, 114, 156, // [email protected].
Expand Down Expand Up @@ -2127,7 +2127,7 @@ static const unsigned char v5[] = {
237, 34, 77, 0, 0, 0 // ."M..
};
static const unsigned char v6[] = {
31, 139, 8, 8, 215, 103, 114, 101, 0, 3, 109, 97, // .....gre..ma
31, 139, 8, 8, 93, 214, 178, 101, 0, 3, 109, 97, // ....]..e..ma
105, 110, 46, 106, 115, 0, 189, 91, 233, 114, 219, 72, // in.js..[.r.H
146, 254, 239, 167, 168, 230, 184, 155, 164, 155, 0, 9, // ............
82, 151, 105, 81, 29, 62, 219, 158, 112, 219, 14, 75, // R.iQ.>..p..K
Expand Down Expand Up @@ -2668,11 +2668,11 @@ static const struct packed_file {
time_t mtime;
} packed_files[] = {
{"/web_root/bundle.js.gz", v1, sizeof(v1), 1695912421},
{"/web_root/components.js.gz", v2, sizeof(v2), 1702979159},
{"/web_root/components.js.gz", v2, sizeof(v2), 1703179015},
{"/web_root/history.min.js.gz", v3, sizeof(v3), 1695912421},
{"/web_root/index.html.gz", v4, sizeof(v4), 1693654553},
{"/web_root/main.css.gz", v5, sizeof(v5), 1702757929},
{"/web_root/main.js.gz", v6, sizeof(v6), 1701996503},
{"/web_root/main.js.gz", v6, sizeof(v6), 1706219101},
{"/certs/server_cert.pem", v7, sizeof(v7), 1692695603},
{"/certs/server_key.pem", v8, sizeof(v8), 1692695603},
{NULL, NULL, 0, 0}
Expand Down
14 changes: 8 additions & 6 deletions examples/esp32/uart-bridge/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

const char *s_listening_url = "http://0.0.0.0:80";

#if 0
char *config_read(void) {
return mg_file_read(&mg_fs_posix, FS_ROOT "/config.json", NULL);
}
#endif

void config_write(struct mg_str config) {
mg_file_write(&mg_fs_posix, FS_ROOT "/config.json", config.ptr, config.len);
Expand All @@ -21,14 +23,14 @@ void app_main(void) {
MG_INFO(("FS at %s initialised, status: %d", conf.base_path, res));

// Try to connect to wifi by using saved WiFi credentials
char *json = mg_file_read(&mg_fs_posix, WIFI_FILE, NULL);
if (json != NULL) {
char *ssid = mg_json_get_str(mg_str(json), "$.ssid");
char *pass = mg_json_get_str(mg_str(json), "$.pass");
struct mg_str json = mg_file_read(&mg_fs_posix, WIFI_FILE);
if (json.ptr != NULL) {
char *ssid = mg_json_get_str(json, "$.ssid");
char *pass = mg_json_get_str(json, "$.pass");
while (!wifi_init(ssid, pass)) (void) 0;
free(ssid);
free(pass);
free(json);
free((void *) json.ptr);
} else {
// If WiFi is not configured, run CLI until configured
MG_INFO(("WiFi is not configured, running CLI. Press enter"));
Expand All @@ -45,6 +47,6 @@ void app_main(void) {
mg_mgr_init(&mgr);
mg_log_set(MG_LL_DEBUG); // Set log level
MG_INFO(("Mongoose v%s on %s", MG_VERSION, s_listening_url));
mg_http_listen(&mgr, s_listening_url, uart_bridge_fn, &mgr);
mg_http_listen(&mgr, s_listening_url, uart_bridge_fn, NULL);
for (;;) mg_mgr_poll(&mgr, 10); // Infinite event loop
}
2 changes: 1 addition & 1 deletion examples/esp32/uart-bridge/main/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define WIFI_FILE FS_ROOT "/wifi.json"
#define UART_NO 1

void uart_bridge_fn(struct mg_connection *, int, void *, void *);
void uart_bridge_fn(struct mg_connection *, int, void *);
int uart_read(void *buf, size_t len);
bool wifi_init(const char *ssid, const char *pass);
void cli(uint8_t ch);
Expand Down
11 changes: 5 additions & 6 deletions examples/modbus-dashboard/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ static void signal_handler(int sig_num) {

bool web_load_settings(void *buf, size_t len) {
bool ok = false;
size_t size = 0;
void *data = mg_file_read(&mg_fs_posix, CONFIG_FILE, &size);
if (data == NULL) {
struct mg_str data = mg_file_read(&mg_fs_posix, CONFIG_FILE);
if (data.ptr == NULL) {
MG_ERROR(("Error reading %s", CONFIG_FILE));
} else if (size != len) {
} else if (data.len != len) {
MG_ERROR(("%s size != %lu", CONFIG_FILE, len));
} else {
memcpy(buf, data, len);
memcpy(buf, data.ptr, len);
}
free(data);
free((void *) data.ptr);
return ok;
}

Expand Down
8 changes: 4 additions & 4 deletions examples/mqtt-dashboard/device/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ static void set_device_id(void) {
fclose(fp);
}
#elif defined(__linux__)
char *id = mg_file_read(&mg_fs_posix, "/etc/machine-id", NULL);
if (id != NULL) {
mg_snprintf(buf, sizeof(buf), "%s", id);
free(id);
struct mg_str id = mg_file_read(&mg_fs_posix, "/etc/machine-id");
if (id.ptr != NULL) {
mg_snprintf(buf, sizeof(buf), "%s", id.ptr);
free((void *) id.ptr);
}
#endif

Expand Down

This file was deleted.

Loading

0 comments on commit 0e2f3de

Please sign in to comment.