]> git.sesse.net Git - vlc/blob - include/httpd.h
* configure.ac:
[vlc] / include / httpd.h
1 /*****************************************************************************
2  * httpd.h
3  *****************************************************************************
4  * Copyright (C) 2001-2003 VideoLAN
5  * $Id: httpd.h,v 1.7 2003/07/11 09:50:10 gbazin Exp $
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 typedef struct httpd_host_t     httpd_host_t;
25
26 typedef struct httpd_file_t     httpd_file_t;
27 //typedef struct httpd_stream_t   httpd_stream_t;
28 typedef httpd_file_t httpd_stream_t;
29
30 typedef struct httpd_file_callback_args_t httpd_file_callback_args_t;
31 typedef int (*httpd_file_callback)( httpd_file_callback_args_t *p_args,
32     uint8_t *p_request, int i_request, uint8_t **pp_data, int *pi_data );
33
34 typedef struct httpd_sys_t httpd_sys_t;
35
36 enum httpdControl_e
37 {
38     HTTPD_GET_HOSTS,
39     HTTPD_GET_URLS,
40     HTTPD_GET_CONNECTIONS,
41     HTTPD_GET_ACL,          /* not implemented */
42
43     HTTPD_SET_CLOSE,
44     HTTPD_SET_ACL           /* not implemented */
45 };
46
47 typedef struct
48 {
49     char *psz_name;
50     char *psz_value;
51 } httpd_val_t;
52
53 typedef struct
54 {
55     int         i_count;
56     httpd_val_t *info;
57 } httpd_info_t;
58
59
60 typedef struct httpd_t httpd_t;
61
62 struct httpd_t
63 {
64     VLC_COMMON_MEMBERS
65
66     module_t        *p_module;
67     httpd_sys_t     *p_sys;
68
69     httpd_host_t   *(*pf_register_host)     ( httpd_t *, char *, int );
70     void            (*pf_unregister_host)   ( httpd_t *, httpd_host_t * );
71
72     httpd_file_t   *(*pf_register_file)     ( httpd_t *,
73                                               char *psz_file, char *psz_mime,
74                                               char *psz_user, char *psz_password,
75                                               httpd_file_callback pf_get,
76                                               httpd_file_callback pf_post,
77                                               httpd_file_callback_args_t *p_args );
78     void            (*pf_unregister_file)   ( httpd_t *, httpd_file_t * );
79
80     httpd_stream_t *(*pf_register_stream)   ( httpd_t *,
81                                               char *psz_file, char *psz_mime,
82                                               char *psz_user, char *psz_password );
83     int             (*pf_send_stream)       ( httpd_t *,
84                                               httpd_stream_t *,
85                                               uint8_t *, int );
86     int             (*pf_header_stream)     ( httpd_t *,
87                                               httpd_stream_t *,
88                                               uint8_t *, int );
89     void            (*pf_unregister_stream) ( httpd_t *, httpd_stream_t * );
90     int             (*pf_control)           ( httpd_t *,
91                                               int i_query,
92                                               void *arg1, void *arg2 );
93 };
94
95
96 /*****************************************************************************
97  * httpd_Find:
98  *  Return the running httpd instance (if none and b_create then a new one is created)
99  * httpd_release:
100  *****************************************************************************/
101
102 static inline httpd_t* httpd_Find( vlc_object_t *p_this, vlc_bool_t b_create )
103 {
104     httpd_t *p_httpd = NULL;
105     vlc_value_t lockval;
106
107     var_Get( p_this->p_libvlc, "httpd", &lockval );
108     vlc_mutex_lock( lockval.p_address );
109
110     p_httpd = vlc_object_find( p_this, VLC_OBJECT_HTTPD, FIND_ANYWHERE );
111     if( !p_httpd && b_create)
112     {
113         msg_Info(p_this, "creating new http daemon" );
114
115         p_httpd = vlc_object_create( p_this, VLC_OBJECT_HTTPD );
116         if( !p_httpd )
117         {
118             msg_Err( p_this, "out of memory" );
119             vlc_mutex_unlock( lockval.p_address );
120             return( NULL );
121         }
122
123         p_httpd->p_module = module_Need( p_httpd, "httpd", "" );
124
125         if( !p_httpd->p_module )
126         {
127             msg_Err( p_this, "no suitable httpd module" );
128             vlc_object_destroy( p_httpd );
129             vlc_mutex_unlock( lockval.p_address );
130             return( NULL );
131         }
132
133         vlc_object_yield( p_httpd );
134         vlc_object_attach( p_httpd, p_this->p_vlc );
135     }
136     vlc_mutex_unlock( lockval.p_address );
137
138     return( p_httpd );
139 }
140
141 static inline void  httpd_Release( httpd_t *p_httpd )
142 {
143     vlc_object_release( p_httpd );
144
145     if( p_httpd->i_refcount <= 0 )
146     {
147         msg_Info( p_httpd, "destroying unused httpd" );
148         vlc_object_detach( p_httpd );
149         module_Unneed( p_httpd, p_httpd->p_module );
150         vlc_object_destroy( p_httpd );
151     }
152 }