Loading...
Searching...
No Matches
Mongo Utils

Various utility functions related to MongoDB. More...

## Functions

void | mongo_util_oid_init (gint32 machine_id)
| Intitialize the static ObjectID components.
guint8 * | mongo_util_oid_new (gint32 seq)
| Generate a new ObjectID.
guint8 * | mongo_util_oid_new_with_time (gint32 time, gint32 seq)
| Generate a new ObjectID, with a predefined timestamp.
gchar * | mongo_util_oid_as_string (const guint8 *oid)
| Convert an ObjectID to its string representation.
gboolean | mongo_util_parse_addr (const gchar *addr, gchar **host, gint *port)
| Parse a HOST:IP pair.

## Detailed Description

Various utility functions related to MongoDB.

## Function Documentation

## mongo_util_oid_as_string()

gchar * mongo_util_oid_as_string | ( | const guint8 * | oid | ) |

Convert an ObjectID to its string representation.

Turns a binary ObjectID into a hexadecimal string.

Parameters

  oid | is the binary ObjectID.

Returns
  A newly allocated string representation of the ObjectID, or NULL on error. It is the responsibility of the caller to free it once it is no longer needed.

## mongo_util_oid_init()

void mongo_util_oid_init | ( | gint32 | machine_id | ) |

Intitialize the static ObjectID components.

Parameters

  machine_id | is the machine id to use, or zero to generate one automatically.

This function needs to be called once, before any OIDs are generated. It is also a good idea to call it whenever the calling program's PID might change.

## mongo_util_oid_new()

guint8 * mongo_util_oid_new | ( | gint32 | seq | ) |

Generate a new ObjectID.

Based on the current time, the pre-determined pid and machine ID and a supplied sequence number, generate a new ObjectID.

The machine id and the PID are updated whenever mongo_util_oid_init() is called.

Parameters

  seq | is the sequence number to use.

Note
  The ObjectID has space for only 24 bits of sequence bytes, so it should be noted that while seq is 32 bits wide, only 24 of that will be used.

Returns
  A newly allocated ObjectID or NULL on error. Freeing it is the responsibility of the caller.

## mongo_util_oid_new_with_time()

guint8 * mongo_util_oid_new_with_time | ( | gint32 | time,
|  | gint32 | seq )

Generate a new ObjectID, with a predefined timestamp.

Based on the suppiled time and sequence number, and the pre-determined pid and machine ID, generate a new ObjectID.

The machine id and the PID are updated whenever mongo_util_oid_init() is called.

Parameters

  time | is the timestamp to use.
  seq | is the sequence number to use.

Note
  The ObjectID has space for only 24 bits of sequence bytes, so it should be noted that while seq is 32 bits wide, only 24 of that will be used.

Returns
  A newly allocated ObjectID or NULL on error. Freeing it is the responsibility of the caller.

## mongo_util_parse_addr()

gboolean mongo_util_parse_addr | ( | const gchar * | addr,
|  | gchar ** | host,
|  | gint * | port )

Parse a HOST:IP pair.

Given a HOST:IP pair, split it up into a host and a port. IPv6 addresses supported, the function cuts at the last ":".

Parameters

  addr | is the address to split.
  host | is a pointer to a string where the host part will be stored.
  port | is a pointer to an integer, where the port part will be stored.

Returns
  TRUE on success, FALSE otherwise. The host parameter will contain a newly allocated string on succes. On failiure, host will be set to NULL, and port to -1.