-
/*
*
* Various SNAC-related dodads...
*
*/
+#define FAIM_INTERNAL
#include <faim/aim.h>
/*
return;
}
+faim_internal unsigned long aim_cachesnac(struct aim_session_t *sess,
+ const unsigned short family,
+ const unsigned short type,
+ const unsigned short flags,
+ const void *data, const int datalen)
+{
+ struct aim_snac_t snac;
+
+ snac.id = sess->snac_nextid++;
+ snac.family = family;
+ snac.type = type;
+ snac.flags = flags;
+
+ snac.data = malloc(datalen);
+ memcpy(snac.data, data, datalen);
+
+ return aim_newsnac(sess, &snac);
+}
+
/*
* Clones the passed snac structure and caches it in the
* list/hash.
int i;
for (i = 0; i < FAIM_SNAC_HASH_SIZE; i++) {
- struct aim_snac_t *cur = NULL, *next = NULL, *prev = NULL;
+ struct aim_snac_t *cur, **prev;
time_t curtime;
faim_mutex_lock(&sess->snac_hash_locks[i]);
curtime = time(NULL); /* done here in case we waited for the lock */
- cur = sess->snac_hash[i];
- while (cur) {
- next = cur->next;
+ for (prev = &sess->snac_hash[i]; (cur = *prev); ) {
if ((curtime - cur->issuetime) > maxage) {
- if (sess->snac_hash[i] == cur)
- prev = sess->snac_hash[i] = next;
- else
- prev->next = next;
+
+ *prev = cur->next;
/* XXX should we have destructors here? */
if (cur->data)
free(cur->data);
free(cur);
- } else {
- prev = cur;
- }
- cur = next;
+ } else
+ prev = &cur->next;
}
faim_mutex_unlock(&sess->snac_hash_locks[i]);