notification_proxy: Make np_observe_notifications() atomic

Otherwise the notification callback might fire before all notifications that should be observed have been
registered. This way the callback will only be called after _all_ notifications have been registered.
diff --git a/src/notification_proxy.c b/src/notification_proxy.c
index 3015ed9..cd8e64c 100644
--- a/src/notification_proxy.c
+++ b/src/notification_proxy.c
@@ -186,13 +186,8 @@
 	return res;
 }
 
-LIBIMOBILEDEVICE_API np_error_t np_observe_notification( np_client_t client, const char *notification )
+static np_error_t internal_np_observe_notification(np_client_t client, const char *notification)
 {
-	if (!client || !notification) {
-		return NP_E_INVALID_ARG;
-	}
-	np_lock(client);
-
 	plist_t dict = plist_new_dict();
 	plist_dict_set_item(dict,"Command", plist_new_string("ObserveNotification"));
 	plist_dict_set_item(dict,"Name", plist_new_string(notification));
@@ -203,6 +198,16 @@
 	}
 	plist_free(dict);
 
+	return res;
+}
+
+LIBIMOBILEDEVICE_API np_error_t np_observe_notification( np_client_t client, const char *notification )
+{
+	if (!client || !notification) {
+		return NP_E_INVALID_ARG;
+	}
+	np_lock(client);
+	np_error_t res = internal_np_observe_notification(client, notification);
 	np_unlock(client);
 	return res;
 }
@@ -221,13 +226,15 @@
 		return NP_E_INVALID_ARG;
 	}
 
+	np_lock(client);
 	while (notifications[i]) {
-		res = np_observe_notification(client, notifications[i]);
+		res = internal_np_observe_notification(client, notifications[i]);
 		if (res != NP_E_SUCCESS) {
 			break;
 		}
 		i++;
 	}
+	np_unlock(client);
 
 	return res;
 }