Skip to content

Commit

Permalink
Move LIMD_GLUE_API definitions to public headers
Browse files Browse the repository at this point in the history
  • Loading branch information
nikias committed Jan 30, 2024
1 parent 2d517eb commit 7ddaea3
Show file tree
Hide file tree
Showing 20 changed files with 190 additions and 144 deletions.
10 changes: 5 additions & 5 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ fi
AC_CHECK_MEMBER(struct dirent.d_type, AC_DEFINE(HAVE_DIRENT_D_TYPE, 1, [define if struct dirent has member d_type]),, [#include <dirent.h>])

AS_COMPILER_FLAGS(GLOBAL_CFLAGS, "-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith -Wwrite-strings -Wswitch-default -Wno-unused-parameter -fsigned-char -fvisibility=hidden")
AC_SUBST(GLOBAL_CFLAGS)

case "$GLOBAL_CFLAGS" in
*-fvisibility=hidden*)
AC_DEFINE([HAVE_FVISIBILITY], [1], [Define if compiled with -fvisibility=hidden])
esac
if test "x$enable_static" = "xyes" -a "x$enable_shared" = "xno"; then
GLOBAL_CFLAGS+=" -DLIMD_GLUE_STATIC"
fi

AC_SUBST(GLOBAL_CFLAGS)

# check for large file support
AC_SYS_LARGEFILE
Expand Down
1 change: 1 addition & 0 deletions include/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ EXTRA_DIST = \
endianness.h

nobase_include_HEADERS = \
libimobiledevice-glue/glue.h \
libimobiledevice-glue/socket.h \
libimobiledevice-glue/thread.h \
libimobiledevice-glue/utils.h \
Expand Down
8 changes: 5 additions & 3 deletions include/libimobiledevice-glue/cbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
#ifndef __CBUF_H
#define __CBUF_H

#include <libimobiledevice-glue/glue.h>

struct char_buf {
unsigned char* data;
unsigned int length;
unsigned int capacity;
};

struct char_buf* char_buf_new();
void char_buf_free(struct char_buf* cbuf);
void char_buf_append(struct char_buf* cbuf, unsigned int length, unsigned char* data);
LIMD_GLUE_API struct char_buf* char_buf_new();
LIMD_GLUE_API void char_buf_free(struct char_buf* cbuf);
LIMD_GLUE_API void char_buf_append(struct char_buf* cbuf, unsigned int length, unsigned char* data);

#endif /* __CBUF_H */
14 changes: 8 additions & 6 deletions include/libimobiledevice-glue/collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@
#ifndef COLLECTION_H
#define COLLECTION_H

#include <libimobiledevice-glue/glue.h>

struct collection {
void **list;
int capacity;
};

void collection_init(struct collection *col);
void collection_add(struct collection *col, void *element);
int collection_remove(struct collection *col, void *element);
int collection_count(struct collection *col);
void collection_free(struct collection *col);
void collection_copy(struct collection *dest, struct collection *src);
LIMD_GLUE_API void collection_init(struct collection *col);
LIMD_GLUE_API void collection_add(struct collection *col, void *element);
LIMD_GLUE_API int collection_remove(struct collection *col, void *element);
LIMD_GLUE_API int collection_count(struct collection *col);
LIMD_GLUE_API void collection_free(struct collection *col);
LIMD_GLUE_API void collection_copy(struct collection *dest, struct collection *src);

#define MERGE_(a,b) a ## _ ## b
#define LABEL_(a,b) MERGE_(a, b)
Expand Down
35 changes: 35 additions & 0 deletions include/libimobiledevice-glue/glue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* glue.h
* Common definitions
*
* Copyright (c) 2024 Nikias Bassen, 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
*/

#ifndef __GLUE_H
#define __GLUE_H

#ifndef LIMD_GLUE_API
#ifdef LIMD_GLUE_STATIC
#define LIMD_GLUE_API
#elif defined(_WIN32)
#define LIMD_GLUE_API __declspec(dllimport)
#else
#define LIMD_GLUE_API
#endif
#endif

#endif
5 changes: 3 additions & 2 deletions include/libimobiledevice-glue/opack.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
#ifndef __OPACK_H
#define __OPACK_H

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

void opack_encode_from_plist(plist_t plist, unsigned char** out, unsigned int* out_len);
int opack_decode_to_plist(unsigned char* buf, unsigned int buf_len, plist_t* plist_out);
LIMD_GLUE_API void opack_encode_from_plist(plist_t plist, unsigned char** out, unsigned int* out_len);
LIMD_GLUE_API int opack_decode_to_plist(unsigned char* buf, unsigned int buf_len, plist_t* plist_out);

#endif /* __OPACK_H */
36 changes: 19 additions & 17 deletions include/libimobiledevice-glue/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,32 @@ typedef enum fd_mode fd_mode;
#include <sys/socket.h>
#endif

#include <libimobiledevice-glue/glue.h>

#ifndef WIN32
int socket_create_unix(const char *filename);
int socket_connect_unix(const char *filename);
LIMD_GLUE_API int socket_create_unix(const char *filename);
LIMD_GLUE_API int socket_connect_unix(const char *filename);
#endif
int socket_create(const char *addr, uint16_t port);
int socket_connect_addr(struct sockaddr *addr, uint16_t port);
int socket_connect(const char *addr, uint16_t port);
int socket_check_fd(int fd, fd_mode fdm, unsigned int timeout);
int socket_accept(int fd, uint16_t port);
LIMD_GLUE_API int socket_create(const char *addr, uint16_t port);
LIMD_GLUE_API int socket_connect_addr(struct sockaddr *addr, uint16_t port);
LIMD_GLUE_API int socket_connect(const char *addr, uint16_t port);
LIMD_GLUE_API int socket_check_fd(int fd, fd_mode fdm, unsigned int timeout);
LIMD_GLUE_API int socket_accept(int fd, uint16_t port);

int socket_shutdown(int fd, int how);
int socket_close(int fd);
LIMD_GLUE_API int socket_shutdown(int fd, int how);
LIMD_GLUE_API int socket_close(int fd);

int socket_receive(int fd, void *data, size_t length);
int socket_peek(int fd, void *data, size_t length);
int socket_receive_timeout(int fd, void *data, size_t length, int flags, unsigned int timeout);
int socket_send(int fd, void *data, size_t length);
LIMD_GLUE_API int socket_receive(int fd, void *data, size_t length);
LIMD_GLUE_API int socket_peek(int fd, void *data, size_t length);
LIMD_GLUE_API int socket_receive_timeout(int fd, void *data, size_t length, int flags, unsigned int timeout);
LIMD_GLUE_API int socket_send(int fd, void *data, size_t length);

int socket_get_socket_port(int fd, uint16_t *port);
LIMD_GLUE_API int socket_get_socket_port(int fd, uint16_t *port);

void socket_set_verbose(int level);
LIMD_GLUE_API void socket_set_verbose(int level);

const char *socket_addr_to_string(struct sockaddr *addr, char *addr_out, size_t addr_out_size);
LIMD_GLUE_API const char *socket_addr_to_string(struct sockaddr *addr, char *addr_out, size_t addr_out_size);

int get_primary_mac_address(unsigned char mac_addr_buf[6]);
LIMD_GLUE_API int get_primary_mac_address(unsigned char mac_addr_buf[6]);

#endif /* SOCKET_SOCKET_H */
11 changes: 6 additions & 5 deletions include/libimobiledevice-glue/termcolors.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <stdarg.h>
#include <stdio.h>
#include <libimobiledevice-glue/glue.h>

#define COLOR_RESET "\e[m"
#define STYLE_NORMAL "\e[0m"
Expand Down Expand Up @@ -74,14 +75,14 @@
#define BG_DEFAULT "\e[49m"

/* automatically called by library constructor */
void term_colors_init();
LIMD_GLUE_API void term_colors_init();

/* enable / disable terminal colors */
void term_colors_set_enabled(int en);
LIMD_GLUE_API void term_colors_set_enabled(int en);

/* color-aware *printf variants */
int cprintf(const char* fmt, ...);
int cfprintf(FILE* stream, const char* fmt, ...);
int cvfprintf(FILE* stream, const char* fmt, va_list vargs);
LIMD_GLUE_API int cprintf(const char* fmt, ...);
LIMD_GLUE_API int cfprintf(FILE* stream, const char* fmt, ...);
LIMD_GLUE_API int cvfprintf(FILE* stream, const char* fmt, va_list vargs);

#endif
32 changes: 16 additions & 16 deletions include/libimobiledevice-glue/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ typedef pthread_once_t thread_once_t;

typedef void* (*thread_func_t)(void* data);

int thread_new(THREAD_T* thread, thread_func_t thread_func, void* data);
void thread_detach(THREAD_T thread);
void thread_free(THREAD_T thread);
int thread_join(THREAD_T thread);
int thread_alive(THREAD_T thread);
LIMD_GLUE_API int thread_new(THREAD_T* thread, thread_func_t thread_func, void* data);
LIMD_GLUE_API void thread_detach(THREAD_T thread);
LIMD_GLUE_API void thread_free(THREAD_T thread);
LIMD_GLUE_API int thread_join(THREAD_T thread);
LIMD_GLUE_API int thread_alive(THREAD_T thread);

int thread_cancel(THREAD_T thread);
LIMD_GLUE_API int thread_cancel(THREAD_T thread);

#ifdef WIN32
#undef HAVE_THREAD_CLEANUP
Expand All @@ -85,17 +85,17 @@ int thread_cancel(THREAD_T thread);
#endif
#endif

void mutex_init(mutex_t* mutex);
void mutex_destroy(mutex_t* mutex);
void mutex_lock(mutex_t* mutex);
void mutex_unlock(mutex_t* mutex);
LIMD_GLUE_API void mutex_init(mutex_t* mutex);
LIMD_GLUE_API void mutex_destroy(mutex_t* mutex);
LIMD_GLUE_API void mutex_lock(mutex_t* mutex);
LIMD_GLUE_API void mutex_unlock(mutex_t* mutex);

void thread_once(thread_once_t *once_control, void (*init_routine)(void));
LIMD_GLUE_API void thread_once(thread_once_t *once_control, void (*init_routine)(void));

void cond_init(cond_t* cond);
void cond_destroy(cond_t* cond);
int cond_signal(cond_t* cond);
int cond_wait(cond_t* cond, mutex_t* mutex);
int cond_wait_timeout(cond_t* cond, mutex_t* mutex, unsigned int timeout_ms);
LIMD_GLUE_API void cond_init(cond_t* cond);
LIMD_GLUE_API void cond_destroy(cond_t* cond);
LIMD_GLUE_API int cond_signal(cond_t* cond);
LIMD_GLUE_API int cond_wait(cond_t* cond, mutex_t* mutex);
LIMD_GLUE_API int cond_wait_timeout(cond_t* cond, mutex_t* mutex, unsigned int timeout_ms);

#endif
15 changes: 8 additions & 7 deletions include/libimobiledevice-glue/tlv.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define __TLV_H

#include <stdint.h>
#include <libimobiledevice-glue/glue.h>

struct tlv_buf {
unsigned char* data;
Expand All @@ -30,13 +31,13 @@ struct tlv_buf {
};
typedef struct tlv_buf* tlv_buf_t;

tlv_buf_t tlv_buf_new();
void tlv_buf_free(tlv_buf_t tlv);
LIMD_GLUE_API tlv_buf_t tlv_buf_new();
LIMD_GLUE_API void tlv_buf_free(tlv_buf_t tlv);

void tlv_buf_append(tlv_buf_t tlv, uint8_t tag, unsigned int length, void* data);
unsigned char* tlv_get_data_ptr(const void* tlv_data, void* tlv_end, uint8_t tag, uint8_t* length);
int tlv_data_get_uint(const void* tlv_data, unsigned int tlv_length, uint8_t tag, uint64_t* value);
int tlv_data_get_uint8(const void* tlv_data, unsigned int tlv_length, uint8_t tag, uint8_t* value);
int tlv_data_copy_data(const void* tlv_data, unsigned int tlv_length, uint8_t tag, void** out, unsigned int* out_len);
LIMD_GLUE_API void tlv_buf_append(tlv_buf_t tlv, uint8_t tag, unsigned int length, void* data);
LIMD_GLUE_API unsigned char* tlv_get_data_ptr(const void* tlv_data, void* tlv_end, uint8_t tag, uint8_t* length);
LIMD_GLUE_API int tlv_data_get_uint(const void* tlv_data, unsigned int tlv_length, uint8_t tag, uint64_t* value);
LIMD_GLUE_API int tlv_data_get_uint8(const void* tlv_data, unsigned int tlv_length, uint8_t tag, uint8_t* value);
LIMD_GLUE_API int tlv_data_copy_data(const void* tlv_data, unsigned int tlv_length, uint8_t tag, void** out, unsigned int* out_len);

#endif /* __TLV_H */
21 changes: 9 additions & 12 deletions include/libimobiledevice-glue/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,20 @@
#ifndef __UTILS_H
#define __UTILS_H

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

#include <stdio.h>
#include <stdint.h>
#include <libimobiledevice-glue/glue.h>

#define MAC_EPOCH 978307200

char *string_concat(const char *str, ...);
char *string_append(char *str, ...);
char *string_build_path(const char *elem, ...);
char *string_format_size(uint64_t size);
char *string_toupper(char *str);
char *generate_uuid(void);
LIMD_GLUE_API char *string_concat(const char *str, ...);
LIMD_GLUE_API char *string_append(char *str, ...);
LIMD_GLUE_API char *string_build_path(const char *elem, ...);
LIMD_GLUE_API char *string_format_size(uint64_t size);
LIMD_GLUE_API char *string_toupper(char *str);
LIMD_GLUE_API char *generate_uuid(void);

int buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length);
int buffer_write_to_filename(const char *filename, const char *buffer, uint64_t length);
LIMD_GLUE_API int buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length);
LIMD_GLUE_API int buffer_write_to_filename(const char *filename, const char *buffer, uint64_t length);

#endif
6 changes: 3 additions & 3 deletions src/cbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "common.h"
#include "libimobiledevice-glue/cbuf.h"

LIBIMOBILEDEVICE_GLUE_API struct char_buf* char_buf_new()
struct char_buf* char_buf_new()
{
struct char_buf* cbuf = (struct char_buf*)malloc(sizeof(struct char_buf));
cbuf->capacity = 256;
Expand All @@ -39,15 +39,15 @@ LIBIMOBILEDEVICE_GLUE_API struct char_buf* char_buf_new()
return cbuf;
}

LIBIMOBILEDEVICE_GLUE_API void char_buf_free(struct char_buf* cbuf)
void char_buf_free(struct char_buf* cbuf)
{
if (cbuf) {
free(cbuf->data);
free(cbuf);
}
}

LIBIMOBILEDEVICE_GLUE_API void char_buf_append(struct char_buf* cbuf, unsigned int length, unsigned char* data)
void char_buf_append(struct char_buf* cbuf, unsigned int length, unsigned char* data)
{
if (!cbuf || !cbuf->data) {
return;
Expand Down
12 changes: 6 additions & 6 deletions src/collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@

#define CAPACITY_STEP 8

LIBIMOBILEDEVICE_GLUE_API void collection_init(struct collection *col)
void collection_init(struct collection *col)
{
col->list = malloc(sizeof(void *) * CAPACITY_STEP);
assert(col->list);
INIT_NULL(col->list, CAPACITY_STEP);
col->capacity = CAPACITY_STEP;
}

LIBIMOBILEDEVICE_GLUE_API void collection_free(struct collection *col)
void collection_free(struct collection *col)
{
free(col->list);
col->list = NULL;
col->capacity = 0;
}

LIBIMOBILEDEVICE_GLUE_API void collection_add(struct collection *col, void *element)
void collection_add(struct collection *col, void *element)
{
int i;
for(i=0; i<col->capacity; i++) {
Expand All @@ -69,7 +69,7 @@ LIBIMOBILEDEVICE_GLUE_API void collection_add(struct collection *col, void *elem
col->capacity += CAPACITY_STEP;
}

LIBIMOBILEDEVICE_GLUE_API int collection_remove(struct collection *col, void *element)
int collection_remove(struct collection *col, void *element)
{
int i;
for(i=0; i<col->capacity; i++) {
Expand All @@ -82,7 +82,7 @@ LIBIMOBILEDEVICE_GLUE_API int collection_remove(struct collection *col, void *el
return -1;
}

LIBIMOBILEDEVICE_GLUE_API int collection_count(struct collection *col)
int collection_count(struct collection *col)
{
int i, cnt = 0;
for(i=0; i<col->capacity; i++) {
Expand All @@ -92,7 +92,7 @@ LIBIMOBILEDEVICE_GLUE_API int collection_count(struct collection *col)
return cnt;
}

LIBIMOBILEDEVICE_GLUE_API void collection_copy(struct collection *dest, struct collection *src)
void collection_copy(struct collection *dest, struct collection *src)
{
if (!dest || !src) return;
dest->capacity = src->capacity;
Expand Down
Loading

0 comments on commit 7ddaea3

Please sign in to comment.