Mercurial > pidgin
annotate plugins/filectl.c @ 6036:547ba881bc7e
[gaim-migrate @ 6486]
Fix the --login=[NAME] command line argument.
Fix the password prompt when signing on an account with no password set. I
made some similar changes that probably fix problems with the filectl plugin,
using gaim-remote to sign on an account, and signing on an account via perl
script. (The change is calling gaim_account_connect() instead of
serv_login().)
Fix a silly compiler warning.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 05 Jul 2003 22:24:57 +0000 |
parents | 7d385de2f9cd |
children | 5239a3b4ab33 |
rev | line source |
---|---|
3198 | 1 #include "config.h" |
106 | 2 #include "gaim.h" |
3 | |
4 #include <gtk/gtk.h> | |
5 #include <stdlib.h> | |
6 #include <unistd.h> | |
7 #include <sys/types.h> | |
8 #include <sys/stat.h> | |
9 #include <string.h> | |
10 #include <ctype.h> | |
11 | |
5255 | 12 #define FILECTL_PLUGIN_ID "core-filectl" |
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
13 static int check; |
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
14 static time_t mtime; |
106 | 15 |
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
16 static void init_file(); |
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
17 static void check_file(); |
106 | 18 |
19 extern void do_quit(); | |
20 | |
21 /* parse char * as if were word array */ | |
22 char *getarg(char *, int, int); | |
23 | |
24 /* go through file and run any commands */ | |
25 void run_commands() { | |
26 struct stat finfo; | |
27 char filename[256]; | |
28 char buffer[1024]; | |
29 char *command, *arg1, *arg2; | |
30 FILE *file; | |
31 | |
32 sprintf(filename, "%s/.gaim/control", getenv("HOME")); | |
33 | |
34 file = fopen(filename, "r+"); | |
35 while (fgets(buffer, sizeof buffer, file)) { | |
36 if (buffer[strlen(buffer) - 1] == '\n') | |
37 buffer[strlen(buffer) - 1] = 0; | |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
38 gaim_debug(GAIM_DEBUG_MISC, "filectl", "read: %s\n", buffer); |
106 | 39 command = getarg(buffer, 0, 0); |
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
40 if (!strncasecmp(command, "signon", 6)) { |
4491 | 41 struct gaim_account *account = NULL; |
42 GSList *accts = gaim_accounts; | |
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
43 arg1 = getarg(buffer, 1, 1); |
2765
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
44 if (arg1) { |
4491 | 45 while (accts) { |
46 struct gaim_account *a = accts->data; | |
47 if (!strcmp(a->username, arg1)) { | |
48 account = a; | |
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
49 break; |
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
50 } |
4491 | 51 accts = accts->next; |
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
52 } |
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
53 free(arg1); |
106 | 54 } |
4491 | 55 if (account) /* username found */ |
6036 | 56 gaim_account_connect(account); |
106 | 57 } else if (!strncasecmp(command, "signoff", 7)) { |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
576
diff
changeset
|
58 struct gaim_connection *gc = NULL; |
2765
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
59 GSList *c = connections; |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
576
diff
changeset
|
60 arg1 = getarg(buffer, 1, 1); |
2766
0e082a9e4c32
[gaim-migrate @ 2779]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2765
diff
changeset
|
61 while (arg1 && c) { |
2765
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
62 gc = c->data; |
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
63 if (!strcmp(gc->username, arg1)) { |
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
64 break; |
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
65 } |
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
66 gc = NULL; |
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
67 c = c->next; |
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
68 } |
2765
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
69 if (gc) |
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
70 signoff(gc); |
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
71 else if (!arg1) |
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
72 signoff_all(NULL, NULL); |
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
73 free(arg1); |
106 | 74 } else if (!strncasecmp(command, "send", 4)) { |
5676
dae79aefac8d
[gaim-migrate @ 6094]
Christian Hammond <chipx86@chipx86.com>
parents:
5255
diff
changeset
|
75 GaimConversation *c; |
106 | 76 arg1 = getarg(buffer, 1, 0); |
77 arg2 = getarg(buffer, 2, 1); | |
78 c = find_conversation(arg1); | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4168
diff
changeset
|
79 if (!c) c = gaim_conversation_new(GAIM_CONV_IM, arg1); |
2906
538c58b43eff
[gaim-migrate @ 2919]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2766
diff
changeset
|
80 write_to_conv(c, arg2, WFLAG_SEND, NULL, time(NULL), -1); |
3061 | 81 serv_send_im(c->gc, arg1, arg2, -1, 0); |
106 | 82 free(arg1); |
83 free(arg2); | |
84 } else if (!strncasecmp(command, "away", 4)) { | |
85 struct away_message a; | |
86 arg1 = getarg(buffer, 1, 1); | |
87 snprintf(a.message, 2048, "%s", arg1); | |
88 a.name[0] = 0; | |
89 do_away_message(NULL, &a); | |
90 free(arg1); | |
3198 | 91 } else if (!strncasecmp(command, "hide", 4)) { |
92 hide_buddy_list(); | |
93 } else if (!strncasecmp(command, "unhide", 6)) { | |
94 unhide_buddy_list(); | |
106 | 95 } else if (!strncasecmp(command, "back", 4)) { |
96 do_im_back(); | |
97 } else if (!strncasecmp(command, "quit", 4)) { | |
98 do_quit(); | |
99 } | |
100 free(command); | |
101 } | |
102 | |
103 fclose(file); | |
104 | |
105 if (stat (filename, &finfo) != 0) | |
106 return; | |
107 mtime = finfo.st_mtime; | |
108 } | |
109 | |
110 /* check to see if the size of the file is > 0. if so, run commands */ | |
111 void init_file() { | |
112 /* most of this was taken from Bash v2.04 by the FSF */ | |
113 struct stat finfo; | |
114 char file[256]; | |
115 | |
116 sprintf(file, "%s/.gaim/control", getenv("HOME")); | |
117 | |
118 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) | |
119 run_commands(); | |
120 } | |
121 | |
122 /* check to see if we need to run commands from the file */ | |
123 void check_file() { | |
124 /* most of this was taken from Bash v2.04 by the FSF */ | |
125 struct stat finfo; | |
126 char file[256]; | |
127 | |
128 sprintf(file, "%s/.gaim/control", getenv("HOME")); | |
129 | |
130 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) | |
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
131 if (mtime != finfo.st_mtime) { |
5227
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
132 gaim_debug(GAIM_DEBUG_INFO, "filectl", |
6d1707dc8c3d
[gaim-migrate @ 5597]
Christian Hammond <chipx86@chipx86.com>
parents:
5205
diff
changeset
|
133 "control changed, checking\n"); |
106 | 134 run_commands(); |
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
135 } |
106 | 136 } |
137 | |
138 char *getarg(char *line, int which, int remain) { | |
139 char *arr; | |
140 char *val; | |
141 int count = -1; | |
142 int i; | |
143 int state = 0; | |
144 | |
145 for (i = 0; i < strlen(line) && count < which; i++) { | |
146 switch (state) { | |
147 case 0: /* in whitespace, expecting word */ | |
148 if (isalnum(line[i])) { | |
149 count++; | |
150 state = 1; | |
151 } | |
152 break; | |
153 case 1: /* inside word, waiting for whitespace */ | |
154 if (isspace(line[i])) { | |
155 state = 0; | |
156 } | |
157 break; | |
158 } | |
159 } | |
160 | |
161 arr = strdup(&line[i - 1]); | |
162 if (remain) | |
163 return arr; | |
164 | |
165 for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++); | |
166 arr[i] = 0; | |
167 val = strdup(arr); | |
168 arr[i] = ' '; | |
169 free(arr); | |
170 return val; | |
171 } | |
5255 | 172 /* |
173 * EXPORTED FUNCTIONS | |
174 */ | |
175 | |
176 static gboolean | |
177 plugin_load(GaimPlugin *plugin) | |
178 { | |
179 init_file(); | |
180 check = g_timeout_add(5000, check_file, NULL); | |
181 | |
182 return TRUE; | |
183 } | |
184 | |
185 static gboolean | |
186 plugin_unload(GaimPlugin *plugin) | |
187 { | |
188 g_source_remove(check); | |
189 | |
190 return TRUE; | |
191 } | |
192 | |
193 static GaimPluginInfo info = | |
194 { | |
195 2, /**< api_version */ | |
196 GAIM_PLUGIN_STANDARD, /**< type */ | |
197 NULL, /**< ui_requirement */ | |
198 0, /**< flags */ | |
199 NULL, /**< dependencies */ | |
200 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
201 | |
202 FILECTL_PLUGIN_ID, /**< id */ | |
203 N_("Gaim File Control"), /**< name */ | |
204 VERSION, /**< version */ | |
205 /** summary */ | |
206 N_("Allows you to control Gaim by entering commands in a file."), | |
207 /** description */ | |
208 N_("Allows you to control Gaim by entering commands in a file."), | |
209 "Eric Warmenhoven <eric@warmenhoven.org>", /**< author */ | |
210 WEBSITE, /**< homepage */ | |
211 | |
212 plugin_load, /**< load */ | |
213 plugin_unload, /**< unload */ | |
214 NULL, /**< destroy */ | |
215 | |
216 NULL, /**< ui_info */ | |
217 NULL /**< extra_info */ | |
218 }; | |
219 | |
220 static void | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
221 init_plugin(GaimPlugin *plugin) |
5255 | 222 { |
223 } | |
224 | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5676
diff
changeset
|
225 GAIM_INIT_PLUGIN(filectl, init_plugin, info); |