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