Mercurial > pidgin.yaz
annotate src/gaimrc.c @ 131:350d88f043b6
[gaim-migrate @ 141]
Um... if you tell gaim not to remember your passwords, it shouldn't remember
them in ~/.gaimrc....
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Tue, 18 Apr 2000 05:53:37 +0000 |
parents | 51943f1a97a0 |
children | fbabd28795d2 |
rev | line source |
---|---|
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;; | |
131
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
286 if (general_options & OPT_GEN_REMEMBER_PASS) |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
287 fprintf(f, "\t\tident { %s } { %s }\n", u->username, u->password); |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
288 else |
350d88f043b6
[gaim-migrate @ 141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
84
diff
changeset
|
289 fprintf(f, "\t\tident { %s } { }\n", u->username); |
1 | 290 fprintf(f, "\t\tuser_info {"); |
291 c = u->user_info; | |
292 while(*c) { | |
293 /* This is not as silly as it looks. */ | |
294 if (*c == '\n') { | |
295 nl++; | |
296 } else { | |
297 if (nl) { | |
298 while(nl) { | |
299 fprintf(f, "\n\t\t\t"); | |
300 nl--; | |
301 } | |
302 } | |
303 fprintf(f, "%c", *c); | |
304 } | |
305 c++; | |
306 } | |
307 fprintf(f, "\n\t\t}\n"); | |
308 | |
309 } | |
310 | |
311 | |
312 static void gaimrc_read_users(FILE *f) | |
313 { | |
314 char buf[2048]; | |
315 struct aim_user *u; | |
316 struct parse *p; | |
317 int cur = 0; | |
318 | |
319 buf[0] = 0; | |
320 | |
321 while (buf[0] != '}') { | |
322 if (buf[0] == '#') | |
323 continue; | |
324 | |
325 if (!fgets(buf, sizeof(buf), f)) | |
326 return; | |
327 | |
328 | |
329 | |
330 p = parse_line(buf); | |
331 | |
332 if (!strcmp(p->option, "current_user")) { | |
333 cur = 1;; | |
334 } else if (strcmp(p->option, "user")) { | |
335 continue; | |
336 } | |
337 | |
338 u = gaimrc_read_user(f); | |
339 | |
340 if (cur) | |
341 current_user = u; | |
342 | |
343 aim_users = g_list_append(aim_users, u); | |
344 } | |
345 } | |
346 | |
347 static void gaimrc_write_users(FILE *f) | |
348 { | |
349 GList *usr = aim_users; | |
350 struct aim_user *u; | |
351 | |
352 fprintf(f, "users {\n"); | |
353 | |
354 while(usr) { | |
355 u = (struct aim_user *)usr->data; | |
356 if (current_user == u) { | |
357 fprintf(f, "\tcurrent_user {\n"); | |
358 } else { | |
359 fprintf(f, "\tuser {\n"); | |
360 } | |
361 gaimrc_write_user(f, u); | |
362 | |
363 fprintf(f, "\t}\n"); | |
364 | |
365 usr = usr->next; | |
366 } | |
367 | |
368 fprintf(f, "}\n"); | |
369 } | |
370 | |
371 | |
372 | |
373 | |
374 static void gaimrc_read_options(FILE *f) | |
375 { | |
376 char buf[2048]; | |
377 struct parse *p; | |
378 | |
379 buf[0] = 0; | |
380 | |
381 while (buf[0] != '}') { | |
382 if (buf[0] == '#') | |
383 continue; | |
384 | |
385 if (!fgets(buf, sizeof(buf), f)) | |
386 return; | |
387 | |
388 p = parse_line(buf); | |
389 | |
390 if (!strcmp(p->option, "general_options")) { | |
391 general_options = atoi(p->value[0]); | |
392 } else if (!strcmp(p->option, "display_options")) { | |
393 display_options = atoi(p->value[0]); | |
394 } else if (!strcmp(p->option, "sound_options")) { | |
395 sound_options = atoi(p->value[0]); | |
396 } else if (!strcmp(p->option, "font_options")) { | |
397 font_options = atoi(p->value[0]); | |
398 } else if (!strcmp(p->option, "report_idle")) { | |
399 report_idle = atoi(p->value[0]); | |
400 } else if (!strcmp(p->option, "web_browser")) { | |
401 web_browser = atoi(p->value[0]); | |
402 } else if (!strcmp(p->option, "web_command")) { | |
403 strcpy(web_command, p->value[0]); | |
404 } else if (!strcmp(p->option, "proxy_type")) { | |
405 proxy_type = atoi(p->value[0]); | |
406 } else if (!strcmp(p->option, "proxy_host")) { | |
407 strcpy(proxy_host, p->value[0]); | |
408 } else if (!strcmp(p->option, "proxy_port")) { | |
409 proxy_port = atoi(p->value[0]); | |
410 } else if (!strcmp(p->option, "aim_host")) { | |
411 strcpy(aim_host, p->value[0]); | |
412 } else if (!strcmp(p->option, "aim_port")) { | |
413 aim_port = atoi(p->value[0]); | |
414 } else if (!strcmp(p->option, "login_host")) { | |
415 strcpy(login_host, p->value[0]); | |
416 } else if (!strcmp(p->option, "login_port")) { | |
417 login_port = atoi(p->value[0]); | |
418 } else if (!strcmp(p->option, "blist_pos")) { | |
419 blist_pos.x = atoi(p->value[0]); | |
420 blist_pos.y = atoi(p->value[1]); | |
421 blist_pos.width = atoi(p->value[2]); | |
422 blist_pos.height = atoi(p->value[3]); | |
423 blist_pos.xoff = atoi(p->value[4]); | |
424 blist_pos.yoff = atoi(p->value[5]); | |
82 | 425 } |
1 | 426 |
427 } | |
428 | |
429 } | |
430 | |
431 static void gaimrc_write_options(FILE *f) | |
432 { | |
433 | |
434 fprintf(f, "options {\n"); | |
435 fprintf(f, "\tgeneral_options { %d }\n", general_options); | |
436 fprintf(f, "\tdisplay_options { %d }\n", display_options); | |
437 fprintf(f, "\tsound_options { %d }\n", sound_options); | |
438 fprintf(f, "\tfont_options { %d }\n", font_options); | |
439 fprintf(f, "\treport_idle { %d }\n", report_idle); | |
440 fprintf(f, "\tweb_browser { %d }\n", web_browser); | |
441 fprintf(f, "\tweb_command { %s }\n", web_command); | |
442 fprintf(f, "\tproxy_type { %d }\n", proxy_type); | |
443 fprintf(f, "\tproxy_host { %s }\n", proxy_host); | |
444 fprintf(f, "\tproxy_port { %d }\n", proxy_port); | |
445 fprintf(f, "\taim_host { %s }\n", aim_host); | |
446 fprintf(f, "\taim_port { %d }\n", aim_port); | |
447 fprintf(f, "\tlogin_host { %s }\n", login_host); | |
448 fprintf(f, "\tlogin_port { %d }\n", login_port); | |
449 fprintf(f, "\tblist_pos { %d } { %d } { %d } { %d } { %d } { %d }\n", | |
450 blist_pos.x, blist_pos.y, blist_pos.width, blist_pos.height, | |
451 blist_pos.xoff, blist_pos.yoff); | |
452 fprintf(f, "}\n"); | |
453 } | |
454 | |
455 | |
456 void set_defaults() | |
457 { | |
458 general_options = | |
459 OPT_GEN_SEND_LINKS | | |
460 OPT_GEN_ENTER_SENDS | | |
461 OPT_GEN_SAVED_WINDOWS | | |
462 OPT_GEN_REMEMBER_PASS | | |
463 OPT_GEN_REGISTERED; | |
464 display_options = | |
465 OPT_DISP_SHOW_IDLETIME | | |
466 OPT_DISP_SHOW_TIME | | |
467 OPT_DISP_SHOW_PIXMAPS | | |
468 OPT_DISP_SHOW_BUTTON_XPM; | |
469 font_options = 0; | |
470 sound_options = OPT_SOUND_LOGIN | OPT_SOUND_LOGOUT | OPT_SOUND_RECV | OPT_SOUND_SEND; | |
471 report_idle = IDLE_GAIM; | |
472 web_browser = BROWSER_NETSCAPE; | |
473 proxy_type = PROXY_NONE; | |
474 | |
475 aim_port = TOC_PORT; | |
476 login_port = AUTH_PORT; | |
477 g_snprintf(aim_host, sizeof(aim_host), "%s", TOC_HOST); | |
478 g_snprintf(login_host, sizeof(login_host), "%s", AUTH_HOST); | |
479 proxy_host[0] = 0; | |
480 proxy_port = 0; | |
481 g_snprintf(web_command, sizeof(web_command), "xterm -e lynx %%s"); | |
482 blist_pos.width = 0; | |
483 blist_pos.height = 0; | |
484 blist_pos.x = 0; | |
485 blist_pos.y = 0; | |
486 blist_pos.xoff = 0; | |
487 blist_pos.yoff = 0; | |
488 } | |
489 | |
490 | |
491 void load_prefs() | |
492 { | |
493 FILE *f; | |
494 char buf[1024]; | |
495 int ver = 0; | |
496 | |
497 if (getenv("HOME")) { | |
498 g_snprintf(buf, sizeof(buf), "%s/.gaimrc", getenv("HOME")); | |
499 if ((f = fopen(buf,"r"))) { | |
500 fgets(buf, sizeof(buf), f); | |
501 sscanf(buf, "# .gaimrc v%d", &ver); | |
15 | 502 if ( (ver <= 1) || (buf[0] != '#')) { |
1 | 503 fclose(f); |
504 set_defaults(); | |
505 save_prefs(); | |
506 load_prefs(); | |
507 return; | |
508 } | |
509 while(!feof(f)) { | |
510 switch(gaimrc_parse_tag(f)) { | |
511 case -1: | |
512 /* Let the loop end, EOF*/ | |
513 break; | |
514 case 0: | |
515 gaimrc_read_users(f); | |
516 break; | |
517 case 1: | |
518 gaimrc_read_options(f); | |
519 break; | |
520 case 2: | |
521 gaimrc_read_away(f); | |
522 break; | |
523 default: | |
524 /* NOOP */ | |
525 break; | |
526 } | |
527 } | |
528 fclose(f); | |
529 } | |
530 } | |
531 | |
532 } | |
533 | |
534 void save_prefs() | |
535 { | |
536 FILE *f; | |
537 char buf[BUF_LONG]; | |
538 | |
539 if (getenv("HOME")) { | |
540 g_snprintf(buf, sizeof(buf), "%s/.gaimrc", getenv("HOME")); | |
541 if ((f = fopen(buf,"w"))) { | |
15 | 542 fprintf(f, "# .gaimrc v%d\n", 2); |
1 | 543 gaimrc_write_users(f); |
544 gaimrc_write_options(f); | |
545 gaimrc_write_away(f); | |
546 fclose(f); | |
547 chmod(buf, S_IRUSR | S_IWUSR); | |
548 } | |
549 | |
550 } | |
551 } | |
552 |