* $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) {
- return ( !strcmp(value, "1") ||
+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",
- "--intf", "dummy",
- };
- int ppsz_argc = 5;
+ char *ppsz_argv[32];
+ int ppsz_argc = 0;
/* locate VLC module path */
#ifdef XP_MACOSX
{
if( i_type == REG_SZ )
{
- strcat( p_data, "\\vlc" );
- ppsz_argv[0] = p_data;
+ strcat( p_data, "\\plugins000" );
+ ppsz_argv[ppsz_argc++] = "--plugin-path";
+ ppsz_argv[ppsz_argc++] = p_data;
}
}
RegCloseKey( h_key );
}
ppsz_argv[ppsz_argc++] = "--no-one-instance";
+#if 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") )
- {
- version = argv[i];
- }
+ else if( !strcmp( argn[i], "version")
+ || !strcmp( argn[i], "progid") )
+ {
+ progid = argv[i];
+ }
}
libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv, NULL);
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 = new RuntimeNPClass<LibvlcRootNPObject>();
+ /* new APIs */
+ p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
}
else
{
- /* legacy APIs */
- scriptClass = new RuntimeNPClass<VlcNPObject>();
+ /* legacy APIs */
+ 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_release(libvlc_instance, NULL );
}
/*****************************************************************************
{
// validate protocol header
const char *start = url;
- while( start != end ) {
- char c = *start | 0x20;
- if( (c < 'a') || (c > 'z') )
- // not valid protocol header, assume relative URL
- break;
+ char c = *start;
+ if( isalpha(c) )
+ {
++start;
+ while( start != end )
+ {
+ c = *start;
+ if( ! (isalnum(c)
+ || ('-' == c)
+ || ('+' == c)
+ || ('.' == c)
+ || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
+ // not valid protocol header, assume relative URL
+ goto relativeurl;
+ ++start;
+ }
+ /* we have a protocol header, therefore URL is absolute */
+ return strdup(url);
}
- /* we have a protocol header, therefore URL is absolute */
- return strdup(url);
+ // not a valid protocol header, assume relative 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 ? */
return href;
}
- /* find last path component and replace it */
- while( '/' != *pathend) --pathend;
+ /* find last path component and replace it */
+ 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;
}