summary refs log tree commit diff stats
path: root/plugins/exec
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/exec')
-rw-r--r--plugins/exec/exec.c138
-rw-r--r--plugins/exec/exec.def3
-rw-r--r--plugins/exec/exec.vcxproj106
-rw-r--r--plugins/exec/exec.vcxproj.filters23
-rw-r--r--plugins/exec/exec.vcxproj.user3
-rw-r--r--plugins/exec/makefile.mak18
6 files changed, 291 insertions, 0 deletions
diff --git a/plugins/exec/exec.c b/plugins/exec/exec.c
new file mode 100644
index 00000000..22f38814
--- /dev/null
+++ b/plugins/exec/exec.c
@@ -0,0 +1,138 @@
+/* XChat-WDK
+ * Copyright (c) 2011 Berke Viktor.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <windows.h>
+#include <time.h>
+
+#include "xchat-plugin.h"
+
+static xchat_plugin *ph;   /* plugin handle */
+static const char name[] = "Exec";
+static const char desc[] = "Execute commands inside XChat";
+static const char version[] = "1.1";
+
+static int
+run_command (char *word[], char *word_eol[], void *userdata)
+{
+	char commandLine[1024];
+	char buffer[4096];
+	DWORD dwRead = 0;
+	DWORD dwLeft = 0;
+	DWORD dwAvail = 0;
+	time_t start;
+	double timeElapsed;
+
+	HANDLE readPipe;
+	HANDLE writePipe;
+	STARTUPINFO sInfo; 
+	PROCESS_INFORMATION pInfo; 
+	SECURITY_ATTRIBUTES secattr; 
+
+	ZeroMemory (&secattr, sizeof (secattr));
+	secattr.nLength = sizeof (secattr);
+	secattr.bInheritHandle = TRUE;
+
+	if (strlen (word[2]) > 0)
+	{
+		strcpy (commandLine, "cmd.exe /c ");
+
+		if (!stricmp("-O", word[2]))
+		{
+			/*strcat (commandLine, word_eol[3]);*/
+			xchat_printf (ph, "Printing Exec output to others is not supported yet.\n");
+			return XCHAT_EAT_XCHAT;
+		}
+		else
+		{
+			strcat (commandLine, word_eol[2]);
+		}
+
+		CreatePipe (&readPipe, &writePipe, &secattr, 0); /* might be replaced with MyCreatePipeEx */
+
+		ZeroMemory (&sInfo, sizeof (sInfo));
+		ZeroMemory (&pInfo, sizeof (pInfo));
+		sInfo.cb = sizeof (sInfo);
+		sInfo.dwFlags = STARTF_USESTDHANDLES;
+		sInfo.hStdInput = NULL;
+		sInfo.hStdOutput = writePipe;
+		sInfo.hStdError = writePipe;
+
+		CreateProcess (0, commandLine, 0, 0, TRUE, NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, 0, 0, &sInfo, &pInfo);
+		CloseHandle (writePipe);
+
+		start = time (0);
+		while (PeekNamedPipe (readPipe, buffer, 1, &dwRead, &dwAvail, &dwLeft) && timeElapsed < 10)
+		{
+			if (dwRead)
+			{
+				if (ReadFile (readPipe, buffer, sizeof (buffer) - 1, &dwRead, NULL) && dwRead != 0 )
+				{
+					/* avoid garbage */
+					buffer[dwRead] = '\0';
+					xchat_printf (ph, "%s", buffer);
+				}
+			}
+			else
+			{
+				/* this way we'll more likely get full lines */
+				SleepEx (100, TRUE);
+			}
+			timeElapsed = difftime (time (0), start);
+		}
+	}
+
+	/* display a newline to separate things */
+	xchat_printf (ph, "\n");
+
+	if (timeElapsed >= 10)
+	{
+		xchat_printf (ph, "Command took too much time to run, execution aborted.\n");
+	}
+
+	CloseHandle (readPipe);
+	CloseHandle (pInfo.hProcess);
+	CloseHandle (pInfo.hThread);
+
+	return XCHAT_EAT_XCHAT;
+}
+
+int
+xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg)
+{
+	ph = plugin_handle;
+
+	*plugin_name = name;
+	*plugin_desc = desc;
+	*plugin_version = version;
+
+	xchat_hook_command (ph, "EXEC", XCHAT_PRI_NORM, run_command, "Usage: /EXEC [-O] - execute commands inside XChat", 0);
+	xchat_printf (ph, "%s plugin loaded\n", name);
+
+	return 1;       /* return 1 for success */
+}
+
+int
+xchat_plugin_deinit (void)
+{
+	xchat_printf (ph, "%s plugin unloaded\n", name);
+	return 1;
+}
diff --git a/plugins/exec/exec.def b/plugins/exec/exec.def
new file mode 100644
index 00000000..77670bf2
--- /dev/null
+++ b/plugins/exec/exec.def
@@ -0,0 +1,3 @@
+EXPORTS 

+xchat_plugin_init 

+xchat_plugin_deinit 

diff --git a/plugins/exec/exec.vcxproj b/plugins/exec/exec.vcxproj
new file mode 100644
index 00000000..22e6200a
--- /dev/null
+++ b/plugins/exec/exec.vcxproj
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="utf-8"?>

+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

+  <ItemGroup Label="ProjectConfigurations">

+    <ProjectConfiguration Include="Release|Win32">

+      <Configuration>Release</Configuration>

+      <Platform>Win32</Platform>

+    </ProjectConfiguration>

+    <ProjectConfiguration Include="Release|x64">

+      <Configuration>Release</Configuration>

+      <Platform>x64</Platform>

+    </ProjectConfiguration>

+  </ItemGroup>

+  <PropertyGroup Label="Globals">

+    <ProjectGuid>{17E4BE39-76F7-4A06-AD21-EFD0C5091F76}</ProjectGuid>

+    <Keyword>Win32Proj</Keyword>

+    <RootNamespace>exec</RootNamespace>

+  </PropertyGroup>

+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">

+    <ConfigurationType>DynamicLibrary</ConfigurationType>

+    <UseDebugLibraries>false</UseDebugLibraries>

+    <WholeProgramOptimization>true</WholeProgramOptimization>

+    <CharacterSet>MultiByte</CharacterSet>

+    <PlatformToolset>WDK7</PlatformToolset>

+  </PropertyGroup>

+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">

+    <ConfigurationType>DynamicLibrary</ConfigurationType>

+    <UseDebugLibraries>false</UseDebugLibraries>

+    <WholeProgramOptimization>true</WholeProgramOptimization>

+    <CharacterSet>MultiByte</CharacterSet>

+    <PlatformToolset>WDK7</PlatformToolset>

+  </PropertyGroup>

+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />

+  <ImportGroup Label="ExtensionSettings">

+  </ImportGroup>

+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">

+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />

+    <Import Project="..\..\win32\xchat.props" />

+  </ImportGroup>

+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">

+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />

+    <Import Project="..\..\win32\xchat.props" />

+  </ImportGroup>

+  <PropertyGroup Label="UserMacros" />

+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">

+    <LinkIncremental>false</LinkIncremental>

+    <TargetName>xcexec</TargetName>

+    <OutDir>$(SolutionDir)build\$(PlatformName)\bin</OutDir>

+    <IntDir>$(SolutionDir)build\$(PlatformName)\obj\$(ProjectName)</IntDir>

+  </PropertyGroup>

+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">

+    <LinkIncremental>false</LinkIncremental>

+    <TargetName>xcexec</TargetName>

+    <OutDir>$(SolutionDir)build\$(PlatformName)\bin</OutDir>

+    <IntDir>$(SolutionDir)build\$(PlatformName)\obj\$(ProjectName)</IntDir>

+  </PropertyGroup>

+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">

+    <ClCompile>

+      <WarningLevel>Level1</WarningLevel>

+      <PrecompiledHeader>

+      </PrecompiledHeader>

+      <Optimization>MaxSpeed</Optimization>

+      <FunctionLevelLinking>true</FunctionLevelLinking>

+      <IntrinsicFunctions>true</IntrinsicFunctions>

+      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;EXEC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>

+      <MultiProcessorCompilation>true</MultiProcessorCompilation>

+      <AdditionalIncludeDirectories>..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

+    </ClCompile>

+    <Link>

+      <SubSystem>Windows</SubSystem>

+      <GenerateDebugInformation>true</GenerateDebugInformation>

+      <EnableCOMDATFolding>true</EnableCOMDATFolding>

+      <OptimizeReferences>true</OptimizeReferences>

+      <ModuleDefinitionFile>exec.def</ModuleDefinitionFile>

+    </Link>

+  </ItemDefinitionGroup>

+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">

+    <ClCompile>

+      <WarningLevel>Level1</WarningLevel>

+      <PrecompiledHeader>

+      </PrecompiledHeader>

+      <Optimization>MaxSpeed</Optimization>

+      <FunctionLevelLinking>true</FunctionLevelLinking>

+      <IntrinsicFunctions>true</IntrinsicFunctions>

+      <PreprocessorDefinitions>WIN32;_WIN64;NDEBUG;_WINDOWS;_USRDLL;EXEC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>

+      <MultiProcessorCompilation>true</MultiProcessorCompilation>

+      <AdditionalIncludeDirectories>..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

+    </ClCompile>

+    <Link>

+      <SubSystem>Windows</SubSystem>

+      <GenerateDebugInformation>true</GenerateDebugInformation>

+      <EnableCOMDATFolding>true</EnableCOMDATFolding>

+      <OptimizeReferences>true</OptimizeReferences>

+      <ModuleDefinitionFile>exec.def</ModuleDefinitionFile>

+    </Link>

+  </ItemDefinitionGroup>

+  <ItemGroup>

+    <None Include="exec.def" />

+  </ItemGroup>

+  <ItemGroup>

+    <ClCompile Include="exec.c" />

+  </ItemGroup>

+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

+  <ImportGroup Label="ExtensionTargets">

+  </ImportGroup>

+</Project>
\ No newline at end of file
diff --git a/plugins/exec/exec.vcxproj.filters b/plugins/exec/exec.vcxproj.filters
new file mode 100644
index 00000000..f800df93
--- /dev/null
+++ b/plugins/exec/exec.vcxproj.filters
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>

+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

+  <ItemGroup>

+    <Filter Include="Source Files">

+      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>

+      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>

+    </Filter>

+    <Filter Include="Resource Files">

+      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>

+      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>

+    </Filter>

+  </ItemGroup>

+  <ItemGroup>

+    <None Include="exec.def">

+      <Filter>Resource Files</Filter>

+    </None>

+  </ItemGroup>

+  <ItemGroup>

+    <ClCompile Include="exec.c">

+      <Filter>Source Files</Filter>

+    </ClCompile>

+  </ItemGroup>

+</Project>
\ No newline at end of file
diff --git a/plugins/exec/exec.vcxproj.user b/plugins/exec/exec.vcxproj.user
new file mode 100644
index 00000000..695b5c78
--- /dev/null
+++ b/plugins/exec/exec.vcxproj.user
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="utf-8"?>

+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

+</Project>
\ No newline at end of file
diff --git a/plugins/exec/makefile.mak b/plugins/exec/makefile.mak
new file mode 100644
index 00000000..d2153faf
--- /dev/null
+++ b/plugins/exec/makefile.mak
@@ -0,0 +1,18 @@
+include "..\..\src\makeinc.mak"

+

+all: exec.obj exec.def

+	link $(LDFLAGS) $(LIBS) /dll /out:xcexec.dll /def:exec.def exec.obj

+

+exec.def:

+	echo EXPORTS > exec.def

+	echo xchat_plugin_init >> exec.def

+	echo xchat_plugin_deinit >> exec.def

+

+exec.obj: exec.c makefile.mak

+	cl $(CFLAGS) $(GLIB) /I.. exec.c

+

+clean:

+	del *.obj

+	del *.dll

+	del *.exp

+	del *.lib