rpm  5.4.15
Data Structures | Functions | Variables
bson.c File Reference
#include "system.h"
#include <stdarg.h>
#include "bson.h"
#include "debug.h"
Include dependency graph for bson.c:

Go to the source code of this file.

Data Structures

union  _dbswap
 

Functions

void bson_little_endian64 (void *outp, const void *inp)
 
void bson_little_endian32 (void *outp, const void *inp)
 
void bson_big_endian64 (void *outp, const void *inp)
 
void bson_big_endian32 (void *outp, const void *inp)
 
static int isLegalUTF8 (const unsigned char *source, int length)
 
static int bson_string_is_db_ref (const unsigned char *string, const size_t length)
 
static int bson_validate_string (bson *b, const unsigned char *string, const size_t length, const char check_utf8, const char check_dot, const char check_dollar)
 
static int bson_check_string (bson *b, const char *string, const size_t length)
 
static int bson_check_field_name (bson *b, const char *string, const size_t length)
 
static int _bson_errprintf (const char *,...)
 
static void _bson_zero (bson *b)
 
static size_t _bson_position (const bson *b)
 
 __declspec (dllimport)
 Allocate memory for a new BSON object. More...
 
static int bson_finished_data_size (const char *data)
 
int bson_init_finished_data (bson *b, char *data, bson_bool_t ownsData)
 Initialize a BSON object for reading and set its data pointer to the provided char*. More...
 
int bson_init_finished_data_with_copy (bson *b, const char *data)
 Initialize a BSON object for reading and copy finalized BSON data from the provided char*. More...
 
static char hexbyte (char hex)
 
int bson_iterator_int_raw (const bson_iterator *i)
 Get the int value of the BSON object currently pointed to by the iterator. More...
 
double bson_iterator_double_raw (const bson_iterator *i)
 Get the double value of the BSON object currently pointed to by the iterator. More...
 
int64_t bson_iterator_long_raw (const bson_iterator *i)
 Get the long value of the BSON object currently pointed to by the iterator. More...
 
bson_bool_t bson_iterator_bool_raw (const bson_iterator *i)
 Get the bson_bool_t value of the BSON object currently pointed to by the iterator. More...
 
int bson_iterator_string_len (const bson_iterator *i)
 Get the string length of the BSON object currently pointed to by the iterator. More...
 
int bson_init_size (bson *b, int size)
 Initialize a BSON object for building and allocate a data buffer of a given size. More...
 
int bson_init_unfinished_data (bson *b, char *data, int dataSize, bson_bool_t ownsData)
 Initialize a BSON object for building, using the provided char* of the given size. More...
 
static int _bson_append_grow_stack (bson *b)
 
static void bson_append_byte (bson *b, char c)
 
static void bson_append (bson *b, const void *data, size_t len)
 
static void bson_append32 (bson *b, const void *data)
 
static void bson_append32_as_int (bson *b, int data)
 
static void bson_append64 (bson *b, const void *data)
 
int bson_ensure_space (bson *b, const size_t bytesNeeded)
 Grow a bson object. More...
 
static int bson_append_estart (bson *b, int type, const char *name, const size_t dataSize)
 
static int bson_append_string_base (bson *b, const char *name, const char *value, size_t len, bson_type type)
 
void * bson_realloc (void *ptr, size_t size)
 Changes the size of allocated memory and checks return value, exiting fatally if realloc() fails. More...
 
void bson_builder_error (bson *b)
 This method is invoked when a non-fatal bson error is encountered. More...
 
void bson_fatal (int ok)
 Exit fatally. More...
 
void bson_fatal_msg (int ok, const char *msg)
 Exit fatally with an error message. More...
 
void bson_numstr (char *str, int i)
 

Variables

static const int initialBufferSize = 128
 
static const int zero = 0
 
static const char trailingBytesForUTF8 [256]
 
const char bson_numstrs [1000][4]
 
static char bson_shared_empty_data [] = {5,0,0,0,0}
 
void *(* bson_malloc_func )(size_t) = malloc
 
void *(* bson_realloc_func )(void *, size_t) = realloc
 
void(* bson_free_func )(void *) = free
 
bson_printf_func bson_printf = printf
 
bson_fprintf_func bson_fprintf = fprintf
 
bson_sprintf_func bson_sprintf = sprintf
 
bson_printf_func bson_errprintf = _bson_errprintf
 
static int(* oid_fuzz_func )(void) = NULL
 
static int(* oid_inc_func )(void) = NULL
 
static bson_err_handler err_handler = NULL
 

Function Documentation

__declspec ( dllimport  )

Allocate memory for a new BSON object.

Clear all errors stored on a mongo connection object.

Set an error on a mongo connection object.

Reset the error state for the connection.

Get the most recent error with the current connection.

Get the error for the last command with the current connection.

Check if the current server is a master.

Authenticate a user.

Add a database user.

Drop a collection.

Drop a database.

Run a command that accepts a simple string key and value.

Run a command that accepts a simple string key and integer value.

Run a command on a MongoDB server.

Create a capped collection.

Create an index with a single key.

Create a compound index.

Count the number of documents in a collection matching a query.

Find a single document in a MongoDB server.

Destroy a cursor object.

Iterate the cursor, returning the next item.

Return the current BSON object data as a const char*.

Set any of the available query options (e.g., MONGO_TAILABLE).

Set the number of documents to return.

Set the number of documents to skip.

Set the fields to return for this cursor.

Set the bson object specifying this cursor's query spec.

Initalize a new cursor object.

Find documents in a MongoDB server.

Free the write_concern object (specifically, the BSON that it owns).

Finish this write concern object by serializing the literal getlasterror command that will be sent to the server.

Initialize a mongo_write_concern object.

Remove a document from a MongoDB server.

Update a document in a MongoDB server.

Insert a batch of BSON documents into a MongoDB server.

Insert a BSON document into a MongoDB server.

The following functions set the attributes of the write_concern object.

The following functions get the attributes of the write_concern object.

Specify the write concern object that this connection should use by default for all writes (inserts, updates, and deletes).

Close any existing connection to the server and free all allocated memory associated with the conn object.

Close the current connection to the server.

Try reconnecting to the server using the existing connection settings.

Ensure that this connection is healthy by performing a round-trip to the server.

Set a timeout for operations on this connection.

DEPRECATED - use mongo_replica_set_client.

Connect to a replica set.

Utility function for validation database and collection names.

DEPRECATED - use mongo_replica_set_add_seed.

Add a seed node to the replica set connection object.

DEPRECATED - use mongo_replica_set_init.

Set up this connection object for connecting to a replica set.

DEPRECATED - use mongo_client.

Connect to a single MongoDB server.

Initialize a new mongo connection object.

Cast an int64_t to double.

Set a function for error handling.

Allocates memory and checks return value, exiting fatally if malloc() fails.

Finish appending a new object or array to a bson.

Start appending a new array to a bson.

Start appending a new object to a bson.

Append a time_t value to a bson.

Append a bson_date_t value to a bson.

Append a bson_timestamp_t value to a bson.

Append a BSON element to a bson from the current point of an iterator.

Append bson data to a bson.

Append a regex value to a bson.

Append a minkey value to a bson.

Append a maxkey value to a bson.

Append an undefined value to a bson.

Append a null value to a bson.

Append a bson_bool_t to a bson.

Append binary data to a bson.

Append len bytes of code to a bson with scope.

Append code to a bson with scope.

Append len bytes of code to a bson.

Append code to a bson.

Append len bytes of a symbol to a bson.

Append a symbol to a bson.

Append len bytes of a string to a bson.

Append a string to a bson.

Append an double to a bson.

Append an long to a bson.

Append an int to a bson.

Append a bson_oid_t to a bson.

Append a previously created bson_oid_t to a bson object.

Make a complete copy of the a BSON object.

Return a pointer to an empty, shared, static BSON object.

Initialize a BSON object to an emoty object with a shared, static data buffer.

Destroy a bson object and deallocate its data buffer.

Finalize a bson object.

Initialize a BSON object for building and allocate a data buffer.

Get the time a bson_oid_t was created.

Set a function to be used to generate the incrementing part of an object id (last four bytes).

Set a function to be used to generate the second four bytes of an object id.

Create a bson_oid object.

Create a string representation of the bson_oid_t.

Create a bson_oid_t from a string.

Get a bson_iterator that on the BSON subobject.

Get the BSON subobject currently pointed to by the iterator.

Get the options of the BSON regex object currently pointed to by the iterator.

Get the value of the BSON regex object currently pointed to by the iterator.

Get the value of the BSON binary object currently pointed to by the iterator.

Get the type of the BSON binary object currently pointed to by the iterator.

Get the length of the BSON binary object currently pointed to by the iterator.

Get the time value of the BSON object currently pointed to by the iterator.

Get the date value of the BSON object currently pointed to by the iterator.

Get the code scope value of the BSON object currently pointed to by the iterator.

Get the code value of the BSON object currently pointed to by the iterator.

Get the string value of the BSON object currently pointed to by the iterator.

Get the bson_oid_t value of the BSON object currently pointed to by the iterator.

Get the boolean value of the BSON object currently pointed to by the iterator.

Get the timestamp value of the BSON object currently pointed to by the iterator.

Get the long value of the BSON object currently pointed to by the iterator.

Get the int value of the BSON object currently pointed to by the iterator.

Get the double value of the BSON object currently pointed to by the iterator.

Get the value of the BSON object currently pointed to by the iterator.

Get the key of the BSON object currently pointed to by the iterator.

Get the type of the BSON object currently pointed to by the iterator.

Point the iterator at the next BSON object.

Check to see if the bson_iterator has more data.

Initialize a bson iterator from a const char* buffer.

Initialize a bson_iterator.

Advance a bson_iterator to the named field.

Returns true if bson_data(b) {b->data} is not null; else, false.

Return a pointer to the raw buffer stored by this bson object.

Print a string representation of a BSON object.

Minimum finished size of an unfinished BSON object given current contents.

Size of a BSON object.

Deallocate a BSON object.

Note
After using this function, you must initialize the object using bson_init_finished_data( ), bson_init_empty( ), bson_init( ), or one of the other init functions.
Returns
a new BSON object.
Note
You must call bson_destroy( ) before calling this function.
Parameters
bthe BSON object.
Returns
the size.
Parameters
bthe BSON object.
Returns
the BSON object's minimum finished size
Parameters
bthe BSON object to print.
ba BSON object
Note
Convenience function for determining if bson data was returned by a function. Check required after calls to mongo_create_index(), mongo_create_simple_index(), mongo_cmd_get_last_error() and mongo_cmd_get_prev_error().
Parameters
bthe bson struct to inspect.
bsonthe raw data to print.
depththe depth to recurse the object.x
itthe bson_iterator to use.
objthe BSON object to use.
namethe name of the field to find.
Returns
the type of the found object or BSON_EOO if it is not found.
Parameters
ithe bson_iterator to initialize.
bsonthe BSON object to associate with the iterator.

Note that this is mostly used internally.

Parameters
ithe bson_iterator to initialize.
bufferthe buffer to point to.
ithe iterator.
Returns
returns true if there is more data.
Parameters
ithe bson_iterator.
Returns
the type of the next BSON object.
Parameters
ithe bson_iterator
Returns
the type of the current BSON object.
Parameters
ithe bson_iterator
Returns
the key of the current BSON object.
Parameters
ithe bson_iterator
Returns
the value of the current BSON object.

Works with bson_code, bson_codewscope, and BSON_STRING returns NULL for everything else.

Parameters
ithe bson_iterator
Returns
the code value of the current BSON object.

Calls bson_init_empty on scope if current object is not BSON_CODEWSCOPE.

Note
When copyData is false, the scope becomes invalid when the iterator's data buffer is deallocated. For either value of copyData, you must pass the scope object to bson_destroy when you are done using it.
Parameters
ithe bson_iterator.
scopean uninitialized BSON object to receive the scope.
copyDatawhen true, makes a copy of the scope data which will remain valid when the iterator's data buffer is deallocated.
ithe bson_iterator
Returns
the date value of the current BSON object.
Parameters
ithe bson_iterator
Returns
the time value of the current BSON object.
Parameters
ithe bson_iterator
Returns
the length of the current BSON binary object.
Parameters
ithe bson_iterator
Returns
the type of the current BSON binary object.
Parameters
ithe bson_iterator
Returns
the value of the current BSON binary object.
Parameters
ithe bson_iterator
Returns
the value of the current BSON regex object.
Parameters
ithe bson_iterator.
Returns
the options of the current BSON regex object.
Note
When copyData is 0, the subobject becomes invalid when its parent's data buffer is deallocated. For either value of copyData, you must pass the subobject to bson_destroy when you are done using it.
Parameters
ithe bson_iterator.
suban unitialized BSON object which will become the new subobject.
ithe bson_iterator.
subthe iterator to point at the BSON subobject.
oidthe bson_oid_t destination.
stra null terminated string comprised of at least 24 hex chars.
oidthe bson_oid_t source.
strthe string representation destination.
oidthe destination for the newly created bson_oid_t.
funca pointer to a function that returns an int.

If you need thread-safety in generating object ids, you should set this function.

Parameters
funca pointer to a function that returns an int.
oidthe bson_oid_t.
Note
You must initialize each new bson object using this, bson_init_finished_data( ), or one of the other init functions. When done using the BSON object, you must pass it to bson_destroy( ).
Parameters
bthe BSON object to initialize.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson object to finalize.
Returns
the standard error code. To deallocate memory, call bson_destroy on the bson object.
Parameters
bthe bson object to destroy.
Note
You must NOT modify this object's data. It is safe though not required to call bson_destroy( ) on this object.
Parameters
objthe BSON object to initialize.
Returns
BSON_OK
Note
This object is owned by the driver. You must NOT modify it and must NOT call bson_destroy( ) on it.
Returns
the shared initialized BSON object.

The source bson object must be in a finished state; otherwise, the copy will fail.

Parameters
outthe copy destination BSON object.
inthe copy source BSON object.
bthe bson to append to.
namethe key for the bson_oid_t.
oidthe bson_oid_t to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the bson_oid_t.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the int.
ithe int to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the long.
ithe long to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the double.
dthe double to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the string.
strthe string to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the string.
strthe string to append.
lenthe number of bytes from str to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the symbol.
strthe symbol to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the symbol.
strthe symbol to append.
lenthe number of bytes from str to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the code.
strthe code to append.
lenthe number of bytes from str to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the code.
strthe string to append.
scopea BSON object containing the scope.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the code.
strthe string to append.
lenthe number of bytes from str to append.
scopea BSON object containing the scope.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the data.
typethe binary data type.
strthe binary data.
lenthe length of the data.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the boolean value.
vthe bson_bool_t to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the null value.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the undefined value.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the maxkey value.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the minkey value.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the regex value.
patternthe regex pattern to append.
theregex options.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the bson data.
bsonthe bson object to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
name_or_nullthe key for the BSON element, or NULL.
elemthe bson_iterator.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the timestampe value.
tsthe bson_timestamp_t value to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the date value.
millisthe bson_date_t to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe key for the date value.
secsthe time_t to append.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe name of the new object.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
namethe name of the new array.
Returns
BSON_OK or BSON_ERROR.
Parameters
bthe bson to append to.
Returns
BSON_OK or BSON_ERROR.

This is simply an alias for bson_append_finish_object.

Parameters
bthe bson to append to.
Returns
BSON_OK or BSON_ERROR.
Parameters
sizebytes to allocate.
Returns
a pointer to the allocated memory.
See also
malloc(3)
Parameters
funca bson_err_handler function.
Returns
the old error handling function, or NULL.

This is necessary for embedding in certain environments.

You must initialize each mongo object using this function.

Note
When finished, you must pass this object to mongo_destroy( ).
Parameters
conna mongo connection object allocated on the stack or heap.
conna mongo object.
hosta numerical network address or a network hostname.
portthe port to connect to.
Returns
MONGO_OK or MONGO_ERROR on failure. On failure, a constant of type mongo_error_t will be set on the conn->err field.

Connect to a single MongoDB server.

Parameters
conna mongo object.
hosta numerical network address or a network hostname.
portthe port to connect to.
Returns
MONGO_OK or MONGO_ERROR on failure. On failure, a constant of type mongo_error_t will be set on the conn->err field.

To connect, pass the object to mongo_replica_set_client().

Parameters
conna mongo object.
namethe name of the replica set to connect to.

Set up this connection object for connecting to a replica set. To connect, pass the object to mongo_replset_connect().

Parameters
conna mongo object.
namethe name of the replica set to connect to.

You must specify at least one seed node before connecting to a replica set.

Parameters
conna mongo object.
hosta numerical network address or a network hostname.
portthe port to connect to.

Add a seed node to the replica set connection object.

You must specify at least one seed node before connecting to a replica set.

Parameters
conna mongo object.
hosta numerical network address or a network hostname.
portthe port to connect to.
conna mongo object.
Returns
MONGO_OK or MONGO_ERROR on failure. On failure, a constant of type mongo_conn_return_t will be set on the conn->err field.

Before passing a connection object to this function, you must already have called mongo_set_replica_set and mongo_replica_set_add_seed.

Parameters
conna mongo object.
Returns
MONGO_OK or MONGO_ERROR on failure. On failure, a constant of type mongo_conn_return_t will be set on the conn->err field.

Connect to a replica set.

Before passing a connection object to this function, you must already have called mongo_set_replset and mongo_replset_add_seed.

Parameters
conna mongo object.
Returns
MONGO_OK or MONGO_ERROR on failure. On failure, a constant of type mongo_conn_return_t will be set on the conn->err field.

This is a platform-specific feature, and only work on *nix system. You must also compile for linux to support this.

Parameters
conna mongo object.
millistimeout time in milliseconds.
Returns
MONGO_OK. On error, return MONGO_ERROR and set the conn->err field.
Parameters
conna mongo connection
Returns
MONGO_OK if connected; otherwise, MONGO_ERROR.

This function will disconnect the current socket. If you've authenticated, you'll need to re-authenticate after calling this function.

Parameters
conna mongo object.
Returns
MONGO_OK or MONGO_ERROR and set the conn->err field.

After calling this function, you may call mongo_reconnect with the same connection object.

Parameters
conna mongo object.

You must always call this function when finished with the connection object.

Parameters
conna mongo object.

This value can be overridden by passing a write_concern object to any write function.

Parameters
conna mongo object.
write_concernpointer to a write concern object.

This function will fail if the supplied BSON struct is not UTF-8 or if the keys are invalid for insert (contain '.' or start with '$').

The default write concern set on the conn object will be used.

Parameters
conna mongo object.
nsthe namespace.
datathe bson data.
custom_write_concerna write concern object that will override any write concern set on the conn object.
Returns
MONGO_OK or MONGO_ERROR. If the conn->err field is MONGO_BSON_INVALID, check the err field on the bson struct for the reason.

This function will fail if any of the documents to be inserted is invalid.

The default write concern set on the conn object will be used.

Parameters
conna mongo object.
nsthe namespace.
datathe bson data.
numthe number of documents in data.
custom_write_concerna write concern object that will override any write concern set on the conn object.
flagsflags on this batch insert. Currently, this value may be 0 or MONGO_CONTINUE_ON_ERROR, which will cause the batch insert to continue even if a given insert in the batch fails.
Returns
MONGO_OK or MONGO_ERROR.

The default write concern set on the conn object will be used.

Parameters
conna mongo object.
nsthe namespace.
condthe bson update query.
opthe bson update data.
flagsflags for the update.
custom_write_concerna write concern object that will override any write concern set on the conn object.
Returns
MONGO_OK or MONGO_ERROR with error stored in conn object.

The default write concern set on the conn object will be used.

Parameters
conna mongo object.
nsthe namespace.
condthe bson query.
custom_write_concerna write concern object that will override any write concern set on the conn object.
Returns
MONGO_OK or MONGO_ERROR with error stored in conn object.

Effectively zeroes out the struct.

You must call mongo_write_concern_destroy() to free the serialized BSON.

Parameters
conna mongo object.
nsthe namespace.
querythe bson query.
fieldsa bson document of fields to be returned.
limitthe maximum number of documents to return.
skipthe number of documents to skip.
optionsA bitfield containing cursor options.
Returns
A cursor object allocated on the heap or NULL if an error has occurred. For finer-grained error checking, use the cursor builder API instead.
Parameters
cursor
nsthe namespace, represented as the the database name and collection name separated by a dot. e.g., "test.users"

If your query is the empty bson object "{}", then you need not set this value.

Parameters
cursor
querya bson object representing the query spec. This may be either a simple query spec or a complex spec storing values for $query, $orderby, $hint, and/or $explain. See http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol for details.

If you want to return all fields, you need not set this value.

Parameters
cursor
fieldsa bson object representing the fields to return. See http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields.
cursor
skip
cursor
limit
cursor
optionsa bitfield storing query options. See mongo_cursor_bitfield_t for available constants.

This is useful for creating bson iterators with bson_iterator_init.

Parameters
cursorWhen successful, the returned object will be stored in cursor->current;
cursor
Returns
MONGO_OK. On error, returns MONGO_ERROR and sets cursor->err with a value of mongo_error_t.

When finished with a cursor, you must pass it to this function.

Parameters
cursorthe cursor to destroy.
Returns
MONGO_OK or an error code. On error, check cursor->conn->err for errors.
Parameters
conna mongo object.
nsthe namespace.
querythe bson query.
fieldsa bson document of the fields to be returned.
outa bson document in which to put the query result.
conna mongo object.
dbthe db name.
collthe collection name.
querythe BSON query.
Returns
the number of matching documents. If the command fails, MONGO_ERROR is returned.
Parameters
conna mongo object.
nsthe namespace.
keythe bson index key.
namethe optional name, use NULL to generate a default name.
optionsa bitfield for setting index options. Possibilities include MONGO_INDEX_UNIQUE, MONGO_INDEX_DROP_DUPS, MONGO_INDEX_BACKGROUND, and MONGO_INDEX_SPARSE.
outa bson document containing errors, if any.
Returns
MONGO_OK if index is created successfully; otherwise, MONGO_ERROR.
Note
May not return bson data when returning MONGO_ERROR, Use bson_has_data() on the returned 'out' for determining this.
Parameters
conna mongo object.
nsthe namespace.
fieldthe index key.
optionsindex options.
outa BSON document containing errors, if any.
Returns
true if the index was created.
Note
May not return bson data when returning MONGO_ERROR, Use bson_has_data() on the returned 'out' for determining this.
Parameters
conna mongo object.
nsthe namespace (e.g., "dbname.collectioname")
sizethe size of the capped collection in bytes.
maxthe max number of documents this collection is allowed to contain. If zero, this argument will be ignored and the server will use the collection's size to age document out. If using this option, ensure that the total size can contain this number of documents.
conna mongo object.
dbthe name of the database.
commandthe BSON command to run.
outthe BSON result of the command.
Returns
MONGO_OK if the command ran without error.
Parameters
conna mongo object.
dbthe name of the database.
cmdthe command to run.
argthe integer argument to the command.
outthe BSON result of the command.
Returns
MONGO_OK or an error code.
Parameters
conna mongo object.
dbthe name of the database.
cmdthe command to run.
argthe string argument to the command.
outthe BSON result of the command.
Returns
true if the command ran without error.
Parameters
conna mongo object.
dbthe name of the database to drop.
Returns
MONGO_OK or an error code.
Parameters
conna mongo object.
dbthe name of the database.
collectionthe name of the collection to drop.
outa BSON document containing the result of the command.
Returns
true if the collection drop was successful.
Parameters
conna mongo object.
dbthe database in which to add the user.
userthe user name
passthe user password
Returns
MONGO_OK or MONGO_ERROR.
Parameters
conna mongo object.
dbthe database to authenticate against.
userthe user name to authenticate.
passthe user's password.
Returns
MONGO_OK on sucess and MONGO_ERROR on failure.
Parameters
conna mongo object.
outa BSON result of the command.
Returns
true if the server is a master.
Parameters
conna mongo object.
dbthe name of the database.
outa BSON object containing the error details.
Returns
MONGO_OK if no error and MONGO_ERROR on error. On error, check the values of conn->lasterrcode and conn->lasterrstr for the error status.
Note
May not return bson data when returning MONGO_ERROR, Use bson_has_data() on the returned 'out' for determining this.
Parameters
conna mongo object.
dbthe name of the database.

Mostly for internal use.

Parameters
conna mongo connection object.
erra driver error code of mongo_error_t.
errstra string version of the error.
errorcodeCurrently errno or WSAGetLastError().
conna mongo connection object.

Definition at line 389 of file bson.c.

References bson::stack.

static int _bson_append_grow_stack ( bson b)
static

Definition at line 963 of file bson.c.

References BSON_ERROR, BSON_OK, bson_realloc(), bson::stack, bson::stackPtr, and bson::stackSize.

int _bson_errprintf ( const char *  format,
  ... 
)
static

Definition at line 1415 of file bson.c.

static size_t _bson_position ( const bson b)
static

Definition at line 449 of file bson.c.

References bson::cur, and bson::data.

Referenced by bson_ensure_space().

static void _bson_zero ( bson b)
static

Definition at line 933 of file bson.c.

Referenced by bson_init_finished_data(), bson_init_size(), and bson_init_unfinished_data().

static void bson_append ( bson b,
const void *  data,
size_t  len 
)
static

Definition at line 1000 of file bson.c.

References bson::cur, and len.

Referenced by bson_append_estart(), and bson_append_string_base().

static void bson_append32 ( bson b,
const void *  data 
)
static

Definition at line 1005 of file bson.c.

References bson_little_endian32(), and bson::cur.

static void bson_append32_as_int ( bson b,
int  data 
)
static

Definition at line 1010 of file bson.c.

References bson_little_endian32(), and bson::cur.

Referenced by bson_append_string_base().

static void bson_append64 ( bson b,
const void *  data 
)
static

Definition at line 1015 of file bson.c.

References bson_little_endian64(), and bson::cur.

static void bson_append_byte ( bson b,
char  c 
)
static

Definition at line 995 of file bson.c.

References bson::cur.

Referenced by bson_append_estart().

static int bson_append_estart ( bson b,
int  type,
const char *  name,
const size_t  dataSize 
)
static
static int bson_append_string_base ( bson b,
const char *  name,
const char *  value,
size_t  len,
bson_type  type 
)
static
void bson_big_endian32 ( void *  outp,
const void *  inp 
)

Definition at line 92 of file bson.c.

References in, out, _dbswap::uc, and _dbswap::ui.

void bson_big_endian64 ( void *  outp,
const void *  inp 
)

Definition at line 71 of file bson.c.

References in, out, _dbswap::uc, and _dbswap::ui.

void bson_builder_error ( bson b)

This method is invoked when a non-fatal bson error is encountered.

Invoke the error handler, but do not exit.

Calls the error handler if available.

Parameters

Definition at line 1433 of file bson.c.

References err_handler.

Referenced by bson_append_estart().

static int bson_check_field_name ( bson b,
const char *  string,
const size_t  length 
)
static

Definition at line 236 of file bson.c.

References bson_validate_string().

Referenced by bson_append_estart().

static int bson_check_string ( bson b,
const char *  string,
const size_t  length 
)
static

Definition at line 230 of file bson.c.

References bson_validate_string().

Referenced by bson_append_string_base().

int bson_ensure_space ( bson b,
const size_t  bytesNeeded 
)

Grow a bson object.

Parameters
bthe bson to grow.
bytesNeededthe additional number of bytes needed.
Returns
BSON_OK or BSON_ERROR with the bson error object set. Exits if allocation fails.

Definition at line 1020 of file bson.c.

References _bson_position(), BSON_DOES_NOT_OWN_DATA, BSON_ERROR, bson_fatal_msg(), BSON_OK, bson_realloc(), BSON_SIZE_OVERFLOW, bson::cur, bson::data, bson::dataSize, bson::err, and bson::ownsData.

Referenced by bson_append_estart().

void bson_fatal ( int  ok)

Exit fatally.

Parameters
okexits if ok is equal to 0.

Definition at line 1438 of file bson.c.

References bson_fatal_msg().

void bson_fatal_msg ( int  ok,
const char *  msg 
)

Exit fatally with an error message.

Parameters
okexits if ok is equal to 0.
msgprints to stderr before exiting.

Definition at line 1442 of file bson.c.

References bson_errprintf, and err_handler.

Referenced by bson_ensure_space(), bson_fatal(), bson_realloc(), gridfile_fill_buf_from_chunk(), and mongo_cursor_op_query().

static int bson_finished_data_size ( const char *  data)
static

Definition at line 402 of file bson.c.

References bson_little_endian32(), and i.

Referenced by bson_init_finished_data(), and bson_init_finished_data_with_copy().

int bson_init_finished_data ( bson b,
char *  data,
bson_bool_t  ownsData 
)

Initialize a BSON object for reading and set its data pointer to the provided char*.

Note
When done using the bson object, you must pass the object to bson_destroy( ).
Parameters
bthe BSON object to initialize.
datathe finalized raw BSON data.
ownsDatawhen true, bson_destroy() will free the data block.
Returns
BSON_OK or BSON_ERROR.

Definition at line 408 of file bson.c.

References _bson_zero(), bson_finished_data_size(), BSON_OK, bson::data, data, bson::dataSize, bson::finished, and bson::ownsData.

Referenced by mongo_cursor_next(), and mongo_cursor_op_query().

int bson_init_finished_data_with_copy ( bson b,
const char *  data 
)

Initialize a BSON object for reading and copy finalized BSON data from the provided char*.

Note
When done using the bson object, you must pass the object to bson_destroy( ).
Parameters
bthe BSON object to initialize.
datathe finalized raw BSON data to copy.
Returns
BSON_OK or BSON_ERROR.

Definition at line 417 of file bson.c.

References BSON_ERROR, bson_finished_data_size(), bson_init_size(), BSON_OK, bson::data, and bson::finished.

int bson_init_size ( bson b,
int  size 
)

Initialize a BSON object for building and allocate a data buffer of a given size.

Note
When done using the bson object, you must pass it to bson_destroy( ).
Parameters
bthe BSON object to initialize.
sizethe initial size of the buffer.
Returns
BSON_OK or BSON_ERROR.

Definition at line 941 of file bson.c.

References _bson_zero(), BSON_ERROR, BSON_OK, bson::cur, bson::data, data, bson::dataSize, bson::ownsData, and size.

Referenced by bson_init_finished_data_with_copy(), and chunk_new().

int bson_init_unfinished_data ( bson b,
char *  data,
int  dataSize,
bson_bool_t  ownsData 
)

Initialize a BSON object for building, using the provided char* of the given size.

When ownsData is true, the BSON object may reallocate the data block as needed, and bson_destroy will free it.

See also bson_init_finished_data( )

Note
When done using the BSON object, you must pass it to bson_destroy( ).
Parameters
bthe BSON object to initialize.
datathe raw BSON data.
dataSize
ownsDatawhen true, bson_ensure_space() may reallocate the block and bson_destroy() will free it
Returns
BSON_OK or BSON_ERROR.

Definition at line 955 of file bson.c.

References _bson_zero(), BSON_OK, bson::data, data, bson::dataSize, and bson::ownsData.

bson_bool_t bson_iterator_bool_raw ( const bson_iterator i)

Get the bson_bool_t value of the BSON object currently pointed to by the iterator.

Assumes the correct type is used.

Parameters
ithe bson_iterator
Returns
the value of the current BSON object.

Definition at line 756 of file bson.c.

double bson_iterator_double_raw ( const bson_iterator i)

Get the double value of the BSON object currently pointed to by the iterator.

Assumes the correct type is used.

Parameters
ithe bson_iterator
Returns
the value of the current BSON object.

Definition at line 744 of file bson.c.

References bson_little_endian64(), and out.

int bson_iterator_int_raw ( const bson_iterator i)

Get the int value of the BSON object currently pointed to by the iterator.

Assumes the correct type is used.

Parameters
ithe bson_iterator
Returns
the value of the current BSON object.

Definition at line 738 of file bson.c.

References bson_little_endian32(), and out.

Referenced by bson_iterator_string_len().

int64_t bson_iterator_long_raw ( const bson_iterator i)

Get the long value of the BSON object currently pointed to by the iterator.

Assumes the correct type is used.

Parameters
ithe bson_iterator
Returns
the value of the current BSON object.

Definition at line 750 of file bson.c.

References bson_little_endian64(), and out.

int bson_iterator_string_len ( const bson_iterator i)

Get the string length of the BSON object currently pointed to by the iterator.

Parameters
ithe bson_iterator
Returns
the length of the current BSON object.

Definition at line 853 of file bson.c.

References bson_iterator_int_raw().

Referenced by mongo_set_last_error().

void bson_little_endian32 ( void *  outp,
const void *  inp 
)
void bson_little_endian64 ( void *  outp,
const void *  inp 
)
void bson_numstr ( char *  str,
int  i 
)

Definition at line 1459 of file bson.c.

References bson_sprintf.

void* bson_realloc ( void *  ptr,
size_t  size 
)

Changes the size of allocated memory and checks return value, exiting fatally if realloc() fails.

Parameters
ptrpointer to the space to reallocate.
sizebytes to allocate.
Returns
a pointer to the allocated memory.
See also
realloc()

Definition at line 1408 of file bson.c.

References bson_fatal_msg(), and bson_realloc_func.

Referenced by _bson_append_grow_stack(), and bson_ensure_space().

static int bson_string_is_db_ref ( const unsigned char *  string,
const size_t  length 
)
static

Definition at line 178 of file bson.c.

Referenced by bson_validate_string().

static int bson_validate_string ( bson b,
const unsigned char *  string,
const size_t  length,
const char  check_utf8,
const char  check_dot,
const char  check_dollar 
)
static
static char hexbyte ( char  hex)
static

Definition at line 462 of file bson.c.

static int isLegalUTF8 ( const unsigned char *  source,
int  length 
)
static

Definition at line 143 of file bson.c.

Referenced by bson_validate_string().

Variable Documentation

bson_fprintf_func bson_fprintf = fprintf

Definition at line 372 of file bson.c.

void( * bson_free_func)(void *) = free

Definition at line 366 of file bson.c.

void*( * bson_malloc_func)(size_t) = malloc

Definition at line 364 of file bson.c.

const char bson_numstrs

Definition at line 246 of file bson.c.

bson_printf_func bson_printf = printf

Definition at line 370 of file bson.c.

void*( * bson_realloc_func)(void *, size_t) = realloc

Definition at line 365 of file bson.c.

Referenced by bson_realloc().

char bson_shared_empty_data[] = {5,0,0,0,0}
static

Definition at line 361 of file bson.c.

bson_sprintf_func bson_sprintf = sprintf

Definition at line 373 of file bson.c.

Referenced by _get_host_port(), bson_numstr(), mongo_env_socket_connect(), and mongo_validate_ns().

bson_err_handler err_handler = NULL
static

Definition at line 1389 of file bson.c.

Referenced by bson_builder_error(), and bson_fatal_msg().

const int initialBufferSize = 128
static

Definition at line 108 of file bson.c.

int( * oid_fuzz_func)(void) = NULL
static

Definition at line 382 of file bson.c.

int( * oid_inc_func)(void) = NULL
static

Definition at line 383 of file bson.c.

const char trailingBytesForUTF8[256]
static
Initial value:
= {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
}

Definition at line 120 of file bson.c.

Referenced by bson_validate_string().

const int zero = 0
static

Definition at line 111 of file bson.c.

Referenced by rpmcliImportPubkey(), rpmgitCmdInit(), and wrSignature().