diff options
author | Nikias Bassen | 2018-10-16 02:49:54 +0200 |
---|---|---|
committer | Nikias Bassen | 2018-10-16 02:49:54 +0200 |
commit | 604c250b969e20534c18300df369291f1ed9fa2d (patch) | |
tree | 4c350ab9757e9cdfd4e73e64c1c80464e7dcb5b6 | |
parent | 450c715317954e2b17abb31549fc27e18d20bf3e (diff) | |
download | libusbmuxd-604c250b969e20534c18300df369291f1ed9fa2d.tar.gz libusbmuxd-604c250b969e20534c18300df369291f1ed9fa2d.tar.bz2 |
Avoid code duplication for sanitizing udid
-rw-r--r-- | src/libusbmuxd.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/libusbmuxd.c b/src/libusbmuxd.c index f2ccb4f..26d0465 100644 --- a/src/libusbmuxd.c +++ b/src/libusbmuxd.c @@ -194,6 +194,19 @@ static int connect_usbmuxd_socket() #endif } +static void sanitize_udid(usbmuxd_device_info_t *devinfo) +{ + if (!devinfo) + return; + if (strlen(devinfo->udid) == 24) { + memmove(&devinfo->udid[9], &devinfo->udid[8], 17); + devinfo->udid[8] = '-'; + } + if (strcasecmp(devinfo->udid, "ffffffffffffffffffffffffffffffffffffffff") == 0) { + sprintf(devinfo->udid + 32, "%08x", devinfo->handle); + } +} + static usbmuxd_device_info_t *device_info_from_plist(plist_t props) { usbmuxd_device_info_t* devinfo = NULL; @@ -224,13 +237,7 @@ static usbmuxd_device_info_t *device_info_from_plist(plist_t props) if (strval) { char *t = stpncpy(devinfo->udid, strval, sizeof(devinfo->udid)-1); *t = '\0'; - if (strlen(devinfo->udid) == 24) { - memmove(&devinfo->udid[9], &devinfo->udid[8], 17); - devinfo->udid[8] = '-'; - } - if (strcasecmp(devinfo->udid, "ffffffffffffffffffffffffffffffffffffffff") == 0) { - sprintf(devinfo->udid + 32, "%08x", devinfo->handle); - } + sanitize_udid(devinfo); free(strval); } } @@ -293,13 +300,7 @@ static usbmuxd_device_info_t *device_info_from_device_record(struct usbmuxd_devi devinfo->product_id = dev->product_id; char *t = stpncpy(devinfo->udid, dev->serial_number, sizeof(devinfo->udid)-2); *t = '\0'; - if (strlen(devinfo->udid) == 24) { - memmove(&devinfo->udid[9], &devinfo->udid[8], 17); - devinfo->udid[8] = '-'; - } - if (strcasecmp(devinfo->udid, "ffffffffffffffffffffffffffffffffffffffff") == 0) { - sprintf(devinfo->udid + 32, "%08x", devinfo->handle); - } + sanitize_udid(devinfo); return devinfo; } |