return NULL;
}
+/**
+ *
+ */
+int
+http_check_local_ip( http_connection_t *hc )
+{
+ if (hc->hc_local_ip == NULL) {
+ hc->hc_local_ip = malloc(sizeof(*hc->hc_local_ip));
+ *hc->hc_local_ip = *hc->hc_self;
+ hc->hc_is_local_ip = ip_check_is_local_address(hc->hc_peer, hc->hc_self, hc->hc_local_ip) > 0;
+ }
+ return hc->hc_is_local_ip;
+}
+
/**
* Transmit a HTTP reply
*/
free(hc->hc_nonce);
hc->hc_nonce = NULL;
+ free(hc->hc_local_ip);
}
char *hc_peer_ipstr;
struct sockaddr_storage *hc_self;
char *hc_representative;
+ struct sockaddr_storage *hc_local_ip;
pthread_mutex_t *hc_paths_mutex;
http_path_list_t *hc_paths;
char *hc_url;
char *hc_url_orig;
- int hc_keep_alive;
htsbuf_queue_t hc_reply;
char *hc_nonce;
access_t *hc_access;
- struct config_head *hc_user_config;
-
- int hc_no_output;
- int hc_shutdown;
+ /* RTSP */
uint64_t hc_cseq;
char *hc_session;
+ /* Flags */
+ uint8_t hc_keep_alive;
+ uint8_t hc_no_output;
+ uint8_t hc_shutdown;
+ uint8_t hc_is_local_ip; /*< a connection from the local network */
+
/* Support for HTTP POST */
char *hc_post_data;
void http_cancel(void *opaque);
+int http_check_local_ip(http_connection_t *hc);
+
typedef int (http_callback_t)(http_connection_t *hc,
const char *remain, void *opaque);
static void rtsp_close_session(session_t *rs);
static void rtsp_free_session(session_t *rs);
+/*
+ *
+ */
+static inline int rtsp_is_nat_active(void)
+{
+ return rtsp_nat_ip[0] != '\0';
+}
+
/*
*
*/
if (strcmp(u, rtsp_ip)) {
if (rtsp_nat_ip == NULL)
return NULL;
- if (rtsp_nat_ip[0] != '*')
- if (rtsp_nat_ip[0] == '\0' || strcmp(u, rtsp_nat_ip))
+ if (rtsp_is_nat_active()) {
+ if (rtsp_nat_ip[0] != '*' && strcmp(u, rtsp_nat_ip))
return NULL;
+ }
}
return p ? p + 1 : u + strlen(u);
}
{
const char *used_ip = rtsp_ip;
int used_port = rtsp_port, local;
- struct sockaddr_storage self;
- if (rtsp_nat_ip[0] == '\0')
+ if (!rtsp_is_nat_active())
goto end;
- self = *hc->hc_self;
- /* note: call ip_check at first to initialize self (ip any) */
- local = ip_check_is_local_address(hc->hc_peer, hc->hc_self, &self);
+ /* note: it initializes hc->hc_local_ip, too */
+ local = http_check_local_ip(hc) > 0;
if (local || satip_server_conf.satip_nat_name_force) {
used_ip = rtsp_nat_ip;
if (rtsp_nat_port > 0)
if (used_ip[0] == '*' || used_ip[0] == '\0' || used_ip == NULL) {
if (local) {
- tcp_get_str_from_ip(&self, buf, buflen);
+ tcp_get_str_from_ip(hc->hc_local_ip, buf, buflen);
used_ip = buf;
} else {
used_ip = "127.0.0.1";