2 * Cookie Caching stuff. Adam wrote this, apparently just some
3 * derivatives of n's SNAC work. I cleaned it up, added comments.
5 * I'm going to rewrite this stuff eventually, honest. -jbm
10 * I'm assuming that cookies are type-specific. that is, we can have
11 * "1234578" for type 1 and type 2 concurrently. if i'm wrong, then we
12 * lose some error checking. if we assume cookies are not type-specific and are
13 * wrong, we get quirky behavior when cookies step on each others' toes.
21 * appends a cookie to the cookie list for sess.
22 * - if cookie->cookie for type cookie->type is found, -1 is returned
23 * - copies cookie struct; you need to free() it afterwards;
24 * - cookie->data is not copied, but passed along. don't free it.
25 * - cookie->type is just passed across.
27 * returns -1 on error, 0 on success.
29 faim_internal int aim_cachecookie(struct aim_session_t *sess,
30 struct aim_msgcookie_t *cookie)
32 struct aim_msgcookie_t *newcook;
37 printf("\t\tCC cache %d %s", cookie->type, cookie->cookie);
38 if(cookie->type == AIM_COOKIETYPE_OFTGET) {
39 struct aim_filetransfer_priv *priv;
41 printf("%s\n", priv->sn);
45 if( (newcook = aim_checkcookie(sess, cookie->cookie, cookie->type)) ) {
46 printf("aim_cachecookie: cookie already cached\n");
50 if (!(newcook = malloc(sizeof(struct aim_msgcookie_t))))
52 memcpy(newcook, cookie, sizeof(struct aim_msgcookie_t));
54 newcook->next = sess->msgcookies;
55 sess->msgcookies = newcook;
62 * takes a cookie string and grabs the cookie struct associated with
63 * it. removes struct from chain. returns the struct if found, or
66 faim_internal struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, unsigned char *cookie, int type)
68 struct aim_msgcookie_t *cur, **prev;
70 if (!cookie || !sess->msgcookies)
73 printf("\t\tCC uncache %d %s\n", type, cookie);
75 for (prev = &sess->msgcookies; (cur = *prev); ) {
76 if ((cur->type == type) &&
77 (memcmp(cur->cookie, cookie, 8) == 0)) {
87 faim_internal struct aim_msgcookie_t *aim_mkcookie(unsigned char *c, int type, void *data)
89 struct aim_msgcookie_t *cookie;
94 if (!(cookie = calloc(1, sizeof(struct aim_msgcookie_t))))
99 memcpy(cookie->cookie, c, 8);
104 faim_internal struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *sess, const unsigned char *cookie, const int type)
106 struct aim_msgcookie_t *cur;
108 printf("\t\tCC check %d %s\n", type, cookie);
110 for (cur = sess->msgcookies; cur; cur = cur->next) {
111 if ((cur->type == type) &&
112 (memcmp(cur->cookie, cookie, 8) == 0))
119 faim_internal int aim_freecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie) {
120 struct aim_msgcookie_t *cur, **prev;
122 if (!sess || !cookie)
126 * Make sure its not in the list somewhere still.
128 * If this actually happens, theres been a major coding failure
129 * on my part. However, that does not reduce its occurance likelyhood.
131 for (prev = &sess->msgcookies; (cur = *prev); ) {
143 faim_internal int aim_msgcookie_gettype(int reqclass) {
144 /* XXX: hokey-assed. needs fixed. */
146 case AIM_CAPS_BUDDYICON:
147 return AIM_COOKIETYPE_OFTICON;
150 return AIM_COOKIETYPE_OFTVOICE;
152 case AIM_CAPS_IMIMAGE:
153 return AIM_COOKIETYPE_OFTIMAGE;
156 return AIM_COOKIETYPE_CHAT;
158 case AIM_CAPS_GETFILE:
159 return AIM_COOKIETYPE_OFTGET;
161 case AIM_CAPS_SENDFILE:
162 return AIM_COOKIETYPE_OFTSEND;
165 return AIM_COOKIETYPE_UNKNOWN;