* $Id$
*
* Authors: Samuel Hocevar <sam@zoy.org>
+ * Damien Fouilleul <damienf.fouilleul@laposte.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "control/npovlc.h"
#include "control/npolibvlc.h"
+#include <ctype.h>
+
/*****************************************************************************
* VlcPlugin constructor and destructor
*****************************************************************************/
VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
i_npmode(mode),
b_stream(0),
- b_autoplay(0),
+ b_autoplay(1),
psz_target(NULL),
libvlc_instance(NULL),
- scriptClass(NULL),
+ libvlc_log(NULL),
+ p_scriptClass(NULL),
p_browser(instance),
psz_baseURL(NULL)
#if XP_WIN
memset(&npwindow, 0, sizeof(NPWindow));
}
-static int boolValue(const char *value) {
+static bool boolValue(const char *value) {
return ( !strcmp(value, "1") ||
!strcasecmp(value, "true") ||
!strcasecmp(value, "yes") );
NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
{
/* prepare VLC command line */
- char *ppsz_argv[32] =
- {
- "vlc",
- "-vv",
- "--no-stats",
- "--no-media-library",
- "--intf", "dummy",
- };
- int ppsz_argc = 5;
+ char *ppsz_argv[32] = { "vlc" };
+ int ppsz_argc = 1;
/* locate VLC module path */
#ifdef XP_MACOSX
{
if( i_type == REG_SZ )
{
- strcat( p_data, "\\vlc" );
- ppsz_argv[0] = p_data;
+ strcat( p_data, "\\plugins" );
+ ppsz_argv[ppsz_argc++] = "--plugin-path";
+ ppsz_argv[ppsz_argc++] = p_data;
}
}
RegCloseKey( h_key );
}
ppsz_argv[ppsz_argc++] = "--no-one-instance";
+ if( IsDebuggerPresent() )
+ {
+ /*
+ ** VLC default threading mechanism is designed to be as compatible
+ ** with POSIX as possible. However when debugged on win32, threads
+ ** lose signals and eventually VLC get stuck during initialization.
+ ** threading support can be configured to be more debugging friendly
+ ** but it will be less compatible with POSIX.
+ ** This is done by initializing with the following options:
+ */
+ ppsz_argv[ppsz_argc++] = "--fast-mutex";
+ ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
+ }
+
+
#if 0
- ppsz_argv[ppsz_argc++] = "--fast-mutex";
- ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
+ ppsz_argv[0] = "C:\\Cygwin\\home\\damienf\\vlc-trunk\\vlc";
#endif
#endif /* XP_MACOSX */
- const char *version = NULL;
+ /* common settings */
+ ppsz_argv[ppsz_argc++] = "-vv";
+ ppsz_argv[ppsz_argc++] = "--no-stats";
+ ppsz_argv[ppsz_argc++] = "--no-media-library";
+ ppsz_argv[ppsz_argc++] = "--intf";
+ ppsz_argv[ppsz_argc++] = "dummy";
+
+ const char *progid = NULL;
/* parse plugin arguments */
for( int i = 0; i < argc ; i++ )
ppsz_argv[ppsz_argc++] = "--no-loop";
}
}
- else if( !strcmp( argn[i], "version") )
+ else if( !strcmp( argn[i], "version")
+ || !strcmp( argn[i], "progid") )
{
- version = argv[i];
+ progid = argv[i];
}
}
if( psz_target )
{
// get absolute URL from src
- psz_target = getAbsoluteURL(psz_target);
+ char *psz_absurl = getAbsoluteURL(psz_target);
+ psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
}
/* assign plugin script root class */
- if( (NULL != version) && (!strcmp(version, "VideoLAN.VLCPlugin.2")) )
+ if( (NULL != progid) && (!strcmp(progid, "VideoLAN.VLCPlugin.2")) )
{
/* new APIs */
- scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
+ p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
}
else
{
/* legacy APIs */
- scriptClass = RuntimeNPClass<VlcNPObject>::getClass();
+ p_scriptClass = RuntimeNPClass<VlcNPObject>::getClass();
}
return NPERR_NO_ERROR;
{
delete psz_baseURL;
delete psz_target;
+ if( libvlc_log )
+ libvlc_log_close(libvlc_log, NULL);
if( libvlc_instance )
- libvlc_destroy(libvlc_instance);
+ libvlc_destroy(libvlc_instance, NULL );
}
/*****************************************************************************
// validate protocol header
const char *start = url;
while( start != end ) {
- char c = *start | 0x20;
+ char c = tolower(*start);
if( (c < 'a') || (c > 'z') )
// not valid protocol header, assume relative URL
- break;
+ goto relativeurl;
++start;
}
/* we have a protocol header, therefore URL is absolute */
return strdup(url);
}
+relativeurl:
+
if( psz_baseURL )
{
size_t baseLen = strlen(psz_baseURL);
- char *href = new char[baseLen+strlen(url)];
+ char *href = new char[baseLen+strlen(url)+1];
if( href )
{
/* prepend base URL */
/* skip over protocol part */
char *pathstart = strchr(href, ':');
char *pathend;
- if( '/' == *(++pathstart) )
+ if( pathstart )
{
if( '/' == *(++pathstart) )
{
- ++pathstart;
+ if( '/' == *(++pathstart) )
+ {
+ ++pathstart;
+ }
+ }
+ /* skip over host part */
+ pathstart = strchr(pathstart, '/');
+ pathend = href+baseLen;
+ if( ! pathstart )
+ {
+ // no path, add a / past end of url (over '\0')
+ pathstart = pathend;
+ *pathstart = '/';
}
}
- /* skip over host part */
- pathstart = strchr(pathstart, '/');
- pathend = href+baseLen;
- if( ! pathstart )
+ else
{
- // no path, add a / past end of url (over '\0')
- pathstart = pathend;
- *pathstart = '/';
+ /* baseURL is just a UNIX path */
+ if( '/' != *href )
+ {
+ /* baseURL is not an absolute path */
+ return NULL;
+ }
+ pathstart = href;
+ pathend = href+baseLen;
}
/* relative URL made of an absolute path ? */
}
/* find last path component and replace it */
- while( '/' != *pathend) --pathend;
+ while( '/' != *pathend)
+ --pathend;
/*
** if relative url path starts with one or more '../',
if( '.' != *p )
break;
++p;
- if( '.' != *p )
+ if( '\0' == *p )
+ {
+ /* relative url is just '.' */
+ url = p;
break;
- ++p;
- if( '/' != *p )
+ }
+ if( '/' == *p )
+ {
+ /* relative url starts with './' */
+ url = ++p;
+ continue;
+ }
+ if( '.' != *p )
break;
++p;
+ if( '\0' == *p )
+ {
+ /* relative url is '..' */
+ }
+ else
+ {
+ if( '/' != *p )
+ break;
+ /* relative url starts with '../' */
+ ++p;
+ }
url = p;
- while( '/' != *pathend ) --pathend;
+ do
+ {
+ --pathend;
+ }
+ while( '/' != *pathend );
}
+ /* skip over '/' separator */
+ ++pathend;
/* concatenate remaining base URL and relative URL */
- strcpy(pathend+1, url);
+ strcpy(pathend, url);
}
return href;
}