Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Xiph.Org
Icecast libigloo
Commits
4f733cba
Commit
4f733cba
authored
Feb 26, 2022
by
Philipp Schafft
🦁
Browse files
Feature: Implemented UUID generation
parent
d4a96a95
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/uuid.c
View file @
4f733cba
...
...
@@ -20,17 +20,72 @@
#include
<config.h>
#endif
#include
<stdio.h>
#include
<string.h>
#include
<igloo/uuid.h>
#include
<igloo/sp.h>
#include
<igloo/error.h>
#include
<igloo/prng.h>
#define UUID_LENGTH_BINARY 16
#define UUID_LENGTH_STRING 36
static
igloo_error_t
igloo_uuid_new_random_r
(
char
*
buffer
,
igloo_ro_t
instance
)
{
unsigned
char
id
[
UUID_LENGTH_BINARY
];
if
(
!
buffer
)
return
igloo_ERROR_FAULT
;
if
(
igloo_prng_read
(
instance
,
id
,
sizeof
(
id
),
igloo_PRNG_FLAG_NONE
)
!=
sizeof
(
id
))
return
igloo_ERROR_IO
;
id
[
6
]
=
(
id
[
6
]
&
0x0F
)
|
0x40
;
id
[
8
]
=
(
id
[
8
]
&
0x3F
)
|
0x80
;
// 0 1 2 3 4 5 6 7 8 9 101112131415
// 551a9547-fe63-45cf-a153-2801bac47ff8
snprintf
(
buffer
,
UUID_LENGTH_STRING
+
1
,
"%.2x%.2x%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x"
,
(
unsigned
int
)
id
[
0
],
(
unsigned
int
)
id
[
1
],
(
unsigned
int
)
id
[
2
],
(
unsigned
int
)
id
[
3
],
(
unsigned
int
)
id
[
4
],
(
unsigned
int
)
id
[
5
],
(
unsigned
int
)
id
[
6
],
(
unsigned
int
)
id
[
7
],
(
unsigned
int
)
id
[
8
],
(
unsigned
int
)
id
[
9
],
(
unsigned
int
)
id
[
10
],
(
unsigned
int
)
id
[
11
],
(
unsigned
int
)
id
[
12
],
(
unsigned
int
)
id
[
13
],
(
unsigned
int
)
id
[
14
],
(
unsigned
int
)
id
[
15
]
);
return
igloo_ERROR_NONE
;
}
igloo_error_t
igloo_uuid_new_random_sp
(
const
char
**
ref
,
igloo_ro_t
instance
)
{
return
igloo_ERROR_NOSYS
;
char
buffer
[
UUID_LENGTH_STRING
+
1
];
igloo_error_t
error
=
igloo_uuid_new_random_r
(
buffer
,
instance
);
if
(
error
!=
igloo_ERROR_NONE
)
return
error
;
return
igloo_sp_replace
(
buffer
,
ref
,
instance
);
}
igloo_error_t
igloo_uuid_new_random_cstr
(
char
**
str
,
igloo_ro_t
instance
)
{
return
igloo_ERROR_NOSYS
;
char
buffer
[
UUID_LENGTH_STRING
+
1
];
igloo_error_t
error
=
igloo_uuid_new_random_r
(
buffer
,
instance
);
char
*
res
;
if
(
!
str
||
*
str
)
return
igloo_ERROR_FAULT
;
if
(
error
!=
igloo_ERROR_NONE
)
return
error
;
res
=
strdup
(
buffer
);
if
(
res
==
NULL
)
return
igloo_ERROR_NOMEM
;
*
str
=
res
;
return
igloo_ERROR_NONE
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment