From: Jaroslav Kysela Date: Tue, 5 Dec 2017 19:45:51 +0000 (+0100) Subject: uuid: master cleanups, store only in the binary format X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=feaefd1eb41f08132f79f28a646db8801250ef21;p=thirdparty%2Ftvheadend.git uuid: master cleanups, store only in the binary format --- diff --git a/src/config.c b/src/config.c index 20c1b56bf..649dec787 100644 --- a/src/config.c +++ b/src/config.c @@ -113,6 +113,7 @@ config_migrate_v1_dvb_svcs ( const char *name, const char *netu, const char *muxu, htsmsg_t *channels ) { tvh_uuid_t svcu; + char ubuf[UUID_HEX_SIZE]; htsmsg_t *c, *e, *svc; htsmsg_field_t *f; const char *str; @@ -123,7 +124,7 @@ config_migrate_v1_dvb_svcs if (!(e = htsmsg_field_get_map(f))) continue; svc = htsmsg_create_map(); - uuid_init_hex(&svcu, NULL); + uuid_set(&svcu, NULL); if (!htsmsg_get_u32(e, "service_id", &u32)) htsmsg_add_u32(svc, "sid", u32); if ((str = htsmsg_get_str(e, "servicename"))) @@ -144,11 +145,11 @@ config_migrate_v1_dvb_svcs // TODO: dvb_eit_enable hts_settings_save(svc, "input/linuxdvb/networks/%s/muxes/%s/services/%s", - netu, muxu, svcu.hex); + netu, muxu, uuid_get_hex(&svcu, ubuf)); /* Map to channel */ if ((str = htsmsg_get_str(e, "channelname"))) - config_migrate_v1_chn_add_svc(channels, str, svcu.hex); + config_migrate_v1_chn_add_svc(channels, str, ubuf); } htsmsg_destroy(c); } @@ -163,6 +164,7 @@ config_migrate_v1_dvb_network { int i; tvh_uuid_t netu, muxu; + char ubuf[UUID_HEX_SIZE], ubuf2[UUID_HEX_SIZE]; htsmsg_t *e, *net, *mux, *tun; htsmsg_field_t *f; const char *str, *type; @@ -185,7 +187,7 @@ config_migrate_v1_dvb_network type = str; /* Create network entry */ - uuid_init_hex(&netu, NULL); + uuid_set(&netu, NULL); net = htsmsg_create_map(); if (!strcmp(str, "ATSC")) htsmsg_add_str(net, "class", "linuxdvb_network_atsc"); @@ -255,18 +257,20 @@ config_migrate_v1_dvb_network htsmsg_add_str(mux, "delsys", "DVBT"); /* Save */ - uuid_init_hex(&muxu, NULL); + uuid_set(&muxu, NULL); hts_settings_save(mux, "input/linuxdvb/networks/%s/muxes/%s/config", - netu.hex, muxu.hex); + uuid_get_hex(&netu, ubuf), + uuid_get_hex(&muxu, ubuf2)); htsmsg_destroy(mux); /* Services */ - config_migrate_v1_dvb_svcs(f->hmf_name, netu.hex, muxu.hex, channels); + config_migrate_v1_dvb_svcs(f->hmf_name, ubuf, ubuf2, channels); } /* Add properties derived from network */ htsmsg_add_str(net, "networkname", name); - hts_settings_save(net, "input/linuxdvb/networks/%s/config", netu.hex); + hts_settings_save(net, "input/linuxdvb/networks/%s/config", + uuid_get_hex(&netu, ubuf)); htsmsg_destroy(net); } @@ -350,6 +354,10 @@ config_migrate_v1 ( void ) uint32_t u32; const char *str; char buf[1024]; + char ubufc[UUID_HEX_SIZE]; + char ubufn[UUID_HEX_SIZE]; + char ubufm[UUID_HEX_SIZE]; + char ubufs[UUID_HEX_SIZE]; htsmsg_t *channels = htsmsg_create_map(); /* Channels */ @@ -358,10 +366,10 @@ config_migrate_v1 ( void ) if (!(e = htsmsg_field_get_map(f))) continue; /* Build entry */ - uuid_init_hex(&chnu, NULL); + uuid_set(&chnu, NULL); m = htsmsg_create_map(); htsmsg_add_u32(m, "channelid", atoi(f->hmf_name)); - htsmsg_add_str(m, "uuid", chnu.hex); + htsmsg_add_str(m, "uuid", uuid_get_hex(&chnu, ubufc)); htsmsg_add_msg(m, "services", htsmsg_create_list()); if (!htsmsg_get_u32(e, "dvr_extra_time_pre", &u32)) htsmsg_add_u32(m, "dvr_pre_time", u32); @@ -386,14 +394,15 @@ config_migrate_v1 ( void ) if ((c = hts_settings_load_r(1, "iptvservices"))) { /* Create a network */ - uuid_init_hex(&netu, NULL); + uuid_set(&netu, NULL); m = htsmsg_create_map(); htsmsg_add_str(m, "networkname", "IPTV Network"); htsmsg_add_u32(m, "skipinitscan", 1); htsmsg_add_u32(m, "autodiscovery", 0); htsmsg_add_u32(m, "max_streams", 0); htsmsg_add_u32(m, "max_bandwidth", 0); - hts_settings_save(m, "input/iptv/networks/%s/config", netu.hex); + hts_settings_save(m, "input/iptv/networks/%s/config", + uuid_get_hex(&netu, ubufn)); htsmsg_destroy(m); /* Process services */ @@ -403,7 +412,7 @@ config_migrate_v1 ( void ) if (htsmsg_get_u32(e, "port", &u32)) continue; /* Create mux entry */ - uuid_init_hex(&muxu, NULL); + uuid_set(&muxu, NULL); m = htsmsg_create_map(); snprintf(buf, sizeof(buf), "udp://%s:%d", str, u32); htsmsg_add_str(m, "iptv_url", buf); @@ -415,11 +424,12 @@ config_migrate_v1 ( void ) !!htsmsg_get_u32_or_default(e, "disabled", 0)); htsmsg_add_u32(m, "initscan", 1); hts_settings_save(m, "input/iptv/networks/%s/muxes/%s/config", - netu.hex, muxu.hex); + ubufn, uuid_get_hex(&muxu, ubufm)); htsmsg_destroy(m); /* Create svc entry */ - uuid_init_hex(&svcu, NULL); + uuid_set(&svcu, NULL); + uuid_get_hex(&svcu, ubufs); m = htsmsg_create_map(); if (!htsmsg_get_u32(e, "pmt", &u32)) htsmsg_add_u32(m, "pmt", u32); @@ -429,10 +439,10 @@ config_migrate_v1 ( void ) htsmsg_add_u32(m, "disabled", u32); if ((str = htsmsg_get_str(e, "channelname"))) { htsmsg_add_str(m, "svcname", str); - config_migrate_v1_chn_add_svc(channels, str, svcu.hex); + config_migrate_v1_chn_add_svc(channels, str, ubufs); } hts_settings_save(m, "input/iptv/networks/%s/muxes/%s/services/%s", - netu.hex, muxu.hex, svcu.hex); + ubufn, ubufm, ubufs); htsmsg_destroy(m); } @@ -474,25 +484,27 @@ config_migrate_v2 ( void ) { htsmsg_t *m; tvh_uuid_t u; + char ubuf[UUID_HEX_SIZE]; char src[1024], dst[1024]; /* Do we have IPTV config to migrate ? */ if (hts_settings_exists("input/iptv/muxes")) { /* Create a dummy network */ - uuid_init_hex(&u, NULL); + uuid_set(&u, NULL); + uuid_get_hex(&u, ubuf); m = htsmsg_create_map(); htsmsg_add_str(m, "networkname", "IPTV Network"); htsmsg_add_u32(m, "skipinitscan", 1); htsmsg_add_u32(m, "autodiscovery", 0); - hts_settings_save(m, "input/iptv/networks/%s/config", u.hex); + hts_settings_save(m, "input/iptv/networks/%s/config", ubuf); htsmsg_destroy(m); /* Move muxes */ hts_settings_buildpath(src, sizeof(src), "input/iptv/muxes"); hts_settings_buildpath(dst, sizeof(dst), - "input/iptv/networks/%s/muxes", u.hex); + "input/iptv/networks/%s/muxes", ubuf); rename(src, dst); } } @@ -659,6 +671,7 @@ config_migrate_simple ( const char *dir, htsmsg_t *list, htsmsg_t *c, *e; htsmsg_field_t *f; tvh_uuid_t u; + char ubuf[UUID_HEX_SIZE]; uint32_t index = 1, id; if (!(c = hts_settings_load(dir))) @@ -666,7 +679,8 @@ config_migrate_simple ( const char *dir, htsmsg_t *list, HTSMSG_FOREACH(f, c) { if (!(e = htsmsg_field_get_map(f))) continue; - uuid_init_hex(&u, NULL); + uuid_set(&u, NULL); + uuid_get_hex(&u, ubuf); if (htsmsg_get_u32(e, "id", &id)) id = 0; else if (list) { @@ -674,14 +688,14 @@ config_migrate_simple ( const char *dir, htsmsg_t *list, char buf[16]; snprintf(buf, sizeof(buf), "%d", id); htsmsg_add_str(m, "id", buf); - htsmsg_add_str(m, "uuid", u.hex); + htsmsg_add_str(m, "uuid", ubuf); htsmsg_add_msg(list, NULL, m); } htsmsg_delete_field(e, "id"); htsmsg_add_u32(e, "index", index++); if (modify) - modify(e, id, u.hex, aux); - hts_settings_save(e, "%s/%s", dir, u.hex); + modify(e, id, ubuf, aux); + hts_settings_save(e, "%s/%s", dir, ubuf); hts_settings_remove("%s/%s", dir, f->hmf_name); } @@ -798,7 +812,7 @@ config_modify_dvr_log( htsmsg_t *c, uint32_t id, const char *uuid, const void *a uint32_t u32; htsmsg_delete_field(c, "index"); - if (chname == NULL || (chuuid != NULL && uuid_init_bin(&uuid0, chuuid))) { + if (chname == NULL || (chuuid != NULL && uuid_set(&uuid0, chuuid))) { chname = strdup(chuuid ?: ""); htsmsg_delete_field(c, "channelname"); htsmsg_delete_field(c, "channel"); @@ -834,6 +848,7 @@ config_migrate_v9 ( void ) htsmsg_t *c, *e; htsmsg_field_t *f; tvh_uuid_t u; + char ubuf[UUID_HEX_SIZE]; config_migrate_simple("autorec", list, config_modify_autorec, NULL); config_migrate_simple("dvr/log", NULL, config_modify_dvr_log, list); @@ -845,9 +860,9 @@ config_migrate_v9 ( void ) if (!(e = htsmsg_field_get_map(f))) continue; if (strcmp(f->hmf_name, "config")) continue; htsmsg_add_str(e, "name", f->hmf_name + 6); - uuid_init_hex(&u, NULL); + uuid_set(&u, NULL); hts_settings_remove("dvr/%s", f->hmf_name); - hts_settings_save(e, "dvr/config/%s", u.hex); + hts_settings_save(e, "dvr/config/%s", uuid_get_hex(&u, ubuf)); } /* step 2: reset (without "config") */ HTSMSG_FOREACH(f, c) { @@ -855,9 +870,9 @@ config_migrate_v9 ( void ) if (strcmp(f->hmf_name, "config") == 0) continue; if (strncmp(f->hmf_name, "config", 6)) continue; htsmsg_add_str(e, "name", f->hmf_name + 6); - uuid_init_hex(&u, NULL); + uuid_set(&u, NULL); hts_settings_remove("dvr/%s", f->hmf_name); - hts_settings_save(e, "dvr/config/%s", u.hex); + hts_settings_save(e, "dvr/config/%s", uuid_get_hex(&u, ubuf)); } htsmsg_destroy(c); } @@ -1243,6 +1258,7 @@ config_migrate_v19 ( void ) htsmsg_field_t *f; const char *username, *passwd; tvh_uuid_t u; + char ubuf[UUID_HEX_SIZE]; if ((c = hts_settings_load("accesscontrol")) != NULL) { HTSMSG_FOREACH(f, c) { @@ -1254,8 +1270,8 @@ config_migrate_v19 ( void ) m = htsmsg_create_map(); htsmsg_add_str(m, "username", username); htsmsg_add_str(m, "password2", passwd); - uuid_init_hex(&u, NULL); - hts_settings_save(m, "passwd/%s", u.hex); + uuid_set(&u, NULL); + hts_settings_save(m, "passwd/%s", uuid_get_hex(&u, ubuf)); htsmsg_delete_field(e, "password2"); hts_settings_save(e, "accesscontrol/%s", f->hmf_name); } @@ -1367,6 +1383,7 @@ config_migrate_v23_one ( const char *modname ) uint32_t maj, min; int64_t num; tvh_uuid_t u; + char ubuf[UUID_HEX_SIZE]; if ((c = hts_settings_load_r(1, "epggrab/%s/channels", modname)) != NULL) { HTSMSG_FOREACH(f, c) { @@ -1381,9 +1398,9 @@ config_migrate_v23_one ( const char *modname ) htsmsg_add_s64(n, "lcn", num); htsmsg_delete_field(n, "major"); htsmsg_delete_field(n, "minor"); - uuid_init_hex(&u, NULL); + uuid_set(&u, NULL); hts_settings_remove("epggrab/%s/channels/%s", modname, f->hmf_name); - hts_settings_save(n, "epggrab/%s/channels/%s", modname, u.hex); + hts_settings_save(n, "epggrab/%s/channels/%s", modname, uuid_get_hex(&u, ubuf)); htsmsg_destroy(n); } htsmsg_destroy(c); diff --git a/src/htsp_server.c b/src/htsp_server.c index 342ee68cb..a6f52df42 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -4067,7 +4067,7 @@ htsp_subscription_start(htsp_subscription_t *hs, const streaming_start_t *ss) { htsmsg_t *m,*streams, *c, *sourceinfo; const char *type; - tvh_uuid_t hex; + char ubuf[UUID_HEX_SIZE]; int i; const source_info_t *si; @@ -4143,18 +4143,15 @@ htsp_subscription_start(htsp_subscription_t *hs, const streaming_start_t *ss) htsmsg_add_msg(m, "streams", streams); si = &ss->ss_si; - if(!uuid_empty(&si->si_adapter_uuid)) { - uuid_bin2hex(&si->si_adapter_uuid, &hex); - htsmsg_add_str(sourceinfo, "adapter_uuid", hex.hex); - } - if(!uuid_empty(&si->si_mux_uuid)) { - uuid_bin2hex(&si->si_mux_uuid, &hex); - htsmsg_add_str(sourceinfo, "mux_uuid", hex.hex); - } - if(!uuid_empty(&si->si_network_uuid)) { - uuid_bin2hex(&si->si_network_uuid, &hex); - htsmsg_add_str(sourceinfo, "network_uuid", hex.hex); - } + if(!uuid_empty(&si->si_adapter_uuid)) + htsmsg_add_str(sourceinfo, "adapter_uuid", + uuid_get_hex(&si->si_adapter_uuid, ubuf)); + if(!uuid_empty(&si->si_mux_uuid)) + htsmsg_add_str(sourceinfo, "mux_uuid", + uuid_get_hex(&si->si_mux_uuid, ubuf)); + if(!uuid_empty(&si->si_network_uuid)) + htsmsg_add_str(sourceinfo, "network_uuid", + uuid_get_hex(&si->si_network_uuid, ubuf)); if (!htsp_anonymize(hs->hs_htsp)) { htsmsg_add_str2(sourceinfo, "adapter", si->si_adapter ); htsmsg_add_str2(sourceinfo, "mux", si->si_mux ); diff --git a/src/idnode.c b/src/idnode.c index 4e5c394e7..2dd4b4212 100644 --- a/src/idnode.c +++ b/src/idnode.c @@ -104,7 +104,7 @@ idnode_insert(idnode_t *in, const char *uuid, const idclass_t *class, int flags) in->in_class = class; do { - if (uuid_init_bin(&u, uuid)) { + if (uuid_set(&u, uuid)) { in->in_class = NULL; return -1; } diff --git a/src/input/mpegts/linuxdvb/linuxdvb_adapter.c b/src/input/mpegts/linuxdvb/linuxdvb_adapter.c index e13784fe3..69c4ecd6e 100644 --- a/src/input/mpegts/linuxdvb/linuxdvb_adapter.c +++ b/src/input/mpegts/linuxdvb/linuxdvb_adapter.c @@ -198,7 +198,6 @@ linuxdvb_adapter_create la->la_rootpath = strdup(path); la->la_name = strdup(buf); la->la_dvb_number = number; - /* Callbacks */ la->la_is_enabled = linuxdvb_adapter_is_enabled; @@ -215,22 +214,23 @@ linuxdvb_adapter_new(const char *path, int a, const char *name, linuxdvb_adapter_t *la; SHA_CTX sha1; uint8_t uuidbin[20]; - tvh_uuid_t uuid; + char uhex[UUID_HEX_SIZE]; /* Create hash for adapter */ SHA1_Init(&sha1); SHA1_Update(&sha1, (void*)path, strlen(path)); SHA1_Update(&sha1, (void*)name, strlen(name)); SHA1_Final(uuidbin, &sha1); - bin2hex(uuid.hex, sizeof(uuid.hex), uuidbin, sizeof(uuidbin)); + + bin2hex(uhex, sizeof(uhex), uuidbin, sizeof(uuidbin)); /* Load config */ - *conf = hts_settings_load("input/linuxdvb/adapters/%s", uuid.hex); + *conf = hts_settings_load("input/linuxdvb/adapters/%s", uhex); if (*conf == NULL) *save = 1; /* Create */ - if (!(la = linuxdvb_adapter_create(uuid.hex, *conf, path, a, display_name))) { + if (!(la = linuxdvb_adapter_create(uhex, *conf, path, a, display_name))) { htsmsg_destroy(*conf); *conf = NULL; return NULL; diff --git a/src/input/mpegts/satip/satip.c b/src/input/mpegts/satip/satip.c index 4b9b0f5e4..766c9f5f5 100644 --- a/src/input/mpegts/satip/satip.c +++ b/src/input/mpegts/satip/satip.c @@ -537,12 +537,12 @@ satip_device_calc_bin_uuid( uint8_t *uuid, const char *satip_uuid ) } static void -satip_device_calc_uuid( tvh_uuid_t *uuid, const char *satip_uuid ) +satip_device_calc_uuid( char *uuid, const char *satip_uuid ) { uint8_t uuidbin[20]; sha1_calc(uuidbin, (const uint8_t *)satip_uuid, strlen(satip_uuid), NULL, 0); - bin2hex(uuid->hex, sizeof(uuid->hex), uuidbin, sizeof(uuidbin)); + bin2hex(uuid, UUID_HEX_SIZE, uuidbin, sizeof(uuidbin)); } static void @@ -590,7 +590,7 @@ static satip_device_t * satip_device_create( satip_device_info_t *info ) { satip_device_t *sd = calloc(1, sizeof(satip_device_t)); - tvh_uuid_t uuid; + char uhex[UUID_HEX_SIZE]; htsmsg_t *conf = NULL, *feconf = NULL; char *argv[10], *tunercfg; int i, j, n, m, fenum, v2, save = 0; @@ -599,9 +599,9 @@ satip_device_create( satip_device_info_t *info ) sd->sd_inload = 1; - satip_device_calc_uuid(&uuid, info->uuid); + satip_device_calc_uuid(uhex, info->uuid); - conf = hts_settings_load("input/satip/adapters/%s", uuid.hex); + conf = hts_settings_load("input/satip/adapters/%s", uhex); /* some sane defaults */ sd->sd_fast_switch = 1; @@ -613,7 +613,7 @@ satip_device_create( satip_device_info_t *info ) sd->sd_dbus_allow = 1; if (!tvh_hardware_create0((tvh_hardware_t*)sd, &satip_device_class, - uuid.hex, conf)) { + uhex, conf)) { /* Note: sd is freed in above fcn */ return NULL; } diff --git a/src/input/mpegts/tvhdhomerun/tvhdhomerun.c b/src/input/mpegts/tvhdhomerun/tvhdhomerun.c index 38372e024..7e4f0d76d 100644 --- a/src/input/mpegts/tvhdhomerun/tvhdhomerun.c +++ b/src/input/mpegts/tvhdhomerun/tvhdhomerun.c @@ -263,12 +263,12 @@ tvhdhomerun_device_calc_bin_uuid( uint8_t *uuid, const uint32_t device_id ) } static void -tvhdhomerun_device_calc_uuid( tvh_uuid_t *uuid, const uint32_t device_id ) +tvhdhomerun_device_calc_uuid( char *uhex, const uint32_t device_id ) { uint8_t uuidbin[20]; tvhdhomerun_device_calc_bin_uuid(uuidbin, device_id); - bin2hex(uuid->hex, sizeof(uuid->hex), uuidbin, sizeof(uuidbin)); + bin2hex(uhex, UUID_HEX_SIZE, uuidbin, sizeof(uuidbin)); } static tvhdhomerun_device_t * @@ -293,12 +293,12 @@ static void tvhdhomerun_device_create(struct hdhomerun_discover_device_t *dInfo) tvhdhomerun_device_t *hd = calloc(1, sizeof(tvhdhomerun_device_t)); htsmsg_t *conf = NULL, *feconf = NULL; - tvh_uuid_t uuid; + char uhex[UUID_HEX_SIZE]; int j, save = 0; struct hdhomerun_device_t *hdhomerun_tuner; dvb_fe_type_t type = DVB_TYPE_C; - tvhdhomerun_device_calc_uuid(&uuid, dInfo->device_id); + tvhdhomerun_device_calc_uuid(uhex, dInfo->device_id); hdhomerun_tuner = hdhomerun_device_create(dInfo->device_id, dInfo->ip_addr, 0, NULL); { @@ -309,7 +309,7 @@ static void tvhdhomerun_device_create(struct hdhomerun_discover_device_t *dInfo) hdhomerun_device_destroy(hdhomerun_tuner); } - conf = hts_settings_load("input/tvhdhomerun/adapters/%s", uuid.hex); + conf = hts_settings_load("input/tvhdhomerun/adapters/%s", uhex); if ( conf != NULL ) { const char *override_type = htsmsg_get_str(conf, "fe_override"); @@ -337,7 +337,7 @@ static void tvhdhomerun_device_create(struct hdhomerun_discover_device_t *dInfo) hd->hd_pids_deladd = 1; if (!tvh_hardware_create0((tvh_hardware_t*)hd, &tvhdhomerun_device_class, - uuid.hex, conf)) + uhex, conf)) return; TAILQ_INIT(&hd->hd_frontends); @@ -352,7 +352,7 @@ static void tvhdhomerun_device_create(struct hdhomerun_discover_device_t *dInfo) memset(&hd->hd_info.ip_address, 0, sizeof(hd->hd_info.ip_address)); hd->hd_info.ip_address.ss_family = AF_INET; ((struct sockaddr_in *)&hd->hd_info.ip_address)->sin_addr.s_addr = htonl(dInfo->ip_addr); - hd->hd_info.uuid = strdup(uuid.hex); + hd->hd_info.uuid = strdup(uhex); hd->hd_info.friendlyname = strdup(fName); if (conf) diff --git a/src/satip/server.c b/src/satip/server.c index ba05491b9..7c9c242b7 100644 --- a/src/satip/server.c +++ b/src/satip/server.c @@ -1071,7 +1071,7 @@ void satip_server_register(void) if (satip_server_conf.satip_uuid == NULL) { /* This is not UPnP complaint UUID */ - if (uuid_init_bin(&u, NULL)) { + if (uuid_set(&u, NULL)) { tvherror(LS_SATIPS, "Unable to create UUID"); return; } diff --git a/src/uuid.c b/src/uuid.c index a2439e4e2..80684151a 100644 --- a/src/uuid.c +++ b/src/uuid.c @@ -114,15 +114,19 @@ uuid_random ( uint8_t *buf, size_t bufsize ) /* Initialise binary */ int -uuid_init_bin ( tvh_uuid_t *u, const char *str ) +uuid_set ( tvh_uuid_t *u, const char *str ) { - memset(u, 0, sizeof(tvh_uuid_t)); if (str) { if (strlen(str) != UUID_HEX_SIZE - 1) { - tvherror(LS_UUID, "wrong uuid size"); + memset(u, 0, sizeof(*u)); + tvherror(LS_UUID, "wrong uuid string size (%zd)", strlen(str)); + return -EINVAL; + } + if (hex2bin(u->bin, sizeof(u->bin), str)) { + memset(u, 0, sizeof(*u)); + tvherror(LS_UUID, "wrong uuid string '%s'", str); return -EINVAL; } - return hex2bin(u->bin, sizeof(u->bin), str); } else if (read(fd, u->bin, sizeof(u->bin)) != sizeof(u->bin)) { tvherror(LS_UUID, "failed to read from %s", RANDOM_PATH); return -EINVAL; @@ -131,39 +135,15 @@ uuid_init_bin ( tvh_uuid_t *u, const char *str ) } /* Initialise hex string */ -int -uuid_init_hex ( tvh_uuid_t *u, const char *str ) -{ - tvh_uuid_t tmp; - if (uuid_init_bin(&tmp, str)) - return 1; - return uuid_bin2hex(&tmp, u); -} - -/* Convert bin to hex string */ -int -uuid_bin2hex ( const tvh_uuid_t *a, tvh_uuid_t *b ) +char * +uuid_get_hex ( const tvh_uuid_t *u, char *dst ) { - tvh_uuid_t tmp; - memset(&tmp, 0, sizeof(tmp)); - bin2hex(tmp.hex, sizeof(tmp.hex), a->bin, sizeof(a->bin)); - memcpy(b, &tmp, sizeof(tmp)); - return 0; -} - -/* Convert hex string to bin (in place) */ -int -uuid_hex2bin ( const tvh_uuid_t *a, tvh_uuid_t *b ) -{ - tvh_uuid_t tmp; - memset(&tmp, 0, sizeof(tmp)); - if (hex2bin(tmp.bin, sizeof(tmp.bin), a->hex)) - return 1; - memcpy(b, &tmp, sizeof(tmp)); - return 0; + assert(dst); + bin2hex(dst, UUID_HEX_SIZE, u->bin, sizeof(u->bin)); + return dst; } -/* Validate hex string */ +/* Validate the hexadecimal representation of uuid */ int uuid_hexvalid ( const char *uuid ) { diff --git a/src/uuid.h b/src/uuid.h index 2daff1cbd..bdd854448 100644 --- a/src/uuid.h +++ b/src/uuid.h @@ -29,10 +29,7 @@ extern uint8_t ___uuid_empty[UUID_BIN_SIZE]; /* Structure to hold UUID */ typedef struct uuid { - union { - uint8_t bin[UUID_BIN_SIZE]; - char hex[UUID_HEX_SIZE]; - }; + uint8_t bin[UUID_BIN_SIZE]; } tvh_uuid_t; /* Initialise subsystem */ @@ -41,25 +38,11 @@ void uuid_init ( void ); /* Random bytes */ void uuid_random ( uint8_t *buf, size_t bufsize ); -/* Initialise binary */ -int uuid_init_bin ( tvh_uuid_t *u, const char *str ); +/* Set uuid */ +int uuid_set ( tvh_uuid_t *u, const char *str ); -/* Initialise hex string */ -int uuid_init_hex ( tvh_uuid_t *u, const char *str ); - -/** - * Convert bin to hex string - * - * Note: conversion is done such that a and b can be the same - */ -int uuid_bin2hex ( const tvh_uuid_t *a, tvh_uuid_t *b ); - -/** - * Convert hex string to bin (in place) - * - * Note: conversion is done such that a and b can be the same - */ -int uuid_hex2bin ( const tvh_uuid_t *a, tvh_uuid_t *b ); +/* Get hexa uuid, str must have length at least UUID_HEX_SIZE */ +char *uuid_get_hex ( const tvh_uuid_t *u, char *dst ); /** * Copy @@ -86,7 +69,7 @@ static inline int uuid_empty ( const tvh_uuid_t *a ) } /** - * Valid hex uuid + * Validate the hexadecimal representation of uuid */ int uuid_hexvalid ( const char *uuid );