summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/AFC.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/src/AFC.c b/src/AFC.c
index 0a24a15..fe6fc00 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -130,7 +130,7 @@ afc_error_t afc_client_free(afc_client_t client)
130static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t length) 130static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t length)
131{ 131{
132 int bytes = 0, offset = 0; 132 int bytes = 0, offset = 0;
133 char *buffer; 133 uint32_t sent = 0;
134 134
135 if (!client || !client->connection || !client->afc_packet) 135 if (!client || !client->connection || !client->afc_packet)
136 return 0; 136 return 0;
@@ -150,8 +150,6 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l
150 // this_length is the parameters 150 // this_length is the parameters
151 // And everything beyond that is the next packet. (for writing) 151 // And everything beyond that is the next packet. (for writing)
152 if (client->afc_packet->this_length != client->afc_packet->entire_length) { 152 if (client->afc_packet->this_length != client->afc_packet->entire_length) {
153 buffer = (char *) malloc(client->afc_packet->this_length);
154 memcpy(buffer, (char *) client->afc_packet, sizeof(AFCPacket));
155 offset = client->afc_packet->this_length - sizeof(AFCPacket); 153 offset = client->afc_packet->this_length - sizeof(AFCPacket);
156 154
157 log_debug_msg("%s: Offset: %i\n", __func__, offset); 155 log_debug_msg("%s: Offset: %i\n", __func__, offset);
@@ -160,39 +158,50 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l
160 log_debug_msg("to based on the packet.\n"); 158 log_debug_msg("to based on the packet.\n");
161 log_debug_msg("%s: length minus offset: %i\n", __func__, length - offset); 159 log_debug_msg("%s: length minus offset: %i\n", __func__, length - offset);
162 log_debug_msg("%s: rest of packet: %i\n", __func__, client->afc_packet->entire_length - client->afc_packet->this_length); 160 log_debug_msg("%s: rest of packet: %i\n", __func__, client->afc_packet->entire_length - client->afc_packet->this_length);
163 free(buffer);
164 return -1; 161 return -1;
165 } 162 }
166 memcpy(buffer + sizeof(AFCPacket), data, offset); 163
167 iphone_device_send(client->connection, buffer, client->afc_packet->this_length, (uint32_t*)&bytes); 164 iphone_device_send(client->connection, (void*)client->afc_packet, sizeof(AFCPacket), &sent);
168 free(buffer); 165 if (sent == 0) {
169 if (bytes <= 0) {
170 return bytes; 166 return bytes;
171 } 167 }
168 bytes += sent;
169
170 iphone_device_send(client->connection, data, offset, &sent);
171 if (sent == 0) {
172 return bytes;
173 }
174 bytes += sent;
172 175
173 log_debug_msg("%s: sent the first now go with the second\n", __func__); 176 log_debug_msg("%s: sent the first now go with the second\n", __func__);
174 log_debug_msg("%s: Length: %i\n", __func__, length - offset); 177 log_debug_msg("%s: Length: %i\n", __func__, length - offset);
175 log_debug_msg("%s: Buffer: \n", __func__); 178 log_debug_msg("%s: Buffer: \n", __func__);
176 log_debug_buffer(data + offset, length - offset); 179 log_debug_buffer(data + offset, length - offset);
177 180
178 iphone_device_send(client->connection, data + offset, length - offset, (uint32_t*)&bytes); 181 sent = 0;
182 iphone_device_send(client->connection, data + offset, length - offset, &sent);
183
184 bytes = sent;
179 return bytes; 185 return bytes;
180 } else { 186 } else {
181 log_debug_msg("%s: doin things the old way\n", __func__); 187 log_debug_msg("%s: doin things the old way\n", __func__);
182 buffer = (char *) malloc(sizeof(char) * client->afc_packet->this_length);
183 log_debug_msg("%s: packet length = %i\n", __func__, client->afc_packet->this_length); 188 log_debug_msg("%s: packet length = %i\n", __func__, client->afc_packet->this_length);
184 memcpy(buffer, (char *) client->afc_packet, sizeof(AFCPacket)); 189
185 log_debug_msg("%s: packet data follows\n", __func__); 190 log_debug_buffer((char*)client->afc_packet, sizeof(AFCPacket));
186 if (length > 0) {
187 memcpy(buffer + sizeof(AFCPacket), data, length);
188 }
189 log_debug_buffer(buffer, client->afc_packet->this_length);
190 log_debug_msg("\n"); 191 log_debug_msg("\n");
191 iphone_device_send(client->connection, buffer, client->afc_packet->this_length, (uint32_t*)&bytes);
192 192
193 if (buffer) { 193 iphone_device_send(client->connection, (void*)client->afc_packet, sizeof(AFCPacket), &sent);
194 free(buffer); 194 if (sent == 0) {
195 buffer = NULL; 195 return bytes;
196 }
197 bytes += sent;
198 if (length > 0) {
199 log_debug_msg("%s: packet data follows\n", __func__);
200
201 log_debug_buffer(data, length);
202 log_debug_msg("\n");
203 iphone_device_send(client->connection, data, length, &sent);
204 bytes += sent;
196 } 205 }
197 return bytes; 206 return bytes;
198 } 207 }