changeset 1912:8ed70631ed15

[gaim-migrate @ 1922] new icqlib committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Tue, 29 May 2001 10:32:53 +0000
parents db3104dda736
children b1e1829bef22
files plugins/icq/chatsession.c plugins/icq/chatsession.h plugins/icq/contacts.c plugins/icq/contacts.h plugins/icq/cyrillic.c plugins/icq/eventhandle.c plugins/icq/eventhandle.h plugins/icq/filesession.c plugins/icq/filesession.h plugins/icq/gaim_icq.c plugins/icq/icq.h plugins/icq/icqbyteorder.c plugins/icq/icqbyteorder.h plugins/icq/icqevent.c plugins/icq/icqevent.h plugins/icq/icqlib.c plugins/icq/icqlib.h plugins/icq/icqpacket.c plugins/icq/icqpacket.h plugins/icq/icqtypes.h plugins/icq/list.c plugins/icq/list.h plugins/icq/proxy.c plugins/icq/queue.c plugins/icq/queue.h plugins/icq/socketmanager.c plugins/icq/socketmanager.h plugins/icq/stdpackets.c plugins/icq/stdpackets.h plugins/icq/tcp.c plugins/icq/tcp.h plugins/icq/tcpchathandle.c plugins/icq/tcpfilehandle.c plugins/icq/tcphandle.c plugins/icq/tcplink.c plugins/icq/tcplink.h plugins/icq/timeout.c plugins/icq/timeout.h plugins/icq/udp.c plugins/icq/udp.h plugins/icq/udphandle.c plugins/icq/util.c plugins/icq/util.h
diffstat 43 files changed, 2119 insertions(+), 2554 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/icq/chatsession.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/chatsession.c	Tue May 29 10:32:53 2001 +0000
@@ -1,13 +1,33 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #include <stdlib.h>
 
-#include "icq.h"
 #include "icqlib.h"
-#include "tcplink.h"
+#include "tcp.h"
+
 #include "chatsession.h"
-#include "list.h"
 
-icq_ChatSession *icq_ChatSessionNew(ICQLINK *icqlink) 
+icq_ChatSession *icq_ChatSessionNew(icq_Link *icqlink) 
 {
   icq_ChatSession *p=(icq_ChatSession *)malloc(sizeof(icq_ChatSession));
 
@@ -18,7 +38,7 @@
     p->icqlink=icqlink;
     p->tcplink=NULL;
     p->user_data=NULL;
-    list_insert(icqlink->d->icq_ChatSessions, 0, p);
+    icq_ListInsert(icqlink->d->icq_ChatSessions, 0, p);
   }
 	
   return p;
@@ -39,9 +59,9 @@
   return (((icq_ChatSession *)p)->remote_uin == uin);
 }
 
-icq_ChatSession *icq_FindChatSession(ICQLINK *icqlink, DWORD uin)
+icq_ChatSession *icq_FindChatSession(icq_Link *icqlink, DWORD uin)
 {
-  return list_traverse(icqlink->d->icq_ChatSessions,
+  return icq_ListTraverse(icqlink->d->icq_ChatSessions,
     _icq_FindChatSession, uin);
 }
 
@@ -61,19 +81,19 @@
  */
 void icq_ChatSessionClose(icq_ChatSession *session)
 {
-  icq_TCPLink *plink = session->tcplink;
+  icq_TCPLink *tcplink = session->tcplink;
 
   /* if we're attached to a tcplink, unattach so the link doesn't try
    * to close us, and then close the tcplink */
-  if (plink)
+  if (tcplink)
   {
-    plink->session=NULL;
-    icq_TCPLinkClose(plink);
+    tcplink->session=NULL;
+    icq_TCPLinkClose(tcplink);
   }
   
   icq_ChatSessionDelete(session);
 
-  list_remove(session->icqlink->d->icq_ChatSessions, session);
+  icq_ListRemove(session->icqlink->d->icq_ChatSessions, session);
 }
 
 /** Sends chat data to the remote uin.
@@ -83,18 +103,18 @@
  */
 void icq_ChatSessionSendData(icq_ChatSession *session, const char *data)
 {
-  icq_TCPLink *plink = session->tcplink;
+  icq_TCPLink *tcplink = session->tcplink;
   int data_length = strlen(data);
   char *buffer;
 
-  if(!plink)
+  if(!tcplink)
     return;
 
   buffer = (char *)malloc(data_length);
   strcpy(buffer, data);
   icq_ChatRusConv_n("kw", buffer, data_length);
   
-  send(plink->socket, buffer, data_length, 0);  
+  send(tcplink->socket, buffer, data_length, 0);  
   
   free(buffer);
 }
@@ -108,17 +128,17 @@
 void icq_ChatSessionSendData_n(icq_ChatSession *session, const char *data,
   int length)
 {
-  icq_TCPLink *plink = session->tcplink;
+  icq_TCPLink *tcplink = session->tcplink;
   char *buffer;
 
-  if(!plink)
+  if(!tcplink)
     return;
   
   buffer = (char *)malloc(length);
   memcpy(buffer, data, length);
   icq_ChatRusConv_n("kw", buffer, length);
     
-  send(plink->socket, buffer, length, 0);
+  send(tcplink->socket, buffer, length, 0);
 
   free(buffer);
 }
--- a/plugins/icq/chatsession.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/chatsession.h	Tue May 29 10:32:53 2001 +0000
@@ -1,3 +1,24 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #ifndef _CHAT_SESSION_H
 #define _CHAT_SESSION_H
@@ -47,9 +68,9 @@
 			ICQ_NOTIFY_SUCCESS
 */
 
-icq_ChatSession *icq_ChatSessionNew(ICQLINK *);
+icq_ChatSession *icq_ChatSessionNew(icq_Link *);
 void icq_ChatSessionDelete(void *);
 void icq_ChatSessionSetStatus(icq_ChatSession *, int);
-icq_ChatSession *icq_FindChatSession(ICQLINK *, DWORD);
+icq_ChatSession *icq_FindChatSession(icq_Link *, DWORD);
 
 #endif
--- a/plugins/icq/contacts.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/contacts.c	Tue May 29 10:32:53 2001 +0000
@@ -1,50 +1,38 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: contacts.c 1442 2001-01-28 01:52:27Z warmenhoven $
-$Log$
-Revision 1.3  2001/01/28 01:52:27  warmenhoven
-icqlib 1.1.5
-
-Revision 1.6  2001/01/16 00:10:13  denis
-Invisible list has been finished.
-
-Revision 1.5  2000/12/19 06:00:07  bills
-moved members from ICQLINK to ICQLINK_private struct
 
-Revision 1.4  2000/06/17 16:38:45  denis
-New parameter was added in icq_ContactSetVis() for setting/resetting
-'Visible to User' status.
-Port's type was changed to unsigned short in icq_UserOnline callback.
-
-Revision 1.3  2000/01/16 03:59:10  bills
-reworked list code so list_nodes don't need to be inside item structures,
-removed strlist code and replaced with generic list calls
-
-Revision 1.2  1999/07/23 12:28:00  denis
-Cleaned up.
-
-Revision 1.1  1999/07/18 20:11:48  bills
-added
-
-*/
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #include <stdlib.h>
-#include <stdarg.h>
 
-#include "icq.h"
 #include "icqlib.h"
-#include "icqtypes.h"
-#include "util.h"
-#include "list.h"
+
 #include "contacts.h"
 
-icq_ContactItem *icq_ContactNew(ICQLINK *link)
+icq_ContactItem *icq_ContactNew(icq_Link *icqlink)
 {
   icq_ContactItem *pcontact=
     (icq_ContactItem *)malloc(sizeof(icq_ContactItem));
 
   if(pcontact)
-    pcontact->icqlink=link;
+    pcontact->icqlink=icqlink;
 
   return pcontact;
 }
@@ -54,30 +42,30 @@
   free(p);
 }
 
-void icq_ContactAdd(ICQLINK *link, DWORD cuin)
+void icq_ContactAdd(icq_Link *icqlink, DWORD cuin)
 {
-  icq_ContactItem *p = icq_ContactNew(link);
+  icq_ContactItem *p = icq_ContactNew(icqlink);
   p->uin = cuin;
   p->vis_list = FALSE;
 
-  list_enqueue(link->d->icq_ContactList, p);
+  icq_ListEnqueue(icqlink->d->icq_ContactList, p);
 }
 
-void icq_ContactRemove(ICQLINK *link, DWORD cuin)
+void icq_ContactRemove(icq_Link *icqlink, DWORD cuin)
 {
-  icq_ContactItem *pcontact=icq_ContactFind(link, cuin);
+  icq_ContactItem *pcontact=icq_ContactFind(icqlink, cuin);
 
   if (pcontact)
   {
-    list_remove(link->d->icq_ContactList, pcontact);
+    icq_ListRemove(icqlink->d->icq_ContactList, pcontact);
     icq_ContactDelete(pcontact);
   }
 }
 
-void icq_ContactClear(ICQLINK *link)
+void icq_ContactClear(icq_Link *icqlink)
 {
-  list_delete(link->d->icq_ContactList, icq_ContactDelete);
-  link->d->icq_ContactList=list_new();
+  icq_ListDelete(icqlink->d->icq_ContactList, icq_ContactDelete);
+  icqlink->d->icq_ContactList=icq_ListNew();
 }
 
 int _icq_ContactFind(void *p, va_list data)
@@ -87,33 +75,33 @@
   return (((icq_ContactItem *)p)->uin == uin);
 }
 
-icq_ContactItem *icq_ContactFind(ICQLINK *link, DWORD cuin)
+icq_ContactItem *icq_ContactFind(icq_Link *icqlink, DWORD cuin)
 {
-  return list_traverse(link->d->icq_ContactList, _icq_ContactFind, cuin);
+  return icq_ListTraverse(icqlink->d->icq_ContactList, _icq_ContactFind, cuin);
 }
 
-void icq_ContactSetVis(ICQLINK *link, DWORD cuin, BYTE vu)
+void icq_ContactSetVis(icq_Link *icqlink, DWORD cuin, BYTE vu)
 {
-  icq_ContactItem *p = icq_ContactFind(link, cuin);
+  icq_ContactItem *p = icq_ContactFind(icqlink, cuin);
   if(p)
     p->vis_list = vu;
 }
 
-void icq_ContactSetInvis(ICQLINK *link, DWORD cuin, BYTE vu)
+void icq_ContactSetInvis(icq_Link *icqlink, DWORD cuin, BYTE vu)
 {
-  icq_ContactItem *p = icq_ContactFind(link, cuin);
+  icq_ContactItem *p = icq_ContactFind(icqlink, cuin);
   if(p)
     p->invis_list = vu;
 }
 
-icq_ContactItem *icq_ContactGetFirst(ICQLINK *link)
+icq_ContactItem *icq_ContactGetFirst(icq_Link *icqlink)
 {
-  return list_first(link->d->icq_ContactList);
+  return icq_ListFirst(icqlink->d->icq_ContactList);
 }
 
 icq_ContactItem *icq_ContactGetNext(icq_ContactItem *pcontact)
 {
-  list_node *p=list_find(pcontact->icqlink->d->icq_ContactList, pcontact);
+  icq_ListNode *p=icq_ListFind(pcontact->icqlink->d->icq_ContactList, pcontact);
 
   if (p && p->next)
     return p->next->item;
--- a/plugins/icq/contacts.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/contacts.h	Tue May 29 10:32:53 2001 +0000
@@ -1,4 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _CONTACTS_H
 #define _CONTACTS_H
 
@@ -7,7 +28,7 @@
 
 typedef struct icq_ContactItem_s
 {
-  ICQLINK *icqlink;
+  icq_Link *icqlink;
   unsigned long uin;
   int vis_list;
   int invis_list;
@@ -17,10 +38,10 @@
   unsigned char tcp_flag;
 } icq_ContactItem;  
 
-icq_ContactItem *icq_ContactNew(ICQLINK *link);
+icq_ContactItem *icq_ContactNew(icq_Link *icqlink);
 void icq_ContactDelete(void *pcontact);
-icq_ContactItem *icq_ContactFind(ICQLINK *link, DWORD cuin);
-icq_ContactItem *icq_ContactGetFirst(ICQLINK *link);
+icq_ContactItem *icq_ContactFind(icq_Link *icqlink, DWORD cuin);
+icq_ContactItem *icq_ContactGetFirst(icq_Link *icqlink);
 icq_ContactItem *icq_ContactGetNext(icq_ContactItem *pcontact);
 
 #endif /* _CONTACTS_H */
--- a/plugins/icq/cyrillic.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/cyrillic.c	Tue May 29 10:32:53 2001 +0000
@@ -1,49 +1,32 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: cyrillic.c 1442 2001-01-28 01:52:27Z warmenhoven $
-$Log$
-Revision 1.3  2001/01/28 01:52:27  warmenhoven
-icqlib 1.1.5
-
-Revision 1.7  2000/05/21 17:41:14  denis
-Applied patch for russian letters IO and io by
-Vladimir Eltchinov <elik@design.ru>
-
-Revision 1.6  2000/02/07 02:31:37  bills
-added icq_RusConv_n
-
-Revision 1.5  1999/09/29 16:45:26  denis
-Cleanups
 
-Revision 1.4  1999/07/16 12:08:20  denis
-Cleaned up.
-
-Revision 1.3  1999/07/12 15:13:29  cproch
-- added definition of ICQLINK to hold session-specific global variabled
-  applications which have more than one connection are now possible
-- changed nearly every function defintion to support ICQLINK parameter
-
-Revision 1.2  1999/04/14 14:44:30  denis
-Switched from icq_Log callback to icq_FmtLog function.
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
-Revision 1.1  1999/03/24 11:37:35  denis
-Underscored files with TCP stuff renamed.
-TCP stuff cleaned up
-Function names changed to corresponding names.
-icqlib.c splitted to many small files by subject.
-C++ comments changed to ANSI C comments.
-
-*/
-
-#include "icqtypes.h"
 #include "icq.h"
 #include "icqlib.h"
-#include "util.h"
 
 BYTE kw[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
-             160,161,162,184,164,165,166,167,168,169,170,171,172,173,174,175,
-             176,177,178,168,180,181,182,183,184,185,186,187,188,189,190,191,
+             160,161,162,184,186,165,179,191,168,169,170,171,172,180,174,175,
+             176,177,178,168,170,181,178,175,184,185,170,187,188,165,190,169,
              254,224,225,246,228,229,244,227,245,232,233,234,235,236,237,238,
              239,255,240,241,242,243,230,226,252,251,231,248,253,249,247,250,
              222,192,193,214,196,197,212,195,213,200,201,202,203,204,205,206,
@@ -51,8 +34,8 @@
 
 BYTE wk[] = {128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
              144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
-             160,161,162,163,164,165,166,167,179,169,170,171,172,173,174,175,
-             176,177,178,179,180,181,182,183,163,185,186,187,188,189,190,191,
+             160,161,162,163,164,189,166,167,179,191,180,171,172,173,174,183,
+             176,177,182,166,173,181,182,183,163,185,164,187,188,189,190,167,
              225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,
              242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241,
              193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,
--- a/plugins/icq/eventhandle.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/eventhandle.c	Tue May 29 10:32:53 2001 +0000
@@ -1,19 +1,24 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
-/* 
- * $Id: eventhandle.c 1442 2001-01-28 01:52:27Z warmenhoven $
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
  *
- * $Log$
- * Revision 1.2  2001/01/28 01:52:27  warmenhoven
- * icqlib 1.1.5
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * Revision 1.3  2000/12/19 06:00:07  bills
- * moved members from ICQLINK to ICQLINK_private struct
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * Revision 1.1  2000/06/15 18:50:03  bills
- * committed for safekeeping - this code will soon replace tcphandle.c 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
-*/
+ */
 
 #include <time.h>
 
@@ -29,14 +34,14 @@
 
 #include "eventhandle.h"
 
-void icq_TCPProcessPacket2(icq_Packet *p, icq_TCPLink *plink)
+void icq_TCPProcessPacket2(icq_Packet *p, icq_TCPLink *tcplink)
 {
   icq_MessageEvent *pevent=(icq_MessageEvent *)icq_ParsePacket(p);
   icq_Event *pbase=(icq_Event *)pevent;
 
-  ICQLINK *icqlink=plink->icqlink;
+  icq_Link *icqlink=tcplink->icqlink;
 
-  if (pbase->uin != plink->remote_uin)
+  if (pbase->uin != tcplink->remote_uin)
   {
     /* TODO: spoofed packet! */
   }
@@ -46,7 +51,7 @@
   /* notify library client than the ack was received from remote client */
   if (pbase->subtype==ICQ_EVENT_ACK)
   {
-    icq_FmtLog(plink->icqlink, ICQ_LOG_MESSAGE, "received ack %d\n", p->id);
+    icq_FmtLog(tcplink->icqlink, ICQ_LOG_MESSAGE, "received ack %d\n", p->id);
     if(icqlink->icq_RequestNotify)
     {
       (*icqlink->icq_RequestNotify)(icqlink, pbase->id,
@@ -57,7 +62,7 @@
   }    
 }
 
-void icq_HandleMessageEvent(icq_Event *pbase, ICQLINK *icqlink)
+void icq_HandleMessageEvent(icq_Event *pbase, icq_Link *icqlink)
 {
   icq_MessageEvent *pevent=(icq_MessageEvent *)pbase;
   struct tm *ptime=localtime(&(pbase->time));
@@ -72,7 +77,7 @@
 
 }
 
-void icq_HandleURLEvent(icq_Event *pbase, ICQLINK *icqlink) 
+void icq_HandleURLEvent(icq_Event *pbase, icq_Link *icqlink) 
 {
   icq_URLEvent *pevent=(icq_URLEvent *)pbase;
   struct tm *ptime=localtime(&(pbase->time));
@@ -86,7 +91,7 @@
   }
 }
 
-void icq_HandleChatRequestEvent(icq_Event *pbase, ICQLINK *icqlink)
+void icq_HandleChatRequestEvent(icq_Event *pbase, icq_Link *icqlink)
 {
   icq_ChatRequestEvent *pevent=(icq_ChatRequestEvent *)pbase;
   icq_MessageEvent *pmsgevent=(icq_MessageEvent *)pmsgevent;
@@ -116,7 +121,7 @@
   }
 }
 
-void icq_HandleChatRequestAck(icq_Event *pbase, ICQLINK *icqlink)
+void icq_HandleChatRequestAck(icq_Event *pbase, icq_Link *icqlink)
 {
   icq_ChatRequestEvent *pevent=(icq_ChatRequestEvent *)pbase;
   icq_TCPLink *pchatlink;
@@ -151,7 +156,7 @@
 }
 
 
-void icq_HandleFileRequestEvent(icq_Event *pbase, ICQLINK *icqlink)
+void icq_HandleFileRequestEvent(icq_Event *pbase, icq_Link *icqlink)
 {
   icq_FileRequestEvent *pevent=(icq_FileRequestEvent *)pbase;
   icq_MessageEvent *pmsgevent=(icq_MessageEvent *)pmsgevent;
@@ -180,7 +185,7 @@
   }
 }
 
-void icq_HandleFileRequestAck(icq_Event *pbase, ICQLINK *icqlink)
+void icq_HandleFileRequestAck(icq_Event *pbase, icq_Link *icqlink)
 {
   icq_FileRequestEvent *pevent=(icq_FileRequestEvent *)pbase;
   icq_TCPLink *pfilelink;
--- a/plugins/icq/eventhandle.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/eventhandle.h	Tue May 29 10:32:53 2001 +0000
@@ -1,16 +1,24 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
 /*
- * $Id: eventhandle.h 1442 2001-01-28 01:52:27Z warmenhoven $
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * $Log$
- * Revision 1.2  2001/01/28 01:52:27  warmenhoven
- * icqlib 1.1.5
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * Revision 1.1  2000/06/15 18:50:03  bills
- * committed for safekeeping - this code will soon replace tcphandle.c
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
-*/
+ */
 
 #ifndef _EVENTHANDLE_H
 #define _EVENTHANDLE_H
@@ -19,12 +27,12 @@
 #include <config.h>
 #endif
 
-void icq_HandleMessageEvent(icq_Event *pevent, ICQLINK *icqlink);
-void icq_HandleURLEvent(icq_Event *pevent, ICQLINK *icqlink);
-void icq_HandleChatRequestEvent(icq_Event *base, ICQLINK *icqlink);
-void icq_HandleFileRequestEvent(icq_Event *base, ICQLINK *icqlink);
+void icq_HandleMessageEvent(icq_Event *pevent, icq_Link *icqlink);
+void icq_HandleURLEvent(icq_Event *pevent, icq_Link *icqlink);
+void icq_HandleChatRequestEvent(icq_Event *base, icq_Link *icqlink);
+void icq_HandleFileRequestEvent(icq_Event *base, icq_Link *icqlink);
 
-void icq_HandleChatRequestAck(icq_Event *pevent, ICQLINK *icqlink);
-void icq_HandleFileRequestAck(icq_Event *pevent, ICQLINK *icqlink);
+void icq_HandleChatRequestAck(icq_Event *pevent, icq_Link *icqlink);
+void icq_HandleFileRequestAck(icq_Event *pevent, icq_Link *icqlink);
 
 #endif /* _EVENTHANDLE_H */
--- a/plugins/icq/filesession.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/filesession.c	Tue May 29 10:32:53 2001 +0000
@@ -1,7 +1,27 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #include <stdlib.h>
 #include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
 #include <sys/stat.h>
 
 #ifdef _MSVC_
@@ -14,11 +34,9 @@
 
 #include "icqlib.h"
 #include "filesession.h"
-#include "list.h"
-#include "icqpacket.h"
 #include "stdpackets.h"
 
-icq_FileSession *icq_FileSessionNew(ICQLINK *icqlink)
+icq_FileSession *icq_FileSessionNew(icq_Link *icqlink)
 {
   icq_FileSession *p=(icq_FileSession *)malloc(sizeof(icq_FileSession));
 
@@ -39,7 +57,7 @@
     p->total_transferred_bytes=0;
     p->working_dir[0]=0;
     p->user_data=NULL;
-    list_insert(icqlink->d->icq_FileSessions, 0, p);
+    icq_ListInsert(icqlink->d->icq_FileSessions, 0, p);
   }
 	
   return p;
@@ -77,10 +95,10 @@
 
 }
 
-icq_FileSession *icq_FindFileSession(ICQLINK *icqlink, DWORD uin,
+icq_FileSession *icq_FindFileSession(icq_Link *icqlink, DWORD uin,
   unsigned long id)
 {
-  return list_traverse(icqlink->d->icq_FileSessions, _icq_FindFileSession, 
+  return icq_ListTraverse(icqlink->d->icq_FileSessions, _icq_FindFileSession, 
     uin, id);
 }
 
@@ -228,7 +246,7 @@
 
   icq_FileSessionDelete(p);
 
-  list_remove(p->icqlink->d->icq_FileSessions, p);		
+  icq_ListRemove(p->icqlink->d->icq_FileSessions, p);		
 }   
 
 void icq_FileSessionSetWorkingDir(icq_FileSession *p, const char *dir)
--- a/plugins/icq/filesession.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/filesession.h	Tue May 29 10:32:53 2001 +0000
@@ -1,3 +1,24 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #ifndef _FILE_SESSION_H
 #define _FILE_SESSION_H
@@ -5,10 +26,10 @@
 #include "icq.h"
 #include "icqtypes.h"
 
-icq_FileSession *icq_FileSessionNew(ICQLINK *);
+icq_FileSession *icq_FileSessionNew(icq_Link *);
 void icq_FileSessionDelete(void *);
 void icq_FileSessionSetStatus(icq_FileSession *, int);
-icq_FileSession *icq_FindFileSession(ICQLINK *, unsigned long, unsigned long);
+icq_FileSession *icq_FindFileSession(icq_Link *, unsigned long, unsigned long);
 void icq_FileSessionSetHandle(icq_FileSession *, const char *);
 void icq_FileSessionSetCurrentFile(icq_FileSession *, const char *);
 void icq_FileSessionPrepareNextFile(icq_FileSession *);
--- a/plugins/icq/gaim_icq.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/gaim_icq.c	Tue May 29 10:32:53 2001 +0000
@@ -17,14 +17,14 @@
 #define USEROPT_NICK 0
 
 struct icq_data {
-	ICQLINK *link;
+	icq_Link *link;
 	int cur_status;
 	GSList *thru_serv;
 };
 
 static guint ack_timer = 0;
 
-static struct gaim_connection *find_gaim_conn_by_icq_link(ICQLINK *link) {
+static struct gaim_connection *find_gaim_conn_by_icq_link(icq_Link *link) {
 	GSList *c = connections;
 	struct gaim_connection *gc = NULL;
 	struct icq_data *id;
@@ -47,7 +47,7 @@
 	return "ICQ";
 }
 
-static void icq_do_log(ICQLINK *link, time_t time, unsigned char level, const char *log) {
+static void icq_do_log(icq_Link *link, time_t time, unsigned char level, const char *log) {
 	debug_printf("ICQ debug %d: %s", level, log);
 }
 
@@ -96,7 +96,7 @@
 	}
 }
 
-static void icq_online(ICQLINK *link) {
+static void icq_online(icq_Link *link) {
 	struct gaim_connection *gc = find_gaim_conn_by_icq_link(link);
 	struct icq_data *id = (struct icq_data *)gc->proto_data;
 	debug_printf("%s is now online.\n", gc->username);
@@ -107,7 +107,7 @@
 	icq_ChangeStatus(id->link, STATUS_ONLINE);
 }
 
-static void icq_logged_off(ICQLINK *link) {
+static void icq_logged_off(icq_Link *link) {
 	struct gaim_connection *gc = find_gaim_conn_by_icq_link(link);
 	struct icq_data *id = (struct icq_data *)gc->proto_data;
 
@@ -121,7 +121,7 @@
 	id->cur_status = STATUS_ONLINE;
 }
 
-static void icq_msg_incoming(ICQLINK *link, unsigned long uin, unsigned char hour, unsigned char minute,
+static void icq_msg_incoming(icq_Link *link, unsigned long uin, unsigned char hour, unsigned char minute,
 			unsigned char day, unsigned char month, unsigned short year, const char *data) {
 	struct gaim_connection *gc = find_gaim_conn_by_icq_link(link);
 	char buf[256], *tmp = g_malloc(BUF_LONG);
@@ -131,7 +131,7 @@
 	g_free(tmp);
 }
 
-static void icq_user_online(ICQLINK *link, unsigned long uin, unsigned long st,
+static void icq_user_online(icq_Link *link, unsigned long uin, unsigned long st,
 				unsigned long ip, unsigned short port, unsigned long real_ip,
 				unsigned char tcp_flags) {
 	struct gaim_connection *gc = find_gaim_conn_by_icq_link(link);
@@ -143,13 +143,13 @@
 	serv_got_update(gc, buf, 1, 0, 0, 0, status, 0);
 }
 
-static void icq_user_offline(ICQLINK *link, unsigned long uin) {
+static void icq_user_offline(icq_Link *link, unsigned long uin) {
 	struct gaim_connection *gc = find_gaim_conn_by_icq_link(link);
 	char buf[256]; g_snprintf(buf, sizeof buf, "%lu", uin);
 	serv_got_update(gc, buf, 0, 0, 0, 0, 0, 0);
 }
 
-static void icq_user_status(ICQLINK *link, unsigned long uin, unsigned long st) {
+static void icq_user_status(icq_Link *link, unsigned long uin, unsigned long st) {
 	struct gaim_connection *gc = find_gaim_conn_by_icq_link(link);
 	guint status;
 	char buf[256];
@@ -175,7 +175,7 @@
 	}
 }
 
-static void icq_url_incoming(struct icq_link *link, unsigned long uin, unsigned char hour,
+static void icq_url_incoming(icq_Link *link, unsigned long uin, unsigned char hour,
 				unsigned char minute, unsigned char day, unsigned char month,
 				unsigned short year, const char *url, const char *descr) {
 	struct gaim_connection *gc = find_gaim_conn_by_icq_link(link);
@@ -186,19 +186,19 @@
 	g_free(msg);
 }
 
-static void icq_wrong_passwd(struct icq_link *link) {
+static void icq_wrong_passwd(icq_Link *link) {
 	struct gaim_connection *gc = find_gaim_conn_by_icq_link(link);
 	hide_login_progress(gc, "Invalid password.");
 	signoff(gc);
 }
 
-static void icq_invalid_uin(struct icq_link *link) {
+static void icq_invalid_uin(icq_Link *link) {
 	struct gaim_connection *gc = find_gaim_conn_by_icq_link(link);
 	hide_login_progress(gc, "Invalid UIN.");
 	signoff(gc);
 }
 
-static void icq_info_reply(struct icq_link *link, unsigned long uin, const char *nick,
+static void icq_info_reply(icq_Link *link, unsigned long uin, const char *nick,
 			const char *first, const char *last, const char *email, char auth) {
 	char buf[16 * 1024];
 
@@ -214,7 +214,7 @@
 	g_show_info_text(buf);
 }
 
-static void icq_web_pager(struct icq_link *link, unsigned char hour, unsigned char minute,
+static void icq_web_pager(icq_Link *link, unsigned char hour, unsigned char minute,
 		unsigned char day, unsigned char month, unsigned short year, const char *nick,
 		const char *email, const char *msg) {
 	struct gaim_connection *gc = find_gaim_conn_by_icq_link(link);
@@ -226,7 +226,7 @@
 	g_free(what);
 }
 
-static void icq_mail_express(struct icq_link *link, unsigned char hour, unsigned char minute,
+static void icq_mail_express(icq_Link *link, unsigned char hour, unsigned char minute,
 		unsigned char day, unsigned char month, unsigned short year, const char *nick,
 		const char *email, const char *msg) {
 	struct gaim_connection *gc = find_gaim_conn_by_icq_link(link);
@@ -238,7 +238,7 @@
 	g_free(what);
 }
 
-static void icq_req_not(struct icq_link *link, unsigned long id, int type, int arg, void *data) {
+static void icq_req_not(icq_Link *link, unsigned long id, int type, int arg, void *data) {
 	if (type == ICQ_NOTIFY_FAILED)
 		do_error_dialog("Failure in sending packet", "ICQ error");
 	return;
@@ -247,7 +247,7 @@
 static void icq_login(struct aim_user *user) {
 	struct gaim_connection *gc = new_gaim_conn(user);
 	struct icq_data *id = gc->proto_data = g_new0(struct icq_data, 1);
-	ICQLINK *link;
+	icq_Link *link;
 	char ps[9];
 
 	icq_LogLevel = ICQ_LOG_MESSAGE;
--- a/plugins/icq/icq.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/icq.h	Tue May 29 10:32:53 2001 +0000
@@ -1,4 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _ICQ_H_
 #define _ICQ_H_
 
@@ -67,22 +88,27 @@
 } icq_ArrayType;
 
 /* dummy forward declarations */
-struct icq_link_private;
+typedef struct icq_LinkPrivate_s icq_LinkPrivate;
 typedef struct icq_TCPLink_s icq_TCPLink;
 typedef struct icq_FileSession_s icq_FileSession;
 typedef struct icq_ChatSession_s icq_ChatSession;
+typedef struct icq_Link_s icq_Link;
+
+/* Legacy compatibility - remove for icqlib 2.0.0 */
+typedef struct icq_Link_s ICQLINK;
+#define icq_ICQLINKNew icq_LinkNew
+#define icq_ICQLINKDelete icq_LinkDelete
 
 /**
- * The ICQLINK structure represents a single connection to the ICQ  servers.
+ * The icq_Link structure represents a single connection to the ICQ servers.
  * It is returned as the result of an icq_ICQLINKNew function, and contains
  * connection-specific parameters such as uin, sockets, current status, etc.
  *
  * This structure should be considered read-only.  Modifying it will cause
  * undefined results.
  */
-typedef struct icq_link
+struct icq_Link_s
 {
-
   /* General parameters */
   
   /** User Identification Number.  This is your ICQ 'account' number. */
@@ -124,7 +150,7 @@
   unsigned short icq_TCPSrvPort;
   
   /** Has TCP been enabled for this connection?
-   * @see icq_NewICQLINK */
+   * @see icq_Newicq_Link */
   unsigned char icq_UseTCP;
   
   /* SOCKS5 Proxy stuff */
@@ -143,7 +169,7 @@
   unsigned short icq_ProxyPort;
   
   /** What's this? :) */
-  int  icq_ProxyAuth;
+  int icq_ProxyAuth;
   
   /** Username used when logging into the proxy. */
   char *icq_ProxyName;
@@ -158,206 +184,216 @@
   unsigned long icq_ProxyDestIP;    /* HOST byteorder */
   unsigned short icq_ProxyDestPort; /* HOST byteorder */
 
-  /*** Callbacks ***/
-  void (*icq_Logged)(struct icq_link *link);
-  void (*icq_Disconnected)(struct icq_link *link);
-  void (*icq_RecvMessage)(struct icq_link *link, unsigned long uin,
+  /* Begin Callbacks */
+  void (*icq_Logged)(icq_Link *icqlink);
+  void (*icq_Disconnected)(icq_Link *icqlink);
+  void (*icq_RecvMessage)(icq_Link *icqlink, unsigned long uin,
        unsigned char hour, unsigned char minute, unsigned char day,
        unsigned char month, unsigned short year, const char *msg);
-  void (*icq_RecvURL)(struct icq_link *link, unsigned long uin,
+  void (*icq_RecvURL)(icq_Link *icqlink, unsigned long uin,
        unsigned char hour, unsigned char minute, unsigned char day,
        unsigned char month, unsigned short year, const char *url,
        const char *descr);
-  void (*icq_RecvContactList)(struct icq_link *link, unsigned long uin,
-       int nr, const char **contact_uin, const char **contact_nick);
-  void (*icq_RecvWebPager)(struct icq_link *link,unsigned char hour,
+  void (*icq_RecvContactList)(icq_Link *icqlink, unsigned long uin,
+       unsigned char hour, unsigned char minute, unsigned char day,
+       unsigned char month, unsigned short year, int nr,
+       const char **contact_uin, const char **contact_nick);
+  void (*icq_RecvWebPager)(icq_Link *icqlink,unsigned char hour,
        unsigned char minute, unsigned char day, unsigned char month,
        unsigned short year, const char *nick, const char *email,
        const char *msg);
-  void (*icq_RecvMailExpress)(struct icq_link *link,unsigned char hour,
+  void (*icq_RecvMailExpress)(icq_Link *icqlink,unsigned char hour,
        unsigned char minute, unsigned char day, unsigned char month,
        unsigned short year, const char *nick, const char *email,
        const char *msg);
-  void (*icq_RecvChatReq)(struct icq_link *link, unsigned long uin,
+  void (*icq_RecvChatReq)(icq_Link *icqlink, unsigned long uin,
        unsigned char hour, unsigned char minute, unsigned char day,
        unsigned char month, unsigned short year, const char *descr,
        unsigned long seq);
-  void (*icq_RecvFileReq)(struct icq_link *link, unsigned long uin,
+  void (*icq_RecvFileReq)(icq_Link *icqlink, unsigned long uin,
        unsigned char hour, unsigned char minute, unsigned char day,
        unsigned char month, unsigned short year, const char *descr,
        const char *filename, unsigned long filesize, unsigned long seq);
-  void (*icq_RecvAdded)(struct icq_link *link, unsigned long uin,
+  void (*icq_RecvAdded)(icq_Link *icqlink, unsigned long uin,
        unsigned char hour, unsigned char minute, unsigned char day,
        unsigned char month, unsigned short year, const char *nick,
        const char *first, const char *last, const char *email);
-  void (*icq_RecvAuthReq)(struct icq_link *link, unsigned long uin,
+  void (*icq_RecvAuthReq)(icq_Link *icqlink, unsigned long uin,
        unsigned char hour, unsigned char minute, unsigned char day,
        unsigned char month, unsigned short year, const char *nick,
        const char *first, const char *last, const char *email,
        const char *reason);
-  void (*icq_UserFound)(struct icq_link *link, unsigned long uin,
+  void (*icq_UserFound)(icq_Link *icqlink, unsigned long uin,
        const char *nick, const char *first, const char *last,
        const char *email, char auth);
-  void (*icq_SearchDone)(struct icq_link *link);
-  void (*icq_UserOnline)(struct icq_link *link, unsigned long uin,
+  void (*icq_SearchDone)(icq_Link *icqlink);
+  void (*icq_UserOnline)(icq_Link *icqlink, unsigned long uin,
        unsigned long status, unsigned long ip, unsigned short port,
        unsigned long real_ip, unsigned char tcp_flag );
-  void (*icq_UserOffline)(struct icq_link *link, unsigned long uin);
-  void (*icq_UserStatusUpdate)(struct icq_link *link, unsigned long uin,
+  void (*icq_UserOffline)(icq_Link *icqlink, unsigned long uin);
+  void (*icq_UserStatusUpdate)(icq_Link *icqlink, unsigned long uin,
        unsigned long status);
-  void (*icq_InfoReply)(struct icq_link *link, unsigned long uin,
+  void (*icq_InfoReply)(icq_Link *icqlink, unsigned long uin,
        const char *nick, const char *first, const char *last,
        const char *email, char auth);
-  void (*icq_ExtInfoReply)(struct icq_link *link, unsigned long uin,
+  void (*icq_ExtInfoReply)(icq_Link *icqlink, unsigned long uin,
        const char *city, unsigned short country_code, char country_stat,
        const char *state, unsigned short age, char gender,
        const char *phone, const char *hp, const char *about);
-  void (*icq_WrongPassword)(struct icq_link *link);
-  void (*icq_InvalidUIN)(struct icq_link *link);
-  void (*icq_Log)(struct icq_link *link, time_t time, unsigned char level,
+  void (*icq_WrongPassword)(icq_Link *icqlink);
+  void (*icq_InvalidUIN)(icq_Link *icqlink);
+  void (*icq_Log)(icq_Link *icqlink, time_t log_time, unsigned char level,
        const char *str);
-  void (*icq_SrvAck)(struct icq_link *link, unsigned short seq);
-  void (*icq_RequestNotify)(struct icq_link *link, unsigned long id, 
+  void (*icq_SrvAck)(icq_Link *icqlink, unsigned short seq);
+  void (*icq_RequestNotify)(icq_Link *icqlink, unsigned long id, 
        int type, int arg, void *data);
   void (*icq_FileNotify)(icq_FileSession *session, int type, int arg,
        void *data);
   void (*icq_ChatNotify)(icq_ChatSession *session, int type, int arg,
        void *data);
-  void (*icq_NewUIN)(struct icq_link *link, unsigned long uin);
-  void (*icq_MetaUserFound)(struct icq_link *link, unsigned short seq2,
+  void (*icq_NewUIN)(icq_Link *icqlink, unsigned long uin);
+  void (*icq_MetaUserFound)(icq_Link *icqlink, unsigned short seq2,
        unsigned long uin, const char *nick, const char *first,
        const char *last, const char *email, char auth);
-  void (*icq_MetaUserInfo)(struct icq_link *link, unsigned short seq2,
+  void (*icq_MetaUserInfo)(icq_Link *icqlink, unsigned short seq2,
        const char *nick, const char *first, const char *last,
        const char *pri_eml, const char *sec_eml, const char *old_eml,
        const char *city, const char *state, const char *phone, const char *fax,
        const char *street, const char *cellular, unsigned long zip,
        unsigned short country, unsigned char timezone, unsigned char auth,
        unsigned char webaware, unsigned char hideip);
-  void (*icq_MetaUserWork)(struct icq_link *link, unsigned short seq2,
+  void (*icq_MetaUserWork)(icq_Link *icqlink, unsigned short seq2,
        const char *wcity, const char *wstate, const char *wphone,
        const char *wfax, const char *waddress, unsigned long wzip,
        unsigned short wcountry, const char *company, const char *department,
        const char *job, unsigned short occupation, const char *whomepage);
-  void (*icq_MetaUserMore)(struct icq_link *link, unsigned short seq2,
+  void (*icq_MetaUserMore)(icq_Link *icqlink, unsigned short seq2,
        unsigned short age, unsigned char gender, const char *homepage,
        unsigned char byear, unsigned char bmonth, unsigned char bday,
        unsigned char lang1, unsigned char lang2, unsigned char lang3);
-  void (*icq_MetaUserAbout)(struct icq_link *link, unsigned short seq2,
+  void (*icq_MetaUserAbout)(icq_Link *icqlink, unsigned short seq2,
        const char *about);
-  void (*icq_MetaUserInterests)(struct icq_link *link, unsigned short seq2,
+  void (*icq_MetaUserInterests)(icq_Link *icqlink, unsigned short seq2,
        unsigned char num, unsigned short icat1, const char *int1,
        unsigned short icat2, const char *int2, unsigned short icat3,
        const char *int3, unsigned short icat4, const char *int4);
-  void (*icq_MetaUserAffiliations)(struct icq_link *link, unsigned short seq2,
+  void (*icq_MetaUserAffiliations)(icq_Link *icqlink, unsigned short seq2,
        unsigned char anum, unsigned short acat1, const char *aff1,
        unsigned short acat2, const char *aff2, unsigned short acat3,
        const char *aff3, unsigned short acat4, const char *aff4,
        unsigned char bnum, unsigned short bcat1, const char *back1,
        unsigned short bcat2, const char *back2, unsigned short bcat3,
        const char *back3, unsigned short bcat4, const char *back4);
-  void (*icq_MetaUserHomePageCategory)(struct icq_link *link,
+  void (*icq_MetaUserHomePageCategory)(icq_Link *icqlink,
        unsigned short seq2, unsigned char num, unsigned short hcat1,
        const char *htext1);
+  /* End Callbacks */
        
   /** Private data pointer. */
-  struct icq_link_private *d;
+  icq_LinkPrivate *d;
   
   /** Space for user data */
   void *icq_UserData;
-} ICQLINK;
+};
 
 extern int icq_Russian;
 extern unsigned char icq_LogLevel;
 extern icq_ArrayType icq_Countries[];
 extern icq_ArrayType icq_Genders[];
 
-void icq_SetProxy(ICQLINK *link, const char *phost, unsigned short pport,
-     int pauth, const char *pname, const char *ppass);
-void icq_UnsetProxy(ICQLINK *link);
-
-ICQLINK *icq_ICQLINKNew(unsigned long uin, const char *password,
+icq_Link *icq_LinkNew(unsigned long uin, const char *password,
+  const char *nick, unsigned char useTCP);
+void icq_LinkInit(icq_Link *icqlink, unsigned long uin, const char *password,
   const char *nick, unsigned char useTCP);
-void icq_ICQLINKDelete(ICQLINK *link);
-  
-int icq_Connect(ICQLINK *link, const char *hostname, int port);
-void icq_Disconnect(ICQLINK *link);
-int icq_GetSok(ICQLINK *link);
-int icq_GetProxySok(ICQLINK *link);
-void icq_HandleServerResponse(ICQLINK *link);
-void icq_HandleProxyResponse(ICQLINK *link);
-void icq_Main(ICQLINK *link);
-unsigned short icq_KeepAlive(ICQLINK *link);
-void icq_Login(ICQLINK *link, unsigned long status);
-void icq_Logout(ICQLINK *link);
-void icq_SendContactList(ICQLINK *link);
-void icq_SendVisibleList(ICQLINK *link);
-void icq_SendInvisibleList(ICQLINK *link);
-void icq_SendNewUser(ICQLINK * link, unsigned long uin);
-unsigned long icq_SendMessage(ICQLINK *link, unsigned long uin,
-     const char *text, unsigned char thruSrv);
-unsigned long icq_SendURL(ICQLINK *link, unsigned long uin, const char *url,
-     const char *descr, unsigned char thruSrv);
-void icq_ChangeStatus(ICQLINK *link, unsigned long status);
-unsigned short icq_SendInfoReq(ICQLINK *link, unsigned long uin);
-unsigned short icq_SendExtInfoReq(ICQLINK *link, unsigned long uin);
-unsigned short icq_SendAuthMsg(ICQLINK *link, unsigned long uin);
-void icq_SendSearchReq(ICQLINK *link, const char *email, const char *nick,
-     const char* first, const char* last);
-void icq_SendSearchUINReq(ICQLINK *link, unsigned long uin);
+void icq_LinkDestroy(icq_Link *icqlink);
+void icq_LinkDelete(icq_Link *icqlink);
 
+void icq_Main(void);
 const char *icq_GetCountryName(unsigned short code);
 const char *icq_GetMetaOccupationName(unsigned short code);
 const char *icq_GetMetaBackgroundName(unsigned short code);
 const char *icq_GetMetaAffiliationName(unsigned short code);
 const char *icq_GetMetaLanguageName(unsigned short code);
-void icq_RegNewUser(ICQLINK *link, const char *pass);
-unsigned short icq_UpdateUserInfo(ICQLINK *link, const char *nick,
+
+/* Begin icq_Link methods */  
+void icq_SetProxy(icq_Link *icqlink, const char *phost, unsigned short pport,
+     int pauth, const char *pname, const char *ppass);
+void icq_UnsetProxy(icq_Link *icqlink);
+
+int icq_Connect(icq_Link *icqlink, const char *hostname, int port);
+void icq_Disconnect(icq_Link *icqlink);
+int icq_GetSok(icq_Link *icqlink);
+int icq_GetProxySok(icq_Link *icqlink);
+void icq_HandleServerResponse(icq_Link *icqlink);
+void icq_HandleProxyResponse(icq_Link *icqlink);
+unsigned short icq_KeepAlive(icq_Link *icqlink);
+void icq_Login(icq_Link *icqlink, unsigned long status);
+void icq_Logout(icq_Link *icqlink);
+void icq_SendContactList(icq_Link *icqlink);
+void icq_SendVisibleList(icq_Link *icqlink);
+void icq_SendInvisibleList(icq_Link *icqlink);
+void icq_SendNewUser(icq_Link *icqlink, unsigned long uin);
+unsigned long icq_SendMessage(icq_Link *icqlink, unsigned long uin,
+     const char *text, unsigned char thruSrv);
+unsigned long icq_SendURL(icq_Link *icqlink, unsigned long uin, const char *url,
+     const char *descr, unsigned char thruSrv);
+void icq_ChangeStatus(icq_Link *icqlink, unsigned long status);
+unsigned short icq_SendInfoReq(icq_Link *icqlink, unsigned long uin);
+unsigned short icq_SendExtInfoReq(icq_Link *icqlink, unsigned long uin);
+unsigned short icq_SendAuthMsg(icq_Link *icqlink, unsigned long uin);
+void icq_SendSearchReq(icq_Link *icqlink, const char *email, const char *nick,
+     const char* first, const char* last);
+void icq_SendSearchUINReq(icq_Link *icqlink, unsigned long uin);
+
+void icq_RegNewUser(icq_Link *icqlink, const char *pass);
+unsigned short icq_UpdateUserInfo(icq_Link *icqlink, const char *nick,
      const char *first, const char *last, const char *email);
-unsigned short icq_UpdateAuthInfo(ICQLINK *link, unsigned long auth);
-unsigned short icq_UpdateMetaInfoSet(ICQLINK *link, const char *nick,
+unsigned short icq_UpdateAuthInfo(icq_Link *icqlink, unsigned long auth);
+unsigned short icq_UpdateMetaInfoSet(icq_Link *icqlink, const char *nick,
      const char *first, const char *last, const char *email,
      const char *email2, const char *email3, const char *city,
      const char *state, const char *phone, const char *fax, const char *street,
      const char *cellular, unsigned long zip, unsigned short cnt_code,
      unsigned char cnt_stat, unsigned char emailhide);
-unsigned short icq_UpdateMetaInfoHomepage(ICQLINK *link, unsigned char age,
+unsigned short icq_UpdateMetaInfoHomepage(icq_Link *icqlink, unsigned char age,
      const char *homepage, unsigned char year, unsigned char month,
      unsigned char day, unsigned char lang1, unsigned char lang2,
      unsigned char lang3);
-unsigned short icq_UpdateMetaInfoAbout(ICQLINK *link, const char *about);
-unsigned short icq_UpdateMetaInfoSecurity(ICQLINK *link, unsigned char reqauth,
+unsigned short icq_UpdateMetaInfoAbout(icq_Link *icqlink, const char *about);
+unsigned short icq_UpdateMetaInfoSecurity(icq_Link *icqlink, unsigned char reqauth,
      unsigned char webpresence, unsigned char pubip);
-unsigned short icq_UpdateNewUserInfo(ICQLINK *link, const char *nick,
+unsigned short icq_UpdateNewUserInfo(icq_Link *icqlink, const char *nick,
      const char *first, const char *last, const char *email);
-unsigned short icq_SendMetaInfoReq(ICQLINK *link, unsigned long uin);
+unsigned short icq_SendMetaInfoReq(icq_Link *icqlink, unsigned long uin);
 
-void icq_FmtLog(ICQLINK *link, int level, const char *fmt, ...);
+void icq_FmtLog(icq_Link *icqlink, int level, const char *fmt, ...);
 
-void icq_ContactAdd(ICQLINK *link, unsigned long cuin);
-void icq_ContactRemove(ICQLINK *link, unsigned long cuin);
-void icq_ContactClear(ICQLINK *link );
-void icq_ContactSetVis(ICQLINK *link, unsigned long cuin, unsigned char vu);
-void icq_ContactSetInvis(ICQLINK *link, unsigned long cuin, unsigned char vu);
+void icq_ContactAdd(icq_Link *icqlink, unsigned long cuin);
+void icq_ContactRemove(icq_Link *icqlink, unsigned long cuin);
+void icq_ContactClear(icq_Link *icqlink );
+void icq_ContactSetVis(icq_Link *icqlink, unsigned long cuin, unsigned char vu);
+void icq_ContactSetInvis(icq_Link *icqlink, unsigned long cuin, unsigned char vu);
 
 /*** TCP ***/
-void icq_TCPMain(ICQLINK *link);
+void icq_TCPMain(icq_Link *icqlink);
 
-void icq_TCPProcessReceived(ICQLINK *link);
+void icq_TCPProcessReceived(icq_Link *icqlink);
 
-unsigned long icq_TCPSendMessage(ICQLINK *link, unsigned long uin,
+unsigned long icq_TCPSendMessage(icq_Link *icqlink, unsigned long uin,
      const char *message);
-unsigned long icq_TCPSendURL(ICQLINK *link, unsigned long uin,
+unsigned long icq_TCPSendURL(icq_Link *icqlink, unsigned long uin,
      const char *message, const char *url);
-unsigned long icq_SendChatRequest(ICQLINK *link, unsigned long uin,
+unsigned long icq_SendChatRequest(icq_Link *icqlink, unsigned long uin,
      const char *message);
-void icq_AcceptChatRequest(ICQLINK *link, unsigned long uin, unsigned long seq);
+void icq_AcceptChatRequest(icq_Link *icqlink, unsigned long uin, unsigned long seq);
 
-void icq_CancelChatRequest(ICQLINK *link, unsigned long uin, 
+void icq_CancelChatRequest(icq_Link *icqlink, unsigned long uin, 
      unsigned long sequence);
-void icq_RefuseChatRequest(ICQLINK *link, unsigned long uin,
+void icq_RefuseChatRequest(icq_Link *icqlink, unsigned long uin,
      unsigned long sequence, const char *reason);
 
+/* End icq_Link Methods */
+
 /*** TCP ***/
 
 /** \defgroup ChatSession Chat Session Documentation
@@ -509,7 +545,7 @@
   int status;
   
   /** ICQLINK that spawned this chat session. */
-  ICQLINK *icqlink;
+  icq_Link *icqlink;
   
   /** For internal icqlib use only. */
   icq_TCPLink *tcplink;
@@ -556,7 +592,7 @@
 
   unsigned long id;
   int status;
-  ICQLINK *icqlink;
+  icq_Link *icqlink;
   icq_TCPLink *tcplink;
 
   int direction;
@@ -582,13 +618,13 @@
   void *user_data;
 };
           
-icq_FileSession *icq_AcceptFileRequest(ICQLINK *link, unsigned long uin,
+icq_FileSession *icq_AcceptFileRequest(icq_Link *icqlink, unsigned long uin,
                  unsigned long sequence);
-unsigned long icq_SendFileRequest(ICQLINK *link, unsigned long uin,
+unsigned long icq_SendFileRequest(icq_Link *icqlink, unsigned long uin,
               const char *message, char **files);
-void icq_CancelFileRequest(ICQLINK *link, unsigned long uin, 
+void icq_CancelFileRequest(icq_Link *icqlink, unsigned long uin, 
      unsigned long sequence);
-void icq_RefuseFileRequest(ICQLINK *link, unsigned long uin,
+void icq_RefuseFileRequest(icq_Link *icqlink, unsigned long uin,
      unsigned long sequence, const char *reason);
 
 void icq_FileSessionSetSpeed(icq_FileSession *p, int speed);
@@ -602,15 +638,15 @@
 #define ICQ_SOCKET_WRITE 1
 #define ICQ_SOCKET_MAX   2
 
-extern void (*icq_SocketNotify)(int socket, int type, int status);
+extern void (*icq_SocketNotify)(int socket_fd, int type, int status);
 
-void icq_HandleReadySocket(int socket, int type);
+void icq_HandleReadySocket(int socket_fd, int type);
 
 /* Timeout Manager */
 
 extern void (*icq_SetTimeout)(long interval);
 
-void icq_HandleTimeout();
+void icq_HandleTimeout(void);
 
 #ifdef __cplusplus
 }
--- a/plugins/icq/icqbyteorder.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/icqbyteorder.c	Tue May 29 10:32:53 2001 +0000
@@ -1,6 +1,4 @@
 /*
- * $Id: icqbyteorder.c 1442 2001-01-28 01:52:27Z warmenhoven $
- *
  * This header defines macros to handle ICQ protocol byte order conversion.
  *
  * Vadim Zaliva <lord@crocodile.org>
@@ -29,22 +27,24 @@
  * they are highly optimised on some platforms.
  * But as last resort this simple code is used.
  */
+
 #ifndef HAVE_BYTESWAP_H
 # ifndef bswap_32
 unsigned long bswap_32(unsigned long v)
 {
-    unsigned char c,*x=(unsigned char *)&v;
-    c=x[0];x[0]=x[3];x[3]=c;
-    c=x[1];x[1]=x[2];x[2]=c;
-    return v;
+  unsigned char c,*x=(unsigned char *)&v;
+  c=x[0];x[0]=x[3];x[3]=c;
+  c=x[1];x[1]=x[2];x[2]=c;
+  return v;
 }
 # endif
+
 # ifndef bswap_16
 unsigned short bswap_16(unsigned short v)
 {
-    unsigned char c,*x=(unsigned char *)&v;
-    c=x[0];x[0]=x[1];x[1]=c;
-    return v;
+  unsigned char c,*x=(unsigned char *)&v;
+  c=x[0];x[0]=x[1];x[1]=c;
+  return v;
 }
 # endif
 #endif
--- a/plugins/icq/icqbyteorder.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/icqbyteorder.h	Tue May 29 10:32:53 2001 +0000
@@ -1,6 +1,4 @@
 /*
- * $Id: icqbyteorder.h 1477 2001-02-04 07:34:46Z warmenhoven $
- *
  * This header defines macros to handle ICQ protocol byte order conversion.
  *
  * Vadim Zaliva <lord@crocodile.org>
@@ -49,14 +47,21 @@
 # include <byteswap.h>
 #endif
 
-/* bsd way */
+/* BSD way */
 #ifdef HAVE_MACHINE_ENDIAN_H
 # include <machine/endian.h>
 #endif
 
-/* hpux way */
+/* HP-UX way */
 #ifdef hpux
-#include <arpa/nameser.h>
+# ifdef HAVE_ARPA_NAMESER_H
+#  include <arpa/nameser.h>
+# endif
+#endif
+
+/* Cygwin way */
+#ifdef HAVE_SYS_PARAM_H
+# include <sys/param.h>
 #endif
 
 /*
@@ -89,13 +94,7 @@
 #else
 
 #ifndef BYTE_ORDER
-/*#   error "Unknown byte order!"*/
-/* I probably shouldn't be doing this, but eh. -EWarmenhoven */
-#   warning "Unknown byte order! Using GLib defines"
-#   include <glib.h>
-#   define BYTE_ORDER G_BYTE_ORDER
-#   define BIG_ENDIAN G_BIG_ENDIAN
-#   define LITTLE_ENDIAN G_LITTLE_ENDIAN
+#   error "Unknown byte order!"
 #endif
 
 #if BYTE_ORDER == BIG_ENDIAN
--- a/plugins/icq/icqevent.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/icqevent.c	Tue May 29 10:32:53 2001 +0000
@@ -1,29 +1,30 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
 /*
- * $Id: icqevent.c 1442 2001-01-28 01:52:27Z warmenhoven $
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
  *
- * $Log$
- * Revision 1.2  2001/01/28 01:52:27  warmenhoven
- * icqlib 1.1.5
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * Revision 1.2  2000/06/15 18:54:09  bills
- * added time attribute and handleEvent function pointer to icq_Event,
- * renamed icq_ChatEvent to icq_ChatRequestEvent, renamed icq_FileEvent to
- * icq_FileRequestEvent, added icq_URLEvent and related methods
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * Revision 1.1  2000/06/15 15:27:39  bills
- * committed for safekeeping - this code will soon replace stdpackets.c and
- * greatly simplify tcphandle.c, as well as reducing code duplication in many
- * places.  it provides a much more flexible framework for managing events
- * and parsing and creating packets
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
-*/
+ */
 
 #include <stdlib.h>
 
+#include "icqlib.h" /* for icqbyteorder.h ?! */
+#include "icqbyteorder.h"
 #include "icqevent.h"
-#include "icqbyteorder.h"
 
 #ifdef EVENT_DEBUG
 #include <string.h>
@@ -385,12 +386,10 @@
   icq_MessageParsePacket(pbase, p);
 
   /* parse file event data */
-  port=icq_PacketRead32(p);                 /* file listen port, network */
+  pevent->port=ntohl(icq_PacketRead32(p));  /* file listen port, network */
   pevent->filename=icq_PacketReadString(p); /* filename text */
   pevent->filesize=icq_PacketRead32(p);     /* total size */
   (void)icq_PacketRead32(p);                /* file listen port, intel */
-
-  pevent->port=ntohl(port);
 }
 
 #ifdef EVENT_DEBUG
--- a/plugins/icq/icqevent.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/icqevent.h	Tue May 29 10:32:53 2001 +0000
@@ -1,24 +1,24 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
 /*
- * $Id: icqevent.h 1442 2001-01-28 01:52:27Z warmenhoven $
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
  *
- * $Log$
- * Revision 1.2  2001/01/28 01:52:27  warmenhoven
- * icqlib 1.1.5
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * Revision 1.2  2000/06/15 18:54:09  bills
- * added time attribute and handleEvent function pointer to icq_Event,
- * renamed icq_ChatEvent to icq_ChatRequestEvent, renamed icq_FileEvent to
- * icq_FileRequestEvent, added icq_URLEvent and related methods
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * Revision 1.1  2000/06/15 15:27:39  bills
- * committed for safekeeping - this code will soon replace stdpackets.c and
- * greatly simplify tcphandle.c, as well as reducing code duplication in many
- * places.  it provides a much more flexible framework for managing events
- * and parsing and creating packets
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
-*/
+ */
 
 #ifndef _ICQEVENT_H
 #define _ICQEVENT_H
@@ -55,7 +55,8 @@
   time_t time;
 
   icq_Packet *(*createPacket)(struct icq_Event_s *, icq_TCPLink *);
-  void (*handleEvent)(struct icq_Event_s *, ICQLINK *);
+  void *(*parsePacket)(struct icq_Event_s *, icq_Packet *);
+  void (*handleEvent)(struct icq_Event_s *, icq_Link *);
 
 #ifdef EVENT_DEBUG
   const char *(*eventName)(struct icq_Event_s *);
--- a/plugins/icq/icqlib.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/icqlib.c	Tue May 29 10:32:53 2001 +0000
@@ -1,52 +1,29 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: icqlib.c 1535 2001-03-03 00:26:04Z warmenhoven $
-$Log$
-Revision 1.6  2001/03/03 00:26:04  warmenhoven
-icqlib updates. beginnings of system logging.
-
-Revision 1.52  2001/03/01 05:30:43  bills
-only initialize TCP subsystem when use_tcp is enabled
-
-Revision 1.51  2001/02/22 05:37:39  bills
-new timeout manager code, correct compilation warnings
-
-Revision 1.50  2001/02/03 17:04:16  mwh
-Add an icq_UserData field to the ICQLINK struct.
-
-Revision 1.49  2001/01/17 01:29:17  bills
-Rework chat and file session interfaces; implement socket notifications.
 
-Revision 1.48  2001/01/15 06:20:24  denis
-Cleanup.
-
-Revision 1.47  2000/12/19 21:29:51  bills
-actually return the link in icq_ICQLINKNew
-
-Revision 1.46  2000/12/19 06:00:07  bills
-moved members from ICQLINK to ICQLINK_private struct
-
-Revision 1.45  2000/11/02 07:29:07  denis
-Ability to disable TCP protocol has been added.
-
-Revision 1.44  2000/07/24 03:10:08  bills
-added support for real nickname during TCP transactions like file and
-chat, instead of using Bill all the time (hmm, where'd I get that from? :)
-
-Revision 1.43  2000/07/09 22:05:11  bills
-removed unnecessary functions
-*/
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #include "icqlib.h"
 
 #include <stdlib.h>
 
-#ifndef _WIN32
-#include <unistd.h>
-#endif
-
-#include <time.h>
-
 #ifdef _WIN32
 #include <winsock.h>
 #else
@@ -56,173 +33,194 @@
 
 #include <sys/stat.h>
 
-#ifndef _WIN32
-#include <sys/time.h>
-#include <netinet/in.h>
-#endif
-
 #include "util.h"
-#include "icqtypes.h"
 #include "icq.h"
 #include "udp.h"
 #include "tcp.h"
 #include "queue.h"
 #include "socketmanager.h"
+#include "contacts.h"
 
 int icq_Russian = FALSE;
 BYTE icq_LogLevel = 0;
 
-DWORD icq_SendMessage(ICQLINK *link, DWORD uin, const char *text, BYTE thruSrv)
+DWORD icq_SendMessage(icq_Link *icqlink, DWORD uin, const char *text, 
+  BYTE thruSrv)
 {
   if(thruSrv==ICQ_SEND_THRUSERVER)
-    return icq_UDPSendMessage(link, uin, text);
+    return icq_UDPSendMessage(icqlink, uin, text);
   else if(thruSrv==ICQ_SEND_DIRECT)
-    return icq_TCPSendMessage(link, uin, text);
+    return icq_TCPSendMessage(icqlink, uin, text);
   else if(thruSrv==ICQ_SEND_BESTWAY)
   {
-    icq_ContactItem *pcontact=icq_ContactFind(link, uin);
+    icq_ContactItem *pcontact=icq_ContactFind(icqlink, uin);
     if(pcontact)
     {
       if(pcontact->tcp_flag == 0x04)
-        return icq_TCPSendMessage(link, uin, text);
+        return icq_TCPSendMessage(icqlink, uin, text);
       else
-        return icq_UDPSendMessage(link, uin, text);
+        return icq_UDPSendMessage(icqlink, uin, text);
     }
     else
     {
-      return icq_UDPSendMessage(link, uin, text);
+      return icq_UDPSendMessage(icqlink, uin, text);
     }
   }
   return 0;
 }
 
-DWORD icq_SendURL(ICQLINK *link, DWORD uin, const char *url, const char *descr, BYTE thruSrv)
+DWORD icq_SendURL(icq_Link *icqlink, DWORD uin, const char *url, 
+  const char *descr, BYTE thruSrv)
 {
   if(thruSrv==ICQ_SEND_THRUSERVER)
-    return icq_UDPSendURL(link, uin, url, descr);
+    return icq_UDPSendURL(icqlink, uin, url, descr);
   else if(thruSrv==ICQ_SEND_DIRECT)
-    return icq_TCPSendURL(link, uin, descr, url);
+    return icq_TCPSendURL(icqlink, uin, descr, url);
   else if(thruSrv==ICQ_SEND_BESTWAY)
   {
-    icq_ContactItem *pcontact=icq_ContactFind(link, uin);
+    icq_ContactItem *pcontact=icq_ContactFind(icqlink, uin);
     if(pcontact)
     {
       if(pcontact->tcp_flag == 0x04)
-        return icq_TCPSendURL(link, uin, descr, url);
+        return icq_TCPSendURL(icqlink, uin, descr, url);
       else
-        return icq_UDPSendURL(link, uin, url, descr);
+        return icq_UDPSendURL(icqlink, uin, url, descr);
     }
     else
     {
-      return icq_UDPSendURL(link, uin, url, descr);
+      return icq_UDPSendURL(icqlink, uin, url, descr);
     }
   }
   return 0;
 }
 
-ICQLINK *icq_ICQLINKNew(DWORD uin, const char *password, const char *nick,
-                        unsigned char useTCP)
+static int icqlib_initialized = 0;
+
+void icq_LibInit()
 {
-  ICQLINK *link = (ICQLINK*)malloc(sizeof(ICQLINK));
-  link->d = (ICQLINK_private*)malloc(sizeof(ICQLINK_private));
-
   srand(time(0L));
 
   /* initialize internal lists, if necessary */
   if (!icq_SocketList)
-    icq_SocketList = list_new();
+    icq_SocketList = icq_ListNew();
 
   if (!icq_TimeoutList)
   {
-    icq_TimeoutList = list_new();
+    icq_TimeoutList = icq_ListNew();
     icq_TimeoutList->compare_function =
       (icq_ListCompareFunc)icq_TimeoutCompare;
   }
 
+  icqlib_initialized = 1;
+}
+
+icq_Link *icq_LinkNew(DWORD uin, const char *password, const char *nick,
+                        unsigned char useTCP)
+{
+  icq_Link *icqlink = (icq_Link *)malloc(sizeof(icq_Link));
+
+  icq_LinkInit(icqlink, uin, password, nick, useTCP);
+
+  return icqlink;
+}
+
+void icq_LinkInit(icq_Link *icqlink, DWORD uin, const char *password, 
+  const char *nick, unsigned char useTCP)
+{
+  icqlink->d = (icq_LinkPrivate *)malloc(sizeof(icq_LinkPrivate));
+
+  if (!icqlib_initialized)
+    icq_LibInit();
+
   /* Initialize all callbacks */
-  link->icq_Logged = 0L;
-  link->icq_Disconnected = 0L;
-  link->icq_RecvMessage = 0L;
-  link->icq_RecvURL = 0L;
-  link->icq_RecvWebPager = 0L;
-  link->icq_RecvMailExpress = 0L;
-  link->icq_RecvChatReq = 0L;
-  link->icq_RecvFileReq = 0L;
-  link->icq_RecvAdded = 0L;
-  link->icq_RecvAuthReq = 0L;
-  link->icq_UserFound = 0L;
-  link->icq_SearchDone = 0L;
-  link->icq_UserOnline = 0L;
-  link->icq_UserOffline = 0L;
-  link->icq_UserStatusUpdate = 0L;
-  link->icq_InfoReply = 0L;
-  link->icq_ExtInfoReply = 0L;
-  link->icq_WrongPassword = 0L;
-  link->icq_InvalidUIN = 0L;
-  link->icq_Log = 0L;
-  link->icq_SrvAck = 0L;
-  link->icq_RequestNotify = 0L;
-  link->icq_NewUIN = 0L;
-  link->icq_MetaUserFound = 0L;
-  link->icq_MetaUserInfo = 0L;
-  link->icq_MetaUserWork = 0L;
-  link->icq_MetaUserMore = 0L;
-  link->icq_MetaUserAbout = 0L;
-  link->icq_MetaUserInterests = 0L;
-  link->icq_MetaUserAffiliations = 0L;
-  link->icq_MetaUserHomePageCategory = 0L;
+  icqlink->icq_Logged = 0L;
+  icqlink->icq_Disconnected = 0L;
+  icqlink->icq_RecvMessage = 0L;
+  icqlink->icq_RecvURL = 0L;
+  icqlink->icq_RecvContactList = 0L;
+  icqlink->icq_RecvWebPager = 0L;
+  icqlink->icq_RecvMailExpress = 0L;
+  icqlink->icq_RecvChatReq = 0L;
+  icqlink->icq_RecvFileReq = 0L;
+  icqlink->icq_RecvAdded = 0L;
+  icqlink->icq_RecvAuthReq = 0L;
+  icqlink->icq_UserFound = 0L;
+  icqlink->icq_SearchDone = 0L;
+  icqlink->icq_UserOnline = 0L;
+  icqlink->icq_UserOffline = 0L;
+  icqlink->icq_UserStatusUpdate = 0L;
+  icqlink->icq_InfoReply = 0L;
+  icqlink->icq_ExtInfoReply = 0L;
+  icqlink->icq_WrongPassword = 0L;
+  icqlink->icq_InvalidUIN = 0L;
+  icqlink->icq_Log = 0L;
+  icqlink->icq_SrvAck = 0L;
+  icqlink->icq_RequestNotify = 0L;
+  icqlink->icq_NewUIN = 0L;
+  icqlink->icq_MetaUserFound = 0L;
+  icqlink->icq_MetaUserInfo = 0L;
+  icqlink->icq_MetaUserWork = 0L;
+  icqlink->icq_MetaUserMore = 0L;
+  icqlink->icq_MetaUserAbout = 0L;
+  icqlink->icq_MetaUserInterests = 0L;
+  icqlink->icq_MetaUserAffiliations = 0L;
+  icqlink->icq_MetaUserHomePageCategory = 0L;
 
   /* General stuff */
-  link->icq_Uin = uin;
-  link->icq_Password = strdup(password);
-  link->icq_Nick = strdup(nick);
-  link->icq_OurIP = -1;
-  link->icq_OurPort = 0;
-  link->d->icq_ContactList = list_new();
-  link->icq_Status = -1;
-  link->icq_UserData = 0L;
+  icqlink->icq_Uin = uin;
+  icqlink->icq_Password = strdup(password);
+  icqlink->icq_Nick = strdup(nick);
+  icqlink->icq_OurIP = -1;
+  icqlink->icq_OurPort = 0;
+  icqlink->d->icq_ContactList = icq_ListNew();
+  icqlink->icq_Status = -1;
+  icqlink->icq_UserData = 0L;
 
   /* UDP stuff */
-  link->icq_UDPSok = -1;
-  memset(link->d->icq_UDPServMess, FALSE, sizeof(link->d->icq_UDPServMess));
-  link->d->icq_UDPSeqNum1 = 0;
-  link->d->icq_UDPSeqNum2 = 0;
-  link->d->icq_UDPSession = 0;
-  icq_UDPQueueNew(link);
+  icqlink->icq_UDPSok = -1;
+  memset(icqlink->d->icq_UDPServMess, FALSE, 
+    sizeof(icqlink->d->icq_UDPServMess));
+  icqlink->d->icq_UDPSeqNum1 = 0;
+  icqlink->d->icq_UDPSeqNum2 = 0;
+  icqlink->d->icq_UDPSession = 0;
+  icq_UDPQueueNew(icqlink);
 
   /* TCP stuff */
-  link->icq_UseTCP = useTCP;
+  icqlink->icq_UseTCP = useTCP;
   if (useTCP)
-    icq_TCPInit(link);
+    icq_TCPInit(icqlink);
 
   /* Proxy stuff */
-  link->icq_UseProxy = 0;
-  link->icq_ProxyHost = 0L;
-  link->icq_ProxyIP = -1;
-  link->icq_ProxyPort = 0;
-  link->icq_ProxyAuth = 0;
-  link->icq_ProxyName = 0L;
-  link->icq_ProxyPass = 0L;
-  link->icq_ProxySok = -1;
-  link->icq_ProxyOurPort = 0;
-  link->icq_ProxyDestIP = -1;
-  link->icq_ProxyDestPort = 0;
-
-  return link;
+  icqlink->icq_UseProxy = 0;
+  icqlink->icq_ProxyHost = 0L;
+  icqlink->icq_ProxyIP = -1;
+  icqlink->icq_ProxyPort = 0;
+  icqlink->icq_ProxyAuth = 0;
+  icqlink->icq_ProxyName = 0L;
+  icqlink->icq_ProxyPass = 0L;
+  icqlink->icq_ProxySok = -1;
+  icqlink->icq_ProxyOurPort = 0;
+  icqlink->icq_ProxyDestIP = -1;
+  icqlink->icq_ProxyDestPort = 0;
 }
 
-void icq_ICQLINKDelete(ICQLINK *link)
+void icq_LinkDestroy(icq_Link *icqlink)
 {
-  icq_TCPDone(link);
-  if(link->icq_Password)
-    free(link->icq_Password);
-  if(link->icq_Nick)
-    free(link->icq_Nick);
-  if(link->d->icq_ContactList)
-    list_delete(link->d->icq_ContactList, icq_ContactDelete);
-  icq_UDPQueueDelete(link);
-  free(link->d);
-  free(link);
+  icq_TCPDone(icqlink);
+  if(icqlink->icq_Password)
+    free(icqlink->icq_Password);
+  if(icqlink->icq_Nick)
+    free(icqlink->icq_Nick);
+  if(icqlink->d->icq_ContactList)
+    icq_ListDelete(icqlink->d->icq_ContactList, icq_ContactDelete);
+  icq_UDPQueueDelete(icqlink);
+  free(icqlink->d);
+}
+
+void icq_LinkDelete(icq_Link *icqlink)
+{
+  icq_LinkDestroy(icqlink);
+  free(icqlink);
 }
 
 /******************************
@@ -230,7 +228,7 @@
 and icq_Password and logins in and sits
 in a loop waiting for server responses.
 *******************************/
-void icq_Main(ICQLINK *link)
+void icq_Main()
 {
   icq_SocketPoll();
 }
@@ -240,107 +238,107 @@
 hostname can be DNS or nnn.nnn.nnn.nnn
 write out messages to the FD aux
 ***********************************/
-int icq_Connect(ICQLINK *link, const char *hostname, int port)
+int icq_Connect(icq_Link *icqlink, const char *hostname, int port)
 {
   char buf[1024]; /*, un = 1;*/
 /*  char tmpbuf[256], our_host[256]*/
   int conct, res;
   unsigned int length;
-  struct sockaddr_in sin, prsin;  /* used to store inet addr stuff */
+  struct sockaddr_in saddr, prsin;  /* used to store inet addr stuff */
   struct hostent *host_struct; /* used in DNS llokup */
 
   /* create the unconnected socket*/
-  link->icq_UDPSok = icq_SocketNew(AF_INET, SOCK_DGRAM, 0);
+  icqlink->icq_UDPSok = icq_SocketNew(AF_INET, SOCK_DGRAM, 0);
 
-  if(link->icq_UDPSok == -1)
+  if(icqlink->icq_UDPSok == -1)
   {
-    icq_FmtLog(link, ICQ_LOG_FATAL, "Socket creation failed\n");
+    icq_FmtLog(icqlink, ICQ_LOG_FATAL, "Socket creation failed\n");
     return -1;
   }
-  icq_FmtLog(link, ICQ_LOG_MESSAGE, "Socket created attempting to connect\n");
-  sin.sin_addr.s_addr = INADDR_ANY;
-  sin.sin_family = AF_INET; /* we're using the inet not appletalk*/
-  sin.sin_port = 0;
-  if(bind(link->icq_UDPSok, (struct sockaddr*)&sin, sizeof(struct sockaddr))<0)
+  icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "Socket created attempting to connect\n");
+  saddr.sin_addr.s_addr = INADDR_ANY;
+  saddr.sin_family = AF_INET; /* we're using the inet not appletalk*/
+  saddr.sin_port = 0;
+  if(bind(icqlink->icq_UDPSok, (struct sockaddr*)&saddr, sizeof(struct sockaddr))<0)
   {
-    icq_FmtLog(link, ICQ_LOG_FATAL, "Can't bind socket to free port\n");
-    icq_SocketDelete(link->icq_UDPSok);
-    link->icq_UDPSok = -1;
+    icq_FmtLog(icqlink, ICQ_LOG_FATAL, "Can't bind socket to free port\n");
+    icq_SocketDelete(icqlink->icq_UDPSok);
+    icqlink->icq_UDPSok = -1;
     return -1;
   }
-  length = sizeof(sin);
-  getsockname(link->icq_UDPSok, (struct sockaddr*)&sin, &length);
-  link->icq_ProxyOurPort = ntohs(sin.sin_port);
-  if(link->icq_UseProxy)
+  length = sizeof(saddr);
+  getsockname(icqlink->icq_UDPSok, (struct sockaddr*)&saddr, &length);
+  icqlink->icq_ProxyOurPort = ntohs(saddr.sin_port);
+  if(icqlink->icq_UseProxy)
   {
-    icq_FmtLog(link, ICQ_LOG_MESSAGE, "[SOCKS] Trying to use SOCKS5 proxy\n");
-    prsin.sin_addr.s_addr = inet_addr(link->icq_ProxyHost);
+    icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "[SOCKS] Trying to use SOCKS5 proxy\n");
+    prsin.sin_addr.s_addr = inet_addr(icqlink->icq_ProxyHost);
     if(prsin.sin_addr.s_addr  == (unsigned long)-1) /* name isn't n.n.n.n so must be DNS */
     {
-      host_struct = gethostbyname(link->icq_ProxyHost);
+      host_struct = gethostbyname(icqlink->icq_ProxyHost);
       if(host_struct == 0L)
       {
-        icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Can't find hostname: %s\n", link->icq_ProxyHost);
+        icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Can't find hostname: %s\n", icqlink->icq_ProxyHost);
         return -1;
       }
       prsin.sin_addr = *((struct in_addr*)host_struct->h_addr);
     }
-    link->icq_ProxyIP = ntohl(prsin.sin_addr.s_addr);
+    icqlink->icq_ProxyIP = ntohl(prsin.sin_addr.s_addr);
     prsin.sin_family = AF_INET; /* we're using the inet not appletalk*/
-    prsin.sin_port = htons(link->icq_ProxyPort); /* port */
+    prsin.sin_port = htons(icqlink->icq_ProxyPort); /* port */
 
     /* create the unconnected socket*/
-    link->icq_ProxySok = icq_SocketNew(AF_INET, SOCK_STREAM, 0);
+    icqlink->icq_ProxySok = icq_SocketNew(AF_INET, SOCK_STREAM, 0);
 
-    if(link->icq_ProxySok == -1)
+    if(icqlink->icq_ProxySok == -1)
     {
-      icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Socket creation failed\n");
+      icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Socket creation failed\n");
       return -1;
     }
-    icq_FmtLog(link, ICQ_LOG_MESSAGE, "[SOCKS] Socket created attempting to connect\n");
-    conct = connect(link->icq_ProxySok, (struct sockaddr *) &prsin, sizeof(prsin));
+    icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "[SOCKS] Socket created attempting to connect\n");
+    conct = connect(icqlink->icq_ProxySok, (struct sockaddr *) &prsin, sizeof(prsin));
     if(conct == -1) /* did we connect ?*/
     {
-      icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Connection refused\n");
+      icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Connection refused\n");
       return -1;
     }
     buf[0] = 5; /* protocol version */
     buf[1] = 1; /* number of methods */
-    if(!strlen(link->icq_ProxyName) || !strlen(link->icq_ProxyPass) || !link->icq_ProxyAuth)
+    if(!strlen(icqlink->icq_ProxyName) || !strlen(icqlink->icq_ProxyPass) || !icqlink->icq_ProxyAuth)
       buf[2] = 0; /* no authorization required */
     else
       buf[2] = 2; /* method username/password */
 #ifdef _WIN32
-    send(link->icq_ProxySok, buf, 3, 0);
-    res = recv(link->icq_ProxySok, buf, 2, 0);
+    send(icqlink->icq_ProxySok, buf, 3, 0);
+    res = recv(icqlink->icq_ProxySok, buf, 2, 0);
 #else
-    write(link->icq_ProxySok, buf, 3);
-    res = read(link->icq_ProxySok, buf, 2);
+    write(icqlink->icq_ProxySok, buf, 3);
+    res = read(icqlink->icq_ProxySok, buf, 2);
 #endif
-    if(strlen(link->icq_ProxyName) && strlen(link->icq_ProxyPass) && link->icq_ProxyAuth)
+    if(strlen(icqlink->icq_ProxyName) && strlen(icqlink->icq_ProxyPass) && icqlink->icq_ProxyAuth)
     {
       if(res != 2 || buf[0] != 5 || buf[1] != 2) /* username/password authentication*/
       {
-        icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Authentication method incorrect\n");
-        icq_SocketDelete(link->icq_ProxySok);
+        icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Authentication method incorrect\n");
+        icq_SocketDelete(icqlink->icq_ProxySok);
         return -1;
       }
       buf[0] = 1; /* version of subnegotiation */
-      buf[1] = strlen(link->icq_ProxyName);
-      memcpy(&buf[2], link->icq_ProxyName, buf[1]);
-      buf[2+buf[1]] = strlen(link->icq_ProxyPass);
-      memcpy(&buf[3+buf[1]], link->icq_ProxyPass, buf[2+buf[1]]);
+      buf[1] = strlen(icqlink->icq_ProxyName);
+      memcpy(&buf[2], icqlink->icq_ProxyName, buf[1]);
+      buf[2+buf[1]] = strlen(icqlink->icq_ProxyPass);
+      memcpy(&buf[3+buf[1]], icqlink->icq_ProxyPass, buf[2+buf[1]]);
 #ifdef _WIN32
-      send(link->icq_ProxySok, buf, buf[1]+buf[2+buf[1]]+3, 0);
-      res = recv(link->icq_ProxySok, buf, 2, 0);
+      send(icqlink->icq_ProxySok, buf, buf[1]+buf[2+buf[1]]+3, 0);
+      res = recv(icqlink->icq_ProxySok, buf, 2, 0);
 #else
-      write(link->icq_ProxySok, buf, buf[1]+buf[2+buf[1]]+3);
-      res = read(link->icq_ProxySok, buf, 2);
+      write(icqlink->icq_ProxySok, buf, buf[1]+buf[2+buf[1]]+3);
+      res = read(icqlink->icq_ProxySok, buf, 2);
 #endif
       if(res != 2 || buf[0] != 1 || buf[1] != 0)
       {
-        icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Authorization failure\n");
-        icq_SocketDelete(link->icq_ProxySok);
+        icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Authorization failure\n");
+        icq_SocketDelete(icqlink->icq_ProxySok);
         return -1;
       }
     }
@@ -348,8 +346,8 @@
     {
       if(res != 2 || buf[0] != 5 || buf[1] != 0) /* no authentication required */
       {
-        icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Authentication method incorrect\n");
-        icq_SocketDelete(link->icq_ProxySok);
+        icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Authentication method incorrect\n");
+        icq_SocketDelete(icqlink->icq_ProxySok);
         return -1;
       }
     }
@@ -361,111 +359,111 @@
     buf[5] = (char)0;
     buf[6] = (char)0;
     buf[7] = (char)0;
-    *(unsigned short*)&buf[8] = htons(link->icq_ProxyOurPort);
-/*     memcpy(&buf[8], &link->icq_ProxyOurPort, 2); */
+    *(unsigned short*)&buf[8] = htons(icqlink->icq_ProxyOurPort);
+/*     memcpy(&buf[8], &icqlink->icq_ProxyOurPort, 2); */
 #ifdef _WIN32
-    send(link->icq_ProxySok, buf, 10, 0);
-    res = recv(link->icq_ProxySok, buf, 10, 0);
+    send(icqlink->icq_ProxySok, buf, 10, 0);
+    res = recv(icqlink->icq_ProxySok, buf, 10, 0);
 #else
-    write(link->icq_ProxySok, buf, 10);
-    res = read(link->icq_ProxySok, buf, 10);
+    write(icqlink->icq_ProxySok, buf, 10);
+    res = read(icqlink->icq_ProxySok, buf, 10);
 #endif
     if(res != 10 || buf[0] != 5 || buf[1] != 0)
     {
       switch(buf[1])
       {
         case 1:
-          icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] General SOCKS server failure\n");
+          icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] General SOCKS server failure\n");
           break;
         case 2:
-          icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Connection not allowed by ruleset\n");
+          icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Connection not allowed by ruleset\n");
           break;
         case 3:
-          icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Network unreachable\n");
+          icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Network unreachable\n");
           break;
         case 4:
-          icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Host unreachable\n");
+          icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Host unreachable\n");
           break;
         case 5:
-          icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Connection refused\n");
+          icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Connection refused\n");
           break;
         case 6:
-          icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] TTL expired\n");
+          icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] TTL expired\n");
           break;
         case 7:
-          icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Command not supported\n");
+          icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Command not supported\n");
           break;
         case 8:
-          icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Address type not supported\n");
+          icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Address type not supported\n");
           break;
         default:
-          icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Unknown SOCKS server failure\n");
+          icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Unknown SOCKS server failure\n");
           break;
       }
-      icq_SocketDelete(link->icq_ProxySok);
-      link->icq_ProxySok = -1;
+      icq_SocketDelete(icqlink->icq_ProxySok);
+      icqlink->icq_ProxySok = -1;
       return -1;
     }
   }
-  sin.sin_addr.s_addr = inet_addr(hostname); /* checks for n.n.n.n notation */
-  if(sin.sin_addr.s_addr == (unsigned long)-1) /* name isn't n.n.n.n so must be DNS */
+  saddr.sin_addr.s_addr = inet_addr(hostname); /* checks for n.n.n.n notation */
+  if(saddr.sin_addr.s_addr == (unsigned long)-1) /* name isn't n.n.n.n so must be DNS */
   {
     host_struct = gethostbyname(hostname);
     if(host_struct == 0L)
     {
-      icq_FmtLog(link, ICQ_LOG_FATAL, "Can't find hostname: %s\n", hostname);
-      if(link->icq_UseProxy)
+      icq_FmtLog(icqlink, ICQ_LOG_FATAL, "Can't find hostname: %s\n", hostname);
+      if(icqlink->icq_UseProxy)
       {
-        icq_SocketDelete(link->icq_ProxySok);
+        icq_SocketDelete(icqlink->icq_ProxySok);
       }
       return -1;
     }
-    sin.sin_addr = *((struct in_addr *)host_struct->h_addr);
+    saddr.sin_addr = *((struct in_addr *)host_struct->h_addr);
   }
-  if(link->icq_UseProxy)
+  if(icqlink->icq_UseProxy)
   {
-    link->icq_ProxyDestIP = ntohl(sin.sin_addr.s_addr);
-    memcpy(&sin.sin_addr.s_addr, &buf[4], 4);
+    icqlink->icq_ProxyDestIP = ntohl(saddr.sin_addr.s_addr);
+    memcpy(&saddr.sin_addr.s_addr, &buf[4], 4);
   }
-  sin.sin_family = AF_INET; /* we're using the inet not appletalk*/
-  sin.sin_port = htons(port); /* port */
-  if(link->icq_UseProxy)
+  saddr.sin_family = AF_INET; /* we're using the inet not appletalk*/
+  saddr.sin_port = htons(port); /* port */
+  if(icqlink->icq_UseProxy)
   {
-    link->icq_ProxyDestPort = port;
-    memcpy(&sin.sin_port, &buf[8], 2);
+    icqlink->icq_ProxyDestPort = port;
+    memcpy(&saddr.sin_port, &buf[8], 2);
   }
-  conct = connect(link->icq_UDPSok, (struct sockaddr*)&sin, sizeof(sin));
+  conct = connect(icqlink->icq_UDPSok, (struct sockaddr*)&saddr, sizeof(saddr));
   if(conct == -1) /* did we connect ?*/
   {
-    icq_FmtLog(link, ICQ_LOG_FATAL, "Connection refused\n");
-    if(link->icq_UseProxy)
+    icq_FmtLog(icqlink, ICQ_LOG_FATAL, "Connection refused\n");
+    if(icqlink->icq_UseProxy)
     {
-      icq_SocketDelete(link->icq_ProxySok);
+      icq_SocketDelete(icqlink->icq_ProxySok);
     }
     return -1;
   }
-  length = sizeof(sin) ;
-  getsockname(link->icq_UDPSok, (struct sockaddr*)&sin, &length);
-  link->icq_OurIP = ntohl(sin.sin_addr.s_addr);
-  link->icq_OurPort = ntohs(sin.sin_port);
+  length = sizeof(saddr) ;
+  getsockname(icqlink->icq_UDPSok, (struct sockaddr*)&saddr, &length);
+  icqlink->icq_OurIP = ntohl(saddr.sin_addr.s_addr);
+  icqlink->icq_OurPort = ntohs(saddr.sin_port);
 
   /* sockets are ready to receive data - install handlers */
-  icq_SocketSetHandler(link->icq_UDPSok, ICQ_SOCKET_READ,
-    (icq_SocketHandler)icq_HandleServerResponse, link);
-  if (link->icq_UseProxy)
-    icq_SocketSetHandler(link->icq_ProxySok, ICQ_SOCKET_READ,
-      (icq_SocketHandler)icq_HandleProxyResponse, link);
-  return link->icq_UDPSok;
+  icq_SocketSetHandler(icqlink->icq_UDPSok, ICQ_SOCKET_READ,
+    (icq_SocketHandler)icq_HandleServerResponse, icqlink);
+  if (icqlink->icq_UseProxy)
+    icq_SocketSetHandler(icqlink->icq_ProxySok, ICQ_SOCKET_READ,
+      (icq_SocketHandler)icq_HandleProxyResponse, icqlink);
+  return icqlink->icq_UDPSok;
 }
 
-void icq_Disconnect(ICQLINK *link)
+void icq_Disconnect(icq_Link *icqlink)
 {
-  icq_SocketDelete(link->icq_UDPSok);
-  if(link->icq_UseProxy)
+  icq_SocketDelete(icqlink->icq_UDPSok);
+  if(icqlink->icq_UseProxy)
   {
-    icq_SocketDelete(link->icq_ProxySok);
+    icq_SocketDelete(icqlink->icq_ProxySok);
   }
-  icq_UDPQueueFree(link);
+  icq_UDPQueueFree(icqlink);
 }
 
 /*
@@ -509,17 +507,17 @@
 /************************
 icq_UDPServMess functions
 *************************/
-BOOL icq_GetServMess(ICQLINK *link, WORD num)
+BOOL icq_GetServMess(icq_Link *icqlink, WORD num)
 {
-  return ((link->d->icq_UDPServMess[num/8] & (1 << (num%8))) >> (num%8));
+  return ((icqlink->d->icq_UDPServMess[num/8] & (1 << (num%8))) >> (num%8));
 }
 
-void icq_SetServMess(ICQLINK *link, WORD num)
+void icq_SetServMess(icq_Link *icqlink, WORD num)
 {
-  link->d->icq_UDPServMess[num/8] |= (1 << (num%8));
+  icqlink->d->icq_UDPServMess[num/8] |= (1 << (num%8));
 }
 
-int icq_GetSok(ICQLINK *link)
+int icq_GetSok(icq_Link *icqlink)
 {
-  return link->icq_UDPSok;
+  return icqlink->icq_UDPSok;
 }
--- a/plugins/icq/icqlib.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/icqlib.h	Tue May 29 10:32:53 2001 +0000
@@ -1,4 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _ICQLIB_H_
 #define _ICQLIB_H_
 
@@ -17,13 +38,11 @@
 #undef __USE_BSD
 #endif
 
-#include <sys/types.h>
-
+#include "icq.h"
 #include "util.h"
-#include "contacts.h"
 
-BOOL icq_GetServMess(ICQLINK *link, WORD num);
-void icq_SetServMess(ICQLINK *link, WORD num);
+BOOL icq_GetServMess(icq_Link *icqlink, WORD num);
+void icq_SetServMess(icq_Link *icqlink, WORD num);
 void icq_RusConv(const char to[4], char *t_in);
 void icq_RusConv_n(const char to[4], char *t_in, int len);
 
@@ -46,9 +65,9 @@
  * icqlib, but must be contained in the per-connection ICQLINK
  * struct.
  */
-typedef struct icq_link_private {
-
-  void *icq_ContactList;
+struct icq_LinkPrivate_s
+{
+  icq_List *icq_ContactList;
 
   /* 65536 seqs max, 1 bit per seq -> 65536/8 = 8192 */
   unsigned char icq_UDPServMess[8192]; 
@@ -56,14 +75,13 @@
   unsigned short icq_UDPSeqNum1, icq_UDPSeqNum2;
   unsigned long icq_UDPSession;
   
-  void *icq_UDPQueue;
+  icq_List *icq_UDPQueue;
 
   int icq_TCPSequence;
-  void *icq_TCPLinks;
-  void *icq_ChatSessions;
-  void *icq_FileSessions;
-
-} ICQLINK_private;
+  icq_List *icq_TCPLinks;
+  icq_List *icq_ChatSessions;
+  icq_List *icq_FileSessions;
+};
 
 #define invoke_callback(plink, callback) \
    if (plink->callback) (*(plink->callback))
--- a/plugins/icq/icqpacket.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/icqpacket.c	Tue May 29 10:32:53 2001 +0000
@@ -1,67 +1,30 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: icqpacket.c 1442 2001-01-28 01:52:27Z warmenhoven $
-$Log$
-Revision 1.3  2001/01/28 01:52:27  warmenhoven
-icqlib 1.1.5
-
-Revision 1.10  2000/07/07 15:26:35  denis
-"icq_Packet data overflow" log message temporarily commented out.
-
-Revision 1.9  2000/06/25 16:26:36  denis
-icq_PacketUDPDump() tweaked a little.
-
-Revision 1.8  2000/05/03 18:20:40  denis
-icq_PacketReadUDPInUIN() was added.
-
-Revision 1.7  2000/04/05 14:37:02  denis
-Applied patch from "Guillaume R." <grs@mail.com> for basic Win32
-compatibility.
-
-Revision 1.6  2000/01/16 03:59:10  bills
-reworked list code so list_nodes don't need to be inside item structures,
-removed strlist code and replaced with generic list calls
-
-Revision 1.5  1999/09/29 19:58:20  bills
-cleanup
 
-Revision 1.4  1999/09/29 16:56:10  denis
-Cleanups.
-
-Revision 1.3  1999/07/18 20:18:43  bills
-changed to use new byte-order functions
-
-Revision 1.2  1999/07/16 15:45:05  denis
-Cleaned up.
-
-Revision 1.1  1999/07/16 12:11:36  denis
-UDP packet support added.
-tcp_packet* functions renamed to icq_Packet*
-
-Revision 1.8  1999/07/12 15:13:38  cproch
-- added definition of ICQLINK to hold session-specific global variabled
-  applications which have more than one connection are now possible
-- changed nearly every function defintion to support ICQLINK parameter
-
-Revision 1.7  1999/07/03 06:33:52  lord
-. byte order conversion macros added
-. some compilation warnings removed
-
-Revision 1.6  1999/04/17 19:36:50  bills
-added tcp_packet_node_delete function and changed structure to include
-list_node for new list routines.
-
-Revision 1.5  1999/04/14 15:08:04  denis
-Cleanups for "strict" compiling (-ansi -pedantic)
-
-*/
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 /*
  * ICQ packet abstraction
  */
 
 #include <stdlib.h>
-#include <sys/types.h>
 
 #ifdef _WIN32
 #include <winsock.h>
@@ -69,14 +32,9 @@
 #include <sys/socket.h>
 #endif
 
-#include "icqtypes.h"
-#include "icq.h"
 #include "icqlib.h"
-#include "icqpacket.h"
 #include "tcp.h"
-#include "util.h"
 #include "icqbyteorder.h"
-#include "list.h"
 
 icq_Packet *icq_PacketNew()
 {
@@ -371,11 +329,11 @@
   return p->cursor;
 }
 
-int icq_PacketSend(icq_Packet *p, int socket)
+int icq_PacketSend(icq_Packet *p, int socket_fd)
 {
   int result;
 
-  result=send(socket, (const char*)&(p->length), p->length+sizeof(WORD), 0);
+  result=send(socket_fd, (const char*)&(p->length), p->length+sizeof(WORD), 0);
 
 #ifdef TCP_RAW_TRACE
   printf("%d bytes sent on socket %d, result %d\n", 
--- a/plugins/icq/icqpacket.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/icqpacket.h	Tue May 29 10:32:53 2001 +0000
@@ -1,4 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _ICQ_PACKET_H_
 #define _ICQ_PACKET_H_
 
--- a/plugins/icq/icqtypes.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/icqtypes.h	Tue May 29 10:32:53 2001 +0000
@@ -1,4 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _ICQTYPES_H_
 #define _ICQTYPES_H_
 
--- a/plugins/icq/list.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/list.c	Tue May 29 10:32:53 2001 +0000
@@ -1,24 +1,24 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: list.c 1508 2001-02-22 23:07:34Z warmenhoven $
-$Log$
-Revision 1.4  2001/02/22 23:07:34  warmenhoven
-updating icqlib
-
-Revision 1.15  2001/02/22 05:38:45  bills
-added sorted list capability - see list_insert_sorted and new
-compare_function list struct member
 
-Revision 1.14  2000/07/10 01:44:20  bills
-i really don't learn - removed LIST_TRACE define
-
-Revision 1.13  2000/07/10 01:43:48  bills
-argh - last list buglet fixed, removed free(node) call from list_free
-
-Revision 1.12  2000/07/10 01:31:17  bills
-oops - removed #define LIST_TRACE and #define QUEUE_DEBUG
-
-*/
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 /*
  * linked list functions
@@ -29,9 +29,9 @@
 
 #include "list.h"
 
-list *list_new()
+icq_List *icq_ListNew()
 {
-  list *plist=(list *)malloc(sizeof(list));
+  icq_List *plist=(icq_List *)malloc(sizeof(icq_List));
 
   plist->head=0;
   plist->tail=0;
@@ -41,36 +41,37 @@
 }
 
 /* Frees all list nodes and list itself */
-void list_delete(list *plist, void (*item_free_f)(void *))
+void icq_ListDelete(icq_List *plist, void (*item_free_f)(void *))
 {
-  list_free(plist, item_free_f);
+  if (item_free_f)
+    icq_ListFree(plist, item_free_f);
   free(plist);
 }
 
 /* Only frees the list nodes */
-void list_free(list *plist, void (*item_free_f)(void *))
+void icq_ListFree(icq_List *plist, void (*item_free_f)(void *))
 {
-  list_node *p=plist->head;
+  icq_ListNode *p=plist->head;
 
 #ifdef LIST_TRACE
-  printf("list_free(%p)\n", plist);
-  list_dump(plist);
+  printf("icq_ListFree(%p)\n", plist);
+  icq_ListDump(plist);
 #endif
 
   while(p)
   {
-    list_node *ptemp=p;
+    icq_ListNode *ptemp=p;
 
     p=p->next;
     (*item_free_f)((void *)ptemp->item);
-    list_remove_node(plist, ptemp);
+    icq_ListRemoveNode(plist, ptemp);
   }
 }
 
-void list_insert_sorted(list *plist, void *pitem)
+void icq_ListInsertSorted(icq_List *plist, void *pitem)
 {
-  list_node *i=plist->head;
-  int done;
+  icq_ListNode *i=plist->head;
+  int done = 0;
 
   while (i && !done)
   {
@@ -80,12 +81,12 @@
       i=i->next;
   }
 
-  list_insert(plist, i, pitem);
+  icq_ListInsert(plist, i, pitem);
 }
 
-void list_insert(list *plist, list_node *pnode, void *pitem)
+void icq_ListInsert(icq_List *plist, icq_ListNode *pnode, void *pitem)
 {
-  list_node *pnew=(list_node *)malloc(sizeof(list_node));
+  icq_ListNode *pnew=(icq_ListNode *)malloc(sizeof(icq_ListNode));
   pnew->item=pitem;
 
 #ifdef LIST_TRACE
@@ -94,7 +95,7 @@
  
   plist->count++;
 
-  /* null source node signifies insert at end of list */
+  /* null source node signifies insert at end of icq_List */
   if(!pnode) 
   {
     pnew->previous=plist->tail;
@@ -122,11 +123,11 @@
   }
 
 #ifdef LIST_TRACE
-  list_dump(plist);
+  icq_ListDump(plist);
 #endif
 }
 
-void *list_remove_node(list *plist, list_node *p)
+void *icq_ListRemoveNode(icq_List *plist, icq_ListNode *p)
 {
   void *pitem;
 
@@ -155,7 +156,7 @@
   p->previous=0;
 
 #ifdef LIST_TRACE
-  list_dump(plist);
+  icq_ListDump(plist);
 #endif
 
   pitem=p->item;
@@ -165,15 +166,15 @@
   return pitem;
 }
 
-void *list_traverse(list *plist, int (*item_f)(void *, va_list), ...)
+void *icq_ListTraverse(icq_List *plist, int (*item_f)(void *, va_list), ...)
 {
-  list_node *i=plist->head;
+  icq_ListNode *i=plist->head;
   int f=0;
   va_list ap;
 
 #ifdef LIST_TRACE
-  printf("list_traverse(%p)\n", plist);
-  list_dump(plist);
+  printf("icq_ListTraverse(%p)\n", plist);
+  icq_ListDump(plist);
 #endif
   va_start(ap, item_f);
 
@@ -181,7 +182,7 @@
    * function returns 0 */
   while(i && !f)
   {
-    list_node *pnext=i->next;
+    icq_ListNode *pnext=i->next;
 
     if(!(f=(*item_f)(i->item, ap)))
       i=pnext;
@@ -195,9 +196,9 @@
     return 0;
 }
 
-int list_dump(list *plist)
+int icq_ListDump(icq_List *plist)
 {
-  list_node *p=plist->head;
+  icq_ListNode *p=plist->head;
 
   printf("list %x { head=%x, tail=%x, count=%d }\ncontents: ",
          (int)plist, (int)plist->head, (int)plist->tail, plist->count);
@@ -212,7 +213,7 @@
   return 0;
 }
 
-void *list_first(list *plist)
+void *icq_ListFirst(icq_List *plist)
 {
   if(plist->head)
     return plist->head->item;
@@ -220,7 +221,7 @@
     return 0;
 }
 
-void *list_last(list *plist)
+void *icq_ListLast(icq_List *plist)
 {
   if(plist->tail)
     return plist->tail->item;
@@ -228,9 +229,9 @@
     return 0;
 }
 
-void *list_at(list *plist, int num)
+void *icq_ListAt(icq_List *plist, int num)
 {
-  list_node *ptr = plist->head;
+  icq_ListNode *ptr = plist->head;
   while(ptr && num)
   {
     num--;
@@ -242,9 +243,9 @@
     return 0L;
 }
 
-list_node *list_find(list *plist, void *pitem)
+icq_ListNode *icq_ListFind(icq_List *plist, void *pitem)
 {
-  list_node *p=plist->head;
+  icq_ListNode *p=plist->head;
 
   while(p)
   {
@@ -255,12 +256,12 @@
   return 0;
 }
 
-void *list_remove(list *plist, void *pitem)
+void *icq_ListRemove(icq_List *plist, void *pitem)
 {
-  list_node *p=list_find(plist, pitem);
+  icq_ListNode *p=icq_ListFind(plist, pitem);
 
   if(p)
-    return list_remove_node(plist, p);
+    return icq_ListRemoveNode(plist, p);
   else
     return 0;
 }
--- a/plugins/icq/list.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/list.h	Tue May 29 10:32:53 2001 +0000
@@ -1,4 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _LIST_H
 #define _LIST_H
 
@@ -8,43 +29,43 @@
 
 #include <stdarg.h>
 
-#define list_enqueue(plist, p) \
-   list_insert(plist, 0, p)
+#define icq_ListEnqueue(plist, p) \
+   icq_ListInsert(plist, 0, p)
 
-#define list_dequeue(plist) \
-  list_remove_node(plist, plist->head)
+#define icq_ListDequeue(plist) \
+  icq_ListRemoveNode(plist, plist->head)
 
-typedef struct list_node_s list_node;
-typedef struct list_s list;
+typedef struct icq_ListNode_s icq_ListNode;
+typedef struct icq_List_s icq_List;
 typedef int (*icq_ListCompareFunc)(void *o1, void *o2);
 
-struct list_node_s
+struct icq_ListNode_s
 {
-  list_node *next;
-  list_node *previous;
+  icq_ListNode *next;
+  icq_ListNode *previous;
   void *item;
 };
 
-struct list_s
+struct icq_List_s
 {
-  list_node *head;
-  list_node *tail;
+  icq_ListNode *head;
+  icq_ListNode *tail;
   int count;
   icq_ListCompareFunc compare_function;
 };
 
-list *list_new(void);
-void list_delete(list *plist, void (*item_free_f)(void *));
-void list_free(list *plist, void (*item_free_f)(void *));
-void list_insert_sorted(list *plist, void *pitem);
-void list_insert(list *plist, list_node *pnode, void *pitem);
-void *list_remove(list *plist, void *pitem);
-void *list_traverse(list *plist, int (*item_f)(void *, va_list), ...);
-int list_dump(list *plist);
-void *list_first(list *plist);
-void *list_last(list *plist);
-void *list_at(list *plist, int num);
-list_node *list_find(list *plist, void *pitem);
-void *list_remove_node(list *plist, list_node *p);
+icq_List *icq_ListNew(void);
+void icq_ListDelete(icq_List *plist, void (*item_free_f)(void *));
+void icq_ListFree(icq_List *plist, void (*item_free_f)(void *));
+void icq_ListInsertSorted(icq_List *plist, void *pitem);
+void icq_ListInsert(icq_List *plist, icq_ListNode *pnode, void *pitem);
+void *icq_ListRemove(icq_List *plist, void *pitem);
+void *icq_ListTraverse(icq_List *plist, int (*item_f)(void *, va_list), ...);
+int icq_ListDump(icq_List *plist);
+void *icq_ListFirst(icq_List *plist);
+void *icq_ListLast(icq_List *plist);
+void *icq_ListAt(icq_List *plist, int num);
+icq_ListNode *icq_ListFind(icq_List *plist, void *pitem);
+void *icq_ListRemoveNode(icq_List *plist, icq_ListNode *p);
 
 #endif /* _LIST_H */
--- a/plugins/icq/proxy.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/proxy.c	Tue May 29 10:32:53 2001 +0000
@@ -1,116 +1,88 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: proxy.c 1442 2001-01-28 01:52:27Z warmenhoven $
-$Log$
-Revision 1.3  2001/01/28 01:52:27  warmenhoven
-icqlib 1.1.5
-
-Revision 1.9  2001/01/17 01:19:49  bills
-cleanup
-
-Revision 1.8  2000/05/10 18:51:23  denis
-icq_Disconnect() now called before icq_Disconnected callback to
-prevent high CPU usage in kicq's "reconnect on disconnect" code.
-
-Revision 1.7  2000/05/03 18:29:15  denis
-Callbacks have been moved to the ICQLINK structure.
-
-Revision 1.6  2000/04/05 14:37:02  denis
-Applied patch from "Guillaume R." <grs@mail.com> for basic Win32
-compatibility.
-
-Revision 1.5  1999/10/07 18:00:59  denis
-proxy.h file removed.
 
-Revision 1.4  1999/07/16 12:01:06  denis
-ICQLINK support added.
-
-Revision 1.3  1999/07/12 15:13:33  cproch
-- added definition of ICQLINK to hold session-specific global variabled
-  applications which have more than one connection are now possible
-- changed nearly every function defintion to support ICQLINK parameter
-
-Revision 1.2  1999/04/14 14:51:42  denis
-Switched from icq_Log callback to icq_Fmt function.
-Cleanups for "strict" compiling (-ansi -pedantic)
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
-Revision 1.1  1999/03/24 11:37:38  denis
-Underscored files with TCP stuff renamed.
-TCP stuff cleaned up
-Function names changed to corresponding names.
-icqlib.c splitted to many small files by subject.
-C++ comments changed to ANSI C comments.
-
-*/
-
-#ifndef _WIN32
-#include <unistd.h>
-#else
+#ifdef _WIN32
 #include <winsock.h>
 #endif
 
 #include <stdlib.h>
 
-#include "util.h"
-#include "icqtypes.h"
-#include "icq.h"
 #include "icqlib.h"
 
-void icq_HandleProxyResponse(ICQLINK *link)
+void icq_HandleProxyResponse(icq_Link *icqlink)
 {
   int s;
   char buf[256];
 #ifdef _WIN32
-  s = recv(link->icq_ProxySok, buf, sizeof(buf), 0);
+  s = recv(icqlink->icq_ProxySok, buf, sizeof(buf), 0);
 #else
-  s = read(link->icq_ProxySok, &buf, sizeof(buf));
+  s = read(icqlink->icq_ProxySok, &buf, sizeof(buf));
 #endif
   if(s<=0)
   {
-    icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Connection terminated\n");
-    icq_Disconnect(link);
-    if(link->icq_Disconnected)
-      (*link->icq_Disconnected)(link);
+    icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Connection terminated\n");
+    icq_Disconnect(icqlink);
+    invoke_callback(icqlink, icq_Disconnected)(icqlink);
   }
 }
 
 /*******************
 SOCKS5 Proxy support
 ********************/
-void icq_SetProxy(ICQLINK *link, const char *phost, unsigned short pport, int pauth, const char *pname, const char *ppass)
+void icq_SetProxy(icq_Link *icqlink, const char *phost, unsigned short pport, 
+  int pauth, const char *pname, const char *ppass)
 {
-  if(link->icq_ProxyHost)
-    free(link->icq_ProxyHost);
-  if(link->icq_ProxyName)
-    free(link->icq_ProxyName);
-  if(link->icq_ProxyPass)
-    free(link->icq_ProxyPass);
+  if(icqlink->icq_ProxyHost)
+    free(icqlink->icq_ProxyHost);
+  if(icqlink->icq_ProxyName)
+    free(icqlink->icq_ProxyName);
+  if(icqlink->icq_ProxyPass)
+    free(icqlink->icq_ProxyPass);
   if(strlen(pname)>255)
   {
-    icq_FmtLog(link, ICQ_LOG_ERROR, "[SOCKS] User name greater than 255 chars\n");
-    link->icq_UseProxy = 0;
+    icq_FmtLog(icqlink, ICQ_LOG_ERROR, "[SOCKS] User name greater than 255 chars\n");
+    icqlink->icq_UseProxy = 0;
     return;
   }
   if(strlen(ppass)>255)
   {
-    icq_FmtLog(link, ICQ_LOG_ERROR, "[SOCKS] User password greater than 255 chars\n");
-    link->icq_UseProxy = 0;
+    icq_FmtLog(icqlink, ICQ_LOG_ERROR, "[SOCKS] User password greater than 255 chars\n");
+    icqlink->icq_UseProxy = 0;
     return;
   }
-  link->icq_UseProxy = 1;
-  link->icq_ProxyHost = strdup(phost);
-  link->icq_ProxyPort = pport;
-  link->icq_ProxyAuth = pauth;
-  link->icq_ProxyName = strdup(pname);
-  link->icq_ProxyPass = strdup(ppass);
+  icqlink->icq_UseProxy = 1;
+  icqlink->icq_ProxyHost = strdup(phost);
+  icqlink->icq_ProxyPort = pport;
+  icqlink->icq_ProxyAuth = pauth;
+  icqlink->icq_ProxyName = strdup(pname);
+  icqlink->icq_ProxyPass = strdup(ppass);
 }
 
-void icq_UnsetProxy(ICQLINK *link)
+void icq_UnsetProxy(icq_Link *icqlink)
 {
-  link->icq_UseProxy = 0;
+  icqlink->icq_UseProxy = 0;
 }
 
-int icq_GetProxySok(ICQLINK *link)
+int icq_GetProxySok(icq_Link *icqlink)
 {
-  return link->icq_ProxySok;
+  return icqlink->icq_ProxySok;
 }
--- a/plugins/icq/queue.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/queue.c	Tue May 29 10:32:53 2001 +0000
@@ -1,70 +1,37 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: queue.c 1508 2001-02-22 23:07:34Z warmenhoven $
-$Log$
-Revision 1.5  2001/02/22 23:07:34  warmenhoven
-updating icqlib
-
-Revision 1.13  2001/02/22 05:40:04  bills
-port tcp connect timeout code and UDP queue to new timeout manager
-
-Revision 1.12  2000/12/19 06:00:07  bills
-moved members from ICQLINK to ICQLINK_private struct
-
-Revision 1.11  2000/12/06 05:15:45  denis
-Handling for mass TCP messages has been added based on patch by
-Konstantin Klyagin <konst@konst.org.ua>
-
-Revision 1.10  2000/12/03 21:56:38  bills
-fixed compilation with gcc-2.96
-
-Revision 1.9  2000/07/10 01:31:17  bills
-oops - removed #define LIST_TRACE and #define QUEUE_DEBUG
 
-Revision 1.8  2000/07/10 01:26:56  bills
-added more trace messages, reworked packet delete handling: now happens
-during _icq_UDEQueueItemFree rather than during icq_UDPQueueDelSeq - fixes
-memory leak
-
-Revision 1.7  2000/07/09 22:07:37  bills
-use new list_free
-
-Revision 1.6  2000/06/25 16:30:05  denis
-Some sanity checks were added to icq_UDPQueueDelete() and
-icq_UDPQueueFree()
-
-Revision 1.5  2000/05/10 19:06:59  denis
-UDP outgoing packet queue was implemented.
-
-Revision 1.4  2000/03/30 14:15:28  denis
-Fixed FreeBSD warning about obsolete malloc.h header.
-
-Revision 1.3  2000/01/16 03:59:10  bills
-reworked list code so list_nodes don't need to be inside item structures,
-removed strlist code and replaced with generic list calls
-
-Revision 1.2  1999/09/29 17:06:47  denis
-ICQLINK compatibility added.
-
-Revision 1.1  1999/07/16 12:12:13  denis
-Initial support for outgoing packet queue added.
-
-*/
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #include <stdlib.h>
-#include <time.h>
 
 #include "icqlib.h"
 #include "queue.h"
-#include "list.h"
 
-void icq_UDPQueueNew(ICQLINK *link)
+void icq_UDPQueueNew(icq_Link *icqlink)
 {
-  link->d->icq_UDPQueue = list_new();
-  link->icq_UDPExpireInterval = 15; /* expire interval = 15 sec */
+  icqlink->d->icq_UDPQueue = icq_ListNew();
+  icqlink->icq_UDPExpireInterval = 15; /* expire interval = 15 sec */
 }
 
-void icq_UDPQueuePut(ICQLINK *link, icq_Packet *p)
+void icq_UDPQueuePut(icq_Link *icqlink, icq_Packet *p)
 {
   icq_UDPQueueItem *ptr = (icq_UDPQueueItem*)malloc(sizeof(icq_UDPQueueItem));
 #ifdef QUEUE_DEBUG
@@ -72,15 +39,15 @@
          icq_PacketReadUDPOutCmd(p));
 #endif
   ptr->attempts = 1;
-  ptr->timeout = icq_TimeoutNew(link->icq_UDPExpireInterval, 
+  ptr->timeout = icq_TimeoutNew(icqlink->icq_UDPExpireInterval, 
     (icq_TimeoutHandler)icq_UDPQueueItemResend, ptr);
   ptr->timeout->single_shot = 0;
   ptr->pack = p;
-  ptr->icqlink = link;
+  ptr->icqlink = icqlink;
 #ifdef QUEUE_DEBUG
   printf("enqueuing queueitem %p\n", ptr);
 #endif
-  list_enqueue(link->d->icq_UDPQueue, ptr);
+  icq_ListEnqueue(icqlink->d->icq_UDPQueue, ptr);
 }
 
 void _icq_UDPQueueItemFree(void *p)
@@ -101,26 +68,26 @@
 }
 
 /* Frees the queue and dispose it */
-void icq_UDPQueueDelete(ICQLINK *link)
+void icq_UDPQueueDelete(icq_Link *icqlink)
 {
 #ifdef QUEUE_DEBUG
   printf("icq_UDPQueueDelete\n");
 #endif
-  if(link->d->icq_UDPQueue)
+  if(icqlink->d->icq_UDPQueue)
   {
-    list_delete(link->d->icq_UDPQueue, _icq_UDPQueueItemFree);
-    link->d->icq_UDPQueue = 0;
+    icq_ListDelete(icqlink->d->icq_UDPQueue, _icq_UDPQueueItemFree);
+    icqlink->d->icq_UDPQueue = 0;
   }
 }
 
 /* Only frees the queue */
-void icq_UDPQueueFree(ICQLINK *link)
+void icq_UDPQueueFree(icq_Link *icqlink)
 {
 #ifdef QUEUE_DEBUG
   printf("icq_UDPQueueFree\n");
 #endif
-  if(link->d->icq_UDPQueue)
-    list_free(link->d->icq_UDPQueue, _icq_UDPQueueItemFree);
+  if(icqlink->d->icq_UDPQueue)
+    icq_ListFree(icqlink->d->icq_UDPQueue, _icq_UDPQueueItemFree);
 }
 
 int icq_UDPQueueFindSeq(void *p, va_list data)
@@ -129,19 +96,19 @@
   return icq_PacketReadUDPOutSeq1(((icq_UDPQueueItem *)p)->pack) == seq;
 }
 
-void icq_UDPQueueDelSeq(ICQLINK *link, WORD seq)
+void icq_UDPQueueDelSeq(icq_Link *icqlink, WORD seq)
 {
   icq_UDPQueueItem *ptr;
 #ifdef QUEUE_DEBUG
   printf("icq_UDPQueueDelSeq(seq=0x%04X", seq);
 #endif
-  ptr = list_traverse(link->d->icq_UDPQueue, icq_UDPQueueFindSeq, seq);
+  ptr = icq_ListTraverse(icqlink->d->icq_UDPQueue, icq_UDPQueueFindSeq, seq);
   if(ptr)
   {
 #ifdef QUEUE_DEBUG
     printf(", cmd=0x%04X",icq_PacketReadUDPOutCmd(ptr->pack));
 #endif
-    list_remove(link->d->icq_UDPQueue, ptr);
+    icq_ListRemove(icqlink->d->icq_UDPQueue, ptr);
     _icq_UDPQueueItemFree(ptr);
   }
 #ifdef QUEUE_DEBUG
--- a/plugins/icq/queue.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/queue.h	Tue May 29 10:32:53 2001 +0000
@@ -1,4 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _QUEUE_H_
 #define _QUEUE_H_
 
@@ -10,20 +31,20 @@
 #include "icqpacket.h"
 #include "timeout.h"
 
-typedef struct udp_item
+typedef struct icq_UDPQueueItem_s
 {
   unsigned char attempts;
   icq_Timeout *timeout;
   icq_Packet *pack;
-  ICQLINK *icqlink;
+  icq_Link *icqlink;
 } icq_UDPQueueItem;
 
-void icq_UDPQueueNew(ICQLINK*);
-void icq_UDPQueueFree(ICQLINK*);
-void icq_UDPQueuePut(ICQLINK*, icq_Packet*);
-void icq_UDPQueueDelete(ICQLINK*);
-void icq_UDPQueueFree(ICQLINK*);
-void icq_UDPQueueDelSeq(ICQLINK*, WORD);
+void icq_UDPQueueNew(icq_Link *);
+void icq_UDPQueueFree(icq_Link *);
+void icq_UDPQueuePut(icq_Link *, icq_Packet*);
+void icq_UDPQueueDelete(icq_Link *);
+void icq_UDPQueueFree(icq_Link *);
+void icq_UDPQueueDelSeq(icq_Link *, WORD);
 void icq_UDPQueueItemResend(icq_UDPQueueItem *pitem);
 
 #endif
--- a/plugins/icq/socketmanager.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/socketmanager.c	Tue May 29 10:32:53 2001 +0000
@@ -1,10 +1,24 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
 /*
-  $Id: socketmanager.c 1539 2001-03-03 12:56:25Z warmenhoven $
-*/
-
-#include "socketmanager.h"
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 /**
  * The icqlib socket manager is a simple socket abstraction layer, which
@@ -26,32 +40,23 @@
  *
  */
 
-/* need to track:
- *   socket wants read notification
- *   socket no longer wants read notification
- *   socket wants write notification
- *   socket no longer wants write notification
- */
+#include <stdlib.h>
 
-#include <sys/types.h>
-
-#ifndef _WIN32
-#include <unistd.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-#else
+#ifdef _WIN32
 #include <winsock.h>
 #endif
 
-list *icq_SocketList = NULL;
+#include "socketmanager.h"
+
+icq_List *icq_SocketList = NULL;
 fd_set icq_FdSets[ICQ_SOCKET_MAX];
 int icq_MaxSocket;
 
-void (*icq_SocketNotify)(int socket, int type, int status);
+void (*icq_SocketNotify)(int socket_fd, int type, int status);
 
 /**
  * Creates a new socket using the operating system's socket creation
- * facitily.
+ * facility.
  */
 int icq_SocketNew(int domain, int type, int protocol)
 {
@@ -67,7 +72,7 @@
  * Creates a new socket by accepting a connection from a listening
  * socket.
  */
-int icq_SocketAccept(int listens, struct sockaddr *addr, int *addrlen)
+int icq_SocketAccept(int listens, struct sockaddr *addr, socklen_t *addrlen)
 {
   int s = accept(listens, addr, addrlen);
 
@@ -91,7 +96,7 @@
     for (i=0; i<ICQ_SOCKET_MAX; i++)
       psocket->handlers[i] = NULL;
 
-    list_enqueue(icq_SocketList, psocket);
+    icq_ListEnqueue(icq_SocketList, psocket);
   }
 }  
 
@@ -100,17 +105,17 @@
  * through the icq_SocketNotify callback if the socket had an installed
  * read or write handler.
  */
-int icq_SocketDelete(int socket)
+int icq_SocketDelete(int socket_fd)
 {
 #ifdef _WIN32
-  int result = closesocket(socket);
+  int result = closesocket(socket_fd);
 #else
-  int result = close(socket);
+  int result = close(socket_fd);
 #endif
 
   if (result != -1)
   {
-    icq_Socket *s = icq_FindSocket(socket);
+    icq_Socket *s = icq_FindSocket(socket_fd);
     int i;
 
     /* uninstall all handlers - this will take care of notifing library
@@ -121,7 +126,7 @@
         icq_SocketSetHandler(s->socket, i, NULL, NULL);
     }
 
-    list_remove(icq_SocketList, s);
+    icq_ListRemove(icq_SocketList, s);
     free(s);
   }
 
@@ -135,16 +140,16 @@
  * addition, user data can be passed to the callback function through
  * the data member.
  */
-void icq_SocketSetHandler(int socket, int type, icq_SocketHandler handler, 
+void icq_SocketSetHandler(int socket_fd, int type, icq_SocketHandler handler, 
   void *data)
 {
-  icq_Socket *s = icq_FindSocket(socket);
+  icq_Socket *s = icq_FindSocket(socket_fd);
   if (s)
   {
     s->data[type] = data;
     s->handlers[type] = handler;
     if (icq_SocketNotify)
-      (*icq_SocketNotify)(socket, type, handler ? 1 : 0);
+      (*icq_SocketNotify)(socket_fd, type, handler ? 1 : 0);
   }
 }
 
@@ -160,16 +165,17 @@
   }
 }
 
-void icq_HandleReadySocket(int socket, int type)
+void icq_HandleReadySocket(int socket_fd, int type)
 {
-  icq_SocketReady(icq_FindSocket(socket), type);
+  icq_SocketReady(icq_FindSocket(socket_fd), type);
 }
   
 int _icq_SocketBuildFdSets(void *p, va_list data)
 {
   icq_Socket *s = p;
   int i;
-
+  (void)data;
+  
   for (i=0; i<ICQ_SOCKET_MAX; i++)
     if (s->handlers[i]) {
       FD_SET(s->socket, &(icq_FdSets[i]));
@@ -177,7 +183,7 @@
         icq_MaxSocket = s->socket;
     }
 
-  return 0; /* traverse entire list */
+  return 0; /* traverse entire icq_List */
 }
 
 void icq_SocketBuildFdSets()
@@ -191,27 +197,26 @@
   icq_MaxSocket = 0;
   
   /* build fd lists for open sockets */
-  (void)list_traverse(icq_SocketList, _icq_SocketBuildFdSets);
+  (void)icq_ListTraverse(icq_SocketList, _icq_SocketBuildFdSets);
 }
 
 int _icq_SocketHandleReady(void *p, va_list data)
 {
   icq_Socket *s = p;
   int i;
-
+  (void)data;
+  
   for (i=0; i<ICQ_SOCKET_MAX; i++)
     if (FD_ISSET(s->socket, &(icq_FdSets[i]))) {
       icq_SocketReady(s, i);
     }
 
-  return 0; /* traverse entire list */
+  return 0; /* traverse entire icq_List */
 }
       
 void icq_SocketPoll()
 {
   struct timeval tv;
-  int max_socket = 0;
-  int i;
 
   icq_SocketBuildFdSets();
   
@@ -222,18 +227,18 @@
     &(icq_FdSets[ICQ_SOCKET_WRITE]), NULL, &tv);
 
   /* handle ready sockets */
-  (void)list_traverse(icq_SocketList, _icq_SocketHandleReady);
+  (void)icq_ListTraverse(icq_SocketList, _icq_SocketHandleReady);
 }
 
 int _icq_FindSocket(void *p, va_list data)
 {
-  int socket = va_arg(data, int);
-  return (((icq_Socket *)p)->socket == socket);
+  int socket_fd = va_arg(data, int);
+  return (((icq_Socket *)p)->socket == socket_fd);
 }
 
-icq_Socket *icq_FindSocket(int socket)
+icq_Socket *icq_FindSocket(int socket_fd)
 {
-  return list_traverse(icq_SocketList, _icq_FindSocket, socket);
+  return icq_ListTraverse(icq_SocketList, _icq_FindSocket, socket_fd);
 }
 
 
--- a/plugins/icq/socketmanager.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/socketmanager.h	Tue May 29 10:32:53 2001 +0000
@@ -1,4 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _SOCKETMANAGER_H
 #define _SOCKETMANAGER_H
 
@@ -6,7 +27,6 @@
 #include <config.h>
 #endif
 
-#include <sys/types.h>
 #include <sys/socket.h>
 
 #include "icq.h"
@@ -24,16 +44,16 @@
 };
 
 int icq_SocketNew(int domain, int type, int protocol);
-int icq_SocketAccept(int listens, struct sockaddr *addr, int *addrlen);
-void icq_SocketAlloc(int s);
-int icq_SocketDelete(int socket);
-void icq_SocketSetHandler(int socket, int type, icq_SocketHandler handler,
+int icq_SocketAccept(int listens, struct sockaddr *addr, socklen_t *addrlen);
+void icq_SocketAlloc(int socket_fd);
+int icq_SocketDelete(int socket_fd);
+void icq_SocketSetHandler(int socket_fd, int type, icq_SocketHandler handler,
   void *data);
 void icq_SocketReady(icq_Socket *s, int type);
 void icq_SocketBuildFdSets(void);
 void icq_SocketPoll();
-icq_Socket *icq_FindSocket(int socket);
+icq_Socket *icq_FindSocket(int socket_fd);
 
-extern list *icq_SocketList;
+extern icq_List *icq_SocketList;
 
 #endif /* _SOCKETMANAGER_H */
--- a/plugins/icq/stdpackets.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/stdpackets.c	Tue May 29 10:32:53 2001 +0000
@@ -1,69 +1,27 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: stdpackets.c 1442 2001-01-28 01:52:27Z warmenhoven $
-$Log$
-Revision 1.3  2001/01/28 01:52:27  warmenhoven
-icqlib 1.1.5
-
-Revision 1.12  2001/01/24 05:11:14  bills
-applied patch from Robin Ericsson <lobbin@localhost.nu> which implements
-receiving contact lists.  See new icq_RecvContactList callback.
-
-Revision 1.11  2000/12/19 06:00:07  bills
-moved members from ICQLINK to ICQLINK_private struct
-
-Revision 1.10  2000/06/15 01:51:23  bills
-added creation functions for cancel and refuse operations
-
-Revision 1.9  2000/05/04 15:50:38  bills
-warning cleanups
-
-Revision 1.8  2000/04/10 18:11:45  denis
-ANSI cleanups.
-
-Revision 1.7  2000/04/06 16:38:04  denis
-icq_*Send*Seq() functions with specified sequence number were added.
-
-Revision 1.6  2000/02/07 02:35:13  bills
-slightly modified chat packets
 
-Revision 1.5  2000/01/20 19:59:15  bills
-first implementation of sending file requests
-
-Revision 1.4  1999/09/29 20:12:32  bills
-tcp_link*->icq_TCPLink*
-
-Revision 1.3  1999/09/29 17:07:48  denis
-Host/network byteorder cleanups.
-
-Revision 1.2  1999/07/16 15:45:20  denis
-Cleaned up.
-
-Revision 1.1  1999/07/16 12:13:11  denis
-UDP packets support added.
-tcppackets.[ch] files renamed to stdpackets.[ch]
-
-Revision 1.9  1999/07/12 15:13:39  cproch
-- added definition of ICQLINK to hold session-specific global variabled
-  applications which have more than one connection are now possible
-- changed nearly every function defintion to support ICQLINK parameter
-
-Revision 1.8  1999/05/03 21:41:28  bills
-initial file xfer support added- untested
-
-Revision 1.7  1999/04/17 19:39:09  bills
-added new functions to create chat packets. removed unnecessary code.
-added new function to create URL ack packet.
-
-Revision 1.6  1999/04/14 15:08:39  denis
-Cleanups for "strict" compiling (-ansi -pedantic)
-
-*/
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #include <stdlib.h>
 
-#include "icqtypes.h"
-#include "icq.h"
 #include "icqlib.h"
 #include "tcp.h"
 #include "stdpackets.h"
@@ -97,7 +55,7 @@
 }
 
 icq_Packet *icq_TCPCreateStdPacket(icq_TCPLink *plink, WORD icq_TCPCommand,
-               WORD type, const unsigned char *msg, WORD status,
+               WORD type, const char *msg, WORD status,
                WORD msg_command)
 {
   icq_Packet *p=icq_PacketNew();
@@ -126,7 +84,7 @@
   return p;
 }
 
-icq_Packet *icq_TCPCreateMessagePacket(icq_TCPLink *plink, const unsigned char *message)
+icq_Packet *icq_TCPCreateMessagePacket(icq_TCPLink *plink, const char *message)
 {
   icq_Packet *p=icq_TCPCreateStdPacket(
     plink,
@@ -153,7 +111,7 @@
     plink,
     ICQ_TCP_MESSAGE,
     ICQ_TCP_MSG_URL,
-    str,
+    (const char *)str,
     0, /* status */
     ICQ_TCP_MSG_REAL);
 
@@ -162,7 +120,7 @@
   return p;
 }
 
-icq_Packet *icq_TCPCreateChatReqPacket(icq_TCPLink *plink, const unsigned char *message)
+icq_Packet *icq_TCPCreateChatReqPacket(icq_TCPLink *plink, const char *message)
 {
   icq_Packet *p=icq_TCPCreateStdPacket(
     plink,
@@ -370,7 +328,7 @@
     plink,
     ICQ_TCP_MESSAGE,
     ICQ_TCP_MSG_FILE,
-    (const unsigned char*)message,
+    (const char*)message,
     0, /* status */
     ICQ_TCP_MSG_REAL);
 
@@ -385,22 +343,22 @@
   return p;
 }
 
-void icq_TCPAppendSequence(ICQLINK *link, icq_Packet *p)
+void icq_TCPAppendSequence(icq_Link *icqlink, icq_Packet *p)
 {
-  p->id=link->d->icq_TCPSequence--;
+  p->id=icqlink->d->icq_TCPSequence--;
   icq_PacketEnd(p);
   icq_PacketAppend32(p, p->id);
 }
 
-void icq_TCPAppendSequenceN(ICQLINK *link, icq_Packet *p, DWORD seq)
+void icq_TCPAppendSequenceN(icq_Link *icqlink, icq_Packet *p, DWORD seq)
 {
-  (void)link;
+  (void)icqlink;
   p->id=seq;
   icq_PacketEnd(p);
   icq_PacketAppend32(p, p->id);
 }
 
-icq_Packet *icq_TCPCreateMessageAck(icq_TCPLink *plink, const unsigned char *message)
+icq_Packet *icq_TCPCreateMessageAck(icq_TCPLink *plink, const char *message)
 {
   icq_Packet *p=icq_TCPCreateStdPacket(
     plink,
@@ -413,7 +371,7 @@
    return p;
 }
 
-icq_Packet *icq_TCPCreateURLAck(icq_TCPLink *plink, const unsigned char *message)
+icq_Packet *icq_TCPCreateURLAck(icq_TCPLink *plink, const char *message)
 {
   icq_Packet *p=icq_TCPCreateStdPacket(
     plink,
@@ -426,7 +384,7 @@
    return p;
 }
 
-icq_Packet *icq_TCPCreateContactListAck(icq_TCPLink *plink, const unsigned char *message)
+icq_Packet *icq_TCPCreateContactListAck(icq_TCPLink *plink, const char *message)
 {
   icq_Packet *p=icq_TCPCreateStdPacket(
     plink,
@@ -544,7 +502,7 @@
   return p;
 }
 
-icq_Packet *icq_UDPCreateStdPacket(ICQLINK *link, WORD cmd)
+icq_Packet *icq_UDPCreateStdPacket(icq_Link *icqlink, WORD cmd)
 {
   icq_Packet *p = icq_PacketNew();
 
@@ -553,30 +511,30 @@
   if(!link->d->icq_UDPSeqNum2)
     link->d->icq_UDPSeqNum2 = rand() & 0x7FFF;*/
 
-  icq_PacketAppend16(p, ICQ_UDP_VER);            /* ver */
-  icq_PacketAppend32(p, 0);                      /* zero */
-  icq_PacketAppend32(p, link->icq_Uin);          /* uin */
-  icq_PacketAppend32(p, link->d->icq_UDPSession);   /* session */
-  icq_PacketAppend16(p, cmd);                    /* cmd */
-  icq_PacketAppend16(p, link->d->icq_UDPSeqNum1++); /* seq1 */
-  icq_PacketAppend16(p, link->d->icq_UDPSeqNum2++); /* seq2 */
-  icq_PacketAppend32(p, 0);                      /* checkcode */
+  icq_PacketAppend16(p, ICQ_UDP_VER);                  /* ver */
+  icq_PacketAppend32(p, 0);                            /* zero */
+  icq_PacketAppend32(p, icqlink->icq_Uin);             /* uin */
+  icq_PacketAppend32(p, icqlink->d->icq_UDPSession);   /* session */
+  icq_PacketAppend16(p, cmd);                          /* cmd */
+  icq_PacketAppend16(p, icqlink->d->icq_UDPSeqNum1++); /* seq1 */
+  icq_PacketAppend16(p, icqlink->d->icq_UDPSeqNum2++); /* seq2 */
+  icq_PacketAppend32(p, 0);                            /* checkcode */
 
   return p;
 }
 
-icq_Packet *icq_UDPCreateStdSeqPacket(ICQLINK *link, WORD cmd, WORD seq)
+icq_Packet *icq_UDPCreateStdSeqPacket(icq_Link *icqlink, WORD cmd, WORD seq)
 {
   icq_Packet *p = icq_PacketNew();
 
-  icq_PacketAppend16(p, ICQ_UDP_VER);            /* ver */
-  icq_PacketAppend32(p, 0);                      /* zero */
-  icq_PacketAppend32(p, link->icq_Uin);          /* uin */
-  icq_PacketAppend32(p, link->d->icq_UDPSession);   /* session */
-  icq_PacketAppend16(p, cmd);                    /* cmd */
-  icq_PacketAppend16(p, seq);                    /* seq1 */
-  icq_PacketAppend16(p, 0);                      /* seq2 */
-  icq_PacketAppend32(p, 0);                      /* checkcode */
+  icq_PacketAppend16(p, ICQ_UDP_VER);                /* ver */
+  icq_PacketAppend32(p, 0);                          /* zero */
+  icq_PacketAppend32(p, icqlink->icq_Uin);           /* uin */
+  icq_PacketAppend32(p, icqlink->d->icq_UDPSession); /* session */
+  icq_PacketAppend16(p, cmd);                        /* cmd */
+  icq_PacketAppend16(p, seq);                        /* seq1 */
+  icq_PacketAppend16(p, 0);                          /* seq2 */
+  icq_PacketAppend32(p, 0);                          /* checkcode */
 
   return p;
 }
--- a/plugins/icq/stdpackets.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/stdpackets.h	Tue May 29 10:32:53 2001 +0000
@@ -1,4 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _ICQTCPPACKETS_H
 #define _ICQTCPPACKETS_H
 
@@ -53,26 +74,24 @@
 #define ICQ_TCP_STATUS_FREE_CHAT   ICQ_TCP_STATUS_ONLINE
 #define ICQ_TCP_STATUS_INVISIBLE   ICQ_TCP_STATUS_ONLINE
 
-#include "icqpacket.h"
 #include "tcplink.h"
 
 icq_Packet *icq_TCPCreateInitPacket(icq_TCPLink *plink);
 icq_Packet *icq_TCPCreateStdPacket(icq_TCPLink *plink, WORD icq_TCPCommand,
-               WORD type, const unsigned char *msg, WORD status, 
-               WORD msg_command);
-icq_Packet *icq_TCPCreateMessagePacket(icq_TCPLink *plink, const unsigned char *message);
+               WORD type, const char *msg, WORD status, WORD msg_command);
+icq_Packet *icq_TCPCreateMessagePacket(icq_TCPLink *plink, const char *message);
 icq_Packet *icq_TCPCreateURLPacket(icq_TCPLink *plink, const char *message,
    const char *url);
-icq_Packet *icq_TCPCreateChatReqPacket(icq_TCPLink *plink,  const unsigned char *message);
+icq_Packet *icq_TCPCreateChatReqPacket(icq_TCPLink *plink, const char *message);
 icq_Packet *icq_TCPCreateFileReqPacket(icq_TCPLink *plink, 
    const char *message, const char *filename, DWORD size);
-void icq_TCPAppendSequence(ICQLINK *link, icq_Packet *p);
-void icq_TCPAppendSequenceN(ICQLINK *link, icq_Packet *p, DWORD seq);
+void icq_TCPAppendSequence(icq_Link *icqlink, icq_Packet *p);
+void icq_TCPAppendSequenceN(icq_Link *icqlink, icq_Packet *p, DWORD seq);
 
-icq_Packet *icq_TCPCreateMessageAck(icq_TCPLink *plink, const unsigned char *message);
-icq_Packet *icq_TCPCreateURLAck(icq_TCPLink *plink, const unsigned char *message);
-icq_Packet *icq_TCPCreateContactListAck(icq_TCPLink *plink, const unsigned char *message);
-icq_Packet *icq_TCPCreateWebPagerAck(icq_TCPLink *plink, const unsigned char *message);
+icq_Packet *icq_TCPCreateMessageAck(icq_TCPLink *plink, const char *message);
+icq_Packet *icq_TCPCreateURLAck(icq_TCPLink *plink, const char *message);
+icq_Packet *icq_TCPCreateContactListAck(icq_TCPLink *plink, const char *message);
+icq_Packet *icq_TCPCreateWebPagerAck(icq_TCPLink *plink, const char *message);
 icq_Packet *icq_TCPCreateChatReqAck(icq_TCPLink *plink, WORD port);
 icq_Packet *icq_TCPCreateChatReqCancel(icq_TCPLink *plink, WORD port);
 icq_Packet *icq_TCPCreateChatReqRefuse(icq_TCPLink *plink, WORD port,
@@ -96,8 +115,8 @@
 icq_Packet *icq_TCPCreateFile05Packet(DWORD speed);
 icq_Packet *icq_TCPCreateFile06Packet(int length, void *data);
 
-icq_Packet *icq_UDPCreateStdPacket(ICQLINK *link, WORD cmd);
-icq_Packet *icq_UDPCreateStdSeqPacket(ICQLINK *link, WORD cmd, WORD seq);
+icq_Packet *icq_UDPCreateStdPacket(icq_Link *icqlink, WORD cmd);
+icq_Packet *icq_UDPCreateStdSeqPacket(icq_Link *icqlink, WORD cmd, WORD seq);
 
 #endif /* _ICQTCPPACKETS_H */
 
--- a/plugins/icq/tcp.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/tcp.c	Tue May 29 10:32:53 2001 +0000
@@ -1,160 +1,50 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: tcp.c 1508 2001-02-22 23:07:34Z warmenhoven $
-$Log$
-Revision 1.4  2001/02/22 23:07:34  warmenhoven
-updating icqlib
-
-Revision 1.39  2001/02/22 05:40:04  bills
-port tcp connect timeout code and UDP queue to new timeout manager
-
-Revision 1.38  2001/01/17 01:29:17  bills
-Rework chat and file session interfaces; implement socket notifications.
-
-Revision 1.37  2000/12/19 06:00:07  bills
-moved members from ICQLINK to ICQLINK_private struct
-
-Revision 1.36  2000/07/09 22:19:35  bills
-added new *Close functions, use *Close functions instead of *Delete
-where correct, and misc cleanup
-
-Revision 1.35  2000/06/15 01:52:16  bills
-added Cancel and Refuse functions for chat and file reqs, changed packet
-sending code to use new icq_TCPLinkSendSeq function to elimitane duplicate
-code, removed *Seq functions, renamed chat req functions
-
-Revision 1.34  2000/05/04 15:57:20  bills
-Reworked file transfer notification, small bugfixes, and cleanups.
-
-Revision 1.33  2000/04/10 18:11:45  denis
-ANSI cleanups.
-
-Revision 1.32  2000/04/10 16:36:04  denis
-Some more Win32 compatibility from Guillaume Rosanis <grs@mail.com>
-
-Revision 1.31  2000/04/06 16:38:04  denis
-icq_*Send*Seq() functions with specified sequence number were added.
-
-Revision 1.30  2000/04/05 14:37:02  denis
-Applied patch from "Guillaume R." <grs@mail.com> for basic Win32
-compatibility.
-
-Revision 1.29  2000/02/15 04:02:41  bills
-warning cleanup
-
-Revision 1.28  2000/02/15 03:58:20  bills
-use new icq_ChatRusConv_n function in icq_TCPSendChatData,
-new icq_TCPSendChatData_n function
-
-Revision 1.27  2000/02/07 02:40:23  bills
-new code for SOCKS connections, more cyrillic translations
-
-Revision 1.26  2000/01/20 19:59:15  bills
-first implementation of sending file requests
-
-Revision 1.25  2000/01/16 21:28:24  bills
-renamed icq_TCPAcceptFileReq to icq_AcceptFileRequest, moved file request
-functions to new file session code
-
-Revision 1.24  2000/01/16 03:59:10  bills
-reworked list code so list_nodes don't need to be inside item structures,
-removed strlist code and replaced with generic list calls
-
-Revision 1.23  1999/12/27 16:10:04  bills
-fixed buy in icq_TCPAcceptFileReq, added icq_TCPFileSetSpeed
-
-Revision 1.22  1999/12/21 00:29:59  bills
-moved _process_packet logic into tcplink::icq_TCPLinkProcessReceived,
-removed unnecessary icq_TCPSendFile??Packet functions
-
-Revision 1.21  1999/12/14 03:31:48  bills
-fixed double delete bug in _handle_ready_sockets, added code to implement
-connect timeout
-
-Revision 1.20  1999/11/30 09:44:31  bills
-added file session logic
-
-Revision 1.19  1999/09/29 20:07:12  bills
-cleanups, moved connect logic from _handle_ready_sockets to
-icq_TCPLinkOnConnect, tcp_link->icq_TCPLink
-
-Revision 1.18  1999/09/29 17:08:48  denis
-Cleanups.
-
-Revision 1.17  1999/07/18 20:19:56  bills
-added better log messages
-
-Revision 1.16  1999/07/16 15:45:56  denis
-Cleaned up.
-
-Revision 1.15  1999/07/16 12:14:13  denis
-tcp_packet* functions renamed to icq_Packet*
-Cleaned up.
-
-Revision 1.14  1999/07/12 15:13:34  cproch
-- added definition of ICQLINK to hold session-specific global variabled
-  applications which have more than one connection are now possible
-- changed nearly every function defintion to support ICQLINK parameter
-
-Revision 1.13  1999/07/03 06:33:49  lord
-. byte order conversion macros added
-. some compilation warnings removed
-
-Revision 1.12  1999/06/30 13:52:22  bills
-implemented non-blocking connects
-
-Revision 1.11  1999/05/03 21:41:26  bills
-initial file xfer support added- untested
-
-Revision 1.10  1999/04/29 09:35:41  denis
-Cleanups, warning removed
-
-Revision 1.9  1999/04/17 19:30:50  bills
-_major_ restructuring.  all tcp sockets (including listening sockets) are
-kept in global linked list, icq_TCPLinks. accept and listen functions
-moved to tcplink.c.  changed return values of Send* functions to DWORD.
-
-Revision 1.8  1999/04/14 14:57:05  denis
-Cleanups for "strict" compiling (-ansi -pedantic)
-Parameter port added to function icq_TCPCreateListeningSocket()
-
-*/
 
 /*
-   Peer-to-peer ICQ protocol implementation
-
-   Uses version 2 of the ICQ protocol
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
-   Thanks to Douglas F. McLaughlin and many others for
-   packet details (see tcp02.txt)
-
-*/
+/*
+ * Peer-to-peer ICQ protocol implementation
+ *
+ * Uses version 2 of the ICQ protocol
+ *
+ * Thanks to Douglas F. McLaughlin and many others for
+ * packet details (see tcp02.txt)
+ *
+ */
 
 #include <stdlib.h>
 
 #include <fcntl.h>
-#include <stdarg.h>
 #include <errno.h>
 
-#include <sys/types.h>
-
 #ifdef _WIN32
 #include <winsock.h>
-#else
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <unistd.h>
 #endif
 
 #include <sys/stat.h>
 
-#include "icqtypes.h"
 #include "icqlib.h"
 
 #include "tcp.h"
 #include "stdpackets.h"
-#include "list.h"
-#include "tcplink.h"
 #include "chatsession.h"
 #include "filesession.h"
 
@@ -165,43 +55,43 @@
  \return true on error
 */
  
-int icq_TCPInit(ICQLINK *link)
+int icq_TCPInit(icq_Link *icqlink)
 {
   icq_TCPLink *plink;
 
   /* allocate lists */
-  link->d->icq_TCPLinks=list_new();
-  link->d->icq_ChatSessions=list_new();
-  link->d->icq_FileSessions=list_new();
+  icqlink->d->icq_TCPLinks=icq_ListNew();
+  icqlink->d->icq_ChatSessions=icq_ListNew();
+  icqlink->d->icq_FileSessions=icq_ListNew();
 
   /* only the main listening socket gets created upon initialization -
    * the other two are created when necessary */
-  plink=icq_TCPLinkNew( link );
+  plink=icq_TCPLinkNew(icqlink);
   icq_TCPLinkListen(plink);
-  link->icq_TCPSrvPort=ntohs(plink->socket_address.sin_port);
+  icqlink->icq_TCPSrvPort=ntohs(plink->socket_address.sin_port);
 
   /* reset tcp sequence number */
-  link->d->icq_TCPSequence=0xfffffffe;
+  icqlink->d->icq_TCPSequence=0xfffffffe;
 
   return 0;
 }
 
-void icq_TCPDone(ICQLINK *link)
+void icq_TCPDone(icq_Link *icqlink)
 {
   /* close and deallocate all tcp links, this will also close any attached 
    * file or chat sessions */
-  list_delete(link->d->icq_TCPLinks, icq_TCPLinkDelete);
-  list_delete(link->d->icq_ChatSessions, icq_ChatSessionDelete);
-  list_delete(link->d->icq_FileSessions, icq_FileSessionDelete);
+  icq_ListDelete(icqlink->d->icq_TCPLinks, icq_TCPLinkDelete);
+  icq_ListDelete(icqlink->d->icq_ChatSessions, icq_ChatSessionDelete);
+  icq_ListDelete(icqlink->d->icq_FileSessions, icq_FileSessionDelete);
 }
 
-icq_TCPLink *icq_TCPCheckLink(ICQLINK *link, DWORD uin, int type)
+icq_TCPLink *icq_TCPCheckLink(icq_Link *icqlink, DWORD uin, int type)
 {
-  icq_TCPLink *plink=icq_FindTCPLink(link, uin, type);
+  icq_TCPLink *plink=icq_FindTCPLink(icqlink, uin, type);
 
   if(!plink)
   {
-    plink=icq_TCPLinkNew( link );
+    plink=icq_TCPLinkNew(icqlink);
     if(type==TCP_LINK_MESSAGE)
       icq_TCPLinkConnect(plink, uin, 0);
   }
@@ -210,7 +100,7 @@
 
 }
 
-DWORD icq_TCPSendMessage(ICQLINK *link, DWORD uin, const char *message)
+DWORD icq_TCPSendMessage(icq_Link *icqlink, DWORD uin, const char *message)
 {
   icq_TCPLink *plink;
   icq_Packet *p;
@@ -220,10 +110,10 @@
   strncpy(data,message,512) ;
   icq_RusConv("kw", data) ;
 
-  plink=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE);
+  plink=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE);
 
   /* create and send the message packet */
-  p=icq_TCPCreateMessagePacket(plink, (unsigned char *)data);
+  p=icq_TCPCreateMessagePacket(plink, data);
   sequence=icq_TCPLinkSendSeq(plink, p, 0);
 
 #ifdef TCP_PACKET_TRACE
@@ -233,14 +123,14 @@
   return sequence;
 }
 
-DWORD icq_TCPSendURL(ICQLINK *link, DWORD uin, const char *message, const char *url)
+DWORD icq_TCPSendURL(icq_Link *icqlink, DWORD uin, const char *message, const char *url)
 {
   icq_TCPLink *plink;
   icq_Packet *p;
   DWORD sequence;
   char data[512];
 
-  plink=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE);
+  plink=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE);
   
   strncpy(data, message, 512);
   data[511] = '\0';
@@ -257,21 +147,21 @@
   return sequence;
 }
 
-DWORD icq_SendChatRequest(ICQLINK *link, DWORD uin, const char *message)
+DWORD icq_SendChatRequest(icq_Link *icqlink, DWORD uin, const char *message)
 {
   icq_TCPLink *plink;
   icq_Packet *p;
   DWORD sequence;
   char data[512];
 
-  plink=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE);
+  plink=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE);
   
   strncpy(data, message, 512);
   data[511] = '\0';
   icq_RusConv("kw", data);
 
   /* create and send the url packet */
-  p=icq_TCPCreateChatReqPacket(plink, (unsigned char *)data);
+  p=icq_TCPCreateChatReqPacket(plink, data);
   sequence=icq_TCPLinkSendSeq(plink, p, 0);
 
 #ifdef TCP_PACKET_TRACE
@@ -281,7 +171,7 @@
   return sequence;
 }
 
-unsigned long icq_SendFileRequest(ICQLINK *link, unsigned long uin,
+unsigned long icq_SendFileRequest(icq_Link *icqlink, unsigned long uin,
   const char *message, char **files)
 {
   icq_TCPLink *plink;
@@ -291,11 +181,11 @@
   char filename[64];
   char data[512];
 
-  plink=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE);
+  plink=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE);
 
   /* create the file session, this will be linked to the incoming icq_TCPLink
    * in icq_HandleFileAck */ 
-  pfile=icq_FileSessionNew(link);
+  pfile=icq_FileSessionNew(icqlink);
   pfile->remote_uin=uin;
   pfile->files=files;
   pfile->direction=FILE_STATUS_SENDING;
@@ -331,25 +221,25 @@
   return sequence;
 }            
 
-void icq_AcceptChatRequest(ICQLINK *link, DWORD uin, unsigned long sequence)
+void icq_AcceptChatRequest(icq_Link *icqlink, DWORD uin, unsigned long sequence)
 {
   icq_TCPLink *pmessage, *plisten;
   icq_ChatSession *pchat;
   icq_Packet *p;
 
-  pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE);
+  pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE);
 
   /* create the chat listening socket if necessary */
-  if(!(plisten=icq_FindTCPLink(link, 0, TCP_LINK_CHAT)))
+  if(!(plisten=icq_FindTCPLink(icqlink, 0, TCP_LINK_CHAT)))
   {
-    plisten=icq_TCPLinkNew( link );
+    plisten=icq_TCPLinkNew(icqlink);
     plisten->type=TCP_LINK_CHAT;
     icq_TCPLinkListen(plisten);
   }
 
   /* create the chat session, this will be linked to the incoming icq_TCPLink
    * in TCPProcessHello */ 
-  pchat=icq_ChatSessionNew(link);
+  pchat=icq_ChatSessionNew(icqlink);
   pchat->id=sequence;
   pchat->remote_uin=uin;
 
@@ -363,9 +253,9 @@
 #endif
 }
 
-void icq_TCPSendChatData(ICQLINK *link, DWORD uin, const char *data)
+void icq_TCPSendChatData(icq_Link *icqlink, DWORD uin, const char *data)
 {
-  icq_TCPLink *plink=icq_FindTCPLink(link, uin, TCP_LINK_CHAT);
+  icq_TCPLink *plink=icq_FindTCPLink(icqlink, uin, TCP_LINK_CHAT);
   char data1[512];
   int data1_len;
 
@@ -381,9 +271,9 @@
 
 }
 
-void icq_TCPSendChatData_n(ICQLINK *link, DWORD uin, const char *data, int len)
+void icq_TCPSendChatData_n(icq_Link *icqlink, DWORD uin, const char *data, int len)
 {
-  icq_TCPLink *plink=icq_FindTCPLink(link, uin, TCP_LINK_CHAT);
+  icq_TCPLink *plink=icq_FindTCPLink(icqlink, uin, TCP_LINK_CHAT);
   char *data1;
 
   if(!plink)
@@ -397,26 +287,26 @@
 
 }
 
-icq_FileSession *icq_AcceptFileRequest(ICQLINK *link, DWORD uin,
+icq_FileSession *icq_AcceptFileRequest(icq_Link *icqlink, DWORD uin,
   unsigned long sequence)
 {
   icq_TCPLink *pmessage, *plisten;
   icq_FileSession *pfile;
   icq_Packet *p;
 
-  pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE);
+  pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE);
 
   /* create the file listening socket if necessary */
-  if(!(plisten=icq_FindTCPLink(link, 0, TCP_LINK_FILE)))
+  if(!(plisten=icq_FindTCPLink(icqlink, 0, TCP_LINK_FILE)))
   {
-    plisten=icq_TCPLinkNew( link );
+    plisten=icq_TCPLinkNew(icqlink);
     plisten->type=TCP_LINK_FILE;
     icq_TCPLinkListen(plisten);
   }
 
   /* create the file session, this will be linked to the incoming icq_TCPLink
    * in TCPProcessHello */ 
-  pfile=icq_FileSessionNew(link);
+  pfile=icq_FileSessionNew(icqlink);
   pfile->id=sequence;
   pfile->remote_uin=uin;
   pfile->direction=FILE_STATUS_RECEIVING;
@@ -435,10 +325,10 @@
 
 }
 
-void icq_RefuseFileRequest(ICQLINK *link, DWORD uin, 
+void icq_RefuseFileRequest(icq_Link *icqlink, DWORD uin, 
   unsigned long sequence, const char *reason)
 {
-  icq_TCPLink *pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE);
+  icq_TCPLink *pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE);
   icq_Packet *p;
 
   /* create and send the refuse packet */
@@ -453,10 +343,10 @@
 
 }
 
-void icq_CancelFileRequest(ICQLINK *link, DWORD uin, unsigned long sequence)
+void icq_CancelFileRequest(icq_Link *icqlink, DWORD uin, unsigned long sequence)
 {
-  icq_TCPLink *pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE);
-  icq_FileSession *psession=icq_FindFileSession(link, uin, sequence);
+  icq_TCPLink *pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE);
+  icq_FileSession *psession=icq_FindFileSession(icqlink, uin, sequence);
   icq_Packet *p;
 
   if (psession)
@@ -472,10 +362,10 @@
 
 }
 
-void icq_RefuseChatRequest(ICQLINK *link, DWORD uin, 
+void icq_RefuseChatRequest(icq_Link *icqlink, DWORD uin, 
   unsigned long sequence, const char *reason)
 {
-  icq_TCPLink *pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE);
+  icq_TCPLink *pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE);
   icq_Packet *p;
 
   /* create and send the refuse packet */
@@ -490,10 +380,10 @@
 
 }
 
-void icq_CancelChatRequest(ICQLINK *link, DWORD uin, unsigned long sequence)
+void icq_CancelChatRequest(icq_Link *icqlink, DWORD uin, unsigned long sequence)
 {
-  icq_TCPLink *pmessage=icq_TCPCheckLink(link, uin, TCP_LINK_MESSAGE);
-  icq_FileSession *psession=icq_FindFileSession(link, uin, sequence);
+  icq_TCPLink *pmessage=icq_TCPCheckLink(icqlink, uin, TCP_LINK_MESSAGE);
+  icq_FileSession *psession=icq_FindFileSession(icqlink, uin, sequence);
   icq_Packet *p;
 
   if (psession)
--- a/plugins/icq/tcp.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/tcp.h	Tue May 29 10:32:53 2001 +0000
@@ -1,5 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _ICQTCP_H
 #define _ICQTCP_H
 
@@ -7,16 +27,14 @@
 #include <config.h>
 #endif
 
-#include "icq.h"
 #include "tcplink.h"
-#include "util.h"
 
 /* initialize icq_TCPSocket and icq_TCPSocketAddress
  * returns < 0 on failure */
-int icq_TCPInit(ICQLINK *link);
+int icq_TCPInit(icq_Link *icqlink);
 
 /* close icq_TCPSocket, internal cleanup */
-void icq_TCPDone(ICQLINK *link);
+void icq_TCPDone(icq_Link *icqlink);
 
 int icq_TCPProcessHello(icq_Packet *p, icq_TCPLink *plink);
 void icq_TCPProcessPacket(icq_Packet *p, icq_TCPLink *plink);
--- a/plugins/icq/tcpchathandle.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/tcpchathandle.c	Tue May 29 10:32:53 2001 +0000
@@ -1,57 +1,30 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: tcpchathandle.c 1442 2001-01-28 01:52:27Z warmenhoven $
-$Log$
-Revision 1.3  2001/01/28 01:52:27  warmenhoven
-icqlib 1.1.5
-
-Revision 1.9  2001/01/17 01:29:17  bills
-Rework chat and file session interfaces; implement socket notifications.
-
-Revision 1.8  2000/07/24 03:10:08  bills
-added support for real nickname during TCP transactions like file and
-chat, instead of using Bill all the time (hmm, where'd I get that from? :)
-
-Revision 1.7  2000/07/09 22:19:35  bills
-added new *Close functions, use *Close functions instead of *Delete
-where correct, and misc cleanup
-
-Revision 1.6  2000/05/04 15:57:20  bills
-Reworked file transfer notification, small bugfixes, and cleanups.
 
-Revision 1.5  2000/05/03 18:29:15  denis
-Callbacks have been moved to the ICQLINK structure.
-
-Revision 1.4  2000/04/05 14:37:02  denis
-Applied patch from "Guillaume R." <grs@mail.com> for basic Win32
-compatibility.
-
-Revision 1.3  2000/02/07 02:54:45  bills
-warning cleanups.
-
-Revision 1.2  2000/02/07 02:43:37  bills
-new code for special chat functions (background, fonts, etc)
-
-Revision 1.1  1999/09/29 19:47:21  bills
-reworked chat/file handling.  fixed chat. (it's been broke since I put
-non-blocking connects in)
-
-*/
-
-#include <time.h>
-
-#ifndef _WIN32
-#include <unistd.h>
-#endif
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #include <stdlib.h>
 
-#include "icqtypes.h"
-#include "icq.h"
 #include "icqlib.h"
 
 #include "stdpackets.h"
-#include "tcplink.h"
 #include "chatsession.h"
 
 void icq_HandleChatAck(icq_TCPLink *plink, icq_Packet *p, int port)
@@ -114,32 +87,31 @@
 
 }
 
-void icq_TCPOnChatReqReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id)
+void icq_TCPOnChatReqReceived(icq_Link *icqlink, DWORD uin,
+  const char *message, DWORD id)
 {
+  /* use the current system time for time received */
+  time_t t=time(0);
+  struct tm *ptime=localtime(&t);
+
 #ifdef TCP_PACKET_TRACE
   printf("chat request packet received from %lu { sequence=%lx, message=%s }\n",
      uin, id, message);
 #endif /* TCP_PACKET_TRACE */
 
-  if(link->icq_RecvChatReq) {
-
-    /* use the current system time for time received */
-    time_t t=time(0);
-    struct tm *ptime=localtime(&t);
+  invoke_callback(icqlink,icq_RecvChatReq)(icqlink, uin, ptime->tm_hour, 
+    ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900,
+    message, id);
 
-    (*link->icq_RecvChatReq)(link, uin, ptime->tm_hour, ptime->tm_min,
-       ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900, message, id);
-
-    /* don't send an acknowledgement to the remote client!
-     * GUI is responsible for sending acknowledgement once user accepts
-     * or denies using icq_TCPSendChatAck */
-  }
+  /* don't send an acknowledgement to the remote client!
+   * GUI is responsible for sending acknowledgement once user accepts
+   * or denies using icq_TCPSendChatAck */
 }
 
 void icq_TCPChatUpdateFont(icq_ChatSession *psession, const char *font, 
   WORD encoding, DWORD style, DWORD size)
 {
-  ICQLINK *icqlink = psession->icqlink;
+  icq_Link *icqlink = psession->icqlink;
   int packet_len, fontlen;
   char *buffer;
 
@@ -166,7 +138,7 @@
 void icq_TCPChatUpdateColors(icq_ChatSession *psession, DWORD foreground, 
   DWORD background)
 {
-  ICQLINK *icqlink = psession->icqlink;
+  icq_Link *icqlink = psession->icqlink;
   char buffer[10];
 
   buffer[0] = '\x00';
--- a/plugins/icq/tcpfilehandle.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/tcpfilehandle.c	Tue May 29 10:32:53 2001 +0000
@@ -1,70 +1,24 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: tcpfilehandle.c 1442 2001-01-28 01:52:27Z warmenhoven $
-$Log$
-Revision 1.3  2001/01/28 01:52:27  warmenhoven
-icqlib 1.1.5
-
-Revision 1.16  2001/01/17 01:29:17  bills
-Rework chat and file session interfaces; implement socket notifications.
-
-Revision 1.15  2000/07/24 03:10:08  bills
-added support for real nickname during TCP transactions like file and
-chat, instead of using Bill all the time (hmm, where'd I get that from? :)
-
-Revision 1.14  2000/07/09 22:19:35  bills
-added new *Close functions, use *Close functions instead of *Delete
-where correct, and misc cleanup
-
-Revision 1.13  2000/06/25 16:35:08  denis
-'\n' was added at the end of log messages.
-
-Revision 1.12  2000/06/15 01:52:59  bills
-fixed bug: sending file sessions would freeze if remote side changed speed
-
-Revision 1.11  2000/05/04 15:57:20  bills
-Reworked file transfer notification, small bugfixes, and cleanups.
-
-Revision 1.10  2000/05/03 18:29:15  denis
-Callbacks have been moved to the ICQLINK structure.
-
-Revision 1.9  2000/04/10 18:11:45  denis
-ANSI cleanups.
 
-Revision 1.8  2000/04/10 16:36:04  denis
-Some more Win32 compatibility from Guillaume Rosanis <grs@mail.com>
-
-Revision 1.7  2000/04/05 14:37:02  denis
-Applied patch from "Guillaume R." <grs@mail.com> for basic Win32
-compatibility.
-
-Revision 1.6  2000/01/20 20:06:00  bills
-removed debugging printfs
-
-Revision 1.5  2000/01/20 19:59:15  bills
-first implementation of sending file requests
-
-Revision 1.4  2000/01/16 21:29:31  bills
-added code so icq_FileSessions now keep track of the tcplink to which
-they are attached
-
-Revision 1.3  1999/12/21 00:30:15  bills
-added more file transfer logic to write file to disk
-
-Revision 1.2  1999/11/30 09:47:04  bills
-added icq_HandleFileHello
-
-Revision 1.1  1999/09/29 19:47:21  bills
-reworked chat/file handling.  fixed chat. (it's been broke since I put
-non-blocking connects in)
-
-*/
-
-#include <time.h>
-
-#ifndef _WIN32
-#include <unistd.h>
-#endif
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #ifdef _MSVC_
 #include <io.h>
@@ -76,44 +30,37 @@
 
 #include <errno.h>
 
-#include "icqtypes.h"
-#include "icq.h"
 #include "icqlib.h"
 
 #include "tcp.h"
-#include "icqpacket.h"
 #include "stdpackets.h"
-#include "tcplink.h"
 #include "filesession.h"
 
-void icq_TCPOnFileReqReceived(ICQLINK *link, DWORD uin, const char *message, 
+void icq_TCPOnFileReqReceived(icq_Link *icqlink, DWORD uin, const char *message, 
    const char *filename, unsigned long filesize, DWORD id)
 {
+  /* use the current system time for time received */
+  time_t t=time(0);
+  struct tm *ptime=localtime(&t);
+
 #ifdef TCP_PACKET_TRACE
   printf("file request packet received from %lu { sequence=%lx, message=%s }\n",
      uin, id, message);
 #endif
 
-  if(link->icq_RecvFileReq) {
-
-    /* use the current system time for time received */
-    time_t t=time(0);
-    struct tm *ptime=localtime(&t);
+  invoke_callback(icqlink,icq_RecvFileReq)(icqlink, uin, ptime->tm_hour, 
+    ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900,
+    message, filename, filesize, id);
 
-    (*link->icq_RecvFileReq)(link, uin, ptime->tm_hour, ptime->tm_min,
-       ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900, message, 
-       filename, filesize, id);
-
-    /* don't send an acknowledgement to the remote client!
-     * GUI is responsible for sending acknowledgement once user accepts
-     * or denies using icq_TCPSendFileAck */
-  }
+  /* don't send an acknowledgement to the remote client!
+   * GUI is responsible for sending acknowledgement once user accepts
+   * or denies using icq_TCPSendFileAck */
 }
 
 void icq_TCPProcessFilePacket(icq_Packet *p, icq_TCPLink *plink)
 {
   icq_FileSession *psession=(icq_FileSession *)plink->session;
-  ICQLINK *icqlink = plink->icqlink;
+  icq_Link *icqlink = plink->icqlink;
   BYTE type;
   DWORD num_files;
   DWORD total_bytes;
--- a/plugins/icq/tcphandle.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/tcphandle.c	Tue May 29 10:32:53 2001 +0000
@@ -1,119 +1,39 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: tcphandle.c 1442 2001-01-28 01:52:27Z warmenhoven $
-$Log$
-Revision 1.3  2001/01/28 01:52:27  warmenhoven
-icqlib 1.1.5
-
-Revision 1.16  2001/01/24 05:11:14  bills
-applied patch from Robin Ericsson <lobbin@localhost.nu> which implements
-receiving contact lists.  See new icq_RecvContactList callback.
-
-Revision 1.15  2001/01/17 01:31:47  bills
-Rework chat and file interfaces; implement socket notifications.
-
-Revision 1.14  2000/12/06 05:15:45  denis
-Handling for mass TCP messages has been added based on patch by
-Konstantin Klyagin <konst@konst.org.ua>
-
-Revision 1.13  2000/08/13 19:44:41  denis
-Cyrillic recoding on received URL description added.
-
-Revision 1.12  2000/07/09 22:19:35  bills
-added new *Close functions, use *Close functions instead of *Delete
-where correct, and misc cleanup
-
-Revision 1.11  2000/06/25 16:36:16  denis
-'\n' was added at the end of log messages.
-
-Revision 1.10  2000/05/04 15:57:20  bills
-Reworked file transfer notification, small bugfixes, and cleanups.
-
-Revision 1.9  2000/05/03 18:29:15  denis
-Callbacks have been moved to the ICQLINK structure.
-
-Revision 1.8  2000/04/05 14:37:02  denis
-Applied patch from "Guillaume R." <grs@mail.com> for basic Win32
-compatibility.
-
-Revision 1.7  2000/01/20 20:06:00  bills
-removed debugging printfs
-
-Revision 1.6  2000/01/20 19:59:15  bills
-first implementation of sending file requests
-
-Revision 1.5  1999/11/30 09:51:42  bills
-more file xfer logic added
 
-Revision 1.4  1999/11/11 15:10:30  guruz
-- Added Base for Webpager Messages. Please type "make fixme"
-- Removed Segfault when kicq is started the first time
-
-Revision 1.3  1999/10/01 02:28:51  bills
-icq_TCPProcessHello returns something now :)
-
-Revision 1.2  1999/10/01 00:49:20  lord
-some compilation problems are fixed.
-
-Revision 1.1  1999/09/29 19:47:21  bills
-reworked chat/file handling.  fixed chat. (it's been broke since I put
-non-blocking connects in)
-
-Revision 1.15  1999/07/16 15:45:59  denis
-Cleaned up.
-
-Revision 1.14  1999/07/16 12:10:10  denis
-tcp_packet* functions renamed to icq_Packet*
-Cleaned up.
-
-Revision 1.13  1999/07/12 15:13:41  cproch
-- added definition of ICQLINK to hold session-specific global variabled
-  applications which have more than one connection are now possible
-- changed nearly every function defintion to support ICQLINK parameter
-
-Revision 1.12  1999/06/30 13:51:25  bills
-cleanups
-
-Revision 1.11  1999/05/03 21:41:30  bills
-initial file xfer support added- untested
-
-Revision 1.10  1999/04/29 09:36:06  denis
-Cleanups, warning removed
-
-Revision 1.9  1999/04/17 19:40:33  bills
-reworked code to use icq_TCPLinks instead of icq_ContactItem entries.
-modified ProcessChatPacket to negotiate both sending and receiving chat
-requests properly.
-
-Revision 1.8  1999/04/14 15:12:02  denis
-Cleanups for "strict" compiling (-ansi -pedantic)
-icq_ContactItem parameter added to function icq_TCPOnMessageReceived()
-Segfault fixed on spoofed messages.
-
-*/
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #include <stdlib.h>
-#include <time.h>
 
-#ifndef _WIN32
-#include <unistd.h>
-#endif
-
-#include "icqtypes.h"
-#include "icq.h"
 #include "icqlib.h"
 
 #include "tcp.h"
 #include "stdpackets.h"
-#include "tcplink.h"
 
-void icq_TCPOnMessageReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id, icq_TCPLink *plink);
-void icq_TCPOnURLReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id);
-void icq_TCPOnContactListReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id);
-void icq_TCPOnChatReqReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id);
-void icq_TCPOnFileReqReceived(ICQLINK *link, DWORD uin, const char *message, 
+void icq_TCPOnMessageReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id, icq_TCPLink *plink);
+void icq_TCPOnURLReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id);
+void icq_TCPOnContactListReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id);
+void icq_TCPOnChatReqReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id);
+void icq_TCPOnFileReqReceived(icq_Link *icqlink, DWORD uin, const char *message, 
    const char *filename, unsigned long filesize, DWORD id);
-void icq_TCPProcessAck(ICQLINK *link, icq_Packet *p);
+void icq_TCPProcessAck(icq_Link *icqlink, icq_Packet *p);
 void icq_HandleChatAck(icq_TCPLink *plink, icq_Packet *p, int port);
 void icq_HandleChatHello(icq_TCPLink *plink);
 void icq_HandleFileHello(icq_TCPLink *plink);
@@ -312,117 +232,113 @@
   return 1;
 }
 
-void icq_TCPOnMessageReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id, icq_TCPLink *plink)
+void icq_TCPOnMessageReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id, icq_TCPLink *plink)
 {
-  char data[512] ;
+  char data[512];
+
+  /* use the current system time for time received */
+  time_t t=time(0);
+  struct tm *ptime=localtime(&t);
+  icq_Packet *pack;
+
 #ifdef TCP_PACKET_TRACE
   printf("tcp message packet received from %lu { sequence=%x }\n",
          uin, (int)id);
 #endif
 
-  if(link->icq_RecvMessage)
-  {
-    /* use the current system time for time received */
-    time_t t=time(0);
-    struct tm *ptime=localtime(&t);
-    icq_Packet *pack;
-    icq_TCPLink *preallink=icq_FindTCPLink(link, uin, TCP_LINK_MESSAGE);
+  strncpy(data,message,512) ;
+  icq_RusConv("wk",data) ;
 
-    strncpy(data,message,512) ;
-    icq_RusConv("wk",data) ;
-
-    (*link->icq_RecvMessage)(link, uin, ptime->tm_hour, ptime->tm_min,
-      ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900, data);
+  invoke_callback(icqlink,icq_RecvMessage)(icqlink, uin, ptime->tm_hour, 
+    ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900, data);
 
-    if(plink != preallink)
-    {
-/*      if(icq_SpoofedMessage)
-        (*icq_SpoofedMessage(uin, ...));*/
-    }
+  /*
+  icq_TCPLink *preallink=icq_FindTCPLink(icqlink, uin, TCP_LINK_MESSAGE);
+  if(plink != preallink)
+    invoke_callback(icqlink,icq_SpoofedMessage)(uin, ...)
+  */
 
-    if(plink)
-    {
-      /* send an acknowledgement to the remote client */
-      pack=icq_TCPCreateMessageAck(plink,0);
-      icq_PacketAppend32(pack, id);
-      icq_PacketSend(pack, plink->socket);
+  /* send an acknowledgement to the remote client */
+  pack=icq_TCPCreateMessageAck(plink,0);
+  icq_PacketAppend32(pack, id);
+  icq_PacketSend(pack, plink->socket);
 #ifdef TCP_PACKET_TRACE
-      printf("tcp message ack sent to uin %lu { sequence=%lx }\n", uin, id);
+  printf("tcp message ack sent to uin %lu { sequence=%lx }\n", uin, id);
 #endif
-      icq_PacketDelete(pack);
-    }
-  }
+  icq_PacketDelete(pack);
 }
 
-void icq_TCPOnURLReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id)
+void icq_TCPOnURLReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id)
 {
+  /* use the current system time for time received */
+  time_t t=time(0);
+  struct tm *ptime=localtime(&t);
+  icq_Packet *pack;
+  char *pfe;
+  icq_TCPLink *plink=icq_FindTCPLink(icqlink, uin, TCP_LINK_MESSAGE);
+
 #ifdef TCP_PACKET_TRACE
   printf("tcp url packet received from %lu { sequence=%lx }\n",
      uin, id);
 #endif /*TCP_PACKET_TRACE*/
 
-  if(link->icq_RecvURL)
-  {
-    /* use the current system time for time received */
-    time_t t=time(0);
-    struct tm *ptime=localtime(&t);
-    icq_Packet *pack;
-    char *pfe;
-    icq_TCPLink *plink=icq_FindTCPLink(link, uin, TCP_LINK_MESSAGE);
+  /* the URL is split from the description by 0xFE */
+  pfe=strchr(message, '\xFE');
+  *pfe=0;
+  icq_RusConv("wk", (char*)message);
+
+  invoke_callback(icqlink,icq_RecvURL)(icqlink, uin, ptime->tm_hour, 
+    ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900, 
+    pfe+1, message);
 
-    /* the URL is split from the description by 0xFE */
-    pfe=strchr(message, '\xFE');
-    *pfe=0;
-    icq_RusConv("wk", (char*)message);
-    (*link->icq_RecvURL)(link, uin, ptime->tm_hour, ptime->tm_min,
-       ptime->tm_mday, ptime->tm_mon+1, ptime->tm_year+1900, pfe+1, message);
-
-    /* send an acknowledgement to the remote client */
-    pack=icq_TCPCreateURLAck(plink,0);
-    icq_PacketAppend32(pack, id);
-    icq_PacketSend(pack, plink->socket);
+  /* send an acknowledgement to the remote client */
+  pack=icq_TCPCreateURLAck(plink,0);
+  icq_PacketAppend32(pack, id);
+  icq_PacketSend(pack, plink->socket);
 #ifdef TCP_PACKET_TRACE
-    printf("tcp message ack sent to %lu { sequence=%lx }\n", uin, id);
+  printf("tcp message ack sent to %lu { sequence=%lx }\n", uin, id);
 #endif
-    icq_PacketDelete(pack);
-  }
+  icq_PacketDelete(pack);
 }
 
-void icq_TCPOnContactListReceived(ICQLINK *link, DWORD uin, const char *message, DWORD id)
+void icq_TCPOnContactListReceived(icq_Link *icqlink, DWORD uin, const char *message, DWORD id)
 {
+  /* use the current system time for time received */
+  time_t t=time(0);
+  struct tm *ptime=localtime(&t);
+  icq_Packet *pack;
+  icq_List *strList = icq_ListNew();
+  int i, k, nr = icq_SplitFields(strList, message);
+  const char **contact_uin  = (const char **)malloc((nr - 2) /2);
+  const char **contact_nick = (const char **)malloc((nr - 2) /2);
+  icq_TCPLink *plink=icq_FindTCPLink(icqlink, uin, TCP_LINK_MESSAGE);
+
 #ifdef TCP_PACKET_TRACE
   printf("tcp contactlist packet received from %lu { sequence=%lx }\n", uin, id);
 #endif /* TCP_PACKET_TRACE */
 
-  if (link->icq_RecvContactList) {
-    /* use the current system time for time received */
-    time_t t=time(0);
-    struct tm *ptime=localtime(&t);
-    icq_Packet *pack;
-    list *strList = list_new();
-    int i, k, nr = icq_SplitFields(strList, message);
-    char *contact_uin[(nr - 2) /2], *contact_nick[(nr - 2) /2];
-    icq_TCPLink *plink=icq_FindTCPLink(link, uin, TCP_LINK_MESSAGE);
+  /* split message */
+  for (i = 1, k = 0; i < (nr - 1); k++)
+  {
+    contact_uin[k]  = icq_ListAt(strList, i);
+    contact_nick[k] = icq_ListAt(strList, i + 1);
+    i += 2;
+  }
+
+  invoke_callback(icqlink,icq_RecvContactList)(icqlink, uin, 
+    ptime->tm_hour, ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, 
+    ptime->tm_year+1900, k, contact_uin, contact_nick);
 
-    /* split message */
-    for (i = 1, k = 0; i < (nr - 1); k++)
-    {
-      contact_uin[k]  = list_at(strList, i);
-      contact_nick[k] = list_at(strList, i + 1);
-      i += 2;
-    }
+  /* send an acknowledement to the remote client */
+  pack=icq_TCPCreateContactListAck(plink, 0);
+  icq_PacketAppend32(pack, id);
+  icq_PacketSend(pack, plink->socket);
+#ifdef TCP_PACKET_TRACE
+  printf("tcp message ack sent to %lu { sequence=%lx }\n", uin, id);
+#endif /* TCP_PACKE_TRACE */
+  icq_PacketDelete(pack);
 
-    (*link->icq_RecvContactList)(link, uin, k, (const char **) 
-      contact_uin, (const char **) contact_nick);
-    /* send an acknowledement to the remote client */
-    pack=icq_TCPCreateContactListAck(plink, 0);
-    icq_PacketAppend32(pack, id);
-    icq_PacketSend(pack, plink->socket);
-#ifdef TCP_PACKET_TRACE
-    printf("tcp message ack sent to %lu { sequence=%lx }\n", uin, id);
-#endif /* TCP_PACKE_TRACE */
-    icq_PacketDelete(pack);
-
-    list_delete(strList, free);
-  }
+  free(contact_nick);
+  free(contact_uin);
+  icq_ListDelete(strList, free);
 }
--- a/plugins/icq/tcplink.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/tcplink.c	Tue May 29 10:32:53 2001 +0000
@@ -1,179 +1,29 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: tcplink.c 1541 2001-03-04 02:26:32Z warmenhoven $
-$Log$
-Revision 1.5  2001/03/04 02:26:32  warmenhoven
-updates to icqlib; don't pay attention to exception; my patch for handling hangups. other minor details.
-
-Revision 1.45  2001/03/03 20:13:06  bills
-add compile fix for BeOS
-
-Revision 1.44  2001/02/22 05:40:04  bills
-port tcp connect timeout code and UDP queue to new timeout manager
-
-Revision 1.43  2001/01/27 22:48:01  bills
-fix bugs related to TCP and new socket manager: implemented accepting TCP
-sockets, fixed crashes when sending TCP messages.
-
-Revision 1.42  2001/01/17 01:29:17  bills
-Rework chat and file session interfaces; implement socket notifications.
-
-Revision 1.41  2001/01/15 06:19:12  denis
-Applied patch from Ilya Melamed <ilya@ort.org.il> which fixes random
-icq_TCPLinkAccept() fails.
-
-Revision 1.40  2000/12/19 06:00:07  bills
-moved members from ICQLINK to ICQLINK_private struct
-
-Revision 1.39  2000/12/03 21:57:15  bills
-fixed bug #105068
-
-Revision 1.38  2000/07/09 22:19:35  bills
-added new *Close functions, use *Close functions instead of *Delete
-where correct, and misc cleanup
-
-Revision 1.37  2000/06/15 01:53:17  bills
-added icq_TCPLinkSendSeq function
-
-Revision 1.36  2000/05/04 15:57:20  bills
-Reworked file transfer notification, small bugfixes, and cleanups.
-
-Revision 1.35  2000/05/03 18:29:15  denis
-Callbacks have been moved to the ICQLINK structure.
-
-Revision 1.34  2000/04/10 18:11:45  denis
-ANSI cleanups.
-
-Revision 1.33  2000/04/10 16:36:04  denis
-Some more Win32 compatibility from Guillaume Rosanis <grs@mail.com>
-
-Revision 1.32  2000/04/05 14:37:02  denis
-Applied patch from "Guillaume R." <grs@mail.com> for basic Win32
-compatibility.
-
-Revision 1.31  2000/02/15 04:00:16  bills
- new icq_ChatRusConv_n function
-
-Revision 1.30  2000/02/07 02:46:29  bills
-implemented non-blocking TCP connects over SOCKS, cyrillic translation for chat
-
-Revision 1.29  2000/01/20 19:59:35  bills
-fixed bug in icq_TCPLinkConnect that caused file/chat connection attempts
-to go to the wrong port
-
-Revision 1.28  2000/01/16 03:59:10  bills
-reworked list code so list_nodes don't need to be inside item structures,
-removed strlist code and replaced with generic list calls
-
-Revision 1.27  1999/12/27 16:13:29  bills
-fixed bug in icq_TCPOnDataReceived, removed flags variable ;)
-
-Revision 1.26  1999/12/27 10:56:10  denis
-Unused "flags" variable commented out.
-
-Revision 1.25  1999/12/21 00:30:53  bills
-added icq_TCPLinkProcessReceived to support processing receive queue
-before delete (packets used to get dropped in this instance, oops),
-reworked icq_TCPLinkOnDataReceived to handle quick, large streams of data,
-changed icq_TCPLinkOnConnect and *Accept to make all sockets non-blocking.
-
-Revision 1.24  1999/12/14 03:33:34  bills
-icq_TCPLinkConnect now uses real_ip when our IP is same as remote IP to make
-connection, added code to implement connect timeout
 
-Revision 1.23  1999/11/30 09:57:44  bills
-buffer overflow check added, tcplinks will now close if buffer overflows.
-increased icq_TCPLinkBufferSize to 4096 to support file transfer packets
-
-Revision 1.22  1999/11/29 17:15:51  denis
-Absence of socklen_t type fixed.
-
-Revision 1.21  1999/10/01 00:49:21  lord
-some compilation problems are fixed.
-
-Revision 1.20  1999/09/29 20:26:41  bills
-ack forgot the args :)
-
-Revision 1.19  1999/09/29 20:21:45  bills
-renamed denis' new function
-
-Revision 1.18  1999/09/29 20:11:29  bills
-renamed tcp_link* to icq_TCPLink*.  many cleanups, added icq_TCPLinkOnConnect
-
-Revision 1.17  1999/09/29 17:10:05  denis
-TCP code SOCKS-ification. Not finished.
-
-Revision 1.16  1999/07/18 20:21:34  bills
-fixed fail notification bug introduced during ICQLINK changes, changed to
-use new byte-order functions & contact list functions, added better log
-messages
-
-Revision 1.15  1999/07/16 15:45:57  denis
-Cleaned up.
-
-Revision 1.14  1999/07/16 12:02:58  denis
-tcp_packet* functions renamed to icq_Packet*
-Cleaned up.
-
-Revision 1.13  1999/07/12 15:13:36  cproch
-- added definition of ICQLINK to hold session-specific global variabled
-  applications which have more than one connection are now possible
-- changed nearly every function defintion to support ICQLINK parameter
-
-Revision 1.12  1999/07/03 06:33:51  lord
-. byte order conversion macros added
-. some compilation warnings removed
-
-Revision 1.11  1999/06/30 13:52:23  bills
-implemented non-blocking connects
-
-Revision 1.10  1999/05/03 21:39:41  bills
-removed exit calls
-
-Revision 1.9  1999/04/29 09:35:54  denis
-Cleanups, warning removed
-
-Revision 1.8  1999/04/17 19:34:49  bills
-fixed bug in icq_TCPLinkOnDataReceived, multiple packets that come in on
-one recv call are now handled correctly.  added icq_TCPLinkAccept and
-icq_TCPLinkListen.  started using mode and type structure entries.  added
-icq_TCPLinks list and icq_FindTCPLink function.  changed received_queue and
-send_queue to lists.
-
-Revision 1.7  1999/04/14 15:02:45  denis
-Cleanups for "strict" compiling (-ansi -pedantic)
-
-Revision 1.6  1999/04/05 18:47:17  bills
-initial chat support implemented
-
-Revision 1.5  1999/03/31 01:50:54  bills
-wrapped up many tcp details- tcp code now handles incoming and outgoing
-tcp messages and urls!
-
-Revision 1.4  1999/03/28 03:27:49  bills
-fixed icq_TCPLinkConnect so it really connects to remote ip instead of
-always my local test computer O:)
-
-Revision 1.3  1999/03/26 20:02:41  bills
-fixed C++ comments, cleaned up
-
-Revision 1.2  1999/03/25 22:21:59  bills
-added necessary includes
-
-Revision 1.1  1999/03/25 21:09:07  bills
-tcp link functions
-*/
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #include <stdlib.h>
 
-#ifndef _WIN32
-#include <unistd.h>
-#endif
-
 #include <fcntl.h>
-#include <stdarg.h>
 #include <errno.h>
-#include <sys/types.h>
 
 #ifdef _WIN32
 #include <winsock.h>
@@ -185,33 +35,29 @@
 #define EAFNOSUPPORT  WSAEAFNOSUPPORT
 #define EWOULDBLOCK   WSAEWOULDBLOCK
 #else
-#include <sys/socket.h>
 #include <netdb.h>
 #endif
 
-#include "icqtypes.h"
-#include "icq.h"
 #include "icqlib.h"
-#include "tcplink.h"
 #include "stdpackets.h"
-#include "util.h"
 #include "tcp.h"
 #include "errno.h"
 #include "chatsession.h"
 #include "filesession.h"
+#include "contacts.h"
 
-icq_TCPLink *icq_TCPLinkNew(ICQLINK *link)
+icq_TCPLink *icq_TCPLinkNew(icq_Link *icqlink)
 {
   icq_TCPLink *p=(icq_TCPLink *)malloc(sizeof(icq_TCPLink));
 
   p->socket=-1;
-  p->icqlink=link;
+  p->icqlink=icqlink;
   p->mode=0;
   p->session=0L;
   p->type=TCP_LINK_MESSAGE;
   p->buffer_count=0;
-  p->send_queue=list_new();
-  p->received_queue=list_new();
+  p->send_queue=icq_ListNew();
+  p->received_queue=icq_ListNew();
   p->id=0;
   p->remote_uin=0;
   p->remote_version=0;
@@ -220,7 +66,7 @@
   p->connect_timeout = NULL;
 
   if(p)
-    list_enqueue(link->d->icq_TCPLinks, p);
+    icq_ListEnqueue(icqlink->d->icq_TCPLinks, p);
 
   return p;
 }
@@ -228,11 +74,12 @@
 int _icq_TCPLinkDelete(void *pv, va_list data)
 {
   icq_Packet *p=(icq_Packet *)pv;
-  ICQLINK *icqlink=va_arg(data, ICQLINK *);
+  icq_Link *icqlink=va_arg(data, icq_Link *);
 
   /* notify the app the packet didn't make it */
   if(p->id)
-    (*icqlink->icq_RequestNotify)(icqlink, p->id, ICQ_NOTIFY_FAILED, 0, 0);
+    invoke_callback(icqlink, icq_RequestNotify)(icqlink, p->id,
+      ICQ_NOTIFY_FAILED, 0, 0);
 
   return 0;
 }
@@ -245,11 +92,11 @@
   icq_TCPLinkProcessReceived(p);
 
   /* make sure we notify app that packets in send queue didn't make it */
-  (void)list_traverse(p->send_queue, _icq_TCPLinkDelete, p->icqlink);
+  (void)icq_ListTraverse(p->send_queue, _icq_TCPLinkDelete, p->icqlink);
 
   /* destruct all packets still waiting on queues */
-  list_delete(p->send_queue, icq_PacketDelete);
-  list_delete(p->received_queue, icq_PacketDelete);
+  icq_ListDelete(p->send_queue, icq_PacketDelete);
+  icq_ListDelete(p->received_queue, icq_PacketDelete);
 
   /* if this is a chat or file link, delete the associated session as
    * well, but make sure we unassociate ourself first so the session
@@ -286,7 +133,7 @@
 
 void icq_TCPLinkClose(icq_TCPLink *plink)
 {
-  list_remove(plink->icqlink->d->icq_TCPLinks, plink);
+  icq_ListRemove(plink->icqlink->d->icq_TCPLinks, plink);
   icq_TCPLinkDelete(plink);
 }
 
@@ -618,14 +465,14 @@
 #else
   int flags;
 #endif
-  int socket;
+  int socket_fd;
   size_t remote_length;
-  icq_TCPLink *pnewlink=icq_TCPLinkNew( plink->icqlink );
+  icq_TCPLink *pnewlink=icq_TCPLinkNew(plink->icqlink);
   
   if(pnewlink)
   {
     remote_length = sizeof(struct sockaddr_in);
-    socket=icq_SocketAccept(plink->socket,
+    socket_fd=icq_SocketAccept(plink->socket,
       (struct sockaddr *)&(plink->remote_address), &remote_length);
 
     icq_FmtLog(plink->icqlink, ICQ_LOG_MESSAGE,
@@ -636,14 +483,14 @@
     /* FIXME: make sure accept succeeded */
 
     pnewlink->type=plink->type;
-    pnewlink->socket=socket;
+    pnewlink->socket=socket_fd;
 
     /* first packet sent on an icq tcp link is always the hello packet */
     pnewlink->mode|=TCP_LINK_MODE_HELLOWAIT;
 
     /* install socket handler for new socket */
-    icq_SocketSetHandler(socket, ICQ_SOCKET_READ, icq_TCPLinkOnDataReceived,
-      pnewlink);
+    icq_SocketSetHandler(socket_fd, ICQ_SOCKET_READ, 
+      icq_TCPLinkOnDataReceived, pnewlink);
   }
 
   /* set the socket to non-blocking */
@@ -842,8 +689,8 @@
   icq_PacketDump(p);
 #endif
 
-  /* Stick packet on ready packet linked list */
-  list_enqueue(plink->received_queue, p);
+  /* Stick packet on ready packet linked icq_List */
+  icq_ListEnqueue(plink->received_queue, p);
 }
 
 void icq_TCPLinkOnConnect(icq_TCPLink *plink)
@@ -928,7 +775,7 @@
    * has been established and send pending data */
   while(plink->send_queue->count>0)
   {
-    icq_Packet *p=list_dequeue(plink->send_queue);
+    icq_Packet *p=icq_ListDequeue(plink->send_queue);
     if(p->id)
       if(plink->icqlink->icq_RequestNotify)
         (*plink->icqlink->icq_RequestNotify)(plink->icqlink, p->id, ICQ_NOTIFY_CONNECTED, 0, 0);
@@ -965,7 +812,7 @@
   /* if the link is currently connecting, queue the packets for
    * later, else send immediately */
   if(plink->mode & TCP_LINK_MODE_CONNECTING) {
-    list_insert(plink->send_queue, 0, p);
+    icq_ListInsert(plink->send_queue, 0, p);
     if(plink->icqlink->icq_RequestNotify)
       (*plink->icqlink->icq_RequestNotify)(plink->icqlink, p->id, ICQ_NOTIFY_CONNECTING, 0, 0);
   } else {
@@ -983,7 +830,7 @@
   /* if the link is currently connecting, queue the packets for
    * later, else send immediately */
   if(plink->mode & TCP_LINK_MODE_CONNECTING) {
-    list_insert(plink->send_queue, 0, p);
+    icq_ListInsert(plink->send_queue, 0, p);
     if(plink->icqlink->icq_RequestNotify)
       (*plink->icqlink->icq_RequestNotify)(plink->icqlink, p->id, ICQ_NOTIFY_CONNECTING, 0, 0);
   } else {
@@ -997,11 +844,11 @@
 
 void icq_TCPLinkProcessReceived(icq_TCPLink *plink)
 {
-  list *plist=plink->received_queue;
+  icq_List *plist=plink->received_queue;
   while(plist->count>0)
 
   {
-    icq_Packet *p=list_dequeue(plist);
+    icq_Packet *p=icq_ListDequeue(plist);
 
     if(plink->mode & TCP_LINK_MODE_HELLOWAIT)
     {
@@ -1041,7 +888,7 @@
   return ( (plink->remote_uin == uin ) && (plink->type == type) );
 }
 
-icq_TCPLink *icq_FindTCPLink(ICQLINK *link, unsigned long uin, int type)
+icq_TCPLink *icq_FindTCPLink(icq_Link *icqlink, unsigned long uin, int type)
 {
-  return list_traverse(link->d->icq_TCPLinks, _icq_FindTCPLink, uin, type);
+  return icq_ListTraverse(icqlink->d->icq_TCPLinks, _icq_FindTCPLink, uin, type);
 }
--- a/plugins/icq/tcplink.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/tcplink.h	Tue May 29 10:32:53 2001 +0000
@@ -1,4 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _TCP_LINK_H_
 #define _TCP_LINK_H_
 
@@ -9,13 +30,10 @@
 #ifdef _WIN32
 #include <winsock.h>
 #else
-#include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #endif
 
-#include <time.h>
-
 #include "icq.h"
 #include "icqpacket.h"
 #include "timeout.h"
@@ -43,7 +61,7 @@
 struct icq_TCPLink_s {
 
    /* icq_TCPLink ICQLINK, type, mode, and session */
-   ICQLINK *icqlink;
+   icq_Link *icqlink;
    int type;
    int mode;
    int proxy_status;
@@ -59,8 +77,8 @@
    int buffer_count;
 
    /* packet queues */
-   list *received_queue;
-   list *send_queue;
+   icq_List *received_queue;
+   icq_List *send_queue;
 
    /* icq specific data, initialized by hello packet */
    unsigned long id;
@@ -73,10 +91,10 @@
 
 };
 
-icq_TCPLink *icq_TCPLinkNew(ICQLINK *link);
+icq_TCPLink *icq_TCPLinkNew(icq_Link *icqlink);
 void icq_TCPLinkDelete(void *p);
 void icq_TCPLinkClose(icq_TCPLink *p);
-void icq_TCPLinkNodeDelete(list_node *p);
+void icq_TCPLinkNodeDelete(icq_ListNode *p);
 
 int icq_TCPLinkConnect(icq_TCPLink *plink, DWORD uin, int port);
 icq_TCPLink *icq_TCPLinkAccept(icq_TCPLink *plink);
@@ -93,7 +111,7 @@
 
 void icq_TCPLinkProcessReceived(icq_TCPLink *plink);
 
-icq_TCPLink *icq_FindTCPLink(ICQLINK *link, unsigned long uin, int type);
+icq_TCPLink *icq_FindTCPLink(icq_Link *icqlink, unsigned long uin, int type);
 
 void icq_ChatRusConv_n(const char to[4], char *t_in, int t_len);
 
--- a/plugins/icq/timeout.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/timeout.c	Tue May 29 10:32:53 2001 +0000
@@ -1,9 +1,31 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <stdlib.h>
+
 #include "timeout.h"
 
 icq_Timeout *icq_CurrentTimeout = NULL;
-list *icq_TimeoutList = NULL;
+icq_List *icq_TimeoutList = NULL;
 
 void (*icq_SetTimeout)(long length);
 
@@ -27,7 +49,7 @@
     t->expire_time = time(NULL) + length;
     t->single_shot = 1;
 
-    list_insert_sorted(icq_TimeoutList, t);
+    icq_ListInsertSorted(icq_TimeoutList, t);
 
     if (count == 0)
       icq_TimeoutDoNotify();
@@ -38,11 +60,11 @@
 
 void icq_TimeoutDelete(icq_Timeout *timeout)
 {
-  list_remove(icq_TimeoutList, timeout);
+  icq_ListRemove(icq_TimeoutList, timeout);
 
   /* if this was the timeout we were currently waiting on, move on
    * to the next */
-  if (icq_CurrentTimeout = timeout)
+  if (icq_CurrentTimeout == timeout)
   {
     icq_CurrentTimeout = NULL;
     icq_TimeoutDoNotify();
@@ -56,10 +78,11 @@
   icq_Timeout *t = p;
   int complete = 0;
   time_t current_time = va_arg(data, time_t);
-  list *expired_timeouts = va_arg(data, list *);
+  icq_List *expired_timeouts = va_arg(data, icq_List *);
+  (void)data;
 
   if (t->expire_time <= current_time)
-    list_enqueue(expired_timeouts, t);
+    icq_ListEnqueue(expired_timeouts, t);
   else
     /* traversal is complete when we reach an expire time in the future */
     complete = 1;
@@ -70,11 +93,14 @@
 int _icq_HandleTimeout2(void *p, va_list data)
 {
   icq_Timeout *t = p;
+  (void)data;
 
   /* maybe a previously executed timeout caused us to be deleted, so
    * make sure we're still around */
-  if (list_find(icq_TimeoutList, t))
+  if (icq_ListFind(icq_TimeoutList, t))
     (t->handler)(t->data);
+
+  return 0; /* traverse entire list */
 }
 
 int _icq_HandleTimeout3(void *p, va_list data)
@@ -100,28 +126,31 @@
 void icq_HandleTimeout()
 {
   time_t current_time = time(NULL);
-  list *expired_timeouts = list_new();
+  icq_List *expired_timeouts = icq_ListNew();
 
   icq_CurrentTimeout = NULL;
 
-  /* these three operations must be split up, in the case where a
+  /* these three operations must be split up for the case where a
    * timeout function causes timers to be deleted - this ensures
    * we don't try to free any timers that have already been removed
    * or corrupt the list traversal process */
 
   /* determine which timeouts that have expired */
-  list_traverse(icq_TimeoutList, _icq_HandleTimeout1, current_time,
+  icq_ListTraverse(icq_TimeoutList, _icq_HandleTimeout1, current_time,
     expired_timeouts);
 
   /* call handler function for expired timeouts */
-  list_traverse(expired_timeouts, _icq_HandleTimeout2);
+  icq_ListTraverse(expired_timeouts, _icq_HandleTimeout2);
 
   /* delete any expired timeouts */
-  list_traverse(icq_TimeoutList, _icq_HandleTimeout3, current_time);
+  icq_ListTraverse(icq_TimeoutList, _icq_HandleTimeout3, current_time);
 
+  /* if there's any timeouts left, notify the library client */
   if (icq_TimeoutList->count)
     icq_TimeoutDoNotify();
-}  
+
+  icq_ListDelete(expired_timeouts, NULL);
+}
 
 void icq_TimeoutDoNotify()
 {
@@ -134,7 +163,7 @@
     return;
   }
 
-  icq_CurrentTimeout = (icq_Timeout *)list_first(icq_TimeoutList);
+  icq_CurrentTimeout = (icq_Timeout *)icq_ListFirst(icq_TimeoutList);
   length = icq_CurrentTimeout->expire_time - current_time;
 
   if (icq_SetTimeout)
--- a/plugins/icq/timeout.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/timeout.h	Tue May 29 10:32:53 2001 +0000
@@ -1,5 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _TIMEOUTMANAGER_H
 #define _TIMEOUTMANAGER_H
 
@@ -32,6 +52,6 @@
 void icq_HandleTimeout();
 void icq_TimeoutDoNotify();
 
-extern list *icq_TimeoutList;
+extern icq_List *icq_TimeoutList;
 
 #endif /* _TIMEOUTMANAGER_H */
--- a/plugins/icq/udp.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/udp.c	Tue May 29 10:32:53 2001 +0000
@@ -1,123 +1,24 @@
-/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2  -*- */
-/*
-$Id: udp.c 1535 2001-03-03 00:26:04Z warmenhoven $
-$Log$
-Revision 1.5  2001/03/03 00:26:04  warmenhoven
-icqlib updates. beginnings of system logging.
-
-Revision 1.29  2001/03/01 05:37:15  bills
-rewrote icq_UDPEncode and icq_UDPCheckCode functions to do their work in
-a seperate buffer so original icq_Packet isn't corrupted, fixed bug where
-UDP_CMD_ACKs were being queued on the UDP packet queue
-
-Revision 1.28  2001/02/22 05:40:04  bills
-port tcp connect timeout code and UDP queue to new timeout manager
-
-Revision 1.27  2001/01/16 00:10:13  denis
-Invisible list has been finished.
-
-Revision 1.26  2000/12/19 06:00:07  bills
-moved members from ICQLINK to ICQLINK_private struct
-
-Revision 1.25  2000/11/02 07:29:07  denis
-Ability to disable TCP protocol has been added.
-
-Revision 1.24  2000/08/13 00:59:52  denis
-Patch #101057 have been applied.
-
-Revision 1.23  2000/07/09 22:19:35  bills
-added new *Close functions, use *Close functions instead of *Delete
-where correct, and misc cleanup
-
-Revision 1.22  2000/07/09 18:25:44  denis
-icq_UpdateNewUserInfo() now returns seq1 instead of seq2 since it
-isn't META function.
-
-Revision 1.21  2000/06/25 16:43:19  denis
-icq_SendMetaInfoReq() was added.
-All icq_*Meta*() functions now returns sequence number 2 because their
-replies from the server are synced with it.
-
-Revision 1.20  2000/06/15 01:50:39  bills
-removed *Seq functions
-
-Revision 1.19  2000/05/10 19:06:59  denis
-UDP outgoing packet queue was implemented.
-
-Revision 1.18  2000/05/03 18:34:43  denis
-icq_UpdateNewUserInfo() was added.
-All icq_UpdateMetaInfo*() now return their sequence number.
-
-Revision 1.17  2000/04/10 16:36:04  denis
-Some more Win32 compatibility from Guillaume Rosanis <grs@mail.com>
-
-Revision 1.16  2000/04/06 19:03:07  denis
-return sequence number
-
-Revision 1.15  2000/04/06 16:36:18  denis
-So called "Online List problem" bug with Long Contact List was fixed.
-icq_*Send*Seq() functions with specified sequence number were added.
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
-Revision 1.14  2000/04/05 14:37:02  denis
-Applied patch from "Guillaume R." <grs@mail.com> for basic Win32
-compatibility.
-
-Revision 1.13  1999/12/27 11:12:35  denis
-icq_UpdateMetaInfoSecurity() added for setting "My authorization is
-required", "Web Aware" and "IP Publishing".
-
-Revision 1.12  1999/10/14 11:43:28  denis
-icq_UpdateMetaInfo* functions added.
-
-Revision 1.11  1999/10/07 18:36:27  denis
-proxy.h file removed.
-
-Revision 1.10  1999/10/04 13:36:17  denis
-Cleanups.
-
-Revision 1.9  1999/09/29 20:15:30  bills
-tcp port wasn't being sent properly in login packet
-
-Revision 1.8  1999/09/29 17:13:45  denis
-Webaware functions enabled without success even with UDP v5 - need more
-investigations.
-
-Revision 1.7  1999/07/18 20:22:16  bills
-changed to use new byte-order functions & contact list functions
-
-Revision 1.6  1999/07/16 15:46:00  denis
-Cleaned up.
-
-Revision 1.5  1999/07/16 12:40:53  denis
-ICQ UDP v5 implemented.
-Encription for ICQ UDP v5 implemented.
-icq_Packet* unified interface for UDP packets implemented.
-Multipacket support of ICQ UDP v5 support added.
-
-Revision 1.4  1999/07/12 15:13:43  cproch
-- added definition of ICQLINK to hold session-specific global variabled
-  applications which have more than one connection are now possible
-- changed nearly every function defintion to support ICQLINK parameter
-
-Revision 1.3  1999/04/29 09:40:52  denis
-Unsuccessful attempt to implement web presence (webaware) feature
-
-Revision 1.2  1999/04/14 15:04:13  denis
-Cleanups for "strict" compiling (-ansi -pedantic)
-Switched from icq_Log callback to icq_Fmt function.
-
-Revision 1.1  1999/03/24 11:37:38  denis
-Underscored files with TCP stuff renamed.
-TCP stuff cleaned up
-Function names changed to corresponding names.
-icqlib.c splitted to many small files by subject.
-C++ comments changed to ANSI C comments.
-
-*/
-
-#ifndef _WIN32
-#include <unistd.h>
-#endif
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #ifdef _WIN32
 #include <winsock.h>
@@ -125,7 +26,6 @@
 
 #include <stdlib.h>
 
-#include "icqtypes.h"
 #include "icqlib.h"
 #include "udp.h"
 #include "queue.h"
@@ -133,6 +33,8 @@
 #include "stdpackets.h"
 #include "icqbyteorder.h"
 
+#include "contacts.h"
+
 static const BYTE icq_UDPTable[] = {
   0x59, 0x60, 0x37, 0x6B, 0x65, 0x62, 0x46, 0x48, 0x53, 0x61, 0x4C, 0x59, 0x60, 0x57, 0x5B, 0x3D,
   0x5E, 0x34, 0x6D, 0x36, 0x50, 0x3F, 0x6F, 0x67, 0x53, 0x61, 0x4C, 0x59, 0x40, 0x47, 0x63, 0x39,
@@ -199,7 +101,7 @@
   return a[0] + a[1] + a[2] + a[3] + a[4];
 }
 
-void icq_UDPEncode(icq_Packet *p, void *buffer)
+void icq_UDPEncode(icq_Packet *p, char *buffer)
 {
   DWORD checkcode = icq_UDPCalculateCheckCode(p);
   DWORD code1, code2, code3;
@@ -227,24 +129,24 @@
 icq_UDPSockWrite and icq_UDPSockRead are for _UDP_ packets
 proxy support for TCP sockets is different!
 *********************************************************/
-int icq_UDPSockWriteDirect(ICQLINK *link, icq_Packet *p)
+int icq_UDPSockWriteDirect(icq_Link *icqlink, icq_Packet *p)
 {
   char tmpbuf[ICQ_PACKET_DATA_SIZE+10];
 
-  if(link->icq_UDPSok <= 3)
+  if(icqlink->icq_UDPSok <= 3)
   {
-    icq_FmtLog(link, ICQ_LOG_ERROR, "Bad socket!\n");
+    icq_FmtLog(icqlink, ICQ_LOG_ERROR, "Bad socket!\n");
     return -1;
   }
 
   icq_UDPEncode(p, tmpbuf+10);
 
-  if(!link->icq_UseProxy)
+  if(!icqlink->icq_UseProxy)
   {
 #ifdef _WIN32
-    return send(link->icq_UDPSok, tmpbuf+10, p->length, 0);
+    return send(icqlink->icq_UDPSok, tmpbuf+10, p->length, 0);
 #else
-    return write(link->icq_UDPSok, tmpbuf+10, p->length);
+    return write(icqlink->icq_UDPSok, tmpbuf+10, p->length);
 #endif
   }
   else
@@ -253,34 +155,34 @@
     tmpbuf[1] = 0; /* reserved */
     tmpbuf[2] = 0; /* standalone packet */
     tmpbuf[3] = 1; /* address type IP v4 */
-    *(unsigned long*)&tmpbuf[4] = htonl(link->icq_ProxyDestIP);
-    *(unsigned short*)&tmpbuf[8] = htons(link->icq_ProxyDestPort);
+    *(unsigned long*)&tmpbuf[4] = htonl(icqlink->icq_ProxyDestIP);
+    *(unsigned short*)&tmpbuf[8] = htons(icqlink->icq_ProxyDestPort);
 #ifdef _WIN32
-    return send(link->icq_UDPSok, tmpbuf, p->length+10, 0)-10;
+    return send(icqlink->icq_UDPSok, tmpbuf, p->length+10, 0)-10;
 #else
-    return write(link->icq_UDPSok, tmpbuf, p->length+10)-10;
+    return write(icqlink->icq_UDPSok, tmpbuf, p->length+10)-10;
 #endif
   }
 }
 
-int icq_UDPSockWrite(ICQLINK *link, icq_Packet *p)
+int icq_UDPSockWrite(icq_Link *icqlink, icq_Packet *p)
 {
-  icq_UDPQueuePut(link, p);
+  icq_UDPQueuePut(icqlink, p);
 
-  return icq_UDPSockWriteDirect(link, p);
+  return icq_UDPSockWriteDirect(icqlink, p);
 }
 
-int icq_UDPSockRead(ICQLINK *link, icq_Packet *p)
+int icq_UDPSockRead(icq_Link *icqlink, icq_Packet *p)
 {
   int res;
   char tmpbuf[ICQ_PACKET_DATA_SIZE];
 
-  if(!link->icq_UseProxy)
+  if(!icqlink->icq_UseProxy)
   {
 #ifdef _WIN32
-    res = recv(link->icq_UDPSok, p->data, ICQ_PACKET_DATA_SIZE, 0);
+    res = recv(icqlink->icq_UDPSok, p->data, ICQ_PACKET_DATA_SIZE, 0);
 #else
-    res = read(link->icq_UDPSok, p->data, ICQ_PACKET_DATA_SIZE);
+    res = read(icqlink->icq_UDPSok, p->data, ICQ_PACKET_DATA_SIZE);
 #endif
     p->length = res;
     return res;
@@ -288,9 +190,9 @@
   else
   {
 #ifdef _WIN32
-    res = recv(link->icq_UDPSok, tmpbuf, ICQ_PACKET_DATA_SIZE, 0);
+    res = recv(icqlink->icq_UDPSok, tmpbuf, ICQ_PACKET_DATA_SIZE, 0);
 #else
-    res = read(link->icq_UDPSok, tmpbuf, ICQ_PACKET_DATA_SIZE);
+    res = read(icqlink->icq_UDPSok, tmpbuf, ICQ_PACKET_DATA_SIZE);
 #endif
     if(res<0)
       return res;
@@ -306,40 +208,40 @@
 JAVA client sends two different commands
 so we do also :)
 *****************************************/
-WORD icq_KeepAlive(ICQLINK *link) /* V5 */
+WORD icq_KeepAlive(icq_Link *icqlink) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdSeqPacket(link, UDP_CMD_KEEP_ALIVE, link->d->icq_UDPSeqNum1++);
+  icq_Packet *p = icq_UDPCreateStdSeqPacket(icqlink, UDP_CMD_KEEP_ALIVE, icqlink->d->icq_UDPSeqNum1++);
   icq_PacketAppend32(p, rand());
-  icq_UDPSockWriteDirect(link, p); /* don't queue keep alive packets! */
+  icq_UDPSockWriteDirect(icqlink, p); /* don't queue keep alive packets! */
   icq_PacketDelete(p);
 
-  icq_FmtLog(link, ICQ_LOG_MESSAGE, "Send Keep Alive packet to the server\n");
+  icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "Send Keep Alive packet to the server\n");
 
-  return link->d->icq_UDPSeqNum1-1;
+  return icqlink->d->icq_UDPSeqNum1-1;
 }
 
 /**********************************
 This must be called to remove
 messages from the server
 ***********************************/
-void icq_SendGotMessages(ICQLINK *link) /* V5 */
+void icq_SendGotMessages(icq_Link *icqlink) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_ACK_MESSAGES);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_ACK_MESSAGES);
   icq_PacketAppend32(p, rand());
-  icq_UDPSockWrite(link, p);
+  icq_UDPSockWrite(icqlink, p);
 }
 
 /*************************************
 this sends over the contact list
 *************************************/
-void icq_SendContactList(ICQLINK *link) /* V5 */
+void icq_SendContactList(icq_Link *icqlink) /* V5 */
 {
   char num_used;
-  icq_ContactItem *ptr = icq_ContactGetFirst(link);
+  icq_ContactItem *ptr = icq_ContactGetFirst(icqlink);
 
   while(ptr)
   {
-    icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_CONT_LIST);
+    icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_CONT_LIST);
 
     num_used = 0;
     icq_PacketAdvance(p,1);
@@ -351,15 +253,15 @@
     }
     icq_PacketGotoUDPOutData(p, 0);
     icq_PacketAppend8(p, num_used);
-    icq_UDPSockWrite(link, p);
+    icq_UDPSockWrite(icqlink, p);
   }
 }
 
-void icq_SendNewUser(ICQLINK *link, unsigned long uin) /* V5 */
+void icq_SendNewUser(icq_Link *icqlink, unsigned long uin) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_ADD_TO_LIST);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_ADD_TO_LIST);
   icq_PacketAppend32(p, uin);
-  icq_UDPSockWrite(link, p);
+  icq_UDPSockWrite(icqlink, p);
 }
 
 /*************************************
@@ -367,11 +269,11 @@
 that allows certain users to see you
 if you're invisible.
 *************************************/
-void icq_SendVisibleList(ICQLINK *link) /* V5 */
+void icq_SendVisibleList(icq_Link *icqlink) /* V5 */
 {
   char num_used;
-  icq_ContactItem *ptr = icq_ContactGetFirst(link);
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_VIS_LIST);
+  icq_ContactItem *ptr = icq_ContactGetFirst(icqlink);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_VIS_LIST);
 
   num_used = 0;
   icq_PacketAdvance(p,1);
@@ -388,16 +290,17 @@
   {
     icq_PacketGotoUDPOutData(p, 0);
     icq_PacketAppend8(p, num_used);
-    icq_UDPSockWrite(link, p);
-  } else
+    icq_UDPSockWrite(icqlink, p);
+  }
+  else
     icq_PacketDelete(p);
 }
 
-void icq_SendInvisibleList(ICQLINK *link) /* V5 */
+void icq_SendInvisibleList(icq_Link *icqlink) /* V5 */
 {
   char num_used;
-  icq_ContactItem *ptr = icq_ContactGetFirst(link);
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_INVIS_LIST);
+  icq_ContactItem *ptr = icq_ContactGetFirst(icqlink);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_INVIS_LIST);
 
   num_used = 0;
   icq_PacketAdvance(p,1);
@@ -414,8 +317,9 @@
   {
     icq_PacketGotoUDPOutData(p, 0);
     icq_PacketAppend8(p, num_used);
-    icq_UDPSockWrite(link, p);
-  } else
+    icq_UDPSockWrite(icqlink, p);
+  }
+  else
     icq_PacketDelete(p);
 }
 
@@ -423,11 +327,11 @@
 This sends the second login command
 this is necessary to finish logging in.
 ***************************************/
-void icq_SendLogin1(ICQLINK *link) /* V5 */
+void icq_SendLogin1(icq_Link *icqlink) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_LOGIN_1);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_LOGIN_1);
   icq_PacketAppend32(p, rand());
-  icq_UDPSockWrite(link, p);
+  icq_UDPSockWrite(icqlink, p);
 }
 
 /************************************
@@ -435,38 +339,38 @@
 on the socket icq_Sok and gives our ip and port.
 It does NOT wait for any kind of a response.
 *************************************/
-void icq_Login(ICQLINK *link, DWORD status) /* V5 */
+void icq_Login(icq_Link *icqlink, DWORD status) /* V5 */
 {
   icq_Packet *p;
 
-  memset(link->d->icq_UDPServMess, FALSE, sizeof(link->d->icq_UDPServMess));
-  link->d->icq_UDPSession = rand() & 0x3FFFFFFF;
-  link->d->icq_UDPSeqNum1 = rand() & 0x7FFF;
-  link->d->icq_UDPSeqNum2 = 1;
+  memset(icqlink->d->icq_UDPServMess, FALSE, sizeof(icqlink->d->icq_UDPServMess));
+  icqlink->d->icq_UDPSession = rand() & 0x3FFFFFFF;
+  icqlink->d->icq_UDPSeqNum1 = rand() & 0x7FFF;
+  icqlink->d->icq_UDPSeqNum2 = 1;
 
-  p = icq_UDPCreateStdPacket(link, UDP_CMD_LOGIN);
+  p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_LOGIN);
   icq_PacketAppend32(p, time(0L));
-  icq_PacketAppend32n(p, link->icq_TCPSrvPort);
+  icq_PacketAppend32n(p, icqlink->icq_TCPSrvPort);
   /*icq_PacketAppend16(p, 0);
-  icq_PacketAppend16n(p, htons(link->icq_OurPort));*/
-  icq_PacketAppendString(p, link->icq_Password);
+  icq_PacketAppend16n(p, htons(icqlink->icq_OurPort));*/
+  icq_PacketAppendString(p, icqlink->icq_Password);
   icq_PacketAppend32(p, LOGIN_X1_DEF);
-  if(link->icq_UseTCP)
+  if(icqlink->icq_UseTCP)
   {
-    if(link->icq_UseProxy)
+    if(icqlink->icq_UseProxy)
     {
-      icq_PacketAppend32n(p, htonl(link->icq_ProxyIP));
+      icq_PacketAppend32n(p, htonl(icqlink->icq_ProxyIP));
       icq_PacketAppend8(p, LOGIN_SNDONLY_TCP);
     }
     else
     {
-      icq_PacketAppend32n(p, htonl(link->icq_OurIP));
+      icq_PacketAppend32n(p, htonl(icqlink->icq_OurIP));
       icq_PacketAppend8(p, LOGIN_SNDRCV_TCP);
     }
   }
   else
   {
-    icq_PacketAppend32n(p, htonl(link->icq_ProxyIP));
+    icq_PacketAppend32n(p, htonl(icqlink->icq_ProxyIP));
     icq_PacketAppend8(p, LOGIN_NO_TCP);
   }
   icq_PacketAppend32(p, status);
@@ -474,19 +378,19 @@
   icq_PacketAppend32(p, LOGIN_X4_DEF);
   icq_PacketAppend32(p, LOGIN_X5_DEF);
 
-  icq_UDPSockWrite(link, p);
+  icq_UDPSockWrite(icqlink, p);
 }
 
 /**********************
 Logs off ICQ
 ***********************/
-void icq_Logout(ICQLINK *link) /* V5 */
+void icq_Logout(icq_Link *icqlink) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdSeqPacket(link, UDP_CMD_SEND_TEXT_CODE, link->d->icq_UDPSeqNum1++);
+  icq_Packet *p = icq_UDPCreateStdSeqPacket(icqlink, UDP_CMD_SEND_TEXT_CODE, icqlink->d->icq_UDPSeqNum1++);
   icq_PacketAppendString(p, "B_USER_DISCONNECTED");
   icq_PacketAppend8(p, 5);
   icq_PacketAppend8(p, 0);
-  icq_UDPSockWriteDirect(link, p); /* don't queue */
+  icq_UDPSockWriteDirect(icqlink, p); /* don't queue */
   icq_PacketDelete(p);
 }
 
@@ -495,20 +399,21 @@
 server it appears that this must be done after
 everything the server sends us
 *******************************/
-void icq_UDPAck(ICQLINK *link, int seq) /* V5 */
+void icq_UDPAck(icq_Link *icqlink, int seq) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdSeqPacket(link, UDP_CMD_ACK, seq);
+  icq_Packet *p = icq_UDPCreateStdSeqPacket(icqlink, UDP_CMD_ACK, seq);
   icq_PacketAppend32(p, rand());
 
-  icq_FmtLog(link, ICQ_LOG_MESSAGE, "Acking\n");
-  icq_UDPSockWriteDirect(link, p);
+  icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "Acking\n");
+  icq_UDPSockWriteDirect(icqlink, p);
+  icq_PacketDelete(p);
 }
 
 /***************************************************
 Sends a message thru the server to uin.  Text is the
 message to send.
 ***************************************************/
-WORD icq_UDPSendMessage(ICQLINK *link, DWORD uin, const char *text) /* V5 */
+WORD icq_UDPSendMessage(icq_Link *icqlink, DWORD uin, const char *text) /* V5 */
 {
   char buf[512]; /* message may be only 450 bytes long */
   icq_Packet *p;
@@ -516,16 +421,16 @@
   strncpy(buf, text, 512);
   icq_RusConv("kw", buf);
 
-  p = icq_UDPCreateStdPacket(link, UDP_CMD_SEND_THRU_SRV);
+  p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_SEND_THRU_SRV);
   icq_PacketAppend32(p, uin);
   icq_PacketAppend16(p, TYPE_MSG);
   icq_PacketAppendString(p, buf);
 
-  icq_UDPSockWrite(link, p);
-  return link->d->icq_UDPSeqNum1-1;
+  icq_UDPSockWrite(icqlink, p);
+  return icqlink->d->icq_UDPSeqNum1-1;
 }
 
-WORD icq_UDPSendURL(ICQLINK *link, DWORD uin, const char *url, const char *descr) /* V5 */
+WORD icq_UDPSendURL(icq_Link *icqlink, DWORD uin, const char *url, const char *descr) /* V5 */
 {
   char buf1[512], buf2[512];
   icq_Packet *p;
@@ -534,96 +439,96 @@
   icq_RusConv("kw", buf1);
   strncpy(buf2, url, 512);
 
-  p = icq_UDPCreateStdPacket(link, UDP_CMD_SEND_THRU_SRV);
+  p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_SEND_THRU_SRV);
   icq_PacketAppend32(p, uin);
   icq_PacketAppend16(p, TYPE_URL);
   icq_PacketAppend16(p, strlen(buf1)+strlen(buf2)+2); /* length + the NULL + 0xFE delimiter */
   icq_PacketAppendStringFE(p, buf1);
   icq_PacketAppendString0(p, buf2);
 
-  icq_UDPSockWrite(link, p);
-  return link->d->icq_UDPSeqNum1-1;
+  icq_UDPSockWrite(icqlink, p);
+  return icqlink->d->icq_UDPSeqNum1-1;
 }
 
 /**************************************************
 Sends a authorization to the server so the Mirabilis
 client can add the user.
 ***************************************************/
-WORD icq_SendAuthMsg(ICQLINK *link, DWORD uin) /* V5 */
+WORD icq_SendAuthMsg(icq_Link *icqlink, DWORD uin) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_SEND_THRU_SRV);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_SEND_THRU_SRV);
   icq_PacketAppend32(p, uin);
   icq_PacketAppend32(p, TYPE_AUTH);
   icq_PacketAppend16(p, 0);
-  icq_UDPSockWrite(link, p);
+  icq_UDPSockWrite(icqlink, p);
 
-  return link->d->icq_UDPSeqNum1-1;
+  return icqlink->d->icq_UDPSeqNum1-1;
 }
 
 /**************************************************
 Changes the users status on the server
 ***************************************************/
-void icq_ChangeStatus(ICQLINK *link, DWORD status) /* V5 */
+void icq_ChangeStatus(icq_Link *icqlink, DWORD status) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_STATUS_CHANGE);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_STATUS_CHANGE);
   icq_PacketAppend32(p, status);
-  link->icq_Status = status;
-  icq_UDPSockWrite(link, p);
+  icqlink->icq_Status = status;
+  icq_UDPSockWrite(icqlink, p);
 }
 
 /********************************************************
 Sends a request to the server for info on a specific user
 *********************************************************/
-WORD icq_SendInfoReq(ICQLINK *link, DWORD uin) /* V5 */
+WORD icq_SendInfoReq(icq_Link *icqlink, DWORD uin) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_INFO_REQ);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_INFO_REQ);
   icq_PacketAppend32(p, uin);
-  icq_UDPSockWrite(link, p);
-  return link->d->icq_UDPSeqNum1-1;
+  icq_UDPSockWrite(icqlink, p);
+  return icqlink->d->icq_UDPSeqNum1-1;
 }
 
 /********************************************************
 Sends a request to the server for info on a specific user
 *********************************************************/
-WORD icq_SendExtInfoReq(ICQLINK *link, DWORD uin) /* V5 */
+WORD icq_SendExtInfoReq(icq_Link *icqlink, DWORD uin) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_EXT_INFO_REQ);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_EXT_INFO_REQ);
   icq_PacketAppend32(p, uin);
-  icq_UDPSockWrite(link, p);
-  return link->d->icq_UDPSeqNum1-1;
+  icq_UDPSockWrite(icqlink, p);
+  return icqlink->d->icq_UDPSeqNum1-1;
 }
 
 /**************************************************************
 Initializes a server search for the information specified
 ***************************************************************/
-void icq_SendSearchReq(ICQLINK *link, const char *email, const char *nick, const char *first,
+void icq_SendSearchReq(icq_Link *icqlink, const char *email, const char *nick, const char *first,
                        const char *last) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_SEARCH_USER);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_SEARCH_USER);
   icq_PacketAppendString(p, nick);
   icq_PacketAppendString(p, first);
   icq_PacketAppendString(p, last);
   icq_PacketAppendString(p, email);
-  icq_UDPSockWrite(link, p);
+  icq_UDPSockWrite(icqlink, p);
 }
 
 /**************************************************************
 Initializes a server search for the information specified
 ***************************************************************/
-void icq_SendSearchUINReq(ICQLINK *link, DWORD uin) /* V5 */
+void icq_SendSearchUINReq(icq_Link *icqlink, DWORD uin) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_SEARCH_UIN);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_SEARCH_UIN);
   icq_PacketAppend32(p, uin);
-  icq_UDPSockWrite(link, p);
+  icq_UDPSockWrite(icqlink, p);
 }
 
 /**************************************************
 Registers a new uin in the ICQ network
 ***************************************************/
-void icq_RegNewUser(ICQLINK *link, const char *pass) /* V5 */
+void icq_RegNewUser(icq_Link *icqlink, const char *pass) /* V5 */
 {
   char pass8[9];
-  icq_Packet *p = icq_UDPCreateStdSeqPacket(link, UDP_CMD_REG_NEW_USER, link->d->icq_UDPSeqNum1++);
+  icq_Packet *p = icq_UDPCreateStdSeqPacket(icqlink, UDP_CMD_REG_NEW_USER, icqlink->d->icq_UDPSeqNum1++);
   strncpy(pass8, pass, 8);
   icq_PacketAppendString(p, pass8);
   icq_PacketAppend32(p, 0xA0);
@@ -633,38 +538,38 @@
   icq_PacketGoto(p, 6);
   icq_PacketAppend32(p, 0);
   icq_PacketAppend32(p, rand());
-  icq_UDPSockWrite(link, p);
-  icq_FmtLog(link, ICQ_LOG_MESSAGE, "Send RegNewUser packet to the server\n");
+  icq_UDPSockWrite(icqlink, p);
+  icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "Send RegNewUser packet to the server\n");
 }
 
-WORD icq_UpdateUserInfo(ICQLINK *link, const char *nick, const char *first, const char *last,
+WORD icq_UpdateUserInfo(icq_Link *icqlink, const char *nick, const char *first, const char *last,
                         const char *email) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_UPDATE_INFO);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_UPDATE_INFO);
   icq_PacketAppendString(p, nick);
   icq_PacketAppendString(p, first);
   icq_PacketAppendString(p, last);
   icq_PacketAppendString(p, email);
 /* auth (byte)? */
-  icq_UDPSockWrite(link, p);
-  return link->d->icq_UDPSeqNum1-1;
+  icq_UDPSockWrite(icqlink, p);
+  return icqlink->d->icq_UDPSeqNum1-1;
 }
 
-WORD icq_UpdateAuthInfo(ICQLINK *link, DWORD auth) /* V5 */
+WORD icq_UpdateAuthInfo(icq_Link *icqlink, DWORD auth) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_UPDATE_AUTH);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_UPDATE_AUTH);
   icq_PacketAppend32(p, auth); /* NOT auth? */
-  icq_UDPSockWrite(link, p);
-  return link->d->icq_UDPSeqNum1-1;
+  icq_UDPSockWrite(icqlink, p);
+  return icqlink->d->icq_UDPSeqNum1-1;
 }
 
-WORD icq_UpdateMetaInfoSet(ICQLINK *link, const char *nick, const char *first, const char *last,
+WORD icq_UpdateMetaInfoSet(icq_Link *icqlink, const char *nick, const char *first, const char *last,
                            const char *email, const char *email2, const char *email3,
                            const char *city, const char *state, const char *phone, const char *fax,
                            const char *street, const char *cellular, unsigned long zip,
                            unsigned short cnt_code, unsigned char cnt_stat, unsigned char emailhide)
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_META_USER);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_META_USER);
   icq_PacketAppend16(p, META_CMD_SET_INFO);
   icq_PacketAppendString(p, nick);
   icq_PacketAppendString(p, first);
@@ -682,15 +587,18 @@
   icq_PacketAppend16(p, cnt_code);
   icq_PacketAppend8(p, cnt_stat);
   icq_PacketAppend8(p, emailhide);
-  icq_UDPSockWrite(link, p);
-  return link->d->icq_UDPSeqNum2-1;
+  icq_UDPSockWrite(icqlink, p);
+  return icqlink->d->icq_UDPSeqNum2-1;
 }
 
-WORD icq_UpdateMetaInfoHomepage(ICQLINK *link, unsigned char age, const char *homepage,
+WORD icq_UpdateMetaInfoHomepage(icq_Link *icqlink, unsigned char age, const char *homepage,
                                 unsigned char year, unsigned char month, unsigned char day,
                                 unsigned char lang1, unsigned char lang2, unsigned char lang3)
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_META_USER);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_META_USER);
+  (void)lang1;
+  (void)lang2;
+  (void)lang3;
   icq_PacketAppend16(p, META_CMD_SET_HOMEPAGE);
   icq_PacketAppend8(p, age);
   icq_PacketAppend16(p, 0x0200);
@@ -701,35 +609,35 @@
   icq_PacketAppend8(p, 0xFF /* lang1 */);
   icq_PacketAppend8(p, 0xFF /* lang2 */);
   icq_PacketAppend8(p, 0xFF /* lang3 */);
-  icq_UDPSockWrite(link, p);
-  return link->d->icq_UDPSeqNum2-1;
+  icq_UDPSockWrite(icqlink, p);
+  return icqlink->d->icq_UDPSeqNum2-1;
 }
 
-WORD icq_UpdateMetaInfoAbout(ICQLINK *link, const char *about)
+WORD icq_UpdateMetaInfoAbout(icq_Link *icqlink, const char *about)
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_META_USER);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_META_USER);
   icq_PacketAppend16(p, META_CMD_SET_ABOUT);
   icq_PacketAppendString(p, about);
-  icq_UDPSockWrite(link, p);
-  return link->d->icq_UDPSeqNum2-1;
+  icq_UDPSockWrite(icqlink, p);
+  return icqlink->d->icq_UDPSeqNum2-1;
 }
 
-WORD icq_UpdateMetaInfoSecurity(ICQLINK *link, unsigned char reqauth, unsigned char webpresence,
+WORD icq_UpdateMetaInfoSecurity(icq_Link *icqlink, unsigned char reqauth, unsigned char webpresence,
                                 unsigned char pubip)
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_META_USER);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_META_USER);
   icq_PacketAppend16(p, META_CMD_SET_SECURE);
   icq_PacketAppend8(p, !reqauth);
   icq_PacketAppend8(p, webpresence);
   icq_PacketAppend8(p, pubip);
-  icq_UDPSockWrite(link, p);
-  return link->d->icq_UDPSeqNum2-1;
+  icq_UDPSockWrite(icqlink, p);
+  return icqlink->d->icq_UDPSeqNum2-1;
 }
 
-WORD icq_UpdateNewUserInfo(ICQLINK *link, const char *nick, const char *first, const char *last,
+WORD icq_UpdateNewUserInfo(icq_Link *icqlink, const char *nick, const char *first, const char *last,
                            const char *email) /* V5 */
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_NEW_USER_INFO);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_NEW_USER_INFO);
   icq_PacketAppendString(p, nick);
   icq_PacketAppendString(p, first);
   icq_PacketAppendString(p, last);
@@ -737,15 +645,15 @@
   icq_PacketAppend8(p, 1);
   icq_PacketAppend8(p, 1);
   icq_PacketAppend8(p, 1);
-  icq_UDPSockWrite(link, p);
-  return link->d->icq_UDPSeqNum1-1;
+  icq_UDPSockWrite(icqlink, p);
+  return icqlink->d->icq_UDPSeqNum1-1;
 }
 
-WORD icq_SendMetaInfoReq(ICQLINK *link, unsigned long uin)
+WORD icq_SendMetaInfoReq(icq_Link *icqlink, unsigned long uin)
 {
-  icq_Packet *p = icq_UDPCreateStdPacket(link, UDP_CMD_META_USER);
+  icq_Packet *p = icq_UDPCreateStdPacket(icqlink, UDP_CMD_META_USER);
   icq_PacketAppend16(p, META_CMD_REQ_INFO);
   icq_PacketAppend32(p, uin);
-  icq_UDPSockWrite(link, p);
-  return link->d->icq_UDPSeqNum2-1;
+  icq_UDPSockWrite(icqlink, p);
+  return icqlink->d->icq_UDPSeqNum2-1;
 }
--- a/plugins/icq/udp.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/udp.h	Tue May 29 10:32:53 2001 +0000
@@ -1,4 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _UDP_H_
 #define _UDP_H_
 
@@ -123,22 +144,22 @@
 #define LOGIN_SNDRCV_TCP  0x04
 #define LOGIN_NO_TCP      0x06
 
-void icq_SendGotMessages(ICQLINK *link);
-void icq_SendLogin1(ICQLINK *link);
-void icq_StatusUpdate(ICQLINK *link, icq_Packet*);
-void icq_AckSrv(ICQLINK *link, int seq);
-void icq_HandleUserOffline(ICQLINK *link, icq_Packet*);
-void icq_HandleUserOnline(ICQLINK *link, icq_Packet*);
-void icq_DoMsg(ICQLINK *link, DWORD type, WORD len, char *data, DWORD uin,
+void icq_SendGotMessages(icq_Link *icqlink);
+void icq_SendLogin1(icq_Link *icqlink);
+void icq_StatusUpdate(icq_Link *icqlink, icq_Packet*);
+void icq_AckSrv(icq_Link *icqlink, int seq);
+void icq_HandleUserOffline(icq_Link *icqlink, icq_Packet*);
+void icq_HandleUserOnline(icq_Link *icqlink, icq_Packet*);
+void icq_DoMsg(icq_Link *icqlink, DWORD type, WORD len, char *data, DWORD uin,
                BYTE hour, BYTE minute, BYTE day, BYTE month, WORD year);
-int icq_UDPSockWriteDirect(ICQLINK *link, icq_Packet*);
-int icq_UDPSockWrite(ICQLINK *link, icq_Packet*);
-int icq_UDPSockRead(ICQLINK *link, icq_Packet*);
-void icq_ServerResponse(ICQLINK *link, icq_Packet*);
-void icq_HandleMultiPacket(ICQLINK *link, icq_Packet*);
+int icq_UDPSockWriteDirect(icq_Link *icqlink, icq_Packet*);
+int icq_UDPSockWrite(icq_Link *icqlink, icq_Packet*);
+int icq_UDPSockRead(icq_Link *icqlink, icq_Packet*);
+void icq_ServerResponse(icq_Link *icqlink, icq_Packet*);
+void icq_HandleMultiPacket(icq_Link *icqlink, icq_Packet*);
 
-void icq_UDPAck(ICQLINK *link, int seq);
-WORD icq_UDPSendMessage(ICQLINK *link, DWORD uin, const char *text);
-WORD icq_UDPSendURL(ICQLINK *link, DWORD uin, const char *url, const char *descr);
+void icq_UDPAck(icq_Link *icqlink, int seq);
+WORD icq_UDPSendMessage(icq_Link *icqlink, DWORD uin, const char *text);
+WORD icq_UDPSendURL(icq_Link *icqlink, DWORD uin, const char *url, const char *descr);
 
 #endif /* _UDP_H_ */
--- a/plugins/icq/udphandle.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/udphandle.c	Tue May 29 10:32:53 2001 +0000
@@ -1,173 +1,44 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: udphandle.c 1871 2001-05-19 17:57:49Z warmenhoven $
-$Log$
-Revision 1.5  2001/05/19 17:57:49  warmenhoven
-this is not an "official" fix
-
-Revision 1.4  2001/02/22 23:07:34  warmenhoven
-updating icqlib
-
-Revision 1.31  2001/02/22 05:40:04  bills
-port tcp connect timeout code and UDP queue to new timeout manager
-
-Revision 1.30  2001/01/15 06:17:35  denis
-Applied patch from Andrey Chernomyrdin <andrey@excom.spb.su> to
-handle icq2000 specific "You've been added" packet.
-
-Revision 1.29  2000/11/02 07:28:30  denis
-Do not ack unhandled protocol version.
-
-Revision 1.28  2000/06/25 17:25:52  denis
-icq_HandleMetaUserInfo() handles all (!) available in original icq2k
-Meta User Info packets along with other useful Meta* packets. (WOW! ;)
-
-Revision 1.27  2000/05/10 18:54:43  denis
-icq_Disconnect() now called before icq_Disconnected callback to
-prevent high CPU usage in kicq's "reconnect on disconnect" code.
-
-Revision 1.26  2000/05/03 18:29:15  denis
-Callbacks have been moved to the ICQLINK structure.
-
-Revision 1.25  2000/02/07 02:48:15  bills
-changed log message in HandleUserOnline
-
-Revision 1.24  2000/01/16 03:59:10  bills
-reworked list code so list_nodes don't need to be inside item structures,
-removed strlist code and replaced with generic list calls
-
-Revision 1.23  1999/12/27 11:12:37  denis
-icq_UpdateMetaInfoSecurity() added for setting "My authorization is
-required", "Web Aware" and "IP Publishing".
-
-Revision 1.22  1999/12/14 03:37:06  bills
-removed old real_ip->ip masq hack, added store to remote_real_ip in
-icq_ContactItem
-
-Revision 1.21  1999/12/12 18:03:58  denis
-Authorization Request packet handling fixed.
-
-Revision 1.20  1999/11/29 17:18:31  denis
-icq_DoMsg() redone using string lists.
-
-Revision 1.18  1999/11/11 15:10:32  guruz
-- Added Base for Webpager Messages. Please type "make fixme"
-- Removed Segfault when kicq is started the first time
-
-Revision 1.17  1999/10/14 11:44:04  denis
-Cleanups.
 
-Revision 1.16  1999/09/29 17:16:08  denis
-MailExpress message handler started.
-
-Revision 1.15  1999/07/18 20:23:54  bills
-fixed tcp port bug in icq_HandleUserOnline, changed to use new byte-order
-& contact list functions
-
-Revision 1.14  1999/07/16 15:46:02  denis
-Cleaned up.
-
-Revision 1.13  1999/07/16 12:40:55  denis
-ICQ UDP v5 implemented.
-Encription for ICQ UDP v5 implemented.
-icq_Packet* unified interface for UDP packets implemented.
-Multipacket support of ICQ UDP v5 support added.
-
-Revision 1.12  1999/07/12 15:13:45  cproch
-- added definition of ICQLINK to hold session-specific global variabled
-  applications which have more than one connection are now possible
-- changed nearly every function defintion to support ICQLINK parameter
-
-Revision 1.11  1999/07/03 06:46:54  lord
-converting icq_userOnline callback parameters to correct
-byte order.
-
-Revision 1.10  1999/07/03 02:29:46  bills
-added code to HandleUserOnline to update tcp_flag
-
-Revision 1.9  1999/04/29 09:40:54  denis
-Unsuccessful attempt to implement web presence (webaware) feature
-
-Revision 1.8  1999/04/18 01:58:37  bills
-changed icq_SrvAck call to icq_RequestNotify
-
-Revision 1.7  1999/04/17 19:26:49  bills
-removed *_link entries from icq_ContactItem, including cleaup/init code
-
-Revision 1.6  1999/04/14 15:05:39  denis
-Cleanups for "strict" compiling (-ansi -pedantic)
-Switched from icq_Log callback to icq_Fmt function.
-
-Revision 1.5  1999/04/05 18:47:23  bills
-initial chat support implemented
-
-Revision 1.4  1999/03/31 01:39:50  bills
-added handling of tcp_flag in HandleLogin
-
-Revision 1.3  1999/03/28 03:35:17  bills
-fixed function names so icqlib compiles, fixed bug in HandleUserOnline
-(remote_ip and remote_real_ip were not evaluating correctly), added
-hack so I can test using local network
-
-Revision 1.2  1999/03/25 22:25:02  bills
-modified icq_HandleUserOnline & Offline for new message_link
-
-Revision 1.1  1999/03/24 11:37:38  denis
-Underscored files with TCP stuff renamed.
-TCP stuff cleaned up
-Function names changed to corresponding names.
-icqlib.c splitted to many small files by subject.
-C++ comments changed to ANSI C comments.
-
-*/
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #include <stdlib.h>
 
-#include "icqtypes.h"
-#include "icq.h"
 #include "icqlib.h"
 #include "udp.h"
-#include "icqpacket.h"
 #include "queue.h"
 #include "icqbyteorder.h"
-#include "list.h"
-
-int icq_SplitFields(list *strList, const char *str)
-{
-  char *tmpBuf, *tmp, *ptr;
-  int count = 0;
-
-  tmpBuf = (char*)malloc(strlen(str)+1);
-  strcpy(tmpBuf, str);
-  ptr = tmpBuf;
+#include "contacts.h"
 
-  while(ptr)
-  {
-    char *p;
-    tmp = strchr(ptr, 0xFE);
-    if(tmp != 0L)
-    {
-      *tmp = 0;
-      tmp++;
-    }
-    count++;
-    p = (char *)malloc(strlen(ptr)+1);
-    strcpy(p, ptr);
-    list_enqueue(strList, p);
-    ptr = tmp;
-  }
-
-  free(tmpBuf);
-  return count;
-}
-
-void icq_DoMsg(ICQLINK *link, DWORD type, WORD len, char *data, DWORD uin, BYTE hour,
+void icq_DoMsg(icq_Link *icqlink, DWORD type, WORD len, char *data, DWORD uin, BYTE hour,
                BYTE minute, BYTE day, BYTE month, WORD year)
 {
-  list *strList;
+  icq_List *strList;
   int fieldCount;
+  int i, k, nr;
+  const char **contact_uin;
+  const char **contact_nick;
+  (void)len;
 
-  strList = list_new();
+  strList = icq_ListNew();
   switch(type)
   {
     case TYPE_ADDED:
@@ -175,60 +46,59 @@
       fieldCount = icq_SplitFields(strList, data);
       if(fieldCount != 4 && fieldCount != 5)
       {
-        icq_FmtLog(link, ICQ_LOG_ERROR, "Bad TYPE_ADDED packet (expected 4/5 args, received %i)!\n",
+        icq_FmtLog(icqlink, ICQ_LOG_ERROR, "Bad TYPE_ADDED packet (expected 4/5 args, received %i)!\n",
                    fieldCount);
         return;
       }
-      icq_RusConv("wk", list_at(strList, 0)); /* Nick */
-      icq_RusConv("wk", list_at(strList, 1)); /* FName */
-      icq_RusConv("wk", list_at(strList, 2)); /* LName */
-      icq_RusConv("wk", list_at(strList, 3)); /* EMail */
-      icq_FmtLog(link, ICQ_LOG_MESSAGE, "%lu has added you to their contact list, "
+      icq_RusConv("wk", icq_ListAt(strList, 0)); /* Nick */
+      icq_RusConv("wk", icq_ListAt(strList, 1)); /* FName */
+      icq_RusConv("wk", icq_ListAt(strList, 2)); /* LName */
+      icq_RusConv("wk", icq_ListAt(strList, 3)); /* EMail */
+      icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "%lu has added you to their contact list, "
                  "Nick: %s, First Name: %s, Last Name: %s, EMail: %s\n",
-                 uin, list_at(strList, 0), list_at(strList, 1),
-                 list_at(strList, 2), list_at(strList, 3));
-      if(link->icq_RecvAdded)
-        (*link->icq_RecvAdded)(link, uin, hour, minute, day, month, year,
-                         list_at(strList, 0), list_at(strList, 1),
-                         list_at(strList, 2), list_at(strList, 3));
+                 uin, icq_ListAt(strList, 0), icq_ListAt(strList, 1),
+                 icq_ListAt(strList, 2), icq_ListAt(strList, 3));
+      invoke_callback(icqlink,icq_RecvAdded)(icqlink, uin, hour, minute, day, month, year,
+                                             icq_ListAt(strList, 0), icq_ListAt(strList, 1),
+                                             icq_ListAt(strList, 2), icq_ListAt(strList, 3));
       break;
     case TYPE_AUTH_REQ:
       /* Format: Nick, 0xFE, FName, 0xFE, LName, 0xFE, EMail, 0xFE, 0, 0xFE, Reason */
       fieldCount = icq_SplitFields(strList, data);
       if(fieldCount != 6)
       {
-        icq_FmtLog(link, ICQ_LOG_ERROR, "Bad TYPE_AUTH_REQ packet (expected 6 args, received %i)!\n",
+        icq_FmtLog(icqlink, ICQ_LOG_ERROR, "Bad TYPE_AUTH_REQ packet (expected 6 args, received %i)!\n",
                    fieldCount);
         return;
       }
-      icq_RusConv("wk", list_at(strList, 0)); /* Nick */
-      icq_RusConv("wk", list_at(strList, 1)); /* FName */
-      icq_RusConv("wk", list_at(strList, 2)); /* LName */
-      icq_RusConv("wk", list_at(strList, 3)); /* EMail */
-      icq_RusConv("wk", list_at(strList, 5)); /* Reason */
-      icq_FmtLog(link, ICQ_LOG_MESSAGE, "%lu has requested your authorization to be added to "
+      icq_RusConv("wk", icq_ListAt(strList, 0)); /* Nick */
+      icq_RusConv("wk", icq_ListAt(strList, 1)); /* FName */
+      icq_RusConv("wk", icq_ListAt(strList, 2)); /* LName */
+      icq_RusConv("wk", icq_ListAt(strList, 3)); /* EMail */
+      icq_RusConv("wk", icq_ListAt(strList, 5)); /* Reason */
+      icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "%lu has requested your authorization to be added to "
                  "their contact list, Nick: %s, First Name: %s, Last Name: %s, "
-                 "EMail: %s, Reason: %s\n", uin, list_at(strList, 0), list_at(strList, 1),
-                 list_at(strList, 2), list_at(strList, 3), list_at(strList, 4));
-      if(link->icq_RecvAuthReq)
-        (*link->icq_RecvAuthReq)(link, uin, hour, minute, day, month, year, list_at(strList, 0),
-                           list_at(strList, 1), list_at(strList, 2),
-                           list_at(strList, 3), list_at(strList, 5));
+                 "EMail: %s, Reason: %s\n", uin, icq_ListAt(strList, 0), icq_ListAt(strList, 1),
+                 icq_ListAt(strList, 2), icq_ListAt(strList, 3), icq_ListAt(strList, 4));
+      invoke_callback(icqlink,icq_RecvAuthReq)(icqlink, uin, hour, minute, day, month, year,
+                                               icq_ListAt(strList, 0), icq_ListAt(strList, 1),
+                                               icq_ListAt(strList, 2), icq_ListAt(strList, 3),
+                                               icq_ListAt(strList, 5));
       break;
     case TYPE_URL:
       /* Format: Description, 0xFE, URL */
       fieldCount = icq_SplitFields(strList, data);
       if(fieldCount != 2)
       {
-        icq_FmtLog(link, ICQ_LOG_ERROR, "Bad TYPE_URL packet (expected 2 args, recived %i)!\n", fieldCount);
+        icq_FmtLog(icqlink, ICQ_LOG_ERROR, "Bad TYPE_URL packet (expected 2 args, recived %i)!\n",
+                   fieldCount);
         return;
       }
-      icq_RusConv("wk", list_at(strList, 0)); /* Description */
-      icq_FmtLog(link, ICQ_LOG_MESSAGE, "URL received from %lu, URL: %s, Description: %s\n",
-                 uin, list_at(strList, 1), list_at(strList, 0));
-      if(link->icq_RecvURL)
-        (*link->icq_RecvURL)(link, uin, hour, minute, day, month, year, list_at(strList, 1),
-                       list_at(strList, 0));
+      icq_RusConv("wk", icq_ListAt(strList, 0)); /* Description */
+      icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "URL received from %lu, URL: %s, Description: %s\n",
+                 uin, icq_ListAt(strList, 1), icq_ListAt(strList, 0));
+      invoke_callback(icqlink,icq_RecvURL)(icqlink, uin, hour, minute, day, month, year,
+                                           icq_ListAt(strList, 1), icq_ListAt(strList, 0));
       break;
     case TYPE_WEBPAGER:
       /* Format: Nick, 0xFE, Empty-FName, 0xFE, Empty-LName, 0xFE, EMail, 0xFE,
@@ -236,18 +106,18 @@
       fieldCount = icq_SplitFields(strList, data);
       if(fieldCount != 6)
       {
-        icq_FmtLog(link, ICQ_LOG_ERROR, "Bad TYPE_WEBPAGER packet (expected 6 args, received %i)!\n",
+        icq_FmtLog(icqlink, ICQ_LOG_ERROR, "Bad TYPE_WEBPAGER packet (expected 6 args, received %i)!\n",
                    fieldCount);
         return;
       }
-      icq_RusConv("wk", list_at(strList, 0)); /* Nick */
-      icq_RusConv("wk", list_at(strList, 5)); /* Message */
-      icq_FmtLog(link, ICQ_LOG_MESSAGE, "WebPager message received, Nick: %s, EMail: %s, "
-                 "Message:\n%s\n", list_at(strList, 0), list_at(strList, 3),
-                 list_at(strList, 5));
-      if(link->icq_RecvWebPager)
-        (*link->icq_RecvWebPager)(link, hour, minute, day, month, year, list_at(strList, 0),
-                                   list_at(strList, 3), list_at(strList, 5));
+      icq_RusConv("wk", icq_ListAt(strList, 0)); /* Nick */
+      icq_RusConv("wk", icq_ListAt(strList, 5)); /* Message */
+      icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "WebPager message received, Nick: %s, EMail: %s, "
+                 "Message:\n%s\n", icq_ListAt(strList, 0), icq_ListAt(strList, 3),
+                 icq_ListAt(strList, 5));
+      invoke_callback(icqlink,icq_RecvWebPager)(icqlink, hour, minute, day, month, year,
+                                                icq_ListAt(strList, 0), icq_ListAt(strList, 3),
+                                                icq_ListAt(strList, 5));
       break;
     case TYPE_EXPRESS:
       /* Format: Nick, 0xFE, Empty-FName, 0xFE, Empty-LName, 0xFE, EMail, 0xFE,
@@ -255,29 +125,49 @@
       fieldCount = icq_SplitFields(strList, data);
       if(fieldCount != 6)
       {
-        icq_FmtLog(link, ICQ_LOG_ERROR, "Bad TYPE_EXPRESS packet (expected 6 args, received %i)!\n",
+        icq_FmtLog(icqlink, ICQ_LOG_ERROR, "Bad TYPE_EXPRESS packet (expected 6 args, received %i)!\n",
                    fieldCount);
         return;
       }
-      icq_RusConv("wk", list_at(strList, 0)); /* Nick */
-      icq_RusConv("wk", list_at(strList, 5)); /* Message */
-      icq_FmtLog(link, ICQ_LOG_MESSAGE, "MailExpress message received, Nick: %s, EMail: %s, "
-                 "Message:\n%s\n", list_at(strList, 0), list_at(strList, 3),
-                 list_at(strList, 5));
-      if(link->icq_RecvMailExpress)
-        (*link->icq_RecvMailExpress)(link, hour, minute, day, month, year, list_at(strList, 0),
-                               list_at(strList, 3), list_at(strList, 5));
+      icq_RusConv("wk", icq_ListAt(strList, 0)); /* Nick */
+      icq_RusConv("wk", icq_ListAt(strList, 5)); /* Message */
+      icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "MailExpress message received, Nick: %s, EMail: %s, "
+                 "Message:\n%s\n", icq_ListAt(strList, 0), icq_ListAt(strList, 3),
+                 icq_ListAt(strList, 5));
+      invoke_callback(icqlink, icq_RecvMailExpress)(icqlink, hour, minute, day, month, year,
+                                                   icq_ListAt(strList, 0), icq_ListAt(strList, 3),
+                                                   icq_ListAt(strList, 5));
+      break;
+    case TYPE_CONTACT:
+      /* Format: Number of contacts, 0xFE, UIN, 0xFE, Nick, 0xFE, ... */
+      nr = icq_SplitFields(strList, data);
+      contact_uin = (const char**)malloc((nr - 1) / 2);
+      contact_nick = (const char**)malloc((nr - 1) / 2);
+
+      icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "Contact List received from %lu (%i):\n", uin,
+                 atoi(icq_ListAt(strList, 0)));
+
+      for(i = 1, k = 0; i < (nr - 1); k++)
+      {
+        contact_uin[k] = icq_ListAt(strList, i);
+        contact_nick[k] = icq_ListAt(strList, i + 1);
+        i += 2;
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "\t%s - %s\n", contact_uin[k], contact_nick[k]);
+      }
+      invoke_callback(icqlink, icq_RecvContactList)(icqlink, uin, hour, minute, day, month, year,
+                                                 k, contact_uin, contact_nick);
+      free(contact_uin);
+      free(contact_nick);
       break;
     default:
       icq_RusConv("wk", data); /* Entire message */
-      icq_FmtLog(link, ICQ_LOG_MESSAGE, "Instant message type %i from %lu:\n%s\n", type, uin, data);
-      if(link->icq_RecvMessage)
-        (*link->icq_RecvMessage)(link, uin, hour, minute, day, month, year, data);
+      icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "Instant message type %i from %lu:\n%s\n", type, uin, data);
+      invoke_callback(icqlink, icq_RecvMessage)(icqlink, uin, hour, minute, day, month, year, data);
   }
-  list_delete(strList, free);
+  icq_ListDelete(strList, free);
 }
 
-void icq_HandleInfoReply(ICQLINK *link, icq_Packet *p)
+void icq_HandleInfoReply(icq_Link *icqlink, icq_Packet *p)
 {
   char *ptr1, *ptr2, *ptr3, *ptr4;
   DWORD uin;
@@ -291,17 +181,16 @@
   icq_RusConv("wk", ptr2);
   icq_RusConv("wk", ptr3);
   icq_RusConv("wk", ptr4);
-  icq_FmtLog(link, ICQ_LOG_MESSAGE, "Info reply for %lu\n", uin);
-  if(link->icq_InfoReply)
-    (*link->icq_InfoReply)(link, uin, ptr1, ptr2, ptr3, ptr4, icq_PacketRead8(p));
-  icq_UDPAck(link, icq_PacketReadUDPInSeq1(p));
+  icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "Info reply for %lu\n", uin);
+  invoke_callback(icqlink,icq_InfoReply)(icqlink, uin, ptr1, ptr2, ptr3, ptr4, icq_PacketRead8(p));
+  icq_UDPAck(icqlink, icq_PacketReadUDPInSeq1(p));
   free(ptr1);
   free(ptr2);
   free(ptr3);
   free(ptr4);
 }
 
-void icq_HandleExtInfoReply(ICQLINK *link, icq_Packet *p)
+void icq_HandleExtInfoReply(icq_Link *icqlink, icq_Packet *p)
 {
   char *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
   DWORD uin;
@@ -324,11 +213,10 @@
   icq_RusConv("wk", ptr3);
   icq_RusConv("wk", ptr4);
   icq_RusConv("wk", ptr5);
-  icq_FmtLog(link, ICQ_LOG_MESSAGE, "Extended info reply for %lu\n", uin);
-  if(link->icq_ExtInfoReply)
-    (*link->icq_ExtInfoReply)(link, uin, (char*)ptr1, cnt_code, cnt_stat, (char*)ptr2, age,
-                              gender, (char*)ptr3, (char*)ptr4, (char*)ptr5);
-  icq_UDPAck(link, icq_PacketReadUDPInSeq1(p));
+  icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "Extended info reply for %lu\n", uin);
+  invoke_callback(icqlink,icq_ExtInfoReply)(icqlink, uin, (char*)ptr1, cnt_code, cnt_stat, (char*)ptr2,
+                                            age, gender, (char*)ptr3, (char*)ptr4, (char*)ptr5);
+  icq_UDPAck(icqlink, icq_PacketReadUDPInSeq1(p));
   free(ptr1);
   free(ptr2);
   free(ptr3);
@@ -336,7 +224,7 @@
   free(ptr5);
 }
 
-void icq_HandleSearchReply(ICQLINK *link, icq_Packet *p)
+void icq_HandleSearchReply(icq_Link *icqlink, icq_Packet *p)
 {
   char *ptr1, *ptr2, *ptr3, *ptr4, auth;
   DWORD uin;
@@ -351,11 +239,11 @@
   icq_RusConv("wk", ptr3);
   icq_RusConv("wk", ptr4);
   auth = icq_PacketRead8(p);
-  icq_FmtLog(link, ICQ_LOG_MESSAGE, "User found %lu, Nick: %s, First Name: %s, Last Name: %s, "
+  icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "User found %lu, Nick: %s, First Name: %s, Last Name: %s, "
              "EMail: %s, Auth: %s\n", uin, ptr1, ptr2, ptr3, ptr4, auth==1?"no":"yes");
-  if(link->icq_UserFound)
-    (*link->icq_UserFound)(link, uin, (char*)ptr1, (char*)ptr2, (char*)ptr3, (char*)ptr4, auth);
-  icq_UDPAck(link, icq_PacketReadUDPInSeq1(p));
+  invoke_callback(icqlink,icq_UserFound)(icqlink, uin, (char*)ptr1, (char*)ptr2,
+                                         (char*)ptr3, (char*)ptr4, auth);
+  icq_UDPAck(icqlink, icq_PacketReadUDPInSeq1(p));
   free(ptr1);
   free(ptr2);
   free(ptr3);
@@ -365,27 +253,26 @@
 /************************************************
 This is called when a user goes offline
 *************************************************/
-void icq_HandleUserOffline(ICQLINK *link, icq_Packet *p)
+void icq_HandleUserOffline(icq_Link *icqlink, icq_Packet *p)
 {
   DWORD remote_uin;
   icq_ContactItem *ptr;
 
   icq_PacketGotoUDPInData(p, 0);
   remote_uin = icq_PacketRead32(p);
-  icq_FmtLog(link, ICQ_LOG_MESSAGE, "User %lu logged off\n", remote_uin);
-  if(link->icq_UserOffline)
-    (*link->icq_UserOffline)(link, remote_uin);
+  icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "User %lu logged off\n", remote_uin);
+  invoke_callback(icqlink,icq_UserOffline)(icqlink, remote_uin);
 
-  ptr=icq_ContactFind(link, remote_uin);
+  ptr=icq_ContactFind(icqlink, remote_uin);
   if(ptr)
   {
     ptr->remote_ip = 0;
     ptr->remote_port = 0;
   }
-  icq_UDPAck(link, icq_PacketReadUDPInSeq1(p));
+  icq_UDPAck(icqlink, icq_PacketReadUDPInSeq1(p));
 }
 
-void icq_HandleUserOnline(ICQLINK *link, icq_Packet *p)
+void icq_HandleUserOnline(icq_Link *icqlink, icq_Packet *p)
 {
   DWORD remote_uin, new_status, remote_ip, remote_real_ip;
   DWORD remote_port; /* Why Mirabilis used 4 bytes for port? */
@@ -400,14 +287,14 @@
   tcp_flag = icq_PacketRead8(p);
   new_status = icq_PacketRead32(p);
 
-  icq_FmtLog(link, ICQ_LOG_MESSAGE,
+  icq_FmtLog(icqlink, ICQ_LOG_MESSAGE,
              "User %lu (%s = 0x%X) logged on. tcp_flag=0x%X IP=%08X, real IP=%08X, port=%d\n",
              remote_uin, icq_ConvertStatus2Str(new_status), new_status, tcp_flag, remote_ip,
              remote_real_ip, remote_port);
-  if(link->icq_UserOnline)
-    (*link->icq_UserOnline)(link, remote_uin, new_status, remote_ip, remote_port, remote_real_ip, tcp_flag);
+  invoke_callback(icqlink,icq_UserOnline)(icqlink, remote_uin, new_status, remote_ip,
+                                          remote_port, remote_real_ip, tcp_flag);
 
-  ptr=icq_ContactFind(link, remote_uin);
+  ptr=icq_ContactFind(icqlink, remote_uin);
   if(ptr)
   {
     ptr->remote_ip=remote_ip;
@@ -415,44 +302,44 @@
     ptr->remote_port = remote_port;
     ptr->tcp_flag = tcp_flag;
   }
-  icq_UDPAck(link, icq_PacketReadUDPInSeq1(p));
+  icq_UDPAck(icqlink, icq_PacketReadUDPInSeq1(p));
 }
 
-void icq_HandleStatusChange(ICQLINK *link, icq_Packet *p)
+void icq_HandleStatusChange(icq_Link *icqlink, icq_Packet *p)
 {
   unsigned long remote_uin, new_status;
 
   icq_PacketGotoUDPInData(p, 0);
   remote_uin = icq_PacketRead32(p);
   new_status = icq_PacketRead32(p);
-  icq_FmtLog(link, ICQ_LOG_MESSAGE, "%lu changed status to %s (0x%X)\n", remote_uin,
+  icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "%lu changed status to %s (0x%X)\n", remote_uin,
              icq_ConvertStatus2Str(new_status), new_status);
-  if(link->icq_UserStatusUpdate)
-    (*link->icq_UserStatusUpdate)(link, remote_uin, new_status);
-  icq_UDPAck(link, icq_PacketReadUDPInSeq1(p));
+  invoke_callback(icqlink,icq_UserStatusUpdate)(icqlink, remote_uin, new_status);
+  icq_UDPAck(icqlink, icq_PacketReadUDPInSeq1(p));
 }
 
-void icq_HandleMetaUserInfo(ICQLINK *link, icq_Packet *p)
+void icq_HandleMetaUserInfo(icq_Link *icqlink, icq_Packet *p)
 {
   unsigned short subcmd, country, seq2, age, occupation, wcountry;
-  unsigned char res, auth, timezone, webaware, hideip, gender;
-  unsigned char *nick, *first, *last, *email, *about, *city;
-  unsigned char *pri_eml, *sec_eml, *old_eml;
-  unsigned char *phone, *fax, *street, *cellular, *state;
-  unsigned char *wcity, *wstate, *wphone, *wfax, *waddress;
-  unsigned char *company, *department, *job, *whomepage;
-  unsigned char *homepage;
-  unsigned char byear, bmonth, bday, lang1, lang2, lang3, inum, i;
-  unsigned char anum, bnum, hnum;
+  char res, auth, timezone, webaware, hideip, gender;
+  char *nick, *first, *last, *email, *about, *city;
+  char *pri_eml, *sec_eml, *old_eml;
+  char *phone, *fax, *street, *cellular, *state;
+  char *wcity, *wstate, *wphone, *wfax, *waddress;
+  char *company, *department, *job, *whomepage;
+  char *homepage;
+  char byear, bmonth, bday, lang1, lang2, lang3, inum;
+  int i;
+  char anum, bnum, hnum;
   unsigned long uin, zip, wzip;
-  unsigned char *empty = "";
-  unsigned char *interests[4] = {0, 0, 0, 0};
+  char *empty = NULL;
+  char *interests[4] = {0, 0, 0, 0};
   unsigned short icategory[4] = {0, 0, 0, 0};
-  unsigned char *affiliations[4] = {0, 0, 0, 0};
+  char *affiliations[4] = {0, 0, 0, 0};
   unsigned short acategory[4] = {0, 0, 0, 0};
-  unsigned char *backgrounds[4] = {0, 0, 0, 0};
+  char *backgrounds[4] = {0, 0, 0, 0};
   unsigned short bcategory[4] = {0, 0, 0, 0};
-  unsigned char *hpcat[4] = {0, 0, 0, 0};
+  char *hpcat[4] = {0, 0, 0, 0};
   unsigned short hcategory[4] = {0, 0, 0, 0};
 
   seq2 = icq_PacketReadUDPInSeq2(p);
@@ -461,9 +348,9 @@
   res = icq_PacketRead8(p);
   if(res == META_SRV_FAILURE)
   {
-    icq_FmtLog(link, ICQ_LOG_WARNING, "META failure\n");
-    if(link->icq_RequestNotify)
-      (*link->icq_RequestNotify)(link, seq2, ICQ_NOTIFY_FAILED, sizeof(subcmd), &subcmd);
+    icq_FmtLog(icqlink, ICQ_LOG_WARNING, "META failure\n");
+    invoke_callback(icqlink,icq_RequestNotify)(icqlink, seq2, ICQ_NOTIFY_FAILED,
+                                               sizeof(subcmd), &subcmd);
   }
   else
     switch(subcmd)
@@ -475,23 +362,22 @@
         last = icq_PacketReadStringNew(p);
         email = icq_PacketReadStringNew(p);
         auth = icq_PacketRead8(p);
-        icq_PacketRead16(p); // ???
-        icq_PacketRead32(p); // ???
+        icq_PacketRead16(p); /* ??? */
+        icq_PacketRead32(p); /* ??? */
         icq_RusConv("wk", nick);
         icq_RusConv("wk", first);
         icq_RusConv("wk", last);
         icq_RusConv("wk", email);
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User Found %lu, Nick: %s, First Name: %s, "\
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "META User Found %lu, Nick: %s, First Name: %s, "\
                    "Last Name: %s, EMail: %s, Auth: %s\n", seq2, uin, nick, first, last,
                    email, auth==1?"no":"yes");
-        if(link->icq_MetaUserFound)
-          (*link->icq_MetaUserFound)(link, seq2, uin, nick, first, last, email, auth);
+        invoke_callback(icqlink,icq_MetaUserFound)(icqlink, seq2, uin, nick, first, last, email, auth);
         free(nick);
         free(first);
         free(last);
         free(email);
         break;
-      case META_SRV_USER_INFO: // finished!
+      case META_SRV_USER_INFO: /* finished! */
         nick = icq_PacketReadStringNew(p);
         first = icq_PacketReadStringNew(p);
         last = icq_PacketReadStringNew(p);
@@ -506,10 +392,10 @@
         cellular = icq_PacketReadStringNew(p);
         zip = icq_PacketRead32(p);
         country = icq_PacketRead16(p);
-        timezone = icq_PacketRead8(p);         // +1 = -30min, -1 = +30min (-4 = GMT+0200)
-        auth = icq_PacketRead8(p);             // 1 - no auth required, 0 - required
-        webaware = icq_PacketRead8(p);         // 1 - yes, 0 - no
-        hideip = icq_PacketRead8(p);           // 1 - yes, 0 - no
+        timezone = icq_PacketRead8(p);         /* +1 = -30min, -1 = +30min (-4 = GMT+0200) */
+        auth = icq_PacketRead8(p);             /* 1 - no auth required, 0 - required */
+        webaware = icq_PacketRead8(p);         /* 1 - yes, 0 - no */
+        hideip = icq_PacketRead8(p);           /* 1 - yes, 0 - no */
         icq_RusConv("wk", nick);
         icq_RusConv("wk", first);
         icq_RusConv("wk", last);
@@ -522,15 +408,15 @@
         icq_RusConv("wk", fax);
         icq_RusConv("wk", street);
         icq_RusConv("wk", cellular);
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User Info: %s, %s, %s, "\
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "META User Info: %s, %s, %s, "\
                    "%s, %s, %s, %s, %s, %s, %s, %s, %s, %lu, %s, %i, %s, %s, %s\n",
                    nick, first, last, pri_eml, sec_eml, old_eml, city, state, phone,
                    fax, street, cellular, zip, icq_GetCountryName(country), timezone,
                    auth?"false":"true", webaware?"true":"false", hideip?"true":"false");
-        if(link->icq_MetaUserInfo)
-          (*link->icq_MetaUserInfo)(link, seq2, nick, first, last, pri_eml, sec_eml,
-                                    old_eml, city, state, phone, fax, street, cellular,
-                                    zip, country, timezone, auth, webaware, hideip);
+        invoke_callback(icqlink,icq_MetaUserInfo)(icqlink, seq2, nick, first, last, pri_eml,
+                                                  sec_eml, old_eml, city, state, phone, fax,
+                                                  street, cellular, zip, country, timezone,
+                                                  auth, webaware, hideip);
         free(nick);
         free(first);
         free(last);
@@ -544,18 +430,18 @@
         free(street);
         free(cellular);
         break;
-      case META_SRV_USER_WORK: // finished!
+      case META_SRV_USER_WORK: /* finished! */
         wcity = icq_PacketReadStringNew(p);
         wstate = icq_PacketReadStringNew(p);
         wphone = icq_PacketReadStringNew(p);
         wfax = icq_PacketReadStringNew(p);
         waddress = icq_PacketReadStringNew(p);
         wzip = icq_PacketRead32(p);
-        wcountry = icq_PacketRead16(p);          // icq_GetCountryName()
+        wcountry = icq_PacketRead16(p);          /* icq_GetCountryName() */
         company = icq_PacketReadStringNew(p);
         department = icq_PacketReadStringNew(p);
         job = icq_PacketReadStringNew(p);
-        occupation = icq_PacketRead16(p);        // icq_GetMetaOccupationName()
+        occupation = icq_PacketRead16(p);        /* icq_GetMetaOccupationName() */
         whomepage = icq_PacketReadStringNew(p);
         icq_RusConv("wk", wcity);
         icq_RusConv("wk", wstate);
@@ -566,15 +452,14 @@
         icq_RusConv("wk", department);
         icq_RusConv("wk", job);
         icq_RusConv("wk", whomepage);
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User Work: %s, %s, %s, "\
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "META User Work: %s, %s, %s, "\
                    "%s, %s,   %lu, %s, %s, %s, %s, %s, %s\n", wcity, wstate,
                    wphone, wfax, waddress, wzip, icq_GetCountryName(wcountry),
                    company, department, job, icq_GetMetaOccupationName(occupation),
                    whomepage);
-        if(link->icq_MetaUserWork)
-          (*link->icq_MetaUserWork)(link, seq2, wcity, wstate, wphone, wfax,
-                                    waddress, wzip, wcountry, company, department,
-                                    job, occupation, whomepage);
+        invoke_callback(icqlink, icq_MetaUserWork)(icqlink, seq2, wcity, wstate, wphone,
+                                                   wfax, waddress, wzip, wcountry, company,
+                                                   department, job, occupation, whomepage);
         free(wcity);
         free(wstate);
         free(wphone);
@@ -585,36 +470,35 @@
         free(job);
         free(whomepage);
         break;
-      case META_SRV_USER_MORE: // finished!
-        age = icq_PacketRead16(p);    // 0xFFFF - not entered
-        gender = icq_PacketRead8(p);  // 1 - female, 2 - male
+      case META_SRV_USER_MORE: /* finished! */
+        age = icq_PacketRead16(p);    /* 0xFFFF - not entered */
+        gender = icq_PacketRead8(p);  /* 1 - female, 2 - male */
         homepage = icq_PacketReadStringNew(p);
-        byear = icq_PacketRead8(p);   // starting from 1900
+        byear = icq_PacketRead8(p);   /* starting from 1900 */
         bmonth = icq_PacketRead8(p);
         bday = icq_PacketRead8(p);
-        lang1 = icq_PacketRead8(p);   // icq_GetMetaLanguageName()
-        lang2 = icq_PacketRead8(p);   // icq_GetMetaLanguageName()
-        lang3 = icq_PacketRead8(p);   // icq_GetMetaLanguageName()
+        lang1 = icq_PacketRead8(p);   /* icq_GetMetaLanguageName() */
+        lang2 = icq_PacketRead8(p);   /* icq_GetMetaLanguageName() */
+        lang3 = icq_PacketRead8(p);   /* icq_GetMetaLanguageName() */
         icq_RusConv("wk", homepage);
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User More: %i, %s, %s, "\
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "META User More: %i, %s, %s, "\
                    "%02i/%02i/%04i, %s, %s, %s\n", age,
                    gender==1?"female":gender==2?"male":"not entered",
                    homepage, bday, bmonth, byear+1900, icq_GetMetaLanguageName(lang1),
                    icq_GetMetaLanguageName(lang2), icq_GetMetaLanguageName(lang3));
-        if(link->icq_MetaUserMore)
-          (*link->icq_MetaUserMore)(link, seq2, age, gender, homepage, byear,
+        if(icqlink->icq_MetaUserMore)
+          (*icqlink->icq_MetaUserMore)(icqlink, seq2, age, gender, homepage, byear,
                                     bmonth, bday, lang1, lang2, lang3);
         free(homepage);
         break;
-      case META_SRV_USER_ABOUT: // finished!
+      case META_SRV_USER_ABOUT: /* finished! */
         about = icq_PacketReadStringNew(p);
         icq_RusConv("wk", about);
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User About: %s\n", about);
-        if(link->icq_MetaUserAbout)
-          (*link->icq_MetaUserAbout)(link, seq2, about);
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "META User About: %s\n", about);
+        invoke_callback(icqlink,icq_MetaUserAbout)(icqlink, seq2, about);
         free(about);
         break;
-      case META_SRV_USER_INTERESTS: // finished!
+      case META_SRV_USER_INTERESTS: /* finished! */
         inum = icq_PacketRead8(p);
         for(i=0; i<inum && i<4; i++)
         {
@@ -622,34 +506,34 @@
           interests[i] = icq_PacketReadStringNew(p);
           icq_RusConv("wk", interests[i]);
         }
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User Interests: %i, %i - %s, "\
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "META User Interests: %i, %i - %s, "\
                    "%i - %s, %i - %s, %i - %s\n", inum, icategory[0],
                    interests[0]?interests[0]:empty, icategory[1], interests[1]?interests[1]:empty,
                    icategory[2], interests[2]?interests[2]:empty, icategory[3],
                    interests[3]?interests[3]:empty);
-        if(link->icq_MetaUserInterests)
-          (*link->icq_MetaUserInterests)(link, seq2, inum, icategory[0], interests[0],
-                                         icategory[1], interests[1], icategory[2],
-                                         interests[2], icategory[3], interests[3]);
+        invoke_callback(icqlink, icq_MetaUserInterests)(icqlink, seq2, inum,
+                                                        icategory[0], interests[0], icategory[1], 
+                                                        interests[1], icategory[2], interests[2],
+                                                        icategory[3], interests[3]);
         for(i=0; i<inum && i<4; i++)
           free(interests[i]);
         break;
-      case META_SRV_USER_AFFILIATIONS: // finished!
+      case META_SRV_USER_AFFILIATIONS: /* finished! */
         bnum = icq_PacketRead8(p);
         for(i=0; i<bnum && i<4; i++)
         {
-          bcategory[i] = icq_PacketRead16(p);           // icq_GetMetaBackgroundName()
+          bcategory[i] = icq_PacketRead16(p);           /* icq_GetMetaBackgroundName() */
           backgrounds[i] = icq_PacketReadStringNew(p);
           icq_RusConv("wk", backgrounds[i]);
         }
         anum = icq_PacketRead8(p);
         for(i=0; i<anum && i<4; i++)
         {
-          acategory[i] = icq_PacketRead16(p);           // icq_GetMetaAffiliationName()
+          acategory[i] = icq_PacketRead16(p);           /* icq_GetMetaAffiliationName() */
           affiliations[i] = icq_PacketReadStringNew(p);
           icq_RusConv("wk", affiliations[i]);
         }
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User Affiliations: %i, %s - %s, "\
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "META User Affiliations: %i, %s - %s, "\
                    "%s - %s, %s - %s, %s - %s; Backgrounds: %i, %s - %s, %s - %s, "\
                    "%s - %s, %s - %s\n", anum,
                    icq_GetMetaAffiliationName(acategory[0]), affiliations[0]?affiliations[0]:empty,
@@ -660,18 +544,19 @@
                    icq_GetMetaBackgroundName(bcategory[1]), backgrounds[1]?backgrounds[1]:empty,
                    icq_GetMetaBackgroundName(bcategory[2]), backgrounds[2]?backgrounds[2]:empty,
                    icq_GetMetaBackgroundName(bcategory[3]), backgrounds[3]?backgrounds[3]:empty);
-        if(link->icq_MetaUserAffiliations)
-          (*link->icq_MetaUserAffiliations)(link, seq2, anum, acategory[0],
-                  affiliations[0], acategory[1], affiliations[1], acategory[2],
-                  affiliations[2], acategory[3], affiliations[3], bnum,
-                  bcategory[0], backgrounds[0], bcategory[1], backgrounds[1],
-                  bcategory[2], backgrounds[2], bcategory[3], backgrounds[3]);
+        invoke_callback(icqlink, icq_MetaUserAffiliations)(icqlink, seq2, anum, acategory[0],
+                                                           affiliations[0], acategory[1], affiliations[1],
+                                                           acategory[2], affiliations[2], acategory[3],
+                                                           affiliations[3], bnum, bcategory[0],
+                                                           backgrounds[0], bcategory[1], backgrounds[1],
+                                                           bcategory[2], backgrounds[2], bcategory[3],
+                                                           backgrounds[3]);
         for(i=0; i<bnum && i<4; i++)
           free(backgrounds[i]);
         for(i=0; i<anum && i<4; i++)
           free(affiliations[i]);
         break;
-      case META_SRV_USER_HPCATEGORY: // finished!
+      case META_SRV_USER_HPCATEGORY: /* finished! */
         hnum = icq_PacketRead8(p);
         for(i=0; i<hnum && i<1; i++)
         {
@@ -679,10 +564,10 @@
           hpcat[i] = icq_PacketReadStringNew(p);
           icq_RusConv("wk", hpcat[i]);
         }
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User Homepage Category: %i, %i - %s\n",
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "META User Homepage Category: %i, %i - %s\n",
                    hnum, hcategory[0], hpcat[0]);
-        if(link->icq_MetaUserHomePageCategory)
-          (*link->icq_MetaUserHomePageCategory)(link, seq2, hnum, hcategory[0], hpcat[0]?hpcat[0]:empty);
+        invoke_callback(icqlink,icq_MetaUserHomePageCategory)(icqlink, seq2,
+                                                              hnum, hcategory[0], hpcat[0]?hpcat[0]:empty);
         for(i=0; i<hnum && i<1; i++)
           free(hpcat[i]);
         break;
@@ -691,26 +576,26 @@
       case META_SRV_RES_ABOUT:
       case META_SRV_RES_SECURE:
       case META_SRV_RES_PASS:
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "META success\n");
-        if(link->icq_RequestNotify)
-          (*link->icq_RequestNotify)(link, seq2, ICQ_NOTIFY_SUCCESS, sizeof(subcmd), &subcmd);
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "META success\n");
+        invoke_callback(icqlink,icq_RequestNotify)(icqlink, seq2, ICQ_NOTIFY_SUCCESS,
+                                                   sizeof(subcmd), &subcmd);
         break;
       default:
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "META User - 0x%04X\n", subcmd);
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "META User - 0x%04X\n", subcmd);
         icq_PacketUDPDump(p);
         break;
     }
-  icq_UDPAck(link, icq_PacketReadUDPInSeq1(p));
+  icq_UDPAck(icqlink, icq_PacketReadUDPInSeq1(p));
 }
 
-void icq_HandleMultiPacket(ICQLINK *link, icq_Packet *p)
+void icq_HandleMultiPacket(icq_Link *icqlink, icq_Packet *p)
 {
   icq_Packet *tmp;
   int num, i;
   icq_PacketGotoUDPInData(p, 0);
   num = icq_PacketRead8(p);
 
-  icq_FmtLog(link, ICQ_LOG_MESSAGE, "MultiPacket: %i packets\n", num);
+  icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "MultiPacket: %i packets\n", num);
 
   for(i = 0; i < num; i++)
   {
@@ -718,12 +603,12 @@
     tmp->length = icq_PacketRead16(p);
     memcpy(tmp->data, &(p->data[p->cursor]), tmp->length);
     icq_PacketAdvance(p, tmp->length);
-    icq_ServerResponse(link, tmp);
+    icq_ServerResponse(icqlink, tmp);
     icq_PacketDelete(tmp);
   }
 }
 
-void icq_ServerResponse(ICQLINK *link, icq_Packet *p)
+void icq_ServerResponse(icq_Link *icqlink, icq_Packet *p)
 {
   time_t cur_time;
   struct tm *tm_str;
@@ -741,37 +626,32 @@
     switch(cmd)
     {
       case UDP_SRV_ACK:
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "The server acknowledged the command\n");
-        if(link->icq_RequestNotify)
-        {
-          (*link->icq_RequestNotify)(link, seq, ICQ_NOTIFY_ACK, 0, 0);
-          (*link->icq_RequestNotify)(link, seq, ICQ_NOTIFY_SUCCESS, 0, 0);
-        }
-        icq_UDPQueueDelSeq(link, seq);
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "The server acknowledged the command\n");
+        invoke_callback(icqlink,icq_RequestNotify)(icqlink, seq, ICQ_NOTIFY_ACK, 0, 0);
+        invoke_callback(icqlink,icq_RequestNotify)(icqlink, seq, ICQ_NOTIFY_SUCCESS, 0, 0);
+        icq_UDPQueueDelSeq(icqlink, seq);
         break;
       case UDP_SRV_MULTI_PACKET:
-        icq_HandleMultiPacket(link, p);
+        icq_HandleMultiPacket(icqlink, p);
         break;
       case UDP_SRV_NEW_UIN:
         uin = icq_PacketReadUDPInUIN(p);
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "The new uin is %lu\n", uin);
-        icq_UDPAck(link, seq);
-        if(link->icq_NewUIN)
-          (*link->icq_NewUIN)(link, uin);
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "The new uin is %lu\n", uin);
+        icq_UDPAck(icqlink, seq);
+        invoke_callback(icqlink,icq_NewUIN)(icqlink, uin);
         break;
       case UDP_SRV_LOGIN_REPLY:
         icq_PacketGotoUDPInData(p, 0);
-        link->icq_OurIP = ntohl(icq_PacketRead32n(p));
+        icqlink->icq_OurIP = ntohl(icq_PacketRead32n(p));
 /*       icq_OurIp = icq_PacketRead32(p); */
-        in_a.s_addr = htonl(link->icq_OurIP);
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "Login successful, UIN: %lu, IP: %s\n",
-                   link->icq_Uin, inet_ntoa(in_a));
-        icq_UDPAck(link, seq);
-        icq_SendLogin1(link);
-        icq_SendContactList(link);
-        icq_SendVisibleList(link);
-        if(link->icq_Logged)
-          (*link->icq_Logged)(link);
+        in_a.s_addr = htonl(icqlink->icq_OurIP);
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "Login successful, UIN: %lu, IP: %s\n",
+                   icqlink->icq_Uin, inet_ntoa(in_a));
+        icq_UDPAck(icqlink, seq);
+        icq_SendLogin1(icqlink);
+        icq_SendContactList(icqlink);
+        icq_SendVisibleList(icqlink);
+        invoke_callback(icqlink,icq_Logged)(icqlink);
         break;
       case UDP_SRV_OFFLINE_MESSAGE: /* Offline message through the server */
         icq_PacketGotoUDPInData(p, 0);
@@ -783,50 +663,49 @@
         minute = icq_PacketRead8(p);
         type = icq_PacketRead16(p);
         len = icq_PacketRead16(p);
-        icq_DoMsg(link, type, len, (char*)&p->data[p->cursor], uin, hour, minute, day, month, year);
-        icq_UDPAck(link, seq);
+        icq_DoMsg(icqlink, type, len, (char*)&p->data[p->cursor], uin, hour, minute, day, month, year);
+        icq_UDPAck(icqlink, seq);
         break;
       case UDP_SRV_X1: /* unknown message sent after login*/
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "Acknowleged UDP_SRV_X1 (Begin messages)\n");
-        icq_UDPAck(link, seq);
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "Acknowleged UDP_SRV_X1 (Begin messages)\n");
+        icq_UDPAck(icqlink, seq);
         break;
       case UDP_SRV_X2: /* unknown message sent after login*/
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "Acknowleged UDP_SRV_X2 (Done old messages)\n");
-        icq_UDPAck(link, seq);
-        icq_SendGotMessages(link);
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "Acknowleged UDP_SRV_X2 (Done old messages)\n");
+        icq_UDPAck(icqlink, seq);
+        icq_SendGotMessages(icqlink);
         break;
       case UDP_SRV_INFO_REPLY:
-        icq_HandleInfoReply(link, p);
+        icq_HandleInfoReply(icqlink, p);
         break;
       case UDP_SRV_EXT_INFO_REPLY:
-        icq_HandleExtInfoReply(link, p);
+        icq_HandleExtInfoReply(icqlink, p);
         break;
       case UDP_SRV_USER_ONLINE:
-        icq_HandleUserOnline(link, p);
+        icq_HandleUserOnline(icqlink, p);
         break;
       case UDP_SRV_USER_OFFLINE:
-        icq_HandleUserOffline(link, p);
+        icq_HandleUserOffline(icqlink, p);
         break;
       case UDP_SRV_TRY_AGAIN:
-        icq_FmtLog(link, ICQ_LOG_WARNING, "Server is busy, please try again\n");
-        icq_Login(link, link->icq_Status);
+        icq_FmtLog(icqlink, ICQ_LOG_WARNING, "Server is busy, please try again\n");
+        icq_Login(icqlink, icqlink->icq_Status);
         break;
       case UDP_SRV_STATUS_UPDATE:
-        icq_HandleStatusChange(link, p);
+        icq_HandleStatusChange(icqlink, p);
         break;
       case UDP_SRV_GO_AWAY:
-        icq_FmtLog(link, ICQ_LOG_ERROR, "Server has forced us to disconnect\n");
-        if(link->icq_Disconnected)
-          (*link->icq_Disconnected)(link);
+        icq_FmtLog(icqlink, ICQ_LOG_ERROR, "Server has forced us to disconnect\n");
+        if(icqlink->icq_Disconnected)
+          (*icqlink->icq_Disconnected)(icqlink);
         break;
       case UDP_SRV_END_OF_SEARCH:
-        icq_FmtLog(link, ICQ_LOG_MESSAGE, "Search done\n");
-        if(link->icq_SearchDone)
-          (*link->icq_SearchDone)(link);
-        icq_UDPAck(link, seq);
+        icq_FmtLog(icqlink, ICQ_LOG_MESSAGE, "Search done\n");
+        invoke_callback(icqlink,icq_SearchDone)(icqlink);
+        icq_UDPAck(icqlink, seq);
         break;
       case UDP_SRV_USER_FOUND:
-        icq_HandleSearchReply(link, p);
+        icq_HandleSearchReply(icqlink, p);
         break;
       case UDP_SRV_ONLINE_MESSAGE: /* Online message through the server */
         cur_time = time(0L);
@@ -835,74 +714,71 @@
         uin = icq_PacketRead32(p);
         type = icq_PacketRead16(p);
         len = icq_PacketRead16(p);
-        icq_DoMsg(link, type, len, (char*)&p->data[p->cursor], uin, tm_str->tm_hour,
+        icq_DoMsg(icqlink, type, len, (char*)&p->data[p->cursor], uin, tm_str->tm_hour,
                   tm_str->tm_min, tm_str->tm_mday, tm_str->tm_mon+1, tm_str->tm_year+1900);
-        icq_UDPAck(link, seq);
+        icq_UDPAck(icqlink, seq);
         break;
       case UDP_SRV_WRONG_PASSWORD:
-        icq_FmtLog(link, ICQ_LOG_ERROR, "Wrong password\n");
-        icq_UDPAck(link, seq);
-        if(link->icq_WrongPassword)
-          (*link->icq_WrongPassword)(link);
+        icq_FmtLog(icqlink, ICQ_LOG_ERROR, "Wrong password\n");
+        icq_UDPAck(icqlink, seq);
+        invoke_callback(icqlink,icq_WrongPassword)(icqlink);
         break;
       case UDP_SRV_INVALID_UIN:
-        icq_FmtLog(link, ICQ_LOG_WARNING, "Invalid UIN\n");
-        icq_UDPAck(link, seq);
-        if(link->icq_InvalidUIN)
-          (*link->icq_InvalidUIN)(link);
+        icq_FmtLog(icqlink, ICQ_LOG_WARNING, "Invalid UIN\n");
+        icq_UDPAck(icqlink, seq);
+        invoke_callback(icqlink,icq_InvalidUIN)(icqlink);
         break;
       case UDP_SRV_META_USER:
-        icq_HandleMetaUserInfo(link, p);
+        icq_HandleMetaUserInfo(icqlink, p);
         break;
       default: /* commands we dont handle yet */
-        icq_FmtLog(link, ICQ_LOG_WARNING, "Unhandled message %04x, Version: %x, "
+        icq_FmtLog(icqlink, ICQ_LOG_WARNING, "Unhandled message %04x, Version: %x, "
                    "Sequence: %04x, Size: %d\n", cmd, icq_PacketReadUDPInVer(p),
                    seq, p->length);
-        icq_UDPAck(link, seq); /* fake like we know what we're doing */
+        icq_UDPAck(icqlink, seq); /* fake like we know what we're doing */
         break;
     }
   }
   else
   {
-    icq_FmtLog(link, ICQ_LOG_WARNING, "Unhandled protocol version! Message %04x, Version: %x, "
+    icq_FmtLog(icqlink, ICQ_LOG_WARNING, "Unhandled protocol version! Message %04x, Version: %x, "
                "Sequence: %04x, Size: %d\n", cmd, icq_PacketReadUDPInVer(p),
                seq, p->length);
-/*    icq_UDPAck(link, seq);  DO NOT ACK unhandled protocol version! */
+/*    icq_UDPAck(icqlink, seq);  DO NOT ACK unhandled protocol version! */
   }
 }
 
 /******************************************
 Handles packets that the server sends to us.
 *******************************************/
-void icq_HandleServerResponse(ICQLINK *link)
+void icq_HandleServerResponse(icq_Link *icqlink)
 {
   WORD seq, cmd;
   int s;
   icq_Packet *p;
 
   p = icq_PacketNew();
-  s = icq_UDPSockRead(link, p);
+  s = icq_UDPSockRead(icqlink, p);
   p->length = s;
   if(s<=0)
   {
-    icq_FmtLog(link, ICQ_LOG_FATAL, "Connection terminated\n");
-    icq_Disconnect(link);
-    if(link->icq_Disconnected)
-      (*link->icq_Disconnected)(link);
+    icq_FmtLog(icqlink, ICQ_LOG_FATAL, "Connection terminated\n");
+    icq_Disconnect(icqlink);
+    invoke_callback(icqlink,icq_Disconnected)(icqlink);
   }
   seq = icq_PacketReadUDPInSeq1(p);
   cmd = icq_PacketReadUDPInCmd(p);
-  if(icq_GetServMess(link, seq) && cmd != UDP_SRV_NEW_UIN && cmd != UDP_SRV_GO_AWAY && cmd != UDP_SRV_ACK)
+  if(icq_GetServMess(icqlink, seq) && cmd != UDP_SRV_NEW_UIN && cmd != UDP_SRV_GO_AWAY && cmd != UDP_SRV_ACK)
   {
-    icq_FmtLog(link, ICQ_LOG_WARNING, "Ignored a message cmd %04x, seq %04x\n", cmd, seq);
-    icq_UDPAck(link, seq); /* LAGGGGG!! */
+    icq_FmtLog(icqlink, ICQ_LOG_WARNING, "Ignored a message cmd %04x, seq %04x\n", cmd, seq);
+    icq_UDPAck(icqlink, seq); /* LAGGGGG!! */
     icq_PacketDelete(p);
     return;
   }
   if(cmd != UDP_SRV_ACK)
-    icq_SetServMess(link, seq);
+    icq_SetServMess(icqlink, seq);
 
-  icq_ServerResponse(link, p);
+  icq_ServerResponse(icqlink, p);
 
   icq_PacketDelete(p);
 }
--- a/plugins/icq/util.c	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/util.c	Tue May 29 10:32:53 2001 +0000
@@ -1,98 +1,30 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/*
-$Id: util.c 1442 2001-01-28 01:52:27Z warmenhoven $
-$Log$
-Revision 1.3  2001/01/28 01:52:27  warmenhoven
-icqlib 1.1.5
-
-Revision 1.33  2000/08/13 19:26:50  denis
-icq_Genders[] array have been added.
-
-Revision 1.32  2000/07/22 16:49:32  denis
-Trinidad and Tobago country was added.
-
-Revision 1.31  2000/07/21 16:51:20  denis
-All languages, possible in original icq were added.
-Occupation array fixed.
-
-Revision 1.30  2000/07/20 09:58:59  denis
-Occupation table corrected to comply with original ICQ.
-
-Revision 1.29  2000/07/04 07:25:29  pcadach
-icq_FmtLog() crashed when it receives NULL at link argument.
-
-Revision 1.28  2000/06/30 13:59:43  denis
-Slovak Republic country code fixed.
-
-Revision 1.27  2000/06/25 17:00:32  denis
-icq_MetaOccupation[], icq_MetaPastBackgrounds[],
-icq_MetaAffiliations[] and icq_MetaLanguages[] arrays were added along
-with icq_GetMetaOccupationName(), icq_GetMetaBackgroundName(),
-icq_GetMetaAffiliationName() and icq_GetMetaLanguageName() functions
-to access them.
-
-Revision 1.26  2000/05/21 17:42:51  denis
-Bulgaria country code was added. Thanks to
-"Napalm Death" <napalmbox@hotmail.com>
-
-Revision 1.25  2000/05/03 18:29:15  denis
-Callbacks have been moved to the ICQLINK structure.
 
-Revision 1.24  2000/04/10 16:36:04  denis
-Some more Win32 compatibility from Guillaume Rosanis <grs@mail.com>
-
-Revision 1.23  2000/04/05 14:37:02  denis
-Applied patch from "Guillaume R." <grs@mail.com> for basic Win32
-compatibility.
-
-Revision 1.22  2000/03/31 12:49:15  nofate
-remove static variable
-
-Revision 1.21  1999/11/11 15:10:33  guruz
-- Added Base for Webpager Messages. Please type "make fixme"
-- Removed Segfault when kicq is started the first time
-
-Revision 1.20  1999/10/07 18:01:40  denis
-Cleanups.
-
-Revision 1.19  1999/09/29 17:16:45  denis
-Cleanups.
-
-Revision 1.18  1999/07/18 20:24:27  bills
-removed old byte order and contact list functions
-
-Revision 1.17  1999/07/16 15:46:03  denis
-Cleaned up.
-
-Revision 1.16  1999/07/16 12:04:49  denis
-Status support changed.
-
-Revision 1.15  1999/07/12 15:13:46  cproch
-- added definition of ICQLINK to hold session-specific global variabled
-  applications which have more than one connection are now possible
-- changed nearly every function defintion to support ICQLINK parameter
-
-Revision 1.14  1999/04/17 19:20:35  bills
-removed *_link entries from icq_ContactItem, including cleanup/init code
-
-Revision 1.13  1999/04/14 15:06:51  denis
-Cleanups for "strict" compiling (-ansi -pedantic)
-
-*/
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
 
 #include <stdlib.h>
 #include <ctype.h>
 
-#ifndef _WIN32
-#include <unistd.h>
-#endif
-
-#include "icqtypes.h"
-#include "icq.h"
 #include "icqlib.h"
 #include "stdpackets.h"
-#include "util.h"
-#include "stdarg.h"
 
 /*
  * This list of countries should be sorted according to country code.
@@ -439,13 +371,13 @@
   return 0;
 }
 
-void icq_FmtLog(ICQLINK *link, int level, const char *fmt, ...)
+void icq_FmtLog(icq_Link *icqlink, int level, const char *fmt, ...)
 {
   char buffer[2048];
   va_list ap;
   va_start(ap, fmt);
   
-  if(!link)
+  if(!icqlink)
     return;
 #ifdef _MSVC_
   _vsnprintf(buffer, 1024, fmt, ap);
@@ -454,8 +386,8 @@
 #endif
   va_end(ap);
 
-  if(link->icq_Log && icq_LogLevel>=level)
-    (*link->icq_Log)(link, time(0L), level, buffer);
+  if(icqlink->icq_Log && icq_LogLevel>=level)
+    (*icqlink->icq_Log)(icqlink, time(0L), level, buffer);
 }
 
 /**
@@ -548,3 +480,32 @@
   else
     return "Error";
 }
+
+int icq_SplitFields(icq_List *strList, const char *str)
+{
+  char *tmpBuf, *tmp, *ptr;
+  int count = 0;
+ 
+  tmpBuf = (char*)malloc(strlen(str)+1);
+  strcpy(tmpBuf, str);
+  ptr = tmpBuf;
+ 
+  while(ptr)
+  {
+    char *p;
+    tmp = strchr(ptr, 0xFE);
+    if(tmp != 0L)
+    {
+      *tmp = 0;
+      tmp++;
+    }
+    count++;
+    p = (char *)malloc(strlen(ptr)+1);
+    strcpy(p, ptr);
+    icq_ListEnqueue(strList, p);
+    ptr = tmp;
+  }
+ 
+  free(tmpBuf);
+  return count;
+}
--- a/plugins/icq/util.h	Tue May 29 09:46:05 2001 +0000
+++ b/plugins/icq/util.h	Tue May 29 10:32:53 2001 +0000
@@ -1,4 +1,25 @@
 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+
+/*
+ * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
+ *                          Bill Soudan <soudan@kde.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef _UTIL_H_
 #define _UTIL_H_
 
@@ -15,7 +36,7 @@
 #endif
 
 #include "icqtypes.h"
-#include "icq.h"
+#include "list.h"
 
 #ifndef FALSE
 #define FALSE 0
@@ -33,5 +54,6 @@
 void Word_2_Chars(unsigned char *buf, WORD num);
 
 const char *icq_ConvertStatus2Str(unsigned long status);
+int icq_SplitFields(icq_List *strList, const char *str);
 
 #endif /* _UTIL_H_ */