~ubuntu-branches/ubuntu/saucy/syslog-ng/saucy

« back to all changes in this revision

Viewing changes to modules/afmongodb/libmongo-client/src/mongo-utils.h

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2011-11-15 08:48:02 UTC
  • mfrom: (26.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20111115084802-n0jegdnjlxk0m26s
Tags: 3.3.1.dfsg-1ubuntu1
* debian/control: remove libsystemd-daemon-dev build-depends
* debian/rules: remove --with-systemdsystemunitdir from
  override_dh_auto_configure.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* mongo-utils.h - libmongo-client utility functions
 
2
 * Copyright 2011 Gergely Nagy <algernon@balabit.hu>
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
/** @file src/mongo-utils.h
 
18
 * Public header for various libmongo-client helper functions.
 
19
 */
 
20
 
 
21
#ifndef LIBMONGO_CLIENT_UTILS_H
 
22
#define LIBMONGO_CLIENT_UTILS_H 1
 
23
 
 
24
#include <glib.h>
 
25
 
 
26
G_BEGIN_DECLS
 
27
 
 
28
/** @defgroup mongo_util Mongo Utils
 
29
 *
 
30
 * Various utility functions related to MongoDB.
 
31
 *
 
32
 * @addtogroup mongo_util
 
33
 * @{
 
34
 */
 
35
 
 
36
/** Intitialize the static ObjectID components.
 
37
 *
 
38
 * @param machine_id is the machine id to use, or zero to generate one
 
39
 * automatically.
 
40
 *
 
41
 * This function needs to be called once, before any OIDs are
 
42
 * generated. It is also a good idea to call it whenever the calling
 
43
 * program's PID might change.
 
44
 */
 
45
void mongo_util_oid_init (gint32 machine_id);
 
46
 
 
47
/** Generate a new ObjectID.
 
48
 *
 
49
 * Based on the current time, the pre-determined pid and machine ID
 
50
 * and a supplied sequence number, generate a new ObjectID.
 
51
 *
 
52
 * The machine id and the PID are updated whenever
 
53
 * mongo_util_oid_init() is called.
 
54
 *
 
55
 * @param seq is the sequence number to use.
 
56
 *
 
57
 * @note The ObjectID has space for only 24 bits of sequence bytes, so
 
58
 * it should be noted that while @a seq is 32 bits wide, only 24 of
 
59
 * that will be used.
 
60
 *
 
61
 * @returns A newly allocated ObjectID or NULL on error. Freeing it is
 
62
 * the responsibility of the caller.
 
63
 */
 
64
guint8 *mongo_util_oid_new (gint32 seq);
 
65
 
 
66
/** Generate a new ObjectID, with a predefined timestamp.
 
67
 *
 
68
 * Based on the suppiled time and sequence number, and the
 
69
 * pre-determined pid and machine ID, generate a new ObjectID.
 
70
 *
 
71
 * The machine id and the PID are updated whenever
 
72
 * mongo_util_oid_init() is called.
 
73
 *
 
74
 * @param time is the timestamp to use.
 
75
 * @param seq is the sequence number to use.
 
76
 *
 
77
 *
 
78
 * @note The ObjectID has space for only 24 bits of sequence bytes, so
 
79
 * it should be noted that while @a seq is 32 bits wide, only 24 of
 
80
 * that will be used.
 
81
 *
 
82
 * @returns A newly allocated ObjectID or NULL on error. Freeing it is
 
83
 * the responsibility of the caller.
 
84
 */
 
85
guint8 *mongo_util_oid_new_with_time (gint32 time, gint32 seq);
 
86
 
 
87
/** Convert an ObjectID to its string representation.
 
88
 *
 
89
 * Turns a binary ObjectID into a hexadecimal string.
 
90
 *
 
91
 * @param oid is the binary ObjectID.
 
92
 *
 
93
 * @returns A newly allocated string representation of the ObjectID,
 
94
 * or NULL on error. It is the responsibility of the caller to free it
 
95
 * once it is no longer needed.
 
96
 */
 
97
gchar *mongo_util_oid_as_string (const guint8 *oid);
 
98
 
 
99
/** Parse a HOST:IP pair.
 
100
 *
 
101
 * Given a HOST:IP pair, split it up into a host and a port. IPv6
 
102
 * addresses supported, the function cuts at the last ":".
 
103
 *
 
104
 * @param addr is the address to split.
 
105
 * @param host is a pointer to a string where the host part will be
 
106
 * stored.
 
107
 * @param port is a pointer to an integer, where the port part will be
 
108
 * stored.
 
109
 *
 
110
 * @returns TRUE on success, FALSE otherwise. The @a host parameter
 
111
 * will contain a newly allocated string on succes. On failiure, host
 
112
 * will be set to NULL, and port to -1.
 
113
 */
 
114
gboolean mongo_util_parse_addr (const gchar *addr, gchar **host,
 
115
                                gint *port);
 
116
 
 
117
/** @} */
 
118
 
 
119
G_END_DECLS
 
120
 
 
121
#endif