]> git.sesse.net Git - vlc/commitdiff
* http.c : added parsing of options in Add MRL option. In http.c is a the
authorSimon Latapie <garf@videolan.org>
Wed, 12 Nov 2003 02:43:33 +0000 (02:43 +0000)
committerSimon Latapie <garf@videolan.org>
Wed, 12 Nov 2003 02:43:33 +0000 (02:43 +0000)
            parse_MRL function which perhaps should be somewhere else
            (playlist ?).
 * Makefile.am : forgoten style.css
 * index.html : little fixes
 * intf-http.txt : updated doc

doc/intf-http.txt
modules/control/http.c
share/Makefile.am
share/http/index.html

index 81b43286773a12254c384b30407512d3176870e4..42eae3de862b3112cdd176a33b831ffaa20a830e 100644 (file)
@@ -110,6 +110,11 @@ pop them backs. It's used with the little RPN evaluator.
     - url_param : 1 if url_value isn't empty else 0
     - version   : the VLC version
     - copyright : the VLC copyright
+    - stream_position : current position of the VLC in the stream (percentage)
+    - stream_time : current position of the VLC in the stream (in seconds)
+    - stream_length : total length of the current stream (in seconds)
+    - volume : current volume level
+    - stream_state : current state of the VLC (playing, paused, stop)
 
  Variables could have fields, just use . to access them.
   Ex: var.field, var.field.subfield, ...
@@ -171,6 +176,8 @@ You have access to :
  * string:
     strcat          : push the result of 'ST(1)ST(2)'
     strcmp          : compare ST(1) and ST(2), push -1, 0, or 1
+    strncmp         : compare the ST(3) first characters of ST(1) and ST(2),
+                      push -1, 0, or 1
     strlen          : push the length of ST(1)
  * stack manipulation
     dup             : duplicate ST(1) on the stack
@@ -199,23 +206,39 @@ commands will work.
 
 Url commands are :
 
-  | Name      | argument     |
-  -----------------------------------------------------------------
-  | play      | item(integer)| Play the specified item
-  | stop      |              | Stop
-  | pause     |              | Pause
-  | next      |              | Go to the next playlist element
-  | previous  |              | Got to the previous playlist element
-  | add       | mrl(string)  | Add a mrl to the playlist
-  | delete    | item(integer)| Deletes an (list of) element of the playlist
-  | empty     |              | Empty the playlist
-  | close     | id(hexa)     | Close a specific connection
-  | shutdown  |              | Quit vlc
+  | Name       | arguments    |
+  -------------------------------------------------------------------------------
+  | play       | item(integer)| Play the specified item
+  | stop       |              | Stop
+  | pause      |              | Pause
+  | next       |              | Go to the next playlist element
+  | previous   |              | Got to the previous playlist element
+  | fullscreen |              | toggle fullscreen
+  | volume     | value(string)| set volume level (absolute or relative)
+  | seek       | seek_value   | c.f. notes
+  | add        | mrl(string)  | Add a mrl to the playlist (with its options)
+  | delete     | item(integer)| Deletes an (list of) element of the playlist
+  | keep       | item(integer)| Deletes all but (list of) element of the playlist
+  | sort       | type,order   | c.f. notes
+  | empty      |              | Empty the playlist
+  | close      | id(hexa)     | Close a specific connection
+  | shutdown   |              | Quit vlc
 
 For example, you  can restrict the execution of the  shutdown command to
 protected pages (through a .access) using the control macro in all pages
 unprotected.
 
+Notes:
+ Seek: The seek command is used to seek in current playing stream. the
+seek_value argument is a string which represents a relative or absolute
+position in the stream: a percentage, or a time.
+For examples "+12min 42sec", "01:13:43", "-12%", "42%", or
+"1 hour 12 minutes" are valid argument values.
+ Sort: sorts the playlist by type (string), and with the order (integer).
+If order is "0", it is normal order. Otherwise it is reverse order. The
+type can be "title", "group", "author".
+
+
  2. Macro "get"
  --------------
 
@@ -285,7 +308,7 @@ variable will be displayed (instead of it name).
           a set of integer. The stack element should be a string like:
            first:last[:step][,first2:last2[:step2][,...]
            Ex: 1:5:2,6:8:1 will be expanded into 1,3,5,6,7,8
-           
+
         - "directory" : take the first  element of the stack as the base
           directory and construct a set of filename and directly in it.
            Each element has the following fields:
@@ -331,7 +354,7 @@ variable will be displayed (instead of it name).
             - ip :
             - url:
             - status: HTTP error code.
-      
+
         - the name of a foreach variable if it's a set of set of value.
           Ex :
             <vlc id="foreach" param1="cat" param2="informations" />
index c0782bbb77913dffbad98f1b0a8ed59952c5b1e9..6eceff2a359df49127315433e8e2efde03bf1af5 100644 (file)
@@ -2,7 +2,7 @@
  * http.c :  http mini-server ;)
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: http.c,v 1.31 2003/11/09 05:22:56 garf Exp $
+ * $Id: http.c,v 1.32 2003/11/12 02:43:33 garf Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  *          Laurent Aimar <fenrir@via.ecp.fr>
@@ -124,6 +124,10 @@ static char *uri_extract_value( char *psz_uri, char *psz_name,
                                 char *psz_value, int i_value_max );
 static void uri_decode_url_encoded( char *psz );
 
+static char *Find_end_MRL( char *psz );
+
+static playlist_item_t * parse_MRL( char *psz );
+
 /*****************************************************************************
  *
  *****************************************************************************/
@@ -1627,7 +1631,7 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                             case TIME_REL_FOR:
                             {
                                 var_Get( p_sys->p_input, "time", &val );
-                                if( (uint64_t)( i_value ) * 1000 + val.i_time <= i_length )
+                                if( (uint64_t)( i_value ) * 1000000 + val.i_time <= i_length )
                                 {
                                     val.i_time = ((uint64_t)( i_value ) * 1000000) + val.i_time;
                                 } else
@@ -1741,11 +1745,22 @@ static void MacroDo( httpd_file_callback_args_t *p_args,
                 case MVLC_ADD:
                 {
                     char mrl[512];
+                    playlist_item_t * p_item;
+
                     uri_extract_value( p_request, "mrl", mrl, 512 );
                     uri_decode_url_encoded( mrl );
-                    playlist_Add( p_sys->p_playlist, mrl, NULL, 0,
-                                  PLAYLIST_APPEND, PLAYLIST_END );
-                    msg_Dbg( p_intf, "requested playlist add: %s", mrl );
+                    p_item = parse_MRL( mrl );
+
+                    if( p_item == NULL )
+                    {
+                        msg_Dbg( p_intf, "invalid requested mrl: %s", mrl );
+                    } else
+                    {
+                        playlist_AddItem( p_sys->p_playlist , p_item ,
+                                          PLAYLIST_APPEND, PLAYLIST_END );
+                        msg_Dbg( p_intf, "requested mrl add: %s", mrl );
+                    }
+
                     break;
                 }
                 case MVLC_DEL:
@@ -2297,9 +2312,9 @@ static int  http_get( httpd_file_callback_args_t *p_args,
             var_Get( p_sys->p_input, "position", &val);
             sprintf( position, "%d" , (int)((val.f_float) * 100.0));
             var_Get( p_sys->p_input, "time", &val);
-            sprintf( time, "%d" , (int)(val.i_time / 1000) );
+            sprintf( time, "%d" , (int)(val.i_time / 1000000) );
             var_Get( p_sys->p_input, "length", &val);
-            sprintf( length, "%d" , (int)(val.i_time / 1000) );
+            sprintf( length, "%d" , (int)(val.i_time / 1000000) );
 
             var_Get( p_sys->p_input, "state", &val );
             if( val.i_int == PLAYING_S )
@@ -2667,6 +2682,16 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
             free( s1 );
             free( s2 );
         }
+        else if( !strcmp( s, "strncmp" ) )
+        {
+            char *s1 = SSPop( st );
+            char *s2 = SSPop( st );
+            int n = SSPopN( st, vars );
+
+            SSPushN( st, strncmp( s1, s2 , n ) );
+            free( s1 );
+            free( s2 );
+        }
         else if( !strcmp( s, "strlen" ) )
         {
             char *str = SSPop( st );
@@ -2736,3 +2761,213 @@ static void  EvaluateRPN( mvar_t  *vars, rpn_stack_t *st, char *exp )
         }
     }
 }
+
+/**********************************************************************
+ * Find_end_MRL: Find the end of the sentence :
+ * this function parses the string psz and find the end of the item
+ * and/or option with detecting the " and ' problems.
+ * returns NULL if an error is detected, otherwise, returns a pointer
+ * of the end of the sentence (after the last character)
+ **********************************************************************/
+static char *Find_end_MRL( char *psz )
+{
+    char *s_sent = psz;
+
+    switch( *s_sent )
+    {
+        case '\"':
+        {
+            s_sent++;
+
+            while( ( *s_sent != '\"' ) && ( *s_sent != '\0' ) )
+            {
+                if( *s_sent == '\'' )
+                {
+                    s_sent = Find_end_MRL( s_sent );
+
+                    if( s_sent == NULL )
+                    {
+                        return NULL;
+                    }
+                } else
+                {
+                    s_sent++;
+                }
+            }
+
+            if( *s_sent == '\"' )
+            {
+                s_sent++;
+                return s_sent;
+            } else  /* *s_sent == '\0' , which means the number of " is incorrect */
+            {
+                return NULL;
+            }
+            break;
+        }
+        case '\'':
+        {
+            s_sent++;
+
+            while( ( *s_sent != '\'' ) && ( *s_sent != '\0' ) )
+            {
+                if( *s_sent == '\"' )
+                {
+                    s_sent = Find_end_MRL( s_sent );
+
+                    if( s_sent == NULL )
+                    {
+                        return NULL;
+                    }
+                } else
+                {
+                    s_sent++;
+                }
+            }
+
+            if( *s_sent == '\'' )
+            {
+                s_sent++;
+                return s_sent;
+            } else  /* *s_sent == '\0' , which means the number of ' is incorrect */
+            {
+                return NULL;
+            }
+            break;
+        }
+        default: /* now we can look for spaces */
+        {
+            while( ( *s_sent != ' ' ) && ( *s_sent != '\0' ) )
+            {
+                if( ( *s_sent == '\'' ) || ( *s_sent == '\"' ) )
+                {
+                    s_sent = Find_end_MRL( s_sent );
+                } else
+                {
+                    s_sent++;
+                }
+            }
+            return s_sent;
+        }
+    }
+}
+
+/**********************************************************************
+ * parse_MRL: parse the MRL, find the mrl string and the options,
+ * create an item with all informations in it, and return the item.
+ * return NULL if there is an error.
+ **********************************************************************/
+playlist_item_t * parse_MRL( char *psz )
+{
+    char **ppsz_options = NULL;
+    char *mrl;
+    char *s_mrl = psz;
+    int i_error = 0;
+    char *s_temp;
+    int i = 0;
+    int i_options = 0;
+    playlist_item_t * p_item;
+
+    /* In case there is spaces before the mrl */
+    while( ( *s_mrl == ' ' ) && ( *s_mrl != '\0' ) )
+    {
+        s_mrl++;
+    }
+
+    /* extract the mrl */
+    s_temp = Find_end_MRL( s_mrl );
+
+    if( s_temp == NULL )
+    {
+        return NULL;
+    }
+
+    /* if the mrl is between " or ', we must remove them */
+    if( (*s_mrl == '\'') || (*s_mrl == '\"') )
+    {
+        mrl = (char *)malloc( (s_temp - s_mrl - 1) * sizeof( char ) );
+        strncpy( mrl , (s_mrl + 1) , s_temp - s_mrl - 2 );
+        mrl[ s_temp - s_mrl - 2 ] = '\0';
+    } else
+    {
+        mrl = (char *)malloc( (s_temp - s_mrl + 1) * sizeof( char ) );
+        strncpy( mrl , s_mrl , s_temp - s_mrl );
+        mrl[ s_temp - s_mrl ] = '\0';
+    }
+
+    s_mrl = s_temp;
+
+    /* now we can take care of the options */
+    while( (*s_mrl != '\0') && (i_error == 0) )
+    {
+        switch( *s_mrl )
+        {
+            case ' ':
+            {
+                s_mrl++;
+                break;
+            }
+            case ':': /* an option */
+            {
+                s_temp = Find_end_MRL( s_mrl );
+
+                if( s_temp == NULL )
+                {
+                    i_error = 1;
+                } else
+                {
+                    i_options++;
+                    ppsz_options = (char **)realloc( ppsz_options , i_options * sizeof(char *) );
+                    ppsz_options[ i_options - 1 ] = (char *)malloc( (s_temp - s_mrl + 1) * sizeof( char ) );
+
+                    strncpy( ppsz_options[ i_options - 1 ] , s_mrl , s_temp - s_mrl );
+                    /* don't forget to finish the string with a '\0' */
+                    (ppsz_options[ i_options - 1 ])[ s_temp - s_mrl ] = '\0';
+
+                    s_mrl = s_temp;
+                }
+                break;
+            }
+            default:
+            {
+                i_error = 1;
+                break;
+            }
+        }
+    }
+
+    if( i_error != 0 )
+    {
+        free( mrl );
+        for( i = 0 ; i < i_options ; i++ )
+        {
+            free( ppsz_options[i] );
+        }
+        free( ppsz_options );
+        return NULL;
+    } else
+    {
+        /* now create an item */
+        p_item = malloc( sizeof( playlist_item_t ) );
+
+        p_item->psz_name   = mrl;
+        p_item->psz_uri    = mrl;
+        p_item->psz_author = strdup( "" );
+        p_item->i_duration = -1;
+        p_item->i_type = 0;
+        p_item->i_status = 0;
+        p_item->b_autodeletion = VLC_FALSE;
+        p_item->b_enabled = VLC_TRUE;
+        p_item->i_group = PLAYLIST_TYPE_MANUAL;
+
+        p_item->ppsz_options = NULL;
+        p_item->i_options = i_options;
+
+        if( i_options )
+        {
+            p_item->ppsz_options = ppsz_options;
+        }
+
+        return p_item;
+    }
+}
index 4198f5783dbed5f845ecde498e75ab9ae01b8adc..91e776c84c8ea3ad9f2def06e86eb719d0e17f35 100644 (file)
@@ -133,4 +133,5 @@ DIST_http = \
        http/admin/index.html \
        http/admin/browse.html \
        http/admin/.access \
+       http/style.css \
        $(NULL)
index 71f4492a9510bfa4ce12a80b219ac39ce5573df0..fb68163ecf6043df321f3d08c7e83c055aea28f9 100644 (file)
     <div class="section">
      <table class="add">
       <tr>
-       <td colspan="1">Current State: <vlc id="value" param1="stream_state" /></td>
-       <td colspan="0" align="right"><a href="info.html">Information</a> <a href="admin/">Administration</a></td>
+       <td nowrap="1">Current State: <vlc id="value" param1="stream_state" /></td>
+       <td align="right"><a href="info.html">Information</a> <a href="admin/">Administration</a></td>
       </tr>
-      <tr><td> </td></tr>
       <tr>
        <form method="get" action="">
-        <td colspan="5">
+        <td nowrap="1">
          <input type="submit" name="control" value="stop" />
          <input type="submit" name="control" value="pause" />
          <input type="submit" name="control" value="previous" />
         </td>
        </form>
        <form>
-        <td colspan="0" align="right">
+        <td align="right" nowrap="1">
          Current Volume: <vlc id="value" param1="volume" /> <input type="text" name="value" size="5"><input type="hidden" name="control" value="volume"><input type="submit" name="Set" value="Set">
         </td>
        </form>
       </tr>
       <tr>
-       <form>
-        <td colspan="8"><input type="submit" name="seek_value" value="-1min"><input type="text" name="seek_value" size="12"><input type="hidden" name="control" value="seek"><input type="submit" name="seek_value" value="+1min"> ( Seek Textbox: for example "+12min 42sec", "01:13:43", "-12%" etc... )</td>
-       </form>
+       <td colspan="2">
+        <table>
+         <tr>
+          <form>
+           <td><input type="submit" name="seek_value" value="-1min"><input type="hidden" name="control" value="seek"></td>
+          </form>
+          <form>
+           <td><input type="text" name="seek_value" size="14"><input type="hidden" name="control" value="seek"></td>
+          </form>
+          <form>
+           <td><input type="submit" name="seek_value" value="+1min"><input type="hidden" name="control" value="seek"></td>
+          </form>
+           <td>
+            ( Seek Textbox: for example "+12min 42sec", "01:13:43", "-12%" etc... )
+           </td>
+         </tr>
+        </table>
+       </td>
       </tr>
      </table>
     </div>
       </table>
      </form>
     </div>
-  
-    <div class="sectitle">VLC Playlist</div>
-    <div class="section"> 
 
-    <form method="get" action="">
-     <table>
-        <vlc id="foreach" param1="pl" param2="playlist" />
-          <tr class="<vlc id="if" param1="2 pl.index % 0 =" />ligne1<vlc id="else" />ligne2<vlc id="end" />">
-          <td>
-           <input type=checkbox name="item" value="<vlc id="value" param1="pl.index" />">
-           <vlc id="if" param1="pl.current" />
-                <b>
-            <vlc id="end" />
-            <a href="?control=play&item=<vlc id="value" param1="pl.index" />"><vlc id="value" param1="pl.index" /> - <vlc id="value" param1="pl.name" /></a>            <vlc id="if" param1="pl.current" />
-                </b>
-            <vlc id="end" />
-          </td></tr>
-        <vlc id="end" />
-     </table>
-     <td><input type="submit" name="control" value="delete" /></td>
-     <td><input type="submit" name="control" value="keep" /></td>
-    </form>
-    <tr>
-     <td>
-      <form>
-       <input type="submit" name="control" value="sort" /> by
-       <select name="type">
-        <option value="title">title
-        <option value="group">group
-        <option value="author">author
-       </select> with
-       <select name="order">
-        <option value="0">normal order
-        <option value="1">reverse order
-       </select>
-      </form>
-     </td>
-    </tr>
+    <div class="sectitle">VLC Playlist</div>
+     <div class="section"> 
+      <tr>
+       <td>
+        <form>
+         <input type="submit" name="control" value="sort" /> by
+         <select name="type">
+          <option value="title">title
+          <option value="group">group
+          <option value="author">author
+         </select> with
+         <select name="order">
+          <option value="0">normal order
+          <option value="1">reverse order
+         </select>
+        </form>
+       </td>
+      </tr>
+      <form method="get" action="">
+      <table>
+       <vlc id="foreach" param1="pl" param2="playlist" />
+        <tr class="<vlc id="if" param1="2 pl.index % 0 =" />ligne1<vlc id="else" />ligne2<vlc id="end" />">
+         <td>
+          <input type=checkbox name="item" value="<vlc id="value" param1="pl.index" />">
+          <vlc id="if" param1="pl.current" />
+               <b>
+           <vlc id="end" />
+           <a href="?control=play&item=<vlc id="value" param1="pl.index" />"><vlc id="value" param1="pl.index" /> - <vlc id="value" param1="pl.name" /></a>
+          <vlc id="if" param1="pl.current" />
+               </b>
+          <vlc id="end" />
+         </td>
+        </tr>
+       <vlc id="end" />
+      </table>
+      <td><input type="submit" name="control" value="delete" /></td>
+      <td><input type="submit" name="control" value="keep" /></td>
+     </form>
     </div>
     <hr/>
     <p> <vlc id="value" param1="copyright" /> </p>