[gaim-migrate @ 3063]
[pidgin-git.git] / src / protocols / icq / queue.c
blobed37dfeebc3ee0608b3f47e934052c707d050dcf
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 /*
4 * $Id: queue.c 2509 2001-10-13 00:06:18Z warmenhoven $
6 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
7 * Bill Soudan <soudan@kde.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <stdlib.h>
27 #include "icqlib.h"
28 #include "queue.h"
29 #include "udp.h"
31 void icq_UDPQueueNew(icq_Link *icqlink)
33 icqlink->d->icq_UDPQueue = icq_ListNew();
34 icqlink->icq_UDPExpireInterval = 15; /* expire interval = 15 sec */
37 void icq_UDPQueuePut(icq_Link *icqlink, icq_Packet *p)
39 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)malloc(sizeof(icq_UDPQueueItem));
40 #ifdef QUEUE_DEBUG
41 printf("icq_UDPQueuePut(seq=0x%04X, cmd=0x%04X)\n", icq_PacketReadUDPOutSeq1(p),
42 icq_PacketReadUDPOutCmd(p));
43 #endif
44 ptr->attempts = 1;
45 ptr->timeout = icq_TimeoutNew(icqlink->icq_UDPExpireInterval,
46 (icq_TimeoutHandler)icq_UDPQueueItemResend, ptr);
47 ptr->timeout->single_shot = 0;
48 ptr->pack = p;
49 ptr->icqlink = icqlink;
50 #ifdef QUEUE_DEBUG
51 printf("enqueuing queueitem %p\n", ptr);
52 #endif
53 icq_ListEnqueue(icqlink->d->icq_UDPQueue, ptr);
56 void _icq_UDPQueueItemFree(void *p)
58 icq_UDPQueueItem *pitem=(icq_UDPQueueItem *)p;
60 #ifdef QUEUE_DEBUG
61 printf("_icq_UDPQueueItemFree(%p)\n", p);
62 #endif
64 if (pitem->pack)
65 icq_PacketDelete(pitem->pack);
67 if (pitem->timeout)
68 icq_TimeoutDelete(pitem->timeout);
70 free(p);
73 /* Frees the queue and dispose it */
74 void icq_UDPQueueDelete(icq_Link *icqlink)
76 #ifdef QUEUE_DEBUG
77 printf("icq_UDPQueueDelete\n");
78 #endif
79 if(icqlink->d->icq_UDPQueue)
81 icq_ListDelete(icqlink->d->icq_UDPQueue, _icq_UDPQueueItemFree);
82 icqlink->d->icq_UDPQueue = 0;
86 /* Only frees the queue */
87 void icq_UDPQueueFree(icq_Link *icqlink)
89 #ifdef QUEUE_DEBUG
90 printf("icq_UDPQueueFree\n");
91 #endif
92 if(icqlink->d->icq_UDPQueue)
93 icq_ListFree(icqlink->d->icq_UDPQueue, _icq_UDPQueueItemFree);
96 int icq_UDPQueueFindSeq(void *p, va_list data)
98 WORD seq=va_arg(data, int);
99 return icq_PacketReadUDPOutSeq1(((icq_UDPQueueItem *)p)->pack) == seq;
102 void icq_UDPQueueDelSeq(icq_Link *icqlink, WORD seq)
104 icq_UDPQueueItem *ptr;
105 #ifdef QUEUE_DEBUG
106 printf("icq_UDPQueueDelSeq(seq=0x%04X", seq);
107 #endif
108 ptr = icq_ListTraverse(icqlink->d->icq_UDPQueue, icq_UDPQueueFindSeq, seq);
109 if(ptr)
111 #ifdef QUEUE_DEBUG
112 printf(", cmd=0x%04X",icq_PacketReadUDPOutCmd(ptr->pack));
113 #endif
114 icq_ListRemove(icqlink->d->icq_UDPQueue, ptr);
115 _icq_UDPQueueItemFree(ptr);
117 #ifdef QUEUE_DEBUG
118 printf(")\n");
119 #endif
122 void icq_UDPQueueItemResend(icq_UDPQueueItem *p)
124 p->attempts++;
125 if (p->attempts > 6)
127 icq_Disconnect(p->icqlink);
128 invoke_callback(p->icqlink, icq_Disconnected)(p->icqlink);
129 return;
132 icq_UDPSockWriteDirect(p->icqlink, p->pack);