Mercurial > pidgin
annotate plugins/icq/queue.c @ 1971:7fbd745756c0
[gaim-migrate @ 1981]
i thought i fixed this already
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Thu, 07 Jun 2001 07:36:03 +0000 |
parents | 8ed70631ed15 |
children | 7b3f1eb1ef7d |
rev | line source |
---|---|
1152 | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
3 /* |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
4 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
5 * Bill Soudan <soudan@kde.org> |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
6 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
7 * This program is free software; you can redistribute it and/or modify |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
9 * the Free Software Foundation; either version 2 of the License, or |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
10 * (at your option) any later version. |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
11 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
15 * GNU General Public License for more details. |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
16 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
17 * You should have received a copy of the GNU General Public License |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
18 * along with this program; if not, write to the Free Software |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
20 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
21 */ |
1152 | 22 |
23 #include <stdlib.h> | |
24 | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
25 #include "icqlib.h" |
1152 | 26 #include "queue.h" |
27 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
28 void icq_UDPQueueNew(icq_Link *icqlink) |
1152 | 29 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
30 icqlink->d->icq_UDPQueue = icq_ListNew(); |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
31 icqlink->icq_UDPExpireInterval = 15; /* expire interval = 15 sec */ |
1152 | 32 } |
33 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
34 void icq_UDPQueuePut(icq_Link *icqlink, icq_Packet *p) |
1152 | 35 { |
36 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)malloc(sizeof(icq_UDPQueueItem)); | |
37 #ifdef QUEUE_DEBUG | |
38 printf("icq_UDPQueuePut(seq=0x%04X, cmd=0x%04X)\n", icq_PacketReadUDPOutSeq1(p), | |
39 icq_PacketReadUDPOutCmd(p)); | |
40 #endif | |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
41 ptr->attempts = 1; |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
42 ptr->timeout = icq_TimeoutNew(icqlink->icq_UDPExpireInterval, |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
43 (icq_TimeoutHandler)icq_UDPQueueItemResend, ptr); |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
44 ptr->timeout->single_shot = 0; |
1152 | 45 ptr->pack = p; |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
46 ptr->icqlink = icqlink; |
1152 | 47 #ifdef QUEUE_DEBUG |
48 printf("enqueuing queueitem %p\n", ptr); | |
49 #endif | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
50 icq_ListEnqueue(icqlink->d->icq_UDPQueue, ptr); |
1152 | 51 } |
52 | |
53 void _icq_UDPQueueItemFree(void *p) | |
54 { | |
55 icq_UDPQueueItem *pitem=(icq_UDPQueueItem *)p; | |
56 | |
57 #ifdef QUEUE_DEBUG | |
58 printf("_icq_UDPQueueItemFree(%p)\n", p); | |
59 #endif | |
60 | |
61 if (pitem->pack) | |
62 icq_PacketDelete(pitem->pack); | |
63 | |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
64 if (pitem->timeout) |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
65 icq_TimeoutDelete(pitem->timeout); |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
66 |
1152 | 67 free(p); |
68 } | |
69 | |
70 /* Frees the queue and dispose it */ | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
71 void icq_UDPQueueDelete(icq_Link *icqlink) |
1152 | 72 { |
73 #ifdef QUEUE_DEBUG | |
74 printf("icq_UDPQueueDelete\n"); | |
75 #endif | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
76 if(icqlink->d->icq_UDPQueue) |
1152 | 77 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
78 icq_ListDelete(icqlink->d->icq_UDPQueue, _icq_UDPQueueItemFree); |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
79 icqlink->d->icq_UDPQueue = 0; |
1152 | 80 } |
81 } | |
82 | |
83 /* Only frees the queue */ | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
84 void icq_UDPQueueFree(icq_Link *icqlink) |
1152 | 85 { |
86 #ifdef QUEUE_DEBUG | |
87 printf("icq_UDPQueueFree\n"); | |
88 #endif | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
89 if(icqlink->d->icq_UDPQueue) |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
90 icq_ListFree(icqlink->d->icq_UDPQueue, _icq_UDPQueueItemFree); |
1152 | 91 } |
92 | |
93 int icq_UDPQueueFindSeq(void *p, va_list data) | |
94 { | |
1192 | 95 WORD seq=va_arg(data, int); |
1152 | 96 return icq_PacketReadUDPOutSeq1(((icq_UDPQueueItem *)p)->pack) == seq; |
97 } | |
98 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
99 void icq_UDPQueueDelSeq(icq_Link *icqlink, WORD seq) |
1152 | 100 { |
101 icq_UDPQueueItem *ptr; | |
102 #ifdef QUEUE_DEBUG | |
103 printf("icq_UDPQueueDelSeq(seq=0x%04X", seq); | |
104 #endif | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
105 ptr = icq_ListTraverse(icqlink->d->icq_UDPQueue, icq_UDPQueueFindSeq, seq); |
1152 | 106 if(ptr) |
107 { | |
108 #ifdef QUEUE_DEBUG | |
109 printf(", cmd=0x%04X",icq_PacketReadUDPOutCmd(ptr->pack)); | |
110 #endif | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1498
diff
changeset
|
111 icq_ListRemove(icqlink->d->icq_UDPQueue, ptr); |
1152 | 112 _icq_UDPQueueItemFree(ptr); |
113 } | |
114 #ifdef QUEUE_DEBUG | |
115 printf(")\n"); | |
116 #endif | |
117 } | |
118 | |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
119 void icq_UDPQueueItemResend(icq_UDPQueueItem *p) |
1152 | 120 { |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
121 p->attempts++; |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
122 if (p->attempts > 6) |
1152 | 123 { |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
124 icq_Disconnect(p->icqlink); |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
125 invoke_callback(p->icqlink, icq_Disconnected)(p->icqlink); |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
126 return; |
1152 | 127 } |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
128 |
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
129 icq_UDPSockWriteDirect(p->icqlink, p->pack); |
1152 | 130 } |
1498
0ef6603d986e
[gaim-migrate @ 1508]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
131 |