19739
|
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
|
19744
|
30 /*Local Function Prototype*/
|
|
31 static void msn_oim_post_single_get_msg(MsnOim *oim,const char *msgid);
|
|
32
|
19739
|
33 /*new a OIM object*/
|
|
34 MsnOim *
|
|
35 msn_oim_new(MsnSession *session)
|
|
36 {
|
|
37 MsnOim *oim;
|
|
38
|
|
39 oim = g_new0(MsnOim, 1);
|
|
40 oim->session = session;
|
|
41 oim->retrieveconn = msn_soap_new(session,oim,1);
|
19744
|
42 oim->oim_list = NULL;
|
19739
|
43 oim->sendconn = msn_soap_new(session,oim,1);
|
|
44
|
|
45 return oim;
|
|
46 }
|
|
47
|
|
48 /*destroy the oim object*/
|
|
49 void
|
|
50 msn_oim_destroy(MsnOim *oim)
|
|
51 {
|
|
52 msn_soap_destroy(oim->retrieveconn);
|
|
53 msn_soap_destroy(oim->sendconn);
|
|
54 g_free(oim);
|
|
55 }
|
|
56
|
19743
|
57 /****************************************
|
|
58 * OIM send SOAP request
|
|
59 * **************************************/
|
19739
|
60 /*oim SOAP server login error*/
|
|
61 static void
|
19743
|
62 msn_oim_send_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data)
|
19739
|
63 {
|
|
64 MsnSoapConn *soapconn = data;
|
|
65 MsnSession *session;
|
|
66
|
|
67 session = soapconn->session;
|
|
68 g_return_if_fail(session != NULL);
|
|
69
|
|
70 msn_session_set_error(session, MSN_ERROR_SERV_DOWN, _("Unable to connect to OIM server"));
|
|
71 }
|
|
72
|
|
73 /*msn oim SOAP server connect process*/
|
|
74 static void
|
19743
|
75 msn_oim_send_connect_cb(gpointer data, GaimSslConnection *gsc,
|
19739
|
76 GaimInputCondition cond)
|
|
77 {
|
|
78 MsnSoapConn *soapconn = data;
|
|
79 MsnSession * session;
|
|
80 MsnOim *oim;
|
|
81
|
|
82 oim = soapconn->parent;
|
|
83 g_return_if_fail(oim != NULL);
|
|
84
|
|
85 session = oim->session;
|
|
86 g_return_if_fail(session != NULL);
|
|
87 }
|
|
88
|
19744
|
89 static void
|
|
90 msn_oim_send_read_cb(gpointer data, GaimSslConnection *gsc,
|
|
91 GaimInputCondition cond)
|
|
92 {
|
|
93 MsnSoapConn * soapconn = data;
|
|
94 MsnOim * msnoim;
|
|
95
|
|
96 gaim_debug_info("MaYuan","read buffer:{%s}\n",soapconn->body);
|
|
97 }
|
|
98
|
|
99 static void
|
|
100 msn_oim_send_written_cb(gpointer data, gint source, GaimInputCondition cond)
|
|
101 {
|
|
102 MsnSoapConn * soapconn = data;
|
|
103
|
|
104 soapconn->read_cb = msn_oim_send_read_cb;
|
|
105 msn_soap_read_cb(data,source,cond);
|
|
106 }
|
|
107
|
|
108 /*pose single message to oim server*/
|
|
109 void msn_oim_send_single_msg(MsnOim *oim,char * msg)
|
|
110 {
|
|
111 const char *oimsoapbody,*t,*p;
|
|
112
|
|
113 gaim_debug_info("MaYuan","send single OIM Message\n");
|
|
114 oim->sendconn->login_path = g_strdup(MSN_OIM_SEND_URL);
|
|
115 oim->sendconn->soap_action = g_strdup(MSN_OIM_SEND_SOAP_ACTION);
|
|
116 t = oim->session->passport_info.t;
|
|
117 p = oim->session->passport_info.p;
|
|
118 #if 0
|
|
119 oimsoapbody = g_strdup_printf(MSN_OIM_SEND_TEMPLATE,
|
|
120 membername,
|
|
121 friendname,
|
|
122 tomember,
|
|
123 mspauth,
|
|
124 prod_id,
|
|
125 lock_key,
|
|
126 msg_num,
|
|
127 msg
|
|
128 );
|
|
129 #endif
|
|
130 msn_soap_post(oim->retrieveconn, oimsoapbody, msn_oim_send_written_cb);
|
|
131
|
|
132 }
|
|
133
|
19742
|
134 void msn_oim_send_msg(MsnOim *oim,char *msg)
|
19739
|
135 {
|
|
136 if(msn_soap_connected(oim->sendconn) == -1){
|
|
137 }
|
|
138
|
|
139 }
|
|
140
|
19743
|
141 /****************************************
|
|
142 * OIM get SOAP request
|
|
143 * **************************************/
|
|
144 /*oim SOAP server login error*/
|
|
145 static void
|
|
146 msn_oim_get_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data)
|
|
147 {
|
|
148 MsnSoapConn *soapconn = data;
|
|
149 MsnSession *session;
|
|
150
|
|
151 session = soapconn->session;
|
|
152 g_return_if_fail(session != NULL);
|
|
153
|
|
154 msn_session_set_error(session, MSN_ERROR_SERV_DOWN, _("Unable to connect to OIM server"));
|
|
155 }
|
|
156
|
|
157 /*msn oim SOAP server connect process*/
|
|
158 static void
|
|
159 msn_oim_get_connect_cb(gpointer data, GaimSslConnection *gsc,
|
|
160 GaimInputCondition cond)
|
|
161 {
|
|
162 MsnSoapConn *soapconn = data;
|
|
163 MsnSession * session;
|
|
164 MsnOim *oim;
|
|
165
|
|
166 oim = soapconn->parent;
|
|
167 g_return_if_fail(oim != NULL);
|
|
168
|
|
169 session = oim->session;
|
|
170 g_return_if_fail(session != NULL);
|
19744
|
171
|
|
172 gaim_debug_info("MaYuan","oim get SOAP Server connected!\n");
|
|
173 /*call to get the message*/
|
|
174 msn_oim_get_msg(oim);
|
19743
|
175 }
|
|
176
|
19742
|
177 static void
|
|
178 msn_oim_get_read_cb(gpointer data, GaimSslConnection *gsc,
|
|
179 GaimInputCondition cond)
|
|
180 {
|
|
181 MsnSoapConn * soapconn = data;
|
|
182 MsnOim * msnoim;
|
|
183
|
19745
|
184 gaim_debug_info("MaYuan","OIM get read buffer:{%s}\n",soapconn->body);
|
19742
|
185 }
|
|
186
|
|
187 static void
|
|
188 msn_oim_get_written_cb(gpointer data, gint source, GaimInputCondition cond)
|
|
189 {
|
|
190 MsnSoapConn * soapconn = data;
|
|
191
|
|
192 soapconn->read_cb = msn_oim_get_read_cb;
|
|
193 msn_soap_read_cb(data,source,cond);
|
|
194 }
|
|
195
|
19743
|
196 /*get the conversation*/
|
19742
|
197 static GaimConversation *
|
19744
|
198 msn_oim_get_conv(MsnOim *oim,const char *passport)
|
19742
|
199 {
|
|
200 GaimAccount *account;
|
|
201 GaimConversation * conv;
|
|
202
|
|
203 g_return_val_if_fail(oim != NULL, NULL);
|
|
204 account = oim->session->account;
|
|
205
|
|
206 conv = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM,
|
|
207 passport, account);
|
|
208 if(conv == NULL){
|
|
209 conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, passport);
|
|
210 }
|
|
211 return conv;
|
|
212 }
|
|
213
|
19743
|
214 /*put the OIM Message to User Conversation*/
|
19742
|
215 void
|
|
216 msn_oim_report_user(MsnOim *oim,const char *passport,char *msg)
|
|
217 {
|
|
218 GaimConversation * conv;
|
|
219
|
|
220 if ((conv = msn_oim_get_conv(oim,passport)) != NULL){
|
|
221 gaim_conversation_write(conv, NULL, msg, GAIM_MESSAGE_SYSTEM, time(NULL));
|
|
222 }
|
|
223
|
|
224 }
|
|
225
|
19743
|
226 /*parse the oim XML data*/
|
19742
|
227 void
|
|
228 msn_parse_oim_msg(MsnOim *oim,char *xmlmsg)
|
|
229 {
|
|
230 xmlnode *mdNode,*mNode,*INode,*nNode,*ENode,*rtNode;
|
|
231 char *passport,*rTime,*msgid,*nickname;
|
|
232
|
|
233 mdNode = xmlnode_from_str(xmlmsg, strlen(xmlmsg));
|
|
234 for(mNode = xmlnode_get_child(mdNode, "M"); mNode;
|
|
235 mNode = xmlnode_get_next_twin(mNode)){
|
|
236 INode = xmlnode_get_child(mNode,"E");
|
|
237 passport = xmlnode_get_data(INode);
|
|
238 INode = xmlnode_get_child(mNode,"I");
|
|
239 msgid = xmlnode_get_data(INode);
|
|
240 rtNode = xmlnode_get_child(mNode,"RT");
|
|
241 rTime = xmlnode_get_data(rtNode);
|
|
242 nNode = xmlnode_get_child(mNode,"N");
|
|
243 nickname = xmlnode_get_data(nNode);
|
|
244 gaim_debug_info("MaYuan","E:{%s},I:{%s},rTime:{%s}\n",passport,msgid,rTime);
|
19743
|
245 // msn_oim_report_user(oim,passport,"hello");
|
19744
|
246 oim->oim_list = g_list_append(oim->oim_list,msgid);
|
19742
|
247 }
|
19744
|
248 if(msn_soap_connected(oim->retrieveconn) == -1){
|
|
249 gaim_debug_info("MaYuan","retreive OIM server not connected! We need to connect it first\n");
|
|
250 msn_oim_connect(oim);
|
|
251 return;
|
|
252 }
|
|
253 msn_oim_get_msg(oim);
|
19742
|
254 }
|
|
255
|
19744
|
256 static void msn_oim_post_single_get_msg(MsnOim *oim,const char *msgid)
|
19742
|
257 {
|
19744
|
258 const char *oimsoapbody,*t,*p;
|
19742
|
259
|
19744
|
260 gaim_debug_info("MaYuan","Get single OIM Message\n");
|
19742
|
261 oim->retrieveconn->login_path = g_strdup(MSN_OIM_RETRIEVE__URL);
|
19743
|
262 oim->retrieveconn->soap_action = g_strdup(MSN_OIM_GET_SOAP_ACTION);
|
19742
|
263 t = oim->session->passport_info.t;
|
|
264 p = oim->session->passport_info.p;
|
|
265
|
|
266 oimsoapbody = g_strdup_printf(MSN_OIM_GET_TEMPLATE,
|
|
267 t,
|
|
268 p,
|
|
269 msgid
|
|
270 );
|
|
271 msn_soap_post(oim->retrieveconn, oimsoapbody, msn_oim_get_written_cb);
|
19744
|
272
|
|
273 }
|
|
274
|
|
275 /*MSN OIM get SOAP request*/
|
|
276 void msn_oim_get_msg(MsnOim *oim)
|
|
277 {
|
|
278 GList *list;
|
|
279
|
|
280 gaim_debug_info("MaYuan","Get OIM with SOAP \n");
|
|
281 // gaim_debug_info("MaYuan","oim->oim_list:%p,data:%s \n",oim->oim_list,oim->oim_list->data);
|
|
282 for(list = oim->oim_list; list!= NULL;list = g_list_next(list)){
|
|
283 msn_oim_post_single_get_msg(oim,list->data);
|
|
284 oim->oim_list = g_list_remove(oim->oim_list, list->data);
|
|
285 }
|
19742
|
286 }
|
|
287
|
19739
|
288 /*msn oim server connect*/
|
|
289 void
|
|
290 msn_oim_connect(MsnOim *oim)
|
|
291 {
|
|
292 gaim_debug_info("MaYuan","msn_oim_connect...\n");
|
|
293
|
19744
|
294 if(msn_soap_connected(oim->retrieveconn) == -1){
|
|
295 msn_soap_init(oim->retrieveconn,MSN_OIM_RETRIEVE_HOST,1,
|
19743
|
296 msn_oim_get_connect_cb,
|
|
297 msn_oim_get_error_cb);
|
19744
|
298 }
|
19745
|
299 #if 0
|
19744
|
300 if(msn_soap_connected(oim->sendconn) == -1){
|
|
301 msn_soap_init(oim->sendconn,MSN_OIM_SEND_HOST,1,
|
19743
|
302 msn_oim_send_connect_cb,
|
|
303 msn_oim_send_error_cb);
|
19744
|
304 }
|
19745
|
305 #endif
|
19739
|
306 }
|
|
307
|
|
308 /*endof oim.c*/
|