uuid.c File Reference
`#include "config.h"`
`#include "uuid.h"`
`#include "UpnpInet.h"`
`#include "UpnpStdInt.h"`
`#include <string.h>`
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <time.h>`
Include dependency graph for uuid.c:

## Data Structures

struct | uuid_state

## Macros

#define | CHECK(f1, f2) if (f1 != f2) return f1 < f2 ? -1 : 1;

## Functions

static int | read_state (uint16_t *clockseq, uuid_time_t *timestamp, uuid_node_t *node)
| Read UUID generator state from non-volatile store. More...
static void | write_state (uint16_t clockseq, uuid_time_t timestamp, uuid_node_t node)
| Save UUID generator state back to non-volatile storage. More...
static void | format_uuid_v1 (uuid_upnp *uid, uint16_t clock_seq, uuid_time_t timestamp, uuid_node_t node)
| Make a UUID from the timestamp, clockseq, and node ID. More...
static void | format_uuid_v3 (uuid_upnp *uid, unsigned char hash[16])
| Make a UUID from a (pseudo)random 128 bit number. More...
static void | get_current_time (uuid_time_t *timestamp)
| Get time as 60 bit 100ns ticks since whenever. More...
static uint16_t | true_random (void)
| generate a crypto-quality random number. This sample doesn't do that. More...
int | uuid_create (uuid_upnp *uid)
| Generator of a UUID. More...
void | upnp_uuid_unpack (uuid_upnp *u, char *out)
| Out will be xxxx-xx-xx-xx-xxxxxx format. More...
void | uuid_create_from_name (uuid_upnp *uid, uuid_upnp nsid, void *name, int namelen)
| Create a UUID using a "name" from a "name space". More...
int | uuid_compare (uuid_upnp *u1, uuid_upnp *u2)
| Compare two UUID's "lexically" and return. More...

## Variables

static uuid_state | st
static int | stateInited = 0

## Function Documentation

## format_uuid_v1()

void format_uuid_v1 | ( | uuid_upnp * | uid,
|  | uint16_t | clockseq,
|  | uuid_time_t | timestamp,
|  | uuid_node_t | node
| ) |  |

static

Make a UUID from the timestamp, clockseq, and node ID.

References _uuid_upnp::clock_seq_hi_and_reserved, _uuid_upnp::clock_seq_low, _uuid_upnp::node, _uuid_upnp::time_hi_and_version, _uuid_upnp::time_low, and _uuid_upnp::time_mid.

## format_uuid_v3()

void format_uuid_v3 | ( | uuid_upnp * | uid,
|  | unsigned char | hash[16]
| ) |  |

static

Make a UUID from a (pseudo)random 128 bit number.

References _uuid_upnp::clock_seq_hi_and_reserved, _uuid_upnp::time_hi_and_version, _uuid_upnp::time_low, and _uuid_upnp::time_mid.

Referenced by uuid_create_from_name().

## get_current_time()

void get_current_time | ( | uuid_time_t * | timestamp | ) |

static

Get time as 60 bit 100ns ticks since whenever.

Compensate for the fact that real clock resolution is less than 100ns.

References get_system_time(), and UUIDS_PER_TICK.

## read_state()

int read_state | ( | uint16_t * | clockseq,
|  | uuid_time_t * | timestamp,
|  | uuid_node_t * | node
| ) |  |

static

Read UUID generator state from non-volatile store.

## true_random()

static uint16_t true_random | ( | void |  | ) |

static

generate a crypto-quality random number. This sample doesn't do that.

References get_system_time(), and UUIDS_PER_TICK.

## upnp_uuid_unpack()

void upnp_uuid_unpack | ( | uuid_upnp * | u,
|  | char * | out
| ) |  |

Out will be xxxx-xx-xx-xx-xxxxxx format.

Parameters

  u | .
  out | .

References _uuid_upnp::clock_seq_hi_and_reserved, _uuid_upnp::clock_seq_low, _uuid_upnp::node, _uuid_upnp::time_hi_and_version, _uuid_upnp::time_low, and _uuid_upnp::time_mid.

## uuid_compare()

int uuid_compare | ( | uuid_upnp * | u1,
|  | uuid_upnp * | u2
| ) |  |

Compare two UUID's "lexically" and return.

Compare two UUID's "lexically".

- -1: u1 is lexically before u2
- 0: u1 is equal to u2
- 1: u1 is lexically after u2

Note: Lexical ordering is not temporal ordering!

Parameters

  u1 | .
  u2 | .

## uuid_create()

int uuid_create | ( | uuid_upnp * | uid | ) |

Generator of a UUID.

Generate a UUID.

Parameters

  uid | .

## uuid_create_from_name()

void uuid_create_from_name | ( | uuid_upnp * | uid,
|  | uuid_upnp | nsid,
|  | void * | name,
|  | int | namelen
| ) |  |

Create a UUID using a "name" from a "name space".

Parameters

  uid | resulting UUID.
  nsid | UUID to serve as context, so identical names from different name spaces generate different UUIDs.
  name | The name from which to generate a UUID.
  namelen | The length of the name.

References format_uuid_v3(), _uuid_upnp::time_hi_and_version, _uuid_upnp::time_low, and _uuid_upnp::time_mid.

## write_state()

void write_state | ( | uint16_t | clockseq,
|  | uuid_time_t | timestamp,
|  | uuid_node_t | node
| ) |  |

static

Save UUID generator state back to non-volatile storage.