* Send commands to Purple via ~/.purple/control * Originally by Eric Warmenhoven <eric@warmenhoven.org> * Compile fixes/mini hacks Alex Bennee <alex@bennee.com> * and Brian Tarricone <bjt23@users.sourceforge.net> #define FILECTL_PLUGIN_ID "core-filectl" static void init_file(void); static gboolean check_file(void); /* parse char * as if were word array */ char *getarg(char *, int, int); /* go through file and run any commands */ char *command, *arg1, *arg2; filename = g_build_filename(purple_config_dir(), "control", NULL); file = g_fopen(filename, "r+"); while (fgets(buffer, sizeof(buffer), file)) { /* Read the next command */ if (buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0; purple_debug_misc("filectl", "read: %s\n", buffer); command = getarg(buffer, 0, 0); if (!g_ascii_strncasecmp(command, "login", 6)) { arg1 = getarg(buffer, 1, 0); arg2 = getarg(buffer, 2, 1); account = purple_accounts_find(arg1, arg2); if (account != NULL) /* username found */ purple_account_connect(account); } else if (!g_ascii_strncasecmp(command, "logout", 7)) { arg1 = getarg(buffer, 1, 1); arg2 = getarg(buffer, 2, 1); account = purple_accounts_find(arg1, arg2); purple_account_disconnect(account); purple_connections_disconnect_all(); } else if (!g_ascii_strncasecmp(command, "away", 4)) { arg1 = getarg(buffer, 1, 1); /* serv_set_away_all(arg1); */ } else if (!g_ascii_strncasecmp(command, "hide", 4)) { purple_blist_set_visible(FALSE); } else if (!g_ascii_strncasecmp(command, "unhide", 6)) { purple_blist_set_visible(TRUE); } else if (!g_ascii_strncasecmp(command, "back", 4)) { } else if (!g_ascii_strncasecmp(command, "quit", 4)) { if (g_stat(filename, &finfo) == 0) * Check to see if the size of the file is > 0. if so, run commands. /* most of this was taken from Bash v2.04 by the FSF */ filename = g_build_filename(purple_config_dir(), "control", NULL); if ((g_stat(filename, &finfo) == 0) && (finfo.st_size > 0)) * Check to see if we need to run commands from the file. /* most of this was taken from Bash v2.04 by the FSF */ filename = g_build_filename(purple_config_dir(), "control", NULL); if ((g_stat(filename, &finfo) == 0) && (finfo.st_size > 0)) if (mtime != finfo.st_mtime) { purple_debug_info("filectl", "control changed, checking\n"); getarg(char *line, int which, int remain) for (i = 0; i < strlen(line) && count < which; i++) { case 0: /* in whitespace, expecting word */ case 1: /* inside word, waiting for whitespace */ arr = g_strdup(&line[i - 1]); for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++); static PurplePluginInfo * plugin_query(GError **error) const gchar * const authors[] = { "Eric Warmenhoven <eric@warmenhoven.org>", return purple_plugin_info_new( "name", N_("File Control"), "version", DISPLAY_VERSION, "category", N_("Utility"), "summary", N_("Allows control by entering commands in a file."), "description", N_("Allows control by entering commands in a file."), "website", PURPLE_WEBSITE, "abi-version", PURPLE_ABI_VERSION, plugin_load(PurplePlugin *plugin, GError **error) check = g_timeout_add_seconds(5, (GSourceFunc)check_file, NULL); plugin_unload(PurplePlugin *plugin, GError **error) PURPLE_PLUGIN_INIT(filectl, plugin_query, plugin_load, plugin_unload);