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