summaryrefslogtreecommitdiff
path: root/plugins/MimCmd
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/MimCmd')
-rw-r--r--plugins/MimCmd/MimCmd.vcxproj36
-rw-r--r--plugins/MimCmd/MimCmd.vcxproj.filters73
-rw-r--r--plugins/MimCmd/res/version.rc38
-rw-r--r--plugins/MimCmd/src/MimCmd.cpp112
-rw-r--r--plugins/MimCmd/src/commands.cpp218
-rw-r--r--plugins/MimCmd/src/commands.h42
-rw-r--r--plugins/MimCmd/src/resource.h14
-rw-r--r--plugins/MimCmd/src/stdafx.cxx18
-rw-r--r--plugins/MimCmd/src/stdafx.h37
-rw-r--r--plugins/MimCmd/src/version.h14
10 files changed, 602 insertions, 0 deletions
diff --git a/plugins/MimCmd/MimCmd.vcxproj b/plugins/MimCmd/MimCmd.vcxproj
new file mode 100644
index 0000000000..12b12d4efd
--- /dev/null
+++ b/plugins/MimCmd/MimCmd.vcxproj
@@ -0,0 +1,36 @@
+<?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="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <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>{1E3BB48A-FFBC-4A03-8C43-9124A484BE51}</ProjectGuid>
+ <ProjectName>MimCmd</ProjectName>
+ </PropertyGroup>
+ <ImportGroup Label="PropertySheets">
+ <Import Project="$(ProjectDir)..\..\build\vc.common\app.props" />
+ </ImportGroup>
+ <ItemGroup>
+ <ClCompile Include="..\CmdLine\src\mimcmd_ipc.cpp" />
+ </ItemGroup>
+ <ItemDefinitionGroup>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ </Link>
+ </ItemDefinitionGroup>
+</Project> \ No newline at end of file
diff --git a/plugins/MimCmd/MimCmd.vcxproj.filters b/plugins/MimCmd/MimCmd.vcxproj.filters
new file mode 100644
index 0000000000..5d862e9cd3
--- /dev/null
+++ b/plugins/MimCmd/MimCmd.vcxproj.filters
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$(ProjectDir)..\..\build\vc.common\common.filters" />
+ <ItemGroup>
+ <ClCompile Include="..\CmdLine\src\mimcmd_ipc.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\stdafx.cxx">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\commands.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\MimCmd.cpp" />
+ <ClCompile Include="src\commands.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\MimCmd.cpp" />
+ <ClCompile Include="src\commands.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\MimCmd.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="src\commands.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\resource.h" />
+ <ClInclude Include="src\stdafx.h" />
+ <ClInclude Include="src\version.h" />
+ <ClInclude Include="src\commands.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\resource.h" />
+ <ClInclude Include="src\stdafx.h" />
+ <ClInclude Include="src\version.h" />
+ <ClInclude Include="src\commands.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\resource.h" />
+ <ClInclude Include="src\stdafx.h" />
+ <ClInclude Include="src\version.h" />
+ <ClInclude Include="src\commands.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\resource.h" />
+ <ClInclude Include="src\stdafx.h" />
+ <ClInclude Include="src\version.h" />
+ <ClInclude Include="src\commands.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\resource.h" />
+ <ClInclude Include="src\stdafx.h" />
+ <ClInclude Include="src\version.h" />
+ <ClInclude Include="src\commands.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\resource.h" />
+ <ClInclude Include="src\stdafx.h" />
+ <ClInclude Include="src\version.h" />
+ <ClInclude Include="src\commands.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\resource.h" />
+ <ClInclude Include="src\stdafx.h" />
+ <ClInclude Include="src\version.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="res\*.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
+ </ItemGroup>
+</Project> \ No newline at end of file
diff --git a/plugins/MimCmd/res/version.rc b/plugins/MimCmd/res/version.rc
new file mode 100644
index 0000000000..5bfbab4754
--- /dev/null
+++ b/plugins/MimCmd/res/version.rc
@@ -0,0 +1,38 @@
+// Microsoft Visual C++ generated resource script.
+//
+#ifdef APSTUDIO_INVOKED
+#error this file is not editable by Microsoft Visual C++
+#endif //APSTUDIO_INVOKED
+
+#include "afxres.h"
+#include "..\src\version.h"
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION __FILEVERSION_STRING
+ PRODUCTVERSION __FILEVERSION_STRING
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x0L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "000004b0"
+ BEGIN
+ VALUE "FileDescription", __DESCRIPTION
+ VALUE "InternalName", __PLUGIN_NAME
+ VALUE "LegalCopyright", __COPYRIGHT
+ VALUE "OriginalFilename", __FILENAME
+ VALUE "ProductName", __PLUGIN_NAME
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x0, 1200
+ END
+END
diff --git a/plugins/MimCmd/src/MimCmd.cpp b/plugins/MimCmd/src/MimCmd.cpp
new file mode 100644
index 0000000000..6bad9d81aa
--- /dev/null
+++ b/plugins/MimCmd/src/MimCmd.cpp
@@ -0,0 +1,112 @@
+/*
+CmdLine plugin for Miranda IM
+
+Copyright © 2007 Cristian Libotean
+
+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 the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "stdafx.h"
+
+int hLangpack = 0;
+
+int lpprintf(const char *format, ...)
+{
+ va_list va;
+ va_start(va, format);
+ const int MAX_SIZE = 16192;
+ char buffer[MAX_SIZE] = {0};
+ int len = mir_vsnprintf(buffer, MAX_SIZE - 1, format, va);
+ buffer[MAX_SIZE - 1] = 0;
+ va_end(va);
+ CharToOemBuffA(buffer, buffer, len);
+ printf("%s", buffer);
+
+ return len;
+}
+
+char* GetProgramName(char *programName, int size)
+{
+ char name[512];
+ GetModuleFileNameA(GetModuleHandle(NULL), name, sizeof(name));
+ char *p = strrchr(name, '\\');
+ if (p)
+ strncpy_s(programName, size, p + 1, _TRUNCATE);
+ else
+ strncpy_s(programName, size, name, _TRUNCATE);
+
+ return programName;
+}
+
+void PrintUsage()
+{
+ char name[128];
+ GetProgramName(name, sizeof(name));
+
+ lpprintf(Translate("%s usage:\n"), name);
+ lpprintf(Translate("%s <command> [<param> [<param> [...]]].\n"), name);
+ lpprintf(Translate("This will tell Miranda to run the specified command. The commands can have zero, one or more parameters. Use '%s help' to get a list of possible commands.\n"), name);
+ lpprintf(Translate("No command can have more than %d parameters.\n"), MAX_ARGUMENTS - 1);
+}
+
+void ShowVersion()
+{
+ char name[128];
+ char message[1024];
+ GetProgramName(name, sizeof(name));
+ mir_snprintf(message, sizeof(message), Translate("%s version %s"), name, __VERSION_STRING_DOTS);
+
+ lpprintf("%s\n", message);
+}
+
+int main(int argc, char *argv[])
+{
+ int error = 0;
+ if ((argc == 2) && (mir_strcmp(argv[1], "-v") == 0))
+ {
+ ShowVersion();
+
+ return 0;
+ }
+
+ if ((InitClient()) || (ConnectToMiranda()) || (GetKnownCommands()) || (LoadLangPackModule()))
+ {
+ lpprintf("Could not create connection with Miranda or could not retrieve list of known commands.\n");
+ error = MIMRES_NOMIRANDA;
+ }
+ else{
+ if ((argc <= 1) || (argc > MAX_ARGUMENTS))
+ {
+ PrintUsage();
+ }
+ else{
+ PReply reply = ParseCommand(argv, argc);
+ if (reply)
+ {
+ error = reply->code;
+ lpprintf("%s\n", reply->message);
+ }
+ else{
+ lpprintf(Translate("Unknown command '%s'.\n"), argv[1]);
+ }
+
+ DestroyKnownCommands();
+ DisconnectFromMiranda();
+ DestroyClient();
+ }
+ }
+
+ return error;
+}
diff --git a/plugins/MimCmd/src/commands.cpp b/plugins/MimCmd/src/commands.cpp
new file mode 100644
index 0000000000..7d844e5a68
--- /dev/null
+++ b/plugins/MimCmd/src/commands.cpp
@@ -0,0 +1,218 @@
+/*
+CmdLine plugin for Miranda IM
+
+Copyright © 2007 Cristian Libotean
+
+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 the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "stdafx.h"
+
+LISTCOMMANDS ListCommands = NULL;
+
+PCommand knownCommands = NULL;
+int cKnownCommands = 0;
+
+HMODULE hCmdLineDLL = NULL;
+
+char *GetMirandaFolder(char *mimFolder, int size)
+{
+ strncpy_s(mimFolder, size, sdCmdLine->mimFolder, _TRUNCATE);
+ mimFolder[size - 1] = 0;
+
+ return mimFolder;
+}
+
+
+int ConnectToMiranda()
+{
+ char pluginPath[1024];
+ GetMirandaFolder(pluginPath, sizeof(pluginPath));
+ mir_strcat(pluginPath, "\\plugins\\cmdline.dll");
+
+ ListCommands = NULL;
+
+ hCmdLineDLL = LoadLibraryA(pluginPath);
+
+ int failure = 1;
+ if (hCmdLineDLL)
+ {
+ ListCommands = (LISTCOMMANDS) GetProcAddress(hCmdLineDLL, "ListCommands");
+ }
+
+ if (ListCommands)
+ {
+ failure = 0;
+ }
+
+ return failure;
+}
+
+int DisconnectFromMiranda()
+{
+ return FreeLibrary(hCmdLineDLL);
+}
+
+int GetKnownCommands()
+{
+ ListCommands(&knownCommands, &cKnownCommands);
+
+ return (knownCommands == NULL);
+}
+
+int DestroyKnownCommands()
+{
+
+
+ return 0;
+}
+
+PCommand GetCommand(char *command)
+{
+ int i;
+ char lower[512];
+ strncpy_s(lower, command, _TRUNCATE);
+ _strlwr(lower);
+
+ for (i = 0; i < cKnownCommands; i++)
+ {
+ if (mir_strcmp(knownCommands[i].command, lower) == 0)
+ {
+ return &knownCommands[i];
+ }
+ }
+
+ //allow more parameters to trigger the help command - /h -h /? --help
+ if ((mir_strcmp(lower, "/h") == 0) || (mir_strcmp(lower, "-h") == 0) || (mir_strcmp(lower, "/?") == 0) || (mir_strcmp(lower, "--help") == 0))
+ {
+ for (i = 0; i < cKnownCommands; i++)
+ {
+ if (knownCommands[i].ID == MIMCMD_HELP)
+ {
+ return &knownCommands[i];
+ }
+ }
+ }
+
+ return NULL;
+}
+
+void HandleHelpCommand(PCommand, char *argv[], int argc, PReply reply)
+{
+ CMStringA szReply;
+
+ if (argc >= 3) {
+ PCommand command = GetCommand(argv[2]);
+
+ if (command) {
+ reply->code = MIMRES_SUCCESS;
+ szReply.Append(Translate(command->help));
+ }
+ else {
+ reply->code = MIMRES_NOTFOUND;
+ szReply.AppendFormat(Translate("No help for '%s'."), argv[2]);
+ }
+ }
+ else {
+ reply->code = MIMRES_SUCCESS;
+ szReply.Append(Translate("Available commands: "));
+
+ for (int i = 0; i < cKnownCommands - 1; i++) {
+ szReply.Append(knownCommands[i].command);
+ szReply.Append(", ");
+ }
+ szReply.Append(knownCommands[cKnownCommands-1].command);
+ szReply.AppendChar('.');
+ }
+ strncpy_s(reply->message, szReply, _TRUNCATE);
+}
+
+PReply ParseCommand(char *argv[], int argc)
+{
+ PCommand command = GetCommand(argv[1]);
+ if (!command)
+ return NULL;
+
+ PReply reply = &sdCmdLine->reply;
+ if (command->ID == MIMCMD_HELP)
+ HandleHelpCommand(command, argv, argc, reply);
+ else
+ ProcessConsoleCommand(command, argv, argc, reply);
+
+ return reply;
+}
+
+void FillSharedDataStruct(PCommand command, char *arguments[], int count)
+{
+ for (int i = 0; i < count; i++)
+ strncpy_s(sdCmdLine->arguments[i], ARGUMENT_SIZE, arguments[i], _TRUNCATE);
+
+ sdCmdLine->cArguments = count;
+ sdCmdLine->command = *command;
+ *sdCmdLine->reply.message = 0;
+ sdCmdLine->reply.code =-1;
+}
+
+void ProcessConsoleCommand(PCommand command, char *arguments[], int count, PReply reply)
+{
+ const HANDLE events[] = {heServerDone, heServerClose, heServerBufferFull};
+ const int cEvents = sizeof(events) / sizeof(events[0]);
+
+ if (WaitForSingleObject(hmClient, INFINITE) == WAIT_OBJECT_0)
+ {//got the mutex, we're the only one who can talk to miranda now
+ FillSharedDataStruct(command, arguments, count);
+ SetEvent(heServerExec); //tell Miranda to process the request
+
+ int done = FALSE;
+ while (!done)
+ {
+ switch (WaitForMultipleObjects(cEvents, events, FALSE, INFINITE)) //wait until server either finished processing or miranda was closed
+ {
+ case WAIT_OBJECT_0: //done event
+ {
+ done = TRUE;
+
+ break; //nothing to do
+ }
+
+ case WAIT_OBJECT_0 + 1: //close event
+ default:
+ {
+ mir_strcpy(sdCmdLine->reply.message, Translate("Miranda has been closed or an error has occurred while waiting for the result, could not process request."));
+ done = TRUE;
+
+ break;
+ }
+
+ case WAIT_OBJECT_0 + 2: //buffer full event
+ {
+ lpprintf("%s", reply->message);
+
+ break;
+ }
+ }
+ }
+
+ reply->code = sdCmdLine->reply.code;
+ strncpy_s(reply->message, sdCmdLine->reply.message, _TRUNCATE);
+
+ ReleaseMutex(hmClient); //let other possible clients talk to the server
+ }
+ else{
+ reply->code = -1;
+ *reply->message = 0;
+ }
+
+} \ No newline at end of file
diff --git a/plugins/MimCmd/src/commands.h b/plugins/MimCmd/src/commands.h
new file mode 100644
index 0000000000..4c60b49565
--- /dev/null
+++ b/plugins/MimCmd/src/commands.h
@@ -0,0 +1,42 @@
+/*
+CmdLine plugin for Miranda IM
+
+Copyright © 2007 Cristian Libotean
+
+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 the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#ifndef M_MIMCMD_COMMANDS_H
+#define M_MIMCMD_COMMANDS_H
+
+extern PCommand knownCommands;
+extern int cKnownCommands;
+
+typedef void (* LISTCOMMANDS)(PCommand *commands, int *count);
+
+extern LISTCOMMANDS ListCommands;
+
+char *GetMirandaFolder();
+
+int ConnectToMiranda();
+int DisconnectFromMiranda();
+int GetKnownCommands();
+int DestroyKnownCommands();
+
+PCommand GetCommand(char *command);
+PReply ParseCommand(char *argv[], int argc);
+void ProcessConsoleCommand(PCommand command, char *arguments[], int count, PReply reply);
+
+#endif \ No newline at end of file
diff --git a/plugins/MimCmd/src/resource.h b/plugins/MimCmd/src/resource.h
new file mode 100644
index 0000000000..c3bc570152
--- /dev/null
+++ b/plugins/MimCmd/src/resource.h
@@ -0,0 +1,14 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by version.rc
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 101
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1001
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/plugins/MimCmd/src/stdafx.cxx b/plugins/MimCmd/src/stdafx.cxx
new file mode 100644
index 0000000000..6fb37564b7
--- /dev/null
+++ b/plugins/MimCmd/src/stdafx.cxx
@@ -0,0 +1,18 @@
+/*
+Copyright (C) 2012-15 Miranda NG project (http://miranda-ng.org)
+
+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 the Free Software Foundation version 2
+of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "stdafx.h" \ No newline at end of file
diff --git a/plugins/MimCmd/src/stdafx.h b/plugins/MimCmd/src/stdafx.h
new file mode 100644
index 0000000000..8fb740fa75
--- /dev/null
+++ b/plugins/MimCmd/src/stdafx.h
@@ -0,0 +1,37 @@
+/*
+CmdLine plugin for Miranda IM
+
+Copyright © 2007 Cristian Libotean
+
+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 the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include <stdio.h>
+#include <windows.h>
+
+#define NO_MIMCMD_COMMANDS
+
+#include <newpluginapi.h>
+#include <m_langpack.h>
+#include <m_system.h>
+#include <m_system_cpp.h>
+#include <m_string.h>
+
+#include "..\CmdLine\src\mimcmd_ipc.h"
+#include "version.h"
+#include "..\CmdLine\src\utils.h"
+#include "commands.h"
+
+int lpprintf(const char *format, ...);
diff --git a/plugins/MimCmd/src/version.h b/plugins/MimCmd/src/version.h
new file mode 100644
index 0000000000..2fb1d42960
--- /dev/null
+++ b/plugins/MimCmd/src/version.h
@@ -0,0 +1,14 @@
+#define __MAJOR_VERSION 0
+#define __MINOR_VERSION 0
+#define __RELEASE_NUM 4
+#define __BUILD_NUM 1
+
+#include <stdver.h>
+
+#define __PLUGIN_NAME "MimCmd"
+#define __FILENAME "MimCmd.exe"
+#define __DESCRIPTION "This will tell Miranda to run the specified command."
+#define __AUTHOR "Cristian Libotean"
+#define __AUTHOREMAIL "eblis102@yahoo.com"
+#define __AUTHORWEB "http://miranda-ng.org/p/CmdLine/"
+#define __COPYRIGHT "© 2007-2011 Cristian Libotean"