summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2021-06-07 02:01:35 +0200
committerGravatar Nikias Bassen2021-06-07 03:41:07 +0200
commit046b26150e004a8ac740e699c6c3e11be29e8f11 (patch)
tree8f59597463dccd81ca180a87668e53864c4b09ae /include
downloadlibimobiledevice-glue-046b26150e004a8ac740e699c6c3e11be29e8f11.tar.gz
libimobiledevice-glue-046b26150e004a8ac740e699c6c3e11be29e8f11.tar.bz2
Initial check-in of sources
Diffstat (limited to 'include')
-rw-r--r--include/Makefile.am5
-rw-r--r--include/libimobiledevice-glue/collection.h52
-rw-r--r--include/libimobiledevice-glue/socket.h68
-rw-r--r--include/libimobiledevice-glue/thread.h87
-rw-r--r--include/libimobiledevice-glue/utils.h59
5 files changed, 271 insertions, 0 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
new file mode 100644
index 0000000..5d54892
--- /dev/null
+++ b/include/Makefile.am
@@ -0,0 +1,5 @@
+nobase_include_HEADERS = \
+ libimobiledevice-glue/socket.h \
+ libimobiledevice-glue/thread.h \
+ libimobiledevice-glue/utils.h \
+ libimobiledevice-glue/collection.h
diff --git a/include/libimobiledevice-glue/collection.h b/include/libimobiledevice-glue/collection.h
new file mode 100644
index 0000000..df1680c
--- /dev/null
+++ b/include/libimobiledevice-glue/collection.h
@@ -0,0 +1,52 @@
+/*
+ * collection.h
+ *
+ * Copyright (C) 2009 Hector Martin <hector@marcansoft.com>
+ * Copyright (C) 2009 Nikias Bassen <nikias@gmx.li>
+ *
+ * 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 COLLECTION_H
+#define COLLECTION_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);
+
+#define MERGE_(a,b) a ## _ ## b
+#define LABEL_(a,b) MERGE_(a, b)
+#define UNIQUE_VAR(a) LABEL_(a, __LINE__)
+
+#define FOREACH(var, col) \
+ do { \
+ int UNIQUE_VAR(_iter); \
+ for(UNIQUE_VAR(_iter)=0; UNIQUE_VAR(_iter)<(col)->capacity; UNIQUE_VAR(_iter)++) { \
+ if(!(col)->list[UNIQUE_VAR(_iter)]) continue; \
+ var = (col)->list[UNIQUE_VAR(_iter)];
+
+#define ENDFOREACH \
+ } \
+ } while(0);
+
+#endif
diff --git a/include/libimobiledevice-glue/socket.h b/include/libimobiledevice-glue/socket.h
new file mode 100644
index 0000000..9567270
--- /dev/null
+++ b/include/libimobiledevice-glue/socket.h
@@ -0,0 +1,68 @@
+/*
+ * socket.h
+ *
+ * Copyright (C) 2012-2020 Nikias Bassen <nikias@gmx.li>
+ * Copyright (C) 2012 Martin Szulecki <m.szulecki@libimobiledevice.org>
+ *
+ * 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 SOCKET_SOCKET_H
+#define SOCKET_SOCKET_H
+
+#include <stdlib.h>
+#include <stdint.h>
+
+enum fd_mode {
+ FDM_READ,
+ FDM_WRITE,
+ FDM_EXCEPT
+};
+typedef enum fd_mode fd_mode;
+
+#ifdef WIN32
+#include <winsock2.h>
+#define SHUT_RD SD_READ
+#define SHUT_WR SD_WRITE
+#define SHUT_RDWR SD_BOTH
+#else
+#include <sys/socket.h>
+#endif
+
+#ifndef WIN32
+int socket_create_unix(const char *filename);
+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);
+
+int socket_shutdown(int fd, int how);
+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);
+
+void socket_set_verbose(int level);
+
+const char *socket_addr_to_string(struct sockaddr *addr, char *addr_out, size_t addr_out_size);
+
+#endif /* SOCKET_SOCKET_H */
diff --git a/include/libimobiledevice-glue/thread.h b/include/libimobiledevice-glue/thread.h
new file mode 100644
index 0000000..2aadc6e
--- /dev/null
+++ b/include/libimobiledevice-glue/thread.h
@@ -0,0 +1,87 @@
+/*
+ * thread.h
+ *
+ * Copyright (c) 2012-2019 Nikias Bassen, All Rights Reserved.
+ * Copyright (c) 2012 Martin Szulecki, 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 __THREAD_H
+#define __THREAD_H
+
+#include <stddef.h>
+
+#ifdef WIN32
+#include <windows.h>
+typedef HANDLE THREAD_T;
+typedef CRITICAL_SECTION mutex_t;
+typedef struct {
+ HANDLE sem;
+} cond_t;
+typedef volatile struct {
+ LONG lock;
+ int state;
+} thread_once_t;
+#define THREAD_ONCE_INIT {0, 0}
+#define THREAD_ID GetCurrentThreadId()
+#define THREAD_T_NULL (THREAD_T)NULL
+#else
+#include <pthread.h>
+#include <signal.h>
+#include <sys/time.h>
+typedef pthread_t THREAD_T;
+typedef pthread_mutex_t mutex_t;
+typedef pthread_cond_t cond_t;
+typedef pthread_once_t thread_once_t;
+#define THREAD_ONCE_INIT PTHREAD_ONCE_INIT
+#define THREAD_ID pthread_self()
+#define THREAD_T_NULL (THREAD_T)NULL
+#endif
+
+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);
+
+int thread_cancel(THREAD_T thread);
+
+#ifdef WIN32
+#undef HAVE_THREAD_CLEANUP
+#else
+#ifdef HAVE_PTHREAD_CANCEL
+#define HAVE_THREAD_CLEANUP 1
+#define thread_cleanup_push(routine, arg) pthread_cleanup_push(routine, arg)
+#define thread_cleanup_pop(execute) pthread_cleanup_pop(execute)
+#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);
+
+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);
+
+#endif
diff --git a/include/libimobiledevice-glue/utils.h b/include/libimobiledevice-glue/utils.h
new file mode 100644
index 0000000..515339a
--- /dev/null
+++ b/include/libimobiledevice-glue/utils.h
@@ -0,0 +1,59 @@
+/*
+ * utils.h
+ * Miscellaneous utilities for string manipulation,
+ * file I/O and plist helper.
+ *
+ * Copyright (c) 2014-2019 Nikias Bassen, All Rights Reserved.
+ * Copyright (c) 2013-2014 Martin Szulecki, All Rights Reserved.
+ * Copyright (c) 2013 Federico Mena Quintero
+ *
+ * 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 __UTILS_H
+#define __UTILS_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef WIN32
+#include <windows.h>
+#endif
+
+#include <stdio.h>
+#include <plist/plist.h>
+
+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);
+
+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);
+
+enum plist_format_t {
+ PLIST_FORMAT_XML,
+ PLIST_FORMAT_BINARY
+};
+
+int plist_read_from_filename(plist_t *plist, const char *filename);
+int plist_write_to_filename(plist_t plist, const char *filename, enum plist_format_t format);
+
+void plist_print_to_stream(plist_t plist, FILE* stream);
+
+#endif