2017-10-19 05:48:23 +03:00
// SoftEther VPN Source Code - Developer Edition Master Branch
2014-01-04 17:00:08 +04:00
// Cedar Communication Module
// vpncmd.c
// VPN Command Line Management Utility
# include <GlobalConst.h>
# ifdef WIN32
# include <winsock2.h>
# include <windows.h>
# include <wincrypt.h>
# include <wininet.h>
# include <shlobj.h>
# include <commctrl.h>
# include <Dbghelp.h>
# endif // WIN32
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <wchar.h>
# include <stdarg.h>
# include <time.h>
# include <Mayaqua/Mayaqua.h>
# include <Cedar/Cedar.h>
// main function
int main ( int argc , char * argv [ ] )
{
wchar_t * s ;
2014-02-05 20:36:42 +04:00
UINT ret = 0 ;
2014-01-04 17:00:08 +04:00
2018-04-22 12:21:19 +03:00
InitProcessCallOnce ( ) ;
2014-01-04 17:00:08 +04:00
# ifdef OS_WIN32
SetConsoleTitleA ( CEDAR_PRODUCT_STR " VPN Command Line Utility " ) ;
2019-04-07 21:13:18 +03:00
# else
// For *nix, disable output buffering to allow for interactive use
setbuf ( stdout , NULL ) ;
2014-01-04 17:00:08 +04:00
# endif // OS_WIN32
2018-10-08 05:03:58 +03:00
# if defined(_DEBUG) || defined(DEBUG) // In VC++ compilers, the macro is "_DEBUG", not "DEBUG".
// If set memcheck = true, the program will be vitally slow since it will log all malloc() / realloc() / free() calls to find the cause of memory leak.
// For normal debug we set memcheck = false.
// Please set memcheck = true if you want to test the cause of memory leaks.
InitMayaqua ( false , true , argc , argv ) ;
2018-09-15 20:12:21 +03:00
# else
2014-01-04 17:00:08 +04:00
InitMayaqua ( false , false , argc , argv ) ;
2018-09-15 20:12:21 +03:00
# endif
2014-01-04 17:00:08 +04:00
InitCedar ( ) ;
s = GetCommandLineUniStr ( ) ;
if ( s = = NULL )
{
s = CopyUniStr ( L " " ) ;
}
if ( UniStrCmpi ( s , L " exit " ) ! = 0 )
{
UINT size = UniStrSize ( s ) + 64 ;
wchar_t * tmp ;
tmp = Malloc ( size ) ;
UniFormat ( tmp , size , L " vpncmd %s " , s ) ;
ret = CommandMain ( tmp ) ;
Free ( tmp ) ;
}
# ifdef OS_WIN32
{
UINT i ;
LIST * o = MsGetProcessList ( ) ;
bool b = false ;
for ( i = 0 ; i < LIST_NUM ( o ) ; i + + )
{
MS_PROCESS * p = LIST_DATA ( o , i ) ;
if ( EndWith ( p - > ExeFilename , " \\ cmd.exe " ) | | EndWith ( p - > ExeFilename , " \\ command.com " ) )
{
b = true ;
break ;
}
}
MsFreeProcessList ( o ) ;
if ( b = = false )
{
if ( ret ! = ERR_NO_ERROR )
{
SleepThread ( 1000 ) ;
}
}
}
# endif // OS_WIN32
Free ( s ) ;
FreeCedar ( ) ;
FreeMayaqua ( ) ;
return ret ;
}