]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
IPTV RTSP: add basic authentication
authorJaroslav Kysela <perex@perex.cz>
Thu, 7 May 2015 13:09:51 +0000 (15:09 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 7 May 2015 13:09:51 +0000 (15:09 +0200)
src/http.h
src/httpc.c
src/input/mpegts/iptv/iptv_rtsp.c
src/rtsp.c

index ebd3ec8c0585b7bb605709fa2e956424c765c1a8..4dd0c06865924e7cacc5f014702089e8c7159df5 100644 (file)
@@ -320,6 +320,8 @@ struct http_client {
   int          hc_rtp_multicast:1;
   long         hc_rtsp_stream_id;
   int          hc_rtp_timeout;
+  char        *hc_rtsp_user;
+  char        *hc_rtsp_pass;
 
   struct http_client_ssl *hc_ssl; /* ssl internals */
 
@@ -344,6 +346,8 @@ void http_client_close ( http_client_t *hc );
 int http_client_send( http_client_t *hc, http_cmd_t cmd,
                       const char *path, const char *query,
                       http_arg_list_t *header, void *body, size_t body_size );
+void http_client_basic_auth( http_client_t *hc, http_arg_list_t *h,
+                             const char *user, const char *pass );
 int http_client_simple( http_client_t *hc, const url_t *url);
 int http_client_clear_state( http_client_t *hc );
 int http_client_run( http_client_t *hc );
index 0995d506ca91df1f4d8771b5df7ab22e5a74c2a3..4bdbeb1d6a5a32000a48f7e50c36c853efd89489 100644 (file)
@@ -1036,6 +1036,31 @@ header:
   goto retry;
 }
 
+/*
+ *
+ */
+void
+http_client_basic_auth( http_client_t *hc, http_arg_list_t *h,
+                        const char *user, const char *pass )
+{
+  if (user && user[0] && pass && pass[0]) {
+#define BASIC "Basic "
+    size_t plen = strlen(pass);
+    size_t ulen = strlen(user);
+    size_t len = BASE64_SIZE(plen + ulen + 1) + 1;
+    char *buf = alloca(ulen + 1 + plen + 1);
+    char *cbuf = alloca(len + sizeof(BASIC) + 1);
+    strcpy(buf, user);
+    strcat(buf, ":");
+    strcat(buf, pass);
+    strcpy(cbuf, BASIC);
+    base64_encode(cbuf + sizeof(BASIC) - 1, len,
+                  (uint8_t *)buf, ulen + 1 + plen);
+    http_arg_set(h, "Authorization", cbuf);
+#undef BASIC
+  }
+}
+
 /*
  * Redirected
  */
@@ -1060,22 +1085,7 @@ http_client_basic_args ( http_client_t *hc, http_arg_list_t *h, const url_t *url
   }
   if (!keepalive)
     http_arg_set(h, "Connection", "close");
-  if (url->user && url->user[0] && url->pass && url->pass[0]) {
-#define BASIC "Basic "
-    size_t plen = strlen(url->pass);
-    size_t ulen = strlen(url->user);
-    size_t len = BASE64_SIZE(plen + ulen + 1) + 1;
-    char *buf = alloca(ulen + 1 + plen + 1);
-    char *cbuf = alloca(len + sizeof(BASIC) + 1);
-    strcpy(buf, url->user);
-    strcat(buf, ":");
-    strcat(buf, url->pass);
-    strcpy(cbuf, BASIC);
-    base64_encode(cbuf + sizeof(BASIC) - 1, len,
-                  (uint8_t *)buf, ulen + 1 + plen);
-    http_arg_set(h, "Authorization", cbuf);
-#undef BASIC
-  }
+  http_client_basic_auth(hc, h, url->user, url->pass);
 }
 
 static int
@@ -1398,6 +1408,8 @@ http_client_close ( http_client_t *hc )
   free(hc->hc_host);
   free(hc->hc_scheme);
   free(hc->hc_bindaddr);
+  free(hc->hc_rtsp_user);
+  free(hc->hc_rtsp_pass);
   free(hc);
 }
 
index 842468890f5e83ffdf50102cf7462fa7e94a9934..906867905bcdf125c1fb86ba7e3dd739cab77deb 100644 (file)
@@ -135,6 +135,11 @@ iptv_rtsp_start
                                  u->host, u->port, NULL)))
     return SM_CODE_TUNING_FAILED;
 
+  if (u->user)
+    hc->hc_rtsp_user = strdup(u->user);
+  if (u->pass)
+    hc->hc_rtsp_pass = strdup(u->pass);
+
   if (udp_bind_double(&rtp, &rtpc,
                       "IPTV", "rtp", "rtcp",
                       NULL, 0, NULL,
index 58a38b7c63282b92165cc65700ef0dbf4d206292..a851fa0d96474da1f53aaf621749f872b63326ab 100644 (file)
@@ -46,6 +46,7 @@ rtsp_send( http_client_t *hc, http_cmd_t cmd,
     }
     http_arg_set(hdr, "Session", hc->hc_rtsp_session);
   }
+  http_client_basic_auth(hc, hdr, hc->hc_rtsp_user, hc->hc_rtsp_pass);
   if (hc->hc_port != 554)
     snprintf(buf2, sizeof(buf2), ":%d", hc->hc_port);
   else