diff options
| author | 2013-12-13 04:14:53 +0100 | |
|---|---|---|
| committer | 2013-12-13 04:14:53 +0100 | |
| commit | 3537f78a98111b88aab5e2d94dda340cf09be5af (patch) | |
| tree | c52974b3f21e0ae395256b3ebaecca66cea8177e /src/client.c | |
| parent | 4c9a8a7268d51c657d1b9b5b8334298bd6d62c9a (diff) | |
| download | usbmuxd-3537f78a98111b88aab5e2d94dda340cf09be5af.tar.gz usbmuxd-3537f78a98111b88aab5e2d94dda340cf09be5af.tar.bz2 | |
make libplist/protov1 support mandatory
Diffstat (limited to 'src/client.c')
| -rw-r--r-- | src/client.c | 32 |
1 files changed, 3 insertions, 29 deletions
diff --git a/src/client.c b/src/client.c index ac5d08e..b81c11c 100644 --- a/src/client.c +++ b/src/client.c | |||
| @@ -33,9 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |||
| 33 | #include <arpa/inet.h> | 33 | #include <arpa/inet.h> |
| 34 | #include <pthread.h> | 34 | #include <pthread.h> |
| 35 | 35 | ||
| 36 | #ifdef HAVE_PLIST | ||
| 37 | #include <plist/plist.h> | 36 | #include <plist/plist.h> |
| 38 | #endif | ||
| 39 | 37 | ||
| 40 | #include "log.h" | 38 | #include "log.h" |
| 41 | #include "usb.h" | 39 | #include "usb.h" |
| @@ -186,7 +184,6 @@ static int send_pkt(struct mux_client *client, uint32_t tag, enum usbmuxd_msgtyp | |||
| 186 | return hdr.length; | 184 | return hdr.length; |
| 187 | } | 185 | } |
| 188 | 186 | ||
| 189 | #ifdef HAVE_PLIST | ||
| 190 | static int send_plist_pkt(struct mux_client *client, uint32_t tag, plist_t plist) | 187 | static int send_plist_pkt(struct mux_client *client, uint32_t tag, plist_t plist) |
| 191 | { | 188 | { |
| 192 | int res = -1; | 189 | int res = -1; |
| @@ -201,12 +198,10 @@ static int send_plist_pkt(struct mux_client *client, uint32_t tag, plist_t plist | |||
| 201 | } | 198 | } |
| 202 | return res; | 199 | return res; |
| 203 | } | 200 | } |
| 204 | #endif | ||
| 205 | 201 | ||
| 206 | static int send_result(struct mux_client *client, uint32_t tag, uint32_t result) | 202 | static int send_result(struct mux_client *client, uint32_t tag, uint32_t result) |
| 207 | { | 203 | { |
| 208 | int res = -1; | 204 | int res = -1; |
| 209 | #ifdef HAVE_PLIST | ||
| 210 | if (client->proto_version == 1) { | 205 | if (client->proto_version == 1) { |
| 211 | /* XML plist packet */ | 206 | /* XML plist packet */ |
| 212 | plist_t dict = plist_new_dict(); | 207 | plist_t dict = plist_new_dict(); |
| @@ -214,9 +209,7 @@ static int send_result(struct mux_client *client, uint32_t tag, uint32_t result) | |||
| 214 | plist_dict_insert_item(dict, "Number", plist_new_uint(result)); | 209 | plist_dict_insert_item(dict, "Number", plist_new_uint(result)); |
| 215 | res = send_plist_pkt(client, tag, dict); | 210 | res = send_plist_pkt(client, tag, dict); |
| 216 | free(dict); | 211 | free(dict); |
| 217 | } else | 212 | } else { |
| 218 | #endif | ||
| 219 | { | ||
| 220 | /* binary packet */ | 213 | /* binary packet */ |
| 221 | res = send_pkt(client, tag, MESSAGE_RESULT, &result, sizeof(uint32_t)); | 214 | res = send_pkt(client, tag, MESSAGE_RESULT, &result, sizeof(uint32_t)); |
| 222 | } | 215 | } |
| @@ -246,7 +239,6 @@ int client_notify_connect(struct mux_client *client, enum usbmuxd_result result) | |||
| 246 | return 0; | 239 | return 0; |
| 247 | } | 240 | } |
| 248 | 241 | ||
| 249 | #ifdef HAVE_PLIST | ||
| 250 | static plist_t create_device_attached_plist(struct device_info *dev) | 242 | static plist_t create_device_attached_plist(struct device_info *dev) |
| 251 | { | 243 | { |
| 252 | plist_t dict = plist_new_dict(); | 244 | plist_t dict = plist_new_dict(); |
| @@ -292,20 +284,16 @@ static int send_device_list(struct mux_client *client, uint32_t tag) | |||
| 292 | plist_free(dict); | 284 | plist_free(dict); |
| 293 | return res; | 285 | return res; |
| 294 | } | 286 | } |
| 295 | #endif | ||
| 296 | 287 | ||
| 297 | static int notify_device_add(struct mux_client *client, struct device_info *dev) | 288 | static int notify_device_add(struct mux_client *client, struct device_info *dev) |
| 298 | { | 289 | { |
| 299 | int res = -1; | 290 | int res = -1; |
| 300 | #ifdef HAVE_PLIST | ||
| 301 | if (client->proto_version == 1) { | 291 | if (client->proto_version == 1) { |
| 302 | /* XML plist packet */ | 292 | /* XML plist packet */ |
| 303 | plist_t dict = create_device_attached_plist(dev); | 293 | plist_t dict = create_device_attached_plist(dev); |
| 304 | res = send_plist_pkt(client, 0, dict); | 294 | res = send_plist_pkt(client, 0, dict); |
| 305 | plist_free(dict); | 295 | plist_free(dict); |
| 306 | } else | 296 | } else { |
| 307 | #endif | ||
| 308 | { | ||
| 309 | /* binary packet */ | 297 | /* binary packet */ |
| 310 | struct usbmuxd_device_record dmsg; | 298 | struct usbmuxd_device_record dmsg; |
| 311 | memset(&dmsg, 0, sizeof(dmsg)); | 299 | memset(&dmsg, 0, sizeof(dmsg)); |
| @@ -322,7 +310,6 @@ static int notify_device_add(struct mux_client *client, struct device_info *dev) | |||
| 322 | static int notify_device_remove(struct mux_client *client, uint32_t device_id) | 310 | static int notify_device_remove(struct mux_client *client, uint32_t device_id) |
| 323 | { | 311 | { |
| 324 | int res = -1; | 312 | int res = -1; |
| 325 | #ifdef HAVE_PLIST | ||
| 326 | if (client->proto_version == 1) { | 313 | if (client->proto_version == 1) { |
| 327 | /* XML plist packet */ | 314 | /* XML plist packet */ |
| 328 | plist_t dict = plist_new_dict(); | 315 | plist_t dict = plist_new_dict(); |
| @@ -330,9 +317,7 @@ static int notify_device_remove(struct mux_client *client, uint32_t device_id) | |||
| 330 | plist_dict_insert_item(dict, "DeviceID", plist_new_uint(device_id)); | 317 | plist_dict_insert_item(dict, "DeviceID", plist_new_uint(device_id)); |
| 331 | res = send_plist_pkt(client, 0, dict); | 318 | res = send_plist_pkt(client, 0, dict); |
| 332 | plist_free(dict); | 319 | plist_free(dict); |
| 333 | } else | 320 | } else { |
| 334 | #endif | ||
| 335 | { | ||
| 336 | /* binary packet */ | 321 | /* binary packet */ |
| 337 | res = send_pkt(client, 0, MESSAGE_DEVICE_REMOVE, &device_id, sizeof(uint32_t)); | 322 | res = send_pkt(client, 0, MESSAGE_DEVICE_REMOVE, &device_id, sizeof(uint32_t)); |
| 338 | } | 323 | } |
| @@ -383,25 +368,17 @@ static int client_command(struct mux_client *client, struct usbmuxd_header *hdr) | |||
| 383 | return -1; | 368 | return -1; |
| 384 | } | 369 | } |
| 385 | 370 | ||
| 386 | #ifdef HAVE_PLIST | ||
| 387 | if((hdr->version != 0) && (hdr->version != 1)) { | 371 | if((hdr->version != 0) && (hdr->version != 1)) { |
| 388 | usbmuxd_log(LL_INFO, "Client %d version mismatch: expected 0 or 1, got %d", client->fd, hdr->version); | 372 | usbmuxd_log(LL_INFO, "Client %d version mismatch: expected 0 or 1, got %d", client->fd, hdr->version); |
| 389 | #else | ||
| 390 | if(hdr->version != USBMUXD_PROTOCOL_VERSION) { | ||
| 391 | usbmuxd_log(LL_INFO, "Client %d version mismatch: expected %d, got %d", client->fd, USBMUXD_PROTOCOL_VERSION, hdr->version); | ||
| 392 | #endif | ||
| 393 | send_result(client, hdr->tag, RESULT_BADVERSION); | 373 | send_result(client, hdr->tag, RESULT_BADVERSION); |
| 394 | return 0; | 374 | return 0; |
| 395 | } | 375 | } |
| 396 | 376 | ||
| 397 | struct usbmuxd_connect_request *ch; | 377 | struct usbmuxd_connect_request *ch; |
| 398 | #ifdef HAVE_PLIST | ||
| 399 | char *payload; | 378 | char *payload; |
| 400 | uint32_t payload_size; | 379 | uint32_t payload_size; |
| 401 | #endif | ||
| 402 | 380 | ||
| 403 | switch(hdr->message) { | 381 | switch(hdr->message) { |
| 404 | #ifdef HAVE_PLIST | ||
| 405 | case MESSAGE_PLIST: | 382 | case MESSAGE_PLIST: |
| 406 | client->proto_version = 1; | 383 | client->proto_version = 1; |
| 407 | payload = (char*)(hdr) + sizeof(struct usbmuxd_header); | 384 | payload = (char*)(hdr) + sizeof(struct usbmuxd_header); |
| @@ -469,12 +446,10 @@ static int client_command(struct mux_client *client, struct usbmuxd_header *hdr) | |||
| 469 | client->state = CLIENT_CONNECTING1; | 446 | client->state = CLIENT_CONNECTING1; |
| 470 | } | 447 | } |
| 471 | return 0; | 448 | return 0; |
| 472 | #ifdef HAVE_PLIST | ||
| 473 | } else if (!strcmp(message, "ListDevices")) { | 449 | } else if (!strcmp(message, "ListDevices")) { |
| 474 | if (send_device_list(client, hdr->tag) < 0) | 450 | if (send_device_list(client, hdr->tag) < 0) |
| 475 | return -1; | 451 | return -1; |
| 476 | return 0; | 452 | return 0; |
| 477 | #endif | ||
| 478 | } else { | 453 | } else { |
| 479 | usbmuxd_log(LL_ERROR, "Unexpected command '%s' received!", message); | 454 | usbmuxd_log(LL_ERROR, "Unexpected command '%s' received!", message); |
| 480 | free(message); | 455 | free(message); |
| @@ -486,7 +461,6 @@ static int client_command(struct mux_client *client, struct usbmuxd_header *hdr) | |||
| 486 | } | 461 | } |
| 487 | // should not be reached?! | 462 | // should not be reached?! |
| 488 | return -1; | 463 | return -1; |
| 489 | #endif | ||
| 490 | case MESSAGE_LISTEN: | 464 | case MESSAGE_LISTEN: |
| 491 | if(send_result(client, hdr->tag, 0) < 0) | 465 | if(send_result(client, hdr->tag, 0) < 0) |
| 492 | return -1; | 466 | return -1; |
