📄 http.c
字号:
desc = inf->child[0]; /* Add a node with name and info */ set = mvar_New( name, "set" ); mvar_AppendNewVar( set, "name", 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" ); for( c = 0; c < ch->i_child; c++ ) { if( ch->child[c]->psz_value ) { mvar_AppendNewVar( n, ch->child[c]->psz_name, ch->child[c]->psz_value ); } else { mvar_t *in = mvar_New( ch->psz_name, ch->child[c]->psz_name ); mvar_AppendVar( n, in ); } } mvar_AppendVar( set, n ); } else { 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 * );static void SSPush ( rpn_stack_t *, char * );static char *SSPop ( rpn_stack_t * );static void SSPushN ( rpn_stack_t *, int );static int SSPopN ( rpn_stack_t *, mvar_t * );/**************************************************************************** * Macro handling ****************************************************************************/typedef struct{ char *id; char *param1; char *param2;} macro_t;static int FileLoad( FILE *f, uint8_t **pp_data, int *pi_data ){ int i_read; /* just load the file */ *pi_data = 0; *pp_data = malloc( 1025 ); /* +1 for \0 */ while( ( i_read = fread( &(*pp_data)[*pi_data], 1, 1024, f ) ) == 1024 ) { *pi_data += 1024; *pp_data = realloc( *pp_data, *pi_data + 1025 ); } if( i_read > 0 ) { *pi_data += i_read; } (*pp_data)[*pi_data] = '\0'; return VLC_SUCCESS;}static int MacroParse( macro_t *m, uint8_t *psz_src ){ uint8_t *dup = strdup( psz_src ); uint8_t *src = dup; uint8_t *p; int i_skip;#define EXTRACT( name, l ) \ src += l; \ p = strchr( src, '"' ); \ if( p ) \ { \ *p++ = '\0'; \ } \ m->name = strdup( src ); \ if( !p ) \ { \ break; \ } \ src = p; /* init m */ m->id = NULL; m->param1 = NULL; m->param2 = NULL; /* parse */ src += 4; while( *src ) { while( *src == ' ') { src++; } if( !strncmp( src, "id=\"", 4 ) ) { EXTRACT( id, 4 ); } else if( !strncmp( src, "param1=\"", 8 ) ) { EXTRACT( param1, 8 ); } else if( !strncmp( src, "param2=\"", 8 ) ) { EXTRACT( param2, 8 ); } else { break; } } if( strstr( src, "/>" ) ) { src = strstr( src, "/>" ) + 2; } else { src += strlen( src ); } if( m->id == NULL ) { m->id = strdup( "" ); } if( m->param1 == NULL ) { m->param1 = strdup( "" ); } if( m->param2 == NULL ) { m->param2 = strdup( "" ); } i_skip = src - dup; free( dup ); return i_skip;#undef EXTRACT}static void MacroClean( macro_t *m ){ free( m->id ); free( m->param1 ); free( m->param2 );}enum macroType{ MVLC_UNKNOWN = 0, MVLC_CONTROL, MVLC_PLAY, MVLC_STOP, MVLC_PAUSE, MVLC_NEXT, MVLC_PREVIOUS, MVLC_ADD, MVLC_DEL, MVLC_EMPTY, 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, MVLC_STACK, MVLC_ELSE, MVLC_END, MVLC_GET, MVLC_SET, MVLC_INT, MVLC_FLOAT, MVLC_STRING, MVLC_VALUE};static struct{ char *psz_name; int i_type;}StrToMacroTypeTab [] ={ { "control", MVLC_CONTROL }, /* player control */ { "play", MVLC_PLAY }, { "stop", MVLC_STOP }, { "pause", MVLC_PAUSE }, { "next", MVLC_NEXT }, { "previous", MVLC_PREVIOUS }, { "seek", MVLC_SEEK }, { "keep", MVLC_KEEP }, { "fullscreen", MVLC_FULLSCREEN }, { "volume", MVLC_VOLUME }, /* playlist management */ { "add", MVLC_ADD }, { "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 }, { "stack", MVLC_STACK }, { "foreach", MVLC_FOREACH }, { "value", MVLC_VALUE }, { "if", MVLC_IF }, { "else", MVLC_ELSE }, { "end", MVLC_END }, { "get", MVLC_GET }, { "set", MVLC_SET }, { "int", MVLC_INT }, { "float", MVLC_FLOAT }, { "string", MVLC_STRING }, /* end */ { NULL, MVLC_UNKNOWN }};static int StrToMacroType( char *name ){ int i; if( !name || *name == '\0') { return MVLC_UNKNOWN; } for( i = 0; StrToMacroTypeTab[i].psz_name != NULL; i++ ) { if( !strcmp( name, StrToMacroTypeTab[i].psz_name ) ) { return StrToMacroTypeTab[i].i_type; } } return MVLC_UNKNOWN;}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, uint8_t **pp_dst ){ intf_thread_t *p_intf = p_args->p_intf; intf_sys_t *p_sys = p_args->p_intf->p_sys; char control[512];#define ALLOC( l ) \ { \ int __i__ = *pp_dst - *pp_data; \ *pi_data += (l); \ *pp_data = realloc( *pp_data, *pi_data ); \ *pp_dst = (*pp_data) + __i__; \ }#define PRINT( str ) \ ALLOC( strlen( str ) + 1 ); \ *pp_dst += sprintf( *pp_dst, str );#define PRINTS( str, s ) \ ALLOC( strlen( str ) + strlen( s ) + 1 ); \ { \ char * psz_cur = *pp_dst; \ *pp_dst += sprintf( *pp_dst, str, s ); \ while( psz_cur && *psz_cur ) \ { \ /* Prevent script injection */ \ if( *psz_cur == '<' ) *psz_cur = '*'; \ if( *psz_cur == '>' ) *psz_cur = '*'; \ psz_cur++ ; \ } \ } switch( StrToMacroType( m->id ) ) { case MVLC_CONTROL: if( i_request <= 0 ) { break; } uri_extract_value( p_request, "control", control, 512 ); if( *m->param1 && !strstr( m->param1, control ) ) { msg_Warn( p_intf, "unauthorized control=%s", control ); break; } switch( StrToMacroType( control ) ) { case MVLC_PLAY: { int i_item; char item[512]; uri_extract_value( p_request, "item", item, 512 ); i_item = atoi( item ); playlist_Control( p_sys->p_playlist, PLAYLIST_ITEMPLAY, playlist_ItemGetById( p_sys->p_playlist, i_item ) ); msg_Dbg( p_intf, "requested playlist item: %i", i_item ); break; } case MVLC_STOP: playlist_Control( p_sys->p_playlist, PLAYLIST_STOP); msg_Dbg( p_intf, "requested playlist stop" ); break; case MVLC_PAUSE: playlist_Control( p_sys->p_playlist, PLAYLIST_PAUSE ); msg_Dbg( p_intf, "requested playlist pause" ); break; case MVLC_NEXT: playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, 1 ); msg_Dbg( p_intf, "requested playlist next" ); break; case MVLC_PREVIOUS: playlist_Control( p_sys->p_playlist, PLAYLIST_SKIP, -1); msg_Dbg( p_intf, "requested playlist next" ); break; case MVLC_FULLSCREEN: { if( p_sys->p_input ) { vout_thread_t *p_vout; p_vout = vlc_object_find( p_sys->p_input, VLC_OBJECT_VOUT, FIND_CHILD ); if( p_vout ) { p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE; vlc_object_release( p_vout ); msg_Dbg( p_intf, "requested fullscreen toggle" ); } } } break; case MVLC_SEEK: { vlc_value_t val; char value[30]; char * p_value; int i_stock = 0; uint64_t i_length; int i_value = 0; int i_relative = 0;#define POSITION_ABSOLUTE 12#define POSITION_REL_FOR 13#define POSITION_REL_BACK 11#define VL_TIME_ABSOLUTE 0#define VL_TIME_REL_FOR 1#define VL_TIME_REL_BACK -1 if( p_sys->p_input ) { uri_extract_value( p_request, "seek_value", value, 20 ); uri_decode_url_encoded( value ); p_value = value; var_Get( p_sys->p_input, "length", &val); i_length = val.i_time; while( p_value[0] != '\0' ) { switch(p_value[0]) { case '+': { i_relative = VL_TIME_REL_FOR; p_value++; break; } case '-': { i_relative = VL_TIME_REL_BACK; p_value++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -