/*****************************************************************************
* http.h: Headers for the HTTP interface
*****************************************************************************
- * Copyright (C) 2001-2005 the VideoLAN team
- * $Id: http.c 12225 2005-08-18 10:01:30Z massiot $
+ * Copyright (C) 2001-2007 the VideoLAN team
+ * $Id$
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
* Laurent Aimar <fenrir@via.ecp.fr>
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef _HTTP_H_
/*****************************************************************************
* Preamble
*****************************************************************************/
+#include <vlc_common.h>
#include <stdlib.h>
-#include <ctype.h>
-#include <vlc/vlc.h>
-#include <vlc/intf.h>
+#include <strings.h>
+#include <vlc_interface.h>
+#include <vlc_playlist.h>
-#include <vlc/aout.h>
-#include <vlc/vout.h> /* for fullscreen */
+#include <vlc_aout.h>
+#include <vlc_vout.h> /* for fullscreen */
-#include "vlc_httpd.h"
-#include "vlc_vlm.h"
-#include "vlc_tls.h"
-#include "vlc_acl.h"
-#include "charset.h"
-
-#ifdef HAVE_SYS_STAT_H
-# include <sys/stat.h>
-#endif
-#ifdef HAVE_ERRNO_H
-# include <errno.h>
-#endif
-#ifdef HAVE_FCNTL_H
-# include <fcntl.h>
-#endif
+#include <vlc_httpd.h>
+#include <vlc_vlm.h>
+#include <vlc_network.h>
+#include <vlc_acl.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
# include <io.h>
#endif
-#ifdef HAVE_DIRENT_H
-# include <dirent.h>
-#endif
-
/* stat() support for large files on win32 */
#if defined( WIN32 ) && !defined( UNDER_CE )
# define stat _stati64
/* File and directory functions */
/** This function recursively parses a directory and adds all files */
-int E_(ParseDirectory)( intf_thread_t *p_intf, char *psz_root,
- char *psz_dir );
+int ParseDirectory( intf_thread_t *p_intf, char *psz_root,
+ char *psz_dir );
/** This function loads a file into a buffer */
-int E_(FileLoad)( FILE *f, char **pp_data, int *pi_data );
-/** This function creates a suitable URL for a filename */
-char *E_(FileToUrl)( char *name, vlc_bool_t *pb_index );
-
-/* Locale handling functions */
-
-/** This fuction converts a locale string to UTF-8 */
-char *E_(FromUTF8)( intf_thread_t *p_intf, char *psz_utf8 );
-/** This function converts an UTF-8 to locale */
-char *E_(ToUTF8)( intf_thread_t *p_intf, char *psz_local );
+int FileLoad( FILE *f, char **pp_data, int *pi_data );
+/** This function returns the real path of a file or directory */
+char *RealPath( const char *psz_src );
/** This command parses the "seek" command for the HTTP interface
* and performs the requested action */
-void E_(Seek)( intf_thread_t *p_intf, char *p_value );
+void HandleSeek( intf_thread_t *p_intf, char *p_value );
/* URI Handling functions */
/** This function extracts the value for a given argument name
* from an HTTP request */
-char *E_(uri_extract_value)( char *psz_uri, const char *psz_name,
- char *psz_value, int i_value_max );
+const char *ExtractURIValue( const char *restrict psz_uri,
+ const char *restrict psz_name,
+ char *restrict psz_value, size_t i_value_max );
+char *ExtractURIString( const char *restrict psz_uri,
+ const char *restrict psz_name );
/** \todo Describe this function */
-int E_(uri_test_param)( char *psz_uri, const char *psz_name );
-/** This function extracts the original value from an URL-encoded string */
-void E_(uri_decode_url_encoded)( char *psz );
+int TestURIParam( char *psz_uri, const char *psz_name );
/** This function parses a MRL */
-playlist_item_t *E_(MRLParse)( intf_thread_t *, char *psz, char *psz_name );
+input_item_t *MRLParse( intf_thread_t *, const char *psz, char *psz_name );
/** Return the first word from a string (works in-place) */
-char *E_(FirstWord)( char *psz, char *new );
+char *FirstWord( char *psz, char *new );
/**@}*/
/** \defgroup http_vars Macro variables
* \ingroup http_intf
- * These variables are used in macros
+ * These variables can be used in the <vlc> macros and in the RPN evaluator.
+ * The variables make a tree: each variable can have an arbitrary
+ * number of "children" variables.
+ * A number of helper functions are provided to manipulate the main variable
+ * structure
* @{
*/
/**
* \struct mvar_t
- * This structure defines a macro variable as used by the HTTP interface.
- * These variables can be used in the <vlc> macros
+ * This structure defines a macro variable
*/
typedef struct mvar_s
{
- char *name;
- char *value;
+ char *name; ///< Variable name
+ char *value; ///< Variable value
- int i_field;
- struct mvar_s **field;
+ int i_field; ///< Number of children variables
+ struct mvar_s **field; ///< Children variables array
} mvar_t;
/** This function retrieves the child variable named "name" */
mvar_t *mvar_GetVar( mvar_t *s, const char *name );
/** This function retrieves the value of the child variable named "field" */
-char *mvar_GetValue( mvar_t *v, char *field );
+const char *mvar_GetValue( mvar_t *v, const char *field );
/** This function creates a variable with the given name and value and
* adds it as first child of vars */
void mvar_PushNewVar( mvar_t *vars, const char *name,
- const char *value );
+ const char *value );
/** This function creates a variable with the given name and value and
* adds it as last child of vars */
void mvar_AppendNewVar( mvar_t *vars, const char *name,
- const char *value );
+ const char *value );
/** @} */
-/** \defgroup http_sets Set variables *
+/** \defgroup http_sets Sets *
* \ingroup http_intf
+ * Sets are an application of the macro variables. There are a number of
+ * predefined functions that will give you variables whose children represent
+ * VLC internal data (playlist, stream info, ...)
* @{
*/
* The arg parameter must be of the form "start[:stop[:step]]" */
mvar_t *mvar_IntegerSetNew( const char *name, const char *arg );
+/** This function creates a set variable with a list of SD plugins */
+mvar_t *mvar_ServicesSetNew( intf_thread_t *p_intf, char *name );
+
/** This function creates a set variable with the contents of the playlist */
mvar_t *mvar_PlaylistSetNew( intf_thread_t *p_intf, char *name,
- playlist_t *p_pl );
+ playlist_t *p_pl );
/** This function creates a set variable with the contents of the Stream
* and media info box */
-mvar_t *mvar_InfoSetNew( intf_thread_t *p_intf, char *name,
- input_thread_t *p_input );
+mvar_t *mvar_InfoSetNew( char *name, input_thread_t *p_input );
/** This function creates a set variable with the input parameters */
mvar_t *mvar_InputVarSetNew( intf_thread_t *p_intf, char *name,
- input_thread_t *p_input,
- const char *psz_variable );
+ input_thread_t *p_input,
+ const char *psz_variable );
/** This function creates a set variable representing the files of the psz_dir
* directory */
mvar_t *mvar_FileSetNew( intf_thread_t *p_intf, char *name,
- char *psz_dir );
+ char *psz_dir );
/** This function creates a set variable representing the VLM streams */
mvar_t *mvar_VlmSetNew( char *name, vlm_t *vlm );
-/** This function converts the listing of a playlist node into a mvar set */
-void E_(PlaylistListNode)( intf_thread_t *p_intf, playlist_t *p_pl,
- playlist_item_t *p_node, char *name, mvar_t *s,
- int i_depth );
+/** This function converts the listing of a playlist node into a mvar set.
+ * It must be entered WITH playlist lock! */
+void PlaylistListNode( intf_thread_t *p_intf, playlist_t *p_pl,
+ playlist_item_t *p_node, char *name, mvar_t *s,
+ int i_depth );
/**@}*/
void SSClean( rpn_stack_t * );
/* Evaluate and execute the RPN Stack */
void EvaluateRPN( intf_thread_t *p_intf, mvar_t *vars,
- rpn_stack_t *st, char *exp );
+ rpn_stack_t *st, char *exp );
/* Push an operand on top of the RPN stack */
void SSPush ( rpn_stack_t *, const char * );
/** \defgroup http_macros <vlc> Macros Handling
* \ingroup http_intf
+ * A macro is a code snippet in the HTML page looking like
+ * <vlc id="macro_id" param1="value1" param2="value2">
+ * Macros string ids are mapped to macro types, and specific handling code
+ * must be written for each macro type
* @{
*/
/** \struct macro_t
* This structure represents a HTTP Interface macro.
- * A macro is a code snippet in the HTML page looking like
- * <vlc id="macro_id" param1="value1" param2="value2"
*/
typedef struct
{
- char *id;
- char *param1;
- char *param2;
+ char *id; ///< Macro ID string
+ char *param1; ///< First parameter
+ char *param2; ///< Second parameter
} macro_t;
-/** This function creates a macro from a <vlc ....> tag */
-int MacroParse( macro_t *m, char *psz_src );
-/** This function cleans a macro */
-void MacroClean( macro_t *m );
-
-/** This function returns the macro type identifier from its id= string value
- * It uses the StrToMacroTypeTab mapping array for this */
-int StrToMacroType( char *name );
-/** This function actually executes the macro */
-void MacroDo( httpd_file_sys_t *p_args, macro_t *m,
- char *p_request, int i_request, char **pp_data,
- int *pi_data, char **pp_dst );
-/** This function looks for macros in a string */
-char *MacroSearch( char *src, char *end,
- int i_mvlc, vlc_bool_t b_after );
-
/** This function parses a file for macros */
-void E_(Execute)( httpd_file_sys_t *p_args,
+void Execute( httpd_file_sys_t *p_args,
char *p_request, int i_request,
char **pp_data, int *pi_data,
char **pp_dst,
- char *_src, char *_end );
+ const char *_src, const char *_end );
/**@}*/
/**
* Core stuff
*/
-/** \struct
+/** \struct httpd_file_sys_t
* This structure represent a single HTML file to be parsed by the macros
* handling engine */
struct httpd_file_sys_t
char *file;
char *name;
- vlc_bool_t b_html;
+ bool b_html, b_handler;
/* inited for each access */
rpn_stack_t stack;
mvar_t *vars;
};
-/** \struct
+/** \struct http_association_t
+ * Structure associating an extension to an external program
+ */
+typedef struct http_association_t
+{
+ char *psz_ext;
+ int i_argc;
+ char **ppsz_argv;
+} http_association_t;
+
+/** \struct httpd_handler_sys_t
+ * This structure represent a single CGI file to be parsed by the macros
+ * handling engine */
+struct httpd_handler_sys_t
+{
+ httpd_file_sys_t file;
+
+ /* HACK ALERT: this is added below so that casting httpd_handler_sys_t
+ * to httpd_file_sys_t works */
+ httpd_handler_t *p_handler;
+ http_association_t *p_association;
+};
+
+/** \struct intf_sys_t
* Internal service structure for the HTTP interface
*/
struct intf_sys_t
int i_files;
httpd_file_sys_t **pp_files;
+ int i_handlers;
+ http_association_t **pp_handlers;
+ httpd_handler_t *p_art_handler;
+
playlist_t *p_playlist;
input_thread_t *p_input;
vlm_t *p_vlm;
- char *psz_html_type;
- vlc_iconv_t iconv_from_utf8, iconv_to_utf8;
+
+ char *psz_address;
+ unsigned short i_port;
};
/** This function is the main HTTPD Callback used by the HTTP Interface */
-int E_(HttpCallback)( httpd_file_sys_t *p_args,
+int HttpCallback( httpd_file_sys_t *p_args,
httpd_file_t *,
uint8_t *p_request,
uint8_t **pp_data, int *pi_data );
+/** This function is the HTTPD Callback used for CGIs */
+int HandlerCallback( httpd_handler_sys_t *p_args,
+ httpd_handler_t *p_handler, char *_p_url,
+ uint8_t *_p_request, int i_type,
+ uint8_t *_p_in, int i_in,
+ char *psz_remote_addr, char *psz_remote_host,
+ uint8_t **_pp_data, int *pi_data );
/**@}*/
#endif