diff --git a/configure.ac b/configure.ac index 9d5eddb..36df4b4 100644 --- a/configure.ac +++ b/configure.ac @@ -117,14 +117,14 @@ AM_CONDITIONAL(WIN32, test x$win32 = xtrue) AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter -fvisibility=hidden $PTHREAD_CFLAGS") GLOBAL_LDFLAGS="$PTHREAD_LIBS" + +if test "x$enable_static" = "xyes" -a "x$enable_shared" = "xno"; then + GLOBAL_CFLAGS+=" -DLIBUSBMUXD_STATIC" +fi + AC_SUBST(GLOBAL_CFLAGS) AC_SUBST(GLOBAL_LDFLAGS) -case "$GLOBAL_CFLAGS" in - *-fvisibility=hidden*) - AC_DEFINE([HAVE_FVISIBILITY], [1], [Define if compiled with -fvisibility=hidden]) -esac - m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) AC_CONFIG_FILES([ diff --git a/include/usbmuxd.h b/include/usbmuxd.h index 6c440c1..cb31fa0 100644 --- a/include/usbmuxd.h +++ b/include/usbmuxd.h @@ -28,6 +28,16 @@ extern "C" { #endif +#ifndef USBMUXD_API + #ifdef LIBUSBMUXD_STATIC + #define USBMUXD_API + #elif defined(_WIN32) + #define USBMUXD_API __declspec(dllimport) + #else + #define USBMUXD_API + #endif +#endif + /** Device lookup options for usbmuxd_get_device. */ enum usbmux_lookup_options { DEVICE_LOOKUP_USBMUX = 1 << 1, /**< include USBMUX devices during lookup */ @@ -99,7 +109,7 @@ typedef struct usbmuxd_subscription_context* usbmuxd_subscription_context_t; * * @return 0 on success or a negative errno value. */ -int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context, usbmuxd_event_cb_t callback, void *user_data); +USBMUXD_API int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context, usbmuxd_event_cb_t callback, void *user_data); /** * Unsubscribe callback function @@ -108,7 +118,7 @@ int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context, usbmuxd_ev * * @return 0 on success or a negative errno value. */ -int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t context); +USBMUXD_API int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t context); /** * Subscribe a callback (deprecated) @@ -122,7 +132,7 @@ int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t context); * @note Deprecated. Use usbmuxd_events_subscribe and usbmuxd_events_unsubscribe instead. * @see usbmuxd_events_subscribe */ -int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data); +USBMUXD_API int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data); /** * Unsubscribe callback (deprecated) @@ -132,7 +142,7 @@ int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data); * @note Deprecated. Use usbmuxd_events_subscribe and usbmuxd_events_unsubscribe instead. * @see usbmuxd_events_unsubscribe */ -int usbmuxd_unsubscribe(void); +USBMUXD_API int usbmuxd_unsubscribe(void); /** * Contacts usbmuxd and retrieves a list of connected devices. @@ -145,7 +155,7 @@ int usbmuxd_unsubscribe(void); * @return number of attached devices, zero on no devices, or negative * if an error occured. */ -int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list); +USBMUXD_API int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list); /** * Frees the device list returned by an usbmuxd_get_device_list call @@ -154,7 +164,7 @@ int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list); * * @return 0 on success, -1 on error. */ -int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list); +USBMUXD_API int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list); /** * Looks up the device specified by UDID and returns device information. @@ -172,7 +182,7 @@ int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list); * @return 0 if no matching device is connected, 1 if the device was found, * or a negative value on error. */ -int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device); +USBMUXD_API int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device); /** * Looks up the device specified by UDID with given options and returns @@ -197,7 +207,7 @@ int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device); * @return 0 if no matching device is connected, 1 if the device was found, * or a negative value on error. */ -int usbmuxd_get_device(const char *udid, usbmuxd_device_info_t *device, enum usbmux_lookup_options options); +USBMUXD_API int usbmuxd_get_device(const char *udid, usbmuxd_device_info_t *device, enum usbmux_lookup_options options); /** * Request proxy connection to the specified device and port. @@ -211,7 +221,7 @@ int usbmuxd_get_device(const char *udid, usbmuxd_device_info_t *device, enum usb * @return socket file descriptor of the connection, or a negative errno * value on error. */ -int usbmuxd_connect(const uint32_t handle, const unsigned short tcp_port); +USBMUXD_API int usbmuxd_connect(const uint32_t handle, const unsigned short tcp_port); /** * Disconnect. For now, this just closes the socket file descriptor. @@ -220,7 +230,7 @@ int usbmuxd_connect(const uint32_t handle, const unsigned short tcp_port); * * @return 0 on success, -1 on error. */ -int usbmuxd_disconnect(int sfd); +USBMUXD_API int usbmuxd_disconnect(int sfd); /** * Send data to the specified socket. @@ -232,7 +242,7 @@ int usbmuxd_disconnect(int sfd); * * @return 0 on success, a negative errno value otherwise. */ -int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes); +USBMUXD_API int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes); /** * Receive data from the specified socket. @@ -245,7 +255,7 @@ int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes); * * @return 0 on success, a negative errno value otherwise. */ -int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout); +USBMUXD_API int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout); /** * Receive data from the specified socket with a default timeout. @@ -257,7 +267,7 @@ int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes * * @return 0 on success, a negative errno value otherwise. */ -int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes); +USBMUXD_API int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes); /** * Reads the SystemBUID @@ -267,7 +277,7 @@ int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes); * * @return 0 on success, a negative errno value otherwise. */ -int usbmuxd_read_buid(char** buid); +USBMUXD_API int usbmuxd_read_buid(char** buid); /** * Read a pairing record @@ -280,7 +290,7 @@ int usbmuxd_read_buid(char** buid); * * @return 0 on success, a negative error value otherwise. */ -int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t *record_size); +USBMUXD_API int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t *record_size); /** * Save a pairing record @@ -291,7 +301,7 @@ int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t * * @return 0 on success, a negative error value otherwise. */ -int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uint32_t record_size); +USBMUXD_API int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uint32_t record_size); /** * Save a pairing record with device identifier @@ -303,7 +313,7 @@ int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uin * * @return 0 on success, a negative error value otherwise. */ -int usbmuxd_save_pair_record_with_device_id(const char* record_id, uint32_t device_id, const char *record_data, uint32_t record_size); +USBMUXD_API int usbmuxd_save_pair_record_with_device_id(const char* record_id, uint32_t device_id, const char *record_data, uint32_t record_size); /** * Delete a pairing record @@ -312,7 +322,7 @@ int usbmuxd_save_pair_record_with_device_id(const char* record_id, uint32_t devi * * @return 0 on success, a negative errno value otherwise. */ -int usbmuxd_delete_pair_record(const char* record_id); +USBMUXD_API int usbmuxd_delete_pair_record(const char* record_id); /** * Enable or disable the use of inotify extension. Enabled by default. @@ -320,9 +330,9 @@ int usbmuxd_delete_pair_record(const char* record_id); * This only has an effect on linux systems if inotify support has been built * in. Otherwise and on all other platforms this function has no effect. */ -void libusbmuxd_set_use_inotify(int set); +USBMUXD_API void libusbmuxd_set_use_inotify(int set); -void libusbmuxd_set_debug_level(int level); +USBMUXD_API void libusbmuxd_set_debug_level(int level); #ifdef __cplusplus } diff --git a/src/libusbmuxd.c b/src/libusbmuxd.c index 95e322f..4c2e7d8 100644 --- a/src/libusbmuxd.c +++ b/src/libusbmuxd.c @@ -29,10 +29,12 @@ #include #include -#ifdef WIN32 +#ifdef LIBUSBMUXD_STATIC + #define USBMUXD_API +#elif defined(_WIN32) #define USBMUXD_API __declspec( dllexport ) #else - #ifdef HAVE_FVISIBILITY + #if __GNUC__ >= 4 #define USBMUXD_API __attribute__((visibility("default"))) #else #define USBMUXD_API @@ -1154,7 +1156,7 @@ static void init_listeners(void) mutex_init(&listener_mutex); } -USBMUXD_API int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context, usbmuxd_event_cb_t callback, void *user_data) +int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context, usbmuxd_event_cb_t callback, void *user_data) { if (!context || !callback) { return -EINVAL; @@ -1198,7 +1200,7 @@ USBMUXD_API int usbmuxd_events_subscribe(usbmuxd_subscription_context_t *context return 0; } -USBMUXD_API int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t context) +int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t context) { int ret = 0; int num = 0; @@ -1245,7 +1247,7 @@ USBMUXD_API int usbmuxd_events_unsubscribe(usbmuxd_subscription_context_t contex return ret; } -USBMUXD_API int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data) +int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data) { if (!callback) { return -EINVAL; @@ -1258,14 +1260,14 @@ USBMUXD_API int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data) return usbmuxd_events_subscribe(&event_ctx, callback, user_data); } -USBMUXD_API int usbmuxd_unsubscribe(void) +int usbmuxd_unsubscribe(void) { int res = usbmuxd_events_unsubscribe(event_ctx); event_ctx = NULL; return res; } -USBMUXD_API int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list) +int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list) { int sfd; int tag; @@ -1406,7 +1408,7 @@ USBMUXD_API int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list) return dev_cnt; } -USBMUXD_API int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list) +int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list) { if (device_list) { free(*device_list); @@ -1414,7 +1416,7 @@ USBMUXD_API int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list) return 0; } -USBMUXD_API int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device) +int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device) { usbmuxd_device_info_t *dev_list = NULL; usbmuxd_device_info_t *dev = NULL; @@ -1457,7 +1459,7 @@ USBMUXD_API int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info return result; } -USBMUXD_API int usbmuxd_get_device(const char *udid, usbmuxd_device_info_t *device, enum usbmux_lookup_options options) +int usbmuxd_get_device(const char *udid, usbmuxd_device_info_t *device, enum usbmux_lookup_options options) { usbmuxd_device_info_t *dev_list = NULL; usbmuxd_device_info_t *dev_network = NULL; @@ -1522,7 +1524,7 @@ USBMUXD_API int usbmuxd_get_device(const char *udid, usbmuxd_device_info_t *devi return result; } -USBMUXD_API int usbmuxd_connect(const uint32_t handle, const unsigned short port) +int usbmuxd_connect(const uint32_t handle, const unsigned short port) { int sfd; int tag; @@ -1574,12 +1576,12 @@ USBMUXD_API int usbmuxd_connect(const uint32_t handle, const unsigned short port return -result; } -USBMUXD_API int usbmuxd_disconnect(int sfd) +int usbmuxd_disconnect(int sfd) { return socket_close(sfd); } -USBMUXD_API int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes) +int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes) { int num_sent; @@ -1604,7 +1606,7 @@ USBMUXD_API int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t * return 0; } -USBMUXD_API int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout) +int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout) { int num_recv = socket_receive_timeout(sfd, (void*)data, len, 0, timeout); if (num_recv < 0) { @@ -1617,12 +1619,12 @@ USBMUXD_API int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t return 0; } -USBMUXD_API int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes) +int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes) { return usbmuxd_recv_timeout(sfd, data, len, recv_bytes, 5000); } -USBMUXD_API int usbmuxd_read_buid(char **buid) +int usbmuxd_read_buid(char **buid) { int sfd; int tag; @@ -1663,7 +1665,7 @@ USBMUXD_API int usbmuxd_read_buid(char **buid) return ret; } -USBMUXD_API int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t *record_size) +int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t *record_size) { int sfd; int tag; @@ -1710,7 +1712,7 @@ USBMUXD_API int usbmuxd_read_pair_record(const char* record_id, char **record_da return ret; } -USBMUXD_API int usbmuxd_save_pair_record_with_device_id(const char* record_id, uint32_t device_id, const char *record_data, uint32_t record_size) +int usbmuxd_save_pair_record_with_device_id(const char* record_id, uint32_t device_id, const char *record_data, uint32_t record_size) { int sfd; int tag; @@ -1748,12 +1750,12 @@ USBMUXD_API int usbmuxd_save_pair_record_with_device_id(const char* record_id, u return ret; } -USBMUXD_API int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uint32_t record_size) +int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uint32_t record_size) { return usbmuxd_save_pair_record_with_device_id(record_id, 0, record_data, record_size); } -USBMUXD_API int usbmuxd_delete_pair_record(const char* record_id) +int usbmuxd_delete_pair_record(const char* record_id) { int sfd; int tag; @@ -1789,14 +1791,14 @@ USBMUXD_API int usbmuxd_delete_pair_record(const char* record_id) return ret; } -USBMUXD_API void libusbmuxd_set_use_inotify(int set) +void libusbmuxd_set_use_inotify(int set) { #ifdef HAVE_INOTIFY use_inotify = set; #endif } -USBMUXD_API void libusbmuxd_set_debug_level(int level) +void libusbmuxd_set_debug_level(int level) { libusbmuxd_debug = level; socket_set_verbose(level);