Beispiel #1
0
static void tgprpl_xfer_send_on_finished (struct tgl_state *TLS, void *_data, int success, struct tgl_message *M) {
  debug ("tgprpl_xfer_on_finished()");
  struct tgp_xfer_send_data *data = _data;

  if (success) {
    if (! purple_xfer_is_canceled (data->xfer)) {
      debug ("purple_xfer_set_completed");
      purple_xfer_set_bytes_sent (data->xfer, purple_xfer_get_size (data->xfer));
      purple_xfer_set_completed (data->xfer, TRUE);
      purple_xfer_end (data->xfer);
    }
    write_secret_chat_file (TLS);
  } else {
    tgp_notify_on_error_gw (TLS, NULL, success);
    if (! purple_xfer_is_canceled (data->xfer)) {
      purple_xfer_cancel_remote (data->xfer);
    }
    failure ("send xfer failed");
  }

  data->loading = FALSE;

  data->xfer->data = NULL;
  purple_xfer_unref (data->xfer);
  tgprpl_xfer_free_data (data);
}
Beispiel #2
0
/*------------------------------------------------------------------------
 * Start the file transfer.
 *
 *  @param xfer			The file transfer object
 */
static void mxit_xfer_start( PurpleXfer* xfer )
{
	unsigned char*	buffer;
	int				size;
	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.
		 */
		buffer = g_malloc( xfer->bytes_remaining );
		size = fread( buffer, xfer->bytes_remaining, 1, xfer->dest_fp );

		wrote = purple_xfer_write( xfer, buffer, xfer->bytes_remaining );
		if ( wrote > 0 )
			purple_xfer_set_bytes_sent( xfer, wrote );

		/* free the buffer */
		g_free( buffer );
		buffer = NULL;
	}
}
Beispiel #3
0
/*------------------------------------------------------------------------
 * 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;
	}
}
Beispiel #4
0
static void tgprpl_xfer_recv_on_finished (struct tgl_state *TLS, void *_data, int success, const char *filename) {
  debug ("tgprpl_xfer_recv_on_finished()");
  struct tgp_xfer_send_data *data = _data;
  char *selected = g_strdup (purple_xfer_get_local_filename (data->xfer));

  if (success) {
    debug ("purple_xfer_set_completed");

    // always completed the file transfer to avoid a warning dialogue when closing (Adium)
    purple_xfer_set_bytes_sent (data->xfer, purple_xfer_get_size (data->xfer));
    purple_xfer_set_completed (data->xfer, TRUE);

    if (! purple_xfer_is_canceled (data->xfer)) {
      purple_xfer_end (data->xfer);
    }
  } else {
    tgp_notify_on_error_gw (TLS, NULL, success);
    if (! purple_xfer_is_canceled (data->xfer)) {
      purple_xfer_cancel_remote (data->xfer);
    }
    failure ("recv xfer failed");
  }

  data->loading = FALSE;

  data->xfer->data = NULL;
  purple_xfer_unref (data->xfer);
  tgprpl_xfer_free_data (data);

  debug ("moving transferred file from tgl directory %s to selected target %s", selected, filename);
  g_unlink (selected);
  g_rename (filename, selected);
  g_free (selected);
}
Beispiel #5
0
static gboolean tgprpl_xfer_upload_progress (gpointer _data) {
  PurpleXfer *X = _data;
  struct tgp_xfer_send_data *data = X->data;
  connection_data *conn = data->conn;
  
  PurpleXferType type = purple_xfer_get_type(X);
  switch (type) {
    case PURPLE_XFER_SEND:
      purple_xfer_set_size (X, conn->TLS->cur_uploading_bytes);
      purple_xfer_set_bytes_sent (X, conn->TLS->cur_uploaded_bytes);
      purple_xfer_update_progress (X);
      
      debug ("PURPLE_XFER_SEND progress %d / %d", conn->TLS->cur_uploaded_bytes, conn->TLS->cur_uploading_bytes);
      if (conn->TLS->cur_uploaded_bytes == conn->TLS->cur_uploading_bytes) {
        data->timer = 0;
        return FALSE;
      }
      break;
      
    case PURPLE_XFER_RECEIVE:
      purple_xfer_set_size (X, conn->TLS->cur_downloading_bytes);
      purple_xfer_set_bytes_sent (X, conn->TLS->cur_downloaded_bytes);
      purple_xfer_update_progress (X);
      
      debug ("PURPLE_XFER_RECEIVE progress %d / %d", conn->TLS->cur_downloaded_bytes, conn->TLS->cur_downloading_bytes);
      if (conn->TLS->cur_downloading_bytes == conn->TLS->cur_downloaded_bytes) {
        data->timer = 0;
        return FALSE;
      }
      break;
      
    default:
    case PURPLE_XFER_UNKNOWN:
      failure ("ERROR: tgprpl_xfer_upload_progress xfer type PURPLE_XFER_UNKNOWN.");
      return FALSE;
      break;
  }
  return TRUE;
}
Beispiel #6
0
static void tgprpl_xfer_on_finished (struct tgl_state *TLS, void *_data, int success, struct tgl_message *M) {
  debug ("tgprpl_xfer_on_finished()");
  struct tgp_xfer_send_data *data = _data;
  
  if (success) {
    if (!data->done) {
      debug ("purple_xfer_set_completed");
      purple_xfer_set_bytes_sent (data->xfer, purple_xfer_get_size (data->xfer));
      purple_xfer_set_completed (data->xfer, TRUE);
      purple_xfer_end(data->xfer);
    }
  } else {
    failure ("ERROR xfer failed");
  }
  
  data->xfer->data = NULL;
  tgprpl_xfer_free_data (data);
}
Beispiel #7
0
/* Checks if the WA protocol has data to output and schedules a write handler */
void waprpl_check_ssl_output(PurpleConnection * gc)
{
	whatsapp_connection *wconn = purple_connection_get_protocol_data(gc);
	if (wconn->sslfd >= 0) {

		int r = waAPI_sslhasoutdata(wconn->waAPI);
		if (r > 0) {
			/* Need to watch for output data (if we are not doing it already) */
			if (wconn->sslwh == 0)
				wconn->sslwh = purple_input_add(wconn->sslfd, PURPLE_INPUT_WRITE, waprpl_ssl_output_cb, gc);
		} else if (r < 0) {
			waprpl_ssl_cerr_cb(0, 0, gc);	/* Finished the connection! */
		} else {
			if (wconn->sslwh != 0)
				purple_input_remove(wconn->sslwh);

			wconn->sslwh = 0;
		}

		purple_debug_info(WHATSAPP_ID, "Watch for output is %d %d\n", r, errno);

		/* Update transfer status */
		int rid, bytes_sent;
		if (waAPI_fileuploadprogress(wconn->waAPI, &rid, &bytes_sent)) {
			GList *xfers = purple_xfers_get_all();
			while (xfers) {
				PurpleXfer *xfer = xfers->data;
				wa_file_upload *xinfo = (wa_file_upload *) xfer->data;
				if (xinfo->ref_id == rid) {
					purple_debug_info(WHATSAPP_ID, "Upload progress %d bytes done\n", bytes_sent);
					purple_xfer_set_bytes_sent(xfer, bytes_sent);
					purple_xfer_update_progress(xfer);
					break;
				}
				xfers = g_list_next(xfers);
			}
		}

	}
	
	// Check uploads to mark them as done :)
	waprpl_check_complete_uploads(gc);
}
Beispiel #8
0
static void
skypeweb_got_file(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message)
{
	SkypeWebFileTransfer *swft = user_data;
	PurpleXfer *xfer = swft->xfer;
	SkypeWebAccount *sa = swft->sa;

	sa->url_datas = g_slist_remove(sa->url_datas, url_data);
	
	if (error_message) {
		purple_xfer_error(purple_xfer_get_type(xfer), sa->account, swft->from, error_message);
		purple_xfer_cancel_local(xfer);
	} else {
		purple_xfer_write_file(xfer, (guchar *)url_text, len);
		purple_xfer_set_bytes_sent(xfer, len);
		purple_xfer_set_completed(xfer, TRUE);
	}
	
	//cleanup
	skypeweb_free_xfer(xfer);
}
Beispiel #9
0
static void tgprpl_xfer_recv_on_finished (struct tgl_state *TLS, void *_data, int success, const char *filename) {
  debug ("tgprpl_xfer_recv_on_finished()");
  struct tgp_xfer_send_data *data = _data;

  if (success) {
    if (!data->done) {
      debug ("purple_xfer_set_completed");
      purple_xfer_set_bytes_sent (data->xfer, purple_xfer_get_size (data->xfer));
      purple_xfer_set_completed (data->xfer, TRUE);
      purple_xfer_end (data->xfer);
    }
    
    g_unlink (purple_xfer_get_local_filename (data->xfer));
    g_rename (filename, purple_xfer_get_local_filename (data->xfer));

  } else {
    failure ("ERROR xfer failed");
  }

  data->xfer->data = NULL;
  tgprpl_xfer_free_data (data);
}
Beispiel #10
0
static void ggp_edisc_xfer_progress_watcher(PurpleHttpConnection *hc,
	gboolean reading_state, int processed, int total, gpointer _xfer)
{
	PurpleXfer *xfer = _xfer;
	gboolean eof;
	int total_real;

	if (purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_RECEIVE) {
		if (!reading_state)
			return;
	} else {
		if (reading_state)
			return;
	}

	eof = (processed >= total);
	total_real = purple_xfer_get_size(xfer);
	if (eof || processed > total_real)
		processed = total_real; /* just to be sure */

	purple_xfer_set_bytes_sent(xfer, processed);
	purple_xfer_update_progress(xfer);
}
Beispiel #11
0
static gboolean ggp_edisc_xfer_recv_writer(PurpleHttpConnection *http_conn,
	PurpleHttpResponse *response, const gchar *buffer, size_t offset,
	size_t length, gpointer _xfer)
{
	PurpleXfer *xfer = _xfer;
	ggp_edisc_xfer *edisc_xfer;
	gssize stored;

	g_return_val_if_fail(xfer != NULL, FALSE);
	edisc_xfer = purple_xfer_get_protocol_data(xfer);
	g_return_val_if_fail(edisc_xfer != NULL, FALSE);

	stored = purple_xfer_write_file(xfer, (guchar *)buffer, length) ?
			(gssize)length : -1;

	if (stored < 0 || (gsize)stored != length) {
		purple_debug_error("gg", "ggp_edisc_xfer_recv_writer: "
			"saved too less\n");
		return FALSE;
	}

	if (stored > purple_xfer_get_bytes_remaining(xfer)) {
		purple_debug_error("gg", "ggp_edisc_xfer_recv_writer: "
			"saved too much (%" G_GSSIZE_FORMAT " > %" G_GOFFSET_FORMAT ")\n",
			stored, purple_xfer_get_bytes_remaining(xfer));
		return FALSE;
	}

	/* May look redundant with ggp_edisc_xfer_progress_watcher,
	 * but it isn't!
	 */
	purple_xfer_set_bytes_sent(xfer,
		purple_xfer_get_bytes_sent(xfer) + stored);

	return TRUE;
}