Mercurial > pidgin
annotate plugins/filectl.c @ 3572:bdd0bebd2d04
[gaim-migrate @ 3670]
Phase II. No longer do you have to worry about protocol plugins. When
Gaim probes plugins on load, it will detect protocol plugins and add them
to the list of available protocols. When you try to log an account on with
one of them, Gaim will automatically load the plugin--when no more accounts
need the protocol--Gaim will automatically unload it. Protocol plugins are
no longer available in the plugins ui, and no protocols are compiled statically
by default.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 30 Sep 2002 01:05:18 +0000 |
parents | cd938f18f3f8 |
children | ebfb80bbe1ed |
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 | |
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
12 static void *handle; |
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; | |
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
38 debug_printf("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)) { |
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
41 struct aim_user *u = NULL; |
2765
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
42 GSList *userlist = aim_users; |
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) { |
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
45 while (userlist) { |
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
46 struct aim_user *current = userlist->data; |
2765
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
47 if (!strcmp(current->username, arg1)) { |
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
48 u = current; |
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 } |
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
51 userlist = userlist->next; |
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 } |
2765
dfd9705bc750
[gaim-migrate @ 2778]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2324
diff
changeset
|
55 if (u) /* username found */ |
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
56 serv_login(u); |
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)) { |
75 struct conversation *c; | |
76 arg1 = getarg(buffer, 1, 0); | |
77 arg2 = getarg(buffer, 2, 1); | |
78 c = find_conversation(arg1); | |
79 if (!c) c = new_conversation(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 | |
1047
ece2d1543b20
[gaim-migrate @ 1057]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
576
diff
changeset
|
110 char *gaim_plugin_init(GModule *h) { |
106 | 111 handle = h; |
112 init_file(); | |
113 check = gtk_timeout_add(5000, (GtkFunction)check_file, NULL); | |
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
114 return NULL; |
106 | 115 } |
116 | |
117 void gaim_plugin_remove() { | |
118 gtk_timeout_remove(check); | |
119 } | |
120 | |
3551 | 121 struct gaim_plugin_description desc; |
122 struct gaim_plugin_description *gaim_plugin_desc() { | |
123 desc.api_version = PLUGIN_API_VERSION; | |
124 desc.name = g_strdup("Gaim File Control"); | |
125 desc.version = g_strdup(VERSION); | |
126 desc.description = g_strdup("Allows you to control Gaim by entering commands in aa file."); | |
127 desc.authors = g_strdup("Eric Warmehoven <eric@warmenhoven.org>"); | |
128 desc.url = g_strdup(WEBSITE); | |
129 return &desc; | |
130 } | |
131 | |
106 | 132 char *name() { |
133 return "Gaim File Control"; | |
134 } | |
135 | |
136 char *description() { | |
137 return "Allows you to control gaim by entering commands in a file."; | |
138 } | |
139 | |
140 /* check to see if the size of the file is > 0. if so, run commands */ | |
141 void init_file() { | |
142 /* most of this was taken from Bash v2.04 by the FSF */ | |
143 struct stat finfo; | |
144 char file[256]; | |
145 | |
146 sprintf(file, "%s/.gaim/control", getenv("HOME")); | |
147 | |
148 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) | |
149 run_commands(); | |
150 } | |
151 | |
152 /* check to see if we need to run commands from the file */ | |
153 void check_file() { | |
154 /* most of this was taken from Bash v2.04 by the FSF */ | |
155 struct stat finfo; | |
156 char file[256]; | |
157 | |
158 sprintf(file, "%s/.gaim/control", getenv("HOME")); | |
159 | |
160 if ((stat (file, &finfo) == 0) && (finfo.st_size > 0)) | |
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
161 if (mtime != finfo.st_mtime) { |
2324
9ab820049ede
[gaim-migrate @ 2334]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1047
diff
changeset
|
162 debug_printf("control changed, checking\n"); |
106 | 163 run_commands(); |
179
8d8faeab01f6
[gaim-migrate @ 189]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
106
diff
changeset
|
164 } |
106 | 165 } |
166 | |
167 char *getarg(char *line, int which, int remain) { | |
168 char *arr; | |
169 char *val; | |
170 int count = -1; | |
171 int i; | |
172 int state = 0; | |
173 | |
174 for (i = 0; i < strlen(line) && count < which; i++) { | |
175 switch (state) { | |
176 case 0: /* in whitespace, expecting word */ | |
177 if (isalnum(line[i])) { | |
178 count++; | |
179 state = 1; | |
180 } | |
181 break; | |
182 case 1: /* inside word, waiting for whitespace */ | |
183 if (isspace(line[i])) { | |
184 state = 0; | |
185 } | |
186 break; | |
187 } | |
188 } | |
189 | |
190 arr = strdup(&line[i - 1]); | |
191 if (remain) | |
192 return arr; | |
193 | |
194 for (i = 0; i < strlen(arr) && isalnum(arr[i]); i++); | |
195 arr[i] = 0; | |
196 val = strdup(arr); | |
197 arr[i] = ' '; | |
198 free(arr); | |
199 return val; | |
200 } |