summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/libimobiledevice/lockdown.h9
-rw-r--r--src/lockdown.c146
2 files changed, 93 insertions, 62 deletions
diff --git a/include/libimobiledevice/lockdown.h b/include/libimobiledevice/lockdown.h
index b5c126c..d0ab037 100644
--- a/include/libimobiledevice/lockdown.h
+++ b/include/libimobiledevice/lockdown.h
@@ -464,6 +464,15 @@ lockdownd_error_t lockdownd_data_classes_free(char **classes);
464 */ 464 */
465lockdownd_error_t lockdownd_service_descriptor_free(lockdownd_service_descriptor_t service); 465lockdownd_error_t lockdownd_service_descriptor_free(lockdownd_service_descriptor_t service);
466 466
467/**
468 * Gets a readable error string for a given lockdown error code.
469 *
470 * @params err A lockdownd error code
471 *
472 * @returns A readable error string
473 */
474const char* lockdownd_strerror(lockdownd_error_t err);
475
467#ifdef __cplusplus 476#ifdef __cplusplus
468} 477}
469#endif 478#endif
diff --git a/src/lockdown.c b/src/lockdown.c
index 694fb47..0f6b93d 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -57,6 +57,46 @@
57#define sleep(x) Sleep(x*1000) 57#define sleep(x) Sleep(x*1000)
58#endif 58#endif
59 59
60struct st_lockdownd_error_str_map {
61 const char *lockdown_errstr;
62 const char *errstr;
63 lockdownd_error_t errcode;
64};
65
66static struct st_lockdownd_error_str_map lockdownd_error_str_map[] = {
67 { "InvalidResponse", "Invalid response", LOCKDOWN_E_INVALID_RESPONSE },
68 { "MissingKey", "Missing key", LOCKDOWN_E_MISSING_KEY },
69 { "MissingValue", "Missing value", LOCKDOWN_E_MISSING_VALUE },
70 { "GetProhibited", "Get value prohibited", LOCKDOWN_E_GET_PROHIBITED },
71 { "SetProhibited", "Set value prohibited", LOCKDOWN_E_SET_PROHIBITED },
72 { "RemoveProhibited", "Remove value prohibited", LOCKDOWN_E_REMOVE_PROHIBITED },
73 { "ImmutableValue", "Immutable value", LOCKDOWN_E_IMMUTABLE_VALUE },
74 { "PasswordProtected", "Password protected", LOCKDOWN_E_PASSWORD_PROTECTED },
75 { "UserDeniedPairing", "User denied pairing", LOCKDOWN_E_USER_DENIED_PAIRING },
76 { "PairingDialogResponsePending", "Pairing dialog response pending", LOCKDOWN_E_PAIRING_DIALOG_RESPONSE_PENDING },
77 { "MissingHostID", "Missing HostID", LOCKDOWN_E_MISSING_HOST_ID },
78 { "InvalidHostID", "Invalid HostID", LOCKDOWN_E_INVALID_HOST_ID },
79 { "SessionActive", "Session active", LOCKDOWN_E_SESSION_ACTIVE },
80 { "SessionInactive", "Session inactive", LOCKDOWN_E_SESSION_INACTIVE },
81 { "MissingSessionID", "Missing session ID", LOCKDOWN_E_MISSING_SESSION_ID },
82 { "InvalidSessionID", "Invalid session ID", LOCKDOWN_E_INVALID_SESSION_ID },
83 { "MissingService", "Missing service", LOCKDOWN_E_MISSING_SERVICE },
84 { "InvalidService", "Invalid service", LOCKDOWN_E_INVALID_SERVICE },
85 { "ServiceLimit", "Service limit reached", LOCKDOWN_E_SERVICE_LIMIT },
86 { "MissingPairRecord", "Missing pair record", LOCKDOWN_E_MISSING_PAIR_RECORD },
87 { "SavePairRecordFailed", "Saving pair record failed", LOCKDOWN_E_SAVE_PAIR_RECORD_FAILED },
88 { "InvalidPairRecord", "Invalid pair record", LOCKDOWN_E_INVALID_PAIR_RECORD },
89 { "InvalidActivationRecord", "Invalid activation record", LOCKDOWN_E_INVALID_ACTIVATION_RECORD },
90 { "MissingActivationRecord", "Missing activation record", LOCKDOWN_E_MISSING_ACTIVATION_RECORD },
91 { "ServiceProhibited", "Service prohibited", LOCKDOWN_E_SERVICE_PROHIBITED },
92 { "EscrowLocked", "Escrow lockded", LOCKDOWN_E_ESCROW_LOCKED },
93 { "PairingProhibitedOverThisConnection", "Pairing prohibited over this connection", LOCKDOWN_E_PAIRING_PROHIBITED_OVER_THIS_CONNECTION },
94 { "FMiPProtected", "Find My iPhone/iPod/iPad protected", LOCKDOWN_E_FMIP_PROTECTED },
95 { "MCProtected", "MC protected" , LOCKDOWN_E_MC_PROTECTED },
96 { "MCChallengeRequired", "MC challenge required", LOCKDOWN_E_MC_CHALLENGE_REQUIRED },
97 { NULL, NULL, 0 }
98};
99
60/** 100/**
61 * Convert an error string identifier to a lockdownd_error_t value. 101 * Convert an error string identifier to a lockdownd_error_t value.
62 * Used internally to get correct error codes from a response. 102 * Used internally to get correct error codes from a response.
@@ -69,69 +109,13 @@
69static lockdownd_error_t lockdownd_strtoerr(const char* name) 109static lockdownd_error_t lockdownd_strtoerr(const char* name)
70{ 110{
71 lockdownd_error_t err = LOCKDOWN_E_UNKNOWN_ERROR; 111 lockdownd_error_t err = LOCKDOWN_E_UNKNOWN_ERROR;
72 112 int i = 0;
73 if (strcmp(name, "InvalidResponse") == 0) { 113 while (lockdownd_error_str_map[i].lockdown_errstr) {
74 err = LOCKDOWN_E_INVALID_RESPONSE; 114 if (strcmp(lockdownd_error_str_map[i].lockdown_errstr, name) == 0) {
75 } else if (strcmp(name, "MissingKey") == 0) { 115 return lockdownd_error_str_map[i].errcode;
76 err = LOCKDOWN_E_MISSING_KEY; 116 }
77 } else if (strcmp(name, "MissingValue") == 0) { 117 i++;
78 err = LOCKDOWN_E_MISSING_VALUE;
79 } else if (strcmp(name, "GetProhibited") == 0) {
80 err = LOCKDOWN_E_GET_PROHIBITED;
81 } else if (strcmp(name, "SetProhibited") == 0) {
82 err = LOCKDOWN_E_SET_PROHIBITED;
83 } else if (strcmp(name, "RemoveProhibited") == 0) {
84 err = LOCKDOWN_E_REMOVE_PROHIBITED;
85 } else if (strcmp(name, "ImmutableValue") == 0) {
86 err = LOCKDOWN_E_IMMUTABLE_VALUE;
87 } else if (strcmp(name, "PasswordProtected") == 0) {
88 err = LOCKDOWN_E_PASSWORD_PROTECTED;
89 } else if (strcmp(name, "UserDeniedPairing") == 0) {
90 err = LOCKDOWN_E_USER_DENIED_PAIRING;
91 } else if (strcmp(name, "PairingDialogResponsePending") == 0) {
92 err = LOCKDOWN_E_PAIRING_DIALOG_RESPONSE_PENDING;
93 } else if (strcmp(name, "MissingHostID") == 0) {
94 err = LOCKDOWN_E_MISSING_HOST_ID;
95 } else if (strcmp(name, "InvalidHostID") == 0) {
96 err = LOCKDOWN_E_INVALID_HOST_ID;
97 } else if (strcmp(name, "SessionActive") == 0) {
98 err = LOCKDOWN_E_SESSION_ACTIVE;
99 } else if (strcmp(name, "SessionInactive") == 0) {
100 err = LOCKDOWN_E_SESSION_INACTIVE;
101 } else if (strcmp(name, "MissingSessionID") == 0) {
102 err = LOCKDOWN_E_MISSING_SESSION_ID;
103 } else if (strcmp(name, "InvalidSessionID") == 0) {
104 err = LOCKDOWN_E_INVALID_SESSION_ID;
105 } else if (strcmp(name, "MissingService") == 0) {
106 err = LOCKDOWN_E_MISSING_SERVICE;
107 } else if (strcmp(name, "InvalidService") == 0) {
108 err = LOCKDOWN_E_INVALID_SERVICE;
109 } else if (strcmp(name, "ServiceLimit") == 0) {
110 err = LOCKDOWN_E_SERVICE_LIMIT;
111 } else if (strcmp(name, "MissingPairRecord") == 0) {
112 err = LOCKDOWN_E_MISSING_PAIR_RECORD;
113 } else if (strcmp(name, "SavePairRecordFailed") == 0) {
114 err = LOCKDOWN_E_SAVE_PAIR_RECORD_FAILED;
115 } else if (strcmp(name, "InvalidPairRecord") == 0) {
116 err = LOCKDOWN_E_INVALID_PAIR_RECORD;
117 } else if (strcmp(name, "InvalidActivationRecord") == 0) {
118 err = LOCKDOWN_E_INVALID_ACTIVATION_RECORD;
119 } else if (strcmp(name, "MissingActivationRecord") == 0) {
120 err = LOCKDOWN_E_MISSING_ACTIVATION_RECORD;
121 } else if (strcmp(name, "ServiceProhibited") == 0) {
122 err = LOCKDOWN_E_SERVICE_PROHIBITED;
123 } else if (strcmp(name, "EscrowLocked") == 0) {
124 err = LOCKDOWN_E_ESCROW_LOCKED;
125 } else if (strcmp(name, "PairingProhibitedOverThisConnection") == 0) {
126 err = LOCKDOWN_E_PAIRING_PROHIBITED_OVER_THIS_CONNECTION;
127 } else if (strcmp(name, "FMiPProtected") == 0) {
128 err = LOCKDOWN_E_FMIP_PROTECTED;
129 } else if (strcmp(name, "MCProtected") == 0) {
130 err = LOCKDOWN_E_MC_PROTECTED;
131 } else if (strcmp(name, "MCChallengeRequired") == 0) {
132 err = LOCKDOWN_E_MC_CHALLENGE_REQUIRED;
133 } 118 }
134
135 return err; 119 return err;
136} 120}
137 121
@@ -1541,3 +1525,41 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_service_descriptor_free(lockdow
1541 1525
1542 return LOCKDOWN_E_SUCCESS; 1526 return LOCKDOWN_E_SUCCESS;
1543} 1527}
1528
1529LIBIMOBILEDEVICE_API const char* lockdownd_strerror(lockdownd_error_t err)
1530{
1531 switch (err) {
1532 case LOCKDOWN_E_SUCCESS:
1533 return "Success";
1534 case LOCKDOWN_E_INVALID_ARG:
1535 return "Invalid argument";
1536 case LOCKDOWN_E_INVALID_CONF:
1537 return "Invalid configuration";
1538 case LOCKDOWN_E_PLIST_ERROR:
1539 return "PropertyList error";
1540 case LOCKDOWN_E_PAIRING_FAILED:
1541 return "Pairing failed";
1542 case LOCKDOWN_E_SSL_ERROR:
1543 return "SSL error";
1544 case LOCKDOWN_E_DICT_ERROR:
1545 return "Invalid dictionary";
1546 case LOCKDOWN_E_RECEIVE_TIMEOUT:
1547 return "Receive timeout";
1548 case LOCKDOWN_E_MUX_ERROR:
1549 return "Mux error";
1550 case LOCKDOWN_E_NO_RUNNING_SESSION:
1551 return "No running session";
1552 case LOCKDOWN_E_UNKNOWN_ERROR:
1553 return "Unknown Error";
1554 default: {
1555 int i = 0;
1556 while (lockdownd_error_str_map[i].lockdown_errstr) {
1557 if (lockdownd_error_str_map[i].errcode == err) {
1558 return lockdownd_error_str_map[i].errstr;
1559 }
1560 i++;
1561 }
1562 } break;
1563 }
1564 return "Unknown Error";
1565}