From d1ccd4eeebc94dac11140ae77b73392d0763d3a4 Mon Sep 17 00:00:00 2001 From: Martin Szulecki Date: Fri, 21 Mar 2014 00:16:29 +0100 Subject: Refactor pair record handling to use new usbmuxd pair record interface This refactoring is mandatory as libimobiledevice should not interact with the pair record configuration directory which is owned by the usbmuxd user. This change also adds compatibility for the native usbmuxd and thus pair records saved by iTunes. --- common/utils.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'common/utils.c') diff --git a/common/utils.c b/common/utils.c index 1b207ea..68b23b9 100644 --- a/common/utils.c +++ b/common/utils.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "utils.h" @@ -107,6 +108,35 @@ char *string_concat(const char *str, ...) return result; } +static int get_rand(int min, int max) +{ + int retval = (rand() % (max - min)) + min; + return retval; +} + +char *generate_uuid() +{ + const char *chars = "ABCDEF0123456789"; + int i = 0; + char *uuid = (char *) malloc(sizeof(char) * 37); + + srand(time(NULL)); + + for (i = 0; i < 36; i++) { + if (i == 8 || i == 13 || i == 18 || i == 23) { + uuid[i] = '-'; + continue; + } else { + uuid[i] = chars[get_rand(0, 16)]; + } + } + + /* make it a real string */ + uuid[36] = '\0'; + + return uuid; +} + void buffer_read_from_filename(const char *filename, char **buffer, uint64_t *length) { FILE *f; -- cgit v1.1-32-gdbae