summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c62
1 files changed, 33 insertions, 29 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index ac79cde1..60fcc0ba 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -1010,7 +1010,7 @@ int new_filesender(Messenger *m, int friendnumber, uint64_t filesize, uint8_t *f
1010 uint32_t i; 1010 uint32_t i;
1011 1011
1012 for (i = 0; i < MAX_CONCURRENT_FILE_PIPES; ++i) { 1012 for (i = 0; i < MAX_CONCURRENT_FILE_PIPES; ++i) {
1013 if (m->friendlist[friendnumber].file_sending[i].status == 0) 1013 if (m->friendlist[friendnumber].file_sending[i].status == FILESTATUS_NONE)
1014 break; 1014 break;
1015 } 1015 }
1016 1016
@@ -1020,7 +1020,7 @@ int new_filesender(Messenger *m, int friendnumber, uint64_t filesize, uint8_t *f
1020 if (file_sendrequest(m, friendnumber, i, filesize, filename, filename_length) == 0) 1020 if (file_sendrequest(m, friendnumber, i, filesize, filename, filename_length) == 0)
1021 return -1; 1021 return -1;
1022 1022
1023 m->friendlist[friendnumber].file_sending[i].status = 1; 1023 m->friendlist[friendnumber].file_sending[i].status = FILESTATUS_NOT_ACCEPTED;
1024 m->friendlist[friendnumber].file_sending[i].size = filesize; 1024 m->friendlist[friendnumber].file_sending[i].size = filesize;
1025 m->friendlist[friendnumber].file_sending[i].transferred = 0; 1025 m->friendlist[friendnumber].file_sending[i].transferred = 0;
1026 return i; 1026 return i;
@@ -1041,7 +1041,7 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f
1041 if (friend_not_valid(m, friendnumber)) 1041 if (friend_not_valid(m, friendnumber))
1042 return 0; 1042 return 0;
1043 1043
1044 if (m->friendlist[friendnumber].file_receiving[filenumber].status == 0) 1044 if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE)
1045 return 0; 1045 return 0;
1046 1046
1047 if (send_receive > 1) 1047 if (send_receive > 1)
@@ -1057,31 +1057,31 @@ int file_control(Messenger *m, int friendnumber, uint8_t send_receive, uint8_t f
1057 if (send_receive == 1) 1057 if (send_receive == 1)
1058 switch (message_id) { 1058 switch (message_id) {
1059 case FILECONTROL_ACCEPT: 1059 case FILECONTROL_ACCEPT:
1060 m->friendlist[friendnumber].file_receiving[filenumber].status = 3; 1060 m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_TRANSFERRING;
1061 break; 1061 break;
1062 1062
1063 case FILECONTROL_PAUSE: 1063 case FILECONTROL_PAUSE:
1064 m->friendlist[friendnumber].file_receiving[filenumber].status = 5; 1064 m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_PAUSED_BY_US;
1065 break; 1065 break;
1066 1066
1067 case FILECONTROL_KILL: 1067 case FILECONTROL_KILL:
1068 case FILECONTROL_FINISHED: 1068 case FILECONTROL_FINISHED:
1069 m->friendlist[friendnumber].file_receiving[filenumber].status = 0; 1069 m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_NONE;
1070 break; 1070 break;
1071 } 1071 }
1072 else 1072 else
1073 switch (message_id) { 1073 switch (message_id) {
1074 case FILECONTROL_ACCEPT: 1074 case FILECONTROL_ACCEPT:
1075 m->friendlist[friendnumber].file_sending[filenumber].status = 3; 1075 m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_TRANSFERRING;
1076 break; 1076 break;
1077 1077
1078 case FILECONTROL_PAUSE: 1078 case FILECONTROL_PAUSE:
1079 m->friendlist[friendnumber].file_sending[filenumber].status = 5; 1079 m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_PAUSED_BY_US;
1080 break; 1080 break;
1081 1081
1082 case FILECONTROL_KILL: 1082 case FILECONTROL_KILL:
1083 case FILECONTROL_FINISHED: 1083 case FILECONTROL_FINISHED:
1084 m->friendlist[friendnumber].file_sending[filenumber].status = 0; 1084 m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_NONE;
1085 break; 1085 break;
1086 } 1086 }
1087 1087
@@ -1105,7 +1105,7 @@ int file_data(Messenger *m, int friendnumber, uint8_t filenumber, uint8_t *data,
1105 if (friend_not_valid(m, friendnumber)) 1105 if (friend_not_valid(m, friendnumber))
1106 return 0; 1106 return 0;
1107 1107
1108 if (m->friendlist[friendnumber].file_sending[filenumber].status != 3) 1108 if (m->friendlist[friendnumber].file_sending[filenumber].status != FILESTATUS_TRANSFERRING)
1109 return 0; 1109 return 0;
1110 1110
1111 uint8_t packet[MAX_DATA_SIZE]; 1111 uint8_t packet[MAX_DATA_SIZE];
@@ -1134,13 +1134,13 @@ uint64_t file_dataremaining(Messenger *m, int friendnumber, uint8_t filenumber,
1134 return 0; 1134 return 0;
1135 1135
1136 if (send_receive == 0) { 1136 if (send_receive == 0) {
1137 if (m->friendlist[friendnumber].file_sending[filenumber].status == 0) 1137 if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_NONE)
1138 return 0; 1138 return 0;
1139 1139
1140 return m->friendlist[friendnumber].file_sending[filenumber].size - 1140 return m->friendlist[friendnumber].file_sending[filenumber].size -
1141 m->friendlist[friendnumber].file_sending[filenumber].transferred; 1141 m->friendlist[friendnumber].file_sending[filenumber].transferred;
1142 } else { 1142 } else {
1143 if (m->friendlist[friendnumber].file_receiving[filenumber].status == 0) 1143 if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE)
1144 return 0; 1144 return 0;
1145 1145
1146 return m->friendlist[friendnumber].file_receiving[filenumber].size - 1146 return m->friendlist[friendnumber].file_receiving[filenumber].size -
@@ -1156,11 +1156,11 @@ static void break_files(Messenger *m, int friendnumber)
1156 uint32_t i; 1156 uint32_t i;
1157 1157
1158 for (i = 0; i < MAX_CONCURRENT_FILE_PIPES; ++i) { 1158 for (i = 0; i < MAX_CONCURRENT_FILE_PIPES; ++i) {
1159 if (m->friendlist[friendnumber].file_sending[i].status != 0) 1159 if (m->friendlist[friendnumber].file_sending[i].status != FILESTATUS_NONE)
1160 m->friendlist[friendnumber].file_sending[i].status = 4; 1160 m->friendlist[friendnumber].file_sending[i].status = FILESTATUS_BROKEN;
1161 1161
1162 if (m->friendlist[friendnumber].file_receiving[i].status != 0) 1162 if (m->friendlist[friendnumber].file_receiving[i].status != FILESTATUS_NONE)
1163 m->friendlist[friendnumber].file_receiving[i].status = 4; 1163 m->friendlist[friendnumber].file_receiving[i].status = FILESTATUS_BROKEN;
1164 } 1164 }
1165} 1165}
1166 1166
@@ -1172,21 +1172,21 @@ static int handle_filecontrol(Messenger *m, int friendnumber, uint8_t send_recei
1172 return -1; 1172 return -1;
1173 1173
1174 if (send_receive == 0) { 1174 if (send_receive == 0) {
1175 if (m->friendlist[friendnumber].file_receiving[filenumber].status == 0) 1175 if (m->friendlist[friendnumber].file_receiving[filenumber].status == FILESTATUS_NONE)
1176 return -1; 1176 return -1;
1177 1177
1178 switch (message_id) { 1178 switch (message_id) {
1179 case FILECONTROL_ACCEPT: 1179 case FILECONTROL_ACCEPT:
1180 if (m->friendlist[friendnumber].file_receiving[filenumber].status != 5) { 1180 if (m->friendlist[friendnumber].file_receiving[filenumber].status != FILESTATUS_PAUSED_BY_US) {
1181 m->friendlist[friendnumber].file_receiving[filenumber].status = 3; 1181 m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_TRANSFERRING;
1182 return 0; 1182 return 0;
1183 } 1183 }
1184 1184
1185 return -1; 1185 return -1;
1186 1186
1187 case FILECONTROL_PAUSE: 1187 case FILECONTROL_PAUSE:
1188 if (m->friendlist[friendnumber].file_receiving[filenumber].status != 5) { 1188 if (m->friendlist[friendnumber].file_receiving[filenumber].status != FILESTATUS_PAUSED_BY_US) {
1189 m->friendlist[friendnumber].file_receiving[filenumber].status = 2; 1189 m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_PAUSED_BY_OTHER;
1190 return 0; 1190 return 0;
1191 } 1191 }
1192 1192
@@ -1194,29 +1194,32 @@ static int handle_filecontrol(Messenger *m, int friendnumber, uint8_t send_recei
1194 1194
1195 case FILECONTROL_KILL: 1195 case FILECONTROL_KILL:
1196 case FILECONTROL_FINISHED: 1196 case FILECONTROL_FINISHED:
1197 m->friendlist[friendnumber].file_receiving[filenumber].status = 0; 1197 m->friendlist[friendnumber].file_receiving[filenumber].status = FILESTATUS_NONE;
1198 return 0; 1198 return 0;
1199 } 1199 }
1200 } else { 1200 } else {
1201 if (m->friendlist[friendnumber].file_sending[filenumber].status == 0) 1201 if (m->friendlist[friendnumber].file_sending[filenumber].status == FILESTATUS_NONE)
1202 return -1; 1202 return -1;
1203 1203
1204 switch (message_id) { 1204 switch (message_id) {
1205 case FILECONTROL_ACCEPT: 1205 case FILECONTROL_ACCEPT:
1206 if (m->friendlist[friendnumber].file_sending[filenumber].status != 5) { 1206 if (m->friendlist[friendnumber].file_sending[filenumber].status != FILESTATUS_PAUSED_BY_US) {
1207 m->friendlist[friendnumber].file_sending[filenumber].status = 3; 1207 m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_TRANSFERRING;
1208 return 0; 1208 return 0;
1209 } 1209 }
1210 1210
1211 return -1; 1211 return -1;
1212 1212
1213 case FILECONTROL_PAUSE: 1213 case FILECONTROL_PAUSE:
1214 m->friendlist[friendnumber].file_sending[filenumber].status = 2; 1214 if (m->friendlist[friendnumber].file_sending[filenumber].status != FILESTATUS_PAUSED_BY_US) {
1215 m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_PAUSED_BY_OTHER;
1216 }
1217
1215 return 0; 1218 return 0;
1216 1219
1217 case FILECONTROL_KILL: 1220 case FILECONTROL_KILL:
1218 case FILECONTROL_FINISHED: 1221 case FILECONTROL_FINISHED:
1219 m->friendlist[friendnumber].file_sending[filenumber].status = 0; 1222 m->friendlist[friendnumber].file_sending[filenumber].status = FILESTATUS_NONE;
1220 return 0; 1223 return 0;
1221 } 1224 }
1222 } 1225 }
@@ -1516,9 +1519,10 @@ void doFriends(Messenger *m)
1516 memcpy(&filesize, data + 1, sizeof(filesize)); 1519 memcpy(&filesize, data + 1, sizeof(filesize));
1517 //TODO: 1520 //TODO:
1518 //filesize = ntohll(filesize); 1521 //filesize = ntohll(filesize);
1519 m->friendlist[i].file_receiving[filenumber].status = 1; 1522 m->friendlist[i].file_receiving[filenumber].status = FILESTATUS_NOT_ACCEPTED;
1520 m->friendlist[i].file_receiving[filenumber].size = filesize; 1523 m->friendlist[i].file_receiving[filenumber].size = filesize;
1521 m->friendlist[i].file_receiving[filenumber].transferred = 0; 1524 m->friendlist[i].file_receiving[filenumber].transferred = 0;
1525
1522 if (m->file_sendrequest) 1526 if (m->file_sendrequest)
1523 (*m->file_sendrequest)(m, i, filenumber, filesize, data + 1 + sizeof(uint64_t), data_length - 1 - sizeof(uint64_t), 1527 (*m->file_sendrequest)(m, i, filenumber, filesize, data + 1 + sizeof(uint64_t), data_length - 1 - sizeof(uint64_t),
1524 m->file_sendrequest_userdata); 1528 m->file_sendrequest_userdata);
@@ -1550,7 +1554,7 @@ void doFriends(Messenger *m)
1550 1554
1551 uint8_t filenumber = data[0]; 1555 uint8_t filenumber = data[0];
1552 1556
1553 if (m->friendlist[i].file_receiving[filenumber].status == 0) 1557 if (m->friendlist[i].file_receiving[filenumber].status == FILESTATUS_NONE)
1554 break; 1558 break;
1555 1559
1556 m->friendlist[i].file_receiving[filenumber].transferred += (data_length - 1); 1560 m->friendlist[i].file_receiving[filenumber].transferred += (data_length - 1);