mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-10 16:31:44 +00:00
Merge pull request #1614 from cesanta/udp-ssdp-search
Added parsing of remote responses
This commit is contained in:
1 file changed
+16
-1
@@ -8,11 +8,26 @@ static const char *s_ssdp_url = "udp://239.255.255.250:1900";
|
|||||||
static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
|
||||||
MG_DEBUG(("%p got event: %d %p %p", c, ev, ev_data, fn_data));
|
MG_DEBUG(("%p got event: %d %p %p", c, ev, ev_data, fn_data));
|
||||||
if (ev == MG_EV_OPEN) {
|
if (ev == MG_EV_OPEN) {
|
||||||
c->is_hexdumping = 1;
|
// c->is_hexdumping = 1;
|
||||||
} else if (ev == MG_EV_RESOLVE) {
|
} else if (ev == MG_EV_RESOLVE) {
|
||||||
// c->rem gets populated with multicast address. Store it in c->label
|
// c->rem gets populated with multicast address. Store it in c->label
|
||||||
memcpy(c->label, &c->rem, sizeof(c->rem));
|
memcpy(c->label, &c->rem, sizeof(c->rem));
|
||||||
} else if (ev == MG_EV_READ) {
|
} else if (ev == MG_EV_READ) {
|
||||||
|
MG_INFO(("Got a response"));
|
||||||
|
struct mg_http_message hm;
|
||||||
|
if (mg_http_parse((const char *) c->recv.buf, c->recv.len, &hm) > 0) {
|
||||||
|
size_t i, max = sizeof(hm.headers) / sizeof(hm.headers[0]);
|
||||||
|
// Iterate over request headers
|
||||||
|
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_vcasecmp(k, "SERVER") == 0) ||
|
||||||
|
(mg_vcasecmp(k, "LOCATION") == 0)) {
|
||||||
|
printf("\t%.*s -> %.*s\n", (int) k->len, k->ptr, (int) v->len,
|
||||||
|
v->ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
// Each response to the SSDP socket will change c->rem.
|
// Each response to the SSDP socket will change c->rem.
|
||||||
// We can now do mg_printf(c, "haha"); to respond back to the remote side.
|
// We can now do mg_printf(c, "haha"); to respond back to the remote side.
|
||||||
// But in our case, we should restore the multicast address in order
|
// But in our case, we should restore the multicast address in order
|
||||||
|
|||||||
Reference in new issue
Block a user