summaryrefslogtreecommitdiffstats
path: root/src/NotificationProxy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/NotificationProxy.c')
-rw-r--r--src/NotificationProxy.c98
1 files changed, 41 insertions, 57 deletions
diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c
index e2c1faa..e994c16 100644
--- a/src/NotificationProxy.c
+++ b/src/NotificationProxy.c
@@ -27,8 +27,8 @@
#include <plist/plist.h>
#include "NotificationProxy.h"
-#include "iphone.h"
-#include "utils.h"
+#include "property_list_service.h"
+#include "debug.h"
struct np_thread {
np_client_t client;
@@ -41,7 +41,7 @@ struct np_thread {
*/
static void np_lock(np_client_t client)
{
- log_debug_msg("NP: Locked\n");
+ debug_info("NP: Locked");
g_mutex_lock(client->mutex);
}
@@ -51,29 +51,30 @@ static void np_lock(np_client_t client)
*/
static void np_unlock(np_client_t client)
{
- log_debug_msg("NP: Unlocked\n");
+ debug_info("NP: Unlocked");
g_mutex_unlock(client->mutex);
}
/**
- * Convert an iphone_error_t value to an np_error_t value.
- * Used internally to get correct error codes when using plist helper
- * functions.
+ * Convert a property_list_service_error_t value to an np_error_t value.
+ * Used internally to get correct error codes.
*
- * @param err An iphone_error_t error code
+ * @param err A property_list_service_error_t error code
*
* @return A matching np_error_t error code,
* NP_E_UNKNOWN_ERROR otherwise.
*/
-static np_error_t iphone_to_np_error(iphone_error_t err)
+static np_error_t np_error(property_list_service_error_t err)
{
switch (err) {
- case IPHONE_E_SUCCESS:
+ case PROPERTY_LIST_SERVICE_E_SUCCESS:
return NP_E_SUCCESS;
- case IPHONE_E_INVALID_ARG:
+ case PROPERTY_LIST_SERVICE_E_INVALID_ARG:
return NP_E_INVALID_ARG;
- case IPHONE_E_PLIST_ERROR:
+ case PROPERTY_LIST_SERVICE_E_PLIST_ERROR:
return NP_E_PLIST_ERROR;
+ case PROPERTY_LIST_SERVICE_E_MUX_ERROR:
+ return NP_E_CONN_FAILED;
default:
break;
}
@@ -83,7 +84,7 @@ static np_error_t iphone_to_np_error(iphone_error_t err)
/** Makes a connection to the NP service on the phone.
*
* @param device The device to connect to.
- * @param dst_port Destination port (usually given by lockdownd_start_service).
+ * @param port Destination port (usually given by lockdownd_start_service).
* @param client Pointer that will be set to a newly allocated np_client_t
* upon successful return.
*
@@ -91,7 +92,7 @@ static np_error_t iphone_to_np_error(iphone_error_t err)
* or NP_E_CONN_FAILED when the connection to the device could not be
* established.
*/
-np_error_t np_client_new(iphone_device_t device, int dst_port, np_client_t *client)
+np_error_t np_client_new(iphone_device_t device, uint16_t port, np_client_t *client)
{
/* makes sure thread environment is available */
if (!g_thread_supported())
@@ -100,14 +101,13 @@ np_error_t np_client_new(iphone_device_t device, int dst_port, np_client_t *clie
if (!device)
return NP_E_INVALID_ARG;
- /* Attempt connection */
- iphone_connection_t connection = NULL;
- if (iphone_device_connect(device, dst_port, &connection) != IPHONE_E_SUCCESS) {
+ property_list_service_client_t plistclient = NULL;
+ if (property_list_service_client_new(device, port, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) {
return NP_E_CONN_FAILED;
}
np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_int));
- client_loc->connection = connection;
+ client_loc->parent = plistclient;
client_loc->mutex = g_mutex_new();
@@ -128,10 +128,10 @@ np_error_t np_client_free(np_client_t client)
if (!client)
return NP_E_INVALID_ARG;
- iphone_device_disconnect(client->connection);
- client->connection = NULL;
+ property_list_service_client_free(client->parent);
+ client->parent = NULL;
if (client->notifier) {
- log_debug_msg("joining np callback\n");
+ debug_info("joining np callback");
g_thread_join(client->notifier);
}
if (client->mutex) {
@@ -144,10 +144,6 @@ np_error_t np_client_free(np_client_t client)
/** Sends a notification to the device's Notification Proxy.
*
- * notification messages seen so far:
- * com.apple.itunes-mobdev.syncWillStart
- * com.apple.itunes-mobdev.syncDidStart
- *
* @param client The client to send to
* @param notification The notification message to send
*
@@ -164,17 +160,17 @@ np_error_t np_post_notification(np_client_t client, const char *notification)
plist_dict_insert_item(dict,"Command", plist_new_string("PostNotification"));
plist_dict_insert_item(dict,"Name", plist_new_string(notification));
- np_error_t res = iphone_to_np_error(iphone_device_send_xml_plist(client->connection, dict));
+ np_error_t res = np_error(property_list_service_send_xml_plist(client->parent, dict));
plist_free(dict);
dict = plist_new_dict();
plist_dict_insert_item(dict,"Command", plist_new_string("Shutdown"));
- res = iphone_to_np_error(iphone_device_send_xml_plist(client->connection, dict));
+ res = np_error(property_list_service_send_xml_plist(client->parent, dict));
plist_free(dict);
if (res != NP_E_SUCCESS) {
- log_debug_msg("%s: Error sending XML plist to device!\n", __func__);
+ debug_info("Error sending XML plist to device!");
}
np_unlock(client);
@@ -200,9 +196,9 @@ np_error_t np_observe_notification( np_client_t client, const char *notification
plist_dict_insert_item(dict,"Command", plist_new_string("ObserveNotification"));
plist_dict_insert_item(dict,"Name", plist_new_string(notification));
- np_error_t res = iphone_to_np_error(iphone_device_send_xml_plist(client->connection, dict));
+ np_error_t res = np_error(property_list_service_send_xml_plist(client->parent, dict));
if (res != NP_E_SUCCESS) {
- log_debug_msg("%s: Error sending XML plist to device!\n", __func__);
+ debug_info("Error sending XML plist to device!");
}
plist_free(dict);
@@ -212,22 +208,10 @@ np_error_t np_observe_notification( np_client_t client, const char *notification
/** Notifies the iphone to send a notification on specified events.
*
- * observation messages seen so far:
- * com.apple.itunes-client.syncCancelRequest
- * com.apple.itunes-client.syncSuspendRequest
- * com.apple.itunes-client.syncResumeRequest
- * com.apple.mobile.lockdown.phone_number_changed
- * com.apple.mobile.lockdown.device_name_changed
- * com.apple.springboard.attemptactivation
- * com.apple.mobile.data_sync.domain_changed
- * com.apple.mobile.application_installed
- * com.apple.mobile.application_uninstalled
- *
* @param client The client to send to
* @param notification_spec Specification of the notifications that should be
* observed. This is expected to be an array of const char* that MUST have a
- * terminating NULL entry. However this parameter can be NULL; in this case,
- * the default set of notifications will be used.
+ * terminating NULL entry.
*
* @return NP_E_SUCCESS on success, NP_E_INVALID_ARG when client is null,
* or an error returned by np_observe_notification.
@@ -243,7 +227,7 @@ np_error_t np_observe_notifications(np_client_t client, const char **notificatio
}
if (!notifications) {
- notifications = np_default_notifications;
+ return NP_E_INVALID_ARG;
}
while (notifications[i]) {
@@ -275,14 +259,14 @@ static int np_get_notification(np_client_t client, char **notification)
int res = 0;
plist_t dict = NULL;
- if (!client || !client->connection || *notification)
+ if (!client || !client->parent || *notification)
return -1;
np_lock(client);
- iphone_device_receive_plist_with_timeout(client->connection, &dict, 500);
+ property_list_service_receive_plist_with_timeout(client->parent, &dict, 500);
if (!dict) {
- log_debug_msg("NotificationProxy: no notification received!\n");
+ debug_info("NotificationProxy: no notification received!");
res = 0;
} else {
char *cmd_value = NULL;
@@ -303,14 +287,14 @@ static int np_get_notification(np_client_t client, char **notification)
res = -2;
if (name_value_node && name_value) {
*notification = name_value;
- log_debug_msg("%s: got notification %s\n", __func__, name_value);
+ debug_info("got notification %s\n", __func__, name_value);
res = 0;
}
} else if (cmd_value && !strcmp(cmd_value, "ProxyDeath")) {
- log_debug_msg("%s: ERROR: NotificationProxy died!\n", __func__);
+ debug_info("ERROR: NotificationProxy died!");
res = -1;
} else if (cmd_value) {
- log_debug_msg("%d: unknown NotificationProxy command '%s' received!\n", __func__);
+ debug_info("unknown NotificationProxy command '%s' received!", cmd_value);
res = -1;
} else {
res = -2;
@@ -337,8 +321,8 @@ gpointer np_notifier( gpointer arg )
if (!npt) return NULL;
- log_debug_msg("%s: starting callback.\n", __func__);
- while (npt->client->connection) {
+ debug_info("starting callback.");
+ while (npt->client->parent) {
np_get_notification(npt->client, &notification);
if (notification) {
npt->cbfunc(notification);
@@ -380,12 +364,12 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb
np_lock(client);
if (client->notifier) {
- log_debug_msg("%s: callback already set, removing\n");
- iphone_connection_t conn = client->connection;
- client->connection = NULL;
+ debug_info("callback already set, removing\n");
+ property_list_service_client_t parent = client->parent;
+ client->parent = NULL;
g_thread_join(client->notifier);
client->notifier = NULL;
- client->connection = conn;
+ client->parent = parent;
}
if (notify_cb) {
@@ -400,7 +384,7 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb
}
}
} else {
- log_debug_msg("%s: no callback set\n", __func__);
+ debug_info("no callback set");
}
np_unlock(client);