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