diff --git a/examples/device-dashboard/packed_fs.c b/examples/device-dashboard/packed_fs.c index 0ed552b870..78caf7ca36 100644 --- a/examples/device-dashboard/packed_fs.c +++ b/examples/device-dashboard/packed_fs.c @@ -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, // .-....M@..r. @@ -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 @@ -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} diff --git a/examples/esp32/uart-bridge/main/main.c b/examples/esp32/uart-bridge/main/main.c index 6b4abedb47..f3073dc90e 100644 --- a/examples/esp32/uart-bridge/main/main.c +++ b/examples/esp32/uart-bridge/main/main.c @@ -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); @@ -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")); @@ -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 } diff --git a/examples/esp32/uart-bridge/main/main.h b/examples/esp32/uart-bridge/main/main.h index d736305591..905ed368ce 100644 --- a/examples/esp32/uart-bridge/main/main.h +++ b/examples/esp32/uart-bridge/main/main.h @@ -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); diff --git a/examples/modbus-dashboard/main.c b/examples/modbus-dashboard/main.c index d8a5a527a4..25256e1d21 100644 --- a/examples/modbus-dashboard/main.c +++ b/examples/modbus-dashboard/main.c @@ -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; } diff --git a/examples/mqtt-dashboard/device/net.c b/examples/mqtt-dashboard/device/net.c index 1c4a28e319..2fc58882e2 100644 --- a/examples/mqtt-dashboard/device/net.c +++ b/examples/mqtt-dashboard/device/net.c @@ -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 diff --git a/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/main.su b/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/main.su deleted file mode 100644 index a8d0384e49..0000000000 --- a/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/main.su +++ /dev/null @@ -1,16 +0,0 @@ -/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/CMSIS/core_cm7.h:1911:22:__NVIC_EnableIRQ 16 static -/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/CMSIS/core_cm7.h:2041:22:__NVIC_SetPriority 16 static -/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/CMSIS/core_cm7.h:2259:26:SysTick_Config 16 static -/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/drivers/fsl_common_arm.h:210:20:_SDK_AtomicLocalClearAndSet4Byte 48 static -/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/drivers/fsl_clock.h:1496:20:CLOCK_ControlGate 32 static -/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/drivers/fsl_clock.h:1513:20:CLOCK_EnableClock 16 static -/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/drivers/fsl_gpio.h:176:24:GPIO_PinRead 16 static -/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/drivers/fsl_iomuxc.h:1288:20:IOMUXC_SetPinMux 24 static -/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/drivers/fsl_iomuxc.h:1320:20:IOMUXC_SetPinConfig 24 static -/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/drivers/fsl_iomuxc.h:1340:20:IOMUXC_EnableMode 24 static -../source/hal.h:16:20:ethernet_init 24 static -../source/main.c:28:6:SysTick_Handler 4 static -../source/main.c:32:10:mg_millis 4 static -../source/main.c:36:6:mg_random 16 static -../source/main.c:40:13:timer_fn 64 static -../source/main.c:52:5:main 224 static diff --git a/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/mongoose.su b/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/mongoose.su deleted file mode 100644 index c80b403910..0000000000 --- a/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/mongoose.su +++ /dev/null @@ -1,368 +0,0 @@ -../source/mongoose.c:5626:14:mg_ota_boot 4 static -../source/mongoose.c:27:12:mg_base64_encode_single 16 static -../source/mongoose.c:39:12:mg_base64_decode_single 16 static -../source/mongoose.c:57:8:mg_base64_update 32 static -../source/mongoose.c:73:8:mg_base64_final 24 static -../source/mongoose.c:84:8:mg_base64_encode 32 static -../source/mongoose.c:93:8:mg_base64_decode 48 static -../source/mongoose.c:207:7:mg_flash_start 4 static -../source/mongoose.c:210:8:mg_flash_size 4 static -../source/mongoose.c:213:8:mg_flash_sector_size 4 static -../source/mongoose.c:216:8:mg_flash_write_align 4 static -../source/mongoose.c:219:5:mg_flash_bank 4 static -../source/mongoose.c:222:6:mg_flash_erase 16 static -../source/mongoose.c:226:6:mg_flash_swap_bank 4 static -../source/mongoose.c:229:6:mg_flash_write 24 static -../source/mongoose.c:233:6:mg_device_reset 4 static -../source/mongoose.c:402:6:mg_flash_save 24 static -../source/mongoose.c:406:6:mg_flash_load 24 static -../source/mongoose.c:737:13:mg_dns_free 24 static -../source/mongoose.c:742:6:mg_resolve_cancel 32 static -../source/mongoose.c:751:15:mg_dns_parse_name_depth 56 static -../source/mongoose.c:788:15:mg_dns_parse_name 40 static -../source/mongoose.c:793:8:mg_dns_parse_rr 40 static -../source/mongoose.c:817:6:mg_dns_parse 56 static -../source/mongoose.c:855:13:dns_cb 344 static -../source/mongoose.c:913:13:mg_dns_send 312 static -../source/mongoose.c:940:13:mg_sendnsreq 56 static -../source/mongoose.c:972:6:mg_resolve 40 static -../source/mongoose.c:994:6:mg_call 32 static -../source/mongoose.c:1013:6:mg_error 92 static -../source/mongoose.c:1031:13:is_digit 16 static -../source/mongoose.c:1035:12:addexp 32 static -../source/mongoose.c:1047:12:xisinf 24 static -../source/mongoose.c:1056:12:xisnan 24 static -../source/mongoose.c:1066:15:mg_dtoa 136 static -../source/mongoose.c:1125:15:mg_lld 64 static -../source/mongoose.c:1147:15:scpy 32 static -../source/mongoose.c:1154:8:mg_xprintf 24 static -../source/mongoose.c:1163:8:mg_vxprintf 176 static -../source/mongoose.c:1257:15:mg_fs_open 32 static -../source/mongoose.c:1270:6:mg_fs_close 16 static -../source/mongoose.c:1277:7:mg_file_read 40 static -../source/mongoose.c:1298:6:mg_file_write 144 static -../source/mongoose.c:1317:6:mg_file_printf 32 static -../source/mongoose.c:1487:15:mg_unpacked 24 static -../source/mongoose.c:1493:12:is_dir_prefix 24 static -../source/mongoose.c:1499:12:packed_stat 40 static -../source/mongoose.c:1510:13:packed_list 256 static -../source/mongoose.c:1531:14:packed_open 32 static -../source/mongoose.c:1544:13:packed_close 16 static -../source/mongoose.c:1548:15:packed_read 32 static -../source/mongoose.c:1556:15:packed_write 24 static -../source/mongoose.c:1561:15:packed_seek 24 static -../source/mongoose.c:1568:13:packed_rename 16 static -../source/mongoose.c:1573:13:packed_remove 16 static -../source/mongoose.c:1578:13:packed_mkdir 16 static -../source/mongoose.c:1602:12:p_stat 112 static -../source/mongoose.c:1743:13:p_list 24 static -../source/mongoose.c:1759:14:p_open 24 static -../source/mongoose.c:1772:13:p_close 16 static -../source/mongoose.c:1776:15:p_read 24 static -../source/mongoose.c:1780:15:p_write 24 static -../source/mongoose.c:1784:15:p_seek 16 static -../source/mongoose.c:1795:13:p_rename 16 static -../source/mongoose.c:1799:13:p_remove 16 static -../source/mongoose.c:1803:13:p_mkdir 16 static -../source/mongoose.c:1870:6:mg_to_size_t 48 static -../source/mongoose.c:1904:8:mg_http_next_multipart 112 static -../source/mongoose.c:1944:6:mg_http_bauth 56 static -../source/mongoose.c:1970:15:mg_http_var 48 static -../source/mongoose.c:1981:5:mg_http_get_var 56 static -../source/mongoose.c:2001:13:isx 16 static -../source/mongoose.c:2006:5:mg_url_decode 32 static -../source/mongoose.c:2028:13:isok 16 static -../source/mongoose.c:2032:5:mg_http_get_request_len 24 static -../source/mongoose.c:2042:16:mg_http_get_header 40 static -../source/mongoose.c:2052:13:vcb 16 static -../source/mongoose.c:2057:15:clen 32 static -../source/mongoose.c:2069:20:skiptorn 24 static -../source/mongoose.c:2078:13:mg_http_parse_headers 48 static -../source/mongoose.c:2100:5:mg_http_parse 48 static -../source/mongoose.c:2173:13:mg_http_vprintf_chunk 32 static -../source/mongoose.c:2186:6:mg_http_printf_chunk 28 static -../source/mongoose.c:2193:6:mg_http_write_chunk 24 static -../source/mongoose.c:2201:20:mg_http_status_code_str 16 static -../source/mongoose.c:2271:6:mg_http_reply 52 static -../source/mongoose.c:2290:13:restore_http_cb 16 static -../source/mongoose.c:2298:7:mg_http_etag 48 static -../source/mongoose.c:2303:13:static_cb 48 static -../source/mongoose.c:2362:22:guess_content_type 64 static -../source/mongoose.c:2384:12:getrange 48 static -../source/mongoose.c:2400:6:mg_http_serve_file 480 static -../source/mongoose.c:2606:12:uri_to_path2 56 static -../source/mongoose.c:2665:12:uri_to_path 112 static -../source/mongoose.c:2679:6:mg_http_serve_dir 152 static -../source/mongoose.c:2700:13:mg_is_url_safe 16 static -../source/mongoose.c:2705:8:mg_url_encode 40 static -../source/mongoose.c:2723:6:mg_http_creds 328 static -../source/mongoose.c:2745:22:stripquotes 24 static -../source/mongoose.c:2751:15:mg_http_get_header_var 56 static -../source/mongoose.c:2768:6:mg_http_match_uri 32 static -../source/mongoose.c:2772:6:mg_http_upload 72 static -../source/mongoose.c:2808:5:mg_http_status 16 static -../source/mongoose.c:2812:13:is_hex_digit 16 static -../source/mongoose.c:2817:12:skip_chunk 32 static -../source/mongoose.c:2831:13:http_cb 616 static -../source/mongoose.c:2896:13:mg_hfn 40 static -../source/mongoose.c:2915:6:mg_hello 96 static -../source/mongoose.c:2924:23:mg_http_connect 32 static -../source/mongoose.c:2931:23:mg_http_listen 32 static -../source/mongoose.c:2946:15:roundup 16 static -../source/mongoose.c:2950:5:mg_iobuf_resize 56 static -../source/mongoose.c:2977:5:mg_iobuf_init 24 static -../source/mongoose.c:2984:8:mg_iobuf_add 32 static -../source/mongoose.c:2996:8:mg_iobuf_del 24 static -../source/mongoose.c:3005:6:mg_iobuf_free 16 static -../source/mongoose.c:3016:20:escapeseq 16 static -../source/mongoose.c:3020:13:json_esc 32 static -../source/mongoose.c:3028:12:mg_pass_string 24 static -../source/mongoose.c:3042:15:mg_atod 72 static -../source/mongoose.c:3089:8:mg_json_next 64 static -../source/mongoose.c:3137:5:mg_json_get 120 static -../source/mongoose.c:3280:6:mg_json_get_num 48 static -../source/mongoose.c:3290:6:mg_json_get_bool 40 static -../source/mongoose.c:3299:6:mg_json_unescape 48 static -../source/mongoose.c:3324:7:mg_json_get_str 48 static -../source/mongoose.c:3338:7:mg_json_get_b64 48 static -../source/mongoose.c:3350:7:mg_json_get_hex 48 static -../source/mongoose.c:3362:6:mg_json_get_long 48 static -../source/mongoose.c:3381:6:mg_log_set_fn 16 static -../source/mongoose.c:3386:13:logc 16 static -../source/mongoose.c:3390:13:logs 24 static -../source/mongoose.c:3398:6:mg_log_prefix 112 static -../source/mongoose.c:3410:6:mg_log 16 static -../source/mongoose.c:3419:22:nibble 16 static -../source/mongoose.c:3424:6:mg_hexdump 48 static -../source/mongoose.c:3467:13:mg_byte_reverse 24 static -../source/mongoose.c:3492:6:mg_md5_init 16 static -../source/mongoose.c:3502:13:mg_md5_transform 32 static -../source/mongoose.c:3584:6:mg_md5_update 32 static -../source/mongoose.c:3619:6:mg_md5_final 32 static -../source/mongoose.c:3701:6:mg_mqtt_send_header 40 static -../source/mongoose.c:3714:13:mg_send_u16 16 static -../source/mongoose.c:3718:13:mg_send_u32 16 static -../source/mongoose.c:3722:16:varint_size 24 static -../source/mongoose.c:3731:15:encode_varint 24 static -../source/mongoose.c:3744:15:decode_varint 40 static -../source/mongoose.c:3759:12:mqtt_prop_type_by_id 24 static -../source/mongoose.c:3769:15:get_properties_length 24 static -../source/mongoose.c:3806:15:get_props_size 24 static -../source/mongoose.c:3812:13:mg_send_mqtt_properties 48 static -../source/mongoose.c:3854:8:mg_mqtt_next_prop 40 static -../source/mongoose.c:3908:6:mg_mqtt_login 72 static -../source/mongoose.c:3974:6:mg_mqtt_pub 40 static -../source/mongoose.c:3996:6:mg_mqtt_sub 32 static -../source/mongoose.c:4011:5:mg_mqtt_parse 48 static -../source/mongoose.c:4081:13:mqtt_cb 112 static -../source/mongoose.c:4153:6:mg_mqtt_ping 16 static -../source/mongoose.c:4157:6:mg_mqtt_pong 16 static -../source/mongoose.c:4161:6:mg_mqtt_disconnect 24 static -../source/mongoose.c:4174:23:mg_mqtt_connect 96 static -../source/mongoose.c:4187:23:mg_mqtt_listen 32 static -../source/mongoose.c:4206:8:mg_vprintf 32 static -../source/mongoose.c:4212:8:mg_printf 28 static -../source/mongoose.c:4221:13:mg_atonl 32 static -../source/mongoose.c:4229:13:mg_atone 24 static -../source/mongoose.c:4236:13:mg_aton4 40 static -../source/mongoose.c:4257:13:mg_v4mapped 40 static -../source/mongoose.c:4275:13:mg_aton6 48 static -../source/mongoose.c:4320:6:mg_aton 24 static -../source/mongoose.c:4326:23:mg_alloc_conn 24 static -../source/mongoose.c:4338:6:mg_close_conn 24 static -../source/mongoose.c:4358:23:mg_connect 32 static -../source/mongoose.c:4379:23:mg_listen 32 static -../source/mongoose.c:4402:23:mg_wrapfd 32 static -../source/mongoose.c:4416:18:mg_timer_add 48 static -../source/mongoose.c:4426:6:mg_io_recv 24 static -../source/mongoose.c:4434:6:mg_mgr_free 32 static -../source/mongoose.c:4451:6:mg_mgr_init 16 static -../source/mongoose.c:4619:13:mkpay 32 static -../source/mongoose.c:4624:17:csumup 32 static -../source/mongoose.c:4630:17:csumfin 16 static -../source/mongoose.c:4635:17:ipcsum 24 static -../source/mongoose.c:4640:13:settmout 56 static -../source/mongoose.c:4653:15:ether_output 24 static -../source/mongoose.c:4659:13:arp_ask 24 static -../source/mongoose.c:4673:13:onstatechange 16 static -../source/mongoose.c:4687:19:tx_ip 32 static -../source/mongoose.c:4707:13:tx_udp 48 static -../source/mongoose.c:4729:13:tx_dhcp 320 static -../source/mongoose.c:4746:13:tx_dhcp_request_sel 80 static -../source/mongoose.c:4763:13:tx_dhcp_request_re 48 static -../source/mongoose.c:4773:13:tx_dhcp_discover 40 static -../source/mongoose.c:4783:30:getpeer 32 static -../source/mongoose.c:4798:13:rx_arp 48 static -../source/mongoose.c:4837:13:rx_icmp 48 static -../source/mongoose.c:4853:13:rx_dhcp_client 88 static -../source/mongoose.c:4902:13:rx_dhcp_server 368 static -../source/mongoose.c:4941:13:rx_udp 24 static -../source/mongoose.c:4963:15:tx_tcp 88 static -../source/mongoose.c:4993:15:tx_tcp_pkt 72 static -../source/mongoose.c:5002:30:accept_conn 32 static -../source/mongoose.c:5029:15:trim_len 48 static -../source/mongoose.c:5056:6:mg_io_send 80 static -../source/mongoose.c:5079:13:read_conn 96 static -../source/mongoose.c:5170:13:rx_tcp 48 static -../source/mongoose.c:5219:13:rx_ip 56 static -../source/mongoose.c:5262:13:rx_ip6 16 static -../source/mongoose.c:5278:13:mg_tcpip_rx 88 static -../source/mongoose.c:5322:13:mg_tcpip_poll 104 static -../source/mongoose.c:5409:6:mg_tcpip_qwrite 32 static -../source/mongoose.c:5420:6:mg_tcpip_init 24 static -../source/mongoose.c:5451:6:mg_tcpip_free 16 static -../source/mongoose.c:5456:13:send_syn 64 static -../source/mongoose.c:5466:6:mg_connect_resolved 48 static -../source/mongoose.c:5506:6:mg_open_listener 16 static -../source/mongoose.c:5511:13:write_conn 24 static -../source/mongoose.c:5522:13:init_closure 80 static -../source/mongoose.c:5536:13:close_conn 24 static -../source/mongoose.c:5542:13:can_write 16 static -../source/mongoose.c:5547:6:mg_mgr_poll 64 static -../source/mongoose.c:5567:6:mg_send 64 static -../source/mongoose.c:5593:6:mg_ota_begin 16 static -../source/mongoose.c:5597:6:mg_ota_write 16 static -../source/mongoose.c:5601:6:mg_ota_end 4 static -../source/mongoose.c:5604:6:mg_ota_commit 4 static -../source/mongoose.c:5607:6:mg_ota_rollback 4 static -../source/mongoose.c:5610:5:mg_ota_status 16 static -../source/mongoose.c:5614:10:mg_ota_crc32 16 static -../source/mongoose.c:5618:10:mg_ota_timestamp 16 static -../source/mongoose.c:5622:8:mg_ota_size 16 static -../source/mongoose.c:5840:8:mg_queue_vprintf 32 static -../source/mongoose.c:5852:8:mg_queue_printf 28 static -../source/mongoose.c:5861:13:mg_pfn_iobuf_private 24 static -../source/mongoose.c:5872:13:mg_putchar_iobuf_static 16 static -../source/mongoose.c:5876:6:mg_pfn_iobuf 16 static -../source/mongoose.c:5880:8:mg_vsnprintf 48 static -../source/mongoose.c:5887:8:mg_snprintf 24 static -../source/mongoose.c:5896:7:mg_vmprintf 32 static -../source/mongoose.c:5902:7:mg_mprintf 16 static -../source/mongoose.c:5911:6:mg_pfn_stdout 16 static -../source/mongoose.c:5916:15:print_ip4 40 static -../source/mongoose.c:5920:15:print_ip6 80 static -../source/mongoose.c:5927:8:mg_print_ip4 32 static -../source/mongoose.c:5932:8:mg_print_ip6 32 static -../source/mongoose.c:5937:8:mg_print_ip 32 static -../source/mongoose.c:5943:8:mg_print_ip_port 40 static -../source/mongoose.c:5948:8:mg_print_mac 64 static -../source/mongoose.c:5954:13:mg_esc 32 static -../source/mongoose.c:5962:13:mg_escape 16 static -../source/mongoose.c:5966:15:qcpy 40 static -../source/mongoose.c:5980:15:bcpy 48 static -../source/mongoose.c:5997:8:mg_print_hex 40 static -../source/mongoose.c:6008:8:mg_print_base64 32 static -../source/mongoose.c:6014:8:mg_print_esc 32 static -../source/mongoose.c:6050:6:mg_queue_init 24 static -../source/mongoose.c:6056:15:mg_queue_read_len 24 static -../source/mongoose.c:6064:13:mg_queue_write_len 24 static -../source/mongoose.c:6070:8:mg_queue_book 32 static -../source/mongoose.c:6083:8:mg_queue_next 24 static -../source/mongoose.c:6097:6:mg_queue_add 16 static -../source/mongoose.c:6104:6:mg_queue_del 16 static -../source/mongoose.c:6115:6:mg_rpc_add 48 static -../source/mongoose.c:6124:6:mg_rpc_del 24 static -../source/mongoose.c:6137:13:mg_rpc_call 40 static -../source/mongoose.c:6148:6:mg_rpc_process 48 static -../source/mongoose.c:6162:6:mg_rpc_vok 72 static -../source/mongoose.c:6172:6:mg_rpc_ok 28 static -../source/mongoose.c:6179:6:mg_rpc_verr 80 static -../source/mongoose.c:6192:6:mg_rpc_err 24 static -../source/mongoose.c:6199:15:print_methods 56 static -../source/mongoose.c:6210:6:mg_rpc_list 16 static -../source/mongoose.c:6229:17:blk0 16 static -../source/mongoose.c:6266:13:mg_sha1_transform 112 static -../source/mongoose.c:6373:6:mg_sha1_init 16 static -../source/mongoose.c:6382:6:mg_sha1_update 32 static -../source/mongoose.c:6402:6:mg_sha1_final 32 static -../source/mongoose.c:6452:6:mg_sha256_init 16 static -../source/mongoose.c:6465:13:mg_sha256_chunk 320 static -../source/mongoose.c:6507:6:mg_sha256_update 40 static -../source/mongoose.c:6521:6:mg_sha256_final 40 static -../source/mongoose.c:6560:6:mg_hmac_sha256 344 static -../source/mongoose.c:6602:16:gettimestamp 56 static -../source/mongoose.c:6608:9:mg_sntp_parse 144 static -../source/mongoose.c:6633:13:sntp_cb 40 static -../source/mongoose.c:6651:6:mg_sntp_request 96 static -../source/mongoose.c:6666:23:mg_sntp_connect 32 static -../source/mongoose.c:7490:6:mg_http_serve_ssi 24 static -../source/mongoose.c:7502:15:mg_str_s 24 static -../source/mongoose.c:7507:15:mg_str_n 32 static -../source/mongoose.c:7512:5:mg_lower 24 static -../source/mongoose.c:7518:5:mg_ncasecmp 40 static -../source/mongoose.c:7526:5:mg_casecmp 16 static -../source/mongoose.c:7530:5:mg_vcmp 32 static -../source/mongoose.c:7537:5:mg_vcasecmp 32 static -../source/mongoose.c:7544:15:mg_strdup 40 static -../source/mongoose.c:7558:5:mg_strcmp 40 static -../source/mongoose.c:7572:13:mg_strstr 40 static -../source/mongoose.c:7585:13:is_space 16 static -../source/mongoose.c:7589:15:mg_strstrip 24 static -../source/mongoose.c:7595:6:mg_match 40 static -../source/mongoose.c:7627:6:mg_globmatch 48 static -../source/mongoose.c:7631:15:mg_nce 32 static -../source/mongoose.c:7644:6:mg_split 80 static -../source/mongoose.c:7654:6:mg_commalist 24 static -../source/mongoose.c:7658:7:mg_hex 40 static -../source/mongoose.c:7670:22:mg_unhex_nimble 16 static -../source/mongoose.c:7676:15:mg_unhexn 24 static -../source/mongoose.c:7682:6:mg_unhex 32 static -../source/mongoose.c:7689:6:mg_path_is_sane 24 static -../source/mongoose.c:7707:6:mg_timer_init 24 static -../source/mongoose.c:7714:6:mg_timer_free 16 static -../source/mongoose.c:7720:6:mg_timer_expired 56 static -../source/mongoose.c:7728:6:mg_timer_poll 56 static -../source/mongoose.c:9642:6:mg_tls_init 16 static -../source/mongoose.c:9646:6:mg_tls_handshake 16 static -../source/mongoose.c:9649:6:mg_tls_free 16 static -../source/mongoose.c:9652:6:mg_tls_recv 24 static -../source/mongoose.c:9655:6:mg_tls_send 24 static -../source/mongoose.c:9658:8:mg_tls_pending 16 static -../source/mongoose.c:9662:6:mg_tls_ctx_init 16 static -../source/mongoose.c:9665:6:mg_tls_ctx_free 16 static -../source/mongoose.c:13331:5:mg_url_is_ssl 16 static -../source/mongoose.c:13337:19:urlparse 56 static -../source/mongoose.c:13365:15:mg_url_host 56 static -../source/mongoose.c:13374:13:mg_url_uri 48 static -../source/mongoose.c:13379:16:mg_url_port 48 static -../source/mongoose.c:13391:15:mg_url_user 64 static -../source/mongoose.c:13401:15:mg_url_pass 64 static -../source/mongoose.c:13418:6:mg_bzero 16 static -../source/mongoose.c:13445:7:mg_random_str 24 static -../source/mongoose.c:13458:10:mg_ntohl 24 static -../source/mongoose.c:13465:10:mg_ntohs 24 static -../source/mongoose.c:13471:10:mg_crc32 32 static -../source/mongoose.c:13486:12:isbyte 16 static -../source/mongoose.c:13490:12:parse_net 72 static -../source/mongoose.c:13504:5:mg_check_ip_acl 56 static -../source/mongoose.c:13591:8:mg_ws_vprintf 32 static -../source/mongoose.c:13599:8:mg_ws_printf 24 static -../source/mongoose.c:13608:13:ws_handshake 176 static -../source/mongoose.c:13634:17:be32 16 static -../source/mongoose.c:13639:15:ws_process 56 static -../source/mongoose.c:13669:15:mkhdr 48 static -../source/mongoose.c:13697:13:mg_ws_mask 32 static -../source/mongoose.c:13705:8:mg_ws_send 48 static -../source/mongoose.c:13716:13:mg_ws_client_handshake 560 static -../source/mongoose.c:13739:13:mg_ws_cb 72 static -../source/mongoose.c:13810:23:mg_ws_connect 112 static -../source/mongoose.c:13840:6:mg_ws_upgrade 40 static -../source/mongoose.c:13860:8:mg_ws_wrap 48 static -../source/mongoose.c:14047:17:enet_phy_read 16 static -../source/mongoose.c:14054:13:enet_phy_write 16 static -../source/mongoose.c:14061:17:enet_phy_id 24 static -../source/mongoose.c:14070:13:mg_tcpip_driver_imxrt_init 40 static -../source/mongoose.c:14138:15:mg_tcpip_driver_imxrt_tx 24 static -../source/mongoose.c:14161:13:mg_tcpip_driver_imxrt_up 48 static -../source/mongoose.c:14196:6:ENET_IRQHandler 24 static -../source/mongoose.c:15221:13:w5500_txn 32 static -../source/mongoose.c:15236:14:w5500_wn 32 static -../source/mongoose.c:15237:14:w5500_w1 24 static -../source/mongoose.c:15238:14:w5500_w2 40 static -../source/mongoose.c:15239:14:w5500_rn 32 static -../source/mongoose.c:15240:17:w5500_r1 32 static -../source/mongoose.c:15241:18:w5500_r2 32 static -../source/mongoose.c:15244:15:w5500_rx 48 static -../source/mongoose.c:15263:15:w5500_tx 48 static -../source/mongoose.c:15282:13:w5500_init 24 static -../source/mongoose.c:15296:13:w5500_up 24 static diff --git a/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/net.su b/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/net.su deleted file mode 100644 index 7d71776391..0000000000 --- a/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/net.su +++ /dev/null @@ -1,23 +0,0 @@ -../source/net.c:32:10:mg_now 16 static -../source/net.c:36:5:ui_event_next 24 static -../source/net.c:54:13:sfn 56 static -../source/net.c:68:13:timer_sntp_fn 16 static -../source/net.c:73:21:authenticate 160 static -../source/net.c:100:13:handle_login 296 static -../source/net.c:109:13:handle_logout 272 static -../source/net.c:119:13:handle_debug 32 static -../source/net.c:125:15:print_int_arr 48 static -../source/net.c:134:13:handle_stats_get 136 static -../source/net.c:143:15:print_events 144 static -../source/net.c:162:13:handle_events_get 64 static -../source/net.c:169:13:handle_settings_set 96 static -../source/net.c:190:13:handle_settings_get 96 static -../source/net.c:199:13:handle_firmware_upload 168 static -../source/net.c:228:13:handle_firmware_commit 32 static -../source/net.c:233:13:handle_firmware_rollback 32 static -../source/net.c:238:15:print_status 120 static -../source/net.c:246:13:handle_firmware_status 32 static -../source/net.c:251:13:handle_device_reset 32 static -../source/net.c:256:13:handle_device_eraselast 32 static -../source/net.c:265:13:fn 120 static -../source/net.c:322:6:web_init 32 static diff --git a/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/packed_fs.su b/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/packed_fs.su deleted file mode 100644 index fd912b7a81..0000000000 --- a/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/packed_fs.su +++ /dev/null @@ -1,3 +0,0 @@ -../source/packed_fs.c:2681:12:scmp 16 static -../source/packed_fs.c:2685:13:mg_unlist 16 static -../source/packed_fs.c:2688:13:mg_unpack 32 static diff --git a/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/subdir.mk b/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/subdir.mk deleted file mode 100644 index d6d8349292..0000000000 --- a/examples/nxp/rt1060-evk-xpresso-baremetal-builtin/Debug/source/subdir.mk +++ /dev/null @@ -1,43 +0,0 @@ -################################################################################ -# Automatically-generated file. Do not edit! -################################################################################ - -# Add inputs and outputs from these tool invocations to the build variables -C_SRCS += \ -../source/main.c \ -../source/mongoose.c \ -../source/net.c \ -../source/packed_fs.c \ -../source/syscalls.c - -C_DEPS += \ -./source/main.d \ -./source/mongoose.d \ -./source/net.d \ -./source/packed_fs.d \ -./source/syscalls.d - -OBJS += \ -./source/main.o \ -./source/mongoose.o \ -./source/net.o \ -./source/packed_fs.o \ -./source/syscalls.o - - -# Each subdirectory must supply rules for building sources it contributes -source/%.o: ../source/%.c source/subdir.mk - @echo 'Building file: $<' - @echo 'Invoking: MCU C Compiler' - arm-none-eabi-gcc -DCPU_MIMXRT1062DVL6B -DCPU_MIMXRT1062DVL6B_cm7 -DSDK_OS_BAREMETAL -DXIP_EXTERNAL_FLASH=1 -DXIP_BOOT_HEADER_ENABLE=1 -DSDK_DEBUGCONSOLE=1 -DSERIAL_PORT_TYPE_UART=1 -D__MCUXPRESSO -D__USE_CMSIS -DDEBUG -D__NEWLIB__ -I"/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/board" -I"/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/source" -I"/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/drivers" -I"/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/xip" -I"/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/CMSIS" -I"/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/device" -I"/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/component/serial_manager" -I"/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/component/uart" -I"/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/utilities" -I"/root/Documents/MCUXpresso_11.8.1_1197/workspace/rt1060-evk-xpresso-baremetal-builtin/component/lists" -O0 -fno-common -g3 -Wall -c -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -fmerge-constants -fmacro-prefix-map="$(is_listening) { - char *config = config_read(); - if (config != NULL) config_apply(mg_str(config)); - free(config); + struct mg_str config = mg_file_read(&mg_fs_posix, "config.json"); + if (config.ptr != NULL) config_apply(config); + free((char *) config.ptr); s_state.tcp.url = strdup(DEFAULT_TCP); s_state.websocket.url = strdup(DEFAULT_WEBSOCKET); s_state.mqtt.url = strdup(DEFAULT_MQTT); @@ -232,5 +226,4 @@ void uart_bridge_fn(struct mg_connection *c, int ev, void *ev_data, mg_http_serve_dir(c, ev_data, &opts); } } - (void) fn_data; } diff --git a/examples/video-stream/main.c b/examples/video-stream/main.c index 5bd731d527..e79077cca4 100644 --- a/examples/video-stream/main.c +++ b/examples/video-stream/main.c @@ -32,20 +32,19 @@ static void broadcast_mjpeg_frame(struct mg_mgr *mgr) { size_t nfiles = sizeof(files) / sizeof(files[0]); static size_t i; const char *path = files[i++ % nfiles]; - size_t size = 0; - char *data = mg_file_read(&mg_fs_posix, path, &size); // Read next file + struct mg_str data = mg_file_read(&mg_fs_posix, path); // Read next file struct mg_connection *c; for (c = mgr->conns; c != NULL; c = c->next) { - if (c->data[0] != 'S') continue; // Skip non-stream connections - if (data == NULL || size == 0) continue; // Skip on file read error + if (c->data[0] != 'S') continue; // Skip non-stream connections + if (data.ptr == NULL) continue; // Skip on file read error mg_printf(c, "--foo\r\nContent-Type: image/jpeg\r\n" "Content-Length: %lu\r\n\r\n", - (unsigned long) size); - mg_send(c, data, size); + data.len); + mg_send(c, data.ptr, data.len); mg_send(c, "\r\n", 2); } - free(data); + free((void *) data.ptr); } static void timer_callback(void *arg) { diff --git a/mongoose.c b/mongoose.c index 7cc14b4774..62fde56a3b 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1619,25 +1619,21 @@ void mg_fs_close(struct mg_fd *fd) { } } -char *mg_file_read(struct mg_fs *fs, const char *path, size_t *sizep) { - struct mg_fd *fd; - char *data = NULL; - size_t size = 0; - fs->st(path, &size, NULL); - if ((fd = mg_fs_open(fs, path, MG_FS_READ)) != NULL) { - data = (char *) calloc(1, size + 1); - if (data != NULL) { - if (fs->rd(fd->fd, data, size) != size) { - free(data); - data = NULL; - } else { - data[size] = '\0'; - if (sizep != NULL) *sizep = size; - } - } - mg_fs_close(fd); - } - return data; +struct mg_str mg_file_read(struct mg_fs *fs, const char *path) { + struct mg_str result = {NULL, 0}; + void *fp; + fs->st(path, &result.len, NULL); + if ((fp = fs->op(path, MG_FS_READ)) != NULL) { + result.ptr = (char *) calloc(1, result.len + 1); + if (result.ptr != NULL && + fs->rd(fp, (void *) result.ptr, result.len) != result.len) { + free((void *) result.ptr); + result.ptr = NULL; + } + fs->cl(fp); + } + if (result.ptr == NULL) result.len = 0; + return result; } bool mg_file_write(struct mg_fs *fs, const char *path, const void *buf, diff --git a/mongoose.h b/mongoose.h index 8295160a73..b1f3ec95de 100644 --- a/mongoose.h +++ b/mongoose.h @@ -1022,7 +1022,7 @@ struct mg_fd { struct mg_fd *mg_fs_open(struct mg_fs *fs, const char *path, int flags); void mg_fs_close(struct mg_fd *fd); bool mg_fs_ls(struct mg_fs *fs, const char *path, char *buf, size_t len); -char *mg_file_read(struct mg_fs *fs, const char *path, size_t *size); +struct mg_str mg_file_read(struct mg_fs *fs, const char *path); bool mg_file_write(struct mg_fs *fs, const char *path, const void *, size_t); bool mg_file_printf(struct mg_fs *fs, const char *path, const char *fmt, ...); diff --git a/src/fs.c b/src/fs.c index 5e84fa813c..758c8e2338 100644 --- a/src/fs.c +++ b/src/fs.c @@ -22,25 +22,21 @@ void mg_fs_close(struct mg_fd *fd) { } } -char *mg_file_read(struct mg_fs *fs, const char *path, size_t *sizep) { - struct mg_fd *fd; - char *data = NULL; - size_t size = 0; - fs->st(path, &size, NULL); - if ((fd = mg_fs_open(fs, path, MG_FS_READ)) != NULL) { - data = (char *) calloc(1, size + 1); - if (data != NULL) { - if (fs->rd(fd->fd, data, size) != size) { - free(data); - data = NULL; - } else { - data[size] = '\0'; - if (sizep != NULL) *sizep = size; - } +struct mg_str mg_file_read(struct mg_fs *fs, const char *path) { + struct mg_str result = {NULL, 0}; + void *fp; + fs->st(path, &result.len, NULL); + if ((fp = fs->op(path, MG_FS_READ)) != NULL) { + result.ptr = (char *) calloc(1, result.len + 1); + if (result.ptr != NULL && + fs->rd(fp, (void *) result.ptr, result.len) != result.len) { + free((void *) result.ptr); + result.ptr = NULL; } - mg_fs_close(fd); + fs->cl(fp); } - return data; + if (result.ptr == NULL) result.len = 0; + return result; } bool mg_file_write(struct mg_fs *fs, const char *path, const void *buf, diff --git a/src/fs.h b/src/fs.h index b09e9bdaae..3f87e0ad2d 100644 --- a/src/fs.h +++ b/src/fs.h @@ -40,7 +40,7 @@ struct mg_fd { struct mg_fd *mg_fs_open(struct mg_fs *fs, const char *path, int flags); void mg_fs_close(struct mg_fd *fd); bool mg_fs_ls(struct mg_fs *fs, const char *path, char *buf, size_t len); -char *mg_file_read(struct mg_fs *fs, const char *path, size_t *size); +struct mg_str mg_file_read(struct mg_fs *fs, const char *path); bool mg_file_write(struct mg_fs *fs, const char *path, const void *, size_t); bool mg_file_printf(struct mg_fs *fs, const char *path, const char *fmt, ...); diff --git a/test/unit_test.c b/test/unit_test.c index 4eefc0ec5c..1c5cd6fdf7 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -743,7 +743,7 @@ static int fetch(struct mg_mgr *mgr, char *buf, const char *url, if (c != NULL && mg_url_is_ssl(url)) { struct mg_tls_opts opts; memset(&opts, 0, sizeof(opts)); // read CA from packed_fs - opts.ca = mg_unpacked("test/data/ca.pem"); + opts.ca = mg_unpacked("/test/data/ca.pem"); if (strstr(url, "127.0.0.1") != NULL) { // Local connection, use self-signed certificates opts.ca = mg_str(s_tls_ca); @@ -998,10 +998,10 @@ static void test_http_server(void) { // ASSERT(cmpbody(buf, "Invalid web root [/BAAADDD!]\n") == 0); { - char *data = mg_file_read(&mg_fs_posix, "./test/data/ca.pem", NULL); + struct mg_str data = mg_file_read(&mg_fs_posix, "./test/data/ca.pem"); ASSERT(fetch(&mgr, buf, url, "GET /ca.pem HTTP/1.0\r\n\n") == 200); - ASSERT(cmpbody(buf, data) == 0); - free(data); + ASSERT(cmpbody(buf, data.ptr) == 0); + free((void *) data.ptr); } { @@ -1059,9 +1059,10 @@ static void test_http_server(void) { { // Test upload - char *p; + struct mg_str s; remove("uploaded.txt"); - ASSERT((p = mg_file_read(&mg_fs_posix, "uploaded.txt", NULL)) == NULL); + s = mg_file_read(&mg_fs_posix, "uploaded.txt"); + ASSERT(s.ptr == NULL); ASSERT(fetch(&mgr, buf, url, "POST /upload HTTP/1.0\n" "Content-Length: 1\n\nx") == 400); @@ -1074,22 +1075,25 @@ static void test_http_server(void) { "POST /upload?file=uploaded.txt&offset=5 HTTP/1.0\r\n" "Content-Length: 6\r\n" "\r\n\nworld") == 200); - ASSERT((p = mg_file_read(&mg_fs_posix, "uploaded.txt", NULL)) != NULL); - ASSERT(strcmp(p, "hello\nworld") == 0); - free(p); + s = mg_file_read(&mg_fs_posix, "uploaded.txt"); + ASSERT(s.ptr != NULL); + ASSERT(strcmp(s.ptr, "hello\nworld") == 0); + free((void *) s.ptr); remove("uploaded.txt"); } { // Test upload directory traversal - char *p; + struct mg_str s; remove("uploaded.txt"); - ASSERT((p = mg_file_read(&mg_fs_posix, "uploaded.txt", NULL)) == NULL); + s = mg_file_read(&mg_fs_posix, "uploaded.txt"); + ASSERT(s.ptr == NULL); ASSERT(fetch(&mgr, buf, url, "POST /upload?file=../uploaded.txt HTTP/1.0\r\n" "Content-Length: 5\r\n" "\r\nhello") == 400); - ASSERT((p = mg_file_read(&mg_fs_posix, "uploaded.txt", NULL)) == NULL); + s = mg_file_read(&mg_fs_posix, "uploaded.txt"); + ASSERT(s.ptr == NULL); } // HEAD request @@ -1238,10 +1242,12 @@ static void test_http_client(void) { struct mg_connection *c = NULL; const char *url = "http://cesanta.com"; int i, ok = 0; - size_t size = 0; // read CA certs from plain file - char *data = mg_file_read(&mg_fs_posix, "test/data/ca.pem", &size); struct mg_tls_opts opts; memset(&opts, 0, sizeof(opts)); + opts.ca = mg_unpacked("/test/data/ca.pem"); + opts.name = mg_url_host(url); + ASSERT(opts.ca.len > 0); + ASSERT(opts.name.len > 0); mg_mgr_init(&mgr); c = mg_http_connect(&mgr, url, f3, &ok); ASSERT(c != NULL); @@ -1255,17 +1261,12 @@ static void test_http_client(void) { #if MG_TLS c = mg_http_connect(&mgr, "https://cesanta.com", f3, &ok); ASSERT(c != NULL); - if (c != NULL) { - opts.ca = mg_str_n(data, size); - // opts.name = mg_url_host(url); - mg_tls_init(c, &opts); - } + mg_tls_init(c, &opts); for (i = 0; i < 1500 && ok <= 0; i++) mg_mgr_poll(&mgr, 1); ASSERT(ok == 200); c->is_closing = 1; mg_mgr_poll(&mgr, 1); -#if 1 // Test failed host validation c = mg_http_connect(&mgr, "https://cesanta.com", f3, &ok); ASSERT(c != NULL); @@ -1287,7 +1288,6 @@ static void test_http_client(void) { ASSERT(ok == 200); mg_mgr_poll(&mgr, 1); #endif -#endif #if MG_ENABLE_IPV6 ok = 0; @@ -1300,7 +1300,6 @@ static void test_http_client(void) { mg_mgr_free(&mgr); ASSERT(mgr.conns == NULL); - free(data); } // Test host validation only (no CA, no cert) @@ -1317,7 +1316,7 @@ static void test_host_validation(void) { ok = 0; c = mg_http_connect(&mgr, url, f3, &ok); ASSERT(c != NULL); - opts.ca = mg_unpacked("test/data/ca.pem"); + opts.ca = mg_unpacked("/test/data/ca.pem"); mg_tls_init(c, &opts); for (i = 0; i < 1500 && ok <= 0; i++) mg_mgr_poll(&mgr, 10); ASSERT(ok == 200); @@ -2188,15 +2187,17 @@ static void test_dns(void) { static void test_util(void) { const char *e; - char buf[100], *p, *s; + char buf[100], *s; struct mg_addr a; uint32_t ipv4; + struct mg_str data; memset(&a, 0xa5, sizeof(a)); ASSERT(mg_file_printf(&mg_fs_posix, "data.txt", "%s", "hi") == true); // if (system("ls -l") != 0) (void) 0; - ASSERT((p = mg_file_read(&mg_fs_posix, "data.txt", NULL)) != NULL); - ASSERT(strcmp(p, "hi") == 0); - free(p); + data = mg_file_read(&mg_fs_posix, "data.txt"); + ASSERT(data.ptr != NULL); + ASSERT(strcmp(data.ptr, "hi") == 0); + free((void *) data.ptr); remove("data.txt"); ASSERT(mg_aton(mg_str("0"), &a) == false); ASSERT(mg_aton(mg_str("0.0.0."), &a) == false); @@ -2610,8 +2611,8 @@ static void eh7(struct mg_connection *c, int ev, void *ev_data) { static void test_packed(void) { struct mg_mgr mgr; const char *url = "http://127.0.0.1:12351"; - char buf[FETCH_BUF_SIZE], - *data = mg_file_read(&mg_fs_posix, "Makefile", NULL); + char buf[FETCH_BUF_SIZE]; + struct mg_str data = mg_file_read(&mg_fs_posix, "Makefile"); mg_mgr_init(&mgr); mg_http_listen(&mgr, url, eh7, NULL); @@ -2619,14 +2620,14 @@ static void test_packed(void) { // fetch(&mgr, buf, url, "GET /Makefile HTTP/1.0\n\n"); // printf("---> %s\n", buf); ASSERT(fetch(&mgr, buf, url, "GET /Makefile HTTP/1.0\n\n") == 200); - ASSERT(cmpbody(buf, data) == 0); - free(data); + ASSERT(cmpbody(buf, data.ptr) == 0); + free((void *) data.ptr); // Load file deeper in the FS tree directly - data = mg_file_read(&mg_fs_posix, "src/ssi.h", NULL); + data = mg_file_read(&mg_fs_posix, "src/ssi.h"); ASSERT(fetch(&mgr, buf, url, "GET /src/ssi.h HTTP/1.0\n\n") == 200); - ASSERT(cmpbody(buf, data) == 0); - free(data); + ASSERT(cmpbody(buf, data.ptr) == 0); + free((void *) data.ptr); // List root dir ASSERT(fetch(&mgr, buf, url, "GET / HTTP/1.0\n\n") == 200);