Mercurial > pidgin.yaz
annotate plugins/icq/queue.c @ 1432:4c510ca3563f
[gaim-migrate @ 1442]
icqlib 1.1.5
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sun, 28 Jan 2001 01:52:27 +0000 |
parents | 0a766047b4fd |
children | 0ef6603d986e |
rev | line source |
---|---|
1152 | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
3 $Id: queue.c 1442 2001-01-28 01:52:27Z warmenhoven $ |
1152 | 4 $Log$ |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
5 Revision 1.4 2001/01/28 01:52:27 warmenhoven |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
6 icqlib 1.1.5 |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
7 |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
8 Revision 1.12 2000/12/19 06:00:07 bills |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
9 moved members from ICQLINK to ICQLINK_private struct |
1192 | 10 |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
11 Revision 1.11 2000/12/06 05:15:45 denis |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
12 Handling for mass TCP messages has been added based on patch by |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
13 Konstantin Klyagin <konst@konst.org.ua> |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
14 |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
15 Revision 1.10 2000/12/03 21:56:38 bills |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
16 fixed compilation with gcc-2.96 |
1152 | 17 |
18 Revision 1.9 2000/07/10 01:31:17 bills | |
19 oops - removed #define LIST_TRACE and #define QUEUE_DEBUG | |
20 | |
21 Revision 1.8 2000/07/10 01:26:56 bills | |
22 added more trace messages, reworked packet delete handling: now happens | |
23 during _icq_UDEQueueItemFree rather than during icq_UDPQueueDelSeq - fixes | |
24 memory leak | |
25 | |
26 Revision 1.7 2000/07/09 22:07:37 bills | |
27 use new list_free | |
28 | |
29 Revision 1.6 2000/06/25 16:30:05 denis | |
30 Some sanity checks were added to icq_UDPQueueDelete() and | |
31 icq_UDPQueueFree() | |
32 | |
33 Revision 1.5 2000/05/10 19:06:59 denis | |
34 UDP outgoing packet queue was implemented. | |
35 | |
36 Revision 1.4 2000/03/30 14:15:28 denis | |
37 Fixed FreeBSD warning about obsolete malloc.h header. | |
38 | |
39 Revision 1.3 2000/01/16 03:59:10 bills | |
40 reworked list code so list_nodes don't need to be inside item structures, | |
41 removed strlist code and replaced with generic list calls | |
42 | |
43 Revision 1.2 1999/09/29 17:06:47 denis | |
44 ICQLINK compatibility added. | |
45 | |
46 Revision 1.1 1999/07/16 12:12:13 denis | |
47 Initial support for outgoing packet queue added. | |
48 | |
49 */ | |
50 | |
51 #include <stdlib.h> | |
52 #include <time.h> | |
53 | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
54 #include "icqlib.h" |
1152 | 55 #include "queue.h" |
56 #include "list.h" | |
57 | |
58 void icq_UDPQueueNew(ICQLINK *link) | |
59 { | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
60 link->d->icq_UDPQueue = list_new(); |
1152 | 61 link->icq_UDPExpireInterval = 15; /* expire interval = 15 sec */ |
62 } | |
63 | |
64 void icq_UDPQueuePut(ICQLINK *link, icq_Packet *p, int attempt) | |
65 { | |
66 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)malloc(sizeof(icq_UDPQueueItem)); | |
67 #ifdef QUEUE_DEBUG | |
68 printf("icq_UDPQueuePut(seq=0x%04X, cmd=0x%04X)\n", icq_PacketReadUDPOutSeq1(p), | |
69 icq_PacketReadUDPOutCmd(p)); | |
70 #endif | |
71 ptr->attempts = attempt; | |
72 ptr->expire = time(0L)+link->icq_UDPExpireInterval; | |
73 ptr->pack = p; | |
74 #ifdef QUEUE_DEBUG | |
75 printf("enqueuing queueitem %p\n", ptr); | |
76 #endif | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
77 list_enqueue(link->d->icq_UDPQueue, ptr); |
1152 | 78 } |
79 | |
80 icq_Packet *icq_UDPQueueGet(ICQLINK *link) | |
81 { | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
82 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)list_first(link->d->icq_UDPQueue); |
1152 | 83 icq_Packet *pack = 0L; |
84 if(ptr) | |
85 { | |
86 pack = ptr->pack; | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
87 list_remove(link->d->icq_UDPQueue, (list_node*)ptr); |
1152 | 88 } |
89 #ifdef QUEUE_DEBUG | |
90 if(pack) | |
91 printf("icq_UDPQueueGet(cmd=0x%04X)\n", icq_PacketReadUDPOutCmd(pack)); | |
92 #endif | |
93 return pack; | |
94 } | |
95 | |
96 icq_Packet *icq_UDPQueuePeek(ICQLINK *link) | |
97 { | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
98 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)list_first(link->d->icq_UDPQueue); |
1152 | 99 if(ptr) |
100 return ptr->pack; | |
101 else | |
102 return 0L; | |
103 } | |
104 | |
105 void _icq_UDPQueueItemFree(void *p) | |
106 { | |
107 icq_UDPQueueItem *pitem=(icq_UDPQueueItem *)p; | |
108 | |
109 #ifdef QUEUE_DEBUG | |
110 printf("_icq_UDPQueueItemFree(%p)\n", p); | |
111 #endif | |
112 | |
113 if (pitem->pack) | |
114 icq_PacketDelete(pitem->pack); | |
115 | |
116 free(p); | |
117 } | |
118 | |
119 /* Frees the queue and dispose it */ | |
120 void icq_UDPQueueDelete(ICQLINK *link) | |
121 { | |
122 #ifdef QUEUE_DEBUG | |
123 printf("icq_UDPQueueDelete\n"); | |
124 #endif | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
125 if(link->d->icq_UDPQueue) |
1152 | 126 { |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
127 list_delete(link->d->icq_UDPQueue, _icq_UDPQueueItemFree); |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
128 link->d->icq_UDPQueue = 0; |
1152 | 129 } |
130 } | |
131 | |
132 /* Only frees the queue */ | |
133 void icq_UDPQueueFree(ICQLINK *link) | |
134 { | |
135 #ifdef QUEUE_DEBUG | |
136 printf("icq_UDPQueueFree\n"); | |
137 #endif | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
138 if(link->d->icq_UDPQueue) |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
139 list_free(link->d->icq_UDPQueue, _icq_UDPQueueItemFree); |
1152 | 140 } |
141 | |
142 int icq_UDPQueueFindSeq(void *p, va_list data) | |
143 { | |
1192 | 144 WORD seq=va_arg(data, int); |
1152 | 145 return icq_PacketReadUDPOutSeq1(((icq_UDPQueueItem *)p)->pack) == seq; |
146 } | |
147 | |
148 void icq_UDPQueueDelSeq(ICQLINK *link, WORD seq) | |
149 { | |
150 icq_UDPQueueItem *ptr; | |
151 #ifdef QUEUE_DEBUG | |
152 printf("icq_UDPQueueDelSeq(seq=0x%04X", seq); | |
153 #endif | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
154 ptr = list_traverse(link->d->icq_UDPQueue, icq_UDPQueueFindSeq, seq); |
1152 | 155 if(ptr) |
156 { | |
157 #ifdef QUEUE_DEBUG | |
158 printf(", cmd=0x%04X",icq_PacketReadUDPOutCmd(ptr->pack)); | |
159 #endif | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
160 list_remove(link->d->icq_UDPQueue, ptr); |
1152 | 161 _icq_UDPQueueItemFree(ptr); |
162 } | |
163 #ifdef QUEUE_DEBUG | |
164 printf(")\n"); | |
165 #endif | |
166 } | |
167 | |
168 long icq_UDPQueueInterval(ICQLINK *link) | |
169 { | |
170 long interval; | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1192
diff
changeset
|
171 icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)list_first(link->d->icq_UDPQueue); |
1152 | 172 if(ptr) |
173 { | |
174 interval = ptr->expire - time(0L); | |
175 return interval>=0?interval:0; | |
176 } | |
177 return -1; | |
178 } |