sub: remove unrar_exec

This removes the ability to open compressed bitmap subtitles from rar
files. The code makes me afraid, and I never needed this feature.
This commit is contained in:
wm4 2012-07-29 18:12:23 +02:00
parent 897d1c01bc
commit 6009965cdd
6 changed files with 0 additions and 490 deletions

View File

@ -160,7 +160,6 @@ SRCS_COMMON-$(TV_DSHOW) += stream/tvi_dshow.c \
SRCS_COMMON-$(TV_V4L1) += stream/tvi_v4l.c stream/audio_in.c
SRCS_COMMON-$(TV_V4L2) += stream/tvi_v4l2.c stream/audio_in.c
SRCS_COMMON-$(UNRAR_EXEC) += sub/unrar_exec.c
SRCS_COMMON-$(VCD) += stream/stream_vcd.c
SRCS_COMMON-$(VORBIS) += libmpcodecs/ad_libvorbis.c \
libmpdemux/demux_ogg.c

View File

@ -44,8 +44,6 @@ extern char *lirc_configfile;
extern char *vo_geometry;
extern int stop_xscreensaver;
extern char *unrar_executable;
extern char *mp_msg_charset;
extern int mp_msg_color;
extern int mp_msg_module;
@ -827,9 +825,6 @@ const m_option_t mplayer_opts[]={
OPT_STRING("vobsub", vobsub_name, 0),
{"vobsubid", &vobsub_id, CONF_TYPE_INT, CONF_RANGE, 0, 31, NULL},
#ifdef CONFIG_UNRAR_EXEC
{"unrarexec", &unrar_executable, CONF_TYPE_STRING, 0, 0, 0, NULL},
#endif
{"sstep", &step_sec, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},

18
configure vendored
View File

@ -324,7 +324,6 @@ Optional features:
--disable-dvdread-internal disable internal libdvdread [autodetect]
--disable-libdvdcss-internal disable internal libdvdcss [autodetect]
--disable-cddb disable cddb [autodetect]
--disable-unrarexec disable using of UnRAR executable [enabled]
--disable-sortsub disable subtitle sorting [enabled]
--disable-enca disable ENCA charset oracle library [autodetect]
--enable-macosx-finder enable Mac OS X Finder invocation parameter
@ -525,7 +524,6 @@ _xinerama=auto
_vm=auto
_xf86keysym=auto
_alsa=auto
_unrar_exec=auto
_win32dll=no
_select=yes
_radio=no
@ -875,8 +873,6 @@ for ac_option do
--disable-select) _select=no ;;
--enable-cddb) _cddb=yes ;;
--disable-cddb) _cddb=no ;;
--enable-unrarexec) _unrar_exec=yes ;;
--disable-unrarexec) _unrar_exec=no ;;
--enable-ftp) _ftp=yes ;;
--disable-ftp) _ftp=no ;;
--enable-vstream) _vstream=yes ;;
@ -3889,18 +3885,6 @@ fi
echores "$_libnut"
echocheck "UnRAR executable"
if test "$_unrar_exec" = auto ; then
_unrar_exec="yes"
mingw32 && _unrar_exec="no"
fi
if test "$_unrar_exec" = yes ; then
def_unrar_exec='#define CONFIG_UNRAR_EXEC 1'
else
def_unrar_exec='#undef CONFIG_UNRAR_EXEC'
fi
echores "$_unrar_exec"
echocheck "TV interface"
if test "$_tv" = yes ; then
def_tv='#define CONFIG_TV 1'
@ -4502,7 +4486,6 @@ TV_DSHOW = $_tv_dshow
TV_V4L = $_tv_v4l
TV_V4L1 = $_tv_v4l1
TV_V4L2 = $_tv_v4l2
UNRAR_EXEC = $_unrar_exec
V4L2 = $_v4l2
VCD = $_vcd
VDPAU = $_vdpau
@ -4650,7 +4633,6 @@ $def_priority
$def_quicktime
$def_restrict_keyword
$def_rtc
$def_unrar_exec
/* configurable options */

View File

@ -1,235 +0,0 @@
/*
* List files and extract file from rars by using external executable unrar.
*
* Copyright (C) 2005 Jindrich Makovicka <makovick gmail com>
* Copyright (C) 2007 Ulion <ulion2002 gmail com>
*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <locale.h>
#include "unrar_exec.h"
#include "mp_msg.h"
#define UNRAR_LIST 1
#define UNRAR_EXTRACT 2
char* unrar_executable = NULL;
static FILE* launch_pipe(pid_t *apid, const char *executable, int action,
const char *archive, const char *filename)
{
if (!executable || access(executable, R_OK | X_OK)) return NULL;
if (access(archive, R_OK)) return NULL;
{
int mypipe[2];
pid_t pid;
if (pipe(mypipe)) {
mp_msg(MSGT_GLOBAL, MSGL_ERR, "UnRAR: Cannot create pipe.\n");
return NULL;
}
pid = fork();
if (pid == 0) {
/* This is the child process. Execute the unrar executable. */
close(mypipe[0]);
// Close MPlayer's stdin, stdout and stderr so the unrar binary
// can not mess them up.
// TODO: Close all other files except the pipe.
close(0); close(1); close(2);
// Assign new stdin, stdout and stderr and check they actually got the
// right descriptors.
if (open("/dev/null", O_RDONLY) != 0 || dup(mypipe[1]) != 1
|| open("/dev/null", O_WRONLY) != 2)
_exit(EXIT_FAILURE);
if (action == UNRAR_LIST)
execl(executable, executable, "v", archive, NULL);
else if (action == UNRAR_EXTRACT)
execl(executable, executable, "p", "-inul", "-p-",
archive,filename,NULL);
mp_msg(MSGT_GLOBAL, MSGL_ERR, "UnRAR: Cannot execute %s\n", executable);
_exit(EXIT_FAILURE);
}
if (pid < 0) {
/* The fork failed. Report failure. */
mp_msg(MSGT_GLOBAL, MSGL_ERR, "UnRAR: Fork failed\n");
return NULL;
}
/* This is the parent process. Prepare the pipe stream. */
close(mypipe[1]);
*apid = pid;
if (action == UNRAR_LIST)
mp_msg(MSGT_GLOBAL, MSGL_V,
"UnRAR: call unrar with command line: %s v %s\n",
executable, archive);
else if (action == UNRAR_EXTRACT)
mp_msg(MSGT_GLOBAL, MSGL_V,
"UnRAR: call unrar with command line: %s p -inul -p- %s %s\n",
executable, archive, filename);
return fdopen(mypipe[0], "r");
}
}
#define ALLOC_INCR 1 * 1024 * 1024
int unrar_exec_get(unsigned char **output, unsigned long *size,
const char *filename, const char *rarfile)
{
int bufsize = ALLOC_INCR, bytesread;
pid_t pid;
int status = 0;
FILE *rar_pipe;
rar_pipe=launch_pipe(&pid,unrar_executable,UNRAR_EXTRACT,rarfile,filename);
if (!rar_pipe) return 0;
*size = 0;
*output = malloc(bufsize);
while (*output) {
bytesread=fread(*output+*size, 1, bufsize-*size, rar_pipe);
if (bytesread <= 0)
break;
*size += bytesread;
if (*size == bufsize) {
char *p;
bufsize += ALLOC_INCR;
p = realloc(*output, bufsize);
if (!p)
free(*output);
*output = p;
}
}
fclose(rar_pipe);
pid = waitpid(pid, &status, 0);
if (!*output || !*size || (pid == -1 && errno != ECHILD) ||
(pid > 0 && status)) {
free(*output);
*output = NULL;
*size = 0;
return 0;
}
if (bufsize > *size) {
char *p = realloc(*output, *size);
if (p)
*output = p;
}
mp_msg(MSGT_GLOBAL, MSGL_V, "UnRAR: got file %s len %lu\n", filename,*size);
return 1;
}
#define PARSE_NAME 0
#define PARSE_PROPS 1
int unrar_exec_list(const char *rarfile, ArchiveList_struct **list)
{
char buf[1024], fname[1024];
char *p;
pid_t pid;
int status = 0, file_num = -1, ignore_next_line = 0, state = PARSE_NAME;
FILE *rar_pipe;
ArchiveList_struct *alist = NULL, *current = NULL, *new;
rar_pipe = launch_pipe(&pid, unrar_executable, UNRAR_LIST, rarfile, NULL);
if (!rar_pipe) return -1;
while (fgets(buf, sizeof(buf), rar_pipe)) {
int packsize, unpsize, ratio, day, month, year, hour, min;
int llen = strlen(buf);
// If read nothing, we got a file_num -1.
if (file_num == -1)
file_num = 0;
if (buf[llen-1] != '\n')
// The line is too long, ignore it.
ignore_next_line = 2;
if (ignore_next_line) {
--ignore_next_line;
state = PARSE_NAME;
continue;
}
// Trim the line.
while (llen > 0 && strchr(" \t\n\r\v\f", buf[llen-1]))
--llen;
buf[llen] = '\0';
p = buf;
while (*p && strchr(" \t\n\r\v\f", *p))
++p;
if (!*p) {
state = PARSE_NAME;
continue;
}
if (state == PARSE_PROPS && sscanf(p, "%d %d %d%% %d-%d-%d %d:%d",
&unpsize, &packsize, &ratio, &day,
&month, &year, &hour, &min) == 8) {
new = calloc(1, sizeof(ArchiveList_struct));
if (!new) {
file_num = -1;
break;
}
if (!current)
alist = new;
else
current->next = new;
current = new;
current->item.Name = strdup(fname);
state = PARSE_NAME;
if (!current->item.Name) {
file_num = -1;
break;
}
current->item.PackSize = packsize;
current->item.UnpSize = unpsize;
++file_num;
continue;
}
strcpy(fname, p);
state = PARSE_PROPS;
}
fclose(rar_pipe);
pid = waitpid(pid, &status, 0);
if (file_num < 0 || (pid == -1 && errno != ECHILD) ||
(pid > 0 && status)) {
unrar_exec_freelist(alist);
return -1;
}
if (!alist)
return -1;
*list = alist;
mp_msg(MSGT_GLOBAL, MSGL_V, "UnRAR: list got %d files\n", file_num);
return file_num;
}
void unrar_exec_freelist(ArchiveList_struct *list)
{
ArchiveList_struct* tmp;
while (list) {
tmp = list->next;
free(list->item.Name);
free(list);
list = tmp;
}
}

View File

@ -1,54 +0,0 @@
/*
* List files and extract file from rars by using external executable unrar.
*
* Copyright (C) 2005 Jindrich Makovicka <makovick gmail com>
* Copyright (C) 2007 Ulion <ulion2002 gmail com>
*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_UNRAR_EXEC_H
#define MPLAYER_UNRAR_EXEC_H
struct RAR_archive_entry
{
char *Name;
unsigned long PackSize;
unsigned long UnpSize;
unsigned long FileCRC;
unsigned long FileTime;
unsigned char UnpVer;
unsigned char Method;
unsigned long FileAttr;
};
typedef struct archivelist
{
struct RAR_archive_entry item;
struct archivelist *next;
} ArchiveList_struct;
extern char* unrar_executable;
int unrar_exec_get(unsigned char **output, unsigned long *size,
const char *filename, const char *rarfile);
int unrar_exec_list(const char *rarfile, ArchiveList_struct **list);
void unrar_exec_freelist(ArchiveList_struct *list);
#endif /* MPLAYER_UNRAR_EXEC_H */

View File

@ -37,7 +37,6 @@
#include "spudec.h"
#include "mp_msg.h"
#include "path.h"
#include "unrar_exec.h"
#include "libavutil/common.h"
extern int vobsub_id;
@ -45,181 +44,6 @@ extern int vobsub_id;
// overridden if slang match any of vobsub streams.
static int vobsubid = -2;
/**********************************************************************
* RAR stream handling
* The RAR file must have the same basename as the file to open
**********************************************************************/
#ifdef CONFIG_UNRAR_EXEC
typedef struct {
FILE *file;
unsigned char *data;
unsigned long size;
unsigned long pos;
} rar_stream_t;
static rar_stream_t *rar_open(const char *const filename,
const char *const mode)
{
rar_stream_t *stream;
/* unrar_exec can only read */
if (strcmp("r", mode) && strcmp("rb", mode)) {
errno = EINVAL;
return NULL;
}
stream = malloc(sizeof(rar_stream_t));
if (stream == NULL)
return NULL;
/* first try normal access */
stream->file = fopen(filename, mode);
if (stream->file == NULL) {
char *rar_filename;
const char *p;
int rc;
/* Guess the RAR archive filename */
rar_filename = NULL;
p = strrchr(filename, '.');
if (p) {
ptrdiff_t l = p - filename;
rar_filename = malloc(l + 5);
if (rar_filename == NULL) {
free(stream);
return NULL;
}
strncpy(rar_filename, filename, l);
strcpy(rar_filename + l, ".rar");
} else {
rar_filename = malloc(strlen(filename) + 5);
if (rar_filename == NULL) {
free(stream);
return NULL;
}
strcpy(rar_filename, filename);
strcat(rar_filename, ".rar");
}
/* get rid of the path if there is any */
p = mp_basename(filename);
rc = unrar_exec_get(&stream->data, &stream->size, p, rar_filename);
if (!rc) {
/* There is no matching filename in the archive. However, sometimes
* the files we are looking for have been given arbitrary names in the archive.
* Let's look for a file with an exact match in the extension only. */
int i, num_files, name_len;
ArchiveList_struct *list, *lp;
num_files = unrar_exec_list(rar_filename, &list);
if (num_files > 0) {
char *demanded_ext;
demanded_ext = strrchr (p, '.');
if (demanded_ext) {
int demanded_ext_len = strlen (demanded_ext);
for (i = 0, lp = list; i < num_files; i++, lp = lp->next) {
name_len = strlen (lp->item.Name);
if (name_len >= demanded_ext_len && !strcasecmp (lp->item.Name + name_len - demanded_ext_len, demanded_ext)) {
rc = unrar_exec_get(&stream->data, &stream->size,
lp->item.Name, rar_filename);
if (rc)
break;
}
}
}
unrar_exec_freelist(list);
}
if (!rc) {
free(rar_filename);
free(stream);
return NULL;
}
}
free(rar_filename);
stream->pos = 0;
}
return stream;
}
static int rar_close(rar_stream_t *stream)
{
if (stream->file)
return fclose(stream->file);
free(stream->data);
return 0;
}
static int rar_eof(rar_stream_t *stream)
{
if (stream->file)
return feof(stream->file);
return stream->pos >= stream->size;
}
static long rar_tell(rar_stream_t *stream)
{
if (stream->file)
return ftell(stream->file);
return stream->pos;
}
static int rar_seek(rar_stream_t *stream, long offset, int whence)
{
if (stream->file)
return fseek(stream->file, offset, whence);
switch (whence) {
case SEEK_SET:
if (offset < 0) {
errno = EINVAL;
return -1;
}
stream->pos = offset;
break;
case SEEK_CUR:
if (offset < 0 && stream->pos < (unsigned long) -offset) {
errno = EINVAL;
return -1;
}
stream->pos += offset;
break;
case SEEK_END:
if (offset < 0 && stream->size < (unsigned long) -offset) {
errno = EINVAL;
return -1;
}
stream->pos = stream->size + offset;
break;
default:
errno = EINVAL;
return -1;
}
return 0;
}
static int rar_getc(rar_stream_t *stream)
{
if (stream->file)
return getc(stream->file);
if (rar_eof(stream))
return EOF;
return stream->data[stream->pos++];
}
static size_t rar_read(void *ptr, size_t size, size_t nmemb,
rar_stream_t *stream)
{
size_t res;
unsigned long remain;
if (stream->file)
return fread(ptr, size, nmemb, stream->file);
if (rar_eof(stream))
return 0;
res = size * nmemb;
remain = stream->size - stream->pos;
if (res > remain)
res = remain / size * size;
memcpy(ptr, stream->data + stream->pos, res);
stream->pos += res;
res /= size;
return res;
}
#else
typedef FILE rar_stream_t;
#define rar_open fopen
#define rar_close fclose
@ -228,7 +52,6 @@ typedef FILE rar_stream_t;
#define rar_seek fseek
#define rar_getc getc
#define rar_read fread
#endif
/**********************************************************************/