mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-19 19:53:25 +01:00
More spm fixes
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
EXTRA_DIST = \
|
||||
endianness.h
|
||||
|
||||
nobase_include_HEADERS = \
|
||||
libimobiledevice-glue/socket.h \
|
||||
libimobiledevice-glue/thread.h \
|
||||
libimobiledevice-glue/utils.h \
|
||||
libimobiledevice-glue/collection.h \
|
||||
libimobiledevice-glue/termcolors.h \
|
||||
libimobiledevice-glue/cbuf.h \
|
||||
libimobiledevice-glue/opack.h \
|
||||
libimobiledevice-glue/tlv.h
|
||||
@@ -0,0 +1,123 @@
|
||||
#ifndef ENDIANNESS_H
|
||||
#define ENDIANNESS_H
|
||||
|
||||
#ifndef __LITTLE_ENDIAN
|
||||
#define __LITTLE_ENDIAN 1234
|
||||
#endif
|
||||
|
||||
#ifndef __BIG_ENDIAN
|
||||
#define __BIG_ENDIAN 4321
|
||||
#endif
|
||||
|
||||
#ifndef __BYTE_ORDER
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
#define __BYTE_ORDER __LITTLE_ENDIAN
|
||||
#else
|
||||
#ifdef __BIG_ENDIAN__
|
||||
#define __BYTE_ORDER __BIG_ENDIAN
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef be16toh
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define be16toh(x) (x)
|
||||
#else
|
||||
#define be16toh(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef htobe16
|
||||
#define htobe16 be16toh
|
||||
#endif
|
||||
|
||||
#ifndef le16toh
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define le16toh(x) ((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
|
||||
#else
|
||||
#define le16toh(x) (x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef htole16
|
||||
#define htole16 le16toh
|
||||
#endif
|
||||
|
||||
#ifndef __bswap_32
|
||||
#define __bswap_32(x) ((((x) & 0xFF000000) >> 24) \
|
||||
| (((x) & 0x00FF0000) >> 8) \
|
||||
| (((x) & 0x0000FF00) << 8) \
|
||||
| (((x) & 0x000000FF) << 24))
|
||||
#endif
|
||||
|
||||
#ifndef be32toh
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define be32toh(x) (x)
|
||||
#else
|
||||
#define be32toh(x) __bswap_32(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef htobe32
|
||||
#define htobe32 be32toh
|
||||
#endif
|
||||
|
||||
#ifndef le32toh
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define le32toh(x) __bswap_32(x)
|
||||
#else
|
||||
#define le32toh(x) (x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef htole32
|
||||
#define htole32 le32toh
|
||||
#endif
|
||||
|
||||
#ifndef __bswap_64
|
||||
#define __bswap_64(x) ((((x) & 0xFF00000000000000ull) >> 56) \
|
||||
| (((x) & 0x00FF000000000000ull) >> 40) \
|
||||
| (((x) & 0x0000FF0000000000ull) >> 24) \
|
||||
| (((x) & 0x000000FF00000000ull) >> 8) \
|
||||
| (((x) & 0x00000000FF000000ull) << 8) \
|
||||
| (((x) & 0x0000000000FF0000ull) << 24) \
|
||||
| (((x) & 0x000000000000FF00ull) << 40) \
|
||||
| (((x) & 0x00000000000000FFull) << 56))
|
||||
#endif
|
||||
|
||||
#ifndef htobe64
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define htobe64(x) (x)
|
||||
#else
|
||||
#define htobe64(x) __bswap_64(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef be64toh
|
||||
#define be64toh htobe64
|
||||
#endif
|
||||
|
||||
#ifndef le64toh
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define le64toh(x) (x)
|
||||
#else
|
||||
#define le64toh(x) __bswap_64(x)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef htole64
|
||||
#define htole64 le64toh
|
||||
#endif
|
||||
|
||||
#if (defined(__BIG_ENDIAN__) \
|
||||
&& !defined(__FLOAT_WORD_ORDER__)) \
|
||||
|| (defined(__FLOAT_WORD_ORDER__) \
|
||||
&& __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||
#define float_bswap64(x) __bswap_64(x)
|
||||
#define float_bswap32(x) __bswap_32(x)
|
||||
#else
|
||||
#define float_bswap64(x) (x)
|
||||
#define float_bswap32(x) (x)
|
||||
#endif
|
||||
|
||||
#endif /* ENDIANNESS_H */
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* cbuf.h
|
||||
* Simple char buffer implementation.
|
||||
*
|
||||
* Copyright (c) 2021 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 __CBUF_H
|
||||
#define __CBUF_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);
|
||||
|
||||
#endif /* __CBUF_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
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* opack.h
|
||||
* "opack" format encoder/decoder implementation.
|
||||
*
|
||||
* Copyright (c) 2021 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 __OPACK_H
|
||||
#define __OPACK_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);
|
||||
|
||||
#endif /* __OPACK_H */
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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);
|
||||
|
||||
int socket_get_socket_port(int fd, uint16_t *port);
|
||||
|
||||
void socket_set_verbose(int level);
|
||||
|
||||
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]);
|
||||
|
||||
#endif /* SOCKET_SOCKET_H */
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* termcolors.h
|
||||
*
|
||||
* Copyright (c) 2020-2021 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 TERMCOLORS_H
|
||||
#define TERMCOLORS_H
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define COLOR_RESET "\e[m"
|
||||
#define STYLE_NORMAL "\e[0m"
|
||||
#define STYLE_BRIGHT "\e[1m"
|
||||
#define STYLE_DARK "\e[2m"
|
||||
#define FG_BLACK "\e[0;30m"
|
||||
#define FG_DARK_GRAY "\e[1;30m"
|
||||
#define FG_RED "\e[0;31m"
|
||||
#define FG_BRIGHT_RED "\e[1;31m"
|
||||
#define FG_DARK_RED "\e[2;31m"
|
||||
#define FG_GREEN "\e[0;32m"
|
||||
#define FG_BRIGHT_GREEN "\e[1;32m"
|
||||
#define FG_DARK_GREEN "\e[2;32m"
|
||||
#define FG_YELLOW "\e[0;33m"
|
||||
#define FG_BRIGHT_YELLOW "\e[1;33m"
|
||||
#define FG_DARK_YELLOW "\e[2;33m"
|
||||
#define FG_BLUE "\e[0;34m"
|
||||
#define FG_BRIGHT_BLUE "\e[1;34m"
|
||||
#define FG_DARK_BLUE "\e[2;34m"
|
||||
#define FG_MAGENTA "\e[0;35m"
|
||||
#define FG_BRIGHT_MAGENTA "\e[1;35m"
|
||||
#define FG_DARK_MAGENTA "\e[2;35m"
|
||||
#define FG_CYAN "\e[0;36m"
|
||||
#define FG_BRIGHT_CYAN "\e[1;36m"
|
||||
#define FG_DARK_CYAN "\e[2;36m"
|
||||
#define FG_LIGHT_GRAY "\e[0;37m"
|
||||
#define FG_WHITE "\e[1;37m"
|
||||
#define FG_GRAY "\e[2;37m"
|
||||
#define FG_DEFAULT "\e[39m"
|
||||
#define BG_BLACK "\e[40m"
|
||||
#define BG_GRAY "\e[100m"
|
||||
#define BG_RED "\e[41m"
|
||||
#define BG_BRIGHT_RED "\e[101m"
|
||||
#define BG_GREEN "\e[42m"
|
||||
#define BG_BRIGHT_GREEN "\e[102m"
|
||||
#define BG_YELLOW "\e[43m"
|
||||
#define BG_BRIGHT_YELLOW "\e[103m"
|
||||
#define BG_BLUE "\e[44m"
|
||||
#define BG_BRIGHT_BLUE "\e[104m"
|
||||
#define BG_MAGENTA "\e[45m"
|
||||
#define BG_BRIGHT_MAGENTA "\e[105m"
|
||||
#define BG_CYAN "\e[46m"
|
||||
#define BG_BRIGHT_CYAN "\e[106m"
|
||||
#define BG_LIGHT_GRAY "\e[47m"
|
||||
#define BG_WHITE "\e[107m"
|
||||
#define BG_DEFAULT "\e[49m"
|
||||
|
||||
/* automatically called by library constructor */
|
||||
void term_colors_init();
|
||||
|
||||
/* enable / disable terminal colors */
|
||||
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);
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* tlv.h
|
||||
* Simple TLV implementation.
|
||||
*
|
||||
* Copyright (c) 2021 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 __TLV_H
|
||||
#define __TLV_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct tlv_buf {
|
||||
unsigned char* data;
|
||||
unsigned int length;
|
||||
unsigned int capacity;
|
||||
};
|
||||
typedef struct tlv_buf* tlv_buf_t;
|
||||
|
||||
tlv_buf_t tlv_buf_new();
|
||||
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);
|
||||
|
||||
#endif /* __TLV_H */
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
#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);
|
||||
|
||||
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);
|
||||
void plist_print_to_stream_with_indentation(plist_t plist, FILE* stream, unsigned int indentation);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user