annotate plugins/filectl.c @ 10458:ad9258716144

[gaim-migrate @ 11727] This should fix sf bug #1093455 Basically it's possible for people to kick you from an AIM chat room, and I don't think there's anything we can do about this. When this happens you can't rejoin, and I don't think there's anything we can do about that, either. But now, at least oscar will tell the core you're no longer in the chat room when you've been kicked. i.e. it changes the chat title from "My Lame Chat" to "(My Lame Chat)" committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 31 Dec 2004 05:42:26 +0000
parents 73d3a64d5574
children 0f7452b1f777
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
1 /**
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
2 * Send commands to Gaim via ~/.gaim/control
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
3 *
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
4 * Originally by Eric Warmenhoven <eric@warmenhoven.org>
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
5 * Compile fixes/mini hacks Alex Bennee <alex@bennee.com>
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
6 * and Brian Tarricone <bjt23@users.sourceforge.net>
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
7 */
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
9 /* system includes */
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 #include <stdlib.h>
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
11 #include <stdio.h>
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 #include <unistd.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 #include <sys/types.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 #include <sys/stat.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 #include <string.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 #include <ctype.h>
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
18 #include "account.h"
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
19 #include "config.h"
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
20 #include "core.h"
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
21 #include "conversation.h"
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
22 #include "debug.h"
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
23 #include "eventloop.h"
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
24 #include "internal.h"
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
25 #include "util.h"
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9863
diff changeset
26 #include "version.h"
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
27
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
28 #define FILECTL_PLUGIN_ID "core-filectl"
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
29 static int check;
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
30 static time_t mtime;
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
32 static void init_file();
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
33 static gboolean check_file();
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 /* parse char * as if were word array */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 char *getarg(char *, int, int);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 /* go through file and run any commands */
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
39 void
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
40 run_commands()
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
41 {
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 struct stat finfo;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 char filename[256];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 char buffer[1024];
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 char *command, *arg1, *arg2;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 FILE *file;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
48 sprintf(filename, "%s" G_DIR_SEPARATOR_S "control", gaim_user_dir());
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 file = fopen(filename, "r+");
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
51 while (fgets(buffer, sizeof(buffer), file)) {
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
52
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
53 /* Read the next command */
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 if (buffer[strlen(buffer) - 1] == '\n')
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 buffer[strlen(buffer) - 1] = 0;
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
56 gaim_debug_misc("filectl", "read: %s\n", buffer);
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 command = getarg(buffer, 0, 0);
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
58
10272
bf1ebc8f3bf3 [gaim-migrate @ 11421]
Mark Doliner <mark@kingant.net>
parents: 10256
diff changeset
59 if (!strncasecmp(command, "login", 6)) {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
60 GaimAccount *account;
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
61
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 arg1 = getarg(buffer, 1, 0);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 arg2 = getarg(buffer, 2, 1);
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
64
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
65 account = gaim_accounts_find(arg1, arg2);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
66 if (account != NULL) /* username found */
10416
73d3a64d5574 [gaim-migrate @ 11667]
Mark Doliner <mark@kingant.net>
parents: 10320
diff changeset
67 gaim_account_connect(account, gaim_account_get_status(account, "online"));
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
68
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
69 free(arg1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
70 free(arg2);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
71
10272
bf1ebc8f3bf3 [gaim-migrate @ 11421]
Mark Doliner <mark@kingant.net>
parents: 10256
diff changeset
72 } else if (!strncasecmp(command, "logout", 7)) {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
73 GaimAccount *account;
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
74 GaimConnection *gc;
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
75
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
76 arg1 = getarg(buffer, 1, 1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
77 arg2 = getarg(buffer, 2, 1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
78
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
79 account = gaim_accounts_find(arg1, arg2);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
80 if (account != NULL)
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
81 {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
82 gc = gaim_account_get_connection(account);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
83 if (gc != NULL)
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
84 gaim_connection_disconnect(gc);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
85 }
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
86 else if (arg1 == NULL)
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
87 gaim_connections_disconnect_all();
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
88
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
89 free(arg1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
90 free(arg2);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
91
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
92 } else if (!strncasecmp(command, "send", 4)) {
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
93 GaimConversation *conv;
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
94
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
95 arg1 = getarg(buffer, 1, 0);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
96 arg2 = getarg(buffer, 2, 1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
97
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
98 conv = gaim_find_conversation(GAIM_CONV_ANY, arg1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
99 if (conv != NULL)
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
100 {
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
101 /*
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
102 gaim_conversation_write(conv, arg2, WFLAG_SEND, NULL, time(NULL), -1);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
103 serv_send_im(conv->gc, arg1, arg2, 0);
9863
0e3a84f18467 [gaim-migrate @ 10742]
Mark Doliner <mark@kingant.net>
parents: 8749
diff changeset
104 */
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
105 }
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
106
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 free(arg1);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 free(arg2);
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
109
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110 } else if (!strncasecmp(command, "away", 4)) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111 arg1 = getarg(buffer, 1, 1);
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
112 /* serv_set_away_all(arg1); */
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 free(arg1);
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
114
3198
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
115 } else if (!strncasecmp(command, "hide", 4)) {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
116 gaim_blist_set_visible(FALSE);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
117
3198
ccf5cd2f0354 [gaim-migrate @ 3215]
Sean Egan <seanegan@gmail.com>
parents: 3061
diff changeset
118 } else if (!strncasecmp(command, "unhide", 6)) {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
119 gaim_blist_set_visible(TRUE);
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
120
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121 } else if (!strncasecmp(command, "back", 4)) {
9863
0e3a84f18467 [gaim-migrate @ 10742]
Mark Doliner <mark@kingant.net>
parents: 8749
diff changeset
122 /* do_im_back(); */
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
123
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 } else if (!strncasecmp(command, "quit", 4)) {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
125 gaim_core_quit();
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
126
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127 }
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
128
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129 free(command);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 fclose(file);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 if (stat (filename, &finfo) != 0)
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 return;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 mtime = finfo.st_mtime;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
139 /**
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
140 * Check to see if the size of the file is > 0. if so, run commands.
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
141 */
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
142 void
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
143 init_file()
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
144 {
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145 /* most of this was taken from Bash v2.04 by the FSF */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146 struct stat finfo;
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
147 char filename[256];
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
149 sprintf(filename, "%s" G_DIR_SEPARATOR_S "control", gaim_user_dir());
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
151 if ((stat(filename, &finfo) == 0) && (finfo.st_size > 0))
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152 run_commands();
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
154
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
155 /**
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
156 * Check to see if we need to run commands from the file.
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
157 */
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
158 gboolean
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
159 check_file()
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
160 {
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161 /* most of this was taken from Bash v2.04 by the FSF */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 struct stat finfo;
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
163 char filename[256];
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
165 sprintf(filename, "%s" G_DIR_SEPARATOR_S "control", gaim_user_dir());
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
167 if ((stat(filename, &finfo) == 0) && (finfo.st_size > 0))
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
168 {
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
169 if (mtime != finfo.st_mtime) {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
170 gaim_debug_info("filectl", "control changed, checking\n");
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
171 run_commands();
179
8d8faeab01f6 [gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 106
diff changeset
172 }
7658
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
173 }
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
174
251e2e434a86 [gaim-migrate @ 8302]
Luke Schierer <lschiere@pidgin.im>
parents: 6982
diff changeset
175 return TRUE;
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
178 char *
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
179 getarg(char *line, int which, int remain)
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
180 {
106
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 char *arr;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182 char *val;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183 int count = -1;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184 int i;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 int state = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
186
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187 for (i = 0; i < strlen(line) && count < which; i++) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 switch (state) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
189 case 0: /* in whitespace, expecting word */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190 if (isalnum(line[i])) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191 count++;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
192 state = 1;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194 break;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195 case 1: /* inside word, waiting for whitespace */
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196 if (isspace(line[i])) {
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
197 state = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
198 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
199 break;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
200 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
201 }
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
202
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
203 arr = strdup(&line[i - 1]);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
204 if (remain)
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205 return arr;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
206
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207 for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
208 arr[i] = 0;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
209 val = strdup(arr);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
210 arr[i] = ' ';
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211 free(arr);
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
212 return val;
e05e6373ea5a [gaim-migrate @ 116]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
213 }
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
214
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
215 /*
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
216 * EXPORTED FUNCTIONS
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
217 */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
218
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
219 static gboolean
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
220 plugin_load(GaimPlugin *plugin)
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
221 {
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
222 init_file();
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
223 check = gaim_timeout_add(5000, (GSourceFunc)check_file, NULL);
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
224
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
225 return TRUE;
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
226 }
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
227
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
228 static gboolean
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
229 plugin_unload(GaimPlugin *plugin)
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
230 {
10256
db39c909d467 [gaim-migrate @ 11397]
Mark Doliner <mark@kingant.net>
parents: 10246
diff changeset
231 gaim_timeout_remove(check);
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
232
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
233 return TRUE;
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
234 }
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
235
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
236 static GaimPluginInfo info =
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
237 {
9954
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9863
diff changeset
238 GAIM_PLUGIN_MAGIC,
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9863
diff changeset
239 GAIM_MAJOR_VERSION,
a9fb4493ae22 [gaim-migrate @ 10851]
Nathan Walp <nwalp@pidgin.im>
parents: 9863
diff changeset
240 GAIM_MINOR_VERSION,
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
241 GAIM_PLUGIN_STANDARD, /**< type */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
242 NULL, /**< ui_requirement */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
243 0, /**< flags */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
244 NULL, /**< dependencies */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
245 GAIM_PRIORITY_DEFAULT, /**< priority */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
246
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
247 FILECTL_PLUGIN_ID, /**< id */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
248 N_("Gaim File Control"), /**< name */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
249 VERSION, /**< version */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
250 /** summary */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
251 N_("Allows you to control Gaim by entering commands in a file."),
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
252 /** description */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
253 N_("Allows you to control Gaim by entering commands in a file."),
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
254 "Eric Warmenhoven <eric@warmenhoven.org>", /**< author */
6371
8f94cce8faa5 [gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents: 6179
diff changeset
255 GAIM_WEBSITE, /**< homepage */
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
256
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
257 plugin_load, /**< load */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
258 plugin_unload, /**< unload */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
259 NULL, /**< destroy */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
260
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
261 NULL, /**< ui_info */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
262 NULL /**< extra_info */
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
263 };
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
264
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
265 static void
5920
7d385de2f9cd [gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents: 5676
diff changeset
266 init_plugin(GaimPlugin *plugin)
5255
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
267 {
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
268 }
c0baa01cdeda [gaim-migrate @ 5627]
Luke Schierer <lschiere@pidgin.im>
parents: 5227
diff changeset
269
6063
5239a3b4ab33 [gaim-migrate @ 6513]
Nathan Walp <nwalp@pidgin.im>
parents: 6036
diff changeset
270 GAIM_INIT_PLUGIN(filectl, init_plugin, info)