]> andersk Git - libfaim.git/blame_incremental - aim_msgcookie.c
- Thu Feb 8 20:12:39 UTC 2001
[libfaim.git] / aim_msgcookie.c
... / ...
CommitLineData
1/*
2 * Cookie Caching stuff. Adam wrote this, apparently just some
3 * derivatives of n's SNAC work. I cleaned it up, added comments.
4 *
5 * I'm going to rewrite this stuff eventually, honest. -jbm
6 *
7 */
8
9/*
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.
14 */
15
16#define FAIM_INTERNAL
17#include <faim/aim.h>
18
19/*
20 * aim_cachecookie:
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.
26 *
27 * returns -1 on error, 0 on success.
28 */
29faim_internal int aim_cachecookie(struct aim_session_t *sess,
30 struct aim_msgcookie_t *cookie)
31{
32 struct aim_msgcookie_t *newcook;
33
34 if (!sess || !cookie)
35 return -1;
36
37 printf("\t\tCC cache %d %s", cookie->type, cookie->cookie);
38 if(cookie->type == AIM_COOKIETYPE_OFTGET) {
39 struct aim_filetransfer_priv *priv;
40 priv = cookie->data;
41 printf("%s\n", priv->sn);
42 } else
43 printf("\n");
44
45 if( (newcook = aim_checkcookie(sess, cookie->cookie, cookie->type)) ) {
46 printf("aim_cachecookie: cookie already cached\n");
47 return -1;
48 }
49
50 if (!(newcook = malloc(sizeof(struct aim_msgcookie_t))))
51 return -1;
52 memcpy(newcook, cookie, sizeof(struct aim_msgcookie_t));
53
54 newcook->next = sess->msgcookies;
55 sess->msgcookies = newcook;
56
57 return 0;
58}
59
60/*
61 * aim_uncachecookie:
62 * takes a cookie string and grabs the cookie struct associated with
63 * it. removes struct from chain. returns the struct if found, or
64 * NULL on not found.
65 */
66faim_internal struct aim_msgcookie_t *aim_uncachecookie(struct aim_session_t *sess, unsigned char *cookie, int type)
67{
68 struct aim_msgcookie_t *cur, **prev;
69
70 if (!cookie || !sess->msgcookies)
71 return NULL;
72
73 printf("\t\tCC uncache %d %s\n", type, cookie);
74
75 for (prev = &sess->msgcookies; (cur = *prev); ) {
76 if ((cur->type == type) &&
77 (memcmp(cur->cookie, cookie, 8) == 0)) {
78 *prev = cur->next;
79 return cur;
80 }
81 prev = &cur->next;
82 }
83
84 return NULL;
85}
86
87faim_internal struct aim_msgcookie_t *aim_mkcookie(unsigned char *c, int type, void *data)
88{
89 struct aim_msgcookie_t *cookie;
90
91 if (!c)
92 return NULL;
93
94 if (!(cookie = calloc(1, sizeof(struct aim_msgcookie_t))))
95 return NULL;
96
97 cookie->data = data;
98 cookie->type = type;
99 memcpy(cookie->cookie, c, 8);
100
101 return cookie;
102}
103
104faim_internal struct aim_msgcookie_t *aim_checkcookie(struct aim_session_t *sess, const unsigned char *cookie, const int type)
105{
106 struct aim_msgcookie_t *cur;
107
108 printf("\t\tCC check %d %s\n", type, cookie);
109
110 for (cur = sess->msgcookies; cur; cur = cur->next) {
111 if ((cur->type == type) &&
112 (memcmp(cur->cookie, cookie, 8) == 0))
113 return cur;
114 }
115
116 return NULL;
117}
118
119faim_internal int aim_freecookie(struct aim_session_t *sess, struct aim_msgcookie_t *cookie) {
120 struct aim_msgcookie_t *cur, **prev;
121
122 if (!sess || !cookie)
123 return -1;
124
125 /*
126 * Make sure its not in the list somewhere still.
127 *
128 * If this actually happens, theres been a major coding failure
129 * on my part. However, that does not reduce its occurance likelyhood.
130 */
131 for (prev = &sess->msgcookies; (cur = *prev); ) {
132 if (cur == cookie) {
133 *prev = cur->next;
134 } else
135 prev = &cur->next;
136 }
137
138 free(cookie);
139
140 return 0;
141}
142
143faim_internal int aim_msgcookie_gettype(int reqclass) {
144 /* XXX: hokey-assed. needs fixed. */
145 switch(reqclass) {
146 case AIM_CAPS_BUDDYICON:
147 return AIM_COOKIETYPE_OFTICON;
148 break;
149 case AIM_CAPS_VOICE:
150 return AIM_COOKIETYPE_OFTVOICE;
151 break;
152 case AIM_CAPS_IMIMAGE:
153 return AIM_COOKIETYPE_OFTIMAGE;
154 break;
155 case AIM_CAPS_CHAT:
156 return AIM_COOKIETYPE_CHAT;
157 break;
158 case AIM_CAPS_GETFILE:
159 return AIM_COOKIETYPE_OFTGET;
160 break;
161 case AIM_CAPS_SENDFILE:
162 return AIM_COOKIETYPE_OFTSEND;
163 break;
164 default:
165 return AIM_COOKIETYPE_UNKNOWN;
166 break;
167 }
168}
This page took 0.03864 seconds and 5 git commands to generate.