Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2612 - struct mg_str::ptr -> buf #2650

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/arduino/teensy41-http/teensy41-http.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ static void simple_http_listener(struct mg_connection *c, int ev, void *ev_data)
// Content-Length header automatically. In the response, we show
// the requested URI and HTTP body:
mg_http_reply(c, 200, "", "{%m:%m,%m:%m}\n", // See mg_snprintf doc
MG_ESC("uri"), mg_print_esc, hm->uri.len, hm->uri.ptr,
MG_ESC("body"), mg_print_esc, hm->body.len, hm->body.ptr);
MG_ESC("uri"), mg_print_esc, hm->uri.len, hm->uri.buf,
MG_ESC("body"), mg_print_esc, hm->body.len, hm->body.buf);
} else {
// For all other URIs, serve some static content
mg_http_reply(c, 200, "", "<html>millis: %lu</html>", millis());
Expand Down
4 changes: 2 additions & 2 deletions examples/arduino/w5500-mqtt/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
// Received MQTT message
struct mg_mqtt_message *mm = (struct mg_mqtt_message *) ev_data;
MG_INFO(("%lu RECEIVED %.*s <- %.*s", c->id, (int) mm->data.len,
mm->data.ptr, (int) mm->topic.len, mm->topic.ptr));
exec_command(mm->data.ptr, mm->data.len);
mm->data.buf, (int) mm->topic.len, mm->topic.buf));
exec_command(mm->data.buf, mm->data.len);
} else if (ev == MG_EV_CLOSE) {
MG_INFO(("%lu CLOSED", c->id));
mqtt_connection = NULL;
Expand Down
4 changes: 2 additions & 2 deletions examples/device-dashboard/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static void handle_firmware_upload(struct mg_connection *c,
mg_http_reply(c, 500, "", "offset and total not set\n");
} else if (ofs == 0 && mg_ota_begin((size_t) tot) == false) {
mg_http_reply(c, 500, "", "mg_ota_begin(%ld) failed\n", tot);
} else if (data.len > 0 && mg_ota_write(data.ptr, data.len) == false) {
} else if (data.len > 0 && mg_ota_write(data.buf, data.len) == false) {
mg_http_reply(c, 500, "", "mg_ota_write(%lu) @%ld failed\n", data.len, ofs);
mg_ota_end();
} else if (data.len == 0 && mg_ota_end() == false) {
Expand Down Expand Up @@ -313,7 +313,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
mg_http_serve_dir(c, ev_data, &opts);
}
MG_DEBUG(("%lu %.*s %.*s -> %.*s", c->id, (int) hm->method.len,
hm->method.ptr, (int) hm->uri.len, hm->uri.ptr, (int) 3,
hm->method.buf, (int) hm->uri.len, hm->uri.buf, (int) 3,
&c->send.buf[9]));
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/esp32/uart-bridge/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct mg_str config_read(void) {
}

void config_write(struct mg_str config) {
mg_file_write(&mg_fs_posix, FS_ROOT "/config.json", config.ptr, config.len);
mg_file_write(&mg_fs_posix, FS_ROOT "/config.json", config.buf, config.len);
}

void app_main(void) {
Expand All @@ -22,13 +22,13 @@ void app_main(void) {

// Try to connect to wifi by using saved WiFi credentials
struct mg_str json = mg_file_read(&mg_fs_posix, WIFI_FILE);
if (json.ptr != NULL) {
if (json.buf != 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((void *) json.ptr);
free((void *) json.buf);
} else {
// If WiFi is not configured, run CLI until configured
MG_INFO(("WiFi is not configured, running CLI. Press enter"));
Expand Down
4 changes: 2 additions & 2 deletions examples/esp8266/http-client-server/src/main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ static void cb(struct mg_connection *c, int ev, void *ev_data) {
static void cb2(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_CONNECT) {
struct mg_str s = mg_url_host(CLIENT_URL);
mg_printf(c, "GET / HTTP/1.0\r\nHost: %.*s\r\n\r\n", (int) s.len, s.ptr);
mg_printf(c, "GET / HTTP/1.0\r\nHost: %.*s\r\n\r\n", (int) s.len, s.buf);
} else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = ev_data; // Print HTTP response
MG_INFO(("Fetched:\n%.*s", (int) hm->message.len, hm->message.ptr));
MG_INFO(("Fetched:\n%.*s", (int) hm->message.len, hm->message.buf));
c->is_draining = 1;
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/file-transfer/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
"Host: %.*s\r\n"
"Content-Type: octet-stream\r\n"
"Content-Length: %d\r\n",
mg_url_uri(s_url), (int) host.len, host.ptr, fsize);
mg_url_uri(s_url), (int) host.len, host.buf, fsize);
mg_http_bauth(c, s_user, s_pass); // Add Basic auth header
mg_printf(c, "%s", "\r\n"); // End HTTP headers
} else if (ev == MG_EV_WRITE && c->send.len < MG_IO_SIZE) {
Expand All @@ -53,7 +53,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
MG_DEBUG(("MSG"));
// Response is received. Print it
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
printf("%.*s", (int) hm->body.len, hm->body.ptr);
printf("%.*s", (int) hm->body.len, hm->body.buf);
c->is_draining = 1; // Tell mongoose to close this connection
mg_fs_close(fd);
*(bool *) c->fn_data = true; // Tell event loop to stop
Expand Down
2 changes: 1 addition & 1 deletion examples/file-transfer/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static void handle_uploads(struct mg_connection *c, int ev, void *ev_data) {
} else {
char fpath[MG_PATH_MAX];
snprintf(fpath, MG_PATH_MAX, "%s%c", s_upld_dir, MG_DIRSEP);
strncat(fpath, hm->uri.ptr + 8, hm->uri.len - 8);
strncat(fpath, hm->uri.buf + 8, hm->uri.len - 8);
if (!mg_path_is_sane(fpath)) {
mg_http_reply(c, 400, "", "Invalid path\n");
c->is_draining = 1; // Tell mongoose to close this connection
Expand Down
6 changes: 3 additions & 3 deletions examples/file-upload-html-form/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ static void cb(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
MG_INFO(("New request to: [%.*s], body size: %lu", (int) hm->uri.len,
hm->uri.ptr, (unsigned long) hm->body.len));
hm->uri.buf, (unsigned long) hm->body.len));
if (mg_http_match_uri(hm, "/upload")) {
struct mg_http_part part;
size_t ofs = 0;
while ((ofs = mg_http_next_multipart(hm->body, ofs, &part)) > 0) {
MG_INFO(("Chunk name: [%.*s] filename: [%.*s] length: %lu bytes",
(int) part.name.len, part.name.ptr, (int) part.filename.len,
part.filename.ptr, (unsigned long) part.body.len));
(int) part.name.len, part.name.buf, (int) part.filename.len,
part.filename.buf, (unsigned long) part.body.len));
}
mg_http_reply(c, 200, "", "Thank you!");
} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/file-upload-single-post/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static void handle_uploads(struct mg_connection *c, int ev, void *ev_data) {
if (mg_match(hm->uri, mg_str("/upload/*"), NULL)) {
char path[MG_PATH_MAX];
mg_snprintf(path, sizeof(path), "%s/%.*s", UPLOAD_DIR, hm->uri.len - 8,
hm->uri.ptr + 8);
hm->uri.buf + 8);
us->expected = hm->body.len; // Store number of bytes we expect
mg_iobuf_del(&c->recv, 0, hm->head.len); // Delete HTTP headers
c->pfn = NULL; // Silence HTTP protocol handler, we'll use MG_EV_READ
Expand Down
4 changes: 2 additions & 2 deletions examples/http-client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
"Content-Length: %d\r\n"
"\r\n",
s_post_data ? "POST" : "GET", mg_url_uri(s_url), (int) host.len,
host.ptr, content_length);
host.buf, content_length);
mg_send(c, s_post_data, content_length);
} else if (ev == MG_EV_HTTP_MSG) {
// Response is received. Print it
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
printf("%.*s", (int) hm->message.len, hm->message.ptr);
printf("%.*s", (int) hm->message.len, hm->message.buf);
c->is_draining = 1; // Tell mongoose to close this connection
*(bool *) c->fn_data = true; // Tell event loop to stop
} else if (ev == MG_EV_ERROR) {
Expand Down
10 changes: 5 additions & 5 deletions examples/http-proxy-client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
static bool connected;
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
printf("%.*s", (int) hm->message.len, hm->message.ptr);
printf("%.*s", (int) hm->message.len, hm->message.buf);
exit(EXIT_SUCCESS);
} else if (ev == MG_EV_CONNECT) {
// Proxy TCP connection established. Send CONNECT request
Expand All @@ -29,8 +29,8 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {

// c->is_hexdumping = 1;
mg_printf(c, "CONNECT %.*s:%hu HTTP/1.1\r\nHost: %.*s:%hu\r\n\r\n",
(int) host.len, host.ptr, mg_url_port(url), (int) host.len,
host.ptr, mg_url_port(url));
(int) host.len, host.buf, mg_url_port(url), (int) host.len,
host.buf, mg_url_port(url));
} else if (!connected && ev == MG_EV_READ) {
struct mg_http_message hm;
int n = mg_http_parse((char *) c->recv.buf, c->recv.len, &hm);
Expand All @@ -39,14 +39,14 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
// CONNECT response - tunnel is established
connected = true;
MG_DEBUG(
("Connected to proxy, status: %.*s", (int) hm.uri.len, hm.uri.ptr));
("Connected to proxy, status: %.*s", (int) hm.uri.len, hm.uri.buf));
mg_iobuf_del(&c->recv, 0, n);
// Send request to the target server
mg_printf(c,
"GET %s HTTP/1.0\r\n"
"Host: %.*s\r\n"
"\r\n",
mg_url_uri(url), (int) host.len, host.ptr);
mg_url_uri(url), (int) host.len, host.buf);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/http-restful-server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
mg_http_printf_chunk(c, ""); // Don't forget the last empty chunk
} else if (mg_http_match_uri(hm, "/api/f2/*")) {
mg_http_reply(c, 200, "", "{\"result\": \"%.*s\"}\n", (int) hm->uri.len,
hm->uri.ptr);
hm->uri.buf);
} else {
struct mg_http_serve_opts opts = {.root_dir = s_root_dir};
mg_http_serve_dir(c, ev_data, &opts);
Expand Down
12 changes: 6 additions & 6 deletions examples/http-reverse-proxy/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ static void forward_request(struct mg_http_message *hm,
size_t i, max = sizeof(hm->headers) / sizeof(hm->headers[0]);
struct mg_str host = mg_url_host(s_backend_url);
mg_printf(c, "%.*s\r\n",
(int) (hm->proto.ptr + hm->proto.len - hm->message.ptr),
hm->message.ptr);
(int) (hm->proto.buf + hm->proto.len - hm->message.buf),
hm->message.buf);
for (i = 0; i < max && hm->headers[i].name.len > 0; i++) {
struct mg_str *k = &hm->headers[i].name, *v = &hm->headers[i].value;
if (mg_strcmp(*k, mg_str("Host")) == 0) v = &host;
mg_printf(c, "%.*s: %.*s\r\n", (int) k->len, k->ptr, (int) v->len, v->ptr);
mg_printf(c, "%.*s: %.*s\r\n", (int) k->len, k->buf, (int) v->len, v->buf);
}
mg_send(c, "\r\n", 2);
mg_send(c, hm->body.ptr, hm->body.len);
MG_DEBUG(("FORWARDING: %.*s %.*s", (int) hm->method.len, hm->method.ptr,
(int) hm->uri.len, hm->uri.ptr));
mg_send(c, hm->body.buf, hm->body.len);
MG_DEBUG(("FORWARDING: %.*s %.*s", (int) hm->method.len, hm->method.buf,
(int) hm->uri.len, hm->uri.buf));
}

static void fn2(struct mg_connection *c, int ev, void *ev_data) {
Expand Down
12 changes: 6 additions & 6 deletions examples/http-server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ static void cb(struct mg_connection *c, int ev, void *ev_data) {
while ((pos = mg_http_next_multipart(hm->body, pos, &part)) > 0) {
char path[MG_PATH_MAX];
MG_INFO(("Chunk name: [%.*s] filename: [%.*s] length: %lu bytes",
part.name.len, part.name.ptr, part.filename.len,
part.filename.ptr, part.body.len));
part.name.len, part.name.buf, part.filename.len,
part.filename.buf, part.body.len));
mg_snprintf(path, sizeof(path), "%s/%.*s", s_upload_dir,
part.filename.len, part.filename.ptr);
part.filename.len, part.filename.buf);
if (mg_path_is_sane(path)) {
mg_file_write(&mg_fs_posix, path, part.body.ptr, part.body.len);
mg_file_write(&mg_fs_posix, path, part.body.buf, part.body.len);
total_bytes += part.body.len;
num_files++;
} else {
Expand All @@ -57,8 +57,8 @@ static void cb(struct mg_connection *c, int ev, void *ev_data) {
}

// Log request
MG_INFO(("%.*s %.*s %lu -> %.*s %lu", hm->method.len, hm->method.ptr,
hm->uri.len, hm->uri.ptr, hm->body.len, 3, c->send.buf + 9,
MG_INFO(("%.*s %.*s %lu -> %.*s %lu", hm->method.len, hm->method.buf,
hm->uri.len, hm->uri.buf, hm->body.len, 3, c->send.buf + 9,
c->send.len));
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/http-streaming-client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
"Connection: close\r\n"
"Host: %.*s\r\n"
"\r\n",
mg_url_uri(s_url), (int) host.len, host.ptr);
mg_url_uri(s_url), (int) host.len, host.buf);
} else if (ev == MG_EV_READ) {
// c->data[0] holds a flag, whether we have parsed the request already
if (c->data[0] == 0) {
Expand Down
2 changes: 1 addition & 1 deletion examples/huge-response/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
const char *headers = "content-type: text/json\r\n";
long start = getparam(hm, "$.start");
long version = getparam(hm, "$.version");
MG_DEBUG(("%.*s", (int) hm->body.len, hm->body.ptr));
MG_DEBUG(("%.*s", (int) hm->body.len, hm->body.buf));
if (version > 0 && version != s_version) {
// Version mismatch: s_data has changed while client fetches it
// Tell client to restart
Expand Down
8 changes: 4 additions & 4 deletions examples/microchip/same54-xpro/mqtt-client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
sub_opts.topic = subt;
sub_opts.qos = s_qos;
mg_mqtt_sub(c, &sub_opts);
MG_INFO(("%lu SUBSCRIBED to %.*s", c->id, (int) subt.len, subt.ptr));
MG_INFO(("%lu SUBSCRIBED to %.*s", c->id, (int) subt.len, subt.buf));
struct mg_mqtt_opts pub_opts;
memset(&pub_opts, 0, sizeof(pub_opts));
pub_opts.topic = pubt;
pub_opts.message = data;
pub_opts.qos = s_qos, pub_opts.retain = false;
mg_mqtt_pub(c, &pub_opts);
MG_INFO(("%lu PUBLISHED %.*s -> %.*s", c->id, (int) data.len, data.ptr,
(int) pubt.len, pubt.ptr));
MG_INFO(("%lu PUBLISHED %.*s -> %.*s", c->id, (int) data.len, data.buf,
(int) pubt.len, pubt.buf));
} else if (ev == MG_EV_MQTT_MSG) {
// When we get echo response, print it
struct mg_mqtt_message *mm = (struct mg_mqtt_message *) ev_data;
MG_INFO(("%lu RECEIVED %.*s <- %.*s", c->id, (int) mm->data.len,
mm->data.ptr, (int) mm->topic.len, mm->topic.ptr));
mm->data.buf, (int) mm->topic.len, mm->topic.buf));
} else if (ev == MG_EV_CLOSE) {
MG_INFO(("%lu CLOSED", c->id));
s_conn = NULL; // Mark that we're closed
Expand Down
4 changes: 2 additions & 2 deletions examples/mip-pcap/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static void fn2(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data;
MG_DEBUG(("Got response (%d) %.*s...", (int) hm->message.len, 12,
hm->message.ptr));
hm->message.buf));
c->is_draining = 1;
} else if (ev == MG_EV_CONNECT) {
mg_printf(c, "GET %s HTTP/1.1\r\n\r\n", mg_url_uri((char *) c->fn_data));
Expand All @@ -72,7 +72,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
}
} else {
mg_http_reply(c, 200, NULL, "%.*s\r\n", (int) hm->message.len,
hm->message.ptr);
hm->message.buf);
}
}
(void) ev_data;
Expand Down
6 changes: 3 additions & 3 deletions examples/modbus-dashboard/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ static void signal_handler(int sig_num) {
bool web_load_settings(void *buf, size_t len) {
bool ok = false;
struct mg_str data = mg_file_read(&mg_fs_posix, CONFIG_FILE);
if (data.ptr == NULL) {
if (data.buf == NULL) {
MG_ERROR(("Error reading %s", CONFIG_FILE));
} else if (data.len != len) {
MG_ERROR(("%s size != %lu", CONFIG_FILE, len));
} else {
memcpy(buf, data.ptr, len);
memcpy(buf, data.buf, len);
}
free((void *) data.ptr);
free((void *) data.buf);
return ok;
}

Expand Down
6 changes: 3 additions & 3 deletions examples/modbus-dashboard/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static struct mg_connection *start_modbus_request(struct mg_mgr *mgr,
uint16_t reg = (uint16_t) mg_json_get_long(json, "$.reg", 1);
uint8_t func = (uint8_t) mg_json_get_long(json, "$.func", 0);
uint16_t nregs = (uint16_t) mg_json_get_long(json, "$.nregs", 1);
MG_INFO(("%lu REQUEST: %.*s", cid, json.len, json.ptr));
MG_INFO(("%lu REQUEST: %.*s", cid, json.len, json.buf));
if (func == 0) {
MG_ERROR(("Set func to a valid modbus function code"));
} else if ((c = mg_connect(mgr, url, mfn, NULL)) == NULL) {
Expand Down Expand Up @@ -275,8 +275,8 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
#endif
mg_http_serve_dir(c, ev_data, &opts);
}
MG_DEBUG(("%lu %.*s %.*s", c->id, (int) hm->method.len, hm->method.ptr,
(int) hm->uri.len, hm->uri.ptr));
MG_DEBUG(("%lu %.*s %.*s", c->id, (int) hm->method.len, hm->method.buf,
(int) hm->uri.len, hm->uri.buf));
} else if (ev == MG_EV_POLL) {
if (cd->expiration_time > 0 && cd->expiration_time < mg_millis()) {
cd->expiration_time = 0;
Expand Down
4 changes: 2 additions & 2 deletions examples/mqtt-client-aws-iot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
} else if (ev == MG_EV_MQTT_MSG) {
// When we receive MQTT message, print it
struct mg_mqtt_message *mm = (struct mg_mqtt_message *) ev_data;
MG_INFO(("Received on %.*s : %.*s", (int) mm->topic.len, mm->topic.ptr,
(int) mm->data.len, mm->data.ptr));
MG_INFO(("Received on %.*s : %.*s", (int) mm->topic.len, mm->topic.buf,
(int) mm->data.len, mm->data.buf));
} else if (ev == MG_EV_POLL && c->data[0] == 'X') {
static unsigned long prev_second;
unsigned long now_second = (*(unsigned long *) ev_data) / 1000;
Expand Down
8 changes: 4 additions & 4 deletions examples/mqtt-client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
sub_opts.topic = subt;
sub_opts.qos = s_qos;
mg_mqtt_sub(c, &sub_opts);
MG_INFO(("%lu SUBSCRIBED to %.*s", c->id, (int) subt.len, subt.ptr));
MG_INFO(("%lu SUBSCRIBED to %.*s", c->id, (int) subt.len, subt.buf));
struct mg_mqtt_opts pub_opts;
memset(&pub_opts, 0, sizeof(pub_opts));
pub_opts.topic = pubt;
pub_opts.message = data;
pub_opts.qos = s_qos, pub_opts.retain = false;
mg_mqtt_pub(c, &pub_opts);
MG_INFO(("%lu PUBLISHED %.*s -> %.*s", c->id, (int) data.len, data.ptr,
(int) pubt.len, pubt.ptr));
MG_INFO(("%lu PUBLISHED %.*s -> %.*s", c->id, (int) data.len, data.buf,
(int) pubt.len, pubt.buf));
} else if (ev == MG_EV_MQTT_MSG) {
// When we get echo response, print it
struct mg_mqtt_message *mm = (struct mg_mqtt_message *) ev_data;
MG_INFO(("%lu RECEIVED %.*s <- %.*s", c->id, (int) mm->data.len,
mm->data.ptr, (int) mm->topic.len, mm->topic.ptr));
mm->data.buf, (int) mm->topic.len, mm->topic.buf));
} else if (ev == MG_EV_CLOSE) {
MG_INFO(("%lu CLOSED", c->id));
s_conn = NULL; // Mark that we're closed
Expand Down
Loading
Loading