#![allow(dead_code)] #![allow(improper_ctypes)] extern crate libc; use libc::{c_char, c_double, c_int, int64_t, size_t}; pub struct Bson { pub data: *mut c_char, // Pointer to a block of data in this BSON object. pub cur: *mut c_char, // Pointer to the current position. pub data_size: c_int, // The number of bytes allocated to char *data. pub finished: c_int, // When finished, the BSON object can no longer be modified. pub owns_data: c_int, // Whether destroying this object will deallocate its data block pub err: c_int, // Bitfield representing errors or warnings on this buffer pub stack_size: c_int, // Number of elements in the current stack pub stack_pos: c_int, // Index of current stack position. pub stack_ptr: *mut size_t, // Pointer to the current stack pub stack: [size_t; 32], // A stack used to keep track of nested BSON elements. // Must be at end of bson struct so _bson_zero does not clear. } pub const OK: i32 = 0; pub const ERROR: i32 = -1; pub const DEFAULT_PORT: i32 = 27017; pub const DEFAULT_MAX_BSON_SIZE: usize = 4 * 1024 * 1024; pub const ERR_LEN: usize = 128; pub const MAXHOSTNAMELEN: usize = 256; #[derive(Clone, Debug, PartialEq)] pub enum Error { ConnSuccess, // Connection success! ConnNoSocket, // Could not create a socket. ConnFail, // An error occured while calling connect(). ConnAddrFail, // An error occured while calling getaddrinfo(). ConnNotMaster, // Warning: connected to a non-master node (read-only). ConnBadSetName, // Given rs name doesn't match this replica set. ConnNoPrimary, // Can't find primary in replica set. Connection closed. IoError, // An error occurred while reading or writing on the socket. SocketError, // Other socket error. ReadSizeError, // The response is not the expected length. CommandFailed, // The command returned with 'ok' value of 0. WriteError, // Write with given write_concern returned an error. NsInvalid, // The name for the ns (database or collection) is invalid. BsonInvalid, // BSON not valid for the specified op. BsonNotFinished, // BSON object has not been finished. BsonTooLarge, // BSON object exceeds max BSON size. WriteConcernFailed, // Supplied write concern object is invalid. } #[derive(Clone, Debug, PartialEq)] pub enum CursorError { Exhausted, // The cursor has no more results. Invalid, // The cursor has timed out or is not recognized. Pending, // Tailable cursor still alive but no data. QueryFail, // The server returned an '$err' object, indicating query failure. // See conn.last_err_code and conn.last_err_str for details. BsonError, // Something is wrong with the BSON provided. See conn.err // for details. } pub enum CursorFlags { MustFree = 1, // mongo_cursor_destroy should free cursor. QuerySent = 1 << 1, // Initial query has been sent. } pub enum IndexOpts { IndexUnique = 1 << 0, IndexDropDups = 1 << 2, IndexBackground = 1 << 3, IndexSparse = 1 << 4, } pub enum UpdateOpts { UpdateUpsert = 0x1, UpdateMulti = 0x2, UpdateBasic = 0x4, } pub enum InsertOpts { ContinueOnError = 0x1, } pub enum CursorOpts { Tailable = 1 << 1, // Create a tailable cursor. SlaveOk = 1 << 2, // Allow queries on a non-primary node. NoCursorTimeout = 1 << 4, // Disable cursor timeouts. AwaitData = 1 << 5, // Momentarily block for more data. Exhaust = 1 << 6, // Stream in multiple 'more' packages. Partial = 1 << 7, // Allow reads even if a shard is down. } pub enum Operations { OpMsg = 1000, OpUpdate = 2001, OpInsert = 2002, OpQuery = 2004, OpGetMore = 2005, OpDelete= 2006, OpKillCursors = 2007, } pub struct Header { pub len: c_int, pub id: c_int, pub response_to: c_int, pub op: c_int, } pub struct Message { pub head: Header, pub data: c_char, } pub struct ReplyFields { pub flag: c_int, // FIX THIS COMMENT non-zero on failure pub cursor_id: int64_t, pub start: c_int, pub num: c_int, } pub struct Reply { pub head: Header, pub fields: ReplyFields, pub objs: c_char, } pub struct ConnectionInfo { pub host: [c_char; MAXHOSTNAMELEN], pub port: c_int, pub next: *mut ConnectionInfo, } pub struct ReplicaSet { pub seeds: *mut ConnectionInfo, // List of seeds provided by the user. pub hosts: *mut ConnectionInfo, // List of host/ports given by the replica set pub name: *mut c_char, // Name of the replica set. pub primary_connected: c_int, // Primary node connection status. } pub struct WriteConcern { pub w: c_int, // Number of total replica write copies to complete including the primary. pub wtimeout: c_int, // Number of milliseconds before replication timeout. pub j: c_int, // If non-zero, block until the journal sync. pub fsync: c_int, // Same as j with journaling enabled; otherwise, call fsync. pub mode: *const c_char, // Either "majority" or a getlasterrormode. Overrides w value. pub cmd: *mut Bson, // The BSON object representing the getlasterror command. } pub struct Connection { pub primary: *mut ConnectionInfo, // Primary connection info. pub replica_set: *mut ReplicaSet, // replica_set object if connected to a replica set. pub sock: c_int, // Socket file descriptor. pub flags: c_int, // Flags on this connection object. pub conn_timeout_ms: c_int, // Connection timeout in milliseconds. pub op_timeout_ms: c_int, // Read and write timeout in milliseconds. pub max_bson_size: c_int, // Largest BSON object allowed on this connection. pub connected: c_int, // Connection status. pub write_concern: *mut WriteConcern, // The default write concern. pub err: Error, // Most recent driver error code. pub err_code: c_int, // Most recent errno or WSAGetLastError(). pub err_str: [c_char; ERR_LEN], // String version of error. pub last_err_code: c_int, // getlasterror code from the server. pub last_err_str: [c_char; ERR_LEN], // getlasterror string from the server. } pub struct Cursor { pub reply: *mut Reply, // reply is owned by cursor pub conn: *mut Connection, // connection is *not* owned by cursor pub ns: *const c_char, // owned by cursor pub flags: c_int, // Flags used internally by this drivers. pub seen: c_int, // Number returned so far. pub current: Bson, // This cursor's current bson object. pub err: CursorError, // Errors on this cursor. pub query: *const Bson, // Bitfield containing cursor options. pub fields: *const Bson, // Bitfield containing cursor options. pub options: c_int, // Bitfield containing cursor options. pub limit: c_int, // Bitfield containing cursor options. pub skip: c_int, // Bitfield containing cursor options. } extern { /////////////////////////////////////////////////////////////////////// // Connection API /////////////////////////////////////////////////////////////////////// // Initialize sockets for Windows. pub fn mongo_init_sockets(); // Initialize a new mongo connection object. You must initialize each mongo // object using this function. // // @note When finished, you must pass this object to // mongo_destroy( ). // // @param conn a mongo connection object allocated on the stack // or heap. pub fn mongo_init(conn: *mut Connection); // Connect to a single MongoDB server. // // @param conn a mongo object. // @param host a numerical network address or a network hostname. // @param port the port to connect to. // // @return OK or ERROR on failure. On failure, a constant of type // Error will be set on the conn.err field. pub fn mongo_client(conn: *mut Connection, host: *const c_char, port: c_int) -> c_int; // DEPRECATED - use mongo_client. // Connect to a single MongoDB server. // // @param conn a mongo object. // @param host a numerical network address or a network hostname. // @param port the port to connect to. // // @return OK or ERROR on failure. On failure, a constant of type // Error will be set on the conn.err field. pub fn mongo_connect(conn: *mut Connection, host: *const c_char, port: c_int) -> c_int; // Set up this connection object for connecting to a replica set. // To connect, pass the object to mongo_replica_set_client(). // // @param conn a mongo object. // @param name the name of the replica set to connect to. pub fn mongo_replica_set_init(conn: *mut Connection, name: *const c_char); // DEPRECATED - use mongo_replica_set_init. // Set up this connection object for connecting to a replica set. // To connect, pass the object to mongo_replset_connect(). // // @param conn a mongo object. // @param name the name of the replica set to connect to. pub fn mongo_replset_init(conn: *mut Connection, name: *const c_char); // Add a seed node to the replica set connection object. // // You must specify at least one seed node before connecting to a replica set. // // @param conn a mongo object. // @param host a numerical network address or a network hostname. // @param port the port to connect to. pub fn mongo_replica_set_add_seed(conn: *mut Connection, host: *const c_char, port: c_int); // DEPRECATED - use mongo_replica_set_add_seed. // Add a seed node to the replica set connection object. // // You must specify at least one seed node before connecting to a replica set. // // @param conn a mongo object. // @param host a numerical network address or a network hostname. // @param port the port to connect to. pub fn mongo_replset_add_seed(conn: *mut Connection, host: *const char, port: c_int); // Utility function for converting a host-port string to a mongo_host_port. // // @param host_string a string containing either a host or a host and port separated // by a colon. // @param host_port the mongo_host_port object to write the result to. fn mongo_parse_host(host_string: *const char, host_port: *mut ConnectionInfo); // Utility function for validation database and collection names. // // @param conn a mongo object. // // @return OK or ERROR on failure. On failure, a constant of type // Error will be set on the conn.err field. pub fn mongo_validate_ns(conn: *mut Connection, ns: *const c_char) -> c_int; // Connect to a replica set. // // Before passing a connection object to this function, you must already have called // mongo_set_replica_set and mongo_replica_set_add_seed. // // @param conn a mongo object. // // @return OK or ERROR on failure. On failure, a constant of type // Error will be set on the conn.err field. pub fn mongo_replica_set_client(conn: *mut Connection) -> c_int; // DEPRECATED - use mongo_replica_set_client. // 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. // // @param conn a mongo object. // // @return OK or ERROR on failure. On failure, a constant of type // Error will be set on the conn.err field. pub fn mongo_replset_connect(conn: *mut Connection) -> c_int; // Set a timeout for operations on this connection. This // is a platform-specific feature, and only work on *nix // system. You must also compile for linux to support this. // // @param conn a mongo object. // @param millis timeout time in milliseconds. // // @return OK. On error, return ERROR and // set the conn.err field. pub fn mongo_set_op_timeout(conn: *mut Connection, millis: c_int) -> c_int; // Ensure that this connection is healthy by performing // a round-trip to the server. // // @param conn a mongo connection // // @return OK if connected; otherwise, ERROR. pub fn mongo_check_connection(conn: *mut Connection) -> c_int; // Try reconnecting to the server using the existing connection settings. // // This function will disconnect the current socket. If you've authenticated, // you'll need to re-authenticate after calling this function. // // @param conn a mongo object. // // @return OK or ERROR and // set the conn.err field. pub fn mongo_reconnect(conn: *mut Connection) -> c_int; // Close the current connection to the server. After calling // this function, you may call mongo_reconnect with the same // connection object. // // @param conn a mongo object. pub fn mongo_disconnect(conn: *mut Connection); // Close any existing connection to the server and free all allocated // memory associated with the conn object. // // You must always call this function when finished with the connection object. // // @param conn a mongo object. pub fn mongo_destroy(conn: *mut Connection); // Specify the write concern object that this connection should use // by default for all writes (inserts, updates, and deletes). This value // can be overridden by passing a write_concern object to any write function. // // @param conn a mongo object. // @param write_concern pointer to a write concern object. pub fn mongo_set_write_concern(conn: *mut Connection, write_concern: *mut WriteConcern); // The following functions get the attributes of the write_concern object. pub fn mongo_write_concern_get_w(write_concern: *mut WriteConcern) -> c_int; pub fn mongo_write_concern_get_wtimeout(write_concern: *mut WriteConcern) -> c_int; pub fn mongo_write_concern_get_j(write_concern: *mut WriteConcern) -> c_int; pub fn mongo_write_concern_get_fsync(write_concern: *mut WriteConcern) -> c_int; pub fn mongo_write_concern_get_mode(write_concern: *mut WriteConcern) -> *const c_char; pub fn mongo_write_concern_get_cmd(write_concern: *mut WriteConcern) -> *mut Bson; // The following functions set the attributes of the write_concern object. pub fn mongo_write_concern_set_w(write_concern: *mut WriteConcern, w: c_int); pub fn mongo_write_concern_set_wtimeout(write_concern: *mut WriteConcern, wtimeout: c_int); pub fn mongo_write_concern_set_j(write_concern: *mut WriteConcern, j: c_int); pub fn mongo_write_concern_set_fsync(write_concern: *mut WriteConcern, fsync: c_int); pub fn mongo_write_concern_set_mode(write_concern: *mut WriteConcern, mode: *const c_char); /////////////////////////////////////////////////////////////////////// // CRUD API /////////////////////////////////////////////////////////////////////// // Insert a BSON document into a MongoDB server. 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. // // @param conn a mongo object. // @param ns the namespace. // @param data the bson data. // @param custom_write_concern a write concern object that will // override any write concern set on the conn object. // // @return OK or ERROR. If the conn.err // field is MongoBsonInvalid, check the err field // on the bson struct for the reason. pub fn mongo_insert(conn: *mut Connection, ns: *const c_char, data: *mut Bson, custom_write_concern: *mut WriteConcern) -> c_int; // Insert a batch of BSON documents into a MongoDB server. 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. // // @param conn a mongo object. // @param ns the namespace. // @param data the bson data. // @param num the number of documents in data. // @param custom_write_concern a write concern object that will // override any write concern set on the conn object. // @param flags flags on this batch insert. Currently, this value // may be 0 or MongoContinueOnError, which will cause the // batch insert to continue even if a given insert in the batch fails. // // @return OK or ERROR. pub fn mongo_insert_batch(conn: *mut Connection, ns: *const c_char, data: *const *mut Bson, num: c_int, custom_write_concern: *mut WriteConcern, flags: c_int) -> c_int; // Update a document in a MongoDB server. // // The default write concern set on the conn object will be used. // // @param conn a mongo object. // @param ns the namespace. // @param cond the bson update query. // @param op the bson update data. // @param flags flags for the update. // @param custom_write_concern a write concern object that will // override any write concern set on the conn object. // // @return OK or ERROR with error stored in conn object. pub fn mongo_update(conn: *mut Connection, ns: *const c_char, cond: *const Bson, op: *const Bson, flags: c_int, custom_write_concern: *mut WriteConcern) -> c_int; // Remove a document from a MongoDB server. // // The default write concern set on the conn object will be used. // // @param conn a mongo object. // @param ns the namespace. // @param cond the bson query. // @param custom_write_concern a write concern object that will // override any write concern set on the conn object. // // @return OK or ERROR with error stored in conn object. pub fn mongo_remove(conn: *mut Connection, ns: *const c_char, cond: *const Bson, custom_write_concern: *mut WriteConcern) -> c_int; /////////////////////////////////////////////////////////////////////// // Write Concern API /////////////////////////////////////////////////////////////////////// // Initialize a mongo_write_concern object. Effectively zeroes out the struct. pub fn mongo_write_concern_init(write_concern: *mut WriteConcern); // Finish this write concern object by serializing the literal getlasterror // command that will be sent to the server. // // You must call mongo_write_concern_destroy() to free the serialized BSON. pub fn mongo_write_concern_finish(write_concern: *mut WriteConcern) -> c_int; // Free the write_concern object (specifically, the BSON that it owns). pub fn mongo_write_concern_destroy(write_concern: *mut WriteConcern); /////////////////////////////////////////////////////////////////////// // Cursor API /////////////////////////////////////////////////////////////////////// // Find documents in a MongoDB server. // // @param conn a mongo object. // @param ns the namespace. // @param query the bson query. // @param fields a bson document of fields to be returned. // @param limit the maximum number of documents to return. // @param skip the number of documents to skip. // @param options A bitfield containing cursor options. // // @return 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. pub fn mongo_find(conn: *mut Connection, ns: *const c_char, query: *const Bson, fields: *const Bson, limit: c_int, skip: c_int, options: c_int) -> *mut Cursor; // Initalize a new cursor object. // // @param cursor // @param ns the namespace, represented as the the database // name and collection name separated by a dot. e.g., "test.users" pub fn mongo_cursor_init(cursor: *mut Cursor, conn: *mut Connection, ns: *const c_char); // Set the bson object specifying this cursor's query spec. If // your query is the empty bson object "{}", then you need not // set this value. // // @param cursor // @param query a 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. pub fn mongo_cursor_set_query(cursor: *const Cursor, query: *const Bson); // Set the fields to return for this cursor. If you want to return // all fields, you need not set this value. // // @param cursor // @param fields a bson object representing the fields to return. // See http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields. pub fn mongo_cursor_set_fields(cursor: *const Cursor, fields: *const Bson); // Set the number of documents to skip. // // @param cursor // @param skip pub fn mongo_cursor_set_skip(cursor: *const Cursor, skip: c_int); // Set the number of documents to return. // // @param cursor // @param limit pub fn mongo_cursor_set_limit(cursor: *const Cursor, limit: c_int); // Set any of the available query options (e.g., Tailable). // // @param cursor // @param options a bitfield storing query options. See // MongoCursorOpts for available constants. pub fn mongo_cursor_set_options(cursor: *const Cursor, options: c_int); // Return the current BSON object data as a const char*. This is useful // for creating bson iterators with bson_iterator_init. // // @param cursor pub fn mongo_cursor_data(cursor: *const Cursor) -> *const c_char; // Return the current BSON object data as a const char*. This is useful // for creating bson iterators with bson_iterator_init. // // @param cursor pub fn mongo_cursor_bson(cursor: *const Cursor) -> *const Bson; // Iterate the cursor, returning the next item. When successful, // the returned object will be stored in cursor.current; // // @param cursor // // @return OK. On error, returns ERROR and sets // cursor.err with a value of Error. pub fn mongo_cursor_next(cursor: *const Cursor) -> c_int; // Destroy a cursor object. When finished with a cursor, you // must pass it to this function. // // @param cursor the cursor to destroy. // // @return OK or an error code. On error, check cursor.conn.err // for errors. pub fn mongo_cursor_destroy(cursor: *const Cursor) -> c_int; // Find a single document in a MongoDB server. // // @param conn a mongo object. // @param ns the namespace. // @param query the bson query. // @param fields a bson document of the fields to be returned. // @param out a bson document in which to put the query result. // // out can be NULL if you don't care about results. useful for commands pub fn mongo_find_one(conn: *mut Connection, ns: *const c_char, query: *const Bson, fields: *const Bson, out: *mut Bson) -> c_int; /////////////////////////////////////////////////////////////////////// // Command API and Helpers /////////////////////////////////////////////////////////////////////// // Count the number of documents in a collection matching a query. // // @param conn a mongo object. // @param db the db name. // @param coll the collection name. // @param query the BSON query. // // @return the number of matching documents. If the command fails, // ERROR is returned. pub fn mongo_count(conn: *mut Connection, db: *const c_char, coll: *const c_char, query: *const Bson) -> c_double; // Create a compound index. // // @param conn a mongo object. // @param ns the namespace. // @param key the bson index key. // @param name the optional name, use NULL to generate a default name. // @param options a bitfield for setting index options. Possibilities include // MongoIndexUnique, MongoIndexDropDups, MongoIndexBackground, // and MongoIndexSparse. // @param out a bson document containing errors, if any. // // @return OK if index is created successfully; otherwise, ERROR. // // @note May not return bson data when returning ERROR, // Use bson_has_data() on the returned 'out' for determining this. pub fn mongo_create_index(conn: *mut Connection, ns: *const c_char, key: *const Bson, name: *const c_char, options: c_int, ttl: c_int, out: *mut Bson) -> c_int; // Create an index with a single key. // // @param conn a mongo object. // @param ns the namespace. // @param field the index key. // @param options index options. // @param out a BSON document containing errors, if any. // // @return true if the index was created. // // @note May not return bson data when returning ERROR, // Use bson_has_data() on the returned 'out' for determining this. pub fn mongo_create_simple_index(conn: *mut Connection, ns: *const c_char, field: *const c_char, options: c_int, out: *mut Bson) -> c_int; // Create a capped collection. // // @param conn a mongo object. // @param ns the namespace (e.g., "dbname.collectioname") // @param size the size of the capped collection in bytes. // @param max the 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. pub fn mongo_create_capped_collection(conn: *mut Connection, db: *const c_char, collection: *const c_char, size: c_int, max: c_int, out: *mut Bson) -> c_int; // Run a command on a MongoDB server. // // @param conn a mongo object. // @param db the name of the database. // @param command the BSON command to run. // @param out the BSON result of the command. // // @return OK if the command ran without error. pub fn mongo_run_command(conn: *mut Connection, db: *const c_char, command: *const Bson, out: *mut Bson) -> c_int; // Run a command that accepts a simple string key and integer value. // // @param conn a mongo object. // @param db the name of the database. // @param cmd the command to run. // @param arg the integer argument to the command. // @param out the BSON result of the command. // // @return OK or an error code. pub fn mongo_simple_int_command(conn: *mut Connection, db: *const c_char, cmd: *const c_char, arg: c_int, out: *mut Bson) -> c_int; // Run a command that accepts a simple string key and value. // // @param conn a mongo object. // @param db the name of the database. // @param cmd the command to run. // @param arg the string argument to the command. // @param out the BSON result of the command. // // @return true if the command ran without error. pub fn mongo_simple_str_command(conn: *mut Connection, db: *const c_char, cmd: *const c_char, arg: *const c_char, out: *mut Bson) -> c_int; // Drop a database. // // @param conn a mongo object. // @param db the name of the database to drop. // // @return OK or an error code. pub fn mongo_cmd_drop_db(conn: *mut Connection, db: *const c_char) -> c_int; // Drop a collection. // // @param conn a mongo object. // @param db the name of the database. // @param collection the name of the collection to drop. // @param out a BSON document containing the result of the command. // // @return true if the collection drop was successful. pub fn mongo_cmd_drop_collection(conn: *mut Connection, db: *const c_char, collection: *const c_char, out: *mut Bson) -> c_int; // Add a database user. // // @param conn a mongo object. // @param db the database in which to add the user. // @param user the user name // @param pass the user password // // @return OK or ERROR. pub fn mongo_cmd_add_user(conn: *mut Connection, db: *const c_char, user: *const c_char, pass: *const c_char) -> c_int; // Authenticate a user. // // @param conn a mongo object. // @param db the database to authenticate against. // @param user the user name to authenticate. // @param pass the user's password. // // @return OK on sucess and ERROR on failure. pub fn mongo_cmd_authenticate(conn: *mut Connection, db: *const c_char, user: *const c_char, pass: *const c_char) -> c_int; // Check if the current server is a master. // // @param conn a mongo object. // @param out a BSON result of the command. // // @return true if the server is a master. // return value is master status pub fn mongo_cmd_ismaster(conn: *mut Connection, out: *mut Bson) -> c_int; // Get the error for the last command with the current connection. // // @param conn a mongo object. // @param db the name of the database. // @param out a BSON object containing the error details. // // @return OK if no error and ERROR on error. On error, check the values // of conn.last_err_code and conn.last_err_str for the error status. // // @note May not return bson data when returning ERROR, // Use bson_has_data() on the returned 'out' for determining this. pub fn mongo_cmd_get_last_error(conn: *mut Connection, db: *const c_char, out: *mut Bson) -> c_int; // Get the most recent error with the current connection. // // @param conn a mongo object. // @param db the name of the database. // @param out a BSON object containing the error details. // // @return OK if no error and ERROR on error. On error, check the values // of conn.last_err_code and conn.last_err_str for the error status. // // @note May not return bson data when returning ERROR, // Use bson_has_data() on the returned 'out' for determining this. pub fn mongo_cmd_get_prev_error(conn: *mut Connection, db: *const c_char, out: *mut Bson) -> c_int; // Reset the error state for the connection. // // @param conn a mongo object. // @param db the name of the database. pub fn mongo_cmd_reset_error(conn: *mut Connection, db: *const c_char); /////////////////////////////////////////////////////////////////////// // Utility API /////////////////////////////////////////////////////////////////////// pub fn mongo_alloc() -> *mut Connection; pub fn mongo_dealloc(conn: *mut Connection); pub fn mongo_get_err(conn: *mut Connection) -> c_int; pub fn mongo_is_connected(conn: *mut Connection) -> c_int; pub fn mongo_get_op_timeout(conn: *mut Connection) -> c_int; pub fn mongo_get_primary(conn: *mut Connection) -> *const c_char; pub fn mongo_get_socket(conn: *mut Connection) -> c_int; pub fn mongo_get_host_count(conn: *mut Connection) -> c_int; pub fn mongo_get_host(conn: *mut Connection, i: c_int) -> *const c_char; pub fn mongo_write_concern_alloc() -> *mut WriteConcern; pub fn mongo_write_concern_dealloc(write_concern: *mut WriteConcern); pub fn mongo_cursor_alloc() -> *mut Cursor; pub fn mongo_cursor_dealloc(mongo_cursor: *mut Cursor); pub fn mongo_get_server_err(conn: *mut Connection) -> c_int; pub fn mongo_get_server_err_string(conn: *mut Connection) -> *const c_char; // Set an error on a mongo connection object. Mostly for internal use. // // @param conn a mongo connection object. // @param err a driver error code of mongo_error_t. // @param errstr a string version of the error. // @param errorcode Currently errno or WSAGetLastError(). pub fn __mongo_set_error(conn: *mut Connection, err: Error, errstr: *const c_char, errorcode: c_int); // Clear all errors stored on a mongo connection object. // // @param conn a mongo connection object. pub fn mongo_clear_errors(conn: *mut Connection); }