http.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * http.h: Headers for the HTTP interface
00003  *****************************************************************************
00004  * Copyright (C) 2001-2007 the VideoLAN team
00005  * $Id: e8dd68c73556146f5f1c242010d77748a8cbc3fc $
00006  *
00007  * Authors: Gildas Bazin <gbazin@netcourrier.com>
00008  *          Laurent Aimar <fenrir@via.ecp.fr>
00009  *          Christophe Massiot <massiot@via.ecp.fr>
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
00024  *****************************************************************************/
00025 
00026 #ifndef _HTTP_H_
00027 #define _HTTP_H_
00028 
00029 /*****************************************************************************
00030  * Preamble
00031  *****************************************************************************/
00032 #include <vlc_common.h>
00033 #include <stdlib.h>
00034 #include <strings.h>
00035 #include <ctype.h>
00036 #include <vlc_interface.h>
00037 #include <vlc_playlist.h>
00038 
00039 #include <vlc_aout.h>
00040 #include <vlc_vout.h> /* for fullscreen */
00041 
00042 #include <vlc_httpd.h>
00043 #include <vlc_vlm.h>
00044 #include <vlc_network.h>
00045 #include <vlc_acl.h>
00046 #include <vlc_charset.h>
00047 
00048 #ifdef HAVE_SYS_STAT_H
00049 #   include <sys/stat.h>
00050 #endif
00051 #include <errno.h>
00052 #ifdef HAVE_FCNTL_H
00053 #   include <fcntl.h>
00054 #endif
00055 
00056 #ifdef HAVE_UNISTD_H
00057 #   include <unistd.h>
00058 #elif defined( WIN32 ) && !defined( UNDER_CE )
00059 #   include <io.h>
00060 #endif
00061 
00062 #ifdef HAVE_DIRENT_H
00063 #   include <dirent.h>
00064 #endif
00065 
00066 /* stat() support for large files on win32 */
00067 #if defined( WIN32 ) && !defined( UNDER_CE )
00068 #   define stat _stati64
00069 #endif
00070 
00071 /** \defgroup http_intf HTTP Interface
00072  * This is the HTTP remote control interface. It is fully customizable
00073  * by writing HTML pages using custom <vlc> tags.
00074  *
00075  * These tags use so-called macros.
00076  *
00077  * These macros can manipulate variables. For more complex operations,
00078  * a custom RPN evaluator with many built-in functions is provided.
00079  * @{
00080  */
00081 
00082 /*****************************************************************************
00083  * Local defines
00084  *****************************************************************************/
00085 #define MAX_DIR_SIZE 2560
00086 #define STACK_MAX 100        //< Maximum RPN stack size
00087 
00088 
00089 /*****************************************************************************
00090  * Utility functions
00091  *****************************************************************************/
00092 
00093 /** \defgroup http_utils Utilities
00094  * \ingroup http_intf
00095  * Utilities
00096  * @{
00097  */
00098 
00099 /* File and directory functions */
00100 
00101 /** This function recursively parses a directory and adds all files */
00102 int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
00103                         char *psz_dir );
00104 /** This function loads a file into a buffer */
00105 int FileLoad( FILE *f, char **pp_data, int *pi_data );
00106 /** This function creates a suitable URL for a filename */
00107 char *FileToUrl( char *name, bool *pb_index );
00108 /** This function returns the real path of a file or directory */
00109 char *RealPath( const char *psz_src );
00110 
00111 /** This command parses the "seek" command for the HTTP interface
00112  * and performs the requested action */
00113 void HandleSeek( intf_thread_t *p_intf, char *p_value );
00114 
00115 /* URI Handling functions */
00116 
00117 /** This function extracts the value for a given argument name
00118  * from an HTTP request */
00119 const char *ExtractURIValue( const char *restrict psz_uri,
00120                            const char *restrict psz_name,
00121                            char *restrict psz_value, size_t i_value_max );
00122 char *ExtractURIString( const char *restrict psz_uri,
00123                             const char *restrict psz_name );
00124 /** \todo Describe this function */
00125 int TestURIParam( char *psz_uri, const char *psz_name );
00126 
00127 /** This function parses a MRL */
00128 input_item_t *MRLParse( intf_thread_t *, const char *psz, char *psz_name );
00129 
00130 /** Return the first word from a string (works in-place) */
00131 char *FirstWord( char *psz, char *new );
00132 
00133 /**@}*/
00134 
00135 /****************************************************************************
00136  * Variable handling functions
00137  ****************************************************************************/
00138 
00139 /** \defgroup http_vars Macro variables
00140  * \ingroup http_intf
00141  * These variables can be used in the <vlc> macros and in the RPN evaluator.
00142  * The variables make a tree: each variable can have an arbitrary
00143  * number of "children" variables.
00144  * A number of helper functions are provided to manipulate the main variable
00145  * structure
00146  * @{
00147  */
00148 
00149 /**
00150  * \struct mvar_t
00151  * This structure defines a macro variable
00152  */
00153 typedef struct mvar_s
00154 {
00155     char *name;                 ///< Variable name
00156     char *value;                ///< Variable value
00157 
00158     int           i_field;      ///< Number of children variables
00159     struct mvar_s **field;      ///< Children variables array
00160 } mvar_t;
00161 
00162 
00163 /** This function creates a new variable */
00164 mvar_t  *mvar_New( const char *name, const char *value );
00165 /** This function deletes a variable */
00166 void     mvar_Delete( mvar_t *v );
00167 /** This function adds f to the children variables of v, at last position */
00168 void     mvar_AppendVar( mvar_t *v, mvar_t *f );
00169 /** This function duplicates a variable */
00170 mvar_t  *mvar_Duplicate( const mvar_t *v );
00171 /** This function adds f to the children variables of v, at fist position */
00172 void     mvar_PushVar( mvar_t *v, mvar_t *f );
00173 /** This function removes f from the children variables of v */
00174 void     mvar_RemoveVar( mvar_t *v, mvar_t *f );
00175 /** This function retrieves the child variable named "name" */
00176 mvar_t  *mvar_GetVar( mvar_t *s, const char *name );
00177 /** This function retrieves the value of the child variable named "field" */
00178 const char *mvar_GetValue( mvar_t *v, const char *field );
00179 /** This function creates a variable with the given name and value and
00180  * adds it as first child of vars */
00181 void     mvar_PushNewVar( mvar_t *vars, const char *name,
00182                               const char *value );
00183 /** This function creates a variable with the given name and value and
00184  * adds it as last child of vars */
00185 void     mvar_AppendNewVar( mvar_t *vars, const char *name,
00186                                 const char *value );
00187 /** @} */
00188 
00189 /** \defgroup http_sets Sets *
00190  * \ingroup http_intf
00191  * Sets are an application of the macro variables. There are a number of
00192  * predefined functions that will give you variables whose children represent
00193  * VLC internal data (playlist, stream info, ...)
00194  * @{
00195  */
00196 
00197 /** This function creates a set variable which represents a series of integer
00198  * The arg parameter must be of the form "start[:stop[:step]]"  */
00199 mvar_t *mvar_IntegerSetNew( const char *name, const char *arg );
00200 
00201 /** This function creates a set variable with a list of VLC objects */
00202 mvar_t *mvar_ObjectSetNew( intf_thread_t *p_intf, char *name, const char *arg );
00203 
00204 /** This function creates a set variable with the contents of the playlist */
00205 mvar_t *mvar_PlaylistSetNew( intf_thread_t *p_intf, char *name,
00206                                  playlist_t *p_pl );
00207 /** This function creates a set variable with the contents of the Stream
00208  * and media info box */
00209 mvar_t *mvar_InfoSetNew( char *name, input_thread_t *p_input );
00210 /** This function creates a set variable with the input parameters */
00211 mvar_t *mvar_InputVarSetNew( intf_thread_t *p_intf, char *name,
00212                                  input_thread_t *p_input,
00213                                  const char *psz_variable );
00214 /** This function creates a set variable representing the files of the psz_dir
00215  * directory */
00216 mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
00217                              char *psz_dir );
00218 /** This function creates a set variable representing the VLM streams */
00219 mvar_t *mvar_VlmSetNew( char *name, vlm_t *vlm );
00220 
00221 /** This function converts the listing of a playlist node into a mvar set */
00222 void PlaylistListNode( intf_thread_t *p_intf, playlist_t *p_pl,
00223                            playlist_item_t *p_node, char *name, mvar_t *s,
00224                            int i_depth );
00225 
00226 /**@}*/
00227 
00228 /*****************************************************************************
00229  * RPN Evaluator
00230  *****************************************************************************/
00231 
00232 /** \defgroup http_rpn RPN Evaluator
00233  * \ingroup http_intf
00234  * @{
00235  */
00236 
00237 /**
00238  * \struct rpn_stack_t
00239  * This structure represents a stack of RPN commands for the HTTP interface
00240  * It is attached to a request
00241  */
00242 typedef struct
00243 {
00244     char *stack[STACK_MAX];
00245     int  i_stack;
00246 } rpn_stack_t;
00247 
00248 /** This function creates the RPN evaluator stack */
00249 void SSInit( rpn_stack_t * );
00250 /** This function cleans the evaluator stack */
00251 void SSClean( rpn_stack_t * );
00252 /* Evaluate and execute the RPN Stack */
00253 void  EvaluateRPN( intf_thread_t *p_intf, mvar_t  *vars,
00254                        rpn_stack_t *st, char *exp );
00255 
00256 /* Push an operand on top of the RPN stack */
00257 void SSPush  ( rpn_stack_t *, const char * );
00258 /* Remove the first operand from the RPN Stack */
00259 char *SSPop  ( rpn_stack_t * );
00260 /* Pushes an operand at a given position in the stack */
00261 void SSPushN ( rpn_stack_t *, int );
00262 /* Removes an operand at the given position in the stack */
00263 int  SSPopN  ( rpn_stack_t *, mvar_t  * );
00264 
00265 /**@}*/
00266 
00267 
00268 /****************************************************************************
00269  * Macro handling (<vlc ... stuff)
00270  ****************************************************************************/
00271 
00272 /** \defgroup http_macros <vlc> Macros Handling
00273  * \ingroup http_intf
00274  * A macro is a code snippet in the HTML page looking like
00275  * <vlc id="macro_id" param1="value1" param2="value2">
00276  * Macros string ids are mapped to macro types, and specific handling code
00277  * must be written for each macro type
00278  * @{
00279  */
00280 
00281 
00282 /** \struct macro_t
00283  * This structure represents a HTTP Interface macro.
00284  */
00285 typedef struct
00286 {
00287     char *id;           ///< Macro ID string
00288     char *param1;       ///< First parameter
00289     char *param2;       ///< Second parameter
00290 } macro_t;
00291 
00292 /** This function parses a file for macros */
00293 void Execute( httpd_file_sys_t *p_args,
00294                   char *p_request, int i_request,
00295                   char **pp_data, int *pi_data,
00296                   char **pp_dst,
00297                   char *_src, char *_end );
00298 
00299 /**@}*/
00300 
00301 /**
00302  * Core stuff
00303  */
00304 /** \struct
00305  * This structure represent a single HTML file to be parsed by the macros
00306  * handling engine */
00307 struct httpd_file_sys_t
00308 {
00309     intf_thread_t    *p_intf;
00310     httpd_file_t     *p_file;
00311     httpd_redirect_t *p_redir;
00312     httpd_redirect_t *p_redir2;
00313 
00314     char          *file;
00315     char          *name;
00316 
00317     bool    b_html, b_handler;
00318 
00319     /* inited for each access */
00320     rpn_stack_t   stack;
00321     mvar_t        *vars;
00322 };
00323 
00324 /** \struct
00325  * Structure associating an extension to an external program
00326  */
00327 typedef struct http_association_t
00328 {
00329     char                *psz_ext;
00330     int                 i_argc;
00331     char                **ppsz_argv;
00332 } http_association_t;
00333 
00334 /** \struct
00335  * This structure represent a single CGI file to be parsed by the macros
00336  * handling engine */
00337 struct httpd_handler_sys_t
00338 {
00339     httpd_file_sys_t file;
00340 
00341     /* HACK ALERT: this is added below so that casting httpd_handler_sys_t
00342      * to httpd_file_sys_t works */
00343     httpd_handler_t  *p_handler;
00344     http_association_t *p_association;
00345 };
00346 
00347 /** \struct
00348  * Internal service structure for the HTTP interface
00349  */
00350 struct intf_sys_t
00351 {
00352     httpd_host_t        *p_httpd_host;
00353 
00354     int                 i_files;
00355     httpd_file_sys_t    **pp_files;
00356 
00357     int                 i_handlers;
00358     http_association_t  **pp_handlers;
00359     httpd_handler_t     *p_art_handler;
00360 
00361     playlist_t          *p_playlist;
00362     input_thread_t      *p_input;
00363     vlm_t               *p_vlm;
00364 
00365     char                *psz_address;
00366     unsigned short      i_port;
00367 };
00368 
00369 /** This function is the main HTTPD Callback used by the HTTP Interface */
00370 int HttpCallback( httpd_file_sys_t *p_args,
00371                       httpd_file_t *,
00372                       uint8_t *p_request,
00373                       uint8_t **pp_data, int *pi_data );
00374 /** This function is the HTTPD Callback used for CGIs */
00375 int  HandlerCallback( httpd_handler_sys_t *p_args,
00376                           httpd_handler_t *p_handler, char *_p_url,
00377                           uint8_t *_p_request, int i_type,
00378                           uint8_t *_p_in, int i_in,
00379                           char *psz_remote_addr, char *psz_remote_host,
00380                           uint8_t **_pp_data, int *pi_data );
00381 /**@}*/
00382 
00383 #endif
00384 

Generated on Fri Nov 20 08:04:59 2009 for VLC by  doxygen 1.5.6