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

This commit is contained in:
Sergey Lyubka committed 2024-04-16 22:42:45 +01:00
1 parent e93d18d200
commit e0e599ffa1
61 files changed
+684 -686

No files matched your search

+25 -25
View File
@@ -170,9 +170,9 @@ static void mg_send_mqtt_properties(struct mg_connection *c,
switch (mqtt_prop_type_by_id(props[i].id)) {
case MQTT_PROP_TYPE_STRING_PAIR:
mg_send_u16(c, mg_htons((uint16_t) props[i].key.len));
mg_send(c, props[i].key.ptr, props[i].key.len);
mg_send(c, props[i].key.buf, props[i].key.len);
mg_send_u16(c, mg_htons((uint16_t) props[i].val.len));
mg_send(c, props[i].val.ptr, props[i].val.len);
mg_send(c, props[i].val.buf, props[i].val.len);
break;
case MQTT_PROP_TYPE_BYTE:
mg_send(c, &props[i].iv, sizeof(uint8_t));
@@ -185,11 +185,11 @@ static void mg_send_mqtt_properties(struct mg_connection *c,
break;
case MQTT_PROP_TYPE_STRING:
mg_send_u16(c, mg_htons((uint16_t) props[i].val.len));
mg_send(c, props[i].val.ptr, props[i].val.len);
mg_send(c, props[i].val.buf, props[i].val.len);
break;
case MQTT_PROP_TYPE_BINARY_DATA:
mg_send_u16(c, mg_htons((uint16_t) props[i].val.len));
mg_send(c, props[i].val.ptr, props[i].val.len);
mg_send(c, props[i].val.buf, props[i].val.len);
break;
case MQTT_PROP_TYPE_VARIABLE_INT:
len = encode_varint(buf_v, props[i].iv);
@@ -201,8 +201,8 @@ static void mg_send_mqtt_properties(struct mg_connection *c,
size_t mg_mqtt_next_prop(struct mg_mqtt_message *msg, struct mg_mqtt_prop *prop,
size_t ofs) {
uint8_t *i = (uint8_t *) msg->dgram.ptr + msg->props_start + ofs;
uint8_t *end = (uint8_t *) msg->dgram.ptr + msg->dgram.len;
uint8_t *i = (uint8_t *) msg->dgram.buf + msg->props_start + ofs;
uint8_t *end = (uint8_t *) msg->dgram.buf + msg->dgram.len;
size_t new_pos = ofs, len;
prop->id = i[0];
@@ -213,10 +213,10 @@ size_t mg_mqtt_next_prop(struct mg_mqtt_message *msg, struct mg_mqtt_prop *prop,
switch (mqtt_prop_type_by_id(prop->id)) {
case MQTT_PROP_TYPE_STRING_PAIR:
prop->key.len = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
prop->key.ptr = (char *) i + 2;
prop->key.buf = (char *) i + 2;
i += 2 + prop->key.len;
prop->val.len = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
prop->val.ptr = (char *) i + 2;
prop->val.buf = (char *) i + 2;
new_pos += 2 * sizeof(uint16_t) + prop->val.len + prop->key.len;
break;
case MQTT_PROP_TYPE_BYTE:
@@ -234,12 +234,12 @@ size_t mg_mqtt_next_prop(struct mg_mqtt_message *msg, struct mg_mqtt_prop *prop,
break;
case MQTT_PROP_TYPE_STRING:
prop->val.len = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
prop->val.ptr = (char *) i + 2;
prop->val.buf = (char *) i + 2;
new_pos += 2 + prop->val.len;
break;
case MQTT_PROP_TYPE_BINARY_DATA:
prop->val.len = (uint16_t) ((((uint16_t) i[0]) << 8) | i[1]);
prop->val.ptr = (char *) i + 2;
prop->val.buf = (char *) i + 2;
new_pos += 2 + prop->val.len;
break;
case MQTT_PROP_TYPE_VARIABLE_INT:
@@ -298,24 +298,24 @@ void mg_mqtt_login(struct mg_connection *c, const struct mg_mqtt_opts *opts) {
if (c->is_mqtt5) mg_send_mqtt_properties(c, opts->props, opts->num_props);
mg_send_u16(c, mg_htons((uint16_t) cid.len));
mg_send(c, cid.ptr, cid.len);
mg_send(c, cid.buf, cid.len);
if (hdr[7] & MQTT_HAS_WILL) {
if (c->is_mqtt5)
mg_send_mqtt_properties(c, opts->will_props, opts->num_will_props);
mg_send_u16(c, mg_htons((uint16_t) opts->topic.len));
mg_send(c, opts->topic.ptr, opts->topic.len);
mg_send(c, opts->topic.buf, opts->topic.len);
mg_send_u16(c, mg_htons((uint16_t) opts->message.len));
mg_send(c, opts->message.ptr, opts->message.len);
mg_send(c, opts->message.buf, opts->message.len);
}
if (opts->user.len > 0) {
mg_send_u16(c, mg_htons((uint16_t) opts->user.len));
mg_send(c, opts->user.ptr, opts->user.len);
mg_send(c, opts->user.buf, opts->user.len);
}
if (opts->pass.len > 0) {
mg_send_u16(c, mg_htons((uint16_t) opts->pass.len));
mg_send(c, opts->pass.ptr, opts->pass.len);
mg_send(c, opts->pass.buf, opts->pass.len);
}
}
@@ -323,14 +323,14 @@ void mg_mqtt_pub(struct mg_connection *c, const struct mg_mqtt_opts *opts) {
uint8_t flags = (uint8_t) (((opts->qos & 3) << 1) | (opts->retain ? 1 : 0));
size_t len = 2 + opts->topic.len + opts->message.len;
MG_DEBUG(("%lu [%.*s] -> [%.*s]", c->id, (int) opts->topic.len,
(char *) opts->topic.ptr, (int) opts->message.len,
(char *) opts->message.ptr));
(char *) opts->topic.buf, (int) opts->message.len,
(char *) opts->message.buf));
if (opts->qos > 0) len += 2;
if (c->is_mqtt5) len += get_props_size(opts->props, opts->num_props);
mg_mqtt_send_header(c, MQTT_CMD_PUBLISH, flags, (uint32_t) len);
mg_send_u16(c, mg_htons((uint16_t) opts->topic.len));
mg_send(c, opts->topic.ptr, opts->topic.len);
mg_send(c, opts->topic.buf, opts->topic.len);
if (opts->qos > 0) {
if (++c->mgr->mqtt_id == 0) ++c->mgr->mqtt_id;
mg_send_u16(c, mg_htons(c->mgr->mqtt_id));
@@ -338,7 +338,7 @@ void mg_mqtt_pub(struct mg_connection *c, const struct mg_mqtt_opts *opts) {
if (c->is_mqtt5) mg_send_mqtt_properties(c, opts->props, opts->num_props);
if (opts->message.len > 0) mg_send(c, opts->message.ptr, opts->message.len);
if (opts->message.len > 0) mg_send(c, opts->message.buf, opts->message.len);
}
void mg_mqtt_sub(struct mg_connection *c, const struct mg_mqtt_opts *opts) {
@@ -352,7 +352,7 @@ void mg_mqtt_sub(struct mg_connection *c, const struct mg_mqtt_opts *opts) {
if (c->is_mqtt5) mg_send_mqtt_properties(c, opts->props, opts->num_props);
mg_send_u16(c, mg_htons((uint16_t) opts->topic.len));
mg_send(c, opts->topic.ptr, opts->topic.len);
mg_send(c, opts->topic.buf, opts->topic.len);
mg_send(c, &qos_, sizeof(qos_));
}
@@ -362,7 +362,7 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version,
uint32_t n = 0, len_len = 0;
memset(m, 0, sizeof(*m));
m->dgram.ptr = (char *) buf;
m->dgram.buf = (char *) buf;
if (len < 2) return MQTT_INCOMPLETE;
m->cmd = (uint8_t) (buf[0] >> 4);
m->qos = (buf[0] >> 1) & 3;
@@ -400,7 +400,7 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version,
case MQTT_CMD_PUBLISH: {
if (p + 2 > end) return MQTT_MALFORMED;
m->topic.len = (uint16_t) ((((uint16_t) p[0]) << 8) | p[1]);
m->topic.ptr = (char *) p + 2;
m->topic.buf = (char *) p + 2;
p += 2 + m->topic.len;
if (p > end) return MQTT_MALFORMED;
if (m->qos > 0) {
@@ -417,7 +417,7 @@ int mg_mqtt_parse(const uint8_t *buf, size_t len, uint8_t version,
p += len_len + m->props_size;
}
if (p > end) return MQTT_MALFORMED;
m->data.ptr = (char *) p;
m->data.buf = (char *) p;
m->data.len = (size_t) (end - p);
break;
}
@@ -439,7 +439,7 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data) {
break;
} else if (rc == MQTT_OK) {
MG_VERBOSE(("%lu MQTT CMD %d len %d [%.*s]", c->id, mm.cmd,
(int) mm.dgram.len, (int) mm.data.len, mm.data.ptr));
(int) mm.dgram.len, (int) mm.data.len, mm.data.buf));
switch (mm.cmd) {
case MQTT_CMD_CONNACK:
mg_call(c, MG_EV_MQTT_OPEN, &mm.ack);
@@ -452,7 +452,7 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data) {
break;
case MQTT_CMD_PUBLISH: {
/*MG_DEBUG(("%lu [%.*s] -> [%.*s]", c->id, (int) mm.topic.len,
mm.topic.ptr, (int) mm.data.len, mm.data.ptr));*/
mm.topic.buf, (int) mm.data.len, mm.data.buf));*/
if (mm.qos > 0) {
uint16_t id = mg_ntohs(mm.id);
uint32_t remaining_len = sizeof(id);