Tue, 31 Jul 2001 01:00:39 +0000
[gaim-migrate @ 2096]
moving protocols from plugins/ to src/protocols. making it so that you can select which protocols are compiled statically.
| 2086 | 1 | /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 | ||
| 3 | /* | |
| 4 | * $Id: queue.c 2096 2001-07-31 01:00:39Z warmenhoven $ | |
| 5 | * | |
| 6 | * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and | |
| 7 | * Bill Soudan <soudan@kde.org> | |
| 8 | * | |
| 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. | |
| 13 | * | |
| 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. | |
| 18 | * | |
| 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. | |
| 22 | * | |
| 23 | */ | |
| 24 | ||
| 25 | #include <stdlib.h> | |
| 26 | ||
| 27 | #include "icqlib.h" | |
| 28 | #include "queue.h" | |
| 29 | ||
| 30 | void icq_UDPQueueNew(icq_Link *icqlink) | |
| 31 | { | |
| 32 | icqlink->d->icq_UDPQueue = icq_ListNew(); | |
| 33 | icqlink->icq_UDPExpireInterval = 15; /* expire interval = 15 sec */ | |
| 34 | } | |
| 35 | ||
| 36 | void icq_UDPQueuePut(icq_Link *icqlink, icq_Packet *p) | |
| 37 | { | |
| 38 | icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)malloc(sizeof(icq_UDPQueueItem)); | |
| 39 | #ifdef QUEUE_DEBUG | |
| 40 | printf("icq_UDPQueuePut(seq=0x%04X, cmd=0x%04X)\n", icq_PacketReadUDPOutSeq1(p), | |
| 41 | icq_PacketReadUDPOutCmd(p)); | |
| 42 | #endif | |
| 43 | ptr->attempts = 1; | |
| 44 | ptr->timeout = icq_TimeoutNew(icqlink->icq_UDPExpireInterval, | |
| 45 | (icq_TimeoutHandler)icq_UDPQueueItemResend, ptr); | |
| 46 | ptr->timeout->single_shot = 0; | |
| 47 | ptr->pack = p; | |
| 48 | ptr->icqlink = icqlink; | |
| 49 | #ifdef QUEUE_DEBUG | |
| 50 | printf("enqueuing queueitem %p\n", ptr); | |
| 51 | #endif | |
| 52 | icq_ListEnqueue(icqlink->d->icq_UDPQueue, ptr); | |
| 53 | } | |
| 54 | ||
| 55 | void _icq_UDPQueueItemFree(void *p) | |
| 56 | { | |
| 57 | icq_UDPQueueItem *pitem=(icq_UDPQueueItem *)p; | |
| 58 | ||
| 59 | #ifdef QUEUE_DEBUG | |
| 60 | printf("_icq_UDPQueueItemFree(%p)\n", p); | |
| 61 | #endif | |
| 62 | ||
| 63 | if (pitem->pack) | |
| 64 | icq_PacketDelete(pitem->pack); | |
| 65 | ||
| 66 | if (pitem->timeout) | |
| 67 | icq_TimeoutDelete(pitem->timeout); | |
| 68 | ||
| 69 | free(p); | |
| 70 | } | |
| 71 | ||
| 72 | /* Frees the queue and dispose it */ | |
| 73 | void icq_UDPQueueDelete(icq_Link *icqlink) | |
| 74 | { | |
| 75 | #ifdef QUEUE_DEBUG | |
| 76 | printf("icq_UDPQueueDelete\n"); | |
| 77 | #endif | |
| 78 | if(icqlink->d->icq_UDPQueue) | |
| 79 | { | |
| 80 | icq_ListDelete(icqlink->d->icq_UDPQueue, _icq_UDPQueueItemFree); | |
| 81 | icqlink->d->icq_UDPQueue = 0; | |
| 82 | } | |
| 83 | } | |
| 84 | ||
| 85 | /* Only frees the queue */ | |
| 86 | void icq_UDPQueueFree(icq_Link *icqlink) | |
| 87 | { | |
| 88 | #ifdef QUEUE_DEBUG | |
| 89 | printf("icq_UDPQueueFree\n"); | |
| 90 | #endif | |
| 91 | if(icqlink->d->icq_UDPQueue) | |
| 92 | icq_ListFree(icqlink->d->icq_UDPQueue, _icq_UDPQueueItemFree); | |
| 93 | } | |
| 94 | ||
| 95 | int icq_UDPQueueFindSeq(void *p, va_list data) | |
| 96 | { | |
| 97 | WORD seq=va_arg(data, int); | |
| 98 | return icq_PacketReadUDPOutSeq1(((icq_UDPQueueItem *)p)->pack) == seq; | |
| 99 | } | |
| 100 | ||
| 101 | void icq_UDPQueueDelSeq(icq_Link *icqlink, WORD seq) | |
| 102 | { | |
| 103 | icq_UDPQueueItem *ptr; | |
| 104 | #ifdef QUEUE_DEBUG | |
| 105 | printf("icq_UDPQueueDelSeq(seq=0x%04X", seq); | |
| 106 | #endif | |
| 107 | ptr = icq_ListTraverse(icqlink->d->icq_UDPQueue, icq_UDPQueueFindSeq, seq); | |
| 108 | if(ptr) | |
| 109 | { | |
| 110 | #ifdef QUEUE_DEBUG | |
| 111 | printf(", cmd=0x%04X",icq_PacketReadUDPOutCmd(ptr->pack)); | |
| 112 | #endif | |
| 113 | icq_ListRemove(icqlink->d->icq_UDPQueue, ptr); | |
| 114 | _icq_UDPQueueItemFree(ptr); | |
| 115 | } | |
| 116 | #ifdef QUEUE_DEBUG | |
| 117 | printf(")\n"); | |
| 118 | #endif | |
| 119 | } | |
| 120 | ||
| 121 | void icq_UDPQueueItemResend(icq_UDPQueueItem *p) | |
| 122 | { | |
| 123 | p->attempts++; | |
| 124 | if (p->attempts > 6) | |
| 125 | { | |
| 126 | icq_Disconnect(p->icqlink); | |
| 127 | invoke_callback(p->icqlink, icq_Disconnected)(p->icqlink); | |
| 128 | return; | |
| 129 | } | |
| 130 | ||
| 131 | icq_UDPSockWriteDirect(p->icqlink, p->pack); | |
| 132 | } | |
| 133 |