2086
|
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
2
|
|
3 /*
|
|
4 * $Id: chatsession.c 2096 2001-07-31 01:00:39Z warmenhoven $
|
|
5 *
|
|
6 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
|
|
7 * Bill Soudan <soudan@kde.org>
|
|
8 *
|
|
9 * This program is free software; you can redistribute it and/or modify
|
|
10 * it under the terms of the GNU General Public License as published by
|
|
11 * the Free Software Foundation; either version 2 of the License, or
|
|
12 * (at your option) any later version.
|
|
13 *
|
|
14 * This program is distributed in the hope that it will be useful,
|
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 * GNU General Public License for more details.
|
|
18 *
|
|
19 * You should have received a copy of the GNU General Public License
|
|
20 * along with this program; if not, write to the Free Software
|
|
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 #include <stdlib.h>
|
|
26
|
|
27 #include "icqlib.h"
|
|
28 #include "tcp.h"
|
|
29
|
|
30 #include "chatsession.h"
|
|
31
|
|
32 icq_ChatSession *icq_ChatSessionNew(icq_Link *icqlink)
|
|
33 {
|
|
34 icq_ChatSession *p=(icq_ChatSession *)malloc(sizeof(icq_ChatSession));
|
|
35
|
|
36 if (p)
|
|
37 {
|
|
38 p->status=0;
|
|
39 p->id=0L;
|
|
40 p->icqlink=icqlink;
|
|
41 p->tcplink=NULL;
|
|
42 p->user_data=NULL;
|
|
43 icq_ListInsert(icqlink->d->icq_ChatSessions, 0, p);
|
|
44 }
|
|
45
|
|
46 return p;
|
|
47 }
|
|
48
|
|
49 void icq_ChatSessionDelete(void *p)
|
|
50 {
|
|
51 icq_ChatSession *pchat = (icq_ChatSession *)p;
|
|
52 invoke_callback(pchat->icqlink, icq_ChatNotify)(pchat, CHAT_NOTIFY_CLOSE,
|
|
53 0, NULL);
|
|
54
|
|
55 free(p);
|
|
56 }
|
|
57
|
|
58 int _icq_FindChatSession(void *p, va_list data)
|
|
59 {
|
|
60 DWORD uin=va_arg(data, DWORD);
|
|
61 return (((icq_ChatSession *)p)->remote_uin == uin);
|
|
62 }
|
|
63
|
|
64 icq_ChatSession *icq_FindChatSession(icq_Link *icqlink, DWORD uin)
|
|
65 {
|
|
66 return icq_ListTraverse(icqlink->d->icq_ChatSessions,
|
|
67 _icq_FindChatSession, uin);
|
|
68 }
|
|
69
|
|
70 void icq_ChatSessionSetStatus(icq_ChatSession *p, int status)
|
|
71 {
|
|
72 p->status=status;
|
|
73 if(p->id)
|
|
74 invoke_callback(p->icqlink, icq_ChatNotify)(p, CHAT_NOTIFY_STATUS,
|
|
75 status, NULL);
|
|
76 }
|
|
77
|
|
78 /* public */
|
|
79
|
|
80 /** Closes a chat session.
|
|
81 * @param session desired icq_ChatSession
|
|
82 * @ingroup ChatSession
|
|
83 */
|
|
84 void icq_ChatSessionClose(icq_ChatSession *session)
|
|
85 {
|
|
86 icq_TCPLink *tcplink = session->tcplink;
|
|
87
|
|
88 /* if we're attached to a tcplink, unattach so the link doesn't try
|
|
89 * to close us, and then close the tcplink */
|
|
90 if (tcplink)
|
|
91 {
|
|
92 tcplink->session=NULL;
|
|
93 icq_TCPLinkClose(tcplink);
|
|
94 }
|
|
95
|
|
96 icq_ChatSessionDelete(session);
|
|
97
|
|
98 icq_ListRemove(session->icqlink->d->icq_ChatSessions, session);
|
|
99 }
|
|
100
|
|
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
|
|
105 */
|
|
106 void icq_ChatSessionSendData(icq_ChatSession *session, const char *data)
|
|
107 {
|
|
108 icq_TCPLink *tcplink = session->tcplink;
|
|
109 int data_length = strlen(data);
|
|
110 char *buffer;
|
|
111
|
|
112 if(!tcplink)
|
|
113 return;
|
|
114
|
|
115 buffer = (char *)malloc(data_length);
|
|
116 strcpy(buffer, data);
|
|
117 icq_ChatRusConv_n("kw", buffer, data_length);
|
|
118
|
|
119 send(tcplink->socket, buffer, data_length, 0);
|
|
120
|
|
121 free(buffer);
|
|
122 }
|
|
123
|
|
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
|
|
129 */
|
|
130 void icq_ChatSessionSendData_n(icq_ChatSession *session, const char *data,
|
|
131 int length)
|
|
132 {
|
|
133 icq_TCPLink *tcplink = session->tcplink;
|
|
134 char *buffer;
|
|
135
|
|
136 if(!tcplink)
|
|
137 return;
|
|
138
|
|
139 buffer = (char *)malloc(length);
|
|
140 memcpy(buffer, data, length);
|
|
141 icq_ChatRusConv_n("kw", buffer, length);
|
|
142
|
|
143 send(tcplink->socket, buffer, length, 0);
|
|
144
|
|
145 free(buffer);
|
|
146 }
|
|
147
|