]> git.sesse.net Git - vlc/commitdiff
- Add httpd_ServerIP() to obtain HTTP server's IP used with a given client
authorRémi Denis-Courmont <rem@videolan.org>
Fri, 29 Jul 2005 17:53:50 +0000 (17:53 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Fri, 29 Jul 2005 17:53:50 +0000 (17:53 +0000)
(much like httpd_ClientIP())
- Rewrite httpd_ClientIP() to use existing API and not use malloc/free

include/vlc_httpd.h
include/vlc_symbols.h
modules/misc/rtsp.c
modules/stream_out/rtp.c
src/misc/httpd.c

index 7947d679cf55f2fb3c54458c6cb5a5b1a2883d85..eca57d32435a82c5726a235c3a490734a3461368 100644 (file)
@@ -131,7 +131,8 @@ VLC_EXPORT( void,           httpd_UrlDelete, ( httpd_url_t * ) );
 /* Default client mode is FILE, use these to change it */
 VLC_EXPORT( void,           httpd_ClientModeStream, ( httpd_client_t *cl ) );
 VLC_EXPORT( void,           httpd_ClientModeBidir, ( httpd_client_t *cl ) );
-VLC_EXPORT( char*,          httpd_ClientIP, ( httpd_client_t *cl ) );
+VLC_EXPORT( char*,          httpd_ClientIP, ( httpd_client_t *cl, char *psz_ip ) );
+VLC_EXPORT( char*,          httpd_ServerIP, ( httpd_client_t *cl, char *psz_ip ) );
 
 /* High level */
 
index fcee70bd6c7c842f5eb58c2e22423748a8f8930e..6357101c6f4621d052da331449870594f5bb34fd 100644 (file)
@@ -201,7 +201,7 @@ struct module_symbols_t
     void (*httpd_UrlDelete_inner) (httpd_url_t *);
     void (*httpd_ClientModeStream_inner) (httpd_client_t *cl);
     void (*httpd_ClientModeBidir_inner) (httpd_client_t *cl);
-    char* (*httpd_ClientIP_inner) (httpd_client_t *cl);
+    char* (*httpd_ClientIP_inner) (httpd_client_t *cl, char *psz_ip);
     httpd_file_t * (*httpd_FileNew_inner) (httpd_host_t *, char *psz_url, char *psz_mime, char *psz_user, char *psz_password, const vlc_acl_t *p_acl, httpd_file_callback_t pf_fill, httpd_file_sys_t *);
     void (*httpd_FileDelete_inner) (httpd_file_t *);
     httpd_redirect_t * (*httpd_RedirectNew_inner) (httpd_host_t *, char *psz_url_dst, char *psz_url_src);
@@ -382,6 +382,7 @@ struct module_symbols_t
     int (*ACL_LoadFile_inner) (vlc_acl_t *p_acl, const char *path);
     int (*ACL_AddNet_inner) (vlc_acl_t *p_acl, const char *psz_ip, int i_len, vlc_bool_t b_allow);
     void (*ACL_Destroy_inner) (vlc_acl_t *p_acl);
+    char* (*httpd_ServerIP_inner) (httpd_client_t *cl, char *psz_ip);
 };
 # if defined (__PLUGIN__)
 #  define aout_FiltersCreatePipeline (p_symbols)->aout_FiltersCreatePipeline_inner
@@ -749,6 +750,7 @@ struct module_symbols_t
 #  define ACL_LoadFile (p_symbols)->ACL_LoadFile_inner
 #  define ACL_AddNet (p_symbols)->ACL_AddNet_inner
 #  define ACL_Destroy (p_symbols)->ACL_Destroy_inner
+#  define httpd_ServerIP (p_symbols)->httpd_ServerIP_inner
 # elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)
 /******************************************************************
  * STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.
@@ -1119,6 +1121,7 @@ struct module_symbols_t
     ((p_symbols)->ACL_LoadFile_inner) = ACL_LoadFile; \
     ((p_symbols)->ACL_AddNet_inner) = ACL_AddNet; \
     ((p_symbols)->ACL_Destroy_inner) = ACL_Destroy; \
+    ((p_symbols)->httpd_ServerIP_inner) = httpd_ServerIP; \
     (p_symbols)->net_ConvertIPv4_deprecated = NULL; \
 
 # endif /* __PLUGIN__ */
index f0eaecf9ce871e1c1179d5317c40f3be9687f238..8bbfaa8d0fbf721af6180130a5411468b19c0681 100644 (file)
@@ -171,7 +171,7 @@ static int RtspCallback( httpd_callback_sys_t *, httpd_client_t *,
 static int RtspCallbackES( httpd_callback_sys_t *, httpd_client_t *,
                            httpd_message_t *, httpd_message_t * );
 
-static char *SDPGenerate( const vod_media_t * );
+static char *SDPGenerate( const vod_media_t *, httpd_client_t *cl );
 
 static void sprintf_hexa( char *s, uint8_t *p_data, int i_data )
 {
@@ -623,7 +623,7 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
         case HTTPD_MSG_DESCRIBE:
         {
             char *psz_sdp =
-                SDPGenerate( p_media );
+                SDPGenerate( p_media, cl );
 
             answer->i_status = 200;
             answer->psz_status = strdup( "OK" );
@@ -636,7 +636,7 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
 
         case HTTPD_MSG_PLAY:
         {
-            char *psz_output, *ip;
+            char *psz_output, ip[NI_MAXNUMERICHOST];
             int i, i_port_audio = 0, i_port_video = 0;
 
             /* for now only multicast so easy */
@@ -660,7 +660,7 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
             }
             else if( p_rtsp->b_playing ) break;
 
-            if( !(ip = httpd_ClientIP( cl )) ) break;
+            if( httpd_ClientIP( cl, ip ) == NULL ) break;
 
             p_rtsp->b_playing = VLC_TRUE;
 
@@ -687,7 +687,6 @@ static int RtspCallback( httpd_callback_sys_t *p_args, httpd_client_t *cl,
             vod_MediaControl( p_vod, p_media, psz_session, VOD_MEDIA_PLAY,
                               psz_output );
             free( psz_output );
-            free( ip );
             break;
         }
 
@@ -773,11 +772,11 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
         {
             rtsp_client_t *p_rtsp;
             rtsp_client_es_t *p_rtsp_es;
-            char *ip = httpd_ClientIP( cl );
+            char ip[NI_MAXNUMERICHOST];
             int i_port = atoi( strstr( psz_transport, "client_port=" ) +
                                strlen("client_port=") );
 
-            if( !ip )
+            if( httpd_ClientIP( cl, ip ) == NULL )
             {
                 answer->i_status = 500;
                 answer->psz_status = strdup( "Internal server error" );
@@ -935,10 +934,10 @@ static int RtspCallbackES( httpd_callback_sys_t *p_args, httpd_client_t *cl,
  * SDPGenerate: TODO
  * FIXME: need to be moved to a common place ?
  *****************************************************************************/
-static char *SDPGenerate( const vod_media_t *p_media )
+static char *SDPGenerate( const vod_media_t *p_media, httpd_client_t *cl )
 {
     int i, i_size;
-    char *p, *psz_sdp;
+    char *p, *psz_sdp, *ip;
 
     /* Calculate size */
     i_size = strlen( "v=0\r\n" ) +
index 7da13f5f02a363f2ce300883ea5a3ce14b85ec14..3ab642b61ad897d4ec789a35b8bece8721498355 100644 (file)
@@ -1641,7 +1641,7 @@ static int  RtspCallbackId( httpd_callback_sys_t *p_args,
             else if( strstr( psz_transport, "unicast" ) && strstr( psz_transport, "client_port=" ) )
             {
                 int  i_port = atoi( strstr( psz_transport, "client_port=" ) + strlen("client_port=") );
-                char *ip    = httpd_ClientIP( cl );
+                char ip[NI_MAXNUMERICHOST];
 
                 char psz_access[100];
                 char psz_url[100];
@@ -1650,7 +1650,7 @@ static int  RtspCallbackId( httpd_callback_sys_t *p_args,
 
                 rtsp_client_t *rtsp = NULL;
 
-                if( ip == NULL )
+                if( httpd_ClientIP( cl, ip ) == NULL )
                 {
                     answer->i_status = 500;
                     answer->psz_status = strdup( "Internal server error" );
@@ -1679,7 +1679,6 @@ static int  RtspCallbackId( httpd_callback_sys_t *p_args,
                         answer->psz_status = strdup( "Unknown session id" );
                         answer->i_body = 0;
                         answer->p_body = NULL;
-                        free( ip );
                         break;
                     }
                 }
@@ -1690,8 +1689,7 @@ static int  RtspCallbackId( httpd_callback_sys_t *p_args,
                 else
                     sprintf( psz_access, "udp{raw}" );
                 sprintf( psz_url, "%s:%d", ip, i_port );
-                free( ip );
-                
+
                 if( ( p_access = sout_AccessOutNew( p_stream->p_sout, psz_access, psz_url ) ) == NULL )
                 {
                     msg_Err( p_stream, "cannot create the access out for %s://%s",
index 6109ce5ce36ad3440edad4ace642358810e431a6..7c33d54a1cb9e7f77a517d761c1f1bb4c79acab4 100644 (file)
@@ -1329,20 +1329,14 @@ void httpd_ClientModeBidir( httpd_client_t *cl )
     cl->i_mode   = HTTPD_CLIENT_BIDIR;
 }
 
-char* httpd_ClientIP( httpd_client_t *cl )
+char* httpd_ClientIP( httpd_client_t *cl, char *psz_ip )
 {
-    int i;
-    char *psz_ip = malloc( NI_MAXNUMERICHOST );
-
-    if( psz_ip == NULL )
-        return NULL;
-
-    i = vlc_getnameinfo( (const struct sockaddr *)&cl->sock, cl->i_sock_size,
-                         psz_ip, NI_MAXNUMERICHOST, NULL, NI_NUMERICHOST );
-    if( i )
-        return NULL;
+    return net_GetPeerAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
+}
 
-    return psz_ip;
+char* httpd_ServerIP( httpd_client_t *cl, char *psz_ip )
+{
+    return net_GetSockAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
 }
 
 static void httpd_ClientClean( httpd_client_t *cl )