gee
oldstatus
2005-09-19, Nathan Walp
** Send commands to gaim via ~/.gaim/control ** By Eric Warmenhoven <eric@warmenhoven.org> ** compile fixes/mini hacks Alex Bennee <alex@bennee.com> #include "conversation.h" #define FILECTL_PLUGIN_ID "core-filectl" static gboolean check_file(); /* parse char * as if were word array */ char *getarg(char *, int, int); /* go through file and run any commands */ char *command, *arg1, *arg2; sprintf(filename, "%s/.gaim/control", getenv("HOME")); file = fopen(filename, "r+"); while (fgets(buffer, sizeof buffer, file)) { if (buffer[strlen(buffer) - 1] == '\n') buffer[strlen(buffer) - 1] = 0; gaim_debug(GAIM_DEBUG_MISC, "filectl", "read: %s\n", buffer); command = getarg(buffer, 0, 0); if (!strncasecmp(command, "signon", 6)) { GaimAccount *account = NULL; GList *accts = gaim_accounts_get_all(); arg1 = getarg(buffer, 1, 1); GaimAccount *a = accts->data; if (!strcmp(a->username, arg1)) { if (account) /* username found */ gaim_account_connect(account); } else if (!strncasecmp(command, "signoff", 7)) { GaimConnection *gc = NULL; GList *c = gaim_connections_get_all(); arg1 = getarg(buffer, 1, 1); if (!strcmp(gc->account->username, arg1)) { gaim_connection_disconnect(gc); gaim_connections_disconnect_all(); } else if (!strncasecmp(command, "send", 4)) { arg1 = getarg(buffer, 1, 0); arg2 = getarg(buffer, 2, 1); c = gaim_find_conversation(arg1); gaim_conversation_write(c, arg2, WFLAG_SEND, NULL, time(NULL), -1); serv_send_im(c->gc, arg1, arg2, 0); } else if (!strncasecmp(command, "away", 4)) { arg1 = getarg(buffer, 1, 1); } else if (!strncasecmp(command, "hide", 4)) { } else if (!strncasecmp(command, "unhide", 6)) { /* unhide_buddy_list(); */ } else if (!strncasecmp(command, "back", 4)) { } else if (!strncasecmp(command, "quit", 4)) { if (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 */ sprintf(file, "%s/.gaim/control", getenv("HOME")); if ((stat (file, &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 */ sprintf(file, "%s/.gaim/control", getenv("HOME")); if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) if (mtime != finfo.st_mtime) { gaim_debug(GAIM_DEBUG_INFO, "filectl", "control changed, checking\n"); char *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 = strdup(&line[i - 1]); for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++); plugin_load(GaimPlugin *plugin) check = g_timeout_add(5000, (GSourceFunc) check_file, NULL); plugin_unload(GaimPlugin *plugin) static GaimPluginInfo info = GAIM_PLUGIN_STANDARD, /**< type */ NULL, /**< ui_requirement */ NULL, /**< dependencies */ GAIM_PRIORITY_DEFAULT, /**< priority */ FILECTL_PLUGIN_ID, /**< id */ N_("Gaim File Control"), /**< name */ N_("Allows you to control Gaim by entering commands in a file."), N_("Allows you to control Gaim by entering commands in a file."), "Eric Warmenhoven <eric@warmenhoven.org>", /**< author */ GAIM_WEBSITE, /**< homepage */ plugin_load, /**< load */ plugin_unload, /**< unload */ init_plugin(GaimPlugin *plugin) GAIM_INIT_PLUGIN(filectl, init_plugin, info)