1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
4 * $Id: chatsession.c 2096 2001-07-31 01:00:39Z warmenhoven $
6 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
7 * Bill Soudan <soudan@kde.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include "chatsession.h"
32 icq_ChatSession
*icq_ChatSessionNew(icq_Link
*icqlink
)
34 icq_ChatSession
*p
=(icq_ChatSession
*)malloc(sizeof(icq_ChatSession
));
43 icq_ListInsert(icqlink
->d
->icq_ChatSessions
, 0, p
);
49 void icq_ChatSessionDelete(void *p
)
51 icq_ChatSession
*pchat
= (icq_ChatSession
*)p
;
52 invoke_callback(pchat
->icqlink
, icq_ChatNotify
)(pchat
, CHAT_NOTIFY_CLOSE
,
58 int _icq_FindChatSession(void *p
, va_list data
)
60 DWORD uin
=va_arg(data
, DWORD
);
61 return (((icq_ChatSession
*)p
)->remote_uin
== uin
);
64 icq_ChatSession
*icq_FindChatSession(icq_Link
*icqlink
, DWORD uin
)
66 return icq_ListTraverse(icqlink
->d
->icq_ChatSessions
,
67 _icq_FindChatSession
, uin
);
70 void icq_ChatSessionSetStatus(icq_ChatSession
*p
, int status
)
74 invoke_callback(p
->icqlink
, icq_ChatNotify
)(p
, CHAT_NOTIFY_STATUS
,
80 /** Closes a chat session.
81 * @param session desired icq_ChatSession
82 * @ingroup ChatSession
84 void icq_ChatSessionClose(icq_ChatSession
*session
)
86 icq_TCPLink
*tcplink
= session
->tcplink
;
88 /* if we're attached to a tcplink, unattach so the link doesn't try
89 * to close us, and then close the tcplink */
92 tcplink
->session
=NULL
;
93 icq_TCPLinkClose(tcplink
);
96 icq_ChatSessionDelete(session
);
98 icq_ListRemove(session
->icqlink
->d
->icq_ChatSessions
, session
);
101 /** Sends chat data to the remote uin.
102 * @param session desired icq_ChatSession
103 * @param data pointer to data buffer, null-terminated
104 * @ingroup ChatSession
106 void icq_ChatSessionSendData(icq_ChatSession
*session
, const char *data
)
108 icq_TCPLink
*tcplink
= session
->tcplink
;
109 int data_length
= strlen(data
);
115 buffer
= (char *)malloc(data_length
);
116 strcpy(buffer
, data
);
117 icq_ChatRusConv_n("kw", buffer
, data_length
);
119 send(tcplink
->socket
, buffer
, data_length
, 0);
124 /** Sends chat data to the remote uin.
125 * @param session desired icq_ChatSession
126 * @param data pointer to data buffer
127 * @param length length of data
128 * @ingroup ChatSession
130 void icq_ChatSessionSendData_n(icq_ChatSession
*session
, const char *data
,
133 icq_TCPLink
*tcplink
= session
->tcplink
;
139 buffer
= (char *)malloc(length
);
140 memcpy(buffer
, data
, length
);
141 icq_ChatRusConv_n("kw", buffer
, length
);
143 send(tcplink
->socket
, buffer
, length
, 0);