static void upload_offline_file_init(PurpleXfer* xfer) { qq_account* ac = purple_connection_get_protocol_data(purple_account_get_connection(xfer->account)); LwqqClient* lc = ac->qq; const char* serv_id; if(ac->flag&QQ_USE_QQNUM){ const char* qqnum = purple_xfer_get_remote_user(xfer); LwqqBuddy* b = find_buddy_by_qqnumber(ac->qq, qqnum); if(b == NULL) return; serv_id = b->uin; }else{ serv_id = purple_xfer_get_remote_user(xfer); } LwqqMsgOffFile* file = lwqq_msg_fill_upload_offline_file( xfer->local_filename, lc->myself->uin, serv_id); xfer->start_time = time(NULL); xfer->data = file; int flags = 0; if(ac->flag&QQ_DONT_EXPECT_100_CONTINUE) flags |= DONT_EXPECTED_100_CONTINUE; LwqqAsyncEvent* ev = lwqq_msg_upload_offline_file(lc,file,flags); lwqq_async_add_event_listener(ev,_C_(2p,send_file,ev,xfer)); LwqqHttpRequest* req = lwqq_async_event_get_conn(ev); lwqq_http_on_progress(req, file_trans_on_progress, xfer); lwqq_http_set_option(req, LWQQ_HTTP_CANCELABLE,1L); }
static void bonjour_xfer_init(PurpleXfer *xfer) { PurpleBuddy *buddy; BonjourBuddy *bb; XepXfer *xf; xf = purple_xfer_get_protocol_data(xfer); if(xf == NULL) return; purple_debug_info("bonjour", "Bonjour-xfer-init.\n"); buddy = purple_blist_find_buddy(purple_xfer_get_account(xfer), purple_xfer_get_remote_user(xfer)); /* this buddy is offline. */ if (buddy == NULL || (bb = purple_buddy_get_protocol_data(buddy)) == NULL) return; /* Assume it is the first IP. We could do something like keep track of which one is in use or something. */ if (bb->ips) xf->buddy_ip = g_strdup(bb->ips->data); if (purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_SEND) { /* initiate file transfer, send SI offer. */ purple_debug_info("bonjour", "Bonjour xfer type is PURPLE_XFER_TYPE_SEND.\n"); xep_ft_si_offer(xfer, purple_xfer_get_remote_user(xfer)); } else { /* accept file transfer request, send SI result. */ xep_ft_si_result(xfer, purple_xfer_get_remote_user(xfer)); purple_debug_info("bonjour", "Bonjour xfer type is PURPLE_XFER_TYPE_RECEIVE.\n"); } }
static PurpleXfer* bonjour_si_xfer_find(BonjourData *bd, const char *sid, const char *from) { GSList *xfers; PurpleXfer *xfer; XepXfer *xf; if(!sid || !from || !bd) return NULL; purple_debug_info("bonjour", "Look for sid=%s from=%s xferlists.\n", sid, from); for(xfers = bd->xfer_lists; xfers; xfers = xfers->next) { xfer = xfers->data; if(xfer == NULL) break; xf = purple_xfer_get_protocol_data(xfer); if(xf == NULL) break; if(xf->sid && purple_xfer_get_remote_user(xfer) && !strcmp(xf->sid, sid) && !strcmp(purple_xfer_get_remote_user(xfer), from)) return xfer; } purple_debug_info("bonjour", "Look for xfer list fail\n"); return NULL; }
static void yahoo_xfer_init_15(PurpleXfer *xfer) { struct yahoo_xfer_data *xfer_data; PurpleConnection *gc; PurpleAccount *account; YahooData *yd; struct yahoo_packet *pkt; xfer_data = purple_xfer_get_protocol_data(xfer); gc = xfer_data->gc; yd = purple_connection_get_protocol_data(gc); account = purple_connection_get_account(gc); if (purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_SEND) { gchar *filename; filename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, YAHOO_STATUS_AVAILABLE, yd->session_id); yahoo_packet_hash(pkt, "sssiiiisiii", 1, purple_normalize(account, purple_account_get_username(account)), 5, purple_xfer_get_remote_user(xfer), 265, xfer_data->xfer_peer_idstring, 222, 1, 266, 1, 302, 268, 300, 268, 27, filename, 28, (int)purple_xfer_get_size(xfer), 301, 268, 303, 268); g_free(filename); } else { if(xfer_data->firstoflist == TRUE) { pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, YAHOO_STATUS_AVAILABLE, yd->session_id); yahoo_packet_hash(pkt, "sssi", 1, purple_normalize(account, purple_account_get_username(account)), 5, purple_xfer_get_remote_user(xfer), 265, xfer_data->xfer_peer_idstring, 222, 3); } else { pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_ACC_15, YAHOO_STATUS_AVAILABLE, yd->session_id); yahoo_packet_hash(pkt, "sssi", 1, purple_normalize(account, purple_account_get_username(account)), 5, purple_xfer_get_remote_user(xfer), 265, xfer_data->xfer_peer_idstring, 271, 1); } } yahoo_packet_send_and_free(pkt, yd); }
static void yahoo_xfer_cancel_recv(PurpleXfer *xfer) { struct yahoo_xfer_data *xfer_data; xfer_data = purple_xfer_get_protocol_data(xfer); if(purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL) { PurpleConnection *gc; PurpleAccount *account; YahooData *yd; struct yahoo_packet *pkt; gc = xfer_data->gc; yd = purple_connection_get_protocol_data(gc); account = purple_connection_get_account(gc); if(!xfer_data->xfer_idstring_for_relay) /* hack to see if file trans acc/info packet has been received */ { pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, YAHOO_STATUS_AVAILABLE, yd->session_id); yahoo_packet_hash(pkt, "sssi", 1, purple_normalize(account, purple_account_get_username(account)), 5, purple_xfer_get_remote_user(xfer), 265, xfer_data->xfer_peer_idstring, 222, 4); } else { pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15, YAHOO_STATUS_DISCONNECTED, yd->session_id); yahoo_packet_hash(pkt, "sssi", 1, purple_normalize(account, purple_account_get_username(account)), 5, purple_xfer_get_remote_user(xfer), 265, xfer_data->xfer_peer_idstring, 66, -1); } yahoo_packet_send_and_free(pkt, yd); } if (xfer_data) { purple_http_conn_cancel(xfer_data->hc); yahoo_xfer_data_free(xfer_data); } purple_xfer_set_protocol_data(xfer, NULL); }
/*------------------------------------------------------------------------ * Start the file transfer. * * @param xfer The file transfer object */ static void mxit_xfer_start( PurpleXfer* xfer ) { goffset filesize; unsigned char* buffer; int wrote; purple_debug_info( MXIT_PLUGIN_ID, "mxit_xfer_start\n" ); if ( purple_xfer_get_type( xfer ) == PURPLE_XFER_SEND ) { /* * the user wants to send a file to one of his contacts. we need to create * a buffer and copy the file data into memory and then we can send it to * the contact. we will send the whole file with one go. */ filesize = purple_xfer_get_bytes_remaining( xfer ); buffer = g_malloc( filesize ); if ( fread( buffer, filesize, 1, xfer->dest_fp ) > 0 ) { /* send data */ wrote = purple_xfer_write( xfer, buffer, filesize ); if ( wrote > 0 ) purple_xfer_set_bytes_sent( xfer, wrote ); } else { /* file read error */ purple_xfer_error( purple_xfer_get_type( xfer ), purple_xfer_get_account( xfer ), purple_xfer_get_remote_user( xfer ), _( "Unable to access the local file" ) ); purple_xfer_cancel_local( xfer ); } /* free the buffer */ g_free( buffer ); buffer = NULL; } }
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); }
/*------------------------------------------------------------------------ * 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 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; }
/*------------------------------------------------------------------------ * 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( purple_xfer_get_type( xfer ), purple_xfer_get_account( xfer ), purple_xfer_get_remote_user( xfer ), _( "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 bonjour_bytestreams_connect(PurpleXfer *xfer) { PurpleBuddy *pb; PurpleAccount *account = NULL; PurpleHash *hash; XepXfer *xf; char dstaddr[41]; const gchar *name = NULL; unsigned char hashval[20]; char *p; int i; if(xfer == NULL) return; purple_debug_info("bonjour", "bonjour-bytestreams-connect.\n"); xf = purple_xfer_get_protocol_data(xfer); if(!xf) return; pb = xf->pb; name = purple_buddy_get_name(pb); account = purple_buddy_get_account(pb); p = g_strdup_printf("%s%s%s", xf->sid, name, bonjour_get_jid(account)); hash = purple_sha1_hash_new(); purple_hash_append(hash, (guchar *)p, strlen(p)); purple_hash_digest(hash, hashval, sizeof(hashval)); g_object_unref(G_OBJECT(hash)); g_free(p); memset(dstaddr, 0, 41); p = dstaddr; for(i = 0; i < 20; i++, p += 2) snprintf(p, 3, "%02x", hashval[i]); xf->proxy_info = purple_proxy_info_new(); purple_proxy_info_set_proxy_type(xf->proxy_info, PURPLE_PROXY_SOCKS5); purple_proxy_info_set_host(xf->proxy_info, xf->proxy_host); purple_proxy_info_set_port(xf->proxy_info, xf->proxy_port); xf->proxy_connection = purple_proxy_connect_socks5_account( purple_account_get_connection(account), account, xf->proxy_info, dstaddr, 0, bonjour_bytestreams_connect_cb, xfer); if(xf->proxy_connection == NULL) { 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); } }
static void bonjour_bytestreams_connect_cb(gpointer data, gint source, const gchar *error_message) { PurpleXfer *xfer = data; XepXfer *xf = purple_xfer_get_protocol_data(xfer); XepIq *iq; PurpleXmlNode *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 = purple_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, purple_xfer_get_remote_user(xfer), bonjour_get_jid(bd->jabber_data->account), xf->iq_id); q_node = purple_xmlnode_new_child(iq->node, "query"); purple_xmlnode_set_namespace(q_node, "http://jabber.org/protocol/bytestreams"); tmp_node = purple_xmlnode_new_child(q_node, "streamhost-used"); purple_xmlnode_set_attrib(tmp_node, "jid", xf->jid); xep_iq_send_and_free(iq); purple_xfer_start(xfer, source, NULL, -1); }
static void bonjour_xfer_request_denied(PurpleXfer *xfer) { XepXfer *xf = purple_xfer_get_protocol_data(xfer); purple_debug_info("bonjour", "Bonjour-xfer-request-denied.\n"); if(xf) xep_ft_si_reject(xf->data, xf->sid, purple_xfer_get_remote_user(xfer), "403", "cancel"); bonjour_free_xfer(xfer); }
static void irc_dccsend_network_listen_cb(int sock, gpointer data) { PurpleXfer *xfer = data; struct irc_xfer_send_data *xd; PurpleConnection *gc; struct irc_conn *irc; const char *arg[2]; char *tmp; struct in_addr addr; unsigned short int port; xd = purple_xfer_get_protocol_data(xfer); xd->listen_data = NULL; if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL || purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_REMOTE) { g_object_unref(xfer); return; } xd = purple_xfer_get_protocol_data(xfer); gc = purple_account_get_connection(purple_xfer_get_account(xfer)); irc = purple_connection_get_protocol_data(gc); g_object_unref(xfer); if (sock < 0) { purple_notify_error(gc, NULL, _("File Transfer Failed"), _("Unable to open a listening port."), purple_request_cpar_from_connection(gc)); purple_xfer_cancel_local(xfer); return; } xd->fd = sock; port = purple_network_get_port_from_fd(sock); purple_debug_misc("irc", "port is %hu\n", port); /* Monitor the listening socket */ purple_xfer_set_watcher(xfer, purple_input_add(sock, PURPLE_INPUT_READ, irc_dccsend_send_connected, xfer)); /* Send the intended recipient the DCC request */ arg[0] = purple_xfer_get_remote_user(xfer); inet_aton(purple_network_get_my_ip(irc->fd), &addr); arg[1] = tmp = g_strdup_printf("\001DCC SEND \"%s\" %u %hu %" G_GOFFSET_FORMAT "\001", purple_xfer_get_filename(xfer), ntohl(addr.s_addr), port, purple_xfer_get_size(xfer)); irc_cmd_privmsg(purple_connection_get_protocol_data(gc), "msg", NULL, arg); g_free(tmp); }
static void upload_offline_file_init(PurpleXfer* xfer) { qq_account* ac = purple_connection_get_protocol_data(purple_account_get_connection(xfer->account)); LwqqClient* lc = ac->qq; LwqqMsgOffFile* file = lwqq_msg_fill_upload_offline_file( xfer->local_filename, lc->myself->uin, purple_xfer_get_remote_user(xfer)); xfer->start_time = time(NULL); xfer->data = file; LwqqAsyncEvent* ev = lwqq_msg_upload_offline_file(lc,file); lwqq_async_add_event_listener(ev,_C_(2p,send_file,ev,xfer)); lwqq_async_event_set_progress(ev, file_trans_on_progress, xfer); }
static void ggp_edisc_xfer_error(PurpleXfer *xfer, const gchar *msg) { if (purple_xfer_is_cancelled(xfer)) g_return_if_reached(); purple_xfer_set_status(xfer, PURPLE_XFER_STATUS_CANCEL_REMOTE); purple_xfer_conversation_write(xfer, msg, TRUE); purple_xfer_error( purple_xfer_get_xfer_type(xfer), purple_xfer_get_account(xfer), purple_xfer_get_remote_user(xfer), msg); ggp_edisc_xfer_free(xfer); purple_xfer_end(xfer); }
void xep_bytestreams_parse(PurpleConnection *pc, PurpleXmlNode *packet, PurpleBuddy *pb) { const char *type, *from, *iq_id, *sid; PurpleXmlNode *query, *streamhost; BonjourData *bd; PurpleXfer *xfer; g_return_if_fail(pc != NULL); g_return_if_fail(packet != NULL); g_return_if_fail(pb != NULL); bd = purple_connection_get_protocol_data(pc); if(bd == NULL) return; purple_debug_info("bonjour", "xep-bytestreams-parse.\n"); type = purple_xmlnode_get_attrib(packet, "type"); from = purple_buddy_get_name(pb); query = purple_xmlnode_get_child(packet,"query"); if(!type) return; query = purple_xmlnode_copy(query); if (!query) return; if(strcmp(type, "set")) { purple_debug_info("bonjour", "bytestream offer Message type - Unknown-%s.\n", type); return; } purple_debug_info("bonjour", "bytestream offer Message type - SET.\n"); iq_id = purple_xmlnode_get_attrib(packet, "id"); sid = purple_xmlnode_get_attrib(query, "sid"); xfer = bonjour_si_xfer_find(bd, sid, from); streamhost = purple_xmlnode_get_child(query, "streamhost"); if(xfer && streamhost && __xep_bytestreams_parse(pb, xfer, streamhost, iq_id)) return; /* success */ purple_debug_error("bonjour", "Didn't find an acceptable streamhost.\n"); if (iq_id && xfer != NULL) xep_ft_si_reject(bd, iq_id, purple_xfer_get_remote_user(xfer), "404", "cancel"); }
static void bonjour_bytestreams_listen(int sock, gpointer data) { PurpleXfer *xfer = data; XepXfer *xf; XepIq *iq; PurpleXmlNode *query, *streamhost; gchar *port; GSList *local_ips; BonjourData *bd; purple_debug_info("bonjour", "Bonjour-bytestreams-listen. sock=%d.\n", sock); if (sock < 0 || xfer == NULL) { /*purple_xfer_cancel_local(xfer);*/ return; } purple_xfer_set_watcher(xfer, purple_input_add(sock, PURPLE_INPUT_READ, bonjour_sock5_request_cb, xfer)); xf = purple_xfer_get_protocol_data(xfer); xf->listen_data = NULL; bd = xf->data; iq = xep_iq_new(bd, XEP_IQ_SET, purple_xfer_get_remote_user(xfer), bonjour_get_jid(bd->jabber_data->account), xf->sid); query = purple_xmlnode_new_child(iq->node, "query"); purple_xmlnode_set_namespace(query, "http://jabber.org/protocol/bytestreams"); purple_xmlnode_set_attrib(query, "sid", xf->sid); purple_xmlnode_set_attrib(query, "mode", "tcp"); purple_xfer_set_local_port(xfer, purple_network_get_port_from_fd(sock)); local_ips = bonjour_jabber_get_local_ips(sock); port = g_strdup_printf("%hu", purple_xfer_get_local_port(xfer)); while(local_ips) { streamhost = purple_xmlnode_new_child(query, "streamhost"); purple_xmlnode_set_attrib(streamhost, "jid", xf->sid); purple_xmlnode_set_attrib(streamhost, "host", local_ips->data); purple_xmlnode_set_attrib(streamhost, "port", port); g_free(local_ips->data); local_ips = g_slist_delete_link(local_ips, local_ips); } g_free(port); xep_iq_send_and_free(iq); }
static void upload_file_init(PurpleXfer* xfer) { void** data = xfer->data; qq_account* ac = data[0]; LwqqClient* lc = ac->qq; LwqqMsgOffFile* file = s_malloc0(sizeof(*file)); file->from = s_strdup(lc->myself->uin); file->to = s_strdup(purple_xfer_get_remote_user(xfer)); file->name = s_strdup(purple_xfer_get_local_filename(xfer)); xfer->start_time = time(NULL); data[1] = file; data[2] = xfer; //lwqq_async_add_event_listener( background_upload_file(lc,file,file_trans_on_progress,xfer); //send_file,data); }
static void recv_file_init(PurpleXfer* xfer) { qq_account* ac = purple_connection_get_protocol_data(purple_account_get_connection(xfer->account)); LwqqClient* lc = ac->qq; LwqqMsgFileMessage* file = xfer->data; const char* filename = purple_xfer_get_local_filename(xfer); xfer->start_time = time(NULL); LwqqAsyncEvent* ev = lwqq_msg_accept_file(lc,file,filename); if(ev == NULL){ lwqq_puts("file trans error "); purple_xfer_error(PURPLE_XFER_RECEIVE, ac->account, purple_xfer_get_remote_user(xfer), "接受文件失败"); purple_xfer_cancel_local(xfer); return; } lwqq_async_event_set_progress(ev,file_trans_on_progress,xfer); lwqq_async_add_event_listener(ev,_C_(p,recv_file_complete,xfer)); }
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 ggp_edisc_xfer_send_init_authenticated(PurpleConnection *gc, gboolean success, gpointer _xfer) { ggp_edisc_session_data *sdata = ggp_edisc_get_sdata(gc); PurpleHttpRequest *req; PurpleXfer *xfer = _xfer; ggp_edisc_xfer *edisc_xfer = purple_xfer_get_protocol_data(xfer); gchar *data; if (purple_xfer_is_cancelled(xfer)) return; if (!success) { ggp_edisc_xfer_error(xfer, _("Authentication failed")); return; } g_return_if_fail(sdata != NULL); req = purple_http_request_new("https://drive.mpa.gg.pl/send_ticket"); purple_http_request_set_method(req, "PUT"); ggp_edisc_set_defaults(req); purple_http_request_set_cookie_jar(req, sdata->cookies); purple_http_request_header_set(req, "X-gged-security-token", sdata->security_token); data = g_strdup_printf("{\"send_ticket\":{" "\"recipient\":\"%s\"," "\"file_name\":\"%s\"," "\"file_size\":\"%u\"" "}}", purple_xfer_get_remote_user(xfer), edisc_xfer->filename, (int)purple_xfer_get_size(xfer)); purple_http_request_set_contents(req, data, -1); g_free(data); edisc_xfer->hc = purple_http_request(gc, req, ggp_edisc_xfer_send_init_ticket_created, xfer); purple_http_request_unref(req); }
static void recv_file_init(PurpleXfer* xfer) { qq_account* ac = purple_connection_get_protocol_data(purple_account_get_connection(xfer->account)); LwqqClient* lc = ac->qq; LwqqMsgFileMessage* file = xfer->data; const char* filename = purple_xfer_get_local_filename(xfer); xfer->start_time = time(NULL); LwqqAsyncEvent* ev = lwqq_msg_accept_file(lc,file,filename); if(ev == NULL){ lwqq_puts("file trans error "); purple_xfer_error(PURPLE_XFER_RECEIVE, ac->account, purple_xfer_get_remote_user(xfer), _("Receive file failed")); purple_xfer_cancel_local(xfer); return; } LwqqHttpRequest* req = lwqq_async_event_get_conn(ev); lwqq_http_on_progress(req, file_trans_on_progress, xfer); lwqq_http_set_option(req, LWQQ_HTTP_CANCELABLE,1L); lwqq_async_add_event_listener(ev,_C_(2p,recv_file_complete,xfer,ev)); }
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 gchar * yahoo_ft_url_gen(PurpleXfer *xfer, const gchar *host) { struct yahoo_xfer_data *xfer_data; PurpleAccount *account; g_return_val_if_fail(host != NULL, NULL); xfer_data = purple_xfer_get_protocol_data(xfer); account = purple_connection_get_account(xfer_data->gc); if (!xfer_data->is_relay) { purple_debug_fatal("yahoo", "Non-relay FT aren't tested yet\n"); return NULL; } return g_strdup_printf("http://%s/relay?token=%s&sender=%s&recver=%s", host, purple_url_encode(xfer_data->xfer_idstring_for_relay), purple_normalize(account, purple_account_get_username(account)), purple_xfer_get_remote_user(xfer)); }
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); }
/*------------------------------------------------------------------------ * Send the file data. * * @param buffer The data to sent * @param size The length of the data to send * @param xfer The file transfer object * @return The amount of data actually sent */ static gssize mxit_xfer_write( const guchar* buffer, size_t size, PurpleXfer* xfer ) { struct mxitxfer* mx = (struct mxitxfer*) xfer->data; purple_debug_info( MXIT_PLUGIN_ID, "mxit_xfer_write\n" ); if ( !mx ) { purple_debug_warning( MXIT_PLUGIN_ID, "mxit_xfer_write: invalid internal mxit xfer data\n" ); return -1; } else if ( purple_xfer_get_type( xfer ) != PURPLE_XFER_SEND ) { purple_debug_warning( MXIT_PLUGIN_ID, "mxit_xfer_write: wrong xfer type received\n" ); return -1; } /* create and send the packet to MXit */ mxit_send_file( mx->session, purple_xfer_get_remote_user( xfer ), purple_xfer_get_filename( xfer ), buffer, size ); /* the transfer is complete */ purple_xfer_set_completed( xfer, TRUE ); return size; }
void yahoo_process_filetrans_15(PurpleConnection *gc, struct yahoo_packet *pkt) { char *from = NULL; char *imv = NULL; long val_222 = 0L; PurpleXfer *xfer; YahooData *yd; struct yahoo_xfer_data *xfer_data; char *service = NULL; char *filename = NULL; char *xfer_peer_idstring = NULL; char *utf8_filename; GSList *l; GSList *filename_list = NULL; GSList *size_list = NULL; int nooffiles = 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 4: if (g_utf8_validate(pair->value, -1, NULL)) { from = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 5: /* to */ break; case 265: if (g_utf8_validate(pair->value, -1, NULL)) { xfer_peer_idstring = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 27: filename_list = g_slist_prepend(filename_list, g_strdup(pair->value)); nooffiles++; break; case 28: if (g_utf8_validate(pair->value, -1, NULL)) { size_list = g_slist_prepend(size_list, g_strdup(pair->value)); } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 222: val_222 = atol(pair->value); /* 1=send, 2=cancel, 3=accept, 4=reject */ break; /* check for p2p and imviron .... not sure it comes by this service packet. Since it was bundled with filexfer in old ymsg version, still keeping it. */ case 49: if (g_utf8_validate(pair->value, -1, NULL)) { service = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 63: if (g_utf8_validate(pair->value, -1, NULL)) { imv = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; /* end check */ } } if(!xfer_peer_idstring) return; if(val_222 == 2 || val_222 == 4) { xfer = g_hash_table_lookup(yd->xfer_peer_idstring_map, xfer_peer_idstring); if(!xfer) return; purple_xfer_cancel_remote(xfer); return; } if(val_222 == 3) { PurpleAccount *account; struct yahoo_xfer_data *xd; xfer = g_hash_table_lookup(yd->xfer_peer_idstring_map, xfer_peer_idstring); if(!xfer) return; xd = purple_xfer_get_protocol_data(xfer); /* * In the file trans info packet that we must reply with, we are * supposed to mention the ip address... * purple connect does not give me a way of finding the ip address... * so, purple dnsquery is used... but retries, trying with next ip * address etc. is not implemented..TODO */ /* To send through p2p */ if( g_hash_table_lookup(yd->peers, from) ) { /* send p2p file transfer information */ purple_debug_error("yahoo", "p2p file transfers are not supported yet\n"); /*xd->is_relay = FALSE;*/ } xd->is_relay = TRUE; account = purple_connection_get_account(gc); if (yd->jp) { purple_dnsquery_a(account, YAHOOJP_XFER_RELAY_HOST, YAHOOJP_XFER_RELAY_PORT, yahoo_xfer_dns_connected_15, xfer); } else { purple_dnsquery_a(account, YAHOO_XFER_RELAY_HOST, YAHOO_XFER_RELAY_PORT, yahoo_xfer_dns_connected_15, xfer); } return; } /* processing for p2p and imviron .... not sure it comes by this service packet. Since it was bundled with filexfer in old ymsg version, still keeping it. */ /* * The remote user has changed their IMVironment. We * record it for later use. */ if (from && imv && service && (strcmp("IMVIRONMENT", service) == 0)) { g_hash_table_replace(yd->imvironments, g_strdup(from), g_strdup(imv)); return; } if (pkt->service == YAHOO_SERVICE_P2PFILEXFER) { if (service && (strcmp("FILEXFER", service) != 0)) { purple_debug_misc("yahoo", "unhandled service 0x%02x\n", pkt->service); return; } } /* end processing */ if(!filename_list) return; /* have to change list into order in which client at other end sends */ filename_list = g_slist_reverse(filename_list); size_list = g_slist_reverse(size_list); filename = filename_list->data; if(!from) return; xfer_data = g_new0(struct yahoo_xfer_data, 1); xfer_data->firstoflist = TRUE; xfer_data->gc = gc; xfer_data->xfer_peer_idstring = g_strdup(xfer_peer_idstring); xfer_data->filename_list = filename_list; xfer_data->size_list = size_list; /* Build the file transfer handle. */ xfer = yahoo_ft_new_xfer_struct(gc, PURPLE_XFER_TYPE_RECEIVE, from); /* Set the info about the incoming file. */ utf8_filename = yahoo_string_decode(gc, filename, TRUE); purple_xfer_set_filename(xfer, utf8_filename); g_free(utf8_filename); purple_xfer_set_protocol_data(xfer, xfer_data); g_hash_table_insert(yd->xfer_peer_idstring_map, xfer_data->xfer_peer_idstring, xfer); if(nooffiles > 1) { gchar* message; message = g_strdup_printf(_("%s is trying to send you a group of %d files.\n"), purple_xfer_get_remote_user(xfer), nooffiles); purple_xfer_conversation_write(xfer, message, FALSE); g_free(message); } /* Now perform the request */ purple_xfer_request(xfer); }
void yahoo_process_filetrans_info_15(PurpleConnection *gc, struct yahoo_packet *pkt) { char *url = NULL; long val_249 = 0; long val_66 = 0; PurpleXfer *xfer; YahooData *yd; struct yahoo_xfer_data *xfer_data; char *xfer_peer_idstring = NULL; char *xfer_idstring_for_relay = NULL; GSList *l; struct yahoo_packet *pkt_to_send; 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 4: /* from */ break; case 5: /* to */ break; case 265: if (g_utf8_validate(pair->value, -1, NULL)) { xfer_peer_idstring = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_info_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 27: /* filename */ break; case 66: val_66 = strtol(pair->value, NULL, 10); break; case 249: val_249 = strtol(pair->value, NULL, 10); /* 249 has value 1 or 2 when doing p2p transfer and value 3 when relaying through yahoo server */ break; case 250: if (g_utf8_validate(pair->value, -1, NULL)) { url = pair->value; /* TODO: rename to host? what about non-relay? */ } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_info_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 251: if (g_utf8_validate(pair->value, -1, NULL)) { xfer_idstring_for_relay = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_info_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; } } if(!xfer_peer_idstring) return; xfer = g_hash_table_lookup(yd->xfer_peer_idstring_map, xfer_peer_idstring); if(!xfer) return; if(val_66==-1) { purple_xfer_cancel_remote(xfer); return; } xfer_data = purple_xfer_get_protocol_data(xfer); xfer_data->info_val_249 = val_249; xfer_data->xfer_idstring_for_relay = g_strdup(xfer_idstring_for_relay); if(val_249 == 1 || val_249 == 3) { PurpleHttpRequest *req; PurpleAccount *account; xfer_data->is_relay = (val_249 == 3); if (!xfer_data->is_relay) { purple_debug_error("yahoo", "Non-relay FT aren't tested yet.\n"); purple_notify_error(gc, NULL, _("File Transfer Failed"), _("Unsupported method"), purple_request_cpar_from_connection(gc)); purple_xfer_cancel_remote(xfer); } account = purple_connection_get_account(xfer_data->gc); xfer_data->url = yahoo_ft_url_gen(xfer, url); pkt_to_send = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_ACC_15, YAHOO_STATUS_AVAILABLE, yd->session_id); yahoo_packet_hash(pkt_to_send, "ssssis", 1, purple_normalize(account, purple_account_get_username(account)), 5, purple_xfer_get_remote_user(xfer), 265, xfer_data->xfer_peer_idstring, 27, purple_xfer_get_filename(xfer), 249, xfer_data->info_val_249, 251, xfer_data->xfer_idstring_for_relay); yahoo_packet_send_and_free(pkt_to_send, yd); req = yahoo_ft_new_req(xfer_data); purple_http_request_set_method(req, "HEAD"); xfer_data->hc = purple_http_request(gc, req, yahoo_process_filetrans_info_15_got, xfer); purple_http_request_unref(req); } else if (val_249 == 2) purple_debug_error("yahoo", "p2p file transfers are not supported yet\n"); }