1
|
1 /*
|
|
2 * gaim
|
|
3 *
|
|
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
|
|
5 *
|
|
6 * This program is free software; you can redistribute it and/or modify
|
|
7 * it under the terms of the GNU General Public License as published by
|
|
8 * the Free Software Foundation; either version 2 of the License, or
|
|
9 * (at your option) any later version.
|
|
10 *
|
|
11 * This program is distributed in the hope that it will be useful,
|
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 * GNU General Public License for more details.
|
|
15 *
|
|
16 * You should have received a copy of the GNU General Public License
|
|
17 * along with this program; if not, write to the Free Software
|
|
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 *
|
|
20 */
|
|
21
|
|
22 #include <string.h>
|
|
23 #include <sys/time.h>
|
|
24
|
|
25 #include <sys/types.h>
|
|
26 #include <sys/stat.h>
|
|
27
|
|
28 #include <unistd.h>
|
|
29 #include <stdio.h>
|
|
30 #include <stdlib.h>
|
|
31 #include <gtk/gtk.h>
|
|
32 #include "gaim.h"
|
|
33 #include "proxy.h"
|
|
34
|
|
35
|
|
36 struct aim_user *current_user = NULL;
|
|
37 GList *aim_users = NULL;
|
|
38 int general_options;
|
|
39 int display_options;
|
|
40 int sound_options;
|
|
41 int font_options;
|
|
42
|
|
43 int report_idle, web_browser;
|
|
44 struct save_pos blist_pos;
|
|
45 char web_command[2048];
|
|
46 char aim_host[512];
|
|
47 int aim_port;
|
|
48 char login_host[512];
|
|
49 int login_port;
|
|
50
|
|
51
|
|
52 struct parse {
|
|
53 char option[256];
|
|
54 char value[6][256];
|
|
55 };
|
|
56
|
|
57 static struct parse *parse_line(char *line)
|
|
58 {
|
|
59 char *c = line;
|
|
60 int inopt = 1, inval = 0, curval = -1;
|
|
61 int optlen = 0, vallen = 0;
|
|
62 static struct parse p;
|
|
63
|
|
64
|
|
65 while(*c) {
|
|
66 if (*c == '\t') {
|
|
67 c++;
|
|
68 continue;
|
|
69 }
|
|
70 if (inopt) {
|
|
71 // if ((*c < 'a' || *c > 'z') && *c != '_') {
|
|
72 if ((*c < 'a' || *c > 'z') && *c != '_' && (*c < 'A' || *c > 'Z')) {
|
|
73 inopt = 0;
|
|
74 p.option[optlen] = 0;
|
|
75 c++;
|
|
76 continue;
|
|
77 }
|
|
78
|
|
79 p.option[optlen] = *c;
|
|
80 optlen++;
|
|
81 c++;
|
|
82 continue;
|
|
83 } else if (inval) {
|
|
84 if ( (*c == '}') ) {
|
|
85 if (*(c-1) == '\\') {
|
|
86 p.value[curval][vallen - 1] = *c;
|
|
87 c++;
|
|
88 continue;
|
|
89 } else {
|
|
90 p.value[curval][vallen - 1] = 0;
|
|
91 inval = 0;
|
|
92 c++;
|
|
93 continue;
|
|
94 }
|
|
95 } else {
|
|
96 p.value[curval][vallen] = *c;
|
|
97 vallen++;
|
|
98 c++;
|
|
99 continue; }
|
|
100 } else if (*c == '{') {
|
|
101 if (*(c-1) == '\\') {
|
|
102 p.value[curval][vallen-1] = *c;
|
|
103 c++;
|
|
104 continue;
|
|
105 }
|
|
106 else
|
|
107 {
|
|
108 curval++;
|
|
109 vallen = 0;
|
|
110 inval = 1;
|
|
111 c++;
|
|
112 c++;
|
|
113 continue;
|
|
114 }
|
|
115 }
|
|
116 c++;
|
|
117 }
|
|
118 return &p;
|
|
119 }
|
|
120
|
|
121
|
|
122 static int gaimrc_parse_tag(FILE *f)
|
|
123 {
|
|
124 char buf[2048];
|
|
125 char tag[256];
|
|
126 buf[0] = '#';
|
|
127
|
|
128 while (buf[0] == '#' && !feof(f))
|
|
129 fgets(buf, sizeof(buf), f);
|
|
130
|
|
131 if (feof(f))
|
|
132 return -1;
|
|
133
|
|
134 sscanf(buf, "%s {", tag);
|
|
135
|
|
136 if (!strcmp(tag, "users")) {
|
|
137 return 0;
|
|
138 } else if (!strcmp(tag, "options")) {
|
|
139 return 1;
|
|
140 } else if (!strcmp(tag, "away")) {
|
|
141 return 2;
|
|
142 }
|
|
143
|
|
144 return -1;
|
|
145 }
|
|
146
|
|
147 void filter_break(char *msg)
|
|
148 {
|
|
149 char *c;
|
|
150 int mc;
|
|
151
|
|
152 c = g_strdup(msg);
|
|
153 mc = 0;
|
|
154 while (*c)
|
|
155 {
|
|
156 if (*c == '\\') {
|
|
157 c++;
|
|
158 msg[mc] = *c;
|
|
159 }
|
|
160 else {
|
|
161 msg[mc] = *c;
|
|
162 }
|
|
163 mc++;
|
|
164 c++;
|
|
165 }
|
|
166 msg[mc] = 0;
|
|
167 }
|
|
168
|
|
169 static void gaimrc_read_away(FILE *f)
|
|
170 {
|
|
171 struct parse *p;
|
|
172 char buf[4096];
|
|
173 struct away_message *a;
|
|
174
|
|
175 buf[0] = 0;
|
|
176
|
|
177 while (buf[0] != '}')
|
|
178 {
|
|
179 if (!fgets(buf, sizeof(buf), f))
|
|
180 return;
|
|
181
|
|
182 if (buf[0] == '}')
|
|
183 return;
|
|
184
|
|
185 p = parse_line(buf);
|
15
|
186 if (!strcmp(p->option, "message"))
|
|
187 {
|
|
188 a = g_new0(struct away_message, 1);
|
1
|
189
|
15
|
190 g_snprintf(a->name, sizeof(a->name), "%s", p->value[0]);
|
|
191 g_snprintf(a->message, sizeof(a->message), "%s", p->value[1]);
|
|
192 filter_break(a->message);
|
|
193 away_messages = g_list_append(away_messages, a);
|
|
194 }
|
1
|
195 }
|
|
196 }
|
|
197
|
|
198 static void gaimrc_write_away(FILE *f)
|
|
199 {
|
|
200 GList *awy = away_messages;
|
|
201 struct away_message *a;
|
|
202
|
|
203 fprintf(f, "away {\n");
|
|
204
|
|
205 while (awy) {
|
|
206 a = (struct away_message *)awy->data;
|
15
|
207 fprintf(f, "\tmessage { %s } { %s }\n", escape_text2(a->name), escape_text2(a->message));
|
1
|
208 awy = awy->next;
|
|
209 }
|
|
210
|
|
211 fprintf(f, "}\n");
|
|
212 }
|
|
213
|
|
214
|
|
215
|
|
216
|
|
217 static struct aim_user *gaimrc_read_user(FILE *f)
|
|
218 {
|
|
219 struct parse *p;
|
|
220 struct aim_user *u;
|
|
221 char buf[4096];
|
|
222
|
|
223 if (!fgets(buf, sizeof(buf), f))
|
|
224 return NULL;
|
|
225
|
|
226 p = parse_line(buf);
|
|
227
|
|
228 if (strcmp(p->option, "ident"))
|
|
229 return NULL;
|
|
230
|
|
231 u = g_new0(struct aim_user, 1);
|
|
232
|
|
233 strcpy(u->username, p->value[0]);
|
|
234 strcpy(u->password, p->value[1]);
|
|
235
|
|
236 u->user_info[0] = 0;
|
|
237
|
|
238 if (!fgets(buf, sizeof(buf), f))
|
|
239 return u;
|
|
240
|
|
241 if (strcmp(buf, "\t\tuser_info {\n")) {
|
|
242 return u;
|
|
243 }
|
|
244
|
|
245 if (!fgets(buf, sizeof(buf), f))
|
|
246 return u;
|
|
247
|
|
248 while (strncmp(buf, "\t\t}", 3)) {
|
|
249 if (strlen(buf) > 3)
|
|
250 strcat(u->user_info, &buf[3]);
|
|
251
|
|
252 if (!fgets(buf, sizeof(buf), f)) {
|
|
253 return u;
|
|
254 }
|
|
255 }
|
|
256
|
|
257 return u;
|
|
258
|
|
259 }
|
|
260
|
|
261 static void gaimrc_write_user(FILE *f, struct aim_user *u)
|
|
262 {
|
|
263 char *c;
|
|
264 int nl = 1;;
|
|
265 fprintf(f, "\t\tident { %s } { %s }\n", u->username, u->password);
|
|
266 fprintf(f, "\t\tuser_info {");
|
|
267 c = u->user_info;
|
|
268 while(*c) {
|
|
269 /* This is not as silly as it looks. */
|
|
270 if (*c == '\n') {
|
|
271 nl++;
|
|
272 } else {
|
|
273 if (nl) {
|
|
274 while(nl) {
|
|
275 fprintf(f, "\n\t\t\t");
|
|
276 nl--;
|
|
277 }
|
|
278 }
|
|
279 fprintf(f, "%c", *c);
|
|
280 }
|
|
281 c++;
|
|
282 }
|
|
283 fprintf(f, "\n\t\t}\n");
|
|
284
|
|
285 }
|
|
286
|
|
287
|
|
288 static void gaimrc_read_users(FILE *f)
|
|
289 {
|
|
290 char buf[2048];
|
|
291 struct aim_user *u;
|
|
292 struct parse *p;
|
|
293 int cur = 0;
|
|
294
|
|
295 buf[0] = 0;
|
|
296
|
|
297 while (buf[0] != '}') {
|
|
298 if (buf[0] == '#')
|
|
299 continue;
|
|
300
|
|
301 if (!fgets(buf, sizeof(buf), f))
|
|
302 return;
|
|
303
|
|
304
|
|
305
|
|
306 p = parse_line(buf);
|
|
307
|
|
308 if (!strcmp(p->option, "current_user")) {
|
|
309 cur = 1;;
|
|
310 } else if (strcmp(p->option, "user")) {
|
|
311 continue;
|
|
312 }
|
|
313
|
|
314 u = gaimrc_read_user(f);
|
|
315
|
|
316 if (cur)
|
|
317 current_user = u;
|
|
318
|
|
319 aim_users = g_list_append(aim_users, u);
|
|
320 }
|
|
321 }
|
|
322
|
|
323 static void gaimrc_write_users(FILE *f)
|
|
324 {
|
|
325 GList *usr = aim_users;
|
|
326 struct aim_user *u;
|
|
327
|
|
328 fprintf(f, "users {\n");
|
|
329
|
|
330 while(usr) {
|
|
331 u = (struct aim_user *)usr->data;
|
|
332 if (current_user == u) {
|
|
333 fprintf(f, "\tcurrent_user {\n");
|
|
334 } else {
|
|
335 fprintf(f, "\tuser {\n");
|
|
336 }
|
|
337 gaimrc_write_user(f, u);
|
|
338
|
|
339 fprintf(f, "\t}\n");
|
|
340
|
|
341 usr = usr->next;
|
|
342 }
|
|
343
|
|
344 fprintf(f, "}\n");
|
|
345 }
|
|
346
|
|
347
|
|
348
|
|
349
|
|
350 static void gaimrc_read_options(FILE *f)
|
|
351 {
|
|
352 char buf[2048];
|
|
353 struct parse *p;
|
|
354
|
|
355 buf[0] = 0;
|
|
356
|
|
357 while (buf[0] != '}') {
|
|
358 if (buf[0] == '#')
|
|
359 continue;
|
|
360
|
|
361 if (!fgets(buf, sizeof(buf), f))
|
|
362 return;
|
|
363
|
|
364 p = parse_line(buf);
|
|
365
|
|
366 if (!strcmp(p->option, "general_options")) {
|
|
367 general_options = atoi(p->value[0]);
|
|
368 } else if (!strcmp(p->option, "display_options")) {
|
|
369 display_options = atoi(p->value[0]);
|
|
370 } else if (!strcmp(p->option, "sound_options")) {
|
|
371 sound_options = atoi(p->value[0]);
|
|
372 } else if (!strcmp(p->option, "font_options")) {
|
|
373 font_options = atoi(p->value[0]);
|
|
374 } else if (!strcmp(p->option, "report_idle")) {
|
|
375 report_idle = atoi(p->value[0]);
|
|
376 } else if (!strcmp(p->option, "web_browser")) {
|
|
377 web_browser = atoi(p->value[0]);
|
|
378 } else if (!strcmp(p->option, "web_command")) {
|
|
379 strcpy(web_command, p->value[0]);
|
|
380 } else if (!strcmp(p->option, "proxy_type")) {
|
|
381 proxy_type = atoi(p->value[0]);
|
|
382 } else if (!strcmp(p->option, "proxy_host")) {
|
|
383 strcpy(proxy_host, p->value[0]);
|
|
384 } else if (!strcmp(p->option, "proxy_port")) {
|
|
385 proxy_port = atoi(p->value[0]);
|
|
386 } else if (!strcmp(p->option, "aim_host")) {
|
|
387 strcpy(aim_host, p->value[0]);
|
|
388 } else if (!strcmp(p->option, "aim_port")) {
|
|
389 aim_port = atoi(p->value[0]);
|
|
390 } else if (!strcmp(p->option, "login_host")) {
|
|
391 strcpy(login_host, p->value[0]);
|
|
392 } else if (!strcmp(p->option, "login_port")) {
|
|
393 login_port = atoi(p->value[0]);
|
|
394 } else if (!strcmp(p->option, "blist_pos")) {
|
|
395 blist_pos.x = atoi(p->value[0]);
|
|
396 blist_pos.y = atoi(p->value[1]);
|
|
397 blist_pos.width = atoi(p->value[2]);
|
|
398 blist_pos.height = atoi(p->value[3]);
|
|
399 blist_pos.xoff = atoi(p->value[4]);
|
|
400 blist_pos.yoff = atoi(p->value[5]);
|
|
401 }
|
|
402
|
|
403 }
|
|
404
|
|
405 }
|
|
406
|
|
407 static void gaimrc_write_options(FILE *f)
|
|
408 {
|
|
409
|
|
410 fprintf(f, "options {\n");
|
|
411 fprintf(f, "\tgeneral_options { %d }\n", general_options);
|
|
412 fprintf(f, "\tdisplay_options { %d }\n", display_options);
|
|
413 fprintf(f, "\tsound_options { %d }\n", sound_options);
|
|
414 fprintf(f, "\tfont_options { %d }\n", font_options);
|
|
415 fprintf(f, "\treport_idle { %d }\n", report_idle);
|
|
416 fprintf(f, "\tweb_browser { %d }\n", web_browser);
|
|
417 fprintf(f, "\tweb_command { %s }\n", web_command);
|
|
418 fprintf(f, "\tproxy_type { %d }\n", proxy_type);
|
|
419 fprintf(f, "\tproxy_host { %s }\n", proxy_host);
|
|
420 fprintf(f, "\tproxy_port { %d }\n", proxy_port);
|
|
421 fprintf(f, "\taim_host { %s }\n", aim_host);
|
|
422 fprintf(f, "\taim_port { %d }\n", aim_port);
|
|
423 fprintf(f, "\tlogin_host { %s }\n", login_host);
|
|
424 fprintf(f, "\tlogin_port { %d }\n", login_port);
|
|
425 fprintf(f, "\tblist_pos { %d } { %d } { %d } { %d } { %d } { %d }\n",
|
|
426 blist_pos.x, blist_pos.y, blist_pos.width, blist_pos.height,
|
|
427 blist_pos.xoff, blist_pos.yoff);
|
|
428 fprintf(f, "}\n");
|
|
429 }
|
|
430
|
|
431
|
|
432 void set_defaults()
|
|
433 {
|
|
434 general_options =
|
|
435 OPT_GEN_SEND_LINKS |
|
|
436 OPT_GEN_ENTER_SENDS |
|
|
437 OPT_GEN_SAVED_WINDOWS |
|
|
438 OPT_GEN_REMEMBER_PASS |
|
|
439 OPT_GEN_REGISTERED;
|
|
440 display_options =
|
|
441 OPT_DISP_SHOW_IDLETIME |
|
|
442 OPT_DISP_SHOW_TIME |
|
|
443 OPT_DISP_SHOW_PIXMAPS |
|
|
444 OPT_DISP_SHOW_BUTTON_XPM;
|
|
445 font_options = 0;
|
|
446 sound_options = OPT_SOUND_LOGIN | OPT_SOUND_LOGOUT | OPT_SOUND_RECV | OPT_SOUND_SEND;
|
|
447 report_idle = IDLE_GAIM;
|
|
448 web_browser = BROWSER_NETSCAPE;
|
|
449 proxy_type = PROXY_NONE;
|
|
450
|
|
451 aim_port = TOC_PORT;
|
|
452 login_port = AUTH_PORT;
|
|
453 g_snprintf(aim_host, sizeof(aim_host), "%s", TOC_HOST);
|
|
454 g_snprintf(login_host, sizeof(login_host), "%s", AUTH_HOST);
|
|
455 proxy_host[0] = 0;
|
|
456 proxy_port = 0;
|
|
457 g_snprintf(web_command, sizeof(web_command), "xterm -e lynx %%s");
|
|
458 blist_pos.width = 0;
|
|
459 blist_pos.height = 0;
|
|
460 blist_pos.x = 0;
|
|
461 blist_pos.y = 0;
|
|
462 blist_pos.xoff = 0;
|
|
463 blist_pos.yoff = 0;
|
|
464 }
|
|
465
|
|
466
|
|
467 void load_prefs()
|
|
468 {
|
|
469 FILE *f;
|
|
470 char buf[1024];
|
|
471 int ver = 0;
|
|
472
|
|
473 if (getenv("HOME")) {
|
|
474 g_snprintf(buf, sizeof(buf), "%s/.gaimrc", getenv("HOME"));
|
|
475 if ((f = fopen(buf,"r"))) {
|
|
476 fgets(buf, sizeof(buf), f);
|
|
477 sscanf(buf, "# .gaimrc v%d", &ver);
|
15
|
478 if ( (ver <= 1) || (buf[0] != '#')) {
|
1
|
479 fclose(f);
|
|
480 set_defaults();
|
|
481 save_prefs();
|
|
482 load_prefs();
|
|
483 return;
|
|
484 }
|
|
485 while(!feof(f)) {
|
|
486 switch(gaimrc_parse_tag(f)) {
|
|
487 case -1:
|
|
488 /* Let the loop end, EOF*/
|
|
489 break;
|
|
490 case 0:
|
|
491 gaimrc_read_users(f);
|
|
492 break;
|
|
493 case 1:
|
|
494 gaimrc_read_options(f);
|
|
495 break;
|
|
496 case 2:
|
|
497 gaimrc_read_away(f);
|
|
498 break;
|
|
499 default:
|
|
500 /* NOOP */
|
|
501 break;
|
|
502 }
|
|
503 }
|
|
504 fclose(f);
|
|
505 }
|
|
506 }
|
|
507
|
|
508 }
|
|
509
|
|
510 void save_prefs()
|
|
511 {
|
|
512 FILE *f;
|
|
513 char buf[BUF_LONG];
|
|
514
|
|
515 if (getenv("HOME")) {
|
|
516 g_snprintf(buf, sizeof(buf), "%s/.gaimrc", getenv("HOME"));
|
|
517 if ((f = fopen(buf,"w"))) {
|
15
|
518 fprintf(f, "# .gaimrc v%d\n", 2);
|
1
|
519 gaimrc_write_users(f);
|
|
520 gaimrc_write_options(f);
|
|
521 gaimrc_write_away(f);
|
|
522 fclose(f);
|
|
523 chmod(buf, S_IRUSR | S_IWUSR);
|
|
524 }
|
|
525
|
|
526 }
|
|
527 }
|
|
528
|