Skip to content

Commit

Permalink
Remove common code in favor of new libimobiledevice-glue
Browse files Browse the repository at this point in the history
  • Loading branch information
nikias committed Sep 1, 2021
1 parent c3a16f3 commit 32a8ebe
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 357 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ sudo apt-get install \
libplist-dev \
libusbmuxd-dev \
libimobiledevice-dev \
libimobiledevice-glue-dev \
libusb-1.0-0-dev \
udev
```
Expand Down Expand Up @@ -152,4 +153,4 @@ iPadOS, tvOS, watchOS, and macOS are trademarks of Apple Inc.
usbmuxd is an independent software application and has not been
authorized, sponsored, or otherwise approved by Apple Inc.

README Updated on: 2020-06-13
README Updated on: 2021-08-30
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ LT_INIT
PKG_CHECK_MODULES(libusb, libusb-1.0 >= 1.0.9)
PKG_CHECK_MODULES(libplist, libplist-2.0 >= 2.2.0)
PKG_CHECK_MODULES(libimobiledevice, libimobiledevice-1.0 >= 1.3.0, have_limd=yes, have_limd=no)
AC_CHECK_LIB(pthread, [pthread_create, pthread_mutex_lock], [AC_SUBST(libpthread_LIBS,[-lpthread])], [AC_MSG_ERROR([libpthread is required to build usbmuxd])])
PKG_CHECK_MODULES(limd_glue, libimobiledevice-glue-1.0 >= 1.0.0)

AC_ARG_WITH([preflight],
[AS_HELP_STRING([--without-preflight],
Expand Down Expand Up @@ -106,7 +106,7 @@ AC_TYPE_UINT8_T
AC_SEARCH_LIBS([clock_gettime],[rt posix4])

# Checks for library functions.
AC_CHECK_FUNCS([strcasecmp strdup strerror strndup stpcpy malloc realloc])
AC_CHECK_FUNCS([strcasecmp strdup strerror strndup malloc realloc])
AC_CHECK_FUNCS([ppoll clock_gettime localtime_r])

# Check for operating system
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ AM_CFLAGS = \
$(GLOBAL_CFLAGS) \
$(libplist_CFLAGS) \
$(libusb_CFLAGS) \
$(limd_glue_CFLAGS) \
$(libimobiledevice_CFLAGS)

AM_LDFLAGS = \
$(libplist_LIBS) \
$(libusb_LIBS) \
$(limd_glue_LIBS) \
$(libimobiledevice_LIBS) \
$(libpthread_LIBS)

Expand Down
43 changes: 22 additions & 21 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
#include <netinet/tcp.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <fcntl.h>

#include <plist/plist.h>
#include <libimobiledevice-glue/collection.h>
#include <libimobiledevice-glue/thread.h>

#include "log.h"
#include "usb.h"
Expand Down Expand Up @@ -75,7 +76,7 @@ struct mux_client {
};

static struct collection client_list;
pthread_mutex_t client_list_mutex;
mutex_t client_list_mutex;
static uint32_t client_number = 0;

#ifdef SO_PEERCRED
Expand Down Expand Up @@ -224,10 +225,10 @@ int client_accept(int listenfd)
client->events = POLLIN;
client->info = NULL;

pthread_mutex_lock(&client_list_mutex);
mutex_lock(&client_list_mutex);
client->number = client_number++;
collection_add(&client_list, client);
pthread_mutex_unlock(&client_list_mutex);
mutex_unlock(&client_list_mutex);

#ifdef SO_PEERCRED
if (log_level >= LL_INFO) {
Expand All @@ -252,7 +253,7 @@ int client_accept(int listenfd)
void client_close(struct mux_client *client)
{
int found = 0;
pthread_mutex_lock(&client_list_mutex);
mutex_lock(&client_list_mutex);
FOREACH(struct mux_client *lc, &client_list) {
if (client == lc) {
found = 1;
Expand All @@ -262,7 +263,7 @@ void client_close(struct mux_client *client)
if (!found) {
// in case we get called again but client was already freed
usbmuxd_log(LL_DEBUG, "%s: ignoring for non-existing client %p", __func__, client);
pthread_mutex_unlock(&client_list_mutex);
mutex_unlock(&client_list_mutex);
return;
}
#ifdef SO_PEERCRED
Expand Down Expand Up @@ -293,17 +294,17 @@ void client_close(struct mux_client *client)
plist_free(client->info);

collection_remove(&client_list, client);
pthread_mutex_unlock(&client_list_mutex);
mutex_unlock(&client_list_mutex);
free(client);
}

void client_get_fds(struct fdlist *list)
{
pthread_mutex_lock(&client_list_mutex);
mutex_lock(&client_list_mutex);
FOREACH(struct mux_client *client, &client_list) {
fdlist_add(list, FD_CLIENT, client->fd, client->events);
} ENDFOREACH
pthread_mutex_unlock(&client_list_mutex);
mutex_unlock(&client_list_mutex);
}

static int output_buffer_add_message(struct mux_client *client, uint32_t tag, enum usbmuxd_msgtype msg, void *payload, int payload_length)
Expand Down Expand Up @@ -442,7 +443,7 @@ static int send_listener_list(struct mux_client *client, uint32_t tag)
plist_t dict = plist_new_dict();
plist_t listeners = plist_new_array();

pthread_mutex_lock(&client_list_mutex);
mutex_lock(&client_list_mutex);
FOREACH(struct mux_client *lc, &client_list) {
if (lc->state == CLIENT_LISTEN) {
plist_t n = NULL;
Expand Down Expand Up @@ -489,7 +490,7 @@ static int send_listener_list(struct mux_client *client, uint32_t tag)
plist_array_append_item(listeners, l);
}
} ENDFOREACH
pthread_mutex_unlock(&client_list_mutex);
mutex_unlock(&client_list_mutex);

plist_dict_set_item(dict, "ListenerList", listeners);
res = send_plist(client, tag, dict);
Expand Down Expand Up @@ -975,14 +976,14 @@ static void input_buffer_process(struct mux_client *client)
void client_process(int fd, short events)
{
struct mux_client *client = NULL;
pthread_mutex_lock(&client_list_mutex);
mutex_lock(&client_list_mutex);
FOREACH(struct mux_client *lc, &client_list) {
if(lc->fd == fd) {
client = lc;
break;
}
} ENDFOREACH
pthread_mutex_unlock(&client_list_mutex);
mutex_unlock(&client_list_mutex);

if(!client) {
usbmuxd_log(LL_INFO, "client_process: fd %d not found in client list", fd);
Expand All @@ -1004,45 +1005,45 @@ void client_process(int fd, short events)

void client_device_add(struct device_info *dev)
{
pthread_mutex_lock(&client_list_mutex);
mutex_lock(&client_list_mutex);
usbmuxd_log(LL_DEBUG, "client_device_add: id %d, location 0x%x, serial %s", dev->id, dev->location, dev->serial);
device_set_visible(dev->id);
FOREACH(struct mux_client *client, &client_list) {
if(client->state == CLIENT_LISTEN)
send_device_add(client, dev);
} ENDFOREACH
pthread_mutex_unlock(&client_list_mutex);
mutex_unlock(&client_list_mutex);
}

void client_device_remove(int device_id)
{
pthread_mutex_lock(&client_list_mutex);
mutex_lock(&client_list_mutex);
uint32_t id = device_id;
usbmuxd_log(LL_DEBUG, "client_device_remove: id %d", device_id);
FOREACH(struct mux_client *client, &client_list) {
if(client->state == CLIENT_LISTEN)
send_device_remove(client, id);
} ENDFOREACH
pthread_mutex_unlock(&client_list_mutex);
mutex_unlock(&client_list_mutex);
}

void client_device_paired(int device_id)
{
pthread_mutex_lock(&client_list_mutex);
mutex_lock(&client_list_mutex);
uint32_t id = device_id;
usbmuxd_log(LL_DEBUG, "client_device_paired: id %d", device_id);
FOREACH(struct mux_client *client, &client_list) {
if (client->state == CLIENT_LISTEN)
send_device_paired(client, id);
} ENDFOREACH
pthread_mutex_unlock(&client_list_mutex);
mutex_unlock(&client_list_mutex);
}

void client_init(void)
{
usbmuxd_log(LL_DEBUG, "client_init");
collection_init(&client_list);
pthread_mutex_init(&client_list_mutex, NULL);
mutex_init(&client_list_mutex);
}

void client_shutdown(void)
Expand All @@ -1051,6 +1052,6 @@ void client_shutdown(void)
FOREACH(struct mux_client *client, &client_list) {
client_close(client);
} ENDFOREACH
pthread_mutex_destroy(&client_list_mutex);
mutex_destroy(&client_list_mutex);
collection_free(&client_list);
}
2 changes: 2 additions & 0 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include <shlobj.h>
#endif

#include <libimobiledevice-glue/utils.h>

#include "conf.h"
#include "utils.h"
#include "log.h"
Expand Down
Loading

0 comments on commit 32a8ebe

Please sign in to comment.