Project

General

Profile

Bug #4692 » SAT-IP-Print-external-NAT-ip-and-port.patch.txt

Mono Polimorph, 2017-10-26 18:10

 
1
diff --git a/src/satip/rtsp.c b/src/satip/rtsp.c
2
index 7b366c8..a455628 100644
3
--- a/src/satip/rtsp.c
4
+++ b/src/satip/rtsp.c
5
@@ -92,6 +92,7 @@ static pthread_mutex_t rtsp_lock;
6
 static void rtsp_close_session(session_t *rs);
7
 static void rtsp_free_session(session_t *rs);
8

    
9
+static char any_ip[] = "127.0.0.1\0";
10

    
11
 /*
12
  *
13
@@ -1322,9 +1323,9 @@ rtsp_process_describe(http_connection_t *hc)
14
   char *u = tvh_strdupa(hc->hc_url);
15
   session_t *rs;
16
   htsbuf_queue_t q;
17
-  char buf[96];
18
+  char buf[96], *used_ip = NULL;
19
   int r = HTTP_STATUS_BAD_REQUEST;
20
-  int stream, first = 1, valid;
21
+  int stream, first = 1, valid, used_port;
22

    
23
   htsbuf_queue_init(&q, 0);
24

    
25
@@ -1381,10 +1382,19 @@ rtsp_process_describe(http_connection_t *hc)
26
   http_arg_init(&args);
27
   if (hc->hc_session)
28
     http_arg_set(&args, "Session", hc->hc_session);
29
-  if (stream > 0)
30
-    snprintf(buf, sizeof(buf), "rtsp://%s/stream=%i", rtsp_ip, stream);
31
+  if (rtsp_nat_ip != NULL)
32
+    used_ip = (rtsp_nat_ip[0] == '*' || rtsp_nat_ip[0] == '\0')? any_ip : rtsp_nat_ip;
33
   else
34
-    snprintf(buf, sizeof(buf), "rtsp://%s", rtsp_ip);
35
+    used_ip = rtsp_ip;
36
+  used_port = (rtsp_nat_port <= 0) ? rtsp_port : rtsp_nat_port;
37
+  if ((stream > 0) && (used_port != 554))
38
+    snprintf(buf, sizeof(buf), "rtsp://%s:%d/stream=%i", used_ip, used_port, stream);
39
+  else if ((stream > 0) && (used_port == 554))
40
+    snprintf(buf, sizeof(buf), "rtsp://%s/stream=%i", used_ip, stream);
41
+  else if (used_port != 554)
42
+    snprintf(buf, sizeof(buf), "rtsp://%s:%d", used_ip, used_port);
43
+  else
44
+    snprintf(buf, sizeof(buf), "rtsp://%s", used_ip);
45
   http_arg_set(&args, "Content-Base", buf);
46
   http_send_begin(hc);
47
   http_send_header(hc, HTTP_STATUS_OK, "application/sdp", q.hq_size,
48
@@ -1408,8 +1418,8 @@ static int
49
 rtsp_process_play(http_connection_t *hc, int cmd)
50
 {
51
   session_t *rs;
52
-  int errcode = HTTP_STATUS_BAD_REQUEST, valid = 0, i, stream;
53
-  char buf[256], *u = tvh_strdupa(hc->hc_url);
54
+  int errcode = HTTP_STATUS_BAD_REQUEST, valid = 0, i, stream, used_port;
55
+  char buf[256], *u = tvh_strdupa(hc->hc_url), *used_ip = NULL;
56
   http_arg_list_t args;
57

    
58
   http_arg_init(&args);
59
@@ -1467,10 +1477,15 @@ rtsp_process_play(http_connection_t *hc, int cmd)
60
     snprintf(buf, sizeof(buf), "%d", rs->stream);
61
     http_arg_set(&args, "com.ses.streamID", buf);
62
   } else {
63
-    if (rtsp_port != 554)
64
-      snprintf(buf, sizeof(buf), "url=rtsp://%s:%d/stream=%d", rtsp_ip, rtsp_port, rs->stream);
65
+    if (rtsp_nat_ip != NULL)
66
+      used_ip = (rtsp_nat_ip[0] == '*' || rtsp_nat_ip[0] == '\0')? any_ip : rtsp_nat_ip;
67
+    else
68
+      used_ip = rtsp_ip;
69
+    used_port = (rtsp_nat_port <= 0) ? rtsp_port : rtsp_nat_port;
70
+    if (used_port != 554)
71
+      snprintf(buf, sizeof(buf), "url=rtsp://%s:%d/stream=%d", used_ip, used_port, rs->stream);
72
     else
73
-      snprintf(buf, sizeof(buf), "url=rtsp://%s/stream=%d", rtsp_ip, rs->stream);
74
+      snprintf(buf, sizeof(buf), "url=rtsp://%s/stream=%d", used_ip, rs->stream);
75
     http_arg_set(&args, "RTP-Info", buf);
76
   }
77

    
(1-1/3)