static void irc_dccsend_recv_init(PurpleXfer *xfer) { struct irc_xfer_rx_data *xd = xfer->data; purple_xfer_start(xfer, -1, xd->ip, xfer->remote_port); g_free(xd->ip); xd->ip = NULL; }
/*------------------------------------------------------------------------ * Initialise a new file transfer. * * @param xfer The file transfer object */ static void mxit_xfer_init( PurpleXfer* xfer ) { struct mxitxfer* mx = (struct mxitxfer*) xfer->data; purple_debug_info( MXIT_PLUGIN_ID, "mxit_xfer_init\n" ); if ( purple_xfer_get_type( xfer ) == PURPLE_XFER_SEND ) { /* we are trying to send a file to MXit */ if ( purple_xfer_get_size( xfer ) > CP_MAX_FILESIZE ) { /* the file is too big */ purple_xfer_error( xfer->type, xfer->account, xfer->who, _( "The file you are trying to send is too large!" ) ); purple_xfer_cancel_local( xfer ); return; } /* start the file transfer */ purple_xfer_start( xfer, -1, NULL, 0 ); } else { /* * we have just accepted a file transfer request from MXit. send a confirmation * to the MXit server so that can send us the file */ mxit_send_file_accept( mx->session, mx->fileid, purple_xfer_get_size( xfer ), 0 ); } }
static void tgprpl_xfer_send_init (PurpleXfer *X) { debug ("tgprpl_xfer_send_init(): sending xfer accepted."); struct tgp_xfer_send_data *data; const char *file, *localfile, *who; tgl_peer_t *P; data = X->data; purple_xfer_start (X, -1, NULL, 0); file = purple_xfer_get_filename (X); localfile = purple_xfer_get_local_filename (X); who = purple_xfer_get_remote_user (X); debug ("xfer_on_init (file=%s, local=%s, who=%s)", file, localfile, who); P = tgp_blist_lookup_peer_get (data->conn->TLS, who); g_return_if_fail (P); if (tgl_get_peer_type (P->id) == TGL_PEER_ENCR_CHAT) { purple_xfer_error (PURPLE_XFER_SEND, data->conn->pa, who, _("Sorry, sending documents to encrypted chats not yet supported.")); purple_xfer_cancel_local (X); return; } tgl_do_send_document (data->conn->TLS, P->id, (char*) localfile, NULL, 0, TGL_SEND_MSG_FLAG_DOCUMENT_AUTO, tgprpl_xfer_send_on_finished, data); // see comment in tgprpl_xfer_recv_init() purple_xfer_ref (X); data->timer = purple_timeout_add (100, tgprpl_xfer_upload_progress, X); data->loading = TRUE; }
static void skypeweb_xfer_send_connect_cb(gpointer user_data, PurpleSslConnection *ssl_connection, PurpleInputCondition cond) { SkypeWebFileTransfer *swft = user_data; SkypeWebAccount *sa = swft->sa; PurpleXfer *xfer = swft->xfer; gchar *headers; headers = g_strdup_printf("PUT /v1/objects/%s/content/original HTTP/1.0\r\n" "Connection: close\r\n" "Authorization: skype_token %s\r\n" //slightly different to normal! "Host: " SKYPEWEB_XFER_HOST "\r\n" "Content-Length: %d\r\n" "Content-Type: application/json\r\n" "\r\n\r\n", purple_url_encode(swft->id), sa->skype_token, purple_xfer_get_size(xfer)); purple_ssl_write(ssl_connection, headers, strlen(headers)); swft->conn = ssl_connection; purple_xfer_ref(xfer); purple_xfer_start(xfer, ssl_connection->fd, NULL, 0); //TODO add input watcher that calls this repeatedly purple_xfer_prpl_ready(xfer); //purple_ssl_input_add( g_free(headers); }
static void yahoo_receivefile_send_cb(gpointer data, gint source, PurpleInputCondition condition) { PurpleXfer *xfer; struct yahoo_xfer_data *xd; int remaining, written; xfer = data; xd = xfer->data; remaining = xd->txbuflen - xd->txbuf_written; written = write(xfer->fd, xd->txbuf + xd->txbuf_written, remaining); if (written < 0 && errno == EAGAIN) written = 0; else if (written <= 0) { purple_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); purple_xfer_cancel_remote(xfer); return; } if (written < remaining) { xd->txbuf_written += written; return; } purple_input_remove(xd->tx_handler); xd->tx_handler = 0; g_free(xd->txbuf); xd->txbuf = NULL; xd->txbuflen = 0; purple_xfer_start(xfer, source, NULL, 0); }
/*------------------------------------------------------------------------ * A file has been received from the MXit server. * * @param session The MXit session object * @param fileid A unique ID that identifies this file * @param data The file data * @param datalen The size of the data */ void mxit_xfer_rx_file( struct MXitSession* session, const char* fileid, const char* data, int datalen ) { PurpleXfer* xfer = NULL; struct mxitxfer* mx = NULL; purple_debug_info( MXIT_PLUGIN_ID, "mxit_xfer_rx_file: (size=%i)\n", datalen ); /* find the file-transfer object */ xfer = find_mxit_xfer( session, fileid ); if ( xfer ) { mx = xfer->data; /* this is the transfer we have been looking for */ purple_xfer_ref( xfer ); purple_xfer_start( xfer, -1, NULL, 0 ); fwrite( data, datalen, 1, xfer->dest_fp ); purple_xfer_unref( xfer ); purple_xfer_set_completed( xfer, TRUE ); purple_xfer_end( xfer ); /* inform MXit that file was successfully received */ mxit_send_file_received( session, fileid, RECV_STATUS_SUCCESS ); } else { /* file transfer not found */ mxit_send_file_received( session, fileid, RECV_STATUS_BAD_ID ); } }
/*------------------------------------------------------------------------ * A file has been received from the MXit server. * * @param session The MXit session object * @param fileid A unique ID that identifies this file * @param data The file data * @param datalen The size of the data */ void mxit_xfer_rx_file( struct MXitSession* session, const char* fileid, const char* data, int datalen ) { PurpleXfer* xfer = NULL; purple_debug_info( MXIT_PLUGIN_ID, "mxit_xfer_rx_file: (size=%i)\n", datalen ); /* find the file-transfer object */ xfer = find_mxit_xfer( session, fileid ); if ( xfer ) { /* this is the transfer we have been looking for */ purple_xfer_ref( xfer ); purple_xfer_start( xfer, -1, NULL, 0 ); if ( fwrite( data, datalen, 1, xfer->dest_fp ) > 0 ) { purple_xfer_unref( xfer ); purple_xfer_set_completed( xfer, TRUE ); purple_xfer_end( xfer ); /* inform MXit that file was successfully received */ mxit_send_file_received( session, fileid, RECV_STATUS_SUCCESS ); } else { /* file write error */ purple_xfer_error( purple_xfer_get_type( xfer ), purple_xfer_get_account( xfer ), purple_xfer_get_remote_user( xfer ), _( "Unable to save the file" ) ); purple_xfer_cancel_local( xfer ); } } else { /* file transfer not found */ mxit_send_file_received( session, fileid, RECV_STATUS_BAD_ID ); } }
static void irc_dccsend_send_connected(gpointer data, int source, PurpleInputCondition cond) { PurpleXfer *xfer = (PurpleXfer *) data; struct irc_xfer_send_data *xd = purple_xfer_get_protocol_data(xfer); int conn; conn = accept(xd->fd, NULL, 0); if (conn == -1) { /* Accepting the connection failed. This could just be related * to the nonblocking nature of the listening socket, so we'll * just try again next time */ /* Let's print an error message anyway */ purple_debug_warning("irc", "accept: %s\n", g_strerror(errno)); return; } purple_input_remove(purple_xfer_get_watcher(xfer)); purple_xfer_set_watcher(xfer, 0); close(xd->fd); xd->fd = -1; _purple_network_set_common_socket_flags(conn); xd->inpa = purple_input_add(conn, PURPLE_INPUT_READ, irc_dccsend_send_read, xfer); /* Start the transfer */ purple_xfer_start(xfer, conn, NULL, 0); }
static void send_file_cb(MsnSlpSession *slpsession) { MsnSlpCall *slpcall; MsnSlpMessage *slpmsg; struct stat st; PurpleXfer *xfer; slpcall = slpsession->slpcall; slpmsg = msn_slpmsg_new(slpcall->slplink); slpmsg->slpcall = slpcall; slpmsg->flags = 0x1000030; slpmsg->slpsession = slpsession; #ifdef MSN_DEBUG_SLP slpmsg->info = "SLP FILE"; #endif xfer = (PurpleXfer *)slpcall->xfer; purple_xfer_start(slpcall->xfer, 0, NULL, 0); slpmsg->fp = xfer->dest_fp; if (g_stat(purple_xfer_get_local_filename(xfer), &st) == 0) slpmsg->size = st.st_size; xfer->dest_fp = NULL; /* Disable double fclose() */ msn_slplink_send_slpmsg(slpcall->slplink, slpmsg); }
void ggp_edisc_xfer_send_ticket_changed(PurpleConnection *gc, PurpleXfer *xfer, gboolean is_allowed) { ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer); if (!edisc_xfer) { purple_debug_fatal("gg", "ggp_edisc_event_ticket_changed: " "transfer %p already free'd\n", xfer); return; } if (!is_allowed) { purple_debug_info("gg", "ggp_edisc_event_ticket_changed: " "transfer %p rejected\n", xfer); purple_xfer_cancel_remote(xfer); ggp_edisc_xfer_free(xfer); return; } if (edisc_xfer->allowed) { purple_debug_misc("gg", "ggp_edisc_event_ticket_changed: " "transfer %p already allowed\n", xfer); return; } edisc_xfer->allowed = TRUE; purple_xfer_start(xfer, -1, NULL, 0); }
static void send_file_cb(MsnSlpCall *slpcall) { MsnSlpMessage *slpmsg; PurpleXfer *xfer; xfer = (PurpleXfer *)slpcall->xfer; if (purple_xfer_get_status(xfer) >= PURPLE_XFER_STATUS_STARTED) return; purple_xfer_ref(xfer); purple_xfer_start(xfer, -1, NULL, 0); if (purple_xfer_get_status(xfer) != PURPLE_XFER_STATUS_STARTED) { purple_xfer_unref(xfer); return; } purple_xfer_unref(xfer); slpmsg = msn_slpmsg_new(slpcall->slplink); slpmsg->slpcall = slpcall; slpmsg->flags = 0x1000030; slpmsg->info = "SLP FILE"; slpmsg->size = purple_xfer_get_size(xfer); msn_slplink_send_slpmsg(slpcall->slplink, slpmsg); }
static void tgprpl_xfer_send_init (PurpleXfer *X) { struct tgp_xfer_send_data *data = X->data; purple_xfer_start (X, -1, NULL, 0); const char *file = purple_xfer_get_filename (X); const char *localfile = purple_xfer_get_local_filename (X); const char *who = purple_xfer_get_remote_user (X); debug ("xfer_on_init (file=%s, local=%s, who=%s)", file, localfile, who); tgl_peer_t *P = find_peer_by_name (data->conn->TLS, who); if (P) { if (tgl_get_peer_type (P->id) != TGL_PEER_ENCR_CHAT) { tgl_do_send_document (data->conn->TLS, P->id, (char*) localfile, NULL, 0, TGL_SEND_MSG_FLAG_DOCUMENT_AUTO, tgprpl_xfer_on_finished, data); } else { purple_notify_message (_telegram_protocol, PURPLE_NOTIFY_MSG_ERROR, "Not supported", "Sorry, sending documents to encrypted chats not yet supported.", NULL, NULL, NULL); } } data->timer = purple_timeout_add (100, tgprpl_xfer_upload_progress, X); }
static void skypeweb_init_file_download(PurpleXfer *xfer) { SkypeWebFileTransfer *swft; const gchar *view_location; gint64 content_full_length; PurpleHttpURL *httpurl; gchar *headers; swft = purple_xfer_get_protocol_data(xfer); view_location = json_object_get_string_member(swft->info, "view_location"); content_full_length = json_object_get_int_member(swft->info, "content_full_length"); purple_xfer_start(xfer, -1, NULL, 0); httpurl = purple_http_url_parse(view_location); headers = g_strdup_printf("GET /%s HTTP/1.0\r\n" "Connection: close\r\n" "Cookie: skypetoken_asm=%s\r\n" "Host: %s\r\n" "\r\n\r\n", purple_http_url_get_path(httpurl), swft->sa->skype_token, purple_http_url_get_host(httpurl)); skypeweb_fetch_url_request(swft->sa, view_location, TRUE, NULL, FALSE, headers, FALSE, content_full_length, skypeweb_got_file, swft); g_free(headers); purple_http_url_free(httpurl); }
static void ggp_edisc_xfer_recv_ticket_completed(PurpleXfer *xfer) { ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer); if (edisc_xfer->ready) return; edisc_xfer->ready = TRUE; purple_xfer_start(xfer, -1, NULL, 0); }
static void connect_cb(gpointer data, gint fd, SIPE_UNUSED_PARAMETER const gchar *error_message) { struct sipe_file_transfer *ft = data; if (fd < 0) { purple_xfer_cancel_local(PURPLE_XFER); return; } purple_xfer_start(PURPLE_XFER, fd, NULL, 0); }
static MsnSlpMessage * init_first_msg(MsnSlpLink *slplink, MsnP2PInfo *info) { MsnSlpMessage *slpmsg; guint32 session_id; slpmsg = msn_slpmsg_new(slplink, NULL); slpmsg->id = msn_p2p_info_get_id(info); session_id = msn_p2p_info_get_session_id(info); slpmsg->size = msn_p2p_info_get_total_size(info); msn_p2p_info_init_first(slpmsg->p2p_info, info); if (session_id) { slpmsg->slpcall = msn_slplink_find_slp_call_with_session_id(slplink, session_id); if (slpmsg->slpcall != NULL) { if (msn_p2p_msg_is_data(info)) { PurpleXfer *xfer = slpmsg->slpcall->xfer; if (xfer != NULL) { slpmsg->ft = TRUE; slpmsg->slpcall->xfer_msg = slpmsg; purple_xfer_ref(xfer); purple_xfer_start(xfer, -1, NULL, 0); if (xfer->data == NULL) { purple_xfer_unref(xfer); msn_slpmsg_destroy(slpmsg); g_return_val_if_reached(NULL); } else { purple_xfer_unref(xfer); } } } } } if (!slpmsg->ft && slpmsg->size) { slpmsg->buffer = g_try_malloc(slpmsg->size); if (slpmsg->buffer == NULL) { purple_debug_error("msn", "Failed to allocate buffer for slpmsg\n"); msn_slpmsg_destroy(slpmsg); return NULL; } } return slpmsg; }
void sipe_backend_ft_start(struct sipe_file_transfer *ft, struct sipe_backend_fd *fd, const char* ip, unsigned port) { if (ip && port && !sipe_backend_ft_is_incoming(ft)) { /* Purple accepts ip & port only for incoming file transfers. * If we want to send file with Sender-Connect = TRUE negotiated, * we have to open the connection ourselves and pass the file * descriptor to purple_xfer_start. */ purple_proxy_connect(NULL, PURPLE_XFER->account, ip, port, connect_cb, ft); return; } purple_xfer_start(PURPLE_XFER, fd ? fd->fd : -1, ip, port); }
static void tgprpl_xfer_send_init (PurpleXfer *X) { struct tgp_xfer_send_data *data = X->data; purple_xfer_start (X, -1, NULL, 0); const char *file = purple_xfer_get_filename (X); const char *localfile = purple_xfer_get_local_filename (X); const char *who = purple_xfer_get_remote_user (X); debug ("xfer_on_init (file=%s, local=%s, who=%s)", file, localfile, who); tgl_peer_t *P = find_peer_by_name (data->conn->TLS, who); if (P) { tgl_do_send_document (data->conn->TLS, P->id, (char*) localfile, NULL, 0, TGL_SEND_MSG_FLAG_DOCUMENT_AUTO, tgprpl_xfer_on_finished, data); } data->timer = purple_timeout_add (100, tgprpl_xfer_upload_progress, X); }
static void tgprpl_xfer_recv_init (PurpleXfer *X) { debug ("tgprpl_xfer_recv_init"); struct tgp_xfer_send_data *data = X->data; purple_xfer_start (X, -1, NULL, 0); const char *who = purple_xfer_get_remote_user (X); tgl_peer_t *P = find_peer_by_name (data->conn->TLS, who); if (P) { if (data->document) { tgl_do_load_document (data->conn->TLS, data->document, tgprpl_xfer_recv_on_finished, data); } else if (data->encr_document) { tgl_do_load_encr_document (data->conn->TLS, data->encr_document, tgprpl_xfer_recv_on_finished, data); } } else { warning ("User not found, not downloading..."); } data->timer = purple_timeout_add (100, tgprpl_xfer_upload_progress, X); }
static void tgprpl_xfer_recv_init (PurpleXfer *X) { debug ("tgprpl_xfer_recv_init(): receiving xfer accepted."); struct tgp_xfer_send_data *data = X->data; struct tgl_state *TLS = data->conn->TLS; struct tgl_message *M = data->msg; struct tgl_document *D = M->media.document; tgl_peer_t *P = NULL; purple_xfer_start (X, -1, NULL, 0); const char *who = purple_xfer_get_remote_user (X); P = tgp_blist_lookup_peer_get (TLS, who); g_return_if_fail(P); switch (M->media.type) { case tgl_message_media_document: tgl_do_load_document (TLS, D, tgprpl_xfer_recv_on_finished, data); break; case tgl_message_media_document_encr: tgl_do_load_encr_document (TLS, M->media.encr_document, tgprpl_xfer_recv_on_finished, data); break; case tgl_message_media_audio: tgl_do_load_audio (TLS, D, tgprpl_xfer_recv_on_finished, data); break; case tgl_message_media_video: tgl_do_load_video (TLS, D, tgprpl_xfer_recv_on_finished, data); break; default: failure ("Unknown message media type: %d, XFER not possible.", M->media.type); return; } // Prevent the xfer data from getting freed after cancelling to allow the file transfer to complete // without crashing. This is necessary cause loading the file in libtgl cannot be aborted once started. purple_xfer_ref (X); data->timer = purple_timeout_add (100, tgprpl_xfer_upload_progress, X); data->loading = TRUE; }
static void bonjour_bytestreams_connect_cb(gpointer data, gint source, const gchar *error_message) { PurpleXfer *xfer = data; XepXfer *xf = xfer->data; XepIq *iq; xmlnode *q_node, *tmp_node; BonjourData *bd; gboolean ret = FALSE; xf->proxy_connection = NULL; if(source < 0) { purple_debug_error("bonjour", "Error connecting via SOCKS5 to %s - %s\n", xf->proxy_host, error_message ? error_message : "(null)"); tmp_node = xmlnode_get_next_twin(xf->streamhost); ret = __xep_bytestreams_parse(xf->pb, xfer, tmp_node, xf->iq_id); if (!ret) { xep_ft_si_reject(xf->data, xf->iq_id, purple_xfer_get_remote_user(xfer), "404", "cancel"); /* Cancel the connection */ purple_xfer_cancel_local(xfer); } return; } purple_debug_info("bonjour", "Connected successfully via SOCKS5, starting transfer.\n"); bd = xf->data; /* Here, start the file transfer.*/ /* Notify Initiator of Connection */ iq = xep_iq_new(bd, XEP_IQ_RESULT, xfer->who, bonjour_get_jid(bd->jabber_data->account), xf->iq_id); q_node = xmlnode_new_child(iq->node, "query"); xmlnode_set_namespace(q_node, "http://jabber.org/protocol/bytestreams"); tmp_node = xmlnode_new_child(q_node, "streamhost-used"); xmlnode_set_attrib(tmp_node, "jid", xf->jid); xep_iq_send_and_free(iq); purple_xfer_start(xfer, source, NULL, -1); }
static void send_file_cb(struct pn_peer_call *call) { struct pn_peer_msg *peer_msg; struct stat st; PurpleXfer *xfer; peer_msg = pn_peer_msg_new(); peer_msg->call = call; peer_msg->flags = 0x1000030; #ifdef PECAN_DEBUG_SLP peer_msg->info = "SLP FILE"; #endif xfer = (PurpleXfer *) call->xfer; purple_xfer_start(call->xfer, 0, NULL, 0); peer_msg->fp = xfer->dest_fp; if (g_stat(purple_xfer_get_local_filename(xfer), &st) == 0) peer_msg->size = st.st_size; xfer->dest_fp = NULL; /* Disable double fclose() */ pn_peer_link_send_msg(call->link, peer_msg); }
static void send_file_cb(MsnSlpCall *slpcall) { MsnSlpMessage *slpmsg; PurpleXfer *xfer; xfer = (PurpleXfer *)slpcall->xfer; if (purple_xfer_get_status(xfer) >= PURPLE_XFER_STATUS_STARTED) return; g_object_ref(xfer); purple_xfer_start(xfer, -1, NULL, 0); if (purple_xfer_get_status(xfer) != PURPLE_XFER_STATUS_STARTED) { g_object_unref(xfer); return; } g_object_unref(xfer); slpmsg = msn_slpmsg_file_new(slpcall, purple_xfer_get_size(xfer)); msn_slplink_send_slpmsg(slpcall->slplink, slpmsg); }
static void tgprpl_xfer_recv_init (PurpleXfer *X) { debug ("tgprpl_xfer_recv_init"); struct tgp_xfer_send_data *data = X->data; struct tgl_state *TLS = data->conn->TLS; struct tgl_message *M = data->msg; struct tgl_document *D = M->media.document; tgl_peer_t *P = NULL; purple_xfer_start (X, -1, NULL, 0); const char *who = purple_xfer_get_remote_user (X); P = find_peer_by_name (TLS, who); if (P) { switch (M->media.type) { case tgl_message_media_document: tgl_do_load_document (TLS, D, tgprpl_xfer_recv_on_finished, data); break; case tgl_message_media_document_encr: tgl_do_load_encr_document (TLS, M->media.encr_document, tgprpl_xfer_recv_on_finished, data); break; case tgl_message_media_audio: tgl_do_load_audio (TLS, D, tgprpl_xfer_recv_on_finished, data); break; case tgl_message_media_video: tgl_do_load_video (TLS, D, tgprpl_xfer_recv_on_finished, data); break; default: failure ("Unknown message media type: %d, XFER not possible.", M->media.type); break; } } else { warning ("User not found, not downloading..."); } data->timer = purple_timeout_add (100, tgprpl_xfer_upload_progress, X); }
static void yahoo_process_filetrans_info_15_got(PurpleHttpConnection *hc, PurpleHttpResponse *response, gpointer _xfer) { PurpleXfer *xfer = _xfer; struct yahoo_xfer_data *xd; YahooData *yd; xd = purple_xfer_get_protocol_data(xfer); yd = purple_connection_get_protocol_data(xd->gc); xd->hc = NULL; if (!purple_http_response_is_successful(response)) { purple_notify_error(yd->gc, NULL, _("File Transfer Failed"), _("Unable to get file header."), purple_request_cpar_from_connection(yd->gc)); purple_xfer_cancel_remote(xfer); return; } purple_xfer_start(xfer, -1, NULL, 0); }
void msn_slplink_process_msg(MsnSlpLink *slplink, MsnSlpHeader *header, const char *data, gsize len) { MsnSlpMessage *slpmsg; guint64 offset; PurpleXfer *xfer = NULL; if (header->total_size < header->length) { purple_debug_error("msn", "This can't be good\n"); g_return_if_reached(); } offset = header->offset; if (offset == 0) { slpmsg = msn_slpmsg_new(slplink); slpmsg->id = header->id; slpmsg->session_id = header->session_id; slpmsg->size = header->total_size; slpmsg->flags = header->flags; if (slpmsg->session_id) { if (slpmsg->slpcall == NULL) slpmsg->slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); if (slpmsg->slpcall != NULL) { if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000020 || slpmsg->flags == 0x1000030) { xfer = slpmsg->slpcall->xfer; if (xfer != NULL) { slpmsg->ft = TRUE; slpmsg->slpcall->xfer_msg = slpmsg; purple_xfer_ref(xfer); purple_xfer_start(xfer, -1, NULL, 0); if (xfer->data == NULL) { purple_xfer_unref(xfer); msn_slpmsg_destroy(slpmsg); g_return_if_reached(); } else { purple_xfer_unref(xfer); } } } } } if (!slpmsg->ft && slpmsg->size) { slpmsg->buffer = g_try_malloc(slpmsg->size); if (slpmsg->buffer == NULL) { purple_debug_error("msn", "Failed to allocate buffer for slpmsg\n"); msn_slpmsg_destroy(slpmsg); return; } } } else { slpmsg = msn_slplink_message_find(slplink, header->session_id, header->id); if (slpmsg == NULL) { /* Probably the transfer was canceled */ purple_debug_error("msn", "Couldn't find slpmsg\n"); return; } } if (slpmsg->ft) { xfer = slpmsg->slpcall->xfer; slpmsg->slpcall->u.incoming_data = g_byte_array_append(slpmsg->slpcall->u.incoming_data, (const guchar *)data, len); purple_xfer_prpl_ready(xfer); } else if (slpmsg->size && slpmsg->buffer) { if (G_MAXSIZE - len < offset || (offset + len) > slpmsg->size || slpmsg->offset != offset) { purple_debug_error("msn", "Oversized slpmsg - msgsize=%lld offset=%" G_GUINT64_FORMAT " len=%" G_GSIZE_FORMAT "\n", slpmsg->size, offset, len); g_return_if_reached(); } else { memcpy(slpmsg->buffer + offset, data, len); slpmsg->offset += len; } } if ((slpmsg->flags == 0x20 || slpmsg->flags == 0x1000020 || slpmsg->flags == 0x1000030) && (slpmsg->slpcall != NULL)) { slpmsg->slpcall->progress = TRUE; if (slpmsg->slpcall->progress_cb != NULL) { slpmsg->slpcall->progress_cb(slpmsg->slpcall, slpmsg->size, len, offset); } } #if 0 if (slpmsg->buffer == NULL) return; #endif if (header->offset + header->length >= header->total_size) { /* All the pieces of the slpmsg have been received */ MsnSlpCall *slpcall; slpcall = msn_slp_process_msg(slplink, slpmsg); if (slpcall == NULL) { msn_slpmsg_destroy(slpmsg); return; } purple_debug_info("msn", "msn_slplink_process_msg: slpmsg complete\n"); if (/* !slpcall->wasted && */ slpmsg->flags == 0x100) { #if 0 MsnDirectConn *directconn; directconn = slplink->directconn; if (!directconn->acked) msn_directconn_send_handshake(directconn); #endif } else if (slpmsg->flags == 0x00 || slpmsg->flags == 0x1000000 || slpmsg->flags == 0x20 || slpmsg->flags == 0x1000020 || slpmsg->flags == 0x1000030) { /* Release all the messages and send the ACK */ if (slpcall->wait_for_socket) { /* * Save ack for later because we have to send * a 200 OK message to the previous direct connect * invitation before ACK but the listening socket isn't * created yet. */ purple_debug_info("msn", "msn_slplink_process_msg: save ACK\n"); slpcall->slplink->dc->prev_ack = msn_slplink_create_ack(slplink, header); } else if (!slpcall->wasted) { purple_debug_info("msn", "msn_slplink_process_msg: send ACK\n"); msn_slplink_send_ack(slplink, header); msn_slplink_send_queued_slpmsgs(slplink); } } msn_slpmsg_destroy(slpmsg); if (!slpcall->wait_for_socket && slpcall->wasted) msn_slpcall_destroy(slpcall); } }
static void bonjour_sock5_request_cb(gpointer data, gint source, PurpleInputCondition cond) { PurpleXfer *xfer = data; XepXfer *xf = xfer->data; int acceptfd; int len = 0; if(xf == NULL) return; purple_debug_info("bonjour", "bonjour_sock5_request_cb - req_state = 0x%x\n", xf->sock5_req_state); switch(xf->sock5_req_state){ case 0x00: acceptfd = accept(source, NULL, 0); if(acceptfd == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) { } else if(acceptfd == -1) { /* This should cancel the ft */ purple_debug_error("bonjour", "Error accepting incoming SOCKS5 connection. (%d)\n", errno); purple_input_remove(xfer->watcher); xfer->watcher = 0; close(source); purple_xfer_cancel_remote(xfer); return; } else { purple_debug_info("bonjour", "Accepted SOCKS5 ft connection - fd=%d\n", acceptfd); _purple_network_set_common_socket_flags(acceptfd); purple_input_remove(xfer->watcher); close(source); xfer->watcher = purple_input_add(acceptfd, PURPLE_INPUT_READ, bonjour_sock5_request_cb, xfer); xf->sock5_req_state++; xf->rxlen = 0; } break; case 0x01: xfer->fd = source; len = read(source, xf->rx_buf + xf->rxlen, 3); if(len < 0 && errno == EAGAIN) return; else if(len <= 0){ purple_input_remove(xfer->watcher); xfer->watcher = 0; close(source); purple_xfer_cancel_remote(xfer); return; } else { purple_input_remove(xfer->watcher); xfer->watcher = purple_input_add(source, PURPLE_INPUT_WRITE, bonjour_sock5_request_cb, xfer); xf->sock5_req_state++; xf->rxlen = 0; bonjour_sock5_request_cb(xfer, source, PURPLE_INPUT_WRITE); } break; case 0x02: xf->tx_buf[0] = 0x05; xf->tx_buf[1] = 0x00; len = write(source, xf->tx_buf, 2); if (len < 0 && errno == EAGAIN) return; else if (len < 0) { purple_input_remove(xfer->watcher); xfer->watcher = 0; close(source); purple_xfer_cancel_remote(xfer); return; } else { purple_input_remove(xfer->watcher); xfer->watcher = purple_input_add(source, PURPLE_INPUT_READ, bonjour_sock5_request_cb, xfer); xf->sock5_req_state++; xf->rxlen = 0; } break; case 0x03: len = read(source, xf->rx_buf + xf->rxlen, 20); if(len<=0){ } else { purple_input_remove(xfer->watcher); xfer->watcher = purple_input_add(source, PURPLE_INPUT_WRITE, bonjour_sock5_request_cb, xfer); xf->sock5_req_state++; xf->rxlen = 0; bonjour_sock5_request_cb(xfer, source, PURPLE_INPUT_WRITE); } break; case 0x04: xf->tx_buf[0] = 0x05; xf->tx_buf[1] = 0x00; xf->tx_buf[2] = 0x00; xf->tx_buf[3] = 0x03; xf->tx_buf[4] = strlen(xf->buddy_ip); memcpy(xf->tx_buf + 5, xf->buddy_ip, strlen(xf->buddy_ip)); xf->tx_buf[5+strlen(xf->buddy_ip)] = 0x00; xf->tx_buf[6+strlen(xf->buddy_ip)] = 0x00; len = write(source, xf->tx_buf, 7 + strlen(xf->buddy_ip)); if (len < 0 && errno == EAGAIN) { return; } else if (len < 0) { purple_input_remove(xfer->watcher); xfer->watcher = 0; close(source); purple_xfer_cancel_remote(xfer); return; } else { purple_input_remove(xfer->watcher); xfer->watcher = 0; xf->rxlen = 0; /*close(source);*/ purple_xfer_start(xfer, source, NULL, -1); } break; default: break; } return; }
void msn_slplink_process_msg(MsnSlpLink *slplink, MsnMessage *msg) { MsnSlpMessage *slpmsg; const char *data; gsize offset; gsize len; #ifdef MSN_DEBUG_SLP msn_slpmsg_show(msg); #endif #ifdef MSN_DEBUG_SLP_FILES debug_msg_to_file(msg, FALSE); #endif if (msg->msnslp_header.total_size < msg->msnslp_header.length) { purple_debug_error("msn", "This can't be good\n"); g_return_if_reached(); } slpmsg = NULL; data = msn_message_get_bin_data(msg, &len); /* OVERHEAD! if (msg->msnslp_header.length < msg->msnslp_header.total_size) */ offset = msg->msnslp_header.offset; if (offset == 0) { slpmsg = msn_slpmsg_new(slplink); slpmsg->id = msg->msnslp_header.id; slpmsg->session_id = msg->msnslp_header.session_id; slpmsg->size = msg->msnslp_header.total_size; slpmsg->flags = msg->msnslp_header.flags; if (slpmsg->session_id) { if (slpmsg->slpcall == NULL) slpmsg->slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); if (slpmsg->slpcall != NULL) { if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) { PurpleXfer *xfer; xfer = slpmsg->slpcall->xfer; if (xfer != NULL) { purple_xfer_ref(xfer); purple_xfer_start(xfer, 0, NULL, 0); if (xfer->data == NULL) { purple_xfer_unref(xfer); return; } else { purple_xfer_unref(xfer); slpmsg->fp = xfer->dest_fp; xfer->dest_fp = NULL; /* Disable double fclose() */ } } } } } if (!slpmsg->fp && slpmsg->size) { slpmsg->buffer = g_try_malloc(slpmsg->size); if (slpmsg->buffer == NULL) { purple_debug_error("msn", "Failed to allocate buffer for slpmsg\n"); return; } } } else { slpmsg = msn_slplink_message_find(slplink, msg->msnslp_header.session_id, msg->msnslp_header.id); } if (slpmsg == NULL) { /* Probably the transfer was canceled */ purple_debug_error("msn", "Couldn't find slpmsg\n"); return; } if (slpmsg->fp) { /* fseek(slpmsg->fp, offset, SEEK_SET); */ len = fwrite(data, 1, len, slpmsg->fp); } else if (slpmsg->size) { if (G_MAXSIZE - len < offset || (offset + len) > slpmsg->size) { purple_debug_error("msn", "Oversized slpmsg\n"); g_return_if_reached(); } else memcpy(slpmsg->buffer + offset, data, len); } if ((slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) && (slpmsg->slpcall != NULL)) { slpmsg->slpcall->progress = TRUE; if (slpmsg->slpcall->progress_cb != NULL) { slpmsg->slpcall->progress_cb(slpmsg->slpcall, slpmsg->size, len, offset); } } #if 0 if (slpmsg->buffer == NULL) return; #endif if (msg->msnslp_header.offset + msg->msnslp_header.length >= msg->msnslp_header.total_size) { /* All the pieces of the slpmsg have been received */ MsnSlpCall *slpcall; slpcall = msn_slp_process_msg(slplink, slpmsg); if (slpmsg->flags == 0x100) { MsnDirectConn *directconn; directconn = slplink->directconn; if (!directconn->acked) msn_directconn_send_handshake(directconn); } else if (slpmsg->flags == 0x0 || slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) { /* Release all the messages and send the ACK */ msn_slplink_send_ack(slplink, msg); msn_slplink_unleash(slplink); } msn_slpmsg_destroy(slpmsg); if (slpcall != NULL && slpcall->wasted) msn_slp_call_destroy(slpcall); } }
static void jabber_oob_xfer_init(PurpleXfer *xfer) { JabberOOBXfer *jox = xfer->data; purple_xfer_start(xfer, -1, jox->address, jox->port); }
/* TODO: Check filename etc. No probs till some hacker comes in the way */ void yahoo_process_filetrans_acc_15(PurpleConnection *gc, struct yahoo_packet *pkt) { gchar *xfer_peer_idstring = NULL; gchar *xfer_idstring_for_relay = NULL; PurpleXfer *xfer; YahooData *yd; struct yahoo_xfer_data *xfer_data; GSList *l; long val_66 = 0; gchar *url = NULL; int val_249 = 0; yd = purple_connection_get_protocol_data(gc); for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 251: if (g_utf8_validate(pair->value, -1, NULL)) { xfer_idstring_for_relay = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_acc_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 265: if (g_utf8_validate(pair->value, -1, NULL)) { xfer_peer_idstring = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_acc_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 66: val_66 = atol(pair->value); break; case 249: val_249 = atol(pair->value); break; case 250: if (g_utf8_validate(pair->value, -1, NULL)) { /* we get a p2p url here when sending file, connected as client */ url = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_acc_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; } } xfer = g_hash_table_lookup(yd->xfer_peer_idstring_map, xfer_peer_idstring); if(!xfer) return; if(val_66 == -1 || ( (!(xfer_idstring_for_relay)) && (val_249 != 2) )) { purple_xfer_cancel_remote(xfer); return; } if( (val_249 == 2) && (!(url)) ) { purple_xfer_cancel_remote(xfer); return; } xfer_data = purple_xfer_get_protocol_data(xfer); if (url) xfer_data->host = g_strdup(url); xfer_data->xfer_idstring_for_relay = g_strdup(xfer_idstring_for_relay); xfer_data->url = yahoo_ft_url_gen(xfer, xfer_data->host); purple_xfer_start(xfer, -1, NULL, 0); }