diff --git a/README.md b/README.md index 78f064b..f50bcd2 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Command-execute is a plugin for Pidgin and Finch which lets you execute a comman It can also act on new chat messages. A conversation update is triggered everytime a message is received which you did not see yet. For example that applies for messages which occur in a window which is in the background of Finch. + +You can pass the name of the sender and the received message by using $sender and $msg in the command. Before that you have to activate this feature in the configuration menu. This feature is untested and probably not secure. I wouldn't recommend using it at the moment. ## How? Just put the `command-execute.so` file into your Pidgin/Finch plugin directory. Normally this is `~/.purple/plugins/` or `/usr/lib/pidgin/`. @@ -11,5 +13,7 @@ Normally this is `~/.purple/plugins/` or `/usr/lib/pidgin/`. If this does not work for you, you maybe have to compile the plugin yourself: gcc command-execute.c -O2 -Wall -fpic `pkg-config --cflags glib-2.0` -I/path/to/your/libpurple/headers -shared -o command-execute.so -## Why? -I wrote this plugin because non of the existing command execution plugins worked for Pidgin _and_ Finch. + +## TODO + +- Provide .so files for every platform. diff --git a/command-execute.c b/command-execute.c index b445f50..f5556cd 100644 --- a/command-execute.c +++ b/command-execute.c @@ -16,10 +16,12 @@ * along with this program; if not, see . */ + #define PURPLE_PLUGINS #include #include +#include #include #include "notify.h" @@ -33,23 +35,30 @@ #ifndef _PIDGIN_CONVERSATION_H_ typedef enum { - PIDGIN_UNSEEN_NONE, - PIDGIN_UNSEEN_EVENT, - PIDGIN_UNSEEN_NO_LOG, - PIDGIN_UNSEEN_TEXT, - PIDGIN_UNSEEN_NICK + PIDGIN_UNSEEN_NONE, + PIDGIN_UNSEEN_EVENT, + PIDGIN_UNSEEN_NO_LOG, + PIDGIN_UNSEEN_TEXT, + PIDGIN_UNSEEN_NICK } PidginUnseenState; #endif -void execute(const char *cmd) { +void execute(const char *cmd, char *sender, char *message) { if(strcmp(cmd,"") != 0) { - /* Execute command */ - if(g_spawn_command_line_async(cmd, NULL) == TRUE) { + pid_t pid = fork(); + if (pid == -1) { + // error, failed to fork() + } else if (pid > 0) { purple_debug_info(PLUGIN_ID, "Command executed\n"); + purple_debug_info(PLUGIN_ID, cmd); } else { + // we are the child + execl(cmd,cmd,sender,message,(char *) NULL); purple_debug_warning(PLUGIN_ID, "There was a problem executing the command\n"); + _exit(EXIT_FAILURE); // exec never returns } } else { + // There is no command purple_debug_warning(PLUGIN_ID, "No command found\n"); } } @@ -66,25 +75,25 @@ static void cmdexe_conversation_updated(PurpleConversation *conv, PurpleConvUpda /* Check if the conversation_updated signal has been emitted by a new message or something else */ if(has_unseen_state || has_unseen_count) { - const char *cmd = purple_prefs_get_string("/plugins/core/tymm-command-execute/command"); - execute(cmd); + //const char *cmd = purple_prefs_get_string("/plugins/core/tymm-command-execute/command"); + //execute(cmd, sender, message); } } } -static void cmdexe_received_im_msg(PurpleConversation *conv, PurpleConvUpdateType type) { +static void cmdexe_received_im_msg(PurpleAccount *account, char *sender, char *message, PurpleConversation *conv, PurpleMessageFlags flags) { /* Check if the user wants to execute the command on _every_ received IM */ if(purple_prefs_get_bool("/plugins/core/tymm-command-execute/execute_always")) { const char *cmd = purple_prefs_get_string("/plugins/core/tymm-command-execute/command"); - execute(cmd); + execute(cmd, sender, message); } } -static void cmdexe_received_chat_msg() { +static void cmdexe_received_chat_msg(PurpleAccount *account, char *sender, char *message, PurpleConversation *conv, PurpleMessageFlags flags) { /* Check if the user wants to execute the command _everytime_ the user receives a chat message */ if(purple_prefs_get_bool("/plugins/core/tymm-command-execute/execute_chat")) { const char *cmd = purple_prefs_get_string("/plugins/core/tymm-command-execute/command"); - execute(cmd); + execute(cmd, sender, message); } } @@ -131,6 +140,9 @@ static PurplePluginPrefFrame *plugin_config_frame(PurplePlugin *plugin) { ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/tymm-command-execute/execute_chat", "Execute command on new chat messages"); purple_plugin_pref_frame_add(frame, ppref); + ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/tymm-command-execute/arguments", "Enable arguments (%s sender, %m message)"); + purple_plugin_pref_frame_add(frame, ppref); + return frame; } @@ -155,7 +167,7 @@ static PurplePluginInfo info = { PURPLE_PRIORITY_DEFAULT, PLUGIN_ID, "Command execute", - "1.0", + "1.1", "Command execution for pidgin and finch", "Takes a command which will be executed either on every new IM or on every conversation update. It can also act on new chat messages.", "tymm ", @@ -178,6 +190,7 @@ static void init_plugin(PurplePlugin *plugin) { purple_prefs_add_string("/plugins/core/tymm-command-execute/command", ""); purple_prefs_add_bool("/plugins/core/tymm-command-execute/execute_always", FALSE); purple_prefs_add_bool("/plugins/core/tymm-command-execute/execute_chat", FALSE); + purple_prefs_add_bool("/plugins/core/tymm-command-execute/arguments", FALSE); } PURPLE_INIT_PLUGIN(command-execute, init_plugin, info) diff --git a/command-execute64.so b/command-execute64.so index 2528afc..efe67a9 100755 Binary files a/command-execute64.so and b/command-execute64.so differ