summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-12-07 18:13:21 +0100
committerGravatar Matt Colyer2009-12-07 19:45:07 -0800
commitea45a41a7987ab1d05e2160ce831d2fcff695077 (patch)
tree882e6070ec9703f87dc7b6d0117b30a2e712b99f /src
parent213025d04ae8788be393b63e245f2805386f7f8a (diff)
downloadlibimobiledevice-ea45a41a7987ab1d05e2160ce831d2fcff695077.tar.gz
libimobiledevice-ea45a41a7987ab1d05e2160ce831d2fcff695077.tar.bz2
better handling of session_id
This will change session_id out of the lockdownd_client_int struct to a pointer instead of using a buffer of fixed size. The session_id is allocated anyway by libplist when reading it from the plist received from the device, so why don't just use it? [#94 state:resolved] Signed-off-by: Matt Colyer <matt@colyer.name>
Diffstat (limited to 'src')
-rw-r--r--src/lockdown.c47
-rw-r--r--src/lockdown.h2
2 files changed, 27 insertions, 22 deletions
diff --git a/src/lockdown.c b/src/lockdown.c
index afca410..6bf4c84 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -120,13 +120,18 @@ lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client)
if (!client)
return LOCKDOWN_E_INVALID_ARG;
+ if (!client->session_id) {
+ log_dbg_msg(DBGMASK_LOCKDOWND, "%s: no session_id given, cannot stop session\n", __func__);
+ return LOCKDOWN_E_INVALID_ARG;
+ }
+
lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
plist_t dict = plist_new_dict();
plist_dict_insert_item(dict,"Request", plist_new_string("StopSession"));
plist_dict_insert_item(dict,"SessionID", plist_new_string(client->session_id));
- log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__);
+ log_dbg_msg(DBGMASK_LOCKDOWND, "%s: stopping session %s\n", __func__, client->session_id);
ret = lockdownd_send(client, dict);
@@ -148,6 +153,9 @@ lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client)
plist_free(dict);
dict = NULL;
+ free(client->session_id);
+ client->session_id = NULL;
+
return ret;
}
@@ -209,6 +217,10 @@ lockdownd_error_t lockdownd_client_free(lockdownd_client_t client)
}
}
+ if (client->session_id) {
+ free(client->session_id);
+ }
+
free(client);
return ret;
}
@@ -642,6 +654,7 @@ lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_
client_loc->ssl_session = NULL;
client_loc->ssl_certificate = NULL;
client_loc->in_SSL = 0;
+ client_loc->session_id = NULL;
if (LOCKDOWN_E_SUCCESS != lockdownd_query_type(client_loc)) {
log_debug_msg("%s: QueryType failed in the lockdownd client.\n", __func__);
@@ -985,7 +998,10 @@ lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const c
uint32_t return_me = 0;
lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
- client->session_id[0] = '\0';
+ if (client->session_id) {
+ free(client->session_id);
+ client->session_id = NULL;
+ }
/* Setup DevicePublicKey request plist */
dict = plist_new_dict();
@@ -1100,27 +1116,16 @@ lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const c
ret = LOCKDOWN_E_SUCCESS;
}
}
- /* store session id */
+ /* store session id, we need it for StopSession */
plist_t session_node = plist_dict_get_item(dict, "SessionID");
- if (session_node) {
-
- plist_type session_node_type = plist_get_node_type(session_node);
-
- if (session_node_type == PLIST_STRING) {
-
- char *session_id = NULL;
- plist_get_string_val(session_node, &session_id);
-
- if (session_node_type == PLIST_STRING && session_id) {
- /* we need to store the session ID for StopSession */
- strcpy(client->session_id, session_id);
- log_dbg_msg(DBGMASK_LOCKDOWND, "%s: SessionID: %s\n", __func__, client->session_id);
- }
- if (session_id)
- free(session_id);
- }
- } else
+ if (session_node && (plist_get_node_type(session_node) == PLIST_STRING)) {
+ plist_get_string_val(session_node, &client->session_id);
+ }
+ if (client->session_id) {
+ log_dbg_msg(DBGMASK_LOCKDOWND, "%s: SessionID: %s\n", __func__, client->session_id);
+ } else {
log_dbg_msg(DBGMASK_LOCKDOWND, "%s: Failed to get SessionID!\n", __func__);
+ }
plist_free(dict);
dict = NULL;
diff --git a/src/lockdown.h b/src/lockdown.h
index 9312867..49b467f 100644
--- a/src/lockdown.h
+++ b/src/lockdown.h
@@ -32,7 +32,7 @@ struct lockdownd_client_int {
gnutls_session_t ssl_session;
gnutls_certificate_credentials_t ssl_certificate;
int in_SSL;
- char session_id[40];
+ char *session_id;
};
lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key);