comparison src/protocols/oscar/msgcookie.c @ 11399:48244c196228

[gaim-migrate @ 13634] Fix some warnings? Get rid of some whitespace. My usual mucking about committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 01 Sep 2005 02:09:56 +0000
parents 7d31d61e6438
children f2431a7e33aa
comparison
equal deleted inserted replaced
11398:90290f579926 11399:48244c196228
1 /* 1 /*
2 * Cookie Caching stuff. Adam wrote this, apparently just some 2 * Cookie Caching stuff. Adam wrote this, apparently just some
3 * derivatives of n's SNAC work. I cleaned it up, added comments. 3 * derivatives of n's SNAC work. I cleaned it up, added comments.
4 * 4 *
5 */ 5 */
6 6
7 /* 7 /*
8 * I'm assuming that cookies are type-specific. that is, we can have 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 9 * "1234578" for type 1 and type 2 concurrently. if i'm wrong, then we
32 32
33 if (!sess || !cookie) 33 if (!sess || !cookie)
34 return -EINVAL; 34 return -EINVAL;
35 35
36 newcook = aim_checkcookie(sess, cookie->cookie, cookie->type); 36 newcook = aim_checkcookie(sess, cookie->cookie, cookie->type);
37 37
38 if (newcook == cookie) { 38 if (newcook == cookie) {
39 newcook->addtime = time(NULL); 39 newcook->addtime = time(NULL);
40 return 1; 40 return 1;
41 } else if (newcook) 41 } else if (newcook)
42 aim_cookie_free(sess, newcook); 42 aim_cookie_free(sess, newcook);
43 43
44 cookie->addtime = time(NULL); 44 cookie->addtime = time(NULL);
45 45
46 cookie->next = sess->msgcookies; 46 cookie->next = sess->msgcookies;
47 sess->msgcookies = cookie; 47 sess->msgcookies = cookie;
48 48
49 return 0; 49 return 0;
65 65
66 if (!cookie || !sess->msgcookies) 66 if (!cookie || !sess->msgcookies)
67 return NULL; 67 return NULL;
68 68
69 for (prev = &sess->msgcookies; (cur = *prev); ) { 69 for (prev = &sess->msgcookies; (cur = *prev); ) {
70 if ((cur->type == type) && 70 if ((cur->type == type) &&
71 (memcmp(cur->cookie, cookie, 8) == 0)) { 71 (memcmp(cur->cookie, cookie, 8) == 0)) {
72 *prev = cur->next; 72 *prev = cur->next;
73 return cur; 73 return cur;
74 } 74 }
75 prev = &cur->next; 75 prev = &cur->next;
85 * @param type cookie type to use 85 * @param type cookie type to use
86 * @param data data to be cached with the cookie 86 * @param data data to be cached with the cookie
87 * @return returns NULL on error, a pointer to the newly-allocated 87 * @return returns NULL on error, a pointer to the newly-allocated
88 * cookie on success. 88 * cookie on success.
89 */ 89 */
90 faim_internal aim_msgcookie_t *aim_mkcookie(fu8_t *c, int type, void *data) 90 faim_internal aim_msgcookie_t *aim_mkcookie(fu8_t *c, int type, void *data)
91 { 91 {
92 aim_msgcookie_t *cookie; 92 aim_msgcookie_t *cookie;
93 93
94 if (!c) 94 if (!c)
95 return NULL; 95 return NULL;
117 faim_internal aim_msgcookie_t *aim_checkcookie(aim_session_t *sess, const fu8_t *cookie, int type) 117 faim_internal aim_msgcookie_t *aim_checkcookie(aim_session_t *sess, const fu8_t *cookie, int type)
118 { 118 {
119 aim_msgcookie_t *cur; 119 aim_msgcookie_t *cur;
120 120
121 for (cur = sess->msgcookies; cur; cur = cur->next) { 121 for (cur = sess->msgcookies; cur; cur = cur->next) {
122 if ((cur->type == type) && 122 if ((cur->type == type) &&
123 (memcmp(cur->cookie, cookie, 8) == 0)) 123 (memcmp(cur->cookie, cookie, 8) == 0))
124 return cur; 124 return cur;
125 } 125 }
126 126
127 return NULL; 127 return NULL;
128 } 128 }
129 129
138 * @param sess session to remove the cookie from 138 * @param sess session to remove the cookie from
139 * @param cookie the address of a pointer to the cookie struct to remove 139 * @param cookie the address of a pointer to the cookie struct to remove
140 * @return returns -1 on error, 0 on success. 140 * @return returns -1 on error, 0 on success.
141 * 141 *
142 */ 142 */
143 faim_internal int aim_cookie_free(aim_session_t *sess, aim_msgcookie_t *cookie) 143 faim_internal int aim_cookie_free(aim_session_t *sess, aim_msgcookie_t *cookie)
144 { 144 {
145 aim_msgcookie_t *cur, **prev; 145 aim_msgcookie_t *cur, **prev;
146 146
147 if (!sess || !cookie) 147 if (!sess || !cookie)
148 return -EINVAL; 148 return -EINVAL;
156 156
157 free(cookie->data); 157 free(cookie->data);
158 free(cookie); 158 free(cookie);
159 159
160 return 0; 160 return 0;
161 } 161 }
162 162
163 /* XXX I hate switch */ 163 /* XXX I hate switch */
164 faim_internal int aim_msgcookie_gettype(int reqclass) 164 faim_internal int aim_msgcookie_gettype(int reqclass)
165 { 165 {
166 /* XXX: hokey-assed. needs fixed. */ 166 /* XXX: hokey-assed. needs fixed. */
167 switch(reqclass) { 167 switch(reqclass) {
168 case AIM_CAPS_BUDDYICON: return AIM_COOKIETYPE_OFTICON; 168 case AIM_CAPS_BUDDYICON: return AIM_COOKIETYPE_OFTICON;
169 case AIM_CAPS_TALK: return AIM_COOKIETYPE_OFTVOICE; 169 case AIM_CAPS_TALK: return AIM_COOKIETYPE_OFTVOICE;
170 case AIM_CAPS_DIRECTIM: return AIM_COOKIETYPE_OFTIMAGE; 170 case AIM_CAPS_DIRECTIM: return AIM_COOKIETYPE_OFTIMAGE;
171 case AIM_CAPS_CHAT: return AIM_COOKIETYPE_CHAT; 171 case AIM_CAPS_CHAT: return AIM_COOKIETYPE_CHAT;
172 case AIM_CAPS_GETFILE: return AIM_COOKIETYPE_OFTGET; 172 case AIM_CAPS_GETFILE: return AIM_COOKIETYPE_OFTGET;
173 case AIM_CAPS_SENDFILE: return AIM_COOKIETYPE_OFTSEND; 173 case AIM_CAPS_SENDFILE: return AIM_COOKIETYPE_OFTSEND;
174 default: return AIM_COOKIETYPE_UNKNOWN; 174 default: return AIM_COOKIETYPE_UNKNOWN;
175 } 175 }
176 } 176 }