]> git.sesse.net Git - vlc/blobdiff - src/network/acl.c
net_Printf: automagic cast to VLC object
[vlc] / src / network / acl.c
index 47b331865df4d9830a6bd96642b7d7fa20326ce9..3c39dd7b89da542b2914cd861c3dc125b01d85e0 100644 (file)
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>
+#include <vlc_common.h>
 
 #include <ctype.h>
 #include <vlc_acl.h>
 
-#include <errno.h>
-
 #include <vlc_network.h>
 #include <vlc_charset.h>
 
@@ -189,9 +187,6 @@ int ACL_AddNet( vlc_acl_t *p_acl, const char *psz_ip, int i_len,
 
         if( i_len > 128 )
             i_len = 128;
-        else
-        if( i_len < 0 )
-            i_len = 0;
     }
     else
         i_len = 128; /* ACL_AddHost */
@@ -204,7 +199,7 @@ int ACL_AddNet( vlc_acl_t *p_acl, const char *psz_ip, int i_len,
     return 0;
 }
 
-
+#undef ACL_Create
 /**
  * Creates an empty ACL.
  *
@@ -213,7 +208,7 @@ int ACL_AddNet( vlc_acl_t *p_acl, const char *psz_ip, int i_len,
  *
  * @return an ACL object. NULL in case of error.
  */
-vlc_acl_t *__ACL_Create( vlc_object_t *p_this, bool b_allow )
+vlc_acl_t *ACL_Create( vlc_object_t *p_this, bool b_allow )
 {
     vlc_acl_t *p_acl;
 
@@ -221,7 +216,7 @@ vlc_acl_t *__ACL_Create( vlc_object_t *p_this, bool b_allow )
     if( p_acl == NULL )
         return NULL;
 
-    vlc_object_yield( p_this );
+    vlc_object_hold( p_this );
     p_acl->p_owner = p_this;
     p_acl->i_size = 0;
     p_acl->p_entries = NULL;
@@ -230,7 +225,7 @@ vlc_acl_t *__ACL_Create( vlc_object_t *p_this, bool b_allow )
     return p_acl;
 }
 
-
+#undef ACL_Duplicate
 /**
  * Perform a deep copy of an existing ACL.
  *
@@ -239,7 +234,7 @@ vlc_acl_t *__ACL_Create( vlc_object_t *p_this, bool b_allow )
  *
  * @return a new ACL object, or NULL on error.
  */
-vlc_acl_t *__ACL_Duplicate( vlc_object_t *p_this, const vlc_acl_t *p_acl )
+vlc_acl_t *ACL_Duplicate( vlc_object_t *p_this, const vlc_acl_t *p_acl )
 {
     vlc_acl_t *p_dupacl;
 
@@ -267,7 +262,7 @@ vlc_acl_t *__ACL_Duplicate( vlc_object_t *p_this, const vlc_acl_t *p_acl )
     else
         p_dupacl->p_entries = NULL;
 
-    vlc_object_yield( p_this );
+    vlc_object_hold( p_this );
     p_dupacl->p_owner = p_this;
     p_dupacl->i_size = p_acl->i_size;
     p_dupacl->b_allow_default = p_acl->b_allow_default;
@@ -283,9 +278,7 @@ void ACL_Destroy( vlc_acl_t *p_acl )
 {
     if( p_acl != NULL )
     {
-        if( p_acl->p_entries != NULL )
-            free( p_acl->p_entries );
-
+        free( p_acl->p_entries );
         vlc_object_release( p_acl->p_owner );
         free( p_acl );
     }
@@ -338,7 +331,7 @@ int ACL_LoadFile( vlc_acl_t *p_acl, const char *psz_path )
             continue;
 
         ptr = strchr( psz_ip, '\n' );
-        if( ptr == NULL )
+        if( ptr == NULL && !feof(file) )
         {
             msg_Warn( p_acl->p_owner, "skipping overly long line in %s",
                       psz_path);
@@ -359,16 +352,15 @@ int ACL_LoadFile( vlc_acl_t *p_acl, const char *psz_path )
             continue; /* skip unusable line */
         }
 
-        /* skips comment-only line */
-        if( *psz_ip == '#' )
-            continue;
-
-        /* looks for first space, CR, LF, etc. or end-of-line comment */
-        /* (there is at least a linefeed) */
-        for( ptr = psz_ip; ( *ptr != '#' ) && !isspace( *ptr ); ptr++ );
+        /* look for first space, CR, LF, etc. or comment character */
+        for( ptr = psz_ip; ( *ptr!='#' ) && !isspace( *ptr ) && *ptr; ++ptr );
 
         *ptr = '\0';
 
+        /* skip lines without usable information */
+        if( ptr == psz_ip )
+            continue;
+
         msg_Dbg( p_acl->p_owner, "restricted to %s", psz_ip );
 
         ptr = strchr( psz_ip, '/' );
@@ -380,7 +372,7 @@ int ACL_LoadFile( vlc_acl_t *p_acl, const char *psz_path )
             : ACL_AddHost( p_acl, psz_ip, true ) )
         {
             msg_Err( p_acl->p_owner, "cannot add ACL from %s", psz_path );
-            goto error;
+            continue;
         }
     }