]> git.sesse.net Git - vlc/blob - modules/control/http/http.h
Fix consistency of some function names
[vlc] / modules / control / http / http.h
1 /*****************************************************************************
2  * http.h: Headers for the HTTP interface
3  *****************************************************************************
4  * Copyright (C) 2001-2005 the VideoLAN team
5  * $Id: http.c 12225 2005-08-18 10:01:30Z massiot $
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
24  *****************************************************************************/
25
26 #ifndef _HTTP_H_
27 #define _HTTP_H_
28
29 /*****************************************************************************
30  * Preamble
31  *****************************************************************************/
32 #include <stdlib.h>
33 #include <ctype.h>
34 #include <vlc/vlc.h>
35 #include <vlc/intf.h>
36
37 #include <vlc/aout.h>
38 #include <vlc/vout.h> /* for fullscreen */
39
40 #include "vlc_httpd.h"
41 #include "vlc_vlm.h"
42 #include "vlc_tls.h"
43 #include "vlc_acl.h"
44 #include "charset.h"
45
46 #ifdef HAVE_SYS_STAT_H
47 #   include <sys/stat.h>
48 #endif
49 #ifdef HAVE_ERRNO_H
50 #   include <errno.h>
51 #endif
52 #ifdef HAVE_FCNTL_H
53 #   include <fcntl.h>
54 #endif
55
56 #ifdef HAVE_UNISTD_H
57 #   include <unistd.h>
58 #elif defined( WIN32 ) && !defined( UNDER_CE )
59 #   include <io.h>
60 #endif
61
62 #ifdef HAVE_DIRENT_H
63 #   include <dirent.h>
64 #endif
65
66 /* stat() support for large files on win32 */
67 #if defined( WIN32 ) && !defined( UNDER_CE )
68 #   define stat _stati64
69 #endif
70
71 /** \defgroup http_intf HTTP Interface
72  * This is the HTTP remote control interface. It is fully customizable
73  * by writing HTML pages using custom <vlc> tags.
74  *
75  * These tags use so-called macros.
76  *
77  * These macros can manipulate variables. For more complex operations,
78  * a custom RPN evaluator with many built-in functions is provided.
79  * @{
80  */
81
82 /*****************************************************************************
83  * Local defines
84  *****************************************************************************/
85 #define MAX_DIR_SIZE 2560
86 #define STACK_MAX 100        //< Maximum RPN stack size
87
88
89 /*****************************************************************************
90  * Utility functions
91  *****************************************************************************/
92
93 /** \defgroup http_utils Utilities
94  * \ingroup http_intf
95  * Utilities
96  * @{
97  */
98
99 /* File and directory functions */
100
101 /** This function recursively parses a directory and adds all files */
102 int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
103                         char *psz_dir );
104 /** This function loads a file into a buffer */
105 int E_(FileLoad)( FILE *f, char **pp_data, int *pi_data );
106 /** This function creates a suitable URL for a filename */
107 char *E_(FileToUrl)( char *name, vlc_bool_t *pb_index );
108
109 /* Locale handling functions */
110
111 /** This fuction converts a locale string to UTF-8 */
112 char *E_(FromUTF8)( intf_thread_t *p_intf, char *psz_utf8 );
113 /** This function converts an UTF-8 to locale */
114 char *E_(ToUTF8)( intf_thread_t *p_intf, char *psz_local );
115
116 /** This command parses the "seek" command for the HTTP interface
117  * and performs the requested action */
118 void E_(HandleSeek)( intf_thread_t *p_intf, char *p_value );
119
120 /* URI Handling functions */
121
122 /** This function extracts the value for a given argument name
123  * from an HTTP request */
124 char *E_(ExtractURIValue)( char *psz_uri, const char *psz_name,
125                              char *psz_value, int i_value_max );
126 /** \todo Describe this function */
127 int E_(TestURIParam)( char *psz_uri, const char *psz_name );
128 /** This function extracts the original value from an URL-encoded string */
129 void E_(DecodeEncodedURI)( char *psz );
130
131 /** This function parses a MRL */
132 playlist_item_t *E_(MRLParse)( intf_thread_t *, char *psz, char *psz_name );
133
134 /** Return the first word from a string (works in-place) */
135 char *E_(FirstWord)( char *psz, char *new );
136
137 /**@}*/
138
139 /****************************************************************************
140  * Variable handling functions
141  ****************************************************************************/
142
143 /** \defgroup http_vars Macro variables
144  * \ingroup http_intf
145  * These variables can be used in the <vlc> macros and in the RPN evaluator.
146  * The variables make a tree: each variable can have an arbitrary
147  * number of "children" variables.
148  * A number of helper functions are provided to manipulate the main variable
149  * structure
150  * @{
151  */
152
153 /**
154  * \struct mvar_t
155  * This structure defines a macro variable
156  */
157 typedef struct mvar_s
158 {
159     char *name;                 ///< Variable name
160     char *value;                ///< Variable value
161
162     int           i_field;      ///< Number of children variables
163     struct mvar_s **field;      ///< Children variables array
164 } mvar_t;
165
166
167 /** This function creates a new variable */
168 mvar_t  *mvar_New( const char *name, const char *value );
169 /** This function deletes a variable */
170 void     mvar_Delete( mvar_t *v );
171 /** This function adds f to the children variables of v, at last position */
172 void     mvar_AppendVar( mvar_t *v, mvar_t *f );
173 /** This function duplicates a variable */
174 mvar_t  *mvar_Duplicate( const mvar_t *v );
175 /** This function adds f to the children variables of v, at fist position */
176 void     mvar_PushVar( mvar_t *v, mvar_t *f );
177 /** This function removes f from the children variables of v */
178 void     mvar_RemoveVar( mvar_t *v, mvar_t *f );
179 /** This function retrieves the child variable named "name" */
180 mvar_t  *mvar_GetVar( mvar_t *s, const char *name );
181 /** This function retrieves the value of the child variable named "field" */
182 char    *mvar_GetValue( mvar_t *v, char *field );
183 /** This function creates a variable with the given name and value and
184  * adds it as first child of vars */
185 void     mvar_PushNewVar( mvar_t *vars, const char *name,
186                              const char *value );
187 /** This function creates a variable with the given name and value and
188  * adds it as last child of vars */
189 void     mvar_AppendNewVar( mvar_t *vars, const char *name,
190                                const char *value );
191 /** @} */
192
193 /** \defgroup http_sets Sets *
194  * \ingroup http_intf
195  * Sets are an application of the macro variables. There are a number of
196  * predefined functions that will give you variables whose children represent
197  * VLC internal data (playlist, stream info, ...)
198  * @{
199  */
200
201 /** This function creates a set variable which represents a series of integer
202  * The arg parameter must be of the form "start[:stop[:step]]"  */
203 mvar_t *mvar_IntegerSetNew( const char *name, const char *arg );
204
205 /** This function creates a set variable with the contents of the playlist */
206 mvar_t *mvar_PlaylistSetNew( intf_thread_t *p_intf, char *name,
207                              playlist_t *p_pl );
208 /** This function creates a set variable with the contents of the Stream
209  * and media info box */
210 mvar_t *mvar_InfoSetNew( intf_thread_t *p_intf, char *name,
211                          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 E_(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 creates a macro from a <vlc ....> tag */
295 int MacroParse( macro_t *m, char *psz_src );
296 /** This function cleans a macro */
297 void MacroClean( macro_t *m );
298
299 /** This function returns the macro type identifier from its id= string value
300  * It uses the StrToMacroTypeTab mapping array for this */
301 int StrToMacroType( char *name );
302 /** This function actually executes the macro */
303 void MacroDo( httpd_file_sys_t *p_args, macro_t *m,
304               char *p_request, int i_request, char **pp_data,
305               int *pi_data, char **pp_dst );
306 /** This function looks for macros in a string */
307 char *MacroSearch( char *src, char *end,
308                    int i_mvlc, vlc_bool_t b_after );
309
310 /** This function parses a file for macros */
311 void E_(Execute)( httpd_file_sys_t *p_args,
312                   char *p_request, int i_request,
313                   char **pp_data, int *pi_data,
314                   char **pp_dst,
315                   char *_src, char *_end );
316
317 /**@}*/
318
319 /**
320  * Core stuff
321  */
322 /** \struct
323  * This structure represent a single HTML file to be parsed by the macros
324  * handling engine */
325 struct httpd_file_sys_t
326 {
327     intf_thread_t    *p_intf;
328     httpd_file_t     *p_file;
329     httpd_redirect_t *p_redir;
330     httpd_redirect_t *p_redir2;
331
332     char          *file;
333     char          *name;
334
335     vlc_bool_t    b_html;
336
337     /* inited for each access */
338     rpn_stack_t   stack;
339     mvar_t        *vars;
340 };
341
342 /** \struct
343  * Internal service structure for the HTTP interface
344  */
345 struct intf_sys_t
346 {
347     httpd_host_t        *p_httpd_host;
348
349     int                 i_files;
350     httpd_file_sys_t    **pp_files;
351
352     playlist_t          *p_playlist;
353     input_thread_t      *p_input;
354     vlm_t               *p_vlm;
355     char                *psz_html_type;
356     vlc_iconv_t         iconv_from_utf8, iconv_to_utf8;
357 };
358
359 /** This function is the main HTTPD Callback used by the HTTP Interface */
360 int E_(HttpCallback)( httpd_file_sys_t *p_args,
361                       httpd_file_t *,
362                       uint8_t *p_request,
363                       uint8_t **pp_data, int *pi_data );
364 /**@}*/
365
366 #endif
367