Convert doat to an internal command

- Trivial plugin
- Useful for many users
- Was under a dumb license
This commit is contained in:
Patrick Griffis 2016-11-08 22:34:31 -05:00 committed by tomek
parent a0e80ebda2
commit 85bdb06cad
12 changed files with 100 additions and 282 deletions

View File

@ -134,10 +134,6 @@ AC_ARG_ENABLE(checksum,
[AS_HELP_STRING([--disable-checksum],[disable the Checksum plugin])],
checksum=$enableval, checksum=yes)
AC_ARG_ENABLE(doat,
[AS_HELP_STRING([--disable-doat],[disable the Do At plugin])],
doat=$enableval, doat=yes)
AC_ARG_ENABLE(fishlim,
[AS_HELP_STRING([--disable-fishlim],[disable the FiSHLiM plugin])],
fishlim=$enableval, fishlim=yes)
@ -457,21 +453,6 @@ AS_IF([test "$checksum" != "no"], [
])
])
dnl *********************************************************************
dnl ** DO AT ************************************************************
dnl *********************************************************************
AS_IF([test "$doat" != "no"], [
AC_MSG_CHECKING(for plugin interface used by Do At)
doat=no
AS_IF([test "$plugin" = yes], [
doat=yes
AC_MSG_RESULT([yes])
], [
AC_MSG_RESULT([plugins are disabled, use the --enable-plugin option for Do At])
])
])
dnl *********************************************************************
dnl ** FiSHLiM **********************************************************
dnl *********************************************************************
@ -609,7 +590,6 @@ AM_CONDITIONAL(DO_LUA, test "x$lua" = "xyes")
AM_CONDITIONAL(DO_PYTHON, test "x$python" != "xno")
AM_CONDITIONAL(DO_PLUGIN, test "x$plugin" = "xyes")
AM_CONDITIONAL(DO_CHECKSUM, test "x$checksum" = "xyes")
AM_CONDITIONAL(DO_DOAT, test "x$doat" = "xyes")
AM_CONDITIONAL(DO_FISHLIM, test "x$fishlim" = "xyes")
AM_CONDITIONAL(DO_SYSINFO, test "x$sysinfo" = "xyes")
AM_CONDITIONAL(DO_STATIC_ANALYSIS, test "x$analyze" = "xyes")
@ -767,7 +747,6 @@ plugins/lua/Makefile
plugins/python/Makefile
plugins/perl/Makefile
plugins/checksum/Makefile
plugins/doat/Makefile
plugins/fishlim/Makefile
plugins/sysinfo/Makefile
po/Makefile.in
@ -794,7 +773,6 @@ echo Perl .................. : $perl
echo Python ................ : $python
echo
echo Checksum .............. : $checksum
echo Do At ................. : $doat
echo FiSHLiM ............... : $fishlim
echo SysInfo ............... : $sysinfo
echo

View File

@ -10,10 +10,6 @@ if DO_PERL
perldir = perl
endif
if DO_DOAT
doatdir = doat
endif
if DO_FISHLIM
fishlimdir = fishlim
endif
@ -26,4 +22,4 @@ if DO_SYSINFO
sysinfodir = sysinfo
endif
SUBDIRS = $(lua) $(pythondir) $(perldir) $(checksumdir) $(doatdir) $(fishlimdir) $(sysinfodir)
SUBDIRS = $(lua) $(pythondir) $(perldir) $(checksumdir) $(fishlimdir) $(sysinfodir)

View File

@ -1,9 +0,0 @@
libdir = $(hexchatlibdir)
lib_LTLIBRARIES = doat.la
doat_la_SOURCES = doat.c
doat_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module
doat_la_LIBADD = $(GLIB_LIBS)
doat_la_CPPFLAGS = -I$(top_srcdir)/src/common
doat_la_CFLAGS = $(GLIB_CFLAGS)

View File

@ -1,92 +0,0 @@
/* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING or http://lwsitu.com/xchat/COPYING
* for more details. */
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <glib.h>
#include "hexchat-plugin.h"
static hexchat_plugin *ph;
static int
parse_command( char *word[], char *word_eol[], void *userdata ) {
char *channel = NULL, *server = NULL, *token = NULL;
/* char *save_ptr1 = NULL;*/
char *str1 = NULL;
char *delimiter = NULL;
hexchat_context *ctx = NULL;
if( word[2] != NULL && word[3] != NULL ) {
for( str1 = word[2]; ; str1 = NULL ) {
/* token = strtok_r( str1, ",", &save_ptr1 );*/
token = strtok( str1, "," );
/* printf( "token: %s\n", token );*/
if( token == NULL ) {
break;
}
channel = g_strdup( token );
delimiter = strchr( channel, '/' );
server = NULL;
if( delimiter != NULL ) {
*delimiter = '\0';
if( strlen( delimiter + 1 ) > 0 ) {
server = g_strdup( delimiter + 1 );
}
}
/* /Network form */
if( strlen( channel ) == 0 ) {
g_free( channel );
channel = NULL;
}
/* printf( "channel[%s] server[%s]\n", channel, server );*/
if( (ctx = hexchat_find_context( ph, server, channel ) ) != NULL ) {
if( hexchat_set_context( ph, ctx ) ) {
hexchat_command( ph, word_eol[3] );
}
}
g_free( channel );
g_free( server );
}
}
return HEXCHAT_EAT_HEXCHAT;
}
int
hexchat_plugin_init( hexchat_plugin * plugin_handle, char **plugin_name,
char **plugin_desc, char **plugin_version, char *arg ) {
ph = plugin_handle;
*plugin_name = "Do At";
*plugin_version = "1.0001";
*plugin_desc = "Perform an arbitrary command on multiple channels";
hexchat_hook_command( ph, "doat", HEXCHAT_PRI_NORM, parse_command, "DOAT [channel,list,/network] [command], perform a command on multiple contexts", NULL );
hexchat_print (ph, "Do At plugin loaded\n");
return 1;
}
int
hexchat_plugin_deinit (void)
{
hexchat_print (ph, "Do At plugin unloaded\n");
return 1;
}

View File

@ -1,3 +0,0 @@
EXPORTS
hexchat_plugin_init
hexchat_plugin_deinit

View File

@ -1,59 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Configuration">
<PlatformToolset>v140</PlatformToolset>
<ConfigurationType>DynamicLibrary</ConfigurationType>
</PropertyGroup>
<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>{4980AF24-9D42-427D-A8E6-0DF3B97C455D}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>doat</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\win32\hexchat.props" />
<PropertyGroup>
<TargetName>hcdoat</TargetName>
<OutDir>$(HexChatRel)plugins\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;DOAT_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\src\common;$(HexChatLib);$(Glib);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(DepsRoot)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>$(DepLibs);%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>doat.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>WIN32;_WIN64;_AMD64_;NDEBUG;_WINDOWS;_USRDLL;DOAT_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>..\..\src\common;$(HexChatLib);$(Glib);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>$(DepsRoot)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>$(DepLibs);%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>doat.def</ModuleDefinitionFile>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="doat.c" />
</ItemGroup>
<ItemGroup>
<None Include="doat.def" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

View File

@ -1,23 +0,0 @@
<?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>
<ClCompile Include="doat.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="doat.def">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
</Project>

View File

@ -1447,6 +1447,41 @@ cmd_dns (struct session *sess, char *tbuf, char *word[], char *word_eol[])
return FALSE;
}
static int
cmd_doat (struct session *sess, char *tbuf, char *word[], char *word_eol[])
{
GStrv channels;
guint i;
if (!word[2] || !*word[2] || !word[3] || !*word[3])
return FALSE;
channels = g_strsplit (word[2], ",", -1);
for (i = 0; channels[i] && *channels[i]; ++i)
{
char *chan = channels[i];
char *serv;
session *ctx;
/* Split channel and network, either may be empty */
if ((serv = strchr (chan, '/')))
{
*serv = '\0';
serv++;
if (!strlen (serv))
serv = NULL;
}
if (!strlen (chan))
chan = NULL;
if ((ctx = plugin_find_context (serv, chan, sess->server)))
handle_command (ctx, word_eol[3], FALSE);
}
g_strfreev (channels);
return TRUE;
}
static int
cmd_echo (struct session *sess, char *tbuf, char *word[], char *word_eol[])
{
@ -3931,6 +3966,7 @@ const struct commands xc_cmds[] = {
N_("DEVOICE <nick>, removes voice status from the nick on the current channel (needs chanop)")},
{"DISCON", cmd_discon, 0, 0, 1, N_("DISCON, Disconnects from server")},
{"DNS", cmd_dns, 0, 0, 1, N_("DNS <nick|host|ip>, Resolves an IP or hostname")},
{"DOAT", cmd_doat, 0, 0, 1, N_("DOAT <channel,list,/network> <command>")},
{"ECHO", cmd_echo, 0, 0, 1, N_("ECHO <text>, Prints text locally")},
#ifndef WIN32
{"EXEC", cmd_exec, 0, 0, 1,

View File

@ -452,7 +452,6 @@ plugin_auto_load (session *sess)
/* a long list of bundled plugins that should be loaded automatically,
* user plugins should go to <config>, leave Program Files alone! */
for_files (lib_dir, "hcchecksum.dll", plugin_auto_load_cb);
for_files (lib_dir, "hcdoat.dll", plugin_auto_load_cb);
for_files (lib_dir, "hcexec.dll", plugin_auto_load_cb);
for_files (lib_dir, "hcfishlim.dll", plugin_auto_load_cb);
for_files(lib_dir, "hclua.dll", plugin_auto_load_cb);
@ -871,6 +870,67 @@ plugin_show_help (session *sess, char *cmd)
return 0;
}
session *
plugin_find_context (const char *servname, const char *channel, server *current_server)
{
GSList *slist, *clist, *sessions = NULL;
server *serv;
session *sess;
char *netname;
if (servname == NULL && channel == NULL)
return current_sess;
slist = serv_list;
while (slist)
{
serv = slist->data;
netname = server_get_network (serv, TRUE);
if (servname == NULL ||
rfc_casecmp (servname, serv->servername) == 0 ||
g_ascii_strcasecmp (servname, serv->hostname) == 0 ||
g_ascii_strcasecmp (servname, netname) == 0)
{
if (channel == NULL)
return serv->front_session;
clist = sess_list;
while (clist)
{
sess = clist->data;
if (sess->server == serv)
{
if (rfc_casecmp (channel, sess->channel) == 0)
{
if (sess->server == current_server)
{
g_slist_free (sessions);
return sess;
} else
{
sessions = g_slist_prepend (sessions, sess);
}
}
}
clist = clist->next;
}
}
slist = slist->next;
}
if (sessions)
{
sessions = g_slist_reverse (sessions);
sess = sessions->data;
g_slist_free (sessions);
return sess;
}
return NULL;
}
/* ========================================================= */
/* ===== these are the functions plugins actually call ===== */
/* ========================================================= */
@ -1038,61 +1098,7 @@ hexchat_set_context (hexchat_plugin *ph, hexchat_context *context)
hexchat_context *
hexchat_find_context (hexchat_plugin *ph, const char *servname, const char *channel)
{
GSList *slist, *clist, *sessions = NULL;
server *serv;
session *sess;
char *netname;
if (servname == NULL && channel == NULL)
return current_sess;
slist = serv_list;
while (slist)
{
serv = slist->data;
netname = server_get_network (serv, TRUE);
if (servname == NULL ||
rfc_casecmp (servname, serv->servername) == 0 ||
g_ascii_strcasecmp (servname, serv->hostname) == 0 ||
g_ascii_strcasecmp (servname, netname) == 0)
{
if (channel == NULL)
return serv->front_session;
clist = sess_list;
while (clist)
{
sess = clist->data;
if (sess->server == serv)
{
if (rfc_casecmp (channel, sess->channel) == 0)
{
if (sess->server == ph->context->server)
{
g_slist_free (sessions);
return sess;
} else
{
sessions = g_slist_prepend (sessions, sess);
}
}
}
clist = clist->next;
}
}
slist = slist->next;
}
if (sessions)
{
sessions = g_slist_reverse (sessions);
sess = sessions->data;
g_slist_free (sessions);
return sess;
}
return NULL;
return plugin_find_context (servname, channel, ph->context->server);
}
const char *

View File

@ -179,5 +179,6 @@ int plugin_emit_keypress (session *sess, unsigned int state, unsigned int keyval
GList* plugin_command_list(GList *tmp_list);
int plugin_show_help (session *sess, char *cmd);
void plugin_command_foreach (session *sess, void *userdata, void (*cb) (session *sess, void *userdata, char *name, char *usage));
session *plugin_find_context (const char *servname, const char *channel, server *current_server);
#endif

View File

@ -29,11 +29,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "python2", "..\plugins\pytho
{87554B59-006C-4D94-9714-897B27067BA3} = {87554B59-006C-4D94-9714-897B27067BA3}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doat", "..\plugins\doat\doat.vcxproj", "{4980AF24-9D42-427D-A8E6-0DF3B97C455D}"
ProjectSection(ProjectDependencies) = postProject
{87554B59-006C-4D94-9714-897B27067BA3} = {87554B59-006C-4D94-9714-897B27067BA3}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "checksum", "..\plugins\checksum\checksum.vcxproj", "{5EF7F47D-D09C-43C4-BF64-B28B11A0FF91}"
ProjectSection(ProjectDependencies) = postProject
{87554B59-006C-4D94-9714-897B27067BA3} = {87554B59-006C-4D94-9714-897B27067BA3}
@ -87,7 +82,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "installer", "installer\inst
{C2321A03-0BA7-45B3-8740-ABD82B36B0BF} = {C2321A03-0BA7-45B3-8740-ABD82B36B0BF}
{19C52A0A-A790-409E-A28A-9745FF990F5C} = {19C52A0A-A790-409E-A28A-9745FF990F5C}
{BF0EBC16-68AD-4CD1-864C-5B56836EBE2A} = {BF0EBC16-68AD-4CD1-864C-5B56836EBE2A}
{4980AF24-9D42-427D-A8E6-0DF3B97C455D} = {4980AF24-9D42-427D-A8E6-0DF3B97C455D}
{17E4BE39-76F7-4A06-AD21-EFD0C5091F76} = {17E4BE39-76F7-4A06-AD21-EFD0C5091F76}
{4C0F3940-2EEE-4646-82F7-6CE75B9A72F4} = {4C0F3940-2EEE-4646-82F7-6CE75B9A72F4}
{B10A2C41-344C-43E0-A32D-B9587C198D8B} = {B10A2C41-344C-43E0-A32D-B9587C198D8B}
@ -156,10 +150,6 @@ Global
{19C52A0A-A790-409E-A28A-9745FF990F5C}.Release|Win32.Build.0 = Release|Win32
{19C52A0A-A790-409E-A28A-9745FF990F5C}.Release|x64.ActiveCfg = Release|x64
{19C52A0A-A790-409E-A28A-9745FF990F5C}.Release|x64.Build.0 = Release|x64
{4980AF24-9D42-427D-A8E6-0DF3B97C455D}.Release|Win32.ActiveCfg = Release|Win32
{4980AF24-9D42-427D-A8E6-0DF3B97C455D}.Release|Win32.Build.0 = Release|Win32
{4980AF24-9D42-427D-A8E6-0DF3B97C455D}.Release|x64.ActiveCfg = Release|x64
{4980AF24-9D42-427D-A8E6-0DF3B97C455D}.Release|x64.Build.0 = Release|x64
{5EF7F47D-D09C-43C4-BF64-B28B11A0FF91}.Release|Win32.ActiveCfg = Release|Win32
{5EF7F47D-D09C-43C4-BF64-B28B11A0FF91}.Release|Win32.Build.0 = Release|Win32
{5EF7F47D-D09C-43C4-BF64-B28B11A0FF91}.Release|x64.ActiveCfg = Release|x64
@ -237,7 +227,6 @@ Global
{E4BDB4C8-2335-415A-ACEE-BA88B19BFE82} = {AAACEB12-9475-410E-AF5A-FDFF907E9043}
{E93E1255-95D1-4B08-8FDF-B53CC6A21280} = {AAACEB12-9475-410E-AF5A-FDFF907E9043}
{19C52A0A-A790-409E-A28A-9745FF990F5C} = {D237DA6B-BD5F-46C0-8BEA-50E9A1340240}
{4980AF24-9D42-427D-A8E6-0DF3B97C455D} = {561126F4-FA18-45FC-A2BF-8F858F161D6D}
{5EF7F47D-D09C-43C4-BF64-B28B11A0FF91} = {561126F4-FA18-45FC-A2BF-8F858F161D6D}
{17E4BE39-76F7-4A06-AD21-EFD0C5091F76} = {561126F4-FA18-45FC-A2BF-8F858F161D6D}
{3C4F42FC-292A-420B-B63D-C03DFBDD8E4E} = {561126F4-FA18-45FC-A2BF-8F858F161D6D}

View File

@ -64,7 +64,6 @@ Name: "translations"; Description: "Translations"; Types: normal custom; Flags:
Name: "spell"; Description: "Spelling Dictionaries"; Types: custom; Flags: disablenouninstallwarning
Name: "plugins"; Description: "Plugins"; Types: custom; Flags: disablenouninstallwarning
Name: "plugins\checksum"; Description: "Checksum"; Types: custom; Flags: disablenouninstallwarning
Name: "plugins\doat"; Description: "Do At"; Types: normal custom; Flags: disablenouninstallwarning
Name: "plugins\exec"; Description: "Exec"; Types: custom; Flags: disablenouninstallwarning
Name: "plugins\fishlim"; Description: "FiSHLiM"; Types: custom; Flags: disablenouninstallwarning
Name: "plugins\mpcinfo"; Description: "mpcInfo"; Types: custom; Flags: disablenouninstallwarning
@ -167,7 +166,6 @@ Source: "share\lua\lgi\*.lua"; DestDir: "{app}\share\lua\lgi"; Flags: ignorevers
Source: "share\lua\lgi\override\*.lua"; DestDir: "{app}\share\lua\lgi\override"; Flags: ignoreversion; Components: langs\lua
Source: "plugins\hcchecksum.dll"; DestDir: "{app}\plugins"; Flags: ignoreversion; Components: plugins\checksum
Source: "plugins\hcdoat.dll"; DestDir: "{app}\plugins"; Flags: ignoreversion; Components: plugins\doat
Source: "plugins\hcexec.dll"; DestDir: "{app}\plugins"; Flags: ignoreversion; Components: plugins\exec
Source: "plugins\hcfishlim.dll"; DestDir: "{app}\plugins"; Flags: ignoreversion; Components: plugins\fishlim
Source: "share\music.png"; DestDir: "{app}\share"; Flags: ignoreversion; Components: plugins\winamp or plugins\mpcinfo