]> git.sesse.net Git - vlc/blob - modules/control/http/http.h
Remove E_()
[vlc] / modules / control / http / http.h
1 /*****************************************************************************
2  * http.h: Headers for the HTTP interface
3  *****************************************************************************
4  * Copyright (C) 2001-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *          Laurent Aimar <fenrir@via.ecp.fr>
9  *          Christophe Massiot <massiot@via.ecp.fr>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifndef _HTTP_H_
27 #define _HTTP_H_
28
29 /*****************************************************************************
30  * Preamble
31  *****************************************************************************/
32 #include <vlc/vlc.h>
33 #include <stdlib.h>
34 #include <strings.h>
35 #include <ctype.h>
36 #include <vlc_interface.h>
37 #include <vlc_playlist.h>
38
39 #include <vlc_aout.h>
40 #include <vlc_vout.h> /* for fullscreen */
41
42 #include "vlc_httpd.h"
43 #include "vlc_vlm.h"
44 #include "vlc_network.h"
45 #include "vlc_acl.h"
46 #include "vlc_charset.h"
47
48 #ifdef HAVE_SYS_STAT_H
49 #   include <sys/stat.h>
50 #endif
51 #ifdef HAVE_ERRNO_H
52 #   include <errno.h>
53 #endif
54 #ifdef HAVE_FCNTL_H
55 #   include <fcntl.h>
56 #endif
57
58 #ifdef HAVE_UNISTD_H
59 #   include <unistd.h>
60 #elif defined( WIN32 ) && !defined( UNDER_CE )
61 #   include <io.h>
62 #endif
63
64 #ifdef HAVE_DIRENT_H
65 #   include <dirent.h>
66 #endif
67
68 /* stat() support for large files on win32 */
69 #if defined( WIN32 ) && !defined( UNDER_CE )
70 #   define stat _stati64
71 #endif
72
73 /** \defgroup http_intf HTTP Interface
74  * This is the HTTP remote control interface. It is fully customizable
75  * by writing HTML pages using custom <vlc> tags.
76  *
77  * These tags use so-called macros.
78  *
79  * These macros can manipulate variables. For more complex operations,
80  * a custom RPN evaluator with many built-in functions is provided.
81  * @{
82  */
83
84 /*****************************************************************************
85  * Local defines
86  *****************************************************************************/
87 #define MAX_DIR_SIZE 2560
88 #define STACK_MAX 100        //< Maximum RPN stack size
89
90
91 /*****************************************************************************
92  * Utility functions
93  *****************************************************************************/
94
95 /** \defgroup http_utils Utilities
96  * \ingroup http_intf
97  * Utilities
98  * @{
99  */
100
101 /* File and directory functions */
102
103 /** This function recursively parses a directory and adds all files */
104 int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
105                         char *psz_dir );
106 /** This function loads a file into a buffer */
107 int FileLoad( FILE *f, char **pp_data, int *pi_data );
108 /** This function creates a suitable URL for a filename */
109 char *FileToUrl( char *name, bool *pb_index );
110 /** This function returns the real path of a file or directory */
111 char *RealPath( intf_thread_t *p_intf, const char *psz_src );
112
113 /** This command parses the "seek" command for the HTTP interface
114  * and performs the requested action */
115 void HandleSeek( intf_thread_t *p_intf, char *p_value );
116
117 /* URI Handling functions */
118
119 /** This function extracts the value for a given argument name
120  * from an HTTP request */
121 char *ExtractURIValue( char *restrict psz_uri,
122                            const char *restrict psz_name,
123                            char *restrict psz_value, size_t i_value_max );
124 char *ExtractURIString( char *restrict psz_uri,
125                             const char *restrict psz_name );
126 /** \todo Describe this function */
127 int TestURIParam( char *psz_uri, const char *psz_name );
128
129 /** This function parses a MRL */
130 input_item_t *MRLParse( intf_thread_t *, char *psz, char *psz_name );
131
132 /** Return the first word from a string (works in-place) */
133 char *FirstWord( char *psz, char *new );
134
135 /**@}*/
136
137 /****************************************************************************
138  * Variable handling functions
139  ****************************************************************************/
140
141 /** \defgroup http_vars Macro variables
142  * \ingroup http_intf
143  * These variables can be used in the <vlc> macros and in the RPN evaluator.
144  * The variables make a tree: each variable can have an arbitrary
145  * number of "children" variables.
146  * A number of helper functions are provided to manipulate the main variable
147  * structure
148  * @{
149  */
150
151 /**
152  * \struct mvar_t
153  * This structure defines a macro variable
154  */
155 typedef struct mvar_s
156 {
157     char *name;                 ///< Variable name
158     char *value;                ///< Variable value
159
160     int           i_field;      ///< Number of children variables
161     struct mvar_s **field;      ///< Children variables array
162 } mvar_t;
163
164
165 /** This function creates a new variable */
166 mvar_t  *mvar_New( const char *name, const char *value );
167 /** This function deletes a variable */
168 void     mvar_Delete( mvar_t *v );
169 /** This function adds f to the children variables of v, at last position */
170 void     mvar_AppendVar( mvar_t *v, mvar_t *f );
171 /** This function duplicates a variable */
172 mvar_t  *mvar_Duplicate( const mvar_t *v );
173 /** This function adds f to the children variables of v, at fist position */
174 void     mvar_PushVar( mvar_t *v, mvar_t *f );
175 /** This function removes f from the children variables of v */
176 void     mvar_RemoveVar( mvar_t *v, mvar_t *f );
177 /** This function retrieves the child variable named "name" */
178 mvar_t  *mvar_GetVar( mvar_t *s, const char *name );
179 /** This function retrieves the value of the child variable named "field" */
180 char    *mvar_GetValue( mvar_t *v, char *field );
181 /** This function creates a variable with the given name and value and
182  * adds it as first child of vars */
183 void     mvar_PushNewVar( mvar_t *vars, const char *name,
184                               const char *value );
185 /** This function creates a variable with the given name and value and
186  * adds it as last child of vars */
187 void     mvar_AppendNewVar( mvar_t *vars, const char *name,
188                                 const char *value );
189 /** @} */
190
191 /** \defgroup http_sets Sets *
192  * \ingroup http_intf
193  * Sets are an application of the macro variables. There are a number of
194  * predefined functions that will give you variables whose children represent
195  * VLC internal data (playlist, stream info, ...)
196  * @{
197  */
198
199 /** This function creates a set variable which represents a series of integer
200  * The arg parameter must be of the form "start[:stop[:step]]"  */
201 mvar_t *mvar_IntegerSetNew( const char *name, const char *arg );
202
203 /** This function creates a set variable with a list of VLC objects */
204 mvar_t *mvar_ObjectSetNew( intf_thread_t *p_intf, char *name, const char *arg );
205
206 /** This function creates a set variable with the contents of the playlist */
207 mvar_t *mvar_PlaylistSetNew( intf_thread_t *p_intf, char *name,
208                                  playlist_t *p_pl );
209 /** This function creates a set variable with the contents of the Stream
210  * and media info box */
211 mvar_t *mvar_InfoSetNew( char *name, input_thread_t *p_input );
212 /** This function creates a set variable with the input parameters */
213 mvar_t *mvar_InputVarSetNew( intf_thread_t *p_intf, char *name,
214                                  input_thread_t *p_input,
215                                  const char *psz_variable );
216 /** This function creates a set variable representing the files of the psz_dir
217  * directory */
218 mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
219                              char *psz_dir );
220 /** This function creates a set variable representing the VLM streams */
221 mvar_t *mvar_VlmSetNew( char *name, vlm_t *vlm );
222
223 /** This function converts the listing of a playlist node into a mvar set */
224 void PlaylistListNode( intf_thread_t *p_intf, playlist_t *p_pl,
225                            playlist_item_t *p_node, char *name, mvar_t *s,
226                            int i_depth );
227
228 /**@}*/
229
230 /*****************************************************************************
231  * RPN Evaluator
232  *****************************************************************************/
233
234 /** \defgroup http_rpn RPN Evaluator
235  * \ingroup http_intf
236  * @{
237  */
238
239 /**
240  * \struct rpn_stack_t
241  * This structure represents a stack of RPN commands for the HTTP interface
242  * It is attached to a request
243  */
244 typedef struct
245 {
246     char *stack[STACK_MAX];
247     int  i_stack;
248 } rpn_stack_t;
249
250 /** This function creates the RPN evaluator stack */
251 void SSInit( rpn_stack_t * );
252 /** This function cleans the evaluator stack */
253 void SSClean( rpn_stack_t * );
254 /* Evaluate and execute the RPN Stack */
255 void  EvaluateRPN( intf_thread_t *p_intf, mvar_t  *vars,
256                        rpn_stack_t *st, char *exp );
257
258 /* Push an operand on top of the RPN stack */
259 void SSPush  ( rpn_stack_t *, const char * );
260 /* Remove the first operand from the RPN Stack */
261 char *SSPop  ( rpn_stack_t * );
262 /* Pushes an operand at a given position in the stack */
263 void SSPushN ( rpn_stack_t *, int );
264 /* Removes an operand at the given position in the stack */
265 int  SSPopN  ( rpn_stack_t *, mvar_t  * );
266
267 /**@}*/
268
269
270 /****************************************************************************
271  * Macro handling (<vlc ... stuff)
272  ****************************************************************************/
273
274 /** \defgroup http_macros <vlc> Macros Handling
275  * \ingroup http_intf
276  * A macro is a code snippet in the HTML page looking like
277  * <vlc id="macro_id" param1="value1" param2="value2">
278  * Macros string ids are mapped to macro types, and specific handling code
279  * must be written for each macro type
280  * @{
281  */
282
283
284 /** \struct macro_t
285  * This structure represents a HTTP Interface macro.
286  */
287 typedef struct
288 {
289     char *id;           ///< Macro ID string
290     char *param1;       ///< First parameter
291     char *param2;       ///< Second parameter
292 } macro_t;
293
294 /** This function parses a file for macros */
295 void Execute( httpd_file_sys_t *p_args,
296                   char *p_request, int i_request,
297                   char **pp_data, int *pi_data,
298                   char **pp_dst,
299                   char *_src, char *_end );
300
301 /**@}*/
302
303 /**
304  * Core stuff
305  */
306 /** \struct
307  * This structure represent a single HTML file to be parsed by the macros
308  * handling engine */
309 struct httpd_file_sys_t
310 {
311     intf_thread_t    *p_intf;
312     httpd_file_t     *p_file;
313     httpd_redirect_t *p_redir;
314     httpd_redirect_t *p_redir2;
315
316     char          *file;
317     char          *name;
318
319     bool    b_html, b_handler;
320
321     /* inited for each access */
322     rpn_stack_t   stack;
323     mvar_t        *vars;
324 };
325
326 /** \struct
327  * Structure associating an extension to an external program
328  */
329 typedef struct http_association_t
330 {
331     char                *psz_ext;
332     int                 i_argc;
333     char                **ppsz_argv;
334 } http_association_t;
335
336 /** \struct
337  * This structure represent a single CGI file to be parsed by the macros
338  * handling engine */
339 struct httpd_handler_sys_t
340 {
341     httpd_file_sys_t file;
342
343     /* HACK ALERT: this is added below so that casting httpd_handler_sys_t
344      * to httpd_file_sys_t works */
345     httpd_handler_t  *p_handler;
346     http_association_t *p_association;
347 };
348
349 /** \struct
350  * Internal service structure for the HTTP interface
351  */
352 struct intf_sys_t
353 {
354     httpd_host_t        *p_httpd_host;
355
356     int                 i_files;
357     httpd_file_sys_t    **pp_files;
358
359     int                 i_handlers;
360     http_association_t  **pp_handlers;
361     httpd_handler_t     *p_art_handler;
362
363     playlist_t          *p_playlist;
364     input_thread_t      *p_input;
365     vlm_t               *p_vlm;
366
367     char                *psz_address;
368     unsigned short      i_port;
369 };
370
371 /** This function is the main HTTPD Callback used by the HTTP Interface */
372 int HttpCallback( httpd_file_sys_t *p_args,
373                       httpd_file_t *,
374                       uint8_t *p_request,
375                       uint8_t **pp_data, int *pi_data );
376 /** This function is the HTTPD Callback used for CGIs */
377 int  HandlerCallback( httpd_handler_sys_t *p_args,
378                           httpd_handler_t *p_handler, char *_p_url,
379                           uint8_t *_p_request, int i_type,
380                           uint8_t *_p_in, int i_in,
381                           char *psz_remote_addr, char *psz_remote_host,
382                           uint8_t **_pp_data, int *pi_data );
383 /**@}*/
384
385 #endif
386