Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
SAT>IP server: send replies to multicast M-SEARCH request from correc…
…t UDP port
  • Loading branch information
perexg committed Nov 1, 2015
1 parent 7358b22 commit aeb20ca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/input/mpegts/satip/satip.c
Expand Up @@ -1164,7 +1164,7 @@ ST: urn:ses-com:device:SatIPServer:1\r\n"
htsbuf_append(&q, MSG, sizeof(MSG)-1);
htsbuf_qprintf(&q, "USER-AGENT: unix/1.0 UPnP/1.1 TVHeadend/%s\r\n", tvheadend_version);
htsbuf_append(&q, "\r\n", 2);
upnp_send(&q, NULL, 0);
upnp_send(&q, NULL, 0, 0);
htsbuf_queue_flush(&q);

gtimer_arm_ms(&satip_discovery_msearch_timer, satip_discovery_send_msearch,
Expand Down
14 changes: 7 additions & 7 deletions src/satip/server.c
Expand Up @@ -264,7 +264,7 @@ CONFIGID.UPNP.ORG: 0\r\n\

htsbuf_queue_init(&q, 0);
htsbuf_append(&q, buf, strlen(buf));
upnp_send(&q, NULL, attempt * 11);
upnp_send(&q, NULL, attempt * 11, 1);
htsbuf_queue_flush(&q);
}
#undef MSG
Expand Down Expand Up @@ -322,15 +322,15 @@ DEVICEID.SES.COM: %d\r\n\r\n"

htsbuf_queue_init(&q, 0);
htsbuf_append(&q, buf, strlen(buf));
upnp_send(&q, NULL, attempt * 11);
upnp_send(&q, NULL, attempt * 11, 1);
htsbuf_queue_flush(&q);
}
#undef MSG
}

static void
satips_upnp_send_discover_reply
(struct sockaddr_storage *dst, const char *deviceid)
(struct sockaddr_storage *dst, const char *deviceid, int from_multicast)
{
#define MSG "\
HTTP/1.1 200 OK\r\n\
Expand Down Expand Up @@ -366,7 +366,7 @@ CONFIGID.UPNP.ORG: 0\r\n"
htsbuf_qprintf(&q, "DEVICEID.SES.COM: %s", deviceid);
htsbuf_append(&q, "\r\n", 2);
storage = *dst;
upnp_send(&q, &storage, 0);
upnp_send(&q, &storage, 0, from_multicast);
htsbuf_queue_flush(&q);
#undef MSG
}
Expand Down Expand Up @@ -471,14 +471,14 @@ satips_upnp_discovery_received
tcp_get_str_from_ip((struct sockaddr *)storage, buf2, sizeof(buf2));
tvhwarn("satips", "received duplicate SAT>IP DeviceID %s from %s:%d, using %d",
deviceid, buf2, ntohs(IP_PORT(*storage)), satip_server_deviceid);
satips_upnp_send_discover_reply(storage, deviceid);
satips_upnp_send_discover_reply(storage, deviceid, 0);
satips_upnp_send_byebye();
satips_upnp_send_announce();
} else {
satips_upnp_send_discover_reply(storage, NULL);
satips_upnp_send_discover_reply(storage, NULL, 0);
}
} else {
satips_upnp_send_discover_reply(storage, NULL);
satips_upnp_send_discover_reply(storage, NULL, 1);
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/upnp.c
Expand Up @@ -50,6 +50,7 @@ typedef struct upnp_data {
struct sockaddr_storage storage;
htsbuf_queue_t queue;
int delay_ms;
int from_multicast;
} upnp_data_t;

TAILQ_HEAD(upnp_data_queue_write, upnp_data);
Expand Down Expand Up @@ -82,7 +83,8 @@ void upnp_service_destroy( upnp_service_t *us )
*
*/
void
upnp_send( htsbuf_queue_t *q, struct sockaddr_storage *storage, int delay_ms )
upnp_send( htsbuf_queue_t *q, struct sockaddr_storage *storage,
int delay_ms, int from_multicast )
{
upnp_data_t *data;

Expand All @@ -96,6 +98,7 @@ upnp_send( htsbuf_queue_t *q, struct sockaddr_storage *storage, int delay_ms )
else
data->storage = *storage;
data->delay_ms = delay_ms;
data->from_multicast = from_multicast;
pthread_mutex_lock(&upnp_lock);
TAILQ_INSERT_TAIL(&upnp_data_write, data, data_link);
pthread_mutex_unlock(&upnp_lock);
Expand Down Expand Up @@ -196,7 +199,8 @@ upnp_thread( void *aux )
if (data == NULL)
break;
upnp_dump_data(data);
udp_write_queue(unicast, &data->queue, &data->storage);
udp_write_queue(data->from_multicast ? multicast : unicast,
&data->queue, &data->storage);
htsbuf_queue_flush(&data->queue);
free(data);
delay_ms = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/upnp.h
Expand Up @@ -39,7 +39,8 @@ upnp_service_t *upnp_service_create0(upnp_service_t *us);
upnp_service_create0(calloc(1, sizeof(struct us)))
void upnp_service_destroy(upnp_service_t *service);

void upnp_send(htsbuf_queue_t *q, struct sockaddr_storage *storage, int delay_ms);
void upnp_send(htsbuf_queue_t *q, struct sockaddr_storage *storage,
int delay_ms, int from_multicast);

void upnp_server_init(const char *bindaddr);
void upnp_server_done(void);
Expand Down

0 comments on commit aeb20ca

Please sign in to comment.