1
/* libmongo-private.h - private headers for libmongo-client
2
* Copyright 2011 Gergely Nagy <algernon@balabit.hu>
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
/** @file libmongo-private.h
19
* Private types and functions, for internal use in libmongo-client only.
22
#ifndef LIBMONGO_PRIVATE_H
23
#define LIBMONGO_PRIVATE_H 1
28
/** @internal BSON structure.
32
GByteArray *data; /**< The actual data of the BSON object. */
33
gboolean finished; /**< Flag to indicate whether the object is open
37
/** @internal Mongo Connection state object. */
38
struct _mongo_connection
40
gint fd; /**< The file descriptor associated with the connection. */
41
gint32 request_id; /**< The last sent command's requestID. */
44
/** @internal Synchronous connection object. */
45
struct _mongo_sync_connection
47
mongo_connection super; /**< The parent object. */
48
gboolean slaveok; /**< Whether queries against slave nodes are
50
gboolean safe_mode; /**< Safe-mode signal flag. */
51
gboolean auto_reconnect; /**< Auto-reconnect flag. */
55
GList *seeds; /**< Replica set seeds, as a list of strings. */
56
GList *hosts; /**< Replica set members, as a list of strings. */
57
gchar *primary; /**< The replica master, if any. */
58
} rs; /**< Replica Set properties. */
60
gchar *last_error; /**< The last error from the server, caught
62
gint32 max_insert_size; /**< Maximum number of bytes an insert
63
command can be before being split to
64
smaller chunks. Used for bulk inserts. */
67
/** @internal MongoDB cursor object.
69
* The cursor object can be used to conveniently iterate over a query
72
struct _mongo_sync_cursor
74
mongo_sync_connection *conn; /**< The connection associated with
75
the cursor. Owned by the caller. */
76
gchar *ns; /**< The namespace of the cursor. */
77
mongo_packet *results; /**< The current result set, as a mongo
80
gint32 offset; /**< Offset of the cursor within the active result
82
mongo_reply_packet_header ph; /**< The reply headers extracted from
83
the active result set. */
86
/** @internal Synchronous pool connection object. */
87
struct _mongo_sync_pool_connection
89
mongo_sync_connection super; /**< The parent object. */
91
gint pool_id; /**< ID of the connection. */
92
gboolean in_use; /**< Whether the object is in use or not. */
95
/** @internal GridFS object */
96
struct _mongo_sync_gridfs
98
mongo_sync_connection *conn; /**< Connection the object is
103
gchar *prefix; /**< The namespace prefix. */
104
gchar *files; /**< The file metadata namespace. */
105
gchar *chunks; /**< The chunk namespace. */
107
gchar *db; /**< The database part of the namespace. */
108
} ns; /**< Namespaces */
110
gint32 chunk_size; /**< The default chunk size. */
113
/** @internal GridFS file types. */
116
LMC_GRIDFS_FILE_CHUNKED, /**< Chunked file. */
117
LMC_GRIDFS_FILE_STREAM_READER, /**< Streamed file, reader. */
118
LMC_GRIDFS_FILE_STREAM_WRITER, /**< Streamed file, writer. */
119
} _mongo_gridfs_type;
121
/** @internal GridFS common file properties.
123
* This is shared between chunked and streamed files.
127
gint32 chunk_size; /**< Maximum chunk size for this file. */
128
gint64 length; /**< Total length of the file. */
132
/** Chunked file data. */
135
const guint8 *oid; /**< The file's ObjectID. */
136
const gchar *md5; /**< MD5 sum of the file. */
137
gint64 date; /**< The upload date. */
138
bson *metadata; /**< Full file metadata, including user-set
142
/** Streamed file data */
145
gint64 offset; /**< Offset we're into the file. */
146
gint64 current_chunk; /**< The current chunk we're on. */
147
guint8 *id; /**< A copy of the file's ObjectID. */
151
_mongo_gridfs_type type; /**< The type of the GridFS file. */
152
} mongo_sync_gridfs_file_common;
154
/** @internal GridFS file object. */
155
struct _mongo_sync_gridfs_chunked_file
157
mongo_sync_gridfs_file_common meta; /**< The file metadata. */
158
mongo_sync_gridfs *gfs; /**< The GridFS the file is on. */
161
/** @internal GridFS file stream object. */
162
struct _mongo_sync_gridfs_stream
164
mongo_sync_gridfs_file_common file; /**< Common file data. */
165
mongo_sync_gridfs *gfs; /**< The GridFS the file is on. */
167
/** Reader & Writer structure union.
171
/** Reader-specific data.
175
bson *bson; /**< The current chunk as BSON. */
177
/** Chunk state information.
181
const guint8 *data; /**< The current chunk data, pointing
182
into ->reader.bson. */
183
gint32 size; /**< Size of the current chunk. */
184
gint32 offset; /**< Offset we're into the chunk. */
188
/** Writer-specific data.
192
bson *metadata; /**< Copy of the user-supplied metadata. */
193
guint8 *buffer; /**< The current output buffer. */
194
gint32 buffer_offset; /**< Offset into the output buffer. */
196
GChecksum *checksum; /**< The running checksum of the output
202
/** @internal Construct a kill cursors command, using a va_list.
204
* @param id is the sequence id.
205
* @param n is the number of cursors to delete.
206
* @param ap is the va_list of cursors to kill.
208
* @note One must supply exaclty @a n number of cursor IDs.
210
* @returns A newly allocated packet, or NULL on error. It is the
211
* responsibility of the caller to free the packet once it is not used
214
mongo_packet *mongo_wire_cmd_kill_cursors_va (gint32 id, gint32 n,
217
/** @internal Get the header data of a packet, without conversion.
219
* Retrieve the mongo packet's header data, but do not convert the
220
* values from little-endian. Use only when the source has the data in
221
* the right byte order already.
223
* @param p is the packet which header we seek.
224
* @param header is a pointer to a variable which will hold the data.
226
* @note Allocating the @a header is the responsibility of the caller.
228
* @returns TRUE on success, FALSE otherwise.
231
mongo_wire_packet_get_header_raw (const mongo_packet *p,
232
mongo_packet_header *header);
234
/** @internal Set the header data of a packet, without conversion.
236
* Override the mongo packet's header data, but do not convert the
237
* values from little-endian. Use only when the source has the data in
238
* the right byte order already.
240
* @note No sanity checks are done, use this function with great care.
242
* @param p is the packet whose header we want to override.
243
* @param header is the header structure to use.
245
* @returns TRUE on success, FALSE otherwise.
248
mongo_wire_packet_set_header_raw (mongo_packet *p,
249
const mongo_packet_header *header);