struct WHOQueueEntry {
char type;
- struct ClientSocket *client;
struct ChanNode *chan;
struct UserNode *user;
struct WHOQueueEntry *next;
void *callback[MAXCALLBACKS];
void *data[MAXCALLBACKS];
};
-
-static struct WHOQueueEntry *first_entry = NULL, *last_entry = NULL;
-
static struct WHOQueueEntry* addWHOQueueEntry(struct ClientSocket *client) {
struct WHOQueueEntry *entry = malloc(sizeof(*entry));
if (!entry)
return NULL;
}
entry->next = NULL;
- entry->client = client;
- if(last_entry) {
- last_entry->next = entry;
- last_entry = entry;
+ if(client->whoqueue_last) {
+ client->whoqueue_last->next = entry;
} else {
- last_entry = entry;
- first_entry = entry;
+ client->whoqueue_first = entry;
}
+ client->whoqueue_last = entry;
return entry;
}
static struct WHOQueueEntry* getNextWHOQueueEntry(struct ClientSocket *client, int freeEntry) {
- if(!first_entry) return NULL;
- struct WHOQueueEntry *entry;
- for(entry = first_entry; entry; entry = entry->next) {
- if(entry->client == client)
- break;
- }
- if(entry == NULL) return NULL;
+ if(!client->whoqueue_first) return NULL;
+ struct WHOQueueEntry *entry = client->whoqueue_first;
if(freeEntry) {
- if(entry == first_entry)
- first_entry = entry->next;
- if(entry == last_entry) {
- struct WHOQueueEntry *last = NULL;
- for(last = first_entry; last; last = last->next)
- if(last->next == NULL) break;
- last_entry = last;
+ client->whoqueue_first = entry->next;
+ if(entry == client->whoqueue_last) {
+ client->whoqueue_last = NULL;
}
}
return entry;
}
+void clear_whoqueue(struct ClientSocket *client) {
+ if(!client->whoqueue_first) return;
+ struct WHOQueueEntry *entry, *next;
+ for(entry = client->whoqueue_first; entry; entry = next) {
+ next = entry->next;
+ free(entry);
+ }
+ client->whoqueue_last = NULL;
+}
+
void get_userlist(struct ChanNode *chan, userlist_callback_t callback, void *data) {
struct ClientSocket *bot;
for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
void get_userauth(struct UserNode *user, userauth_callback_t callback, void *data) {
//check if we have already an active WHO for this user
+ struct ClientSocket *bot, *whobot = NULL;
struct WHOQueueEntry *entry;
- for(entry = first_entry; entry; entry = entry->next) {
- if((entry->type & WHOQUEUETYPE_USERAUTH) && entry->user == user) {
- int i = 0;
- for(i = 1; i < MAXCALLBACKS; i++) {
- if(!entry->callback[i]) {
- entry->callback[i] = callback;
- entry->data[i] = data;
- return;
+ for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
+ for(entry = bot->whoqueue_first; entry; entry = entry->next) {
+ if((entry->type & WHOQUEUETYPE_USERAUTH) && entry->user == user) {
+ int i = 0;
+ for(i = 1; i < MAXCALLBACKS; i++) {
+ if(!entry->callback[i]) {
+ entry->callback[i] = callback;
+ entry->data[i] = data;
+ return;
+ }
}
}
}
- }
- struct ClientSocket *bot;
- for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
if(bot->flags & SOCKET_FLAG_PREFERRED)
- break;
+ whobot = bot;
}
+ bot = whobot;
if(bot == NULL) bot = getBots(SOCKET_FLAG_READY, NULL);
//check if we really need to who the user
if((user->flags & (USERFLAG_ISAUTHED | USERFLAG_ISIRCOP | USERFLAG_ISBOT | USERFLAG_ISSERVER)) || (time(0) - user->last_who) <= REWHO_TIMEOUT) {
}
void free_whoqueue() {
- struct WHOQueueEntry *entry, *next;
- for(entry = first_entry; entry; entry = next) {
- next = entry->next;
- free(entry);
- }
- first_entry = NULL;
- last_entry = NULL;
+
}