]> git.sesse.net Git - vlc/blobdiff - modules/control/ntservice.c
Revert "--stats: default to false" (fixes #14035)
[vlc] / modules / control / ntservice.c
index e7104cba01783daab98a72069a058e3c8cfd88f5..3eda3ecdc2f7a8ba134e8eb34c5020a6b248fa89 100644 (file)
@@ -31,6 +31,7 @@
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_interface.h>
+#include <vlc_charset.h>
 
 #define VLCSERVICENAME "VLC media player"
 
@@ -66,15 +67,15 @@ vlc_module_begin ()
     set_description( N_("Windows Service interface") )
     set_category( CAT_INTERFACE )
     set_subcategory( SUBCAT_INTERFACE_CONTROL )
-    add_bool( "ntservice-install", 0, NULL,
+    add_bool( "ntservice-install", false,
               INSTALL_TEXT, INSTALL_LONGTEXT, true )
-    add_bool( "ntservice-uninstall", 0, NULL,
+    add_bool( "ntservice-uninstall", false,
               UNINSTALL_TEXT, UNINSTALL_LONGTEXT, true )
-    add_string ( "ntservice-name", VLCSERVICENAME, NULL,
+    add_string ( "ntservice-name", VLCSERVICENAME,
                  NAME_TEXT, NAME_LONGTEXT, true )
-    add_string ( "ntservice-options", NULL, NULL,
+    add_string ( "ntservice-options", NULL,
                  OPTIONS_TEXT, OPTIONS_LONGTEXT, true )
-    add_string ( "ntservice-extraintf", NULL, NULL,
+    add_string ( "ntservice-extraintf", NULL,
                  EXTRAINTF_TEXT, EXTRAINTF_LONGTEXT, true )
 
     set_capability( "interface", 0 )
@@ -86,12 +87,13 @@ struct intf_sys_t
     SERVICE_STATUS_HANDLE hStatus;
     SERVICE_STATUS status;
     char *psz_service;
+    vlc_thread_t thread;
 };
 
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static void Run( intf_thread_t *p_intf );
+static void *Run( void * );
 static int NTServiceInstall( intf_thread_t *p_intf );
 static int NTServiceUninstall( intf_thread_t *p_intf );
 static void WINAPI ServiceDispatch( DWORD numArgs, char **args );
@@ -106,8 +108,15 @@ static intf_thread_t *p_global_intf;
 static int Activate( vlc_object_t *p_this )
 {
     intf_thread_t *p_intf = (intf_thread_t*)p_this;
+    intf_sys_t *p_sys = malloc( sizeof( *p_sys ) );
+    if( unlikely(p_sys == NULL) )
+        return VLC_ENOMEM;
+
+    p_intf->p_sys = p_sys;
+
+    if( vlc_clone( &p_sys->thread, Run, p_intf, VLC_THREAD_PRIORITY_LOW ) )
+        return VLC_ENOMEM;
 
-    p_intf->pf_run = Run;
     return VLC_SUCCESS;
 }
 
@@ -116,39 +125,40 @@ static int Activate( vlc_object_t *p_this )
  *****************************************************************************/
 void Close( vlc_object_t *p_this )
 {
-    (void)p_this;
+    intf_thread_t *p_intf = (intf_thread_t*)p_this;
+    intf_sys_t *p_sys = p_intf->p_sys;
+
+    vlc_join( p_sys->thread, NULL );
+    free( p_sys );
 }
 
 /*****************************************************************************
  * Run: interface thread
  *****************************************************************************/
-static void Run( intf_thread_t *p_intf )
+static void *Run( void *data )
 {
-    intf_sys_t sys;
-    intf_thread_t *p_extraintf;
+    intf_thread_t *p_intf = data;
     SERVICE_TABLE_ENTRY dispatchTable[] =
     {
-        { VLCSERVICENAME, &ServiceDispatch },
+        { TEXT(VLCSERVICENAME), &ServiceDispatch },
         { NULL, NULL }
     };
 
-    int canc = vlc_savecancel();
     p_global_intf = p_intf;
-    p_intf->p_sys = &sys;
-    p_intf->p_sys->psz_service = config_GetPsz( p_intf, "ntservice-name" );
+    p_intf->p_sys->psz_service = var_InheritString( p_intf, "ntservice-name" );
     p_intf->p_sys->psz_service = p_intf->p_sys->psz_service ?
         p_intf->p_sys->psz_service : strdup(VLCSERVICENAME);
 
-    if( config_GetInt( p_intf, "ntservice-install" ) )
+    if( var_InheritBool( p_intf, "ntservice-install" ) )
     {
         NTServiceInstall( p_intf );
-        return;
+        return NULL;
     }
 
-    if( config_GetInt( p_intf, "ntservice-uninstall" ) )
+    if( var_InheritBool( p_intf, "ntservice-uninstall" ) )
     {
         NTServiceUninstall( p_intf );
-        return;
+        return NULL;
     }
 
     if( StartServiceCtrlDispatcher( dispatchTable ) == 0 )
@@ -160,7 +170,7 @@ static void Run( intf_thread_t *p_intf )
 
     /* Make sure we exit (In case other interfaces have been spawned) */
     libvlc_Quit( p_intf->p_libvlc );
-    vlc_restorecancel( canc );
+    return NULL;
 }
 
 /*****************************************************************************
@@ -169,7 +179,9 @@ static void Run( intf_thread_t *p_intf )
 static int NTServiceInstall( intf_thread_t *p_intf )
 {
     intf_sys_t *p_sys  = p_intf->p_sys;
-    char psz_path[10*MAX_PATH], psz_pathtmp[MAX_PATH], *psz_extra;
+    char psz_path[10*MAX_PATH], *psz_extra;
+    TCHAR psz_pathtmp[MAX_PATH];
+
     SC_HANDLE handle = OpenSCManager( NULL, NULL, SC_MANAGER_ALL_ACCESS );
     if( handle == NULL )
     {
@@ -181,26 +193,26 @@ static int NTServiceInstall( intf_thread_t *p_intf )
     /* Find out the filename of ourselves so we can install it to the
      * service control manager */
     GetModuleFileName( NULL, psz_pathtmp, MAX_PATH );
-    sprintf( psz_path, "\"%s\" -I "MODULE_STRING, psz_pathtmp );
+    sprintf( psz_path, "\"%s\" -I "MODULE_STRING, FromT(psz_pathtmp) );
 
-    psz_extra = config_GetPsz( p_intf, "ntservice-extraintf" );
-    if( psz_extra && *psz_extra )
+    psz_extra = var_InheritString( p_intf, "ntservice-extraintf" );
+    if( psz_extra )
     {
         strcat( psz_path, " --ntservice-extraintf " );
         strcat( psz_path, psz_extra );
+        free( psz_extra );
     }
-    free( psz_extra );
 
-    psz_extra = config_GetPsz( p_intf, "ntservice-options" );
+    psz_extra = var_InheritString( p_intf, "ntservice-options" );
     if( psz_extra && *psz_extra )
     {
         strcat( psz_path, " " );
         strcat( psz_path, psz_extra );
+        free( psz_extra );
     }
-    free( psz_extra );
 
     SC_HANDLE service =
-        CreateService( handle, p_sys->psz_service, p_sys->psz_service,
+        CreateServiceA( handle, p_sys->psz_service, p_sys->psz_service,
                        GENERIC_READ | GENERIC_EXECUTE,
                        SERVICE_WIN32_OWN_PROCESS,
                        SERVICE_AUTO_START, SERVICE_ERROR_IGNORE,
@@ -244,7 +256,7 @@ static int NTServiceUninstall( intf_thread_t *p_intf )
     }
 
     /* First, open a handle to the service */
-    SC_HANDLE service = OpenService( handle, p_sys->psz_service, DELETE );
+    SC_HANDLE service = OpenServiceA( handle, p_sys->psz_service, DELETE );
     if( service == NULL )
     {
         msg_Err( p_intf, "could not open service" );
@@ -284,7 +296,7 @@ static void WINAPI ServiceDispatch( DWORD numArgs, char **args )
     p_sys->status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
 
     p_sys->hStatus =
-        RegisterServiceCtrlHandler( p_sys->psz_service, &ServiceCtrlHandler );
+        RegisterServiceCtrlHandlerA( p_sys->psz_service, &ServiceCtrlHandler );
     if( p_sys->hStatus == (SERVICE_STATUS_HANDLE)0 )
     {
         msg_Err( p_intf, "failed to register service control handler" );
@@ -294,7 +306,7 @@ static void WINAPI ServiceDispatch( DWORD numArgs, char **args )
     /*
      * Load background interfaces
      */
-    psz_modules = config_GetPsz( p_intf, "ntservice-extraintf" );
+    psz_modules = var_InheritString( p_intf, "ntservice-extraintf" );
     psz_parser = psz_modules;
     while( psz_parser && *psz_parser )
     {
@@ -310,7 +322,7 @@ static void WINAPI ServiceDispatch( DWORD numArgs, char **args )
         if( asprintf( &psz_temp, "%s,none", psz_module ) != -1 )
         {
             /* Try to create the interface */
-            if( intf_Create( p_intf, psz_temp ) )
+            if( intf_Create( pl_Get(p_intf), psz_temp ) )
             {
                 msg_Err( p_intf, "interface \"%s\" initialization failed",
                          psz_temp );