Mercurial > pidgin
annotate src/protocols/zephyr/ZVariables.c @ 12645:fc28451f5d96
[gaim-migrate @ 14983]
SF Patch #1314512 from Sadrul (who has a patch for everything)
"This patch introduces a flag for protocol plugins that
support offline messages (like Y!M and ICQ). This was
encouraged by the following conversation:
<sadrul> should offline buddies be listed/enabled in
the send-to menu?
<rekkanoryo> i would think only for protocols that
support offline messaging, if it's indicated that the
buddy is offline
-- <snip> --
<Bleeter> sadrul: personally, I'd like to see a
'supports offline' flag of some description
<Bleeter> one could then redirect (via plugins) through
email or alternative methods
<Bleeter> just a thought
<Paco-Paco> yeah, that sounds like a reasonble thing to have
This patch uses this flag to disable the buddies in the
send-to menu who are offline and the protocol doesn't
support offline messages."
I made this make the label insensitive instead of the whole menuitem. This
should address SimGuy's concerns about inconsistency (i.e. you could create a
conversation with someone via the buddy list that you couldn't create via the
Send To menu). I also hacked up some voodoo to show the label as sensitive when
moused-over, as that looks better (given the label-insensitive thing is itself a
hack). I think this works quite well.
BUG NOTE:
This makes more obvious an existing bug. The Send To menu isn't updated when
buddies sign on or off or change status (at least under some circumstances).
We need to fix that anyway, so I'm not going to let it hold up this commit.
Switching tabs will clear it up. I'm thinking we just might want to build the
contents of that menu when it is selected. That would save us a mess of
inefficient signal callbacks that update the Send To menus in open windows all
the time.
AIM NOTE:
This assumes that AIM can't offline message. That's not strictly true. You can
message invisible users on AIM. However, by design, we can't tell when a user
is invisible without resorting to dirty hackery. In practice, this isn't a
problem, as you can still select the AIM user from the menu. And really, how
often will you be choosing the Invisible contact, rather than the user going
Invisible in the middle of a conversation or IMing you while they're Invisible?
JABBER NOTE:
This assumes that Jabber can always offline message. This isn't strictly true.
Sadrul said:
I have updated Jabber according to this link which seems to
talk about how to determine the existence offline-message
support in a server:
http://www.jabber.org/jeps/jep-0013.html#discover
However, jabber.org doesn't seem to send the required
info. So I am not sure about it.
He later said:
I talked to Nathan and he said offline message support is
mostly assumed for most jabber servers. GTalk doesn't yet
support it, but they are working on it. So I have made
jabber to always return TRUE.
If there is truly no way to detect offline messaging capability, then this is
an acceptable solution. We could special case Google Talk because of its
popularity, and remove that later. It's probably not worth it though.
MSN NOTE:
This assumes that MSN can never offline message. That's effectively true, but
to be technically correct, MSN can offline message if there's already a
switchboard conversation open with a user. We could write an offline_message
function in the MSN prpl to detect that, but it'd be of limited usefulness,
especially given that under most circumstances (where this might matter), the
switchboard connection will be closed almost immediately.
CVS NOTE:
I'm writing to share a tragic little story.
I have a PC that I use for Gaim development. One day, I was writing a commit
message on it, when all of a suddent it went berserk. The screen started
flashing, and the whole commit message just disappeared. All of it. And it was
a good commit message! I had to cram and rewrite it really quickly. Needless to
say, my rushed commit message wasn't nearly as good, and I blame the PC for that.
Seriously, though, what kind of version control system loses your commit
message on a broken connection to the server? Stupid!
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Fri, 23 Dec 2005 19:26:04 +0000 |
| parents | 64895571248f |
| children |
| rev | line source |
|---|---|
| 2086 | 1 /* This file is part of the Project Athena Zephyr Notification System. |
| 2 * It contains source for the ZGetVariable, ZSetVariable, and ZUnsetVariable | |
| 3 * functions. | |
| 4 * | |
| 5 * Created by: Robert French | |
| 6 * | |
| 7 * Copyright (c) 1987 by the Massachusetts Institute of Technology. | |
| 8 * For copying and distribution information, see the file | |
| 9 * "mit-copyright.h". | |
| 10 */ | |
| 11 | |
|
8792
43d6c08d7e96
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
12 #include "internal.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
4272
diff
changeset
|
13 #include "util.h" |
| 2086 | 14 |
| 15 #include <ctype.h> | |
| 10867 | 16 #ifndef WIN32 |
| 2086 | 17 #include <pwd.h> |
| 10867 | 18 #endif |
| 2086 | 19 |
| 20 static int get_localvarfile __P((char *bfr)); | |
| 21 static char *get_varval __P((char *fn, char *val)); | |
| 22 static int varline __P((char *bfr, char *var)); | |
| 23 | |
| 24 char *ZGetVariable(var) | |
| 25 char *var; | |
| 26 { | |
| 27 char varfile[128], *ret; | |
| 28 | |
| 29 if (get_localvarfile(varfile)) | |
| 30 return ((char *)0); | |
| 31 | |
| 32 if ((ret = get_varval(varfile, var)) != ZERR_NONE) | |
| 33 return (ret); | |
| 34 | |
| 10867 | 35 #ifdef WIN32 |
| 36 sprintf(varfile, "C:\\zephyr\\zephyr.var"); | |
| 37 #else | |
| 2086 | 38 sprintf(varfile, "%s/zephyr.vars", CONFDIR); |
| 10867 | 39 #endif |
| 2086 | 40 return (get_varval(varfile, var)); |
| 41 } | |
| 42 | |
| 43 Code_t ZSetVariable(var, value) | |
| 44 char *var; | |
| 45 char *value; | |
| 46 { | |
| 47 int written; | |
| 48 FILE *fpin, *fpout; | |
| 49 char varfile[128], varfilebackup[128], varbfr[512]; | |
| 50 | |
| 51 written = 0; | |
| 52 | |
| 53 if (get_localvarfile(varfile)) | |
| 54 return (ZERR_INTERNAL); | |
| 55 | |
| 56 (void) strcpy(varfilebackup, varfile); | |
| 57 (void) strcat(varfilebackup, ".backup"); | |
| 58 | |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
59 if (!(fpout = fopen(varfilebackup, "w"))) |
| 2086 | 60 return (errno); |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
61 if ((fpin = fopen(varfile, "r")) != NULL) { |
| 2086 | 62 while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) { |
| 63 if (varbfr[strlen(varbfr)-1] < ' ') | |
| 64 varbfr[strlen(varbfr)-1] = '\0'; | |
| 65 if (varline(varbfr, var)) { | |
| 66 fprintf(fpout, "%s = %s\n", var, value); | |
| 67 written = 1; | |
| 68 } | |
| 69 else | |
| 70 fprintf(fpout, "%s\n", varbfr); | |
| 71 } | |
| 72 (void) fclose(fpin); /* don't care about errs on input */ | |
| 73 } | |
| 74 if (!written) | |
| 75 fprintf(fpout, "%s = %s\n", var, value); | |
| 76 if (fclose(fpout) == EOF) | |
| 77 return(EIO); /* can't rely on errno */ | |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
78 if (rename(varfilebackup, varfile)) |
| 2086 | 79 return (errno); |
| 80 return (ZERR_NONE); | |
| 81 } | |
| 82 | |
| 83 Code_t ZUnsetVariable(var) | |
| 84 char *var; | |
| 85 { | |
| 86 FILE *fpin, *fpout; | |
| 87 char varfile[128], varfilebackup[128], varbfr[512]; | |
| 88 | |
| 89 if (get_localvarfile(varfile)) | |
| 90 return (ZERR_INTERNAL); | |
| 91 | |
| 92 (void) strcpy(varfilebackup, varfile); | |
| 93 (void) strcat(varfilebackup, ".backup"); | |
| 94 | |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
95 if (!(fpout = fopen(varfilebackup, "w"))) |
| 2086 | 96 return (errno); |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
97 if ((fpin = fopen(varfile, "r")) != NULL) { |
| 2086 | 98 while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) { |
| 99 if (varbfr[strlen(varbfr)-1] < ' ') | |
| 100 varbfr[strlen(varbfr)-1] = '\0'; | |
| 101 if (!varline(varbfr, var)) | |
| 102 fprintf(fpout, "%s\n", varbfr); | |
| 103 } | |
| 104 (void) fclose(fpin); /* don't care about read close errs */ | |
| 105 } | |
| 106 if (fclose(fpout) == EOF) | |
| 107 return(EIO); /* errno isn't reliable */ | |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
108 if (rename(varfilebackup, varfile)) |
| 2086 | 109 return (errno); |
| 110 return (ZERR_NONE); | |
| 111 } | |
| 112 | |
| 113 static int get_localvarfile(bfr) | |
| 114 char *bfr; | |
| 115 { | |
| 4272 | 116 const char *envptr; |
| 10867 | 117 #ifndef WIN32 |
| 2086 | 118 struct passwd *pwd; |
| 4272 | 119 envptr = gaim_home_dir(); |
| 10867 | 120 #else |
| 121 envptr = getenv("HOME"); | |
| 122 if (!envptr) | |
| 123 envptr = getenv("HOMEPATH"); | |
| 124 if (!envptr) | |
| 125 envptr = "C:\\"; | |
| 126 #endif | |
| 2086 | 127 if (envptr) |
| 128 (void) strcpy(bfr, envptr); | |
| 129 else { | |
| 10867 | 130 #ifndef WIN32 |
| 2086 | 131 if (!(pwd = getpwuid((int) getuid()))) { |
| 132 fprintf(stderr, "Zephyr internal failure: Can't find your entry in /etc/passwd\n"); | |
| 133 return (1); | |
| 134 } | |
| 135 (void) strcpy(bfr, pwd->pw_dir); | |
| 10867 | 136 #endif |
| 2086 | 137 } |
| 138 | |
| 139 (void) strcat(bfr, "/"); | |
| 140 (void) strcat(bfr, ".zephyr.vars"); | |
| 141 return (0); | |
| 142 } | |
| 143 | |
| 144 static char *get_varval(fn, var) | |
| 145 char *fn; | |
| 146 char *var; | |
| 147 { | |
| 148 FILE *fp; | |
| 149 static char varbfr[512]; | |
| 150 int i; | |
| 151 | |
|
10592
d72fffd1b1ad
[gaim-migrate @ 11998]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10589
diff
changeset
|
152 fp = fopen(fn, "r"); |
| 2086 | 153 if (!fp) |
| 154 return ((char *)0); | |
| 155 | |
| 156 while (fgets(varbfr, sizeof varbfr, fp) != (char *) 0) { | |
| 157 if (varbfr[strlen(varbfr)-1] < ' ') | |
| 158 varbfr[strlen(varbfr)-1] = '\0'; | |
| 159 if (!(i = varline(varbfr, var))) | |
| 160 continue; | |
| 161 (void) fclose(fp); /* open read-only, don't care */ | |
| 162 return (varbfr+i); | |
| 163 } | |
| 164 (void) fclose(fp); /* open read-only, don't care */ | |
| 165 return ((char *)0); | |
| 166 } | |
| 167 | |
| 168 /* If the variable in the line bfr[] is the same as var, return index to | |
| 169 the variable value, else return 0. */ | |
| 170 static int varline(bfr, var) | |
| 171 char *bfr; | |
| 172 char *var; | |
| 173 { | |
| 174 register char *cp; | |
| 175 | |
| 176 | |
| 177 if (!bfr[0] || bfr[0] == '#') /* comment or null line */ | |
| 178 return (0); | |
| 179 | |
| 180 cp = bfr; | |
| 181 while (*cp && !isspace(*cp) && (*cp != '=')) | |
| 182 cp++; | |
| 183 | |
| 10867 | 184 #ifndef WIN32 |
| 2086 | 185 #define max(a,b) ((a > b) ? (a) : (b)) |
| 10867 | 186 #endif |
| 2086 | 187 |
| 188 if (strncasecmp(bfr, var, max(strlen(var),cp - bfr))) | |
| 189 return(0); /* var is not the var in | |
| 190 bfr ==> no match */ | |
| 191 | |
| 192 cp = strchr(bfr, '='); | |
| 193 if (!cp) | |
| 194 return(0); | |
| 195 cp++; | |
| 196 while (*cp && isspace(*cp)) /* space up to variable value */ | |
| 197 cp++; | |
| 198 | |
| 199 return (cp - bfr); /* return index */ | |
| 200 } |
