Mercurial > pidgin
annotate src/protocols/zephyr/ZVariables.c @ 7011:4375bf2d9020
[gaim-migrate @ 7574]
The user-visible changes? Gaim now shows peep's away messages in their
tooltip for AIM over oscar.
Things to do:
-Make sure this doesn't screw up with huge buddy lists
-Replace %n with your screen name, etc. in the tooltip
-Leave in b, i, u tags in the tooltip
-Fix the 2 8 byte memleaks in locate.c
Client authors that aren't me will want to read the following pretty
closely...
I made some internal libfaim changes. I desire to make libfaim cleaner.
I don't know if this really helps or not. Here's what I've done:
Changed all the SNAC-sending functions in info.c to NOT take a conn
argument. The connection is looked up from the session. I'm trying
to make oscar.c less-aware of connections.
Added aim_locate_finduserinfo() - Use for getting the aim_userinfo_t for the
given screenname.
Added aim_locate_getinfoshort() - Use this to request that the servers send
you profile info, away message, caps, or a combination of the above. It's
like aim_locate_getinfo() but less rate limited.
Renamed aim_bos_reqlocaterights() to aim_locate_reqrights()
Renamed aim_getinfo() to aim_locate_getinfo()
Renamed aim_setdirectoryinfo() to aim_locate_setdirinfo()
Renamed aim_0002_000b() to aim_locate_000b()
Renamed aim_setuserinterests() to aim_locate_setinterests()
Removed aim_userinfo_sn()
Removed aim_userinfo_flags()
Removed aim_userinfo_idle()
Removed aim_userinfo_warnlevel()
Removed aim_userinfo_createtime()
Removed aim_userinfo_membersince()
Removed aim_userinfo_onlinesince()
Removed aim_userinfo_sessionlen()
Removed aim_userinfo_hascap()
Renamed info.c to locate.c
Made locate.c keep a static, linked list of nodes of sn, away message,
available message, user info. This list is maintained by libfaim
automatically. Now clients don't have to keep track of all this stuff
themselves, and users won't have to wait for away message/info retrieval
if the person is in your buddy list. libfaim uses the iChat way of
retrieving stuff, which is not nearly as rate limited as the old way.
I actually have a feeling WinAIM uses the same SNAC now (although I
didn't check), but I like pluggin iChat because it's innovative.
Moved sess->emailinfo to a static variable inside email.c.
Removed evilhack from oscar.c
I think that's about everything...
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Mon, 29 Sep 2003 12:30:03 +0000 |
| parents | 059d95c67cda |
| children | 43d6c08d7e96 |
| 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 * $Source$ | |
|
5872
059d95c67cda
[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 | |
| 20 #include <internal.h> | |
|
5872
059d95c67cda
[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 | 119 const char *envptr; |
| 2086 | 120 struct passwd *pwd; |
| 121 | |
| 4272 | 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 } |
