annotate libpurple/protocols/zephyr/ZVariables.c @ 29685:6797736dbe37

Does anyone know the purpose of the ui_write, ui_read and data_not_sent FT UI callbacks? It looks like they allow a UI to decide how to safe incoming file transfers? They're not used in Pidgin or Finch. Are they used elsewhere? Valgrind is complaining about an invalid free. I think it happens either when the local user cancels a file transfer or when the remote user cancels a file transfer. I think this change fixes it. Revision fa4ce539e5025eb07aad3ca824cd4c512010d8a8 is related to these callbacks and to this change by foufou33@ gee male dot com The valgrind error is: ==23064== Invalid free() / delete / delete[] ==23064== at 0x4C24D68: free (vg_replace_malloc.c:325) ==23064== by 0x9293209: g_array_free (in /lib/libglib-2.0.so.0.2200.3) ==23064== by 0x95B1995: purple_xfer_priv_data_destroy (ft.c:71) ==23064== by 0x92AA5D1: ??? (in /lib/libglib-2.0.so.0.2200.3) ==23064== by 0x92AAE17: g_hash_table_remove_all (in /lib/libglib-2.0.so.0.2200.3) ==23064== by 0x92AAFC4: g_hash_table_destroy (in /lib/libglib-2.0.so.0.2200.3) ==23064== by 0x95B579C: purple_xfers_uninit (ft.c:1642) ==23064== by 0x95ACF08: purple_core_quit (core.c:238) ==23064== by 0x43EB3E: gtk_blist_delete_cb (gtkblist.c:227) ==23064== by 0x6F9A727: ??? (in /usr/lib/libgtk-x11-2.0.so.0.1800.3) ==23064== Address 0x2355f0e0 is not stack'd, malloc'd or (recently) free'd
author Mark Doliner <mark@kingant.net>
date Tue, 06 Apr 2010 09:52:27 +0000
parents bd1b1353e8fa
children e59a86a86643
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1 /* This file is part of the Project Athena Zephyr Notification System.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
2 * It contains source for the ZGetVariable, ZSetVariable, and ZUnsetVariable
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
3 * functions.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
4 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
5 * Created by: Robert French
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
6 *
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
7 * Copyright (c) 1987 by the Massachusetts Institute of Technology.
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
8 * For copying and distribution information, see the file
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
9 * "mit-copyright.h".
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
10 */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
11
18210
b8572b937c09 #include reorganizations to allow compiling with glib < 2.8 using the
Stu Tomlinson <stu@nosnilmot.com>
parents: 15822
diff changeset
12 #include "libpurple/internal.h"
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
13 #include "internal.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
14 #include "util.h"
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
15
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
16 #include <ctype.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
17 #ifndef WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
18 #include <pwd.h>
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
19 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
20
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
21 static char *get_localvarfile __P((void));
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
22 static char *get_varval __P((char *fn, char *val));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 static int varline __P((char *bfr, char *var));
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25 char *ZGetVariable(var)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 char *var;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 {
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
28 char *varfile, *ret;
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
29
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
30 if ((varfile = get_localvarfile()) == NULL)
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
31 return ((char *)0);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
33 if ((ret = get_varval(varfile, var)) != ZERR_NONE) {
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
34 g_free(varfile);
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
35 return ret;
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
36 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 #ifdef WIN32
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
39 varfile = g_strdup("C:\\zephyr\\zephyr.var");
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
40 #else
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
41 varfile = g_strdup_printf("%s/zephyr.vars", CONFDIR);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
42 #endif
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
43 ret = get_varval(varfile, var);
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
44 g_free(varfile);
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
45
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
46 return ret;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
47 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
48
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
49 Code_t ZSetVariable(var, value)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
50 char *var;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
51 char *value;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
52 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
53 int written;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
54 FILE *fpin, *fpout;
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
55 char *varfile, *varfilebackup, varbfr[512];
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
56
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 written = 0;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
59 if ((varfile = get_localvarfile()) == NULL)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60 return (ZERR_INTERNAL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
61
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
62 varfilebackup = g_strconcat(varfile, ".backup", NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
64 if (!(fpout = fopen(varfilebackup, "w"))) {
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
65 g_free(varfile);
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
66 g_free(varfilebackup);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
67 return (errno);
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
68 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
69 if ((fpin = fopen(varfile, "r")) != NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
70 while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
71 if (varbfr[strlen(varbfr)-1] < ' ')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
72 varbfr[strlen(varbfr)-1] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
73 if (varline(varbfr, var)) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
74 fprintf(fpout, "%s = %s\n", var, value);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
75 written = 1;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
76 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
77 else
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
78 fprintf(fpout, "%s\n", varbfr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
79 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
80 (void) fclose(fpin); /* don't care about errs on input */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
81 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
82 if (!written)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
83 fprintf(fpout, "%s = %s\n", var, value);
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
84 if (fclose(fpout) == EOF) {
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
85 g_free(varfilebackup);
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
86 g_free(varfile);
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
87 return(EIO); /* can't rely on errno */
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
88 }
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
89 if (rename(varfilebackup, varfile)) {
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
90 g_free(varfilebackup);
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
91 g_free(varfile);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
92 return (errno);
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
93 }
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
94 g_free(varfilebackup);
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
95 g_free(varfile);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
96 return (ZERR_NONE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
97 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
98
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
99 Code_t ZUnsetVariable(var)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
100 char *var;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
101 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
102 FILE *fpin, *fpout;
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
103 char *varfile, *varfilebackup, varbfr[512];
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
104
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
105 if ((varfile = get_localvarfile()) == NULL)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
106 return (ZERR_INTERNAL);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
107
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
108 varfilebackup = g_strconcat(varfile, ".backup", NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
109
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
110 if (!(fpout = fopen(varfilebackup, "w"))) {
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
111 g_free(varfile);
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
112 g_free(varfilebackup);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
113 return (errno);
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
114 }
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
115 if ((fpin = fopen(varfile, "r")) != NULL) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 if (varbfr[strlen(varbfr)-1] < ' ')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 varbfr[strlen(varbfr)-1] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 if (!varline(varbfr, var))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 fprintf(fpout, "%s\n", varbfr);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 (void) fclose(fpin); /* don't care about read close errs */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 }
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
124 if (fclose(fpout) == EOF) {
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
125 g_free(varfilebackup);
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
126 g_free(varfile);
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
127 return(EIO); /* errno isn't reliable */
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
128 }
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
129 if (rename(varfilebackup, varfile)) {
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
130 g_free(varfilebackup);
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
131 g_free(varfile);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 return (errno);
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
133 }
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
134 g_free(varfilebackup);
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
135 g_free(varfile);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 return (ZERR_NONE);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
139 static char *get_localvarfile(void)
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 {
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
141 const char *base;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
142 #ifndef WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
143 struct passwd *pwd;
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
144 base = purple_home_dir();
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
145 #else
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
146 base = getenv("HOME");
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
147 if (!base)
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
148 base = getenv("HOMEPATH");
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
149 if (!base)
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
150 base = "C:\\";
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
151 #endif
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
152 if (!base) {
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
153 #ifndef WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
154 if (!(pwd = getpwuid((int) getuid()))) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
155 fprintf(stderr, "Zephyr internal failure: Can't find your entry in /etc/passwd\n");
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
156 return NULL;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
157 }
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
158 base = pwd->pw_dir;
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
159 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
160 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
161
27732
bd1b1353e8fa Don't use a static buffer to hold a full filename, since it could possibly
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 26505
diff changeset
162 return g_strconcat(base, "/.zephyr.vars", NULL);
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
163 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
164
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
165 static char *get_varval(fn, var)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
166 char *fn;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
167 char *var;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
168 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
169 FILE *fp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
170 static char varbfr[512];
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
171 int i;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
172
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
173 fp = fopen(fn, "r");
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
174 if (!fp)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
175 return ((char *)0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
176
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
177 while (fgets(varbfr, sizeof varbfr, fp) != (char *) 0) {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 if (varbfr[strlen(varbfr)-1] < ' ')
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 varbfr[strlen(varbfr)-1] = '\0';
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 if (!(i = varline(varbfr, var)))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181 continue;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 (void) fclose(fp); /* open read-only, don't care */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 return (varbfr+i);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
185 (void) fclose(fp); /* open read-only, don't care */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
186 return ((char *)0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
187 }
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189 /* If the variable in the line bfr[] is the same as var, return index to
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 the variable value, else return 0. */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191 static int varline(bfr, var)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 char *bfr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193 char *var;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194 {
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 register char *cp;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 if (!bfr[0] || bfr[0] == '#') /* comment or null line */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
199 return (0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
200
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 cp = bfr;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 while (*cp && !isspace(*cp) && (*cp != '='))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203 cp++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 #ifndef WIN32
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206 #define max(a,b) ((a > b) ? (a) : (b))
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207 #endif
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208
26505
0c796a1950b7 Updates for GTK+ 3.0. Remove some deprecated functions (someone should
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 18398
diff changeset
209 if (g_ascii_strncasecmp(bfr, var, max(strlen(var), cp - bfr)))
15373
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
210 return(0); /* var is not the var in
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211 bfr ==> no match */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213 cp = strchr(bfr, '=');
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 if (!cp)
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215 return(0);
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216 cp++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217 while (*cp && isspace(*cp)) /* space up to variable value */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218 cp++;
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220 return (cp - bfr); /* return index */
5fe8042783c1 Rename gtk/ and libgaim/ to pidgin/ and libpurple/
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
221 }