Mercurial > pidgin.yaz
annotate src/protocols/oscar/msgcookie.c @ 13047:473d3a454615
[gaim-migrate @ 15408]
15:52:32 <NSA_> In the system tray, the "Custom Status..." should be changed to
"New Status..." to be more consistent.
committer: Tailor Script <tailor@pidgin.im>
author | Etan Reisner <pidgin@unreliablesource.net> |
---|---|
date | Thu, 26 Jan 2006 20:54:00 +0000 |
parents | 48244c196228 |
children | f2431a7e33aa |
rev | line source |
---|---|
2086 | 1 /* |
2 * Cookie Caching stuff. Adam wrote this, apparently just some | |
3 * derivatives of n's SNAC work. I cleaned it up, added comments. | |
11399 | 4 * |
2086 | 5 */ |
6 | |
7 /* | |
8 * I'm assuming that cookies are type-specific. that is, we can have | |
9 * "1234578" for type 1 and type 2 concurrently. if i'm wrong, then we | |
10 * lose some error checking. if we assume cookies are not type-specific and are | |
11 * wrong, we get quirky behavior when cookies step on each others' toes. | |
12 */ | |
13 | |
14 #define FAIM_INTERNAL | |
15 #include <aim.h> | |
16 | |
17 /** | |
18 * aim_cachecookie - appends a cookie to the cookie list | |
19 * | |
20 * if cookie->cookie for type cookie->type is found, updates the | |
21 * ->addtime of the found structure; otherwise adds the given cookie | |
22 * to the cache | |
23 * | |
8866 | 24 * @param sess session to add to |
25 * @param cookie pointer to struct to append | |
26 * @return returns -1 on error, 0 on append, 1 on update. the cookie you pass | |
27 * in may be free'd, so don't count on its value after calling this! | |
2086 | 28 */ |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
29 faim_internal int aim_cachecookie(aim_session_t *sess, aim_msgcookie_t *cookie) |
2086 | 30 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
31 aim_msgcookie_t *newcook; |
2086 | 32 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
33 if (!sess || !cookie) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
34 return -EINVAL; |
2086 | 35 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
36 newcook = aim_checkcookie(sess, cookie->cookie, cookie->type); |
11399 | 37 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
38 if (newcook == cookie) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
39 newcook->addtime = time(NULL); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
40 return 1; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
41 } else if (newcook) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
42 aim_cookie_free(sess, newcook); |
2086 | 43 |
11399 | 44 cookie->addtime = time(NULL); |
2086 | 45 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
46 cookie->next = sess->msgcookies; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
47 sess->msgcookies = cookie; |
2086 | 48 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
49 return 0; |
2086 | 50 } |
51 | |
52 /** | |
53 * aim_uncachecookie - grabs a cookie from the cookie cache (removes it from the list) | |
54 * | |
55 * takes a cookie string and a cookie type and finds the cookie struct associated with that duple, removing it from the cookie list ikn the process. | |
56 * | |
8866 | 57 * @param sess session to grab cookie from |
58 * @param cookie cookie string to look for | |
59 * @param type cookie type to look for | |
60 * @return if found, returns the struct; if none found (or on error), returns NULL: | |
2086 | 61 */ |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
62 faim_internal aim_msgcookie_t *aim_uncachecookie(aim_session_t *sess, fu8_t *cookie, int type) |
2086 | 63 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
64 aim_msgcookie_t *cur, **prev; |
2086 | 65 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
66 if (!cookie || !sess->msgcookies) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
67 return NULL; |
2086 | 68 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
69 for (prev = &sess->msgcookies; (cur = *prev); ) { |
11399 | 70 if ((cur->type == type) && |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
71 (memcmp(cur->cookie, cookie, 8) == 0)) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
72 *prev = cur->next; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
73 return cur; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
74 } |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
75 prev = &cur->next; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
76 } |
2086 | 77 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
78 return NULL; |
2086 | 79 } |
80 | |
81 /** | |
82 * aim_mkcookie - generate an aim_msgcookie_t *struct from a cookie string, a type, and a data pointer. | |
83 * | |
8866 | 84 * @param c pointer to the cookie string array |
85 * @param type cookie type to use | |
86 * @param data data to be cached with the cookie | |
87 * @return returns NULL on error, a pointer to the newly-allocated | |
88 * cookie on success. | |
2086 | 89 */ |
11399 | 90 faim_internal aim_msgcookie_t *aim_mkcookie(fu8_t *c, int type, void *data) |
2086 | 91 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
92 aim_msgcookie_t *cookie; |
2086 | 93 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
94 if (!c) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
95 return NULL; |
2086 | 96 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
97 if (!(cookie = calloc(1, sizeof(aim_msgcookie_t)))) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
98 return NULL; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
99 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
100 cookie->data = data; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
101 cookie->type = type; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
102 memcpy(cookie->cookie, c, 8); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
103 |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
104 return cookie; |
2086 | 105 } |
106 | |
107 /** | |
108 * aim_checkcookie - check to see if a cookietuple has been cached | |
109 * | |
8866 | 110 * @param sess session to check for the cookie in |
111 * @param cookie pointer to the cookie string array | |
112 * @param type type of the cookie to look for | |
113 * @return returns a pointer to the cookie struct (still in the list) | |
114 * on success; returns NULL on error/not found | |
2086 | 115 */ |
116 | |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
117 faim_internal aim_msgcookie_t *aim_checkcookie(aim_session_t *sess, const fu8_t *cookie, int type) |
2086 | 118 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
119 aim_msgcookie_t *cur; |
2086 | 120 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
121 for (cur = sess->msgcookies; cur; cur = cur->next) { |
11399 | 122 if ((cur->type == type) && |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
123 (memcmp(cur->cookie, cookie, 8) == 0)) |
11399 | 124 return cur; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
125 } |
2086 | 126 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
127 return NULL; |
2086 | 128 } |
129 | |
130 /** | |
131 * aim_cookie_free - free an aim_msgcookie_t struct | |
132 * | |
10504 | 133 * this function removes the cookie *cookie from the list of cookies |
2086 | 134 * in sess, and then frees all memory associated with it. including |
135 * its data! if you want to use the private data after calling this, | |
136 * make sure you copy it first. | |
137 * | |
8866 | 138 * @param sess session to remove the cookie from |
139 * @param cookie the address of a pointer to the cookie struct to remove | |
140 * @return returns -1 on error, 0 on success. | |
2086 | 141 * |
142 */ | |
11399 | 143 faim_internal int aim_cookie_free(aim_session_t *sess, aim_msgcookie_t *cookie) |
2086 | 144 { |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
145 aim_msgcookie_t *cur, **prev; |
2086 | 146 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
147 if (!sess || !cookie) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
148 return -EINVAL; |
2086 | 149 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
150 for (prev = &sess->msgcookies; (cur = *prev); ) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
151 if (cur == cookie) |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
152 *prev = cur->next; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
153 else |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
154 prev = &cur->next; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
155 } |
2086 | 156 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
157 free(cookie->data); |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
158 free(cookie); |
2086 | 159 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
160 return 0; |
11399 | 161 } |
2086 | 162 |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
163 /* XXX I hate switch */ |
11399 | 164 faim_internal int aim_msgcookie_gettype(int reqclass) |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
165 { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
166 /* XXX: hokey-assed. needs fixed. */ |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
167 switch(reqclass) { |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
168 case AIM_CAPS_BUDDYICON: return AIM_COOKIETYPE_OFTICON; |
8092 | 169 case AIM_CAPS_TALK: return AIM_COOKIETYPE_OFTVOICE; |
6871 | 170 case AIM_CAPS_DIRECTIM: return AIM_COOKIETYPE_OFTIMAGE; |
2246
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
171 case AIM_CAPS_CHAT: return AIM_COOKIETYPE_CHAT; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
172 case AIM_CAPS_GETFILE: return AIM_COOKIETYPE_OFTGET; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
173 case AIM_CAPS_SENDFILE: return AIM_COOKIETYPE_OFTSEND; |
933346315b9b
[gaim-migrate @ 2256]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
174 default: return AIM_COOKIETYPE_UNKNOWN; |
11399 | 175 } |
2086 | 176 } |