diff --git a/configure.ac b/configure.ac index 4a19fdd99909313f1c3d947e50f1092d576b5ed5..a09a3ef5b7bfa27766761be220dac0cfd49501ca 100644 --- a/configure.ac +++ b/configure.ac @@ -950,7 +950,7 @@ dnl Check for headers dnl dnl POSIX -AC_CHECK_HEADERS([arpa/inet.h poll.h pthread.h search.h sys/shm.h sys/socket.h sys/uio.h]) +AC_CHECK_HEADERS([arpa/inet.h poll.h pthread.h search.h sys/shm.h sys/socket.h sys/uio.h wordexp.h]) AC_CHECK_HEADERS([net/if.h], [], [], [ #include <sys/types.h> diff --git a/modules/control/cli/cli.c b/modules/control/cli/cli.c index ac9caebb8f3d864907622c9c65131d499358f141..8086db514c9385a06954aca05ce1b6e8625d0cd1 100644 --- a/modules/control/cli/cli.c +++ b/modules/control/cli/cli.c @@ -34,6 +34,9 @@ #include <math.h> #include <sys/types.h> #include <unistd.h> +#ifdef HAVE_WORDEXP_H +#include <wordexp.h> +#endif #define VLC_MODULE_LICENSE VLC_LICENSE_GPL_2_PLUS #include <vlc_common.h> @@ -276,6 +279,26 @@ static void Process(intf_thread_t *intf, const char *line) if (*cmd == '\0') return; /* Ignore empty line */ +#ifdef HAVE_WORDEXP_H + wordexp_t we; + int val = wordexp(cmd, &we, 0); + + if (val != 0) + { + if (val == WRDE_NOSPACE) +error: wordfree(&we); + msg_print(intf, N_("parse error")); + return; + } + + size_t count = we.we_wordc; + const char **args = vlc_alloc(count, sizeof (*args)); + if (unlikely(args == NULL)) + goto error; + + for (size_t i = 0; i < we.we_wordc; i++) + args[i] = we.we_wordv[i]; +#else /* Split psz_cmd at the first space and make sure that * psz_arg is valid */ const char *args[] = { cmd, NULL }; @@ -290,17 +313,26 @@ static void Process(intf_thread_t *intf, const char *line) if (*arg) count++; } +#endif - void (*cb)(intf_thread_t *, const char *const *, size_t) = UnknownCmd; + if (count > 0) + { + void (*cb)(intf_thread_t *, const char *const *, size_t) = UnknownCmd; - for (size_t i = 0; i < ARRAY_SIZE(cmds); i++) - if (strcmp(args[0], cmds[i].name) == 0) - { - cb = cmds[i].handler; - break; - } + for (size_t i = 0; i < ARRAY_SIZE(cmds); i++) + if (strcmp(args[0], cmds[i].name) == 0) + { + cb = cmds[i].handler; + break; + } - cb(intf, args, count); + cb(intf, args, count); + } + +#ifdef HAVE_WORDEXP_H + free(args); + wordfree(&we); +#endif } diff --git a/modules/control/cli/playlist.c b/modules/control/cli/playlist.c index a5685b7e94e93c71af63c9a697245ccd84f9fe06..f582b4daeb09888af595d97a2a6d9913f896b669 100644 --- a/modules/control/cli/playlist.c +++ b/modules/control/cli/playlist.c @@ -34,6 +34,7 @@ #include "cli.h" +#ifndef HAVE_WORDEXP_H /***************************************************************************** * parse_MRL: build a input item from a full mrl ***************************************************************************** @@ -137,6 +138,7 @@ static input_item_t *parse_MRL(const char *mrl) return p_item; } +#endif static void print_playlist(intf_thread_t *p_intf, vlc_playlist_t *playlist) { @@ -388,9 +390,59 @@ static void PlaylistAddCommon(intf_thread_t *intf, const char *const *args, size_t n_args, bool play) { vlc_playlist_t *playlist = intf->p_sys->playlist; - const char *arg = n_args > 1 ? args[1] : ""; + size_t count; vlc_playlist_Lock(playlist); + count = vlc_playlist_Count(playlist); +#ifdef HAVE_WORDEXP_H + + for (size_t i = 1; i < n_args;) + { + input_item_t *item; + + if (strstr(args[i], "://" ) != NULL) + item = input_item_New(args[i], NULL); + else + { + char *url = vlc_path2uri(args[i], NULL); + + if (url != NULL) + { + item = input_item_New(url, NULL); + free(url); + } + else + item = NULL; + } + + i++; + + /* Check if following argument(s) are input item options prefixed with + * a colon. + */ + while (i < n_args && args[i][0] == ':') + { + if (likely(item != NULL)) + input_item_AddOption(item, args[i] + 1, + VLC_INPUT_OPTION_TRUSTED); + i++; + } + + if (unlikely(item == NULL)) + continue; + + if (vlc_playlist_InsertOne(playlist, count, item) == VLC_SUCCESS) + { + if (play) + vlc_playlist_PlayAt(playlist, count); + + count++; + } + + input_item_Release(item); + } +#else + const char *arg = n_args > 1 ? args[1] : ""; input_item_t *item = parse_MRL( arg ); @@ -399,14 +451,13 @@ static void PlaylistAddCommon(intf_thread_t *intf, const char *const *args, msg_print(intf, "Trying to %s %s to playlist.", play ? "add" : "enqueue", arg); - size_t count = vlc_playlist_Count(playlist); if (vlc_playlist_InsertOne(playlist, count, item) == VLC_SUCCESS && play) vlc_playlist_PlayAt(playlist, count); input_item_Release(item); } - +#endif vlc_playlist_Unlock(playlist); }