Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual C++ Compatibility #28

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#include <config.h>
#endif

#ifdef _MSC_VER
#include "..\src\msc_config.h"
#endif

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Expand Down
8 changes: 6 additions & 2 deletions common/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifdef _MSC_VER
#include "..\src\msc_config.h"
#endif

#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/stat.h>
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
static int wsa_init = 0;
#else
#include <unistd.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
Expand Down
26 changes: 16 additions & 10 deletions include/usbmuxd-proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
#define USBMUXD_SOCKET_FILE "/var/run/usbmuxd"
#endif

#ifndef _MSC_VER
#define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__))
#else
#define PACK( __Declaration__ ) __pragma( pack(push, 1) ) __Declaration__ __pragma( pack(pop) )
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -57,36 +63,36 @@ enum usbmuxd_msgtype {
MESSAGE_PLIST = 8,
};

struct usbmuxd_header {
PACK(struct usbmuxd_header {
uint32_t length; // length of message, including header
uint32_t version; // protocol version
uint32_t message; // message type
uint32_t tag; // responses to this query will echo back this tag
} __attribute__((__packed__));
});

struct usbmuxd_result_msg {
PACK(struct usbmuxd_result_msg {
struct usbmuxd_header header;
uint32_t result;
} __attribute__((__packed__));
});

struct usbmuxd_connect_request {
PACK(struct usbmuxd_connect_request {
struct usbmuxd_header header;
uint32_t device_id;
uint16_t port; // TCP port number
uint16_t reserved; // set to zero
} __attribute__((__packed__));
});

struct usbmuxd_listen_request {
PACK(struct usbmuxd_listen_request {
struct usbmuxd_header header;
} __attribute__((__packed__));
});

struct usbmuxd_device_record {
PACK(struct usbmuxd_device_record {
uint32_t device_id;
uint16_t product_id;
char serial_number[256];
uint16_t padding;
uint32_t location;
} __attribute__((__packed__));
});

#ifdef __cplusplus
}
Expand Down
38 changes: 22 additions & 16 deletions include/usbmuxd.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
#define USBMUXD_H
#include <stdint.h>

#ifdef _MSC_VER
#define USBMUXD_API_MSC __declspec( dllexport )
#else
#define USBMUXD_API_MSC
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -71,14 +77,14 @@ typedef void (*usbmuxd_event_cb_t) (const usbmuxd_event_t *event, void *user_dat
*
* @return 0 on success or negative on error.
*/
int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data);
USBMUXD_API_MSC int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data);

/**
* Unsubscribe callback.
*
* @return only 0 for now.
*/
int usbmuxd_unsubscribe();
USBMUXD_API_MSC int usbmuxd_unsubscribe();

/**
* Contacts usbmuxd and retrieves a list of connected devices.
Expand All @@ -91,7 +97,7 @@ int usbmuxd_unsubscribe();
* @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_MSC int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list);

/**
* Frees the device list returned by an usbmuxd_get_device_list call
Expand All @@ -100,7 +106,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_MSC int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list);

/**
* Gets device information for the device specified by udid.
Expand All @@ -113,7 +119,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_MSC int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device);

/**
* Request proxy connect to
Expand All @@ -125,7 +131,7 @@ int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device);
*
* @return file descriptor socket of the connection, or -1 on error
*/
int usbmuxd_connect(const int handle, const unsigned short tcp_port);
USBMUXD_API_MSC int usbmuxd_connect(const int handle, const unsigned short tcp_port);

/**
* Disconnect. For now, this just closes the socket file descriptor.
Expand All @@ -134,7 +140,7 @@ int usbmuxd_connect(const int handle, const unsigned short tcp_port);
*
* @return 0 on success, -1 on error.
*/
int usbmuxd_disconnect(int sfd);
USBMUXD_API_MSC int usbmuxd_disconnect(int sfd);

/**
* Send data to the specified socket.
Expand All @@ -146,7 +152,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_MSC int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes);

/**
* Receive data from the specified socket.
Expand All @@ -159,7 +165,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_MSC 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.
Expand All @@ -171,7 +177,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_MSC int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes);

/**
* Reads the SystemBUID
Expand All @@ -181,7 +187,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_MSC int usbmuxd_read_buid(char** buid);

/**
* Read a pairing record
Expand All @@ -194,7 +200,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_MSC int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t *record_size);

/**
* Save a pairing record
Expand All @@ -205,7 +211,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_MSC int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uint32_t record_size);

/**
* Delete a pairing record
Expand All @@ -214,17 +220,17 @@ int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uin
*
* @return 0 on success, a negative errno value otherwise.
*/
int usbmuxd_delete_pair_record(const char* record_id);
USBMUXD_API_MSC int usbmuxd_delete_pair_record(const char* record_id);

/**
* Enable or disable the use of inotify extension. Enabled by default.
* Use 0 to disable and 1 to enable inotify support.
* 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_MSC void libusbmuxd_set_use_inotify(int set);

void libusbmuxd_set_debug_level(int level);
USBMUXD_API_MSC void libusbmuxd_set_debug_level(int level);

#ifdef __cplusplus
}
Expand Down
18 changes: 13 additions & 5 deletions src/libusbmuxd.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef _MSC_VER
#include "msc_config.h"
#endif

#include <stdint.h>
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef _MSC_VER
#define USBMUXD_API __declspec( dllexport )
#else
#ifdef WIN32
#define USBMUXD_API __declspec( dllexport )
#else
Expand All @@ -39,6 +46,7 @@
#define USBMUXD_API
#endif
#endif
#endif

#ifdef WIN32
#include <windows.h>
Expand All @@ -51,6 +59,7 @@
#define EBADMSG 104
#endif
#else
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <pthread.h>
Expand All @@ -64,7 +73,6 @@
#define USBMUXD_SOCKET_NAME "usbmuxd"
#endif /* HAVE_INOTIFY */

#include <unistd.h>
#include <signal.h>

#include <plist/plist.h>
Expand Down
31 changes: 31 additions & 0 deletions src/msc_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* msc_config.h
* Contains definitions that will help the Visual C++ compiler compile
* the libimobiledevice code base.
*
* Copyright (c) 2015 Frederik Carlier, Quamotion bvba. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifdef _MSC_VER
#define inline __inline
#define WIN32_LEAN_AND_MEAN
#define _CRT_SECURE_NO_WARNINGS
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#define __func__ __FUNCTION__
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#endif