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