diff options
author | irungentoo <irungentoo@gmail.com> | 2013-10-02 20:53:48 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-10-02 20:53:48 -0400 |
commit | c014cebbe5753287c2d0657e0ebe002a520017b0 (patch) | |
tree | 5ac34c6c9e75bf35b90b464231cfb2e8ab7b83e0 /toxcore/tox.h | |
parent | efa3c79699c4d0af21b7fcdc30b6117adfdc1e9d (diff) | |
parent | fbd494a8b44d58911a6329761d48a85f71fc1718 (diff) |
Merge branch 'file-transfers'
File transfers are now working and in public api.
Diffstat (limited to 'toxcore/tox.h')
-rw-r--r-- | toxcore/tox.h | 90 |
1 files changed, 89 insertions, 1 deletions
diff --git a/toxcore/tox.h b/toxcore/tox.h index eabbb1af..b1f18515 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -426,8 +426,96 @@ int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_ | |||
426 | int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length); | 426 | int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length); |
427 | 427 | ||
428 | 428 | ||
429 | /****************FILE SENDING FUNCTIONS*****************/ | ||
430 | /* NOTE: This how to will be updated. | ||
431 | * | ||
432 | * HOW TO SEND FILES CORRECTLY: | ||
433 | * 1. Use tox_new_filesender(...) to create a new file sender. | ||
434 | * 2. Wait for the callback set with tox_callback_file_control(...) to be called with receive_send == 1 and control_type == TOX_FILECONTROL_ACCEPT | ||
435 | * 3. Send the data with tox_file_senddata(...) | ||
436 | * 4. When sending is done, send a tox_file_sendcontrol(...) with send_receive = 0 and message_id = TOX_FILECONTROL_FINISHED | ||
437 | * | ||
438 | * HOW TO RECEIVE FILES CORRECTLY: | ||
439 | * 1. wait for the callback set with tox_callback_file_sendrequest(...) | ||
440 | * 2. accept or refuse the connection with tox_file_sendcontrol(...) with send_receive = 1 and message_id = TOX_FILECONTROL_ACCEPT or TOX_FILECONTROL_KILL | ||
441 | * 3. save all the data received with the callback set with tox_callback_file_data(...) to a file. | ||
442 | * 4. when the callback set with tox_callback_file_control(...) is called with receive_send == 0 and control_type == TOX_FILECONTROL_FINISHED | ||
443 | * the file is done transferring. | ||
444 | * | ||
445 | * tox_file_dataremaining(...) can be used to know how many bytes are left to send/receive. | ||
446 | * | ||
447 | * More to come... | ||
448 | */ | ||
449 | |||
450 | enum { | ||
451 | TOX_FILECONTROL_ACCEPT, | ||
452 | TOX_FILECONTROL_PAUSE, | ||
453 | TOX_FILECONTROL_KILL, | ||
454 | TOX_FILECONTROL_FINISHED | ||
455 | }; | ||
456 | /* Set the callback for file send requests. | ||
457 | * | ||
458 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length, void *userdata) | ||
459 | */ | ||
460 | void tox_callback_file_sendrequest(Tox *tox, void (*function)(Tox *m, int, uint8_t, uint64_t, uint8_t *, uint16_t, | ||
461 | void *), void *userdata); | ||
462 | |||
463 | /* Set the callback for file control requests. | ||
464 | * | ||
465 | * receive_send is 1 if the message is for a slot on which we are currently sending a file and 0 if the message | ||
466 | * is for a slot on which we are receiving the file | ||
467 | * | ||
468 | * Function(Tox *tox, int friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, uint8_t *data, uint16_t length, void *userdata) | ||
469 | * | ||
470 | */ | ||
471 | void tox_callback_file_control(Tox *tox, void (*function)(Tox *m, int, uint8_t, uint8_t, uint8_t, uint8_t *, | ||
472 | uint16_t, void *), void *userdata); | ||
473 | |||
474 | /* Set the callback for file data. | ||
475 | * | ||
476 | * Function(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length, void *userdata) | ||
477 | * | ||
478 | */ | ||
479 | void tox_callback_file_data(Tox *tox, void (*function)(Tox *m, int, uint8_t, uint8_t *, uint16_t length, void *), | ||
480 | void *userdata); | ||
481 | |||
482 | |||
483 | /* Send a file send request. | ||
484 | * Maximum filename length is 255 bytes. | ||
485 | * return file number on success | ||
486 | * return -1 on failure | ||
487 | */ | ||
488 | int tox_new_filesender(Tox *tox, int friendnumber, uint64_t filesize, uint8_t *filename, uint16_t filename_length); | ||
489 | |||
490 | /* Send a file control request. | ||
491 | * | ||
492 | * send_receive is 0 if we want the control packet to target a file we are currently sending, | ||
493 | * 1 if it targets a file we are currently receiving. | ||
494 | * | ||
495 | * return 1 on success | ||
496 | * return 0 on failure | ||
497 | */ | ||
498 | int tox_file_sendcontrol(Tox *tox, int friendnumber, uint8_t send_receive, uint8_t filenumber, uint8_t message_id, | ||
499 | uint8_t *data, uint16_t length); | ||
500 | |||
501 | /* Send file data. | ||
502 | * | ||
503 | * return 1 on success | ||
504 | * return 0 on failure | ||
505 | */ | ||
506 | int tox_file_senddata(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t *data, uint16_t length); | ||
507 | |||
508 | /* Give the number of bytes left to be sent/received. | ||
509 | * | ||
510 | * send_receive is 0 if we want the sending files, 1 if we want the receiving. | ||
511 | * | ||
512 | * return number of bytes remaining to be sent/received on success | ||
513 | * return 0 on failure | ||
514 | */ | ||
515 | uint64_t tox_file_dataremaining(Tox *tox, int friendnumber, uint8_t filenumber, uint8_t send_receive); | ||
516 | |||
517 | /***************END OF FILE SENDING FUNCTIONS******************/ | ||
429 | 518 | ||
430 | /******************END OF GROUP CHAT FUNCTIONS************************/ | ||
431 | 519 | ||
432 | /* | 520 | /* |
433 | * Use these two functions to bootstrap the client. | 521 | * Use these two functions to bootstrap the client. |