summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2010-01-12 16:05:52 +0100
committerGravatar Martin Szulecki2010-01-12 16:13:02 +0100
commit4a8b8455e358afd1a42f52cbf342fd6c7f9ccbbd (patch)
treec2a2f61612fb44bd8d5b2aacacff0f62ab37c3ed
parent65a88c0ba7b2327d2c6a386eee310c7044e75524 (diff)
downloadlibimobiledevice-4a8b8455e358afd1a42f52cbf342fd6c7f9ccbbd.tar.gz
libimobiledevice-4a8b8455e358afd1a42f52cbf342fd6c7f9ccbbd.tar.bz2
Remove obsoleted plist helper functions
-rw-r--r--src/iphone.c288
-rw-r--r--src/iphone.h10
2 files changed, 0 insertions, 298 deletions
diff --git a/src/iphone.c b/src/iphone.c
index 4a54848..9307b19 100644
--- a/src/iphone.c
+++ b/src/iphone.c
@@ -351,294 +351,6 @@ iphone_error_t iphone_device_recv(iphone_connection_t connection, char *data, ui
351 return IPHONE_E_UNKNOWN_ERROR; 351 return IPHONE_E_UNKNOWN_ERROR;
352} 352}
353 353
354/**
355 * Sends a plist over the given connection.
356 * Internally used generic plist send function.
357 *
358 * @param connection The connection to use for sending.
359 * Can be NULL if ssl_session is non-NULL.
360 * @param plist plist to send
361 * @param binary 1 = send binary plist, 0 = send xml plist
362 * @param ssl_session If set to NULL, the communication will be unencrypted.
363 * For encrypted communication, pass a valid and properly initialized
364 * gnutls_session_t. connection is ignored when ssl_session is non-NULL.
365 *
366 * @return IPHONE_E_SUCCESS on success, IPHONE_E_INVALID_ARG when one or more
367 * parameters are invalid, IPHONE_E_PLIST_ERROR when dict is not a valid
368 * plist, or IPHONE_E_UNKNOWN_ERROR when an unspecified error occurs.
369 */
370static iphone_error_t internal_plist_send(iphone_connection_t connection, plist_t plist, int binary, gnutls_session_t ssl_session)
371{
372 iphone_error_t res = IPHONE_E_UNKNOWN_ERROR;
373 char *content = NULL;
374 uint32_t length = 0;
375 uint32_t nlen = 0;
376 int bytes = 0;
377
378 if ((!connection && !ssl_session) || !plist) {
379 return IPHONE_E_INVALID_ARG;
380 }
381
382 if (binary) {
383 plist_to_bin(plist, &content, &length);
384 } else {
385 plist_to_xml(plist, &content, &length);
386 }
387
388 if (!content || length == 0) {
389 return IPHONE_E_PLIST_ERROR;
390 }
391
392 nlen = htonl(length);
393 log_debug_msg("%s: sending %d bytes\n", __func__, length);
394 if (ssl_session) {
395 bytes = gnutls_record_send(ssl_session, (const char*)&nlen, sizeof(nlen));
396 } else {
397 iphone_device_send(connection, (const char*)&nlen, sizeof(nlen), (uint32_t*)&bytes);
398 }
399 if (bytes == sizeof(nlen)) {
400 if (ssl_session) {
401 bytes = gnutls_record_send(ssl_session, content, length);
402 } else {
403 iphone_device_send(connection, content, length, (uint32_t*)&bytes);
404 }
405 if (bytes > 0) {
406 log_debug_msg("%s: sent %d bytes\n", __func__, bytes);
407 log_debug_buffer(content, bytes);
408 if ((uint32_t)bytes == length) {
409 res = IPHONE_E_SUCCESS;
410 } else {
411 log_debug_msg("%s: ERROR: Could not send all data (%d of %d)!\n", __func__, bytes, length);
412 }
413 }
414 }
415 if (bytes <= 0) {
416 log_debug_msg("%s: ERROR: sending to device failed.\n", __func__);
417 }
418
419 free(content);
420
421 return res;
422}
423
424/**
425 * Sends an XML plist over the given connection.
426 *
427 * @param connection The connection to send data over
428 * @param plist plist to send
429 *
430 * @return IPHONE_E_SUCCESS on success, IPHONE_E_INVALID_ARG when connection
431 * or plist is NULL, IPHONE_E_PLIST_ERROR when dict is not a valid plist,
432 * or IPHONE_E_UNKNOWN_ERROR when an unspecified error occurs.
433 */
434iphone_error_t iphone_device_send_xml_plist(iphone_connection_t connection, plist_t plist)
435{
436 return internal_plist_send(connection, plist, 0, NULL);
437}
438
439/**
440 * Sends a binary plist over the given connection.
441 *
442 * @param connection The connection to send data over
443 * @param plist plist to send
444 *
445 * @return IPHONE_E_SUCCESS on success, IPHONE_E_INVALID_ARG when connection
446 * or plist is NULL, IPHONE_E_PLIST_ERROR when dict is not a valid plist,
447 * or IPHONE_E_UNKNOWN_ERROR when an unspecified error occurs.
448 */
449iphone_error_t iphone_device_send_binary_plist(iphone_connection_t connection, plist_t plist)
450{
451 return internal_plist_send(connection, plist, 1, NULL);
452}
453
454/**
455 * Sends an encrypted XML plist.
456 *
457 * @param ssl_session Valid and properly initialized gnutls_session_t.
458 * @param plist plist to send
459 *
460 * @return IPHONE_E_SUCCESS on success, IPHONE_E_INVALID_ARG when ssl_session
461 * or plist is NULL, IPHONE_E_PLIST_ERROR when dict is not a valid plist,
462 * or IPHONE_E_UNKNOWN_ERROR when an unspecified error occurs.
463 */
464iphone_error_t iphone_device_send_encrypted_xml_plist(gnutls_session_t ssl_session, plist_t plist)
465{
466 return internal_plist_send(NULL, plist, 0, ssl_session);
467}
468
469/**
470 * Sends an encrypted binary plist.
471 *
472 * @param ssl_session Valid and properly initialized gnutls_session_t.
473 * @param plist plist to send
474 *
475 * @return IPHONE_E_SUCCESS on success, IPHONE_E_INVALID_ARG when ssl_session
476 * or plist is NULL, IPHONE_E_PLIST_ERROR when dict is not a valid plist,
477 * or IPHONE_E_UNKNOWN_ERROR when an unspecified error occurs.
478 */
479iphone_error_t iphone_device_send_encrypted_binary_plist(gnutls_session_t ssl_session, plist_t plist)
480{
481 return internal_plist_send(NULL, plist, 1, ssl_session);
482}
483
484/**
485 * Receives a plist over the given connection.
486 * Internally used generic plist send function.
487 *
488 * @param connection The connection to receive data on
489 * @param plist pointer to a plist_t that will point to the received plist
490 * upon successful return
491 * @param timeout Maximum time in milliseconds to wait for data.
492 * @param ssl_session If set to NULL, the communication will be unencrypted.
493 * For encrypted communication, pass a valid and properly initialized
494 * gnutls_session_t.
495 *
496 * @return IPHONE_E_SUCCESS on success, IPHONE_E_INVALID_ARG when connection
497 * or *plist is NULL, IPHONE_E_PLIST_ERROR when the received data cannot be
498 * converted to a plist, or IPHONE_E_UNKNOWN_ERROR when an unspecified
499 * error occurs.
500 */
501static iphone_error_t internal_plist_recv_timeout(iphone_connection_t connection, plist_t *plist, unsigned int timeout, gnutls_session_t ssl_session)
502{
503 iphone_error_t res = IPHONE_E_UNKNOWN_ERROR;
504 uint32_t pktlen = 0;
505 uint32_t bytes = 0;
506
507 if ((!connection && !ssl_session) || !plist) {
508 return IPHONE_E_INVALID_ARG;
509 }
510
511 if (ssl_session) {
512 bytes = gnutls_record_recv(ssl_session, (char*)&pktlen, sizeof(pktlen));
513 } else {
514 iphone_device_recv_timeout(connection, (char*)&pktlen, sizeof(pktlen), &bytes, timeout);
515 }
516 log_debug_msg("%s: initial read=%i\n", __func__, bytes);
517 if (bytes < 4) {
518 log_debug_msg("%s: initial read failed!\n", __func__);
519 return IPHONE_E_NOT_ENOUGH_DATA;
520 } else {
521 if ((char)pktlen == 0) { /* prevent huge buffers */
522 uint32_t curlen = 0;
523 char *content = NULL;
524 pktlen = ntohl(pktlen);
525 log_debug_msg("%s: %d bytes following\n", __func__, pktlen);
526 content = (char*)malloc(pktlen);
527
528 while (curlen < pktlen) {
529 if (ssl_session) {
530 bytes = gnutls_record_recv(ssl_session, content+curlen, pktlen-curlen);
531 } else {
532 iphone_device_recv(connection, content+curlen, pktlen-curlen, &bytes);
533 }
534 if (bytes <= 0) {
535 res = IPHONE_E_UNKNOWN_ERROR;
536 break;
537 }
538 log_debug_msg("%s: received %d bytes\n", __func__, bytes);
539 curlen += bytes;
540 }
541 log_debug_buffer(content, pktlen);
542 if (!memcmp(content, "bplist00", 8)) {
543 plist_from_bin(content, pktlen, plist);
544 } else {
545 plist_from_xml(content, pktlen, plist);
546 }
547 if (*plist) {
548 res = IPHONE_E_SUCCESS;
549 } else {
550 res = IPHONE_E_PLIST_ERROR;
551 }
552 free(content);
553 content = NULL;
554 } else {
555 res = IPHONE_E_UNKNOWN_ERROR;
556 }
557 }
558 return res;
559}
560
561/**
562 * Receives a plist over the given connection with specified timeout.
563 * Binary or XML plists are automatically handled.
564 *
565 * @param connection The connection to receive data on
566 * @param plist pointer to a plist_t that will point to the received plist
567 * upon successful return
568 * @param timeout Maximum time in milliseconds to wait for data.
569 *
570 * @return IPHONE_E_SUCCESS on success, IPHONE_E_INVALID_ARG when connection
571 * or *plist is NULL, IPHONE_E_PLIST_ERROR when the received data cannot be
572 * converted to a plist, or IPHONE_E_UNKNOWN_ERROR when an unspecified
573 * error occurs.
574 */
575iphone_error_t iphone_device_receive_plist_with_timeout(iphone_connection_t connection, plist_t *plist, unsigned int timeout)
576{
577 return internal_plist_recv_timeout(connection, plist, timeout, NULL);
578}
579
580/**
581 * Receives a plist over the given connection.
582 * Binary or XML plists are automatically handled.
583 *
584 * This function is like iphone_device_receive_plist_with_timeout
585 * using a timeout of 10 seconds.
586 * @see iphone_device_receive_plist_with_timeout
587 *
588 * @param connection The connection to receive data on
589 * @param plist pointer to a plist_t that will point to the received plist
590 * upon successful return
591 *
592 * @return IPHONE_E_SUCCESS on success, IPHONE_E_INVALID_ARG when connection
593 * or *plist is NULL, IPHONE_E_PLIST_ERROR when the received data cannot be
594 * converted to a plist, or IPHONE_E_UNKNOWN_ERROR when an unspecified
595 * error occurs.
596 */
597iphone_error_t iphone_device_receive_plist(iphone_connection_t connection, plist_t *plist)
598{
599 return internal_plist_recv_timeout(connection, plist, 10000, NULL);
600}
601
602/**
603 * Receives an encrypted plist with specified timeout.
604 * Binary or XML plists are automatically handled.
605 *
606 * @param ssl_session Valid and properly initialized gnutls_session_t.
607 * @param plist pointer to a plist_t that will point to the received plist
608 * upon successful return
609 * @param timeout Maximum time in milliseconds to wait for data.
610 *
611 * @return IPHONE_E_SUCCESS on success, IPHONE_E_INVALID_ARG when ssl_session
612 * or *plist is NULL, IPHONE_E_PLIST_ERROR when the received data cannot be
613 * converted to a plist, or IPHONE_E_UNKNOWN_ERROR when an unspecified
614 * error occurs.
615 */
616iphone_error_t iphone_device_receive_encrypted_plist_with_timeout(gnutls_session_t ssl_session, plist_t *plist, unsigned int timeout)
617{
618 return internal_plist_recv_timeout(NULL, plist, timeout, ssl_session);
619}
620
621/**
622 * Receives an encrypted plist.
623 * Binary or XML plists are automatically handled.
624 * This function is like iphone_device_receive_encrypted_plist_with_timeout
625 * with a timeout value of 10 seconds.
626 *
627 * @param ssl_session Valid and properly initialized gnutls_session_t.
628 * @param connection The connection to receive data on
629 * @param plist pointer to a plist_t that will point to the received plist
630 * upon successful return
631 *
632 * @return IPHONE_E_SUCCESS on success, IPHONE_E_INVALID_ARG when ssl_session
633 * or *plist is NULL, IPHONE_E_PLIST_ERROR when the received data cannot be
634 * converted to a plist, or IPHONE_E_UNKNOWN_ERROR when an unspecified
635 * error occurs.
636 */
637iphone_error_t iphone_device_receive_encrypted_plist(gnutls_session_t ssl_session, plist_t *plist)
638{
639 return internal_plist_recv_timeout(NULL, plist, 10000, ssl_session);
640}
641
642iphone_error_t iphone_device_get_handle(iphone_device_t device, uint32_t *handle) 354iphone_error_t iphone_device_get_handle(iphone_device_t device, uint32_t *handle)
643{ 355{
644 if (!device) 356 if (!device)
diff --git a/src/iphone.h b/src/iphone.h
index 7ffc811..51f9c9d 100644
--- a/src/iphone.h
+++ b/src/iphone.h
@@ -41,14 +41,4 @@ struct iphone_device_int {
41 void *conn_data; 41 void *conn_data;
42}; 42};
43 43
44iphone_error_t iphone_device_send_xml_plist(iphone_connection_t connection, plist_t plist);
45iphone_error_t iphone_device_send_binary_plist(iphone_connection_t connection, plist_t plist);
46iphone_error_t iphone_device_send_encrypted_xml_plist(gnutls_session_t ssl_session, plist_t plist);
47iphone_error_t iphone_device_send_encrypted_binary_plist(gnutls_session_t ssl_session, plist_t plist);
48
49iphone_error_t iphone_device_receive_plist_with_timeout(iphone_connection_t connection, plist_t *plist, unsigned int timeout);
50iphone_error_t iphone_device_receive_plist(iphone_connection_t connection, plist_t *plist);
51iphone_error_t iphone_device_receive_encrypted_plist_with_timeout(gnutls_session_t ssl_session, plist_t *plist, unsigned int timeout);
52iphone_error_t iphone_device_receive_encrypted_plist(gnutls_session_t ssl_session, plist_t *plist);
53
54#endif 44#endif