* http.c : http mini-server ;)
*****************************************************************************
* Copyright (C) 2001-2004 VideoLAN
- * $Id: http.c,v 1.53 2004/02/09 23:30:37 garf Exp $
+ * $Id$
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
* Laurent Aimar <fenrir@via.ecp.fr>
/*****************************************************************************
* Preamble
*****************************************************************************/
-/*
- * TODO:
- *
+/* TODO:
* - clean up ?
* - doc ! (mouarf ;)
- *
*/
#include <stdlib.h>
#include <vlc/aout.h>
#include <vlc/vout.h> /* for fullscreen */
-#include "httpd.h"
+#include "vlc_httpd.h"
+#include "vlc_vlm.h"
#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
/*****************************************************************************
* Module descriptor
*****************************************************************************/
-static int Activate ( vlc_object_t * );
-static void Close ( vlc_object_t * );
+static int Open ( vlc_object_t * );
+static void Close( vlc_object_t * );
#define HOST_TEXT N_( "Host address" )
#define HOST_LONGTEXT N_( \
add_string ( "http-host", NULL, NULL, HOST_TEXT, HOST_LONGTEXT, VLC_TRUE );
add_string ( "http-src", NULL, NULL, SRC_TEXT, SRC_LONGTEXT, VLC_TRUE );
set_capability( "interface", 0 );
- set_callbacks( Activate, Close );
+ set_callbacks( Open, Close );
vlc_module_end();
return VLC_SUCCESS;
}
-
-static int http_get( httpd_file_callback_args_t *p_args,
- uint8_t *p_request, int i_request,
- uint8_t **pp_data, int *pi_data );
+static int HttpCallback( httpd_file_sys_t *p_args,
+ httpd_file_t *,
+ uint8_t *p_request,
+ uint8_t **pp_data, int *pi_data );
static char *uri_extract_value( char *psz_uri, char *psz_name,
char *psz_value, int i_value_max );
+static int uri_test_param( char *psz_uri, char *psz_name );
+
static void uri_decode_url_encoded( char *psz );
static char *Find_end_MRL( char *psz );
int i_stack;
} rpn_stack_t;
-struct httpd_file_callback_args_t
+struct httpd_file_sys_t
{
- intf_thread_t *p_intf;
- httpd_file_t *p_file;
+ intf_thread_t *p_intf;
+ httpd_file_t *p_file;
+ httpd_redirect_t *p_redir;
char *file;
char *name;
- char *mime;
+
+ vlc_bool_t b_html;
/* inited for each access */
- rpn_stack_t stack;
+ rpn_stack_t stack;
mvar_t *vars;
};
struct intf_sys_t
{
- httpd_t *p_httpd;
httpd_host_t *p_httpd_host;
- int i_files;
- httpd_file_callback_args_t **pp_files;
+ int i_files;
+ httpd_file_sys_t **pp_files;
playlist_t *p_playlist;
input_thread_t *p_input;
+ vlm_t *p_vlm;
};
/*****************************************************************************
* Activate: initialize and create stuff
*****************************************************************************/
-static int Activate( vlc_object_t *p_this )
+static int Open( vlc_object_t *p_this )
{
intf_thread_t *p_intf = (intf_thread_t*)p_this;
intf_sys_t *p_sys;
}
p_sys->p_playlist = NULL;
p_sys->p_input = NULL;
+ p_sys->p_vlm = NULL;
- if( ( p_sys->p_httpd = httpd_Find( VLC_OBJECT(p_intf), VLC_TRUE ) ) == NULL )
- {
- msg_Err( p_intf, "cannot create/find httpd" );
- free( p_sys );
- return VLC_EGENERIC;
- }
-
- if( ( p_sys->p_httpd_host =
- p_sys->p_httpd->pf_register_host( p_sys->p_httpd,
- psz_address, i_port ) ) == NULL )
+ p_sys->p_httpd_host = httpd_HostNew( VLC_OBJECT(p_intf), psz_address, i_port );
+ if( p_sys->p_httpd_host == NULL )
{
msg_Err( p_intf, "cannot listen on %s:%d", psz_address, i_port );
- httpd_Release( p_sys->p_httpd );
free( p_sys );
return VLC_EGENERIC;
}
free( psz_host );
}
- p_sys->i_files = 0;
- p_sys->pp_files = malloc( sizeof( httpd_file_callback_args_t *) );
- if( !p_sys->pp_files )
- {
- return( VLC_ENOMEM );
- }
+ p_sys->i_files = 0;
+ p_sys->pp_files = NULL;
#if defined(SYS_DARWIN) || defined(SYS_BEOS) || \
( defined(WIN32) && !defined(UNDER_CE ) )
psz_src = malloc( strlen(psz_vlcpath) + strlen("/share/http" ) + 1 );
if( !psz_src )
{
- return( VLC_ENOMEM );
+ return VLC_ENOMEM;
}
#if defined(WIN32)
sprintf( psz_src, "%s/http", psz_vlcpath);
failed:
if( psz_src ) free( psz_src );
- free( p_sys->pp_files );
- p_sys->p_httpd->pf_unregister_host( p_sys->p_httpd,
- p_sys->p_httpd_host );
- httpd_Release( p_sys->p_httpd );
+ if( p_sys->pp_files )
+ {
+ free( p_sys->pp_files );
+ }
+ httpd_HostDelete( p_sys->p_httpd_host );
free( p_sys );
return VLC_EGENERIC;
}
int i;
+ if( p_sys->p_vlm )
+ {
+ vlm_Delete( p_sys->p_vlm );
+ }
+
for( i = 0; i < p_sys->i_files; i++ )
{
- p_sys->p_httpd->pf_unregister_file( p_sys->p_httpd,
- p_sys->pp_files[i]->p_file );
- /* do not free mime */
+ httpd_FileDelete( p_sys->pp_files[i]->p_file );
+ if( p_sys->pp_files[i]->p_redir )
+ {
+ httpd_RedirectDelete( p_sys->pp_files[i]->p_redir );
+ }
+
free( p_sys->pp_files[i]->file );
free( p_sys->pp_files[i]->name );
free( p_sys->pp_files[i] );
}
- free( p_sys->pp_files );
- p_sys->p_httpd->pf_unregister_host( p_sys->p_httpd,
- p_sys->p_httpd_host );
- httpd_Release( p_sys->p_httpd );
+ if( p_sys->pp_files )
+ {
+ free( p_sys->pp_files );
+ }
+ httpd_HostDelete( p_sys->p_httpd_host );
+
free( p_sys );
}
return url;
}
-/****************************************************************************
- * FileToMime: XXX duplicated with modules/access_out/http.c
- ****************************************************************************/
-static struct
-{
- char *psz_ext;
- char *psz_mime;
-} http_mime[] =
-{
- { ".htm", "text/html" },
- { ".html", "text/html" },
-
- { ".css", "text/css" },
-
- /* media mime */
- { ".avi", "video/avi" },
- { ".asf", "video/x-ms-asf" },
- { ".m1a", "audio/mpeg" },
- { ".m2a", "audio/mpeg" },
- { ".m1v", "video/mpeg" },
- { ".m2v", "video/mpeg" },
- { ".mp2", "audio/mpeg" },
- { ".mp3", "audio/mpeg" },
- { ".mpa", "audio/mpeg" },
- { ".mpg", "video/mpeg" },
- { ".mpeg", "video/mpeg" },
- { ".mpe", "video/mpeg" },
- { ".mov", "video/quicktime" },
- { ".moov", "video/quicktime" },
- { ".ogg", "application/ogg" },
- { ".ogm", "application/ogg" },
- { ".wav", "audio/wav" },
-
- /* end */
- { NULL, NULL }
-};
-
-static char *FileToMime( char *psz_name )
-{
- char *psz_ext;
-
- psz_ext = strrchr( psz_name, '.' );
- if( psz_ext )
- {
- int i;
-
- for( i = 0; http_mime[i].psz_ext != NULL ; i++ )
- {
- if( !strcmp( http_mime[i].psz_ext, psz_ext ) )
- {
- return( http_mime[i].psz_mime );
- }
- }
- }
- return( "application/octet-stream" );
-}
-
/****************************************************************************
* ParseDirectory: parse recursively a directory, adding each file
****************************************************************************/
sprintf( dir, "%s/%s", psz_dir, p_dir_content->d_name );
if( ParseDirectory( p_intf, psz_root, dir ) )
{
-#define f p_sys->pp_files[p_sys->i_files]
- f = malloc( sizeof( httpd_file_callback_args_t ) );
- if( !f )
- {
- msg_Err( p_intf, "out of memory" );
- closedir( p_dir );
- return( VLC_ENOMEM );
- }
+ httpd_file_sys_t *f = malloc( sizeof( httpd_file_sys_t ) );
+
f->p_intf = p_intf;
+ f->p_file = NULL;
+ f->p_redir = NULL;
f->file = strdup( dir );
f->name = FileToUrl( &dir[strlen( psz_root )] );
- f->mime = FileToMime( &dir[strlen( psz_root )] );
+ f->b_html = strstr( &dir[strlen( psz_root )], ".htm" ) ? VLC_TRUE : VLC_FALSE;
- if( !f->name || !f->mime )
+ if( !f->name )
{
msg_Err( p_intf , "unable to parse directory" );
closedir( p_dir );
free( f );
return( VLC_ENOMEM );
}
- msg_Dbg( p_intf, "file=%s (url=%s mime=%s)",
- f->file, f->name, f->mime );
-
- f->p_file =
- p_sys->p_httpd->pf_register_file( p_sys->p_httpd,
- f->name, f->mime,
- user, password,
- http_get, http_get,
- f );
+ msg_Dbg( p_intf, "file=%s (url=%s)",
+ f->file, f->name );
+
+ f->p_file = httpd_FileNew( p_sys->p_httpd_host,
+ f->name, f->b_html ? "text/html" : NULL,
+ user, password,
+ HttpCallback, f );
+
if( f->p_file )
{
- p_sys->i_files++;
- p_sys->pp_files = realloc( p_sys->pp_files,
- (p_sys->i_files+1) * sizeof( httpd_file_callback_args_t ) );
+ TAB_APPEND( p_sys->i_files, p_sys->pp_files, f );
}
-#define fold p_sys->pp_files[p_sys->i_files-1]
-
- /* FIXME for rep/ add rep (it would be better to do a redirection) */
- if( p_sys->i_files && strlen(fold->name) > 1 &&
- fold->name[strlen(fold->name) - 1] == '/' )
+ /* For rep/ add a redir from rep to rep/ */
+ if( f && f->name[strlen(f->name) - 1] == '/' )
{
- f = malloc( sizeof( httpd_file_callback_args_t ) );
- if( !f )
- {
- msg_Err( p_intf, "out of memory" );
- closedir( p_dir );
- return( VLC_ENOMEM );
- }
- f->p_intf = p_intf;
- f->file = strdup( fold->file );
- f->name = strdup( fold->name );
- f->mime = fold->mime;
-
- f->name[strlen(f->name) - 1] = '\0';
- msg_Dbg( p_intf, "file=%s (url=%s mime=%s)", f->file, f->name,
- f->mime );
- f->p_file =
- p_sys->p_httpd->pf_register_file( p_sys->p_httpd,
- f->name, f->mime,
- user, password,
- http_get, http_get,
- f );
- if( f->p_file )
- {
- p_sys->i_files++;
- p_sys->pp_files =
- realloc( p_sys->pp_files, (p_sys->i_files+1) *
- sizeof( httpd_file_callback_args_t ) );
- }
+ char *psz_redir = strdup( f->name );
+ psz_redir[strlen( psz_redir ) - 1] = '\0';
+
+ msg_Dbg( p_intf, "redir=%s -> %s", psz_redir, f->name );
+ f->p_redir = httpd_RedirectNew( p_sys->p_httpd_host, f->name, psz_redir );
+ free( psz_redir );
}
-#undef fold
-#undef f
}
}
sprintf( value, "%d", i );
mvar_AppendNewVar( itm, "index", value );
- mvar_AppendNewVar( itm, "name", p_pl->pp_items[i]->psz_name );
+ mvar_AppendNewVar( itm, "name", p_pl->pp_items[i]->input.psz_name );
+
+ mvar_AppendNewVar( itm, "uri", p_pl->pp_items[i]->input.psz_uri );
sprintf( value, "%d", p_pl->pp_items[i]->i_group );
mvar_AppendNewVar( itm, "group", value );
static mvar_t *mvar_InfoSetNew( char *name, input_thread_t *p_input )
{
mvar_t *s = mvar_New( name, "set" );
-
- input_info_category_t * p_category;
- input_info_t * p_info;
+ int i, j;
fprintf( stderr," mvar_InfoSetNew: name=`%s'\n", name );
if( p_input == NULL )
return s;
}
- vlc_mutex_lock( &p_input->stream.stream_lock );
- p_category = p_input->stream.p_info;
- while ( p_category )
+ vlc_mutex_lock( &p_input->p_item->lock );
+ for ( i = 0; i < p_input->p_item->i_categories; i++ )
{
+ info_category_t *p_category = p_input->p_item->pp_categories[i];
mvar_t *cat = mvar_New( name, "set" );
mvar_t *iset = mvar_New( "info", "set" );
mvar_AppendNewVar( cat, "name", p_category->psz_name );
mvar_AppendVar( cat, iset );
- p_info = p_category->p_info;
- while ( p_info )
+ for ( j = 0; j < p_category->i_infos; j++ )
{
+ info_t *p_info = p_category->pp_infos[j];
mvar_t *info = mvar_New( "info", "" );
- msg_Dbg( p_input, "adding info name=%s value=%s", p_info->psz_name, p_info->psz_value );
+ msg_Dbg( p_input, "adding info name=%s value=%s",
+ p_info->psz_name, p_info->psz_value );
mvar_AppendNewVar( info, "name", p_info->psz_name );
mvar_AppendNewVar( info, "value", p_info->psz_value );
mvar_AppendVar( iset, info );
- p_info = p_info->p_next;
}
mvar_AppendVar( s, cat );
- p_category = p_category->p_next;
}
- vlc_mutex_unlock( &p_input->stream.stream_lock );
+ vlc_mutex_unlock( &p_input->p_item->lock );
return s;
}
-
+#if 0
static mvar_t *mvar_HttpdInfoSetNew( char *name, httpd_t *p_httpd, int i_type )
{
mvar_t *s = mvar_New( name, "set" );
return s;
}
+#endif
+
static mvar_t *mvar_FileSetNew( char *name, char *psz_dir )
{
mvar_t *s = mvar_New( name, "set" );
return s;
}
+static mvar_t *mvar_VlmSetNew( char *name, vlm_t *vlm )
+{
+ mvar_t *s = mvar_New( name, "set" );
+ vlm_message_t *msg;
+ int i;
+
+ /* fprintf( stderr," mvar_VlmSetNew: name=`%s'\n", name ); */
+ if( vlm == NULL )
+ return s;
+ if( vlm_ExecuteCommand( vlm, "show", &msg ) )
+ {
+ return s;
+ }
+
+ for( i = 0; i < msg->i_child; i++ )
+ {
+ /* Over media, schedule */
+ vlm_message_t *ch = msg->child[i];
+ int j;
+
+ for( j = 0; j < ch->i_child; j++ )
+ {
+ /* Over name */
+ vlm_message_t *el = ch->child[j];
+ vlm_message_t *inf, *desc;
+ mvar_t *set;
+ char psz[500];
+ int k;
+
+ sprintf( psz, "show %s", el->psz_name );
+ if( vlm_ExecuteCommand( vlm, psz, &inf ) )
+ continue;
+ desc = inf->child[0];
+
+ /* Add a node with name and info */
+ set = mvar_New( name, "set" );
+ mvar_AppendNewVar( set, "name", el->psz_name );
+
+ /* fprintf( stderr, "#### name=%s\n", el->psz_name ); */
+
+ for( k = 0; k < desc->i_child; k++ )
+ {
+ vlm_message_t *ch = desc->child[k];
+ if( ch->i_child > 0 )
+ {
+ int c;
+ mvar_t *n = mvar_New( ch->psz_name, "set" );
+
+ /* fprintf( stderr, " child=%s [%d]\n", ch->psz_name, ch->i_child ); */
+ for( c = 0; c < ch->i_child; c++ )
+ {
+ mvar_t *in = mvar_New( ch->psz_name, ch->child[c]->psz_name );
+ mvar_AppendVar( n, in );
+
+ /* fprintf( stderr, " sub=%s\n", ch->child[c]->psz_name );*/
+ }
+ mvar_AppendVar( set, n );
+ }
+ else
+ {
+ /* fprintf( stderr, " child=%s->%s\n", ch->psz_name, ch->psz_value ); */
+ mvar_AppendNewVar( set, ch->psz_name, ch->psz_value );
+ }
+ }
+ vlm_MessageDelete( inf );
+
+ mvar_AppendVar( s, set );
+ }
+ }
+ vlm_MessageDelete( msg );
+
+ return s;
+}
+
+
static void SSInit( rpn_stack_t * );
static void SSClean( rpn_stack_t * );
static void EvaluateRPN( mvar_t *, rpn_stack_t *, char * );
MVLC_SEEK,
MVLC_KEEP,
MVLC_SORT,
+ MVLC_MOVE,
MVLC_VOLUME,
MVLC_FULLSCREEN,
MVLC_CLOSE,
MVLC_SHUTDOWN,
+
+ MVLC_VLM_NEW,
+ MVLC_VLM_SETUP,
+ MVLC_VLM_DEL,
+ MVLC_VLM_PLAY,
+ MVLC_VLM_PAUSE,
+ MVLC_VLM_STOP,
+ MVLC_VLM_SEEK,
+ MVLC_VLM_LOAD,
+ MVLC_VLM_SAVE,
+
MVLC_FOREACH,
MVLC_IF,
MVLC_RPN,
{ "delete", MVLC_DEL },
{ "empty", MVLC_EMPTY },
{ "sort", MVLC_SORT },
+ { "move", MVLC_MOVE },
/* admin control */
{ "close", MVLC_CLOSE },
{ "shutdown", MVLC_SHUTDOWN },
+ /* vlm control */
+ { "vlm_new", MVLC_VLM_NEW },
+ { "vlm_setup", MVLC_VLM_SETUP },
+ { "vlm_del", MVLC_VLM_DEL },
+ { "vlm_play", MVLC_VLM_PLAY },
+ { "vlm_pause", MVLC_VLM_PAUSE },
+ { "vlm_stop", MVLC_VLM_STOP },
+ { "vlm_seek", MVLC_VLM_SEEK },
+ { "vlm_load", MVLC_VLM_LOAD },
+ { "vlm_save", MVLC_VLM_SAVE },
+
{ "rpn", MVLC_RPN },
{ "foreach", MVLC_FOREACH },
return MVLC_UNKNOWN;
}
-static void MacroDo( httpd_file_callback_args_t *p_args,
+static void MacroDo( httpd_file_sys_t *p_args,
macro_t *m,
uint8_t *p_request, int i_request,
uint8_t **pp_data, int *pi_data,
uri_decode_url_encoded( mrl );
p_item = parse_MRL( p_intf, mrl );
- if( !p_item || !p_item->psz_uri || !*p_item->psz_uri )
+ if( !p_item || !p_item->input.psz_uri ||
+ !*p_item->input.psz_uri )
{
msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
} else
{
playlist_SortAuthor( p_sys->p_playlist , i_order );
msg_Dbg( p_intf, "requested playlist sort by author (%d)" , i_order );
- }
+ } else if( !strcmp( type , "shuffle" ) )
+ {
+ playlist_Sort( p_sys->p_playlist , SORT_RANDOM, ORDER_NORMAL );
+ msg_Dbg( p_intf, "requested playlist shuffle");
+ }
break;
}
+ case MVLC_MOVE:
+ {
+ char psz_pos[6];
+ char psz_newpos[6];
+ int i_pos;
+ int i_newpos;
+ uri_extract_value( p_request, "psz_pos", psz_pos, 6 );
+ uri_extract_value( p_request, "psz_newpos", psz_newpos, 6 );
+ i_pos = atoi( psz_pos );
+ i_newpos = atoi( psz_newpos );
+ if ( i_pos < i_newpos )
+ {
+ playlist_Move( p_sys->p_playlist, i_pos, i_newpos + 1 );
+ } else {
+ playlist_Move( p_sys->p_playlist, i_pos, i_newpos );
+ }
+ msg_Dbg( p_intf, "requested move playlist item %d to %d", i_pos, i_newpos);
+ break;
+ }
/* admin function */
case MVLC_CLOSE:
char id[512];
uri_extract_value( p_request, "id", id, 512 );
msg_Dbg( p_intf, "requested close id=%s", id );
+#if 0
if( p_sys->p_httpd->pf_control( p_sys->p_httpd, HTTPD_SET_CLOSE, id, NULL ) )
{
msg_Warn( p_intf, "close failed for id=%s", id );
}
+#endif
break;
}
case MVLC_SHUTDOWN:
p_intf->p_vlc->b_die = VLC_TRUE;
break;
}
+ /* vlm */
+ case MVLC_VLM_NEW:
+ case MVLC_VLM_SETUP:
+ {
+ static const char *vlm_properties[11] =
+ {
+ /* no args */
+ "enabled", "disabled", "loop", "unloop",
+ /* args required */
+ "input", "output", "option", "append", "date", "period", "repeat",
+ };
+ vlm_message_t *vlm_answer;
+ char name[512];
+ char *psz = malloc( strlen( p_request ) + 1000 );
+ char *p = psz;
+ char *vlm_error;
+ int i;
+
+ if( p_intf->p_sys->p_vlm == NULL )
+ p_intf->p_sys->p_vlm = vlm_New( p_intf );
+
+ uri_extract_value( p_request, "name", name, 512 );
+ if( StrToMacroType( control ) == MVLC_VLM_NEW )
+ {
+ char type[20];
+ uri_extract_value( p_request, "type", type, 20 );
+ p += sprintf( psz, "new %s %s", name, type );
+ }
+ else
+ {
+ p += sprintf( psz, "setup %s", name );
+ }
+ /* Parse the request */
+ for( i = 0; i < 11; i++ )
+ {
+ char val[512];
+ uri_extract_value( p_request, vlm_properties[i], val, 512 );
+ uri_decode_url_encoded( val );
+ if( strlen( val ) > 0 && i >= 4 )
+ {
+ p += sprintf( p, " %s %s", vlm_properties[i], val );
+ }
+ else if( uri_test_param( p_request, vlm_properties[i] ) && i < 4 )
+ {
+ p += sprintf( p, " %s", vlm_properties[i] );
+ }
+ }
+ fprintf( stderr, "vlm_ExecuteCommand: %s\n", psz );
+ vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
+ if( vlm_answer->psz_value == NULL ) /* there is no error */
+ {
+ vlm_error = strdup( "" );
+ }
+ else
+ {
+ vlm_error = malloc( strlen(vlm_answer->psz_name) +
+ strlen(vlm_answer->psz_value) +
+ strlen( " : ") + 1 );
+ sprintf( vlm_error , "%s : %s" , vlm_answer->psz_name,
+ vlm_answer->psz_value );
+ }
+
+ mvar_AppendNewVar( p_args->vars, "vlm_error", vlm_error );
+
+ vlm_MessageDelete( vlm_answer );
+ free( vlm_error );
+ free( psz );
+ break;
+ }
+
+ case MVLC_VLM_DEL:
+ {
+ vlm_message_t *vlm_answer;
+ char name[512];
+ char psz[512+10];
+ if( p_intf->p_sys->p_vlm == NULL )
+ p_intf->p_sys->p_vlm = vlm_New( p_intf );
+
+ uri_extract_value( p_request, "name", name, 512 );
+ sprintf( psz, "del %s", name );
+
+ vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
+ /* FIXME do a vlm_answer -> var stack conversion */
+ vlm_MessageDelete( vlm_answer );
+ break;
+ }
+
+ case MVLC_VLM_PLAY:
+ case MVLC_VLM_PAUSE:
+ case MVLC_VLM_STOP:
+ case MVLC_VLM_SEEK:
+ {
+ vlm_message_t *vlm_answer;
+ char name[512];
+ char psz[512+10];
+ if( p_intf->p_sys->p_vlm == NULL )
+ p_intf->p_sys->p_vlm = vlm_New( p_intf );
+
+ uri_extract_value( p_request, "name", name, 512 );
+ if( StrToMacroType( control ) == MVLC_VLM_PLAY )
+ sprintf( psz, "control %s play", name );
+ else if( StrToMacroType( control ) == MVLC_VLM_PAUSE )
+ sprintf( psz, "control %s pause", name );
+ else if( StrToMacroType( control ) == MVLC_VLM_STOP )
+ sprintf( psz, "control %s stop", name );
+ else if( StrToMacroType( control ) == MVLC_VLM_SEEK )
+ {
+ char percent[20];
+ uri_extract_value( p_request, "percent", percent, 512 );
+ sprintf( psz, "control %s seek %s", name, percent );
+ }
+
+ vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
+ /* FIXME do a vlm_answer -> var stack conversion */
+ vlm_MessageDelete( vlm_answer );
+ break;
+ }
+ case MVLC_VLM_LOAD:
+ case MVLC_VLM_SAVE:
+ {
+ vlm_message_t *vlm_answer;
+ char file[512];
+ char psz[512];
+
+ if( p_intf->p_sys->p_vlm == NULL )
+ p_intf->p_sys->p_vlm = vlm_New( p_intf );
+
+ uri_extract_value( p_request, "file", file, 512 );
+ uri_decode_url_encoded( file );
+
+ if( StrToMacroType( control ) == MVLC_VLM_LOAD )
+ sprintf( psz, "load %s", file );
+ else
+ sprintf( psz, "save %s", file );
+
+ vlm_ExecuteCommand( p_intf->p_sys->p_vlm, psz, &vlm_answer );
+ /* FIXME do a vlm_answer -> var stack conversion */
+ vlm_MessageDelete( vlm_answer );
+ break;
+ }
+
default:
- PRINTS( "<!-- control param(%s) unsuported -->", control );
+ if( *control )
+ {
+ PRINTS( "<!-- control param(%s) unsuported -->", control );
+ }
break;
}
break;
case MVLC_RPN:
EvaluateRPN( p_args->vars, &p_args->stack, m->param1 );
break;
+
case MVLC_UNKNOWN:
default:
PRINTS( "<!-- invalid macro id=`%s' -->", m->id );
return NULL;
}
-static void Execute( httpd_file_callback_args_t *p_args,
+static void Execute( httpd_file_sys_t *p_args,
uint8_t *p_request, int i_request,
uint8_t **pp_data, int *pi_data,
uint8_t **pp_dst,
{
index = mvar_InfoSetNew( m.param1, p_intf->p_sys->p_input );
}
+ else if( !strcmp( m.param2, "vlm" ) )
+ {
+ if( p_intf->p_sys->p_vlm == NULL )
+ {
+ p_intf->p_sys->p_vlm = vlm_New( p_intf );
+ }
+ index = mvar_VlmSetNew( m.param1, p_intf->p_sys->p_vlm );
+ }
+#if 0
else if( !strcmp( m.param2, "hosts" ) )
{
index = mvar_HttpdInfoSetNew( m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_HOSTS );
{
index = mvar_HttpdInfoSetNew(m.param1, p_intf->p_sys->p_httpd, HTTPD_GET_CONNECTIONS);
}
+#endif
else if( ( v = mvar_GetVar( p_args->vars, m.param2 ) ) )
{
index = mvar_Duplicate( v );
}
/****************************************************************************
- * http_get:
+ * HttpCallback:
****************************************************************************
- * a file with mime == text/html is parsed and all "macro" replaced
+ * a file with b_html is parsed and all "macro" replaced
* <vlc id="macro name" [param1="" [param2=""]] />
* valid id are
*
****************************************************************************/
-static int http_get( httpd_file_callback_args_t *p_args,
- uint8_t *p_request, int i_request,
- uint8_t **pp_data, int *pi_data )
+static int HttpCallback( httpd_file_sys_t *p_args,
+ httpd_file_t *p_file,
+ uint8_t *p_request,
+ uint8_t **pp_data, int *pi_data )
{
+ int i_request = p_request ? strlen( p_request ) : 0;
char *p;
FILE *f;
return VLC_SUCCESS;
}
- if( strcmp( p_args->mime, "text/html" ) )
+ if( !p_args->b_html )
{
FileLoad( f, pp_data, pi_data );
}
/****************************************************************************
* uri parser
****************************************************************************/
+static int uri_test_param( char *psz_uri, char *psz_name )
+{
+ char *p = psz_uri;
+
+ while( (p = strstr( p, psz_name )) )
+ {
+ /* Verify that we are dealing with a post/get argument */
+ if( p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n' )
+ {
+ return VLC_TRUE;
+ }
+ p++;
+ }
+
+ return VLC_FALSE;
+}
static char *uri_extract_value( char *psz_uri, char *psz_name,
char *psz_value, int i_value_max )
{