Fri, 21 May 2004 14:33:32 +0000
[gaim-migrate @ 9774]
" This patch renames the existing received-*-msg signals
to receiving-*msg to fit the naming of other signals
where a pointer to the message is passed (writing,
sending, displaying)
It adds new received-*-msg signals which are emitted
after the receiving signals, in line with the other
conversation signals (wrote, sent, displayed)
This is necessary to allow plugins which depend on the
final received message to work alongside plugins which
may modify the message.
One known example of this is festival-gaim alongside
gaim-encryption - festival-gaim would try to "speak"
the encrypted text:
http://sf.net/tracker/?func=detail&aid=943216&group_id=89763&atid=591320
I've tested this with gaim-encryption and festival-gaim
(locally modified so gaim-encryption uses the receiving
signal and festival uses the received signal)
All in-tree users of received-*-msg are updated to use
receiving-*-msg if they do modify the message, the
conversation-signals documentation is updated, the
signals-test.c & signal-test.tcl plugins are also updated." --Stu Tomlinson
committer: Luke Schierer <lschiere@pidgin.im>
| 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 | * $Source$ | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
4272
diff
changeset
|
8 | * $Author: chipx86 $ |
| 2086 | 9 | * |
| 10 | * Copyright (c) 1987 by the Massachusetts Institute of Technology. | |
| 11 | * For copying and distribution information, see the file | |
| 12 | * "mit-copyright.h". | |
| 13 | */ | |
| 14 | /* $Header$ */ | |
| 15 | ||
| 16 | #ifndef lint | |
| 17 | static char rcsid_ZVariables_c[] = "$Header$"; | |
| 18 | #endif | |
| 19 | ||
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
20 | #include "internal.h" |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
4272
diff
changeset
|
21 | #include "util.h" |
| 2086 | 22 | |
| 23 | #include <ctype.h> | |
| 24 | #include <pwd.h> | |
| 25 | ||
| 26 | static int get_localvarfile __P((char *bfr)); | |
| 27 | static char *get_varval __P((char *fn, char *val)); | |
| 28 | static int varline __P((char *bfr, char *var)); | |
| 29 | ||
| 30 | char *ZGetVariable(var) | |
| 31 | char *var; | |
| 32 | { | |
| 33 | char varfile[128], *ret; | |
| 34 | char *get_varval(); | |
| 35 | ||
| 36 | if (get_localvarfile(varfile)) | |
| 37 | return ((char *)0); | |
| 38 | ||
| 39 | if ((ret = get_varval(varfile, var)) != ZERR_NONE) | |
| 40 | return (ret); | |
| 41 | ||
| 42 | sprintf(varfile, "%s/zephyr.vars", CONFDIR); | |
| 43 | return (get_varval(varfile, var)); | |
| 44 | } | |
| 45 | ||
| 46 | Code_t ZSetVariable(var, value) | |
| 47 | char *var; | |
| 48 | char *value; | |
| 49 | { | |
| 50 | int written; | |
| 51 | FILE *fpin, *fpout; | |
| 52 | char varfile[128], varfilebackup[128], varbfr[512]; | |
| 53 | ||
| 54 | written = 0; | |
| 55 | ||
| 56 | if (get_localvarfile(varfile)) | |
| 57 | return (ZERR_INTERNAL); | |
| 58 | ||
| 59 | (void) strcpy(varfilebackup, varfile); | |
| 60 | (void) strcat(varfilebackup, ".backup"); | |
| 61 | ||
| 62 | if (!(fpout = fopen(varfilebackup, "w"))) | |
| 63 | return (errno); | |
| 64 | if ((fpin = fopen(varfile, "r")) != NULL) { | |
| 65 | while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) { | |
| 66 | if (varbfr[strlen(varbfr)-1] < ' ') | |
| 67 | varbfr[strlen(varbfr)-1] = '\0'; | |
| 68 | if (varline(varbfr, var)) { | |
| 69 | fprintf(fpout, "%s = %s\n", var, value); | |
| 70 | written = 1; | |
| 71 | } | |
| 72 | else | |
| 73 | fprintf(fpout, "%s\n", varbfr); | |
| 74 | } | |
| 75 | (void) fclose(fpin); /* don't care about errs on input */ | |
| 76 | } | |
| 77 | if (!written) | |
| 78 | fprintf(fpout, "%s = %s\n", var, value); | |
| 79 | if (fclose(fpout) == EOF) | |
| 80 | return(EIO); /* can't rely on errno */ | |
| 81 | if (rename(varfilebackup, varfile)) | |
| 82 | return (errno); | |
| 83 | return (ZERR_NONE); | |
| 84 | } | |
| 85 | ||
| 86 | Code_t ZUnsetVariable(var) | |
| 87 | char *var; | |
| 88 | { | |
| 89 | FILE *fpin, *fpout; | |
| 90 | char varfile[128], varfilebackup[128], varbfr[512]; | |
| 91 | ||
| 92 | if (get_localvarfile(varfile)) | |
| 93 | return (ZERR_INTERNAL); | |
| 94 | ||
| 95 | (void) strcpy(varfilebackup, varfile); | |
| 96 | (void) strcat(varfilebackup, ".backup"); | |
| 97 | ||
| 98 | if (!(fpout = fopen(varfilebackup, "w"))) | |
| 99 | return (errno); | |
| 100 | if ((fpin = fopen(varfile, "r")) != NULL) { | |
| 101 | while (fgets(varbfr, sizeof varbfr, fpin) != (char *) 0) { | |
| 102 | if (varbfr[strlen(varbfr)-1] < ' ') | |
| 103 | varbfr[strlen(varbfr)-1] = '\0'; | |
| 104 | if (!varline(varbfr, var)) | |
| 105 | fprintf(fpout, "%s\n", varbfr); | |
| 106 | } | |
| 107 | (void) fclose(fpin); /* don't care about read close errs */ | |
| 108 | } | |
| 109 | if (fclose(fpout) == EOF) | |
| 110 | return(EIO); /* errno isn't reliable */ | |
| 111 | if (rename(varfilebackup, varfile)) | |
| 112 | return (errno); | |
| 113 | return (ZERR_NONE); | |
| 114 | } | |
| 115 | ||
| 116 | static int get_localvarfile(bfr) | |
| 117 | char *bfr; | |
| 118 | { | |
|
4272
fd89c8c4964d
[gaim-migrate @ 4523]
Robert McQueen <robot101@debian.org>
parents:
4271
diff
changeset
|
119 | const char *envptr; |
| 2086 | 120 | struct passwd *pwd; |
| 121 | ||
|
4272
fd89c8c4964d
[gaim-migrate @ 4523]
Robert McQueen <robot101@debian.org>
parents:
4271
diff
changeset
|
122 | envptr = gaim_home_dir(); |
| 2086 | 123 | if (envptr) |
| 124 | (void) strcpy(bfr, envptr); | |
| 125 | else { | |
| 126 | if (!(pwd = getpwuid((int) getuid()))) { | |
| 127 | fprintf(stderr, "Zephyr internal failure: Can't find your entry in /etc/passwd\n"); | |
| 128 | return (1); | |
| 129 | } | |
| 130 | (void) strcpy(bfr, pwd->pw_dir); | |
| 131 | } | |
| 132 | ||
| 133 | (void) strcat(bfr, "/"); | |
| 134 | (void) strcat(bfr, ".zephyr.vars"); | |
| 135 | return (0); | |
| 136 | } | |
| 137 | ||
| 138 | static char *get_varval(fn, var) | |
| 139 | char *fn; | |
| 140 | char *var; | |
| 141 | { | |
| 142 | FILE *fp; | |
| 143 | static char varbfr[512]; | |
| 144 | int i; | |
| 145 | ||
| 146 | fp = fopen(fn, "r"); | |
| 147 | if (!fp) | |
| 148 | return ((char *)0); | |
| 149 | ||
| 150 | while (fgets(varbfr, sizeof varbfr, fp) != (char *) 0) { | |
| 151 | if (varbfr[strlen(varbfr)-1] < ' ') | |
| 152 | varbfr[strlen(varbfr)-1] = '\0'; | |
| 153 | if (!(i = varline(varbfr, var))) | |
| 154 | continue; | |
| 155 | (void) fclose(fp); /* open read-only, don't care */ | |
| 156 | return (varbfr+i); | |
| 157 | } | |
| 158 | (void) fclose(fp); /* open read-only, don't care */ | |
| 159 | return ((char *)0); | |
| 160 | } | |
| 161 | ||
| 162 | /* If the variable in the line bfr[] is the same as var, return index to | |
| 163 | the variable value, else return 0. */ | |
| 164 | static int varline(bfr, var) | |
| 165 | char *bfr; | |
| 166 | char *var; | |
| 167 | { | |
| 168 | register char *cp; | |
| 169 | ||
| 170 | ||
| 171 | if (!bfr[0] || bfr[0] == '#') /* comment or null line */ | |
| 172 | return (0); | |
| 173 | ||
| 174 | cp = bfr; | |
| 175 | while (*cp && !isspace(*cp) && (*cp != '=')) | |
| 176 | cp++; | |
| 177 | ||
| 178 | #define max(a,b) ((a > b) ? (a) : (b)) | |
| 179 | ||
| 180 | if (strncasecmp(bfr, var, max(strlen(var),cp - bfr))) | |
| 181 | return(0); /* var is not the var in | |
| 182 | bfr ==> no match */ | |
| 183 | ||
| 184 | cp = strchr(bfr, '='); | |
| 185 | if (!cp) | |
| 186 | return(0); | |
| 187 | cp++; | |
| 188 | while (*cp && isspace(*cp)) /* space up to variable value */ | |
| 189 | cp++; | |
| 190 | ||
| 191 | return (cp - bfr); /* return index */ | |
| 192 | } |