summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c41
-rw-r--r--src/shared/util.h2
2 files changed, 43 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 38ee493a81..f9ec14aff4 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5854,3 +5854,44 @@ void* greedy_realloc(void **p, size_t *allocated, size_t need) {
*allocated = a;
return q;
}
+
+bool id128_is_valid(const char *s) {
+ size_t i, l;
+
+ l = strlen(s);
+ if (l == 32) {
+
+ /* Simple formatted 128bit hex string */
+
+ for (i = 0; i < l; i++) {
+ char c = s[i];
+
+ if (!(c >= '0' && c <= '9') &&
+ !(c >= 'a' && c <= 'z') &&
+ !(c >= 'A' && c <= 'Z'))
+ return false;
+ }
+
+ } else if (l == 36) {
+
+ /* Formatted UUID */
+
+ for (i = 0; i < l; i++) {
+ char c = s[i];
+
+ if ((i == 8 || i == 13 || i == 18 || i == 23)) {
+ if (c != '-')
+ return false;
+ } else {
+ if (!(c >= '0' && c <= '9') &&
+ !(c >= 'a' && c <= 'z') &&
+ !(c >= 'A' && c <= 'Z'))
+ return false;
+ }
+ }
+
+ } else
+ return false;
+
+ return true;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index e3fc876857..5d1b0b1c31 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -733,3 +733,5 @@ static inline void _reset_locale_(struct _locale_struct_ *s) {
} \
!_saved_locale_.quit; }) ; \
_saved_locale_.quit = true)
+
+bool id128_is_valid(const char *s);