Mercurial > pidgin.yaz
annotate plugins/icq/chatsession.c @ 1977:7b3f1eb1ef7d
[gaim-migrate @ 1987]
updated icqlib. fixed import dialog (watch debug window for errors). adam's (not mid's) patch for oscar.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sat, 09 Jun 2001 14:46:51 +0000 |
parents | 8ed70631ed15 |
children |
rev | line source |
---|---|
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
2 |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
3 /* |
1977
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
4 * $Id: chatsession.c 1987 2001-06-09 14:46:51Z warmenhoven $ |
7b3f1eb1ef7d
[gaim-migrate @ 1987]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1912
diff
changeset
|
5 * |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
6 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
7 * Bill Soudan <soudan@kde.org> |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
8 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
9 * This program is free software; you can redistribute it and/or modify |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
10 * it under the terms of the GNU General Public License as published by |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
11 * the Free Software Foundation; either version 2 of the License, or |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
12 * (at your option) any later version. |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
13 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
17 * GNU General Public License for more details. |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
18 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
19 * You should have received a copy of the GNU General Public License |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
20 * along with this program; if not, write to the Free Software |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
22 * |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
23 */ |
1152 | 24 |
25 #include <stdlib.h> | |
26 | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
27 #include "icqlib.h" |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
28 #include "tcp.h" |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
29 |
1152 | 30 #include "chatsession.h" |
31 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
32 icq_ChatSession *icq_ChatSessionNew(icq_Link *icqlink) |
1152 | 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; | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
41 p->tcplink=NULL; |
1531
e06dcc3025a9
[gaim-migrate @ 1541]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
42 p->user_data=NULL; |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
43 icq_ListInsert(icqlink->d->icq_ChatSessions, 0, p); |
1152 | 44 } |
45 | |
46 return p; | |
47 } | |
48 | |
49 void icq_ChatSessionDelete(void *p) | |
50 { | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
51 icq_ChatSession *pchat = (icq_ChatSession *)p; |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
52 invoke_callback(pchat->icqlink, icq_ChatNotify)(pchat, CHAT_NOTIFY_CLOSE, |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
53 0, NULL); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
54 |
1152 | 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 | |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
64 icq_ChatSession *icq_FindChatSession(icq_Link *icqlink, DWORD uin) |
1152 | 65 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
66 return icq_ListTraverse(icqlink->d->icq_ChatSessions, |
1152 | 67 _icq_FindChatSession, uin); |
68 } | |
69 | |
70 void icq_ChatSessionSetStatus(icq_ChatSession *p, int status) | |
71 { | |
72 p->status=status; | |
73 if(p->id) | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
74 invoke_callback(p->icqlink, icq_ChatNotify)(p, CHAT_NOTIFY_STATUS, |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
75 status, NULL); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
76 } |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
77 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
78 /* public */ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
79 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
80 /** Closes a chat session. |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
81 * @param session desired icq_ChatSession |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
82 * @ingroup ChatSession |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
83 */ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
84 void icq_ChatSessionClose(icq_ChatSession *session) |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
85 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
86 icq_TCPLink *tcplink = session->tcplink; |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
87 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
88 /* if we're attached to a tcplink, unattach so the link doesn't try |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
89 * to close us, and then close the tcplink */ |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
90 if (tcplink) |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
91 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
92 tcplink->session=NULL; |
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
93 icq_TCPLinkClose(tcplink); |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
94 } |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
95 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
96 icq_ChatSessionDelete(session); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
97 |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
98 icq_ListRemove(session->icqlink->d->icq_ChatSessions, session); |
1152 | 99 } |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
100 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
101 /** Sends chat data to the remote uin. |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
102 * @param session desired icq_ChatSession |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
103 * @param data pointer to data buffer, null-terminated |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
104 * @ingroup ChatSession |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
105 */ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
106 void icq_ChatSessionSendData(icq_ChatSession *session, const char *data) |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
107 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
108 icq_TCPLink *tcplink = session->tcplink; |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
109 int data_length = strlen(data); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
110 char *buffer; |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
111 |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
112 if(!tcplink) |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
113 return; |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
114 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
115 buffer = (char *)malloc(data_length); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
116 strcpy(buffer, data); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
117 icq_ChatRusConv_n("kw", buffer, data_length); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
118 |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
119 send(tcplink->socket, buffer, data_length, 0); |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
120 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
121 free(buffer); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
122 } |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
123 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
124 /** Sends chat data to the remote uin. |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
125 * @param session desired icq_ChatSession |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
126 * @param data pointer to data buffer |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
127 * @param length length of data |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
128 * @ingroup ChatSession |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
129 */ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
130 void icq_ChatSessionSendData_n(icq_ChatSession *session, const char *data, |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
131 int length) |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
132 { |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
133 icq_TCPLink *tcplink = session->tcplink; |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
134 char *buffer; |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
135 |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
136 if(!tcplink) |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
137 return; |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
138 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
139 buffer = (char *)malloc(length); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
140 memcpy(buffer, data, length); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
141 icq_ChatRusConv_n("kw", buffer, length); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
142 |
1912
8ed70631ed15
[gaim-migrate @ 1922]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1531
diff
changeset
|
143 send(tcplink->socket, buffer, length, 0); |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
144 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
145 free(buffer); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
146 } |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
147 |