19785
|
1 /**
|
|
2 * @file oim.c
|
|
3 * get and send MSN offline Instant Message via SOAP request
|
|
4 * Author
|
|
5 * MaYuan<mayuan2006@gmail.com>
|
|
6 * gaim
|
|
7 *
|
|
8 * Gaim is the legal property of its developers, whose names are too numerous
|
|
9 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
10 * source distribution.
|
|
11 *
|
|
12 * This program is free software; you can redistribute it and/or modify
|
|
13 * it under the terms of the GNU General Public License as published by
|
|
14 * the Free Software Foundation; either version 2 of the License, or
|
|
15 * (at your option) any later version.
|
|
16 *
|
|
17 * This program is distributed in the hope that it will be useful,
|
|
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 * GNU General Public License for more details.
|
|
21 *
|
|
22 * You should have received a copy of the GNU General Public License
|
|
23 * along with this program; if not, write to the Free Software
|
|
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
25 */
|
|
26 #include "msn.h"
|
|
27 #include "soap.h"
|
|
28 #include "oim.h"
|
|
29
|
|
30 /*new a OIM object*/
|
|
31 MsnOim *
|
|
32 msn_oim_new(MsnSession *session)
|
|
33 {
|
|
34 MsnOim *oim;
|
|
35
|
|
36 oim = g_new0(MsnOim, 1);
|
|
37 oim->session = session;
|
|
38 oim->retrieveconn = msn_soap_new(session,oim,1);
|
|
39 oim->sendconn = msn_soap_new(session,oim,1);
|
|
40
|
|
41 return oim;
|
|
42 }
|
|
43
|
|
44 /*destroy the oim object*/
|
|
45 void
|
|
46 msn_oim_destroy(MsnOim *oim)
|
|
47 {
|
|
48 msn_soap_destroy(oim->retrieveconn);
|
|
49 msn_soap_destroy(oim->sendconn);
|
|
50 g_free(oim);
|
|
51 }
|
|
52
|
19789
|
53 /****************************************
|
|
54 * OIM send SOAP request
|
|
55 * **************************************/
|
19785
|
56 /*oim SOAP server login error*/
|
|
57 static void
|
19789
|
58 msn_oim_send_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data)
|
19785
|
59 {
|
|
60 MsnSoapConn *soapconn = data;
|
|
61 MsnSession *session;
|
|
62
|
|
63 session = soapconn->session;
|
|
64 g_return_if_fail(session != NULL);
|
|
65
|
|
66 msn_session_set_error(session, MSN_ERROR_SERV_DOWN, _("Unable to connect to OIM server"));
|
|
67 }
|
|
68
|
|
69 /*msn oim SOAP server connect process*/
|
|
70 static void
|
19789
|
71 msn_oim_send_connect_cb(gpointer data, GaimSslConnection *gsc,
|
19785
|
72 GaimInputCondition cond)
|
|
73 {
|
|
74 MsnSoapConn *soapconn = data;
|
|
75 MsnSession * session;
|
|
76 MsnOim *oim;
|
|
77
|
|
78 oim = soapconn->parent;
|
|
79 g_return_if_fail(oim != NULL);
|
|
80
|
|
81 session = oim->session;
|
|
82 g_return_if_fail(session != NULL);
|
|
83 }
|
|
84
|
19788
|
85 void msn_oim_send_msg(MsnOim *oim,char *msg)
|
19785
|
86 {
|
|
87 if(msn_soap_connected(oim->sendconn) == -1){
|
|
88 msn_soap_init(oim->sendconn,MSN_OIM_SEND_HOST,1,
|
19789
|
89 msn_oim_send_connect_cb,
|
|
90 msn_oim_send_error_cb);
|
19785
|
91 }
|
|
92
|
|
93 }
|
|
94
|
19789
|
95 /****************************************
|
|
96 * OIM get SOAP request
|
|
97 * **************************************/
|
|
98 /*oim SOAP server login error*/
|
|
99 static void
|
|
100 msn_oim_get_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data)
|
|
101 {
|
|
102 MsnSoapConn *soapconn = data;
|
|
103 MsnSession *session;
|
|
104
|
|
105 session = soapconn->session;
|
|
106 g_return_if_fail(session != NULL);
|
|
107
|
|
108 msn_session_set_error(session, MSN_ERROR_SERV_DOWN, _("Unable to connect to OIM server"));
|
|
109 }
|
|
110
|
|
111 /*msn oim SOAP server connect process*/
|
|
112 static void
|
|
113 msn_oim_get_connect_cb(gpointer data, GaimSslConnection *gsc,
|
|
114 GaimInputCondition cond)
|
|
115 {
|
|
116 MsnSoapConn *soapconn = data;
|
|
117 MsnSession * session;
|
|
118 MsnOim *oim;
|
|
119
|
|
120 oim = soapconn->parent;
|
|
121 g_return_if_fail(oim != NULL);
|
|
122
|
|
123 session = oim->session;
|
|
124 g_return_if_fail(session != NULL);
|
|
125 }
|
|
126
|
19788
|
127 static void
|
|
128 msn_oim_get_read_cb(gpointer data, GaimSslConnection *gsc,
|
|
129 GaimInputCondition cond)
|
|
130 {
|
|
131 MsnSoapConn * soapconn = data;
|
|
132 MsnOim * msnoim;
|
|
133
|
|
134 gaim_debug_info("MaYuan","read buffer:{%s}\n",soapconn->body);
|
|
135 }
|
|
136
|
|
137 static void
|
|
138 msn_oim_get_written_cb(gpointer data, gint source, GaimInputCondition cond)
|
|
139 {
|
|
140 MsnSoapConn * soapconn = data;
|
|
141
|
|
142 soapconn->read_cb = msn_oim_get_read_cb;
|
|
143 msn_soap_read_cb(data,source,cond);
|
|
144 }
|
|
145
|
19789
|
146 /*get the conversation*/
|
19788
|
147 static GaimConversation *
|
|
148 msn_oim_get_conv(MsnOim *oim,char *passport)
|
|
149 {
|
|
150 GaimAccount *account;
|
|
151 GaimConversation * conv;
|
|
152
|
|
153 g_return_val_if_fail(oim != NULL, NULL);
|
|
154 account = oim->session->account;
|
|
155
|
|
156 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM,
|
|
157 passport, account);
|
|
158 if(conv == NULL){
|
|
159 conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, passport);
|
|
160 }
|
|
161 return conv;
|
|
162 }
|
|
163
|
19789
|
164 /*put the OIM Message to User Conversation*/
|
19788
|
165 void
|
|
166 msn_oim_report_user(MsnOim *oim,const char *passport,char *msg)
|
|
167 {
|
|
168 GaimConversation * conv;
|
|
169
|
|
170 if ((conv = msn_oim_get_conv(oim,passport)) != NULL){
|
|
171 gaim_conversation_write(conv, NULL, msg, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
172 }
|
|
173
|
|
174 }
|
|
175
|
19789
|
176 /*parse the oim XML data*/
|
19788
|
177 void
|
|
178 msn_parse_oim_msg(MsnOim *oim,char *xmlmsg)
|
|
179 {
|
|
180 xmlnode *mdNode,*mNode,*INode,*nNode,*ENode,*rtNode;
|
|
181 char *passport,*rTime,*msgid,*nickname;
|
|
182
|
|
183 mdNode = xmlnode_from_str(xmlmsg, strlen(xmlmsg));
|
|
184 for(mNode = xmlnode_get_child(mdNode, "M"); mNode;
|
|
185 mNode = xmlnode_get_next_twin(mNode)){
|
|
186 INode = xmlnode_get_child(mNode,"E");
|
|
187 passport = xmlnode_get_data(INode);
|
|
188 INode = xmlnode_get_child(mNode,"I");
|
|
189 msgid = xmlnode_get_data(INode);
|
|
190 rtNode = xmlnode_get_child(mNode,"RT");
|
|
191 rTime = xmlnode_get_data(rtNode);
|
|
192 nNode = xmlnode_get_child(mNode,"N");
|
|
193 nickname = xmlnode_get_data(nNode);
|
|
194 gaim_debug_info("MaYuan","E:{%s},I:{%s},rTime:{%s}\n",passport,msgid,rTime);
|
19789
|
195 // msn_oim_report_user(oim,passport,"hello");
|
|
196 msn_oim_get_msg(oim,msgid);
|
19788
|
197 }
|
|
198 }
|
|
199
|
19789
|
200 /*MSN OIM get SOAP request*/
|
19788
|
201 void msn_oim_get_msg(MsnOim *oim,char *msgid)
|
|
202 {
|
|
203 const char *oimid ,*oimsoapbody,*t,*p;
|
|
204
|
|
205 if(msn_soap_connected(oim->retrieveconn) == -1){
|
|
206 gaim_debug_info("MaYuan","retreive OIM server not connected!\n");
|
|
207 return;
|
|
208 }
|
|
209
|
19789
|
210 gaim_debug_info("MaYuan","Get OIM with SOAP \n");
|
19788
|
211 oim->retrieveconn->login_path = g_strdup(MSN_OIM_RETRIEVE__URL);
|
19789
|
212 oim->retrieveconn->soap_action = g_strdup(MSN_OIM_GET_SOAP_ACTION);
|
19788
|
213 t = oim->session->passport_info.t;
|
|
214 p = oim->session->passport_info.p;
|
|
215
|
|
216 oimsoapbody = g_strdup_printf(MSN_OIM_GET_TEMPLATE,
|
|
217 t,
|
|
218 p,
|
|
219 msgid
|
|
220 );
|
|
221 msn_soap_post(oim->retrieveconn, oimsoapbody, msn_oim_get_written_cb);
|
|
222 }
|
|
223
|
19785
|
224 /*msn oim server connect*/
|
|
225 void
|
|
226 msn_oim_connect(MsnOim *oim)
|
|
227 {
|
|
228 gaim_debug_info("MaYuan","msn_oim_connect...\n");
|
|
229
|
|
230 msn_soap_init(oim->retrieveconn,MSN_OIM_RETRIEVE_HOST,1,
|
19789
|
231 msn_oim_get_connect_cb,
|
|
232 msn_oim_get_error_cb);
|
|
233 msn_soap_init(oim->sendconn,MSN_OIM_SEND_HOST,1,
|
|
234 msn_oim_send_connect_cb,
|
|
235 msn_oim_send_error_cb);
|
19785
|
236 }
|
|
237
|
|
238 /*endof oim.c*/
|