]> git.sesse.net Git - vlc/blob - modules/misc/lua/acl.c
Merge branch 'master' of git@git.videolan.org:vlc
[vlc] / modules / misc / lua / acl.c
1 /*****************************************************************************
2  * acl.c: Access list related functions
3  *****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea at videolan tod org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #ifndef  _GNU_SOURCE
28 #   define  _GNU_SOURCE
29 #endif
30
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include <vlc/vlc.h>
36 #include <vlc_acl.h>
37
38 #include <lua.h>        /* Low level lua C API */
39 #include <lauxlib.h>    /* Higher level C API */
40 #include <lualib.h>     /* Lua libs */
41
42 #include "vlc.h"
43
44 /*****************************************************************************
45  *
46  *****************************************************************************/
47 int vlclua_acl_create( lua_State *L )
48 {
49     vlc_object_t *p_this = vlclua_get_this( L );
50     bool b_allow = luaL_checkboolean( L, 1 ) ? true : false;
51     vlc_acl_t *p_acl = ACL_Create( p_this, b_allow );
52     if( !p_acl )
53         return luaL_error( L, "ACL creation failed." );
54     lua_pushlightuserdata( L, p_acl ); /* FIXME */
55     return 1;
56 }
57
58 int vlclua_acl_delete( lua_State *L )
59 {
60     vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 );
61     ACL_Destroy( p_acl );
62     return 0;
63 }
64
65 int vlclua_acl_check( lua_State *L )
66 {
67     vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 );
68     const char *psz_ip = luaL_checkstring( L, 2 );
69     lua_pushinteger( L, ACL_Check( p_acl, psz_ip ) );
70     return 1;
71 }
72
73 int vlclua_acl_duplicate( lua_State *L )
74 {
75     vlc_object_t *p_this = vlclua_get_this( L );
76     vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 );
77     vlc_acl_t *p_acl_new = ACL_Duplicate( p_this, p_acl );
78     lua_pushlightuserdata( L, p_acl_new );
79     return 1;
80 }
81
82 int vlclua_acl_add_host( lua_State *L )
83 {
84     vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 );
85     const char *psz_ip = luaL_checkstring( L, 2 );
86     bool b_allow = luaL_checkboolean( L, 3 ) ? true : false;
87     lua_pushinteger( L, ACL_AddHost( p_acl, psz_ip, b_allow ) );
88     return 1;
89 }
90
91 int vlclua_acl_add_net( lua_State *L )
92 {
93     vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 );
94     const char *psz_ip = luaL_checkstring( L, 2 );
95     int i_len = luaL_checkint( L, 3 );
96     bool b_allow = luaL_checkboolean( L, 4 ) ? true : false;
97     lua_pushinteger( L, ACL_AddNet( p_acl, psz_ip, i_len, b_allow ) );
98     return 1;
99 }
100
101 int vlclua_acl_load_file( lua_State *L )
102 {
103     vlc_acl_t *p_acl = (vlc_acl_t*)luaL_checklightuserdata( L, 1 );
104     const char *psz_path = luaL_checkstring( L, 2 );
105     lua_pushinteger( L, ACL_LoadFile( p_acl, psz_path ) );
106     return 1;
107 }