summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore7
-rw-r--r--configure.ac1
-rw-r--r--docs/TODO16
-rw-r--r--testing/Makefile.inc17
-rw-r--r--testing/crypto_speed_test.c2
-rw-r--r--toxcore/Messenger.c79
-rw-r--r--toxcore/Messenger.h6
-rw-r--r--toxcore/group_chats.c2
-rw-r--r--toxcore/net_crypto.c9
-rw-r--r--toxcore/net_crypto.h2
-rw-r--r--toxcore/network.c4
-rw-r--r--toxcore/tox.c14
-rw-r--r--toxcore/tox.h20
-rw-r--r--toxmsi/phone.c375
-rw-r--r--toxrtp/toxrtp.h66
-rw-r--r--toxrtp/toxrtp_helper.c97
16 files changed, 405 insertions, 312 deletions
diff --git a/.gitignore b/.gitignore
index 059987b5..aa7d8f50 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,11 @@
1# OS files
1.DS_Store 2.DS_Store
3.DS_Store?
4._*
5.Spotlight-V100
6.Trashes
7ethumbs.db
8Thumbs.db
2 9
3//nacl build 10//nacl build
4nacl/build/ 11nacl/build/
diff --git a/configure.ac b/configure.ac
index dba051c7..62bb91bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -587,6 +587,7 @@ AM_CONDITIONAL(BUILD_TESTS, test "x$BUILD_TESTS" = "xyes")
587AM_CONDITIONAL(BUILD_NTOX, test "x$BUILD_NTOX" = "xyes") 587AM_CONDITIONAL(BUILD_NTOX, test "x$BUILD_NTOX" = "xyes")
588AM_CONDITIONAL(BUILD_AV, test "x$BUILD_AV" = "xyes") 588AM_CONDITIONAL(BUILD_AV, test "x$BUILD_AV" = "xyes")
589AM_CONDITIONAL(BUILD_TESTING, test "x$BUILD_TESTING" = "xyes") 589AM_CONDITIONAL(BUILD_TESTING, test "x$BUILD_TESTING" = "xyes")
590AM_CONDITIONAL(WIN32, test "x$WIN32" = "xyes")
590 591
591AC_CONFIG_FILES([Makefile 592AC_CONFIG_FILES([Makefile
592 build/Makefile 593 build/Makefile
diff --git a/docs/TODO b/docs/TODO
index 14fe8619..974dc350 100644
--- a/docs/TODO
+++ b/docs/TODO
@@ -2,6 +2,10 @@ TODO list.
2 2
3[IN PROGRESS] Add what is left to do to the TODO list. 3[IN PROGRESS] Add what is left to do to the TODO list.
4 4
5Networking:
6 [NOT STARTED] UPnP port forwarding.
7 [NOT STARTED] NAT-PMP port forwarding.
8
5DHT: 9DHT:
6 [IN PROGRESS] Metadata collection prevention. 10 [IN PROGRESS] Metadata collection prevention.
7 [IN PROGRESS] Hardening against attacks. 11 [IN PROGRESS] Hardening against attacks.
@@ -11,9 +15,9 @@ Lossless UDP:
11 [DONE] Increase data send/receive rates. 15 [DONE] Increase data send/receive rates.
12 16
13[IN PROGRESS] Massive IRC like group chats (text only) 17[IN PROGRESS] Massive IRC like group chats (text only)
14 [DONE] networking base. 18 [DONE] Networking base.
15 [TODO] Syncing chat state between clients (nicknames, list of who is in chat, etc...) 19 [NOT STARTED] Syncing chat state between clients (nicknames, list of who is in chat, etc...)
16 [TODO] Make clients sign their messages so that peers can't modify them. 20 [NOT STARTED] Make clients sign their messages so that peers can't modify them.
17 21
18[IN PROGRESS] Audio/Video 22[IN PROGRESS] Audio/Video
19 [DONE] Capture/encoding/streaming/decoding/displaying 23 [DONE] Capture/encoding/streaming/decoding/displaying
@@ -23,9 +27,9 @@ Lossless UDP:
23 [NOT STARTED] Push to talk for audio 27 [NOT STARTED] Push to talk for audio
24 28
25Friend_requests.c: 29Friend_requests.c:
26 [TODO] What happens when a friend request is recieved needs to be changed. 30 [NOT STARTED] What happens when a friend request is recieved needs to be changed.
27 31
28[IN PROGRESS] File transfers 32[DONE] File transfers
29[NOT STARTED] Offline messaging 33[NOT STARTED] Offline messaging
30[NOT STARTED] Friends list syncing 34[NOT STARTED] Friends list syncing
31[IN PROGRESS] IPV6 support 35[IN PROGRESS] IPV6 support
@@ -33,5 +37,5 @@ Friend_requests.c:
33 [DONE] DHT + Messenger 37 [DONE] DHT + Messenger
34 [NOT STARTED] Group chats 38 [NOT STARTED] Group chats
35 39
36[IN PROGRESS] GUI (https://github.com/nurupo/ProjectTox-Qt-GUI) 40[IN PROGRESS] GUI (no official GUI chosen yet)
37[NOT STARTED] Security audit from professionals 41[NOT STARTED] Security audit from professionals
diff --git a/testing/Makefile.inc b/testing/Makefile.inc
index de3995be..31c84678 100644
--- a/testing/Makefile.inc
+++ b/testing/Makefile.inc
@@ -25,8 +25,7 @@ noinst_PROGRAMS += DHT_test \
25 Lossless_UDP_testclient \ 25 Lossless_UDP_testclient \
26 Lossless_UDP_testserver \ 26 Lossless_UDP_testserver \
27 Messenger_test \ 27 Messenger_test \
28 crypto_speed_test \ 28 crypto_speed_test
29 tox_sync
30 29
31DHT_test_SOURCES = ../testing/DHT_test.c 30DHT_test_SOURCES = ../testing/DHT_test.c
32 31
@@ -102,20 +101,22 @@ crypto_speed_test_LDADD = \
102 $(NACL_LIBS) \ 101 $(NACL_LIBS) \
103 $(WINSOCK2_LIBS) 102 $(WINSOCK2_LIBS)
104 103
105tox_sync_SOURCES = \ 104if !WIN32
106 ../testing/tox_sync.c
107 105
108tox_sync_CFLAGS = \ 106noinst_PROGRAMS += tox_sync
109 $(LIBSODIUM_CFLAGS) \ 107
108tox_sync_SOURCES = ../testing/tox_sync.c
109
110tox_sync_CFLAGS = $(LIBSODIUM_CFLAGS) \
110 $(NACL_CFLAGS) 111 $(NACL_CFLAGS)
111 112
112tox_sync_LDADD = \ 113tox_sync_LDADD = $(LIBSODIUM_LDFLAGS) \
113 $(LIBSODIUM_LDFLAGS) \
114 $(NACL_LDFLAGS) \ 114 $(NACL_LDFLAGS) \
115 libtoxcore.la \ 115 libtoxcore.la \
116 $(LIBSODIUM_LIBS) \ 116 $(LIBSODIUM_LIBS) \
117 $(NACL_LIBS) \ 117 $(NACL_LIBS) \
118 $(WINSOCK2_LIBS) 118 $(WINSOCK2_LIBS)
119endif
119 120
120EXTRA_DIST += $(top_srcdir)/testing/misc_tools.c 121EXTRA_DIST += $(top_srcdir)/testing/misc_tools.c
121 122
diff --git a/testing/crypto_speed_test.c b/testing/crypto_speed_test.c
index 05f4aaf2..bc8052da 100644
--- a/testing/crypto_speed_test.c
+++ b/testing/crypto_speed_test.c
@@ -8,6 +8,8 @@
8//Windows XP 8//Windows XP
9#define WINVER 0x0501 9#define WINVER 0x0501
10#endif 10#endif
11
12#include <winsock2.h>
11#include <windows.h> 13#include <windows.h>
12double get_time() 14double get_time()
13{ 15{
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 6764dfe3..2e8efeac 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -31,6 +31,28 @@
31 31
32#define MIN(a,b) (((a)<(b))?(a):(b)) 32#define MIN(a,b) (((a)<(b))?(a):(b))
33 33
34
35void host_to_net(uint8_t *num, uint16_t numbytes)
36{
37 union {
38 uint32_t i;
39 uint8_t c[4];
40 } a;
41 a.i = 1;
42
43 if (a.c[0] == 1) {
44 uint32_t i;
45 uint8_t buff[numbytes];
46
47 for (i = 0; i < numbytes; ++i) {
48 buff[i] = num[numbytes - i - 1];
49 }
50
51 memcpy(num, buff, numbytes);
52 }
53}
54#define net_to_host(x, y) host_to_net(x, y)
55
34static void set_friend_status(Messenger *m, int friendnumber, uint8_t status); 56static void set_friend_status(Messenger *m, int friendnumber, uint8_t status);
35static int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length); 57static int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint8_t *data, uint32_t length);
36 58
@@ -1017,8 +1039,7 @@ int file_sendrequest(Messenger *m, int friendnumber, uint8_t filenumber, uint64_
1017 1039
1018 uint8_t packet[MAX_FILENAME_LENGTH + 1 + sizeof(filesize)]; 1040 uint8_t packet[MAX_FILENAME_LENGTH + 1 + sizeof(filesize)];
1019 packet[0] = filenumber; 1041 packet[0] = filenumber;
1020 //TODO: 1042 host_to_net((uint8_t *)&filesize, sizeof(filesize));
1021 //filesize = htonll(filesize);
1022 memcpy(packet + 1, &filesize, sizeof(filesize)); 1043 memcpy(packet + 1, &filesize, sizeof(filesize));
1023 memcpy(packet + 1 + sizeof(filesize), filename, filename_length); 1044 memcpy(packet + 1 + sizeof(filesize), filename, filename_length);
1024 return write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_SENDREQUEST, packet, 1045 return write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_SENDREQUEST, packet,
@@ -1084,7 +1105,20 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f
1084 packet[0] = send_receive; 1105 packet[0] = send_receive;
1085 packet[1] = filenumber; 1106 packet[1] = filenumber;
1086 packet[2] = message_id; 1107 packet[2] = message_id;
1087 memcpy(packet + 3, data, length); 1108 uint64_t transferred = 0;
1109
1110 if (message_id == FILECONTROL_RESUME_BROKEN) {
1111 if (length != sizeof(uint64_t))
1112 return 0;
1113
1114 uint8_t remaining[sizeof(uint64_t)];
1115 memcpy(remaining, data, sizeof(uint64_t));
1116 host_to_net(remaining, sizeof(uint64_t));
1117 memcpy(packet + 3, remaining, sizeof(uint64_t));
1118 memcpy(&transferred, data, sizeof(uint64_t));
1119 } else {
1120 memcpy(packet + 3, data, length);
1121 }
1088 1122
1089 if (write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_CONTROL, packet, length + 3)) { 1123 if (write_cryptpacket_id(m, friendnumber, PACKET_ID_FILE_CONTROL, packet, length + 3)) {
1090 if (send_receive == 1) 1124 if (send_receive == 1)
@@ -1101,6 +1135,11 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f
1101 case FILECONTROL_FINISHED: 1135 case FILECONTROL_FINISHED:
1102 m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_NONE; 1136 m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_NONE;
1103 break; 1137 break;
1138
1139 case FILECONTROL_RESUME_BROKEN:
1140 m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_PAUSED_BY_OTHER;
1141 m->friendlist[friendnumber].file_receiving[filenumber].transferred = transferred;
1142 break;
1104 } 1143 }
1105 else 1144 else
1106 switch (message_id) { 1145 switch (message_id) {
@@ -1201,17 +1240,23 @@ static void break_files(Messenger *m, int friendnumber)
1201 } 1240 }
1202} 1241}
1203 1242
1204static int handle_filecontrol(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t filenumber, 1243static int handle_filecontrol(Messenger *m, int friendnumber, uint8_t receive_send, uint8_t filenumber,
1205 uint8_t message_id, uint8_t *data, 1244 uint8_t message_id, uint8_t *data,
1206 uint16_t length) 1245 uint16_t length)
1207{ 1246{
1208 if (send_receive > 1) 1247 if (receive_send > 1)
1209 return -1; 1248 return -1;
1210 1249
1211 if (send_receive == 0) { 1250 if (receive_send == 0) {
1212 if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE) 1251 if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE) {
1252 /* Tell the other to kill the file sending if we don't know this one. */
1253 m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_TEMPORARY;
1254 file_control(m, friendnumber, !receive_send, filenumber, FILECONTROL_KILL, NULL, 0);
1255 m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_NONE;
1213 return -1; 1256 return -1;
1214 1257
1258 }
1259
1215 switch (message_id) { 1260 switch (message_id) {
1216 case FILECONTROL_ACCEPT: 1261 case FILECONTROL_ACCEPT:
1217 if (m->friendlist[friendnumber].file_receiving[filenumber].status != FILESTATUS_PAUSED_BY_US) { 1262 if (m->friendlist[friendnumber].file_receiving[filenumber].status != FILESTATUS_PAUSED_BY_US) {
@@ -1235,8 +1280,13 @@ static int handle_filecontrol(Messenger *m, int friendnumber, uint8_t send_recei
1235 return 0; 1280 return 0;
1236 } 1281 }
1237 } else { 1282 } else {
1238 if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_NONE) 1283 if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_NONE) {
1284 /* Tell the other to kill the file sending if we don't know this one. */
1285 m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_TEMPORARY;
1286 file_control(m, friendnumber, !receive_send, filenumber, FILECONTROL_KILL, NULL, 0);
1287 m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_NONE;
1239 return -1; 1288 return -1;
1289 }
1240 1290
1241 switch (message_id) { 1291 switch (message_id) {
1242 case FILECONTROL_ACCEPT: 1292 case FILECONTROL_ACCEPT:
@@ -1258,6 +1308,16 @@ static int handle_filecontrol(Messenger *m, int friendnumber, uint8_t send_recei
1258 case FILECONTROL_FINISHED: 1308 case FILECONTROL_FINISHED:
1259 m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_NONE; 1309 m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_NONE;
1260 return 0; 1310 return 0;
1311
1312 case FILECONTROL_RESUME_BROKEN: {
1313 if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_BROKEN && length == sizeof(uint64_t)) {
1314 m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_PAUSED_BY_US;
1315 net_to_host(data, sizeof(uint64_t));
1316 return 0;
1317 }
1318
1319 return -1;
1320 }
1261 } 1321 }
1262 } 1322 }
1263 1323
@@ -1584,9 +1644,8 @@ void doFriends(Messenger *m)
1584 1644
1585 uint8_t filenumber = data[0]; 1645 uint8_t filenumber = data[0];
1586 uint64_t filesize; 1646 uint64_t filesize;
1647 net_to_host(data + 1, sizeof(filesize));
1587 memcpy(&filesize, data + 1, sizeof(filesize)); 1648 memcpy(&filesize, data + 1, sizeof(filesize));
1588 //TODO:
1589 //filesize = ntohll(filesize);
1590 m->friendlist[i].file_receiving[filenumber].status = FILESTATUS_NOT_ACCEPTED; 1649 m->friendlist[i].file_receiving[filenumber].status = FILESTATUS_NOT_ACCEPTED;
1591 m->friendlist[i].file_receiving[filenumber].size = filesize; 1650 m->friendlist[i].file_receiving[filenumber].size = filesize;
1592 m->friendlist[i].file_receiving[filenumber].transferred = 0; 1651 m->friendlist[i].file_receiving[filenumber].transferred = 0;
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h
index f03a7478..c6ead732 100644
--- a/toxcore/Messenger.h
+++ b/toxcore/Messenger.h
@@ -111,7 +111,8 @@ enum {
111 FILESTATUS_PAUSED_BY_OTHER, 111 FILESTATUS_PAUSED_BY_OTHER,
112 FILESTATUS_TRANSFERRING, 112 FILESTATUS_TRANSFERRING,
113 FILESTATUS_BROKEN, 113 FILESTATUS_BROKEN,
114 FILESTATUS_PAUSED_BY_US 114 FILESTATUS_PAUSED_BY_US,
115 FILESTATUS_TEMPORARY
115}; 116};
116/* This cannot be bigger than 256 */ 117/* This cannot be bigger than 256 */
117#define MAX_CONCURRENT_FILE_PIPES 256 118#define MAX_CONCURRENT_FILE_PIPES 256
@@ -120,7 +121,8 @@ enum {
120 FILECONTROL_ACCEPT, 121 FILECONTROL_ACCEPT,
121 FILECONTROL_PAUSE, 122 FILECONTROL_PAUSE,
122 FILECONTROL_KILL, 123 FILECONTROL_KILL,
123 FILECONTROL_FINISHED 124 FILECONTROL_FINISHED,
125 FILECONTROL_RESUME_BROKEN
124}; 126};
125 127
126typedef struct { 128typedef struct {
diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c
index c32b26ba..0d6d6972 100644
--- a/toxcore/group_chats.c
+++ b/toxcore/group_chats.c
@@ -266,7 +266,7 @@ int group_peername(Group_Chat *chat, int peernum, uint8_t *name)
266 return -1; 266 return -1;
267 267
268 if (chat->group[peernum].nick_len == 0) { 268 if (chat->group[peernum].nick_len == 0) {
269 memcpy(name, "NSA Agent", 10); /* Kindly remind the user that someone with no name might be a NSA agent.*/ 269 memcpy(name, "NSA Agent", 10); /* Kindly remind the user that someone with no name might be an NSA agent.*/
270 return 10; 270 return 10;
271 } 271 }
272 272
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 3049776f..b7e3ced7 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -704,10 +704,17 @@ static void receive_crypto(Net_Crypto *c)
704 CONN_ESTABLISHED; /* Connection status needs to be 3 for write_cryptpacket() to work. */ 704 CONN_ESTABLISHED; /* Connection status needs to be 3 for write_cryptpacket() to work. */
705 write_cryptpacket(c, i, ((uint8_t *)&zero), sizeof(zero)); 705 write_cryptpacket(c, i, ((uint8_t *)&zero), sizeof(zero));
706 c->crypto_connections[i].status = CONN_NOT_CONFIRMED; /* Set it to its proper value right after. */ 706 c->crypto_connections[i].status = CONN_NOT_CONFIRMED; /* Set it to its proper value right after. */
707 } else {
708 /* This should not happen, timeout the connection if it does. */
709 c->crypto_connections[i].status = CONN_TIMED_OUT;
707 } 710 }
711 } else {
712 /* This should not happen, timeout the connection if it does. */
713 c->crypto_connections[i].status = CONN_TIMED_OUT;
708 } 714 }
709 } else if (id_packet(c->lossless_udp, 715 } else if (id_packet(c->lossless_udp,
710 c->crypto_connections[i].number) != -1) { // This should not happen, timeout the connection if it does. 716 c->crypto_connections[i].number) != -1) {
717 /* This should not happen, timeout the connection if it does. */
711 c->crypto_connections[i].status = CONN_TIMED_OUT; 718 c->crypto_connections[i].status = CONN_TIMED_OUT;
712 } 719 }
713 } 720 }
diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h
index 0c1bffe6..0ddb711a 100644
--- a/toxcore/net_crypto.h
+++ b/toxcore/net_crypto.h
@@ -28,7 +28,7 @@
28 28
29#define CRYPTO_PACKET_FRIEND_REQ 32 /* Friend request crypto packet ID. */ 29#define CRYPTO_PACKET_FRIEND_REQ 32 /* Friend request crypto packet ID. */
30#define CRYPTO_PACKET_NAT_PING 254 /* NAT ping crypto packet ID. */ 30#define CRYPTO_PACKET_NAT_PING 254 /* NAT ping crypto packet ID. */
31#define CRYPTO_HANDSHAKE_TIMEOUT CONNEXION_TIMEOUT 31#define CRYPTO_HANDSHAKE_TIMEOUT (CONNEXION_TIMEOUT * 2)
32 32
33typedef struct { 33typedef struct {
34 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* The real public key of the peer. */ 34 uint8_t public_key[crypto_box_PUBLICKEYBYTES]; /* The real public key of the peer. */
diff --git a/toxcore/network.c b/toxcore/network.c
index ee950d97..53511df6 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -20,6 +20,10 @@
20 * along with Tox. If not, see <http://www.gnu.org/licenses/>. 20 * along with Tox. If not, see <http://www.gnu.org/licenses/>.
21 * 21 *
22 */ 22 */
23
24#if (_WIN32_WINNT >= _WIN32_WINNT_WINXP)
25#define _WIN32_WINNT 0x501
26#endif
23 27
24#ifdef HAVE_CONFIG_H 28#ifdef HAVE_CONFIG_H
25#include "config.h" 29#include "config.h"
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 8f4aef5b..5f882965 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -171,20 +171,6 @@ uint32_t tox_sendaction_withid(Tox *tox, int friendnumber, uint32_t theid, uint8
171 return m_sendaction_withid(m, friendnumber, theid, action, length); 171 return m_sendaction_withid(m, friendnumber, theid, action, length);
172} 172}
173 173
174/* Set friendnumber's nickname.
175 * name must be a string of maximum MAX_NAME_LENGTH length.
176 * length must be at least 1 byte.
177 * length is the length of name with the NULL terminator.
178 *
179 * return 0 if success.
180 * return -1 if failure.
181 */
182int tox_setfriendname(Tox *tox, int friendnumber, uint8_t *name, uint16_t length)
183{
184 Messenger *m = tox;
185 return setfriendname(m, friendnumber, name, length);
186}
187
188/* Set our nickname. 174/* Set our nickname.
189 * name must be a string of maximum MAX_NAME_LENGTH length. 175 * name must be a string of maximum MAX_NAME_LENGTH length.
190 * length must be at least 1 byte. 176 * length must be at least 1 byte.
diff --git a/toxcore/tox.h b/toxcore/tox.h
index bcc89ce1..2a26e7a6 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -211,16 +211,6 @@ uint32_t tox_sendmessage_withid(Tox *tox, int friendnumber, uint32_t theid, uint
211uint32_t tox_sendaction(Tox *tox, int friendnumber, uint8_t *action, uint32_t length); 211uint32_t tox_sendaction(Tox *tox, int friendnumber, uint8_t *action, uint32_t length);
212uint32_t tox_sendaction_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length); 212uint32_t tox_sendaction_withid(Tox *tox, int friendnumber, uint32_t theid, uint8_t *action, uint32_t length);
213 213
214/* Set friendnumber's nickname.
215 * name must be a string of maximum MAX_NAME_LENGTH length.
216 * length must be at least 1 byte.
217 * length is the length of name with the NULL terminator.
218 *
219 * return 0 if success.
220 * return -1 if failure.
221 */
222int tox_setfriendname(Tox *tox, int friendnumber, uint8_t *name, uint16_t length);
223
224/* Set our nickname. 214/* Set our nickname.
225 * name must be a string of maximum MAX_NAME_LENGTH length. 215 * name must be a string of maximum MAX_NAME_LENGTH length.
226 * length must be at least 1 byte. 216 * length must be at least 1 byte.
@@ -434,6 +424,13 @@ int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t
434 * 424 *
435 * tox_file_dataremaining(...) can be used to know how many bytes are left to send/receive. 425 * tox_file_dataremaining(...) can be used to know how many bytes are left to send/receive.
436 * 426 *
427 * If the connection breaks during file sending (The other person goes offline without pausing the sending and then comes back)
428 * the reciever must send a control packet with receive_send == 0 message_id = TOX_FILECONTROL_RESUME_BROKEN and the data being
429 * a uint64_t (in host byte order) containing the number of bytes recieved.
430 *
431 * If the sender recieves this packet, he must send a control packet with receive_send == 1 and control_type == TOX_FILECONTROL_ACCEPT
432 * then he must start sending file data from the position (data , uint64_t in host byte order) recieved in the TOX_FILECONTROL_RESUME_BROKEN packet.
433 *
437 * More to come... 434 * More to come...
438 */ 435 */
439 436
@@ -441,7 +438,8 @@ enum {
441 TOX_FILECONTROL_ACCEPT, 438 TOX_FILECONTROL_ACCEPT,
442 TOX_FILECONTROL_PAUSE, 439 TOX_FILECONTROL_PAUSE,
443 TOX_FILECONTROL_KILL, 440 TOX_FILECONTROL_KILL,
444 TOX_FILECONTROL_FINISHED 441 TOX_FILECONTROL_FINISHED,
442 TOX_FILECONTROL_RESUME_BROKEN
445}; 443};
446/* Set the callback for file send requests. 444/* Set the callback for file send requests.
447 * 445 *
diff --git a/toxmsi/phone.c b/toxmsi/phone.c
index 010f26aa..f14d0323 100644
--- a/toxmsi/phone.c
+++ b/toxmsi/phone.c
@@ -14,13 +14,13 @@
14#include <stdio.h> 14#include <stdio.h>
15#include <string.h> 15#include <string.h>
16#include <stdlib.h> 16#include <stdlib.h>
17#include <termios.h> 17/* #include <termios.h> Can this be removed? */
18#include <pthread.h> 18#include <pthread.h>
19#include "AV_codec.h" 19#include "AV_codec.h"
20 20
21 21
22 22
23void INFO (const char* _format, ...) 23void INFO (const char *_format, ...)
24{ 24{
25 printf("\r[!] "); 25 printf("\r[!] ");
26 va_list _arg; 26 va_list _arg;
@@ -31,13 +31,13 @@ void INFO (const char* _format, ...)
31 fflush(stdout); 31 fflush(stdout);
32} 32}
33 33
34int rtp_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32_t length ) 34int rtp_handlepacket ( void *_object, tox_IP_Port ip_port, uint8_t *data, uint32_t length )
35{ 35{
36 phone_t* _phone = _object; 36 phone_t *_phone = _object;
37 rtp_msg_t* _msg; 37 rtp_msg_t *_msg;
38 uint8_t _payload_id; 38 uint8_t _payload_id;
39 39
40 if ( _phone->_msi->_call && _phone->_msi->_call->_state == call_active ){ 40 if ( _phone->_msi->_call && _phone->_msi->_call->_state == call_active ) {
41 41
42 _msg = rtp_msg_parse ( NULL, data + 1, length - 1 ); /* ignore marker byte */ 42 _msg = rtp_msg_parse ( NULL, data + 1, length - 1 ); /* ignore marker byte */
43 43
@@ -55,10 +55,10 @@ int rtp_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32
55 55
56 return SUCCESS; 56 return SUCCESS;
57} 57}
58int msi_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32_t length ) 58int msi_handlepacket ( void *_object, tox_IP_Port ip_port, uint8_t *data, uint32_t length )
59{ 59{
60 msi_session_t* _session = _object; 60 msi_session_t *_session = _object;
61 msi_msg_t* _msg; 61 msi_msg_t *_msg;
62 62
63 _msg = msi_parse_msg ( data + 1 ); /* ignore marker byte */ 63 _msg = msi_parse_msg ( data + 1 ); /* ignore marker byte */
64 64
@@ -75,9 +75,9 @@ int msi_handlepacket ( void* _object, tox_IP_Port ip_port, uint8_t* data, uint32
75 return SUCCESS; 75 return SUCCESS;
76} 76}
77 77
78void* phone_receivepacket ( void* _phone_p ) 78void *phone_receivepacket ( void *_phone_p )
79{ 79{
80 phone_t* _phone = _phone_p; 80 phone_t *_phone = _phone_p;
81 81
82 82
83 networking_registerhandler(_phone->_networking, MSI_PACKET, msi_handlepacket, _phone->_msi); 83 networking_registerhandler(_phone->_networking, MSI_PACKET, msi_handlepacket, _phone->_msi);
@@ -94,31 +94,31 @@ void* phone_receivepacket ( void* _phone_p )
94 94
95/* Media transport callback */ 95/* Media transport callback */
96typedef struct hmtc_args_s { 96typedef struct hmtc_args_s {
97 rtp_session_t** _rtp_audio; 97 rtp_session_t **_rtp_audio;
98 rtp_session_t** _rtp_video; 98 rtp_session_t **_rtp_video;
99 call_type* _local_type_call; 99 call_type *_local_type_call;
100 call_state* _this_call; 100 call_state *_this_call;
101 void *_core_handler; 101 void *_core_handler;
102} hmtc_args_t; 102} hmtc_args_t;
103 103
104void* phone_handle_media_transport_poll ( void* _hmtc_args_p ) 104void *phone_handle_media_transport_poll ( void *_hmtc_args_p )
105{ 105{
106 rtp_msg_t* _audio_msg, * _video_msg; 106 rtp_msg_t *_audio_msg, * _video_msg;
107 107
108 hmtc_args_t* _hmtc_args = _hmtc_args_p; 108 hmtc_args_t *_hmtc_args = _hmtc_args_p;
109 109
110 rtp_session_t* _rtp_audio = *_hmtc_args->_rtp_audio; 110 rtp_session_t *_rtp_audio = *_hmtc_args->_rtp_audio;
111 rtp_session_t* _rtp_video = *_hmtc_args->_rtp_video; 111 rtp_session_t *_rtp_video = *_hmtc_args->_rtp_video;
112 112
113 call_type* _type = _hmtc_args->_local_type_call; 113 call_type *_type = _hmtc_args->_local_type_call;
114 void* _core_handler = _hmtc_args->_core_handler; 114 void *_core_handler = _hmtc_args->_core_handler;
115 115
116 116
117 call_state* _this_call = _hmtc_args->_this_call; 117 call_state *_this_call = _hmtc_args->_this_call;
118 118
119 while ( *_this_call == call_active ) { 119 while ( *_this_call == call_active ) {
120 120
121 // THREADLOCK() 121 // THREADLOCK()
122 122
123 _audio_msg = rtp_recv_msg ( _rtp_audio ); 123 _audio_msg = rtp_recv_msg ( _rtp_audio );
124 _video_msg = rtp_recv_msg ( _rtp_video ); 124 _video_msg = rtp_recv_msg ( _rtp_video );
@@ -139,14 +139,15 @@ void* phone_handle_media_transport_poll ( void* _hmtc_args_p )
139 rtp_free_msg ( _rtp_video, _video_msg ); 139 rtp_free_msg ( _rtp_video, _video_msg );
140 _video_msg = NULL; 140 _video_msg = NULL;
141 } 141 }
142
142 /* -------------------- */ 143 /* -------------------- */
143 144
144 _audio_msg = rtp_msg_new ( _rtp_audio, (const uint8_t*)"audio\0", 6 ) ; 145 _audio_msg = rtp_msg_new ( _rtp_audio, (const uint8_t *)"audio\0", 6 ) ;
145 rtp_send_msg ( _rtp_audio, _audio_msg, _core_handler ); 146 rtp_send_msg ( _rtp_audio, _audio_msg, _core_handler );
146 _audio_msg = NULL; 147 _audio_msg = NULL;
147 148
148 if ( *_type == type_video ){ /* if local call send video */ 149 if ( *_type == type_video ) { /* if local call send video */
149 _video_msg = rtp_msg_new ( _rtp_video, (const uint8_t*)"video\0", 6 ) ; 150 _video_msg = rtp_msg_new ( _rtp_video, (const uint8_t *)"video\0", 6 ) ;
150 rtp_send_msg ( _rtp_video, _video_msg, _core_handler ); 151 rtp_send_msg ( _rtp_video, _video_msg, _core_handler );
151 _video_msg = NULL; 152 _video_msg = NULL;
152 } 153 }
@@ -159,7 +160,7 @@ void* phone_handle_media_transport_poll ( void* _hmtc_args_p )
159 160
160 //THREADLOCK() 161 //THREADLOCK()
161 162
162 if ( _audio_msg ){ 163 if ( _audio_msg ) {
163 rtp_free_msg(_rtp_audio, _audio_msg); 164 rtp_free_msg(_rtp_audio, _audio_msg);
164 } 165 }
165 166
@@ -185,9 +186,9 @@ void* phone_handle_media_transport_poll ( void* _hmtc_args_p )
185 pthread_exit ( NULL ); 186 pthread_exit ( NULL );
186} 187}
187 188
188pthread_t phone_startmedia_loop ( phone_t* _phone ) 189pthread_t phone_startmedia_loop ( phone_t *_phone )
189{ 190{
190 if ( !_phone ){ 191 if ( !_phone ) {
191 return 0; 192 return 0;
192 } 193 }
193 194
@@ -207,10 +208,10 @@ pthread_t phone_startmedia_loop ( phone_t* _phone )
207 rtp_set_prefix ( _phone->_rtp_video, &_prefix, 1 ); 208 rtp_set_prefix ( _phone->_rtp_video, &_prefix, 1 );
208 rtp_add_receiver ( _phone->_rtp_video, &_phone->_msi->_friend_id ); 209 rtp_add_receiver ( _phone->_rtp_video, &_phone->_msi->_friend_id );
209 rtp_set_payload_type(_phone->_rtp_video, _PAYLOAD_VP8); 210 rtp_set_payload_type(_phone->_rtp_video, _PAYLOAD_VP8);
210
211
212 211
213 hmtc_args_t* rtp_targs = calloc(sizeof(hmtc_args_t),1); 212
213
214 hmtc_args_t *rtp_targs = calloc(sizeof(hmtc_args_t), 1);
214 215
215 216
216 rtp_targs->_rtp_audio = &_phone->_rtp_audio; 217 rtp_targs->_rtp_audio = &_phone->_rtp_audio;
@@ -220,26 +221,29 @@ pthread_t phone_startmedia_loop ( phone_t* _phone )
220 rtp_targs->_core_handler = _phone->_networking; 221 rtp_targs->_core_handler = _phone->_networking;
221 222
222 codec_state *cs; 223 codec_state *cs;
223 cs=_phone->cs; 224 cs = _phone->cs;
224 //_status = pthread_create ( &_rtp_tid, NULL, phone_handle_media_transport_poll, rtp_targs ); 225 //_status = pthread_create ( &_rtp_tid, NULL, phone_handle_media_transport_poll, rtp_targs );
225 cs->_rtp_audio=_phone->_rtp_audio; 226 cs->_rtp_audio = _phone->_rtp_audio;
226 cs->_rtp_video=_phone->_rtp_video; 227 cs->_rtp_video = _phone->_rtp_video;
227 cs->_networking=_phone->_networking; 228 cs->_networking = _phone->_networking;
228 cs->socket=_phone->_tox_sock; 229 cs->socket = _phone->_tox_sock;
229 cs->quit = 0; 230 cs->quit = 0;
230 231
231 printf("support: %d %d\n",cs->support_send_audio,cs->support_send_video); 232 printf("support: %d %d\n", cs->support_send_audio, cs->support_send_video);
232 233
233 if(cs->support_send_audio&&cs->support_send_video) /* quick fix */ 234 if (cs->support_send_audio && cs->support_send_video) /* quick fix */
234 pthread_create(&_phone->cs->encode_audio_thread, NULL, encode_audio_thread, _phone->cs); 235 pthread_create(&_phone->cs->encode_audio_thread, NULL, encode_audio_thread, _phone->cs);
235 if(cs->support_receive_audio) 236
236 pthread_create(&_phone->cs->decode_audio_thread, NULL, decode_audio_thread, _phone->cs); 237 if (cs->support_receive_audio)
237 238 pthread_create(&_phone->cs->decode_audio_thread, NULL, decode_audio_thread, _phone->cs);
238 if(cs->support_send_video) 239
239 pthread_create(&_phone->cs->encode_video_thread, NULL, encode_video_thread, _phone->cs); 240 if (cs->support_send_video)
240 if(cs->support_receive_video) 241 pthread_create(&_phone->cs->encode_video_thread, NULL, encode_video_thread, _phone->cs);
241 pthread_create(&_phone->cs->decode_video_thread, NULL, decode_video_thread, _phone->cs); 242
242// 243 if (cs->support_receive_video)
244 pthread_create(&_phone->cs->decode_video_thread, NULL, decode_video_thread, _phone->cs);
245
246//
243 return 1; 247 return 1;
244 248
245 249
@@ -252,20 +256,21 @@ pthread_t phone_startmedia_loop ( phone_t* _phone )
252 256
253MCBTYPE callback_recv_invite ( MCBARGS ) 257MCBTYPE callback_recv_invite ( MCBARGS )
254{ 258{
255 const char* _call_type; 259 const char *_call_type;
256 260
257 msi_session_t* _msi = _arg; 261 msi_session_t *_msi = _arg;
258 262
259 /* Get the last one */ 263 /* Get the last one */
260 call_type _type = _msi->_call->_type_peer[_msi->_call->_participants - 1]; 264 call_type _type = _msi->_call->_type_peer[_msi->_call->_participants - 1];
261 265
262 switch ( _type ){ 266 switch ( _type ) {
263 case type_audio: 267 case type_audio:
264 _call_type = "audio"; 268 _call_type = "audio";
265 break; 269 break;
266 case type_video: 270
267 _call_type = "video"; 271 case type_video:
268 break; 272 _call_type = "video";
273 break;
269 } 274 }
270 275
271 INFO( "Incoming %s call!", _call_type ); 276 INFO( "Incoming %s call!", _call_type );
@@ -281,8 +286,9 @@ MCBTYPE callback_recv_ringing ( MCBARGS )
281} 286}
282MCBTYPE callback_recv_starting ( MCBARGS ) 287MCBTYPE callback_recv_starting ( MCBARGS )
283{ 288{
284 msi_session_t* _session = _arg; 289 msi_session_t *_session = _arg;
285 if ( !phone_startmedia_loop(_session->_agent_handler) ){ 290
291 if ( !phone_startmedia_loop(_session->_agent_handler) ) {
286 INFO("Starting call failed!"); 292 INFO("Starting call failed!");
287 } else { 293 } else {
288 INFO ("Call started! ( press h to hangup )"); 294 INFO ("Call started! ( press h to hangup )");
@@ -290,34 +296,40 @@ MCBTYPE callback_recv_starting ( MCBARGS )
290} 296}
291MCBTYPE callback_recv_ending ( MCBARGS ) 297MCBTYPE callback_recv_ending ( MCBARGS )
292{ 298{
293 msi_session_t* _session = _arg; 299 msi_session_t *_session = _arg;
294 phone_t * _phone = _session->_agent_handler; 300 phone_t *_phone = _session->_agent_handler;
295 _phone->cs->quit=1; 301 _phone->cs->quit = 1;
296 if(_phone->cs->encode_video_thread) 302
297 pthread_join(_phone->cs->encode_video_thread,NULL); 303 if (_phone->cs->encode_video_thread)
298 if(_phone->cs->encode_audio_thread) 304 pthread_join(_phone->cs->encode_video_thread, NULL);
299 pthread_join(_phone->cs->encode_audio_thread,NULL); 305
300 if(_phone->cs->decode_audio_thread) 306 if (_phone->cs->encode_audio_thread)
301 pthread_join(_phone->cs->decode_audio_thread,NULL); 307 pthread_join(_phone->cs->encode_audio_thread, NULL);
302 if(_phone->cs->decode_video_thread) 308
303 pthread_join(_phone->cs->decode_video_thread,NULL); 309 if (_phone->cs->decode_audio_thread)
310 pthread_join(_phone->cs->decode_audio_thread, NULL);
311
312 if (_phone->cs->decode_video_thread)
313 pthread_join(_phone->cs->decode_video_thread, NULL);
314
304 SDL_Quit(); 315 SDL_Quit();
305 printf("all A/V threads successfully shut down\n"); 316 printf("all A/V threads successfully shut down\n");
306 317
307 INFO ( "Call ended!" ); 318 INFO ( "Call ended!" );
308} 319}
309 320
310MCBTYPE callback_recv_error ( MCBARGS ) 321MCBTYPE callback_recv_error ( MCBARGS )
311{ 322{
312 msi_session_t* _session = _arg; 323 msi_session_t *_session = _arg;
313 324
314 INFO( "Error: %s", _session->_last_error_str ); 325 INFO( "Error: %s", _session->_last_error_str );
315} 326}
316 327
317MCBTYPE callback_call_started ( MCBARGS ) 328MCBTYPE callback_call_started ( MCBARGS )
318{ 329{
319 msi_session_t* _session = _arg; 330 msi_session_t *_session = _arg;
320 if ( !phone_startmedia_loop(_session->_agent_handler) ){ 331
332 if ( !phone_startmedia_loop(_session->_agent_handler) ) {
321 INFO("Starting call failed!"); 333 INFO("Starting call failed!");
322 } else { 334 } else {
323 INFO ("Call started! ( press h to hangup )"); 335 INFO ("Call started! ( press h to hangup )");
@@ -334,21 +346,26 @@ MCBTYPE callback_call_rejected ( MCBARGS )
334} 346}
335MCBTYPE callback_call_ended ( MCBARGS ) 347MCBTYPE callback_call_ended ( MCBARGS )
336{ 348{
337 349
338 msi_session_t* _session = _arg; 350 msi_session_t *_session = _arg;
339 phone_t * _phone = _session->_agent_handler; 351 phone_t *_phone = _session->_agent_handler;
340 _phone->cs->quit=1; 352 _phone->cs->quit = 1;
341 if(_phone->cs->encode_video_thread) 353
342 pthread_join(_phone->cs->encode_video_thread,NULL); 354 if (_phone->cs->encode_video_thread)
343 if(_phone->cs->encode_audio_thread) 355 pthread_join(_phone->cs->encode_video_thread, NULL);
344 pthread_join(_phone->cs->encode_audio_thread,NULL); 356
345 if(_phone->cs->decode_audio_thread) 357 if (_phone->cs->encode_audio_thread)
346 pthread_join(_phone->cs->decode_audio_thread,NULL); 358 pthread_join(_phone->cs->encode_audio_thread, NULL);
347 if(_phone->cs->decode_video_thread) 359
348 pthread_join(_phone->cs->decode_video_thread,NULL); 360 if (_phone->cs->decode_audio_thread)
361 pthread_join(_phone->cs->decode_audio_thread, NULL);
362
363 if (_phone->cs->decode_video_thread)
364 pthread_join(_phone->cs->decode_video_thread, NULL);
365
349 SDL_Quit(); 366 SDL_Quit();
350 printf("all A/V threads successfully shut down\n"); 367 printf("all A/V threads successfully shut down\n");
351 368
352 INFO ( "Call ended!" ); 369 INFO ( "Call ended!" );
353} 370}
354 371
@@ -358,10 +375,10 @@ MCBTYPE callback_requ_timeout ( MCBARGS )
358} 375}
359 376
360 377
361phone_t* initPhone(uint16_t _listen_port, uint16_t _send_port) 378phone_t *initPhone(uint16_t _listen_port, uint16_t _send_port)
362{ 379{
363 phone_t* _retu = calloc(sizeof(phone_t),1); 380 phone_t *_retu = calloc(sizeof(phone_t), 1);
364 _retu->cs = av_calloc(sizeof(codec_state),1); 381 _retu->cs = av_calloc(sizeof(codec_state), 1);
365 382
366 /* Initialize our mutex */ 383 /* Initialize our mutex */
367 pthread_mutex_init ( &_mutex, NULL ); 384 pthread_mutex_init ( &_mutex, NULL );
@@ -388,13 +405,13 @@ phone_t* initPhone(uint16_t _listen_port, uint16_t _send_port)
388 405
389 406
390 /* Initialize msi */ 407 /* Initialize msi */
391 _retu->_msi = msi_init_session ( _retu->_networking, (const uint8_t*)_USERAGENT ); 408 _retu->_msi = msi_init_session ( _retu->_networking, (const uint8_t *)_USERAGENT );
392 409
393 if ( !_retu->_msi ) { 410 if ( !_retu->_msi ) {
394 fprintf ( stderr, "msi_init_session() failed\n" ); 411 fprintf ( stderr, "msi_init_session() failed\n" );
395 return NULL; 412 return NULL;
396 } 413 }
397 414
398 /* Initiate codecs */ 415 /* Initiate codecs */
399 init_encoder(_retu->cs); 416 init_encoder(_retu->cs);
400 init_decoder(_retu->cs); 417 init_decoder(_retu->cs);
@@ -425,7 +442,7 @@ phone_t* initPhone(uint16_t _listen_port, uint16_t _send_port)
425 return _retu; 442 return _retu;
426} 443}
427 444
428pthread_t phone_startmain_loop(phone_t* _phone) 445pthread_t phone_startmain_loop(phone_t *_phone)
429{ 446{
430 int _status; 447 int _status;
431 /* Start receive thread */ 448 /* Start receive thread */
@@ -461,9 +478,9 @@ pthread_t phone_startmain_loop(phone_t* _phone)
461 return _phone_loop_thread; 478 return _phone_loop_thread;
462} 479}
463 480
464void* phone_poll ( void* _p_phone ) 481void *phone_poll ( void *_p_phone )
465{ 482{
466 phone_t* _phone = _p_phone; 483 phone_t *_phone = _p_phone;
467 484
468 int _status = SUCCESS; 485 int _status = SUCCESS;
469 486
@@ -482,121 +499,127 @@ void* phone_poll ( void* _p_phone )
482 "r (reject incoming call)\n" 499 "r (reject incoming call)\n"
483 "q (quit)\n" 500 "q (quit)\n"
484 "================================================================================" 501 "================================================================================"
485 ); 502 );
486 503
487 while ( 1 ) 504 while ( 1 ) {
488 {
489 fgets(_line, sizeof(_line), stdin); 505 fgets(_line, sizeof(_line), stdin);
490 int i; 506 int i;
507
491 for (i = 0; i < 100; i++) { 508 for (i = 0; i < 100; i++) {
492 if (_line[i] == '\n') { 509 if (_line[i] == '\n') {
493 _line[i] = '\0'; 510 _line[i] = '\0';
494 } 511 }
495 } 512 }
513
496 _len = strlen(_line); 514 _len = strlen(_line);
497 515
498 if ( !_len ){ 516 if ( !_len ) {
499 printf(" >> "); fflush(stdout); 517 printf(" >> ");
518 fflush(stdout);
500 continue; 519 continue;
501 } 520 }
502 521
503 if ( _len > 1 && _line[1] != ' ' && _line[1] != '\n' ){ 522 if ( _len > 1 && _line[1] != ' ' && _line[1] != '\n' ) {
504 INFO("Invalid input!"); 523 INFO("Invalid input!");
505 continue; 524 continue;
506 } 525 }
507 526
508 switch (_line[0]){ 527 switch (_line[0]) {
509 528
510 case 'c': 529 case 'c': {
511 { 530 if ( _phone->_msi->_call ) {
512 if ( _phone->_msi->_call ){ 531 INFO("Already in a call");
513 INFO("Already in a call"); 532 break;
514 break; 533 }
515 }
516 534
517 call_type _ctype; 535 call_type _ctype;
518 if ( _len < 11 ){
519 INFO("Invalid input; usage: c a/v 0.0.0.0");
520 break;
521 }
522 else if ( _line[2] == 'a' || _line[2] != 'v' ){ /* default and audio */
523 _ctype = type_audio;
524 }
525 else { /* video */
526 _ctype = type_video;
527 }
528 536
529 strcpy(_dest, _line + 4 ); 537 if ( _len < 11 ) {
530 _status = t_setipport(_dest, _phone->_send_port, &(_phone->_msi->_friend_id)); 538 INFO("Invalid input; usage: c a/v 0.0.0.0");
539 break;
540 } else if ( _line[2] == 'a' || _line[2] != 'v' ) { /* default and audio */
541 _ctype = type_audio;
542 } else { /* video */
543 _ctype = type_video;
544 }
545
546 strcpy(_dest, _line + 4 );
547 _status = t_setipport(_dest, _phone->_send_port, &(_phone->_msi->_friend_id));
548
549 if ( _status < 0 ) {
550 INFO("Could not resolve address!");
551 } else {
552 /* Set timeout */
553 msi_invite ( _phone->_msi, _ctype, 30 * 1000 );
554 INFO("Calling!");
555 }
556
557 t_memset((uint8_t *)_dest, '\0', 17);
531 558
532 if ( _status < 0 ){
533 INFO("Could not resolve address!");
534 } else {
535 /* Set timeout */
536 msi_invite ( _phone->_msi, _ctype, 30 * 1000 );
537 INFO("Calling!");
538 } 559 }
560 break;
539 561
540 t_memset((uint8_t*)_dest, '\0', 17); 562 case 'h': {
563 if ( !_phone->_msi->_call ) {
564 break;
565 }
566
567 msi_hangup(_phone->_msi);
568
569 INFO("Hung up...");
541 570
542 } break;
543 case 'h':
544 {
545 if ( !_phone->_msi->_call ){
546 break;
547 } 571 }
572 break;
548 573
549 msi_hangup(_phone->_msi); 574 case 'a': {
575 if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ) {
576 break;
577 }
550 578
551 INFO("Hung up..."); 579 if ( _len > 1 && _line[2] == 'v' )
580 msi_answer(_phone->_msi, type_video);
581 else
582 msi_answer(_phone->_msi, type_audio);
552 583
553 } break;
554 case 'a':
555 {
556 if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ) {
557 break;
558 } 584 }
585 break;
586
587 case 'r': {
588 if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ) {
589 break;
590 }
559 591
560 if ( _len > 1 && _line[2] == 'v' ) 592 msi_reject(_phone->_msi);
561 msi_answer(_phone->_msi, type_video); 593
562 else 594 INFO("Call Rejected...");
563 msi_answer(_phone->_msi, type_audio);
564 595
565 } break;
566 case 'r':
567 {
568 if ( _phone->_msi->_call && _phone->_msi->_call->_state != call_starting ){
569 break;
570 } 596 }
597 break;
571 598
572 msi_reject(_phone->_msi); 599 case 'q': {
600 INFO("Quitting!");
601 pthread_exit(NULL);
602 }
573 603
574 INFO("Call Rejected..."); 604 default: {
605 INFO("Invalid command!");
606 }
607 break;
575 608
576 } break;
577 case 'q':
578 {
579 INFO("Quitting!");
580 pthread_exit(NULL);
581 } 609 }
582 default:
583 {
584 INFO("Invalid command!");
585 } break;
586 610
587 } 611 usleep(1000);
588 usleep(1000);
589 } 612 }
590 613
591 pthread_exit(NULL); 614 pthread_exit(NULL);
592} 615}
593 616
594int quitPhone(phone_t* _phone) 617int quitPhone(phone_t *_phone)
595{ 618{
596 if ( _phone->_msi->_call ){ 619 if ( _phone->_msi->_call ) {
597 msi_hangup(_phone->_msi); /* Hangup the phone first */ 620 msi_hangup(_phone->_msi); /* Hangup the phone first */
598 } 621 }
599 622
600 msi_terminate_session(_phone->_msi); 623 msi_terminate_session(_phone->_msi);
601 pthread_mutex_destroy ( &_mutex ); 624 pthread_mutex_destroy ( &_mutex );
602 625
@@ -606,17 +629,17 @@ int quitPhone(phone_t* _phone)
606 629
607/* ---------------------- */ 630/* ---------------------- */
608 631
609int print_help ( const char* _name ) 632int print_help ( const char *_name )
610{ 633{
611 printf ( "Usage: %s -m (mode) -r/s ( for setting the ports on test version )\n", _name ); 634 printf ( "Usage: %s -m (mode) -r/s ( for setting the ports on test version )\n", _name );
612 return FAILURE; 635 return FAILURE;
613} 636}
614 637
615int main ( int argc, char* argv [] ) 638int main ( int argc, char *argv [] )
616{ 639{
617 arg_t* _args = parse_args ( argc, argv ); 640 arg_t *_args = parse_args ( argc, argv );
618 641
619 const char* _mode = find_arg_duble ( _args, "-m" ); 642 const char *_mode = find_arg_duble ( _args, "-m" );
620 uint16_t _listen_port; 643 uint16_t _listen_port;
621 uint16_t _send_port; 644 uint16_t _send_port;
622 645
@@ -631,9 +654,9 @@ int main ( int argc, char* argv [] )
631 _listen_port = 31000; 654 _listen_port = 31000;
632 } else return print_help ( argv[0] ); 655 } else return print_help ( argv[0] );
633 656
634 phone_t* _phone = initPhone(_listen_port, _send_port); 657 phone_t *_phone = initPhone(_listen_port, _send_port);
635 658
636 if ( _phone ){ 659 if ( _phone ) {
637 phone_startmain_loop(_phone); 660 phone_startmain_loop(_phone);
638 661
639 quitPhone(_phone); 662 quitPhone(_phone);
diff --git a/toxrtp/toxrtp.h b/toxrtp/toxrtp.h
index f6270c11..44717835 100644
--- a/toxrtp/toxrtp.h
+++ b/toxrtp/toxrtp.h
@@ -31,7 +31,7 @@
31#define RTP_VERSION 2 31#define RTP_VERSION 2
32#include <inttypes.h> 32#include <inttypes.h>
33#include "../toxcore/tox.h" 33#include "../toxcore/tox.h"
34 34#include <pthread.h>
35/* Extension header flags */ 35/* Extension header flags */
36#define RTP_EXT_TYPE_RESOLUTION 0x01 36#define RTP_EXT_TYPE_RESOLUTION 0x01
37#define RTP_EXT_TYPE_FRAMERATE 0x02 37#define RTP_EXT_TYPE_FRAMERATE 0x02
@@ -72,7 +72,7 @@ typedef struct rtp_session_s {
72 uint32_t _time_elapsed; 72 uint32_t _time_elapsed;
73 uint32_t _current_timestamp; 73 uint32_t _current_timestamp;
74 uint32_t _ssrc; 74 uint32_t _ssrc;
75 uint32_t* _csrc; 75 uint32_t *_csrc;
76 76
77 77
78 /* If some additional data must be sent via message 78 /* If some additional data must be sent via message
@@ -80,7 +80,7 @@ typedef struct rtp_session_s {
80 * automatically placing it within a message. 80 * automatically placing it within a message.
81 */ 81 */
82 82
83 struct rtp_ext_header_s* _ext_header; 83 struct rtp_ext_header_s *_ext_header;
84 /* External header identifiers */ 84 /* External header identifiers */
85 int _exthdr_resolution; 85 int _exthdr_resolution;
86 int _exthdr_framerate; 86 int _exthdr_framerate;
@@ -95,16 +95,16 @@ typedef struct rtp_session_s {
95 95
96 uint64_t _packet_loss; 96 uint64_t _packet_loss;
97 97
98 const char* _last_error; 98 const char *_last_error;
99 99
100 struct rtp_dest_list_s* _dest_list; 100 struct rtp_dest_list_s *_dest_list;
101 struct rtp_dest_list_s* _last_user; /* a tail for faster appending */ 101 struct rtp_dest_list_s *_last_user; /* a tail for faster appending */
102 102
103 struct rtp_msg_s* _oldest_msg; 103 struct rtp_msg_s *_oldest_msg;
104 struct rtp_msg_s* _last_msg; /* tail */ 104 struct rtp_msg_s *_last_msg; /* tail */
105 105
106 uint16_t _prefix_length; 106 uint16_t _prefix_length;
107 uint8_t* _prefix; 107 uint8_t *_prefix;
108 108
109 /* Specifies multiple session use. 109 /* Specifies multiple session use.
110 * When using one session it uses default value ( -1 ) 110 * When using one session it uses default value ( -1 )
@@ -125,35 +125,35 @@ typedef struct rtp_session_s {
125 */ 125 */
126 126
127 127
128void rtp_free_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg ); 128void rtp_free_msg ( rtp_session_t *_session, struct rtp_msg_s *_msg );
129int rtp_release_session_recv ( rtp_session_t* _session ); 129int rtp_release_session_recv ( rtp_session_t *_session );
130 130
131/* Functions handling receiving */ 131/* Functions handling receiving */
132struct rtp_msg_s* rtp_recv_msg ( rtp_session_t* _session ); 132struct rtp_msg_s *rtp_recv_msg ( rtp_session_t *_session );
133void rtp_store_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg ); 133void rtp_store_msg ( rtp_session_t *_session, struct rtp_msg_s *_msg );
134 134
135/* 135/*
136 * rtp_msg_parse() stores headers separately from the payload data 136 * rtp_msg_parse() stores headers separately from the payload data
137 * and so the _length variable is set accordingly 137 * and so the _length variable is set accordingly
138 */ 138 */
139struct rtp_msg_s* rtp_msg_parse ( rtp_session_t* _session, const uint8_t* _data, uint32_t _length ); 139struct rtp_msg_s *rtp_msg_parse ( rtp_session_t *_session, const uint8_t *_data, uint32_t _length );
140 140
141int rtp_check_late_message (rtp_session_t* _session, struct rtp_msg_s* _msg); 141int rtp_check_late_message (rtp_session_t *_session, struct rtp_msg_s *_msg);
142void rtp_register_msg ( rtp_session_t* _session, struct rtp_msg_s* ); 142void rtp_register_msg ( rtp_session_t *_session, struct rtp_msg_s * );
143 143
144/* Functions handling sending */ 144/* Functions handling sending */
145int rtp_send_msg ( rtp_session_t* _session, struct rtp_msg_s* _msg, void* _core_handler ); 145int rtp_send_msg ( rtp_session_t *_session, struct rtp_msg_s *_msg, void *_core_handler );
146 146
147/* 147/*
148 * rtp_msg_new() stores headers and payload data in one container ( _data ) 148 * rtp_msg_new() stores headers and payload data in one container ( _data )
149 * and the _length is set accordingly. Returned message is used for sending only 149 * and the _length is set accordingly. Returned message is used for sending only
150 * so there is not much use of the headers there 150 * so there is not much use of the headers there
151 */ 151 */
152struct rtp_msg_s* rtp_msg_new ( rtp_session_t* _session, const uint8_t* _data, uint32_t _length ); 152struct rtp_msg_s *rtp_msg_new ( rtp_session_t *_session, const uint8_t *_data, uint32_t _length );
153 153
154 154
155/* Convenient functions for creating a header */ 155/* Convenient functions for creating a header */
156struct rtp_header_s* rtp_build_header ( rtp_session_t* _session ); 156struct rtp_header_s *rtp_build_header ( rtp_session_t *_session );
157 157
158/* Functions handling session control */ 158/* Functions handling session control */
159 159
@@ -163,26 +163,26 @@ struct rtp_header_s* rtp_build_header ( rtp_session_t* _session );
163/* Session initiation and termination. 163/* Session initiation and termination.
164 * Set _multi_session to -1 if not using multiple sessions 164 * Set _multi_session to -1 if not using multiple sessions
165 */ 165 */
166rtp_session_t* rtp_init_session ( int _max_users, int _multi_session ); 166rtp_session_t *rtp_init_session ( int _max_users, int _multi_session );
167int rtp_terminate_session ( rtp_session_t* _session ); 167int rtp_terminate_session ( rtp_session_t *_session );
168 168
169/* Adding receiver */ 169/* Adding receiver */
170int rtp_add_receiver ( rtp_session_t* _session, tox_IP_Port* _dest ); 170int rtp_add_receiver ( rtp_session_t *_session, tox_IP_Port *_dest );
171 171
172/* Convenient functions for marking the resolution */ 172/* Convenient functions for marking the resolution */
173int rtp_add_resolution_marking ( rtp_session_t* _session, uint16_t _width, uint16_t _height ); 173int rtp_add_resolution_marking ( rtp_session_t *_session, uint16_t _width, uint16_t _height );
174int rtp_remove_resolution_marking ( rtp_session_t* _session ); 174int rtp_remove_resolution_marking ( rtp_session_t *_session );
175uint16_t rtp_get_resolution_marking_height ( struct rtp_ext_header_s* _header, uint32_t _position ); 175uint16_t rtp_get_resolution_marking_height ( struct rtp_ext_header_s *_header, uint32_t _position );
176uint16_t rtp_get_resolution_marking_width ( struct rtp_ext_header_s* _header, uint32_t _position ); 176uint16_t rtp_get_resolution_marking_width ( struct rtp_ext_header_s *_header, uint32_t _position );
177 177
178int rtp_add_framerate_marking ( rtp_session_t* _session, uint32_t _value ); 178int rtp_add_framerate_marking ( rtp_session_t *_session, uint32_t _value );
179int rtp_remove_framerate_marking ( rtp_session_t* _session ); 179int rtp_remove_framerate_marking ( rtp_session_t *_session );
180uint32_t rtp_get_framerate_marking ( struct rtp_ext_header_s* _header ); 180uint32_t rtp_get_framerate_marking ( struct rtp_ext_header_s *_header );
181/* Convenient functions for marking the payload */ 181/* Convenient functions for marking the payload */
182void rtp_set_payload_type ( rtp_session_t* _session, uint8_t _payload_value ); 182void rtp_set_payload_type ( rtp_session_t *_session, uint8_t _payload_value );
183uint32_t rtp_get_payload_type ( rtp_session_t* _session ); 183uint32_t rtp_get_payload_type ( rtp_session_t *_session );
184 184
185/* When using RTP in core be sure to set prefix when sending via rtp_send_msg */ 185/* When using RTP in core be sure to set prefix when sending via rtp_send_msg */
186int rtp_set_prefix ( rtp_session_t* _session, uint8_t* _prefix, uint16_t _prefix_length ); 186int rtp_set_prefix ( rtp_session_t *_session, uint8_t *_prefix, uint16_t _prefix_length );
187 187
188#endif /* _RTP__IMPL_H_ */ 188#endif /* _RTP__IMPL_H_ */
diff --git a/toxrtp/toxrtp_helper.c b/toxrtp/toxrtp_helper.c
index bb2dc56b..6f952359 100644
--- a/toxrtp/toxrtp_helper.c
+++ b/toxrtp/toxrtp_helper.c
@@ -31,7 +31,6 @@
31#include "toxrtp_helper.h" 31#include "toxrtp_helper.h"
32#include "../toxcore/network.h" 32#include "../toxcore/network.h"
33 33
34#include <arpa/inet.h> /* Fixes implicit function warning. */
35#include <assert.h> 34#include <assert.h>
36 35
37#ifdef WIN 36#ifdef WIN
@@ -41,11 +40,11 @@
41 40
42static int _seed = 0; /* Not initiated */ 41static int _seed = 0; /* Not initiated */
43 42
44int t_setipport ( const char* _ip, unsigned short _port, void* _dest ) 43int t_setipport ( const char *_ip, unsigned short _port, void *_dest )
45{ 44{
46 assert(_dest); 45 assert(_dest);
47 46
48 IP_Port* _dest_c = ( IP_Port* ) _dest; 47 IP_Port *_dest_c = ( IP_Port * ) _dest;
49 ip_init(&_dest_c->ip, 0); 48 ip_init(&_dest_c->ip, 0);
50 49
51 IP_Port _ipv6_garbage; 50 IP_Port _ipv6_garbage;
@@ -72,7 +71,7 @@ uint32_t t_random ( uint32_t _max )
72 } 71 }
73} 72}
74 73
75void t_memcpy ( uint8_t* _dest, const uint8_t* _source, size_t _size ) 74void t_memcpy ( uint8_t *_dest, const uint8_t *_source, size_t _size )
76{ 75{
77 /* 76 /*
78 * Using countdown to zero method 77 * Using countdown to zero method
@@ -87,7 +86,7 @@ void t_memcpy ( uint8_t* _dest, const uint8_t* _source, size_t _size )
87 86
88} 87}
89 88
90uint8_t* t_memset ( uint8_t* _dest, uint8_t _valu, size_t _size ) 89uint8_t *t_memset ( uint8_t *_dest, uint8_t _valu, size_t _size )
91{ 90{
92 /* 91 /*
93 * Again using countdown to zero method 92 * Again using countdown to zero method
@@ -102,9 +101,9 @@ uint8_t* t_memset ( uint8_t* _dest, uint8_t _valu, size_t _size )
102 return _dest; 101 return _dest;
103} 102}
104 103
105size_t t_memlen ( const uint8_t* _valu) 104size_t t_memlen ( const uint8_t *_valu)
106{ 105{
107 const uint8_t* _it; 106 const uint8_t *_it;
108 size_t _retu = 0; 107 size_t _retu = 0;
109 108
110 for ( _it = _valu; *_it; ++_it ) ++_retu; 109 for ( _it = _valu; *_it; ++_it ) ++_retu;
@@ -112,13 +111,13 @@ size_t t_memlen ( const uint8_t* _valu)
112 return _retu; 111 return _retu;
113} 112}
114 113
115uint8_t* t_strallcpy ( const uint8_t* _source ) /* string alloc and copy */ 114uint8_t *t_strallcpy ( const uint8_t *_source ) /* string alloc and copy */
116{ 115{
117 assert(_source); 116 assert(_source);
118 117
119 size_t _length = t_memlen(_source) + 1; /* make space for null character */ 118 size_t _length = t_memlen(_source) + 1; /* make space for null character */
120 119
121 uint8_t* _dest = calloc( sizeof ( uint8_t ), _length ); 120 uint8_t *_dest = calloc( sizeof ( uint8_t ), _length );
122 assert(_dest); 121 assert(_dest);
123 122
124 t_memcpy(_dest, _source, _length); 123 t_memcpy(_dest, _source, _length);
@@ -126,75 +125,75 @@ uint8_t* t_strallcpy ( const uint8_t* _source ) /* string alloc and copy */
126 return _dest; 125 return _dest;
127} 126}
128 127
129size_t t_strfind ( const uint8_t* _str, const uint8_t* _substr ) 128size_t t_strfind ( const uint8_t *_str, const uint8_t *_substr )
130{ 129{
131 size_t _pos = 0; 130 size_t _pos = 0;
132 size_t _it, _delit = 0; 131 size_t _it, _delit = 0;
133 132
134 for ( _it = 0; _str[_it] != '\0'; _it++ ){ 133 for ( _it = 0; _str[_it] != '\0'; _it++ ) {
135 if ( _str[_it] == _substr[_delit] ){ 134 if ( _str[_it] == _substr[_delit] ) {
136 _pos = _it; 135 _pos = _it;
137 while ( _str[_it] == _substr[_delit] && _str[_it] != '\0' ){ 136
137 while ( _str[_it] == _substr[_delit] && _str[_it] != '\0' ) {
138 _it ++; 138 _it ++;
139 _delit++; 139 _delit++;
140 140
141 if ( _substr[_delit] == '\0' ){ 141 if ( _substr[_delit] == '\0' ) {
142 return _pos; 142 return _pos;
143 } 143 }
144 } 144 }
145
145 _delit = 0; 146 _delit = 0;
146 _pos = 0; 147 _pos = 0;
147 } 148 }
148 } 149 }
150
149 return _pos; 151 return _pos;
150} 152}
151 153
152#ifdef WIN 154#ifdef WIN
153#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) 155#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
154 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 156#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
155#else 157#else
156 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL 158#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
157#endif 159#endif
158 160
159struct timezone 161struct timezone {
160{ 162 int tz_minuteswest; /* minutes W of Greenwich */
161 int tz_minuteswest; /* minutes W of Greenwich */ 163 int tz_dsttime; /* type of dst correction */
162 int tz_dsttime; /* type of dst correction */
163}; 164};
164 165
165int gettimeofday(struct timeval *tv, struct timezone *tz) 166int gettimeofday(struct timeval *tv, struct timezone *tz)
166{ 167{
167 FILETIME ft; 168 FILETIME ft;
168 unsigned __int64 tmpres = 0; 169 unsigned __int64 tmpres = 0;
169 static int tzflag; 170 static int tzflag;
170 171
171 if (NULL != tv) 172 if (NULL != tv) {
172 { 173 GetSystemTimeAsFileTime(&ft);
173 GetSystemTimeAsFileTime(&ft); 174
174 175 tmpres |= ft.dwHighDateTime;
175 tmpres |= ft.dwHighDateTime; 176 tmpres <<= 32;
176 tmpres <<= 32; 177 tmpres |= ft.dwLowDateTime;
177 tmpres |= ft.dwLowDateTime; 178
178 179 /*converting file time to unix epoch*/
179 /*converting file time to unix epoch*/ 180 tmpres -= DELTA_EPOCH_IN_MICROSECS;
180 tmpres -= DELTA_EPOCH_IN_MICROSECS; 181 tmpres /= 10; /*convert into microseconds*/
181 tmpres /= 10; /*convert into microseconds*/ 182 tv->tv_sec = (long)(tmpres / 1000000UL);
182 tv->tv_sec = (long)(tmpres / 1000000UL); 183 tv->tv_usec = (long)(tmpres % 1000000UL);
183 tv->tv_usec = (long)(tmpres % 1000000UL); 184 }
184 } 185
185 186 if (NULL != tz) {
186 if (NULL != tz) 187 if (!tzflag) {
187 { 188 _tzset();
188 if (!tzflag) 189 tzflag++;
189 { 190 }
190 _tzset(); 191
191 tzflag++; 192 tz->tz_minuteswest = _timezone / 60;
193 tz->tz_dsttime = _daylight;
192 } 194 }
193 tz->tz_minuteswest = _timezone / 60;
194 tz->tz_dsttime = _daylight;
195 }
196 195
197 return 0; 196 return 0;
198} 197}
199#endif /* WIN */ 198#endif /* WIN */
200 199