File: uuid.h

package info (click to toggle)
libigloo 0.9.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,968 kB
  • sloc: ansic: 5,476; sh: 4,996; makefile: 62
file content (85 lines) | stat: -rw-r--r-- 2,858 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Copyright (C) 2022-2024  Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 */

#ifndef _LIBIGLOO__UUID_H_
#define _LIBIGLOO__UUID_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <igloo/types.h>

/* Creates a new random UUID (v4).
 *
 * This function generates a new random UUID providing a string pool reference.
 * This is the preferred way of working with string based UUIDs as it allows the reference to travel.
 * The reference must be freed with igloo_sp_unref().
 *
 * Parameters:
 *  ref
 *  instance
 *      Reference and instance as used by igloo_sp_replace().
 *
 * See also:
 *  * igloo_sp_replace().
 */
igloo_error_t igloo_uuid_new_random_sp(const char **ref, igloo_ro_t instance) igloo_ATTR_F_WARN_UNUSED_RESULT;

/* Creates a new random UUID (v4).
 *
 * This function generates a new random UUID providing a bare C string.
 * The string must later be freed with free(3).
 *
 * Parameters:
 *  ref
 *      A pointer to a C string. The C string MUST be NULL when this function is called. It will be updated
 *      to a newly created C string containing the UUID. It must be freed with free(3).
 *  instance
 *      The instance to use for the generation process.
 *      The instance may be un-referenced before the provided C string is free(3)ed.
 *
 * See also:
 *  * igloo_uuid_new_random_sp().
 */
igloo_error_t igloo_uuid_new_random_cstr(char **str, igloo_ro_t instance) igloo_ATTR_F_WARN_UNUSED_RESULT;

/* Check if a string is a valid UUID.
 *
 * This function checks a string for it being a valid UUID.
 * The strictness for the check can be given.
 *
 * Parameters:
 *  string
 *      The string to check.
 *  strictness
 *      The strictness to use.
 */
typedef enum {
    igloo_UUID_STRICTNESS_STRICT  = 0, /* only normal format */
    igloo_UUID_STRICTNESS_RELAXED = 1, /* mixed case allowed */
    igloo_UUID_STRICTNESS_LOOSE   = 2, /* mixed case, padding, and common pre/suffixes allowe */
} igloo_uuid_strictness_t;

igloo_error_t igloo_uuid_is_valid(const char *str, igloo_uuid_strictness_t strictness);

#ifdef __cplusplus
}
#endif

#endif /* ! _LIBIGLOO__UUID_H_ */