comparison libpurple/protocols/myspace/myspace.c @ 17903:cbda7f26d27d

Add a send_raw function, msim_send_really_raw, into the prpl_info struct, so that third-party plugins can send raw data if they choose.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Sun, 24 Jun 2007 19:23:41 +0000
parents 8caecd2c079c
children 38030f1a2e56
comparison
equal deleted inserted replaced
17902:8caecd2c079c 17903:cbda7f26d27d
189 purple_debug_info("msim", "%s=%s\n", (gchar *)key, (gchar *)value); 189 purple_debug_info("msim", "%s=%s\n", (gchar *)key, (gchar *)value);
190 } 190 }
191 #endif 191 #endif
192 192
193 /** 193 /**
194 * Send raw data to the server. 194 * Send raw data (given as a NUL-terminated string) to the server.
195 * 195 *
196 * @param session 196 * @param session
197 * @param msg The raw data to send. 197 * @param msg The raw data to send, in a NUL-terminated string.
198 * 198 *
199 * @return TRUE if succeeded, FALSE if not. 199 * @return TRUE if succeeded, FALSE if not.
200 * 200 *
201 */ 201 */
202 gboolean msim_send_raw(MsimSession *session, const gchar *msg) 202 gboolean msim_send_raw(MsimSession *session, const gchar *msg)
203 { 203 {
204 int total_bytes_sent, total_bytes;
205
206 purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg); 204 purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg);
207 205
208 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); 206 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
209 g_return_val_if_fail(msg != NULL, FALSE); 207 g_return_val_if_fail(msg != NULL, FALSE);
210 208
211 209 return msim_send_really_raw(session->gc, msg, strlen(msg)) ==
210 strlen(msg);
211 }
212
213 /** Send raw data to the server, possibly with embedded NULs.
214 *
215 * Used in prpl_info struct, so that plugins can have the most possible
216 * control of what is sent over the connection. Inside this prpl,
217 * msim_send_raw() is used, since it sends NUL-terminated strings (easier).
218 *
219 * @param gc PurpleConnection
220 * @param buf Buffer to send
221 * @param total_bytes Size of buffer to send
222 *
223 * @return Bytes successfully sent.
224 */
225 int msim_send_really_raw(PurpleConnection *gc, const char *buf, int total_bytes)
226 {
227 int total_bytes_sent;
228
212 /* Loop until all data is sent, or a failure occurs. */ 229 /* Loop until all data is sent, or a failure occurs. */
213 total_bytes_sent = 0; 230 total_bytes_sent = 0;
214 total_bytes = strlen(msg);
215 do 231 do
216 { 232 {
217 int bytes_sent; 233 int bytes_sent;
218 234
219 bytes_sent = send(session->fd, msg + total_bytes_sent, 235 bytes_sent = send(((MsimSession*)(gc->proto_data))->fd,
220 total_bytes - total_bytes_sent, 0); 236 buf + total_bytes_sent, total_bytes - total_bytes_sent, 0);
221 237
222 if (bytes_sent < 0) 238 if (bytes_sent < 0)
223 { 239 {
224 purple_debug_info("msim", "msim_send_raw(%s): send() failed: %s\n", 240 purple_debug_info("msim", "msim_send_raw(%s): send() failed: %s\n",
225 msg, g_strerror(errno)); 241 buf, g_strerror(errno));
226 return FALSE; 242 return total_bytes_sent;
227 } 243 }
228 total_bytes_sent += bytes_sent; 244 total_bytes_sent += bytes_sent;
229 245
230 } while(total_bytes_sent < total_bytes); 246 } while(total_bytes_sent < total_bytes);
231 return TRUE; 247
232 } 248 return total_bytes_sent;
249 }
250
233 251
234 /** 252 /**
235 * Start logging in to the MSIM servers. 253 * Start logging in to the MSIM servers.
236 * 254 *
237 * @param acct Account information to use to login. 255 * @param acct Account information to use to login.
269 * working port and try that first next time. */ 287 * working port and try that first next time. */
270 purple_connection_error(gc, _("Couldn't create socket")); 288 purple_connection_error(gc, _("Couldn't create socket"));
271 return; 289 return;
272 } 290 }
273 } 291 }
292
274 /** 293 /**
275 * Process a login challenge, sending a response. 294 * Process a login challenge, sending a response.
276 * 295 *
277 * @param session 296 * @param session
278 * @param msg Login challenge message. 297 * @param msg Login challenge message.
1695 */ 1714 */
1696 gboolean msim_offline_message(const PurpleBuddy *buddy) 1715 gboolean msim_offline_message(const PurpleBuddy *buddy)
1697 { 1716 {
1698 return TRUE; 1717 return TRUE;
1699 } 1718 }
1700
1701 1719
1702 /** 1720 /**
1703 * Callback when input available. 1721 * Callback when input available.
1704 * 1722 *
1705 * @param gc_uncasted A PurpleConnection pointer. 1723 * @param gc_uncasted A PurpleConnection pointer.
2215 NULL, /* can_receive_file */ 2233 NULL, /* can_receive_file */
2216 NULL, /* send_file */ 2234 NULL, /* send_file */
2217 NULL, /* new_xfer */ 2235 NULL, /* new_xfer */
2218 msim_offline_message, /* offline_message */ 2236 msim_offline_message, /* offline_message */
2219 NULL, /* whiteboard_prpl_ops */ 2237 NULL, /* whiteboard_prpl_ops */
2220 NULL, /* send_raw */ 2238 msim_send_really_raw, /* send_raw */
2221 NULL, /* roomlist_room_serialize */ 2239 NULL, /* roomlist_room_serialize */
2222 NULL, /* _purple_reserved1 */ 2240 NULL, /* _purple_reserved1 */
2223 NULL, /* _purple_reserved2 */ 2241 NULL, /* _purple_reserved2 */
2224 NULL, /* _purple_reserved3 */ 2242 NULL, /* _purple_reserved3 */
2225 NULL /* _purple_reserved4 */ 2243 NULL /* _purple_reserved4 */