rpm  5.4.15
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
mongo.c File Reference
#include "system.h"
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <fcntl.h>
#include <rpmiotypes.h>
#include <rpmio.h>
#include <rpmlog.h>
#include <rpmurl.h>
#include <mongo.h>
#include "debug.h"
Include dependency graph for mongo.c:

Go to the source code of this file.

Data Structures

struct  gridfs
 
struct  gridfile
 

Macros

#define _RPMMGO_INTERNAL
 
#define INVALID_SOCKET   (-1)
 
#define NI_MAXSERV   32
 
#define INDEX_NAME_BUFFER_SIZE   255
 
#define INDEX_NAME_MAX_LENGTH   (INDEX_NAME_BUFFER_SIZE - 1)
 

Typedefs

typedef uint64_t gridfs_offset
 
typedef int(* gridfs_chunk_filter_func )(char **targetBuf, size_t *targetLen, const char *srcBuf, size_t srcLen, int flags)
 
typedef size_t(* gridfs_pending_data_size_func )(int flags)
 

Enumerations

enum  { DEFAULT_CHUNK_SIZE = 256 * 1024 }
 
enum  gridfile_storage_type { GRIDFILE_DEFAULT = 0, GRIDFILE_NOMD5 = ( 1<<0 ) }
 

Functions

static char * _strupr (char *str)
 
MONGO_EXPORT gridfsgridfs_alloc (void)
 
MONGO_EXPORT void gridfs_dealloc (gridfs *gfs)
 
MONGO_EXPORT gridfilegridfile_create (void)
 
MONGO_EXPORT void gridfile_dealloc (gridfile *gf)
 
MONGO_EXPORT void gridfile_get_descriptor (gridfile *gf, bson *out)
 
MONGO_EXPORT void gridfs_set_chunk_filter_funcs (gridfs_chunk_filter_func writeFilter, gridfs_chunk_filter_func readFilter, gridfs_pending_data_size_func pendingDataNeededSize)
 
MONGO_EXPORT int gridfs_init (mongo *client, const char *dbname, const char *prefix, gridfs *gfs)
 Initializes a GridFS object. More...
 
MONGO_EXPORT void gridfs_destroy (gridfs *gfs)
 Destroys a GridFS object. More...
 
MONGO_EXPORT int gridfile_init (gridfs *gfs, const bson *meta, gridfile *gfile)
 Initializes a GridFile containing the GridFS and file bson. More...
 
MONGO_EXPORT void gridfile_destroy (gridfile *gfile)
 Destroys the GridFile. More...
 
MONGO_EXPORT int gridfile_writer_init (gridfile *gfile, gridfs *gfs, const char *remote_name, const char *content_type, int flags)
 Initializes a gridfile for writing incrementally with gridfs_write_buffer. More...
 
MONGO_EXPORT gridfs_offset gridfile_write_buffer (gridfile *gfile, const char *data, gridfs_offset length)
 Write to a GridFS file incrementally. More...
 
MONGO_EXPORT int gridfile_writer_done (gridfile *gfile)
 Signal that writing of this gridfile is complete by writing any buffered chunks along with the entry in the files collection. More...
 
MONGO_EXPORT int gridfs_store_buffer (gridfs *gfs, const char *data, gridfs_offset length, const char *remotename, const char *contenttype, int flags)
 Store a buffer as a GridFS file. More...
 
MONGO_EXPORT int gridfs_store_file (gridfs *gfs, const char *filename, const char *remotename, const char *contenttype, int flags)
 Open the file referenced by filename and store it as a GridFS file. More...
 
MONGO_EXPORT int gridfs_remove_filename (gridfs *gfs, const char *filename)
 Removes the files referenced by filename from the db. More...
 
MONGO_EXPORT int gridfs_find_query (gridfs *gfs, const bson *query, gridfile *gfile)
 Find the first file matching the provided query within the GridFS files collection, and return the file as a GridFile. More...
 
MONGO_EXPORT int gridfs_find_filename (gridfs *gfs, const char *filename, gridfile *gfile)
 Find the first file referenced by filename within the GridFS and return it as a GridFile. More...
 
MONGO_EXPORT bson_bool_t gridfile_exists (const gridfile *gfile)
 Returns whether or not the GridFile exists. More...
 
MONGO_EXPORT const char * gridfile_get_filename (const gridfile *gfile)
 Returns the filename of GridFile. More...
 
MONGO_EXPORT int gridfile_get_chunksize (const gridfile *gfile)
 Returns the size of the chunks of the GridFile. More...
 
MONGO_EXPORT gridfs_offset gridfile_get_contentlength (const gridfile *gfile)
 Returns the length of GridFile's data. More...
 
MONGO_EXPORT const char * gridfile_get_contenttype (const gridfile *gfile)
 Returns the MIME type of the GridFile. More...
 
MONGO_EXPORT bson_date_t gridfile_get_uploaddate (const gridfile *gfile)
 Returns the upload date of GridFile. More...
 
MONGO_EXPORT const char * gridfile_get_md5 (const gridfile *gfile)
 Returns the MD5 of GridFile. More...
 
MONGO_EXPORT bson_oid_t gridfile_get_id (const gridfile *gfile)
 Returns the _id in GridFile specified by name. More...
 
MONGO_EXPORT const char * gridfile_get_field (gridfile *gfile, const char *name)
 Returns the field in GridFile specified by name. More...
 
MONGO_EXPORT bson_bool_t gridfs_get_caseInsensitive (const gridfs *gfs)
 Returns the caseInsensitive flag value of gfs. More...
 
MONGO_EXPORT void gridfs_set_caseInsensitive (gridfs *gfs, bson_bool_t newValue)
 Sets the caseInsensitive flag value of gfs. More...
 
MONGO_EXPORT void gridfile_set_flags (gridfile *gfile, int flags)
 Sets the flags of the GridFile. More...
 
MONGO_EXPORT int gridfile_get_flags (const gridfile *gfile)
 gets the flags of the GridFile More...
 
MONGO_EXPORT bson_bool_t gridfile_get_boolean (const gridfile *gfile, const char *name)
 Returns a boolean field in GridFile specified by name. More...
 
MONGO_EXPORT void gridfile_get_metadata (const gridfile *gfile, bson *metadata, bson_bool_t copyData)
 Returns the metadata of GridFile. More...
 
MONGO_EXPORT int gridfile_get_numchunks (const gridfile *gfile)
 Returns the number of chunks in the GridFile. More...
 
MONGO_EXPORT void gridfile_get_chunk (gridfile *gfile, int n, bson *out)
 Returns chunk n of GridFile. More...
 
MONGO_EXPORT mongo_cursorgridfile_get_chunks (gridfile *gfile, size_t start, size_t size)
 Returns a mongo_cursor of size chunks starting with chunk start More...
 
MONGO_EXPORT gridfs_offset gridfile_write_file (gridfile *gfile, FILE *stream)
 Writes the GridFile to a stream. More...
 
MONGO_EXPORT gridfs_offset gridfile_read_buffer (gridfile *gfile, char *buf, gridfs_offset size)
 Reads length bytes from the GridFile to a buffer and updates the position in the file. More...
 
MONGO_EXPORT gridfs_offset gridfile_seek (gridfile *gfile, gridfs_offset offset)
 Updates the position in the file (If the offset goes beyond the contentlength, the position is updated to the end of the file.) More...
 
MONGO_EXPORT gridfs_offset gridfile_truncate (gridfile *gfile, gridfs_offset newSize)
 
MONGO_EXPORT gridfs_offset gridfile_expand (gridfile *gfile, gridfs_offset bytesToExpand)
 
MONGO_EXPORT gridfs_offset gridfile_set_size (gridfile *gfile, gridfs_offset newSize)
 
static int gridfs_default_chunk_filter (char **targetBuf, size_t *targetLen, const char *srcData, size_t srcLen, int flags)
 
static size_t gridfs_default_pending_data_size (int flags)
 
static bsonchunk_new (bson_oid_t id, int chunkNumber, char **dataBuf, const char *srcData, size_t len, int flags)
 
static void chunk_free (bson *oChunk)
 
static int bson_append_string_uppercase (bson *b, const char *name, const char *str, bson_bool_t upperCase)
 
static int gridfs_insert_file (gridfs *gfs, const char *name, const bson_oid_t id, gridfs_offset length, const char *contenttype, int flags, int chunkSize)
 
static int gridfile_flush_pendingchunk (gridfile *gfile)
 
static void gridfile_init_flags (gridfile *gfile)
 
static void gridfile_init_length (gridfile *gfile)
 
static void gridfile_init_chunkSize (gridfile *gfile)
 
static void gridfile_prepare_chunk_key_bson (bson *q, bson_oid_t *id, int chunk_num)
 
static int gridfile_load_pending_data_with_pos_chunk (gridfile *gfile)
 
static gridfs_offset gridfile_read_from_pending_buffer (gridfile *gfile, gridfs_offset totalBytesToRead, char *buf, int *first_chunk)
 
static gridfs_offset gridfile_load_from_chunks (gridfile *gfile, int total_chunks, gridfs_offset chunksize, mongo_cursor *chunks, char *buf, gridfs_offset bytes_left)
 
static gridfs_offset gridfile_fill_buf_from_chunk (gridfile *gfile, const bson *chunk, gridfs_offset chunksize, char **buf, int *allocatedMem, char **targetBuf, size_t *targetBufLen, gridfs_offset *bytes_left, int chunkNo)
 
static int gridfile_remove_chunks (gridfile *gfile, int deleteFromChunk)
 
int mongo_env_close_socket (SOCKET socket)
 
static int mongo_env_sock_init (void)
 
static int mongo_env_write_socket (mongo *conn, const void *buf, size_t len)
 
static int mongo_env_read_socket (mongo *conn, void *buf, size_t len)
 
static int mongo_env_set_socket_op_timeout (mongo *conn, int millis)
 
static int mongo_env_unix_socket_connect (mongo *conn, const char *sock_path)
 
static int mongo_env_socket_connect (mongo *conn, const char *host, int port)
 
MONGO_EXPORT mongomongo_alloc (void)
 
MONGO_EXPORT void mongo_dealloc (mongo *conn)
 
MONGO_EXPORT int mongo_get_err (mongo *conn)
 
MONGO_EXPORT int mongo_is_connected (mongo *conn)
 
MONGO_EXPORT int mongo_get_op_timeout (mongo *conn)
 
static const char * _get_host_port (mongo_host_port *hp)
 
MONGO_EXPORT const char * mongo_get_primary (mongo *conn)
 
MONGO_EXPORT SOCKET mongo_get_socket (mongo *conn)
 
MONGO_EXPORT int mongo_get_host_count (mongo *conn)
 
MONGO_EXPORT const char * mongo_get_host (mongo *conn, int i)
 
MONGO_EXPORT mongo_write_concernmongo_write_concern_alloc (void)
 
MONGO_EXPORT void mongo_write_concern_dealloc (mongo_write_concern *write_concern)
 
MONGO_EXPORT mongo_cursormongo_cursor_alloc (void)
 
MONGO_EXPORT void mongo_cursor_dealloc (mongo_cursor *cursor)
 
MONGO_EXPORT int mongo_get_server_err (mongo *conn)
 
MONGO_EXPORT const char * mongo_get_server_err_string (mongo *conn)
 
MONGO_EXPORT void __mongo_set_error (mongo *conn, mongo_error_t err, const char *str, int errcode)
 
MONGO_EXPORT void mongo_clear_errors (mongo *conn)
 
static char * mongo_ns_to_cmd_db (const char *ns)
 
MONGO_EXPORT int mongo_validate_ns (mongo *conn, const char *ns)
 
static void mongo_set_last_error (mongo *conn, bson_iterator *it, bson *obj)
 
static mongo_messagemongo_message_create (size_t len, int id, int responseTo, int op)
 
static int mongo_message_send (mongo *conn, mongo_message *mm)
 
static int mongo_read_response (mongo *conn, mongo_reply **reply)
 
static char * mongo_data_append (char *start, const void *data, size_t len)
 
static char * mongo_data_append32 (char *start, const void *data)
 
static char * mongo_data_append64 (char *start, const void *data)
 
static int mongo_check_is_master (mongo *conn)
 
MONGO_EXPORT void mongo_init_sockets (void)
 
MONGO_EXPORT void mongo_init (mongo *conn)
 
MONGO_EXPORT int mongo_client (mongo *conn, const char *host, int port)
 
MONGO_EXPORT int mongo_connect (mongo *conn, const char *host, int port)
 
MONGO_EXPORT void mongo_replica_set_init (mongo *conn, const char *name)
 
MONGO_EXPORT void mongo_replset_init (mongo *conn, const char *name)
 
static void mongo_replica_set_add_node (mongo_host_port **list, const char *host, int port)
 
static void mongo_replica_set_free_list (mongo_host_port **list)
 
MONGO_EXPORT void mongo_replica_set_add_seed (mongo *conn, const char *host, int port)
 
MONGO_EXPORT void mongo_replset_add_seed (mongo *conn, const char *host, int port)
 
void mongo_parse_host (const char *host_string, mongo_host_port *host_port)
 Utility function for converting a host-port string to a mongo_host_port. More...
 
static void mongo_replica_set_check_seed (mongo *conn)
 
static int mongo_replica_set_check_host (mongo *conn)
 
MONGO_EXPORT int mongo_replica_set_client (mongo *conn)
 
MONGO_EXPORT int mongo_replset_connect (mongo *conn)
 
MONGO_EXPORT int mongo_set_op_timeout (mongo *conn, int millis)
 
MONGO_EXPORT int mongo_reconnect (mongo *conn)
 
MONGO_EXPORT int mongo_check_connection (mongo *conn)
 
MONGO_EXPORT void mongo_disconnect (mongo *conn)
 
MONGO_EXPORT void mongo_destroy (mongo *conn)
 
static int mongo_bson_valid (mongo *conn, const bson *bson, int write)
 
static int mongo_cursor_bson_valid (mongo_cursor *cursor, const bson *bson)
 
static int mongo_check_last_error (mongo *conn, const char *ns, mongo_write_concern *write_concern)
 
static int mongo_choose_write_concern (mongo *conn, mongo_write_concern *custom_write_concern, mongo_write_concern **write_concern)
 
static int mongo_message_send_and_check_write_concern (mongo *conn, const char *ns, mongo_message *mm, mongo_write_concern *write_concern)
 
MONGO_EXPORT int mongo_insert (mongo *conn, const char *ns, const bson *bson, mongo_write_concern *custom_write_concern)
 
MONGO_EXPORT int mongo_insert_batch (mongo *conn, const char *ns, const bson **bsons, int count, mongo_write_concern *custom_write_concern, int flags)
 
MONGO_EXPORT int mongo_update (mongo *conn, const char *ns, const bson *cond, const bson *op, int flags, mongo_write_concern *custom_write_concern)
 
MONGO_EXPORT int mongo_remove (mongo *conn, const char *ns, const bson *cond, mongo_write_concern *custom_write_concern)
 
MONGO_EXPORT void mongo_write_concern_init (mongo_write_concern *write_concern)
 
MONGO_EXPORT int mongo_write_concern_finish (mongo_write_concern *write_concern)
 
MONGO_EXPORT void mongo_write_concern_destroy (mongo_write_concern *write_concern)
 Free the write_concern object (specifically, the BSON object that it holds). More...
 
MONGO_EXPORT void mongo_set_write_concern (mongo *conn, mongo_write_concern *write_concern)
 
MONGO_EXPORT int mongo_write_concern_get_w (mongo_write_concern *write_concern)
 
MONGO_EXPORT int mongo_write_concern_get_wtimeout (mongo_write_concern *write_concern)
 
MONGO_EXPORT int mongo_write_concern_get_j (mongo_write_concern *write_concern)
 
MONGO_EXPORT int mongo_write_concern_get_fsync (mongo_write_concern *write_concern)
 
MONGO_EXPORT const char * mongo_write_concern_get_mode (mongo_write_concern *write_concern)
 
MONGO_EXPORT bsonmongo_write_concern_get_cmd (mongo_write_concern *write_concern)
 
MONGO_EXPORT void mongo_write_concern_set_w (mongo_write_concern *write_concern, int w)
 
MONGO_EXPORT void mongo_write_concern_set_wtimeout (mongo_write_concern *write_concern, int wtimeout)
 
MONGO_EXPORT void mongo_write_concern_set_j (mongo_write_concern *write_concern, int j)
 
MONGO_EXPORT void mongo_write_concern_set_fsync (mongo_write_concern *write_concern, int fsync)
 
MONGO_EXPORT void mongo_write_concern_set_mode (mongo_write_concern *write_concern, const char *mode)
 
static int mongo_cursor_op_query (mongo_cursor *cursor)
 
static int mongo_cursor_get_more (mongo_cursor *cursor)
 
MONGO_EXPORT mongo_cursormongo_find (mongo *conn, const char *ns, const bson *query, const bson *fields, int limit, int skip, int options)
 
MONGO_EXPORT int mongo_find_one (mongo *conn, const char *ns, const bson *query, const bson *fields, bson *out)
 
MONGO_EXPORT void mongo_cursor_init (mongo_cursor *cursor, mongo *conn, const char *ns)
 
MONGO_EXPORT void mongo_cursor_set_query (mongo_cursor *cursor, const bson *query)
 
MONGO_EXPORT void mongo_cursor_set_fields (mongo_cursor *cursor, const bson *fields)
 
MONGO_EXPORT void mongo_cursor_set_skip (mongo_cursor *cursor, int skip)
 
MONGO_EXPORT void mongo_cursor_set_limit (mongo_cursor *cursor, int limit)
 
MONGO_EXPORT void mongo_cursor_set_options (mongo_cursor *cursor, int options)
 
MONGO_EXPORT const char * mongo_cursor_data (mongo_cursor *cursor)
 
MONGO_EXPORT const bsonmongo_cursor_bson (mongo_cursor *cursor)
 
MONGO_EXPORT int mongo_cursor_next (mongo_cursor *cursor)
 
MONGO_EXPORT int mongo_cursor_destroy (mongo_cursor *cursor)
 
MONGO_EXPORT int mongo_create_index (mongo *conn, const char *ns, const bson *key, const char *name, int options, bson *out)
 
MONGO_EXPORT bson_bool_t mongo_create_simple_index (mongo *conn, const char *ns, const char *field, int options, bson *out)
 
MONGO_EXPORT int mongo_create_capped_collection (mongo *conn, const char *db, const char *collection, int size, int max, bson *out)
 
MONGO_EXPORT double mongo_count (mongo *conn, const char *db, const char *coll, const bson *query)
 
MONGO_EXPORT int mongo_run_command (mongo *conn, const char *db, const bson *command, bson *out)
 
MONGO_EXPORT int mongo_simple_int_command (mongo *conn, const char *db, const char *cmdstr, int arg, bson *out)
 
MONGO_EXPORT int mongo_simple_str_command (mongo *conn, const char *db, const char *cmdstr, const char *arg, bson *out)
 
MONGO_EXPORT int mongo_cmd_drop_db (mongo *conn, const char *db)
 
MONGO_EXPORT int mongo_cmd_drop_collection (mongo *conn, const char *db, const char *collection, bson *out)
 
MONGO_EXPORT void mongo_cmd_reset_error (mongo *conn, const char *db)
 
static int mongo_cmd_get_error_helper (mongo *conn, const char *db, bson *realout, const char *cmdtype)
 
MONGO_EXPORT int mongo_cmd_get_prev_error (mongo *conn, const char *db, bson *out)
 
MONGO_EXPORT int mongo_cmd_get_last_error (mongo *conn, const char *db, bson *out)
 
MONGO_EXPORT bson_bool_t mongo_cmd_ismaster (mongo *conn, bson *realout)
 
static int mongo_pass_digest (mongo *conn, const char *user, const char *pass, char hex_digest[33])
 
MONGO_EXPORT int mongo_cmd_add_user (mongo *conn, const char *db, const char *user, const char *pass)
 
MONGO_EXPORT bson_bool_t mongo_cmd_authenticate (mongo *conn, const char *db, const char *user, const char *pass)
 
static void rpmmgoFini (void *_mgo)
 
static rpmmgo rpmmgoGetPool (rpmioPool pool)
 
rpmmgo rpmmgoNew (const char *fn, int flags)
 Create and load a mongo wrapper. More...
 

Variables

int _rpmmgo_debug = 0
 
rpmmgo _rpmmgoI
 
static const int zero = 0
 
static const int one = 1
 
static gridfs_chunk_filter_func gridfs_write_filter = gridfs_default_chunk_filter
 
static gridfs_chunk_filter_func gridfs_read_filter = gridfs_default_chunk_filter
 
static
gridfs_pending_data_size_func 
gridfs_pending_data_size = gridfs_default_pending_data_size
 
static const int ZERO = 0
 
static const int ONE = 1
 
static char WC1_data [] = {23,0,0,0,16,103,101,116,108,97,115,116,101,114,114,111,114,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0}
 
static bson WC1_cmd
 
static mongo_write_concern WC1 = { 1, 0, 0, 0, 0, &WC1_cmd }
 
rpmioPool _rpmmgoPool = NULL
 

Macro Definition Documentation

#define _RPMMGO_INTERNAL

Definition at line 36 of file mongo.c.

#define INDEX_NAME_BUFFER_SIZE   255

Definition at line 3194 of file mongo.c.

Referenced by mongo_create_index().

#define INDEX_NAME_MAX_LENGTH   (INDEX_NAME_BUFFER_SIZE - 1)

Definition at line 3195 of file mongo.c.

Referenced by mongo_create_index().

#define INVALID_SOCKET   (-1)

Definition at line 1582 of file mongo.c.

Referenced by mongo_env_socket_connect(), and mongo_env_unix_socket_connect().

#define NI_MAXSERV   32

Definition at line 1588 of file mongo.c.

Referenced by ftpReq(), mongo_env_socket_connect(), and tcpConnect().

Typedef Documentation

typedef int( * gridfs_chunk_filter_func)(char **targetBuf, size_t *targetLen, const char *srcBuf, size_t srcLen, int flags)

Definition at line 96 of file mongo.c.

typedef uint64_t gridfs_offset

Definition at line 56 of file mongo.c.

typedef size_t( * gridfs_pending_data_size_func)(int flags)

Definition at line 97 of file mongo.c.

Enumeration Type Documentation

anonymous enum
Enumerator
DEFAULT_CHUNK_SIZE 

Definition at line 54 of file mongo.c.

Enumerator
GRIDFILE_DEFAULT 
GRIDFILE_NOMD5 

Definition at line 84 of file mongo.c.

Function Documentation

MONGO_EXPORT void __mongo_set_error ( mongo conn,
mongo_error_t  err,
const char *  str,
int  errcode 
)
static const char* _get_host_port ( mongo_host_port hp)
static

Definition at line 1794 of file mongo.c.

References bson_sprintf, mongo_host_port::host, and mongo_host_port::port.

Referenced by mongo_get_host(), and mongo_get_primary().

static char * _strupr ( char *  str)
static

Definition at line 462 of file mongo.c.

References str.

Referenced by bson_append_string_uppercase().

static int bson_append_string_uppercase ( bson b,
const char *  name,
const char *  str,
bson_bool_t  upperCase 
)
static

Definition at line 644 of file mongo.c.

References _strupr().

Referenced by gridfs_find_filename(), gridfs_insert_file(), and gridfs_remove_filename().

static void chunk_free ( bson oChunk)
static

Definition at line 544 of file mongo.c.

Referenced by gridfile_flush_pendingchunk(), and gridfile_write_buffer().

static bson* chunk_new ( bson_oid_t  id,
int  chunkNumber,
char **  dataBuf,
const char *  srcData,
size_t  len,
int  flags 
)
static

Definition at line 529 of file mongo.c.

References b, BSON_BIN_BINARY, bson_init_size(), and gridfs_write_filter.

Referenced by gridfile_flush_pendingchunk(), and gridfile_write_buffer().

MONGO_EXPORT gridfile * gridfile_create ( void  )

Definition at line 493 of file mongo.c.

MONGO_EXPORT void gridfile_dealloc ( gridfile gf)

Definition at line 499 of file mongo.c.

MONGO_EXPORT void gridfile_destroy ( gridfile gfile)

Destroys the GridFile.

Parameters
oGridFIle- the GridFile being destroyed

Definition at line 1005 of file mongo.c.

References gridfile::meta.

Referenced by gridfile_writer_init(), gridfs_store_buffer(), and gridfs_store_file().

MONGO_EXPORT bson_bool_t gridfile_exists ( const gridfile gfile)

Returns whether or not the GridFile exists.

Parameters
gfile- the GridFile being examined

Definition at line 1027 of file mongo.c.

References gridfile::meta.

Referenced by gridfile_writer_init().

MONGO_EXPORT gridfs_offset gridfile_expand ( gridfile gfile,
gridfs_offset  bytesToExpand 
)
Parameters
gfile- the working GridFile
bytesToExpand- number of bytes the file will be expanded

Definition at line 1541 of file mongo.c.

References gridfile_get_chunksize(), gridfile_get_contentlength(), gridfile_seek(), and gridfile_write_buffer().

Referenced by gridfile_set_size().

static gridfs_offset gridfile_fill_buf_from_chunk ( gridfile gfile,
const bson chunk,
gridfs_offset  chunksize,
char **  buf,
int *  allocatedMem,
char **  targetBuf,
size_t *  targetBufLen,
gridfs_offset bytes_left,
int  chunkNo 
)
static

Definition at line 1432 of file mongo.c.

References BSON_EOO, bson_fatal_msg(), gridfile::flags, gridfs_read_filter, and gridfile::pos.

Referenced by gridfile_load_from_chunks().

static int gridfile_flush_pendingchunk ( gridfile gfile)
static
MONGO_EXPORT bson_bool_t gridfile_get_boolean ( const gridfile gfile,
const char *  name 
)

Returns a boolean field in GridFile specified by name.

Parameters
gfile- the working GridFile
name- the name of the field to be returned
Returns
- the boolean of the field specified (NULL if none exists)

Definition at line 1104 of file mongo.c.

References BSON_EOO, and gridfile::meta.

MONGO_EXPORT void gridfile_get_chunk ( gridfile gfile,
int  n,
bson out 
)

Returns chunk n of GridFile.

Parameters
gfile- the working GridFile
Returns
- the nth chunk of the Gridfile

Definition at line 1287 of file mongo.c.

References gridfs::chunks_ns, gridfs::client, gridfile::gfs, gridfile_get_id(), mongo_find_one(), MONGO_OK, and query.

Referenced by gridfile_load_pending_data_with_pos_chunk().

MONGO_EXPORT mongo_cursor * gridfile_get_chunks ( gridfile gfile,
size_t  start,
size_t  size 
)

Returns a mongo_cursor of size chunks starting with chunk start

Parameters
gfile- the working GridFile
start- the first chunk in the cursor
size- the number of chunks to be returned
Returns
- mongo_cursor of the chunks (must be destroyed after use)

Definition at line 1305 of file mongo.c.

References BSON_EOO, gridfs::chunks_ns, gridfs::client, command, gridfile::gfs, gridfile::id, gridfile::meta, mongo_find(), and query.

Referenced by gridfile_read_buffer().

MONGO_EXPORT int gridfile_get_chunksize ( const gridfile gfile)

Returns the size of the chunks of the GridFile.

Parameters
gfile- the working GridFile
Returns
- the size of the chunks of the Gridfile

Definition at line 1043 of file mongo.c.

References BSON_EOO, gridfile::chunkSize, DEFAULT_CHUNK_SIZE, and gridfile::meta.

Referenced by gridfile_expand(), gridfile_get_contentlength(), gridfile_read_buffer(), gridfile_read_from_pending_buffer(), gridfile_seek(), gridfile_truncate(), and gridfile_writer_init().

MONGO_EXPORT gridfs_offset gridfile_get_contentlength ( const gridfile gfile)

Returns the length of GridFile's data.

Parameters
gfile- the working GridFile
Returns
- the length of the Gridfile's data

Definition at line 1054 of file mongo.c.

References gridfile::chunk_num, gridfile_get_chunksize(), gridfile::length, MAX, and gridfile::pending_len.

Referenced by gridfile_expand(), gridfile_read_buffer(), gridfile_seek(), gridfile_set_size(), and gridfile_truncate().

MONGO_EXPORT const char * gridfile_get_contenttype ( const gridfile gfile)

Returns the MIME type of the GridFile.

Parameters
gfile- the working GridFile
Returns
- the MIME type of the Gridfile (NULL if no type specified)

Definition at line 1060 of file mongo.c.

References BSON_EOO, and gridfile::meta.

MONGO_EXPORT void gridfile_get_descriptor ( gridfile gf,
bson out 
)

Definition at line 503 of file mongo.c.

References gridfile::meta.

MONGO_EXPORT const char * gridfile_get_field ( gridfile gfile,
const char *  name 
)

Returns the field in GridFile specified by name.

Parameters
gfile- the working GridFile
name- the name of the field to be returned
Returns
- the data of the field specified (NULL if none exists)

Definition at line 1095 of file mongo.c.

References BSON_EOO, and gridfile::meta.

MONGO_EXPORT const char * gridfile_get_filename ( const gridfile gfile)

Returns the filename of GridFile.

Parameters
gfile- the working GridFile
Returns
- the filename of the Gridfile

Definition at line 1032 of file mongo.c.

References BSON_EOO, gridfs::caseInsensitive, gridfile::gfs, gridfile::meta, and gridfile::remote_name.

MONGO_EXPORT int gridfile_get_flags ( const gridfile gfile)

gets the flags of the GridFile

Parameters
gfile- the working GridFile
Returns
- void

Definition at line 1091 of file mongo.c.

References gridfile::flags.

MONGO_EXPORT bson_oid_t gridfile_get_id ( const gridfile gfile)

Returns the _id in GridFile specified by name.

Parameters
gfile- the working GridFile
Returns
- the _id field in metadata

Definition at line 1015 of file mongo.c.

References BSON_EOO, BSON_OID, gridfile::id, and gridfile::meta.

Referenced by gridfile_get_chunk(), gridfile_remove_chunks(), and gridfile_writer_init().

MONGO_EXPORT const char * gridfile_get_md5 ( const gridfile gfile)

Returns the MD5 of GridFile.

Parameters
gfile- the working GridFile
Returns
- the MD5 of the Gridfile

Definition at line 1078 of file mongo.c.

References BSON_EOO, and gridfile::meta.

MONGO_EXPORT void gridfile_get_metadata ( const gridfile gfile,
bson metadata,
bson_bool_t  copyData 
)

Returns the metadata of GridFile.

Calls bson_init_empty on metadata if none exits.

Note
When copyData is false, the metadata object becomes invalid when gfile is destroyed. For either value of copyData, you must pass the metadata object to bson_destroy when you are done using it.
Parameters
gfile- the working GridFile
metadataan uninitialized BSON object to receive the metadata.
copyDatawhen true, makes a copy of the scope data which will remain valid when the grid file is deallocated.

Definition at line 1113 of file mongo.c.

References BSON_EOO, and gridfile::meta.

MONGO_EXPORT int gridfile_get_numchunks ( const gridfile gfile)

Returns the number of chunks in the GridFile.

Parameters
gfile- the working GridFile
Returns
- the number of chunks in the Gridfile

Definition at line 1126 of file mongo.c.

References BSON_EOO, BSON_INT, DEFAULT_CHUNK_SIZE, and gridfile::meta.

MONGO_EXPORT bson_date_t gridfile_get_uploaddate ( const gridfile gfile)

Returns the upload date of GridFile.

Parameters
gfile- the working GridFile
Returns
- the upload date of the Gridfile

Definition at line 1069 of file mongo.c.

References BSON_EOO, and gridfile::meta.

MONGO_EXPORT int gridfile_init ( gridfs gfs,
const bson meta,
gridfile gfile 
)

Initializes a GridFile containing the GridFS and file bson.

Parameters
gfs- the GridFS where the GridFile is located
meta- the file object
gfile- the output GridFile that is being initialized
Returns
- MONGO_OK or MONGO_ERROR.

Definition at line 878 of file mongo.c.

References gridfile::gfs, gridfile_init_chunkSize(), gridfile_init_flags(), gridfile_init_length(), gridfile::meta, MONGO_ERROR, MONGO_OK, gridfile::pending_data, gridfile::pending_len, and gridfile::pos.

Referenced by gridfs_find_query(), gridfs_store_buffer(), and gridfs_store_file().

static void gridfile_init_chunkSize ( gridfile gfile)
static

Definition at line 925 of file mongo.c.

References BSON_EOO, BSON_INT, gridfile::chunkSize, DEFAULT_CHUNK_SIZE, and gridfile::meta.

Referenced by gridfile_init().

static void gridfile_init_flags ( gridfile gfile)
static

Definition at line 949 of file mongo.c.

References BSON_EOO, gridfile::flags, and gridfile::meta.

Referenced by gridfile_init(), and gridfile_writer_init().

static void gridfile_init_length ( gridfile gfile)
static

Definition at line 937 of file mongo.c.

References BSON_EOO, BSON_INT, gridfile::length, and gridfile::meta.

Referenced by gridfile_init(), and gridfile_writer_init().

static gridfs_offset gridfile_load_from_chunks ( gridfile gfile,
int  total_chunks,
gridfs_offset  chunksize,
mongo_cursor chunks,
char *  buf,
gridfs_offset  bytes_left 
)
static
static int gridfile_load_pending_data_with_pos_chunk ( gridfile gfile)
static
static void gridfile_prepare_chunk_key_bson ( bson q,
bson_oid_t id,
int  chunk_num 
)
static

Definition at line 1152 of file mongo.c.

Referenced by gridfile_flush_pendingchunk(), and gridfile_write_buffer().

MONGO_EXPORT gridfs_offset gridfile_read_buffer ( gridfile gfile,
char *  buf,
gridfs_offset  size 
)

Reads length bytes from the GridFile to a buffer and updates the position in the file.

(assumes the buffer is large enough) (if size is greater than EOF gridfile_read reads until EOF)

Parameters
gfile- the working GridFile
size- the amount of bytes to be read
buf- the buffer to read to
Returns
- the number of bytes read

Definition at line 1354 of file mongo.c.

References gridfile_flush_pendingchunk(), gridfile_get_chunks(), gridfile_get_chunksize(), gridfile_get_contentlength(), gridfile_load_from_chunks(), gridfile_read_from_pending_buffer(), mongo_cursor_destroy(), MONGO_OK, gridfile::pos, and size.

Referenced by gridfile_write_file().

static gridfs_offset gridfile_read_from_pending_buffer ( gridfile gfile,
gridfs_offset  totalBytesToRead,
char *  buf,
int *  first_chunk 
)
static
static int gridfile_remove_chunks ( gridfile gfile,
int  deleteFromChunk 
)
static

Definition at line 1495 of file mongo.c.

References gridfs::chunks_ns, gridfs::client, gridfile::gfs, gridfile_get_id(), and mongo_remove().

Referenced by gridfile_truncate().

MONGO_EXPORT gridfs_offset gridfile_seek ( gridfile gfile,
gridfs_offset  offset 
)

Updates the position in the file (If the offset goes beyond the contentlength, the position is updated to the end of the file.)

Parameters
gfile- the working GridFile
offset- the position to update to
Returns
- resulting offset location

Definition at line 1463 of file mongo.c.

References gridfile::chunk_num, gridfile_flush_pendingchunk(), gridfile_get_chunksize(), gridfile_get_contentlength(), MONGO_OK, gridfile::pending_len, and gridfile::pos.

Referenced by gridfile_expand(), and gridfile_truncate().

MONGO_EXPORT void gridfile_set_flags ( gridfile gfile,
int  flags 
)

Sets the flags of the GridFile.

Parameters
gfile- the working GridFile
flags- the value of the flags to set on the provided GridFile
Returns
- void

Definition at line 1087 of file mongo.c.

References gridfile::flags, and flags.

MONGO_EXPORT gridfs_offset gridfile_set_size ( gridfile gfile,
gridfs_offset  newSize 
)
Parameters
gfile- the working GridFile
newSize- the new size of file

Definition at line 1569 of file mongo.c.

References gridfile_expand(), gridfile_get_contentlength(), and gridfile_truncate().

MONGO_EXPORT gridfs_offset gridfile_truncate ( gridfile gfile,
gridfs_offset  newSize 
)
MONGO_EXPORT gridfs_offset gridfile_write_buffer ( gridfile gfile,
const char *  data,
gridfs_offset  length 
)

Write to a GridFS file incrementally.

You can call this function any number of times with a new buffer each time. This allows you to effectively stream to a GridFS file. When finished, be sure to call gridfs_writer_done.

Parameters
gfile- GridFile to write to
data- Pointer to buffer with data to be written
length- Size of buffer with data to be written
Returns
- Number of bytes written. If different from length assume somethind went wrong

Definition at line 1220 of file mongo.c.

References chunk_free(), chunk_new(), gridfile::chunk_num, gridfs::chunks_ns, gridfs::client, data, DEFAULT_CHUNK_SIZE, gridfile::flags, gridfile::gfs, gridfile_flush_pendingchunk(), gridfile_load_pending_data_with_pos_chunk(), gridfile_prepare_chunk_key_bson(), gridfile::id, gridfile::length, MONGO_OK, mongo_update(), MONGO_UPDATE_UPSERT, gridfile::pending_data, gridfile::pending_len, and gridfile::pos.

Referenced by gridfile_expand(), gridfs_store_buffer(), and gridfs_store_file().

MONGO_EXPORT gridfs_offset gridfile_write_file ( gridfile gfile,
FILE *  stream 
)

Writes the GridFile to a stream.

Parameters
gfile- the working GridFile
stream- the file stream to write to

Definition at line 1479 of file mongo.c.

References buffer, DEFAULT_CHUNK_SIZE, and gridfile_read_buffer().

MONGO_EXPORT int gridfile_writer_done ( gridfile gfile)

Signal that writing of this gridfile is complete by writing any buffered chunks along with the entry in the files collection.

Returns
- MONGO_OK or MONGO_ERROR.

Definition at line 897 of file mongo.c.

References gridfile::chunkSize, gridfile::content_type, gridfile::flags, gridfile::gfs, gridfile_flush_pendingchunk(), gridfs_insert_file(), gridfile::id, gridfile::length, MONGO_OK, gridfile::pending_data, gridfile::pending_len, and gridfile::remote_name.

Referenced by gridfs_store_buffer(), and gridfs_store_file().

MONGO_EXPORT int gridfile_writer_init ( gridfile gfile,
gridfs gfs,
const char *  remote_name,
const char *  content_type,
int  flags 
)

Initializes a gridfile for writing incrementally with gridfs_write_buffer.

Once initialized, you can write any number of buffers with gridfs_write_buffer. When done, you must call gridfs_writer_done to save the file metadata. +-+-+-+- This modified version of GridFS allows the file to read/write randomly +-+-+-+- when using this function

Definition at line 958 of file mongo.c.

References gridfile::chunk_num, gridfile::chunkSize, gridfile::content_type, gridfile::flags, flags, gridfile::gfs, GRIDFILE_DEFAULT, gridfile_destroy(), gridfile_exists(), gridfile_get_chunksize(), gridfile_get_id(), gridfile_init_flags(), gridfile_init_length(), gridfs_find_filename(), gridfs_pending_data_size, gridfile::id, gridfile::length, MONGO_OK, gridfile::pending_data, gridfile::pending_len, gridfile::pos, and gridfile::remote_name.

Referenced by gridfs_store_buffer(), and gridfs_store_file().

MONGO_EXPORT gridfs * gridfs_alloc ( void  )

Definition at line 485 of file mongo.c.

MONGO_EXPORT void gridfs_dealloc ( gridfs gfs)

Definition at line 489 of file mongo.c.

static int gridfs_default_chunk_filter ( char **  targetBuf,
size_t *  targetLen,
const char *  srcData,
size_t  srcLen,
int  flags 
)
static

Definition at line 508 of file mongo.c.

static size_t gridfs_default_pending_data_size ( int  flags)
static

Definition at line 514 of file mongo.c.

References DEFAULT_CHUNK_SIZE.

MONGO_EXPORT void gridfs_destroy ( gridfs gfs)

Destroys a GridFS object.

Call this when finished with the object..

Parameters
gfsa grid

Definition at line 614 of file mongo.c.

References gridfs::chunks_ns, gridfs::dbname, gridfs::files_ns, and gridfs::prefix.

Referenced by gridfs_init().

MONGO_EXPORT int gridfs_find_filename ( gridfs gfs,
const char *  filename,
gridfile gfile 
)

Find the first file referenced by filename within the GridFS and return it as a GridFile.

Parameters
gfs- the working GridFS
filename- filename of the file to find
gfile- the output GridFile to be intialized
Returns
MONGO_OK or MONGO_ERROR.

Definition at line 854 of file mongo.c.

References bson_append_string_uppercase(), gridfs::caseInsensitive, gridfs_find_query(), and query.

Referenced by gridfile_writer_init().

MONGO_EXPORT int gridfs_find_query ( gridfs gfs,
const bson query,
gridfile gfile 
)

Find the first file matching the provided query within the GridFS files collection, and return the file as a GridFile.

Parameters
gfs- the working GridFS
query- a pointer to the bson with the query data
gfile- the output GridFile to be initialized
Returns
MONGO_OK if successful, MONGO_ERROR otherwise

Definition at line 826 of file mongo.c.

References gridfs::client, gridfs::files_ns, gridfile_init(), i, MONGO_ERROR, mongo_find_one(), MONGO_OK, and out.

Referenced by gridfs_find_filename().

MONGO_EXPORT bson_bool_t gridfs_get_caseInsensitive ( const gridfs gfs)

Returns the caseInsensitive flag value of gfs.

Parameters
gfile- the working GridFile
Returns
- the caseInsensitive flag of the gfs

Definition at line 636 of file mongo.c.

References gridfs::caseInsensitive.

MONGO_EXPORT int gridfs_init ( mongo client,
const char *  dbname,
const char *  prefix,
gridfs gfs 
)

Initializes a GridFS object.

Parameters
client- db connection
dbname- database name
prefix- collection prefix, default is fs if NULL or empty
gfs- the GridFS object to initialize
Returns
- MONGO_OK or MONGO_ERROR.

Definition at line 557 of file mongo.c.

References b, gridfs::caseInsensitive, gridfs::chunks_ns, gridfs::client, gridfs::dbname, gridfs::files_ns, gridfs_destroy(), mongo_create_index(), MONGO_ERROR, MONGO_INDEX_UNIQUE, MONGO_OK, and gridfs::prefix.

static int gridfs_insert_file ( gridfs gfs,
const char *  name,
const bson_oid_t  id,
gridfs_offset  length,
const char *  contenttype,
int  flags,
int  chunkSize 
)
static
MONGO_EXPORT int gridfs_remove_filename ( gridfs gfs,
const char *  filename 
)

Removes the files referenced by filename from the db.

Parameters
gfs- the working GridFS
filename- the filename of the file/s to be removed
Returns
MONGO_OK if a matching file was removed, and MONGO_ERROR if an error occurred or the file did not exist

Definition at line 783 of file mongo.c.

References b, bson_append_string_uppercase(), gridfs::caseInsensitive, gridfs::chunks_ns, gridfs::client, mongo_cursor::current, file, gridfs::files_ns, mongo_cursor_destroy(), mongo_cursor_next(), MONGO_ERROR, mongo_find(), MONGO_OK, mongo_remove(), and query.

MONGO_EXPORT void gridfs_set_caseInsensitive ( gridfs gfs,
bson_bool_t  newValue 
)

Sets the caseInsensitive flag value of gfs.

Parameters
gfs- the working gfs
newValue- the new value for the caseInsensitive flag of gfs
Returns
- void

Definition at line 640 of file mongo.c.

References gridfs::caseInsensitive.

MONGO_EXPORT void gridfs_set_chunk_filter_funcs ( gridfs_chunk_filter_func  writeFilter,
gridfs_chunk_filter_func  readFilter,
gridfs_pending_data_size_func  pendingDataNeededSize 
)

Definition at line 523 of file mongo.c.

MONGO_EXPORT int gridfs_store_buffer ( gridfs gfs,
const char *  data,
gridfs_offset  length,
const char *  remotename,
const char *  contenttype,
int  flags 
)

Store a buffer as a GridFS file.

Parameters
gfs- the working GridFS
data- pointer to buffer to store in GridFS
length- length of the buffer
remotename- filename for use in the database
contenttype- optional MIME type for this object
Returns
- MONGO_OK or MONGO_ERROR.

Definition at line 723 of file mongo.c.

References gridfile_destroy(), gridfile_init(), gridfile_write_buffer(), gridfile_writer_done(), gridfile_writer_init(), MONGO_ERROR, and MONGO_OK.

MONGO_EXPORT int gridfs_store_file ( gridfs gfs,
const char *  filename,
const char *  remotename,
const char *  contenttype,
int  flags 
)

Open the file referenced by filename and store it as a GridFS file.

Parameters
gfs- the working GridFS
filename- local filename relative to the process
remotename- optional filename for use in the database
contenttype- optional MIME type for this object
Returns
- MONGO_OK or MONGO_ERROR.

Definition at line 738 of file mongo.c.

References buffer, DEFAULT_CHUNK_SIZE, gridfile_destroy(), gridfile_init(), gridfile_write_buffer(), gridfile_writer_done(), gridfile_writer_init(), MONGO_ERROR, and MONGO_OK.

MONGO_EXPORT mongo* mongo_alloc ( void  )

Definition at line 1770 of file mongo.c.

static int mongo_bson_valid ( mongo conn,
const bson bson,
int  write 
)
static
MONGO_EXPORT int mongo_check_connection ( mongo conn)

Definition at line 2451 of file mongo.c.

References mongo::connected, MONGO_ERROR, and mongo_simple_int_command().

static int mongo_check_is_master ( mongo conn)
static
static int mongo_check_last_error ( mongo conn,
const char *  ns,
mongo_write_concern write_concern 
)
static
static int mongo_choose_write_concern ( mongo conn,
mongo_write_concern custom_write_concern,
mongo_write_concern **  write_concern 
)
static
MONGO_EXPORT void mongo_clear_errors ( mongo conn)
MONGO_EXPORT int mongo_client ( mongo conn,
const char *  host,
int  port 
)
MONGO_EXPORT int mongo_cmd_add_user ( mongo conn,
const char *  db,
const char *  user,
const char *  pass 
)

Definition at line 3456 of file mongo.c.

References MONGO_OK, mongo_pass_digest(), mongo_update(), MONGO_UPDATE_UPSERT, and ns.

MONGO_EXPORT bson_bool_t mongo_cmd_authenticate ( mongo conn,
const char *  db,
const char *  user,
const char *  pass 
)
MONGO_EXPORT int mongo_cmd_drop_collection ( mongo conn,
const char *  db,
const char *  collection,
bson out 
)

Definition at line 3372 of file mongo.c.

References mongo_simple_str_command().

MONGO_EXPORT int mongo_cmd_drop_db ( mongo conn,
const char *  db 
)

Definition at line 3368 of file mongo.c.

References mongo_simple_int_command().

static int mongo_cmd_get_error_helper ( mongo conn,
const char *  db,
bson realout,
const char *  cmdtype 
)
static
MONGO_EXPORT int mongo_cmd_get_last_error ( mongo conn,
const char *  db,
bson out 
)

Definition at line 3412 of file mongo.c.

References mongo_cmd_get_error_helper().

Referenced by mongo_create_index().

MONGO_EXPORT int mongo_cmd_get_prev_error ( mongo conn,
const char *  db,
bson out 
)

Definition at line 3408 of file mongo.c.

References mongo_cmd_get_error_helper().

MONGO_EXPORT bson_bool_t mongo_cmd_ismaster ( mongo conn,
bson realout 
)

Definition at line 3416 of file mongo.c.

References BSON_EOO, MONGO_OK, mongo_simple_int_command(), and out.

MONGO_EXPORT void mongo_cmd_reset_error ( mongo conn,
const char *  db 
)

Definition at line 3376 of file mongo.c.

References mongo_simple_int_command().

MONGO_EXPORT int mongo_connect ( mongo conn,
const char *  host,
int  port 
)

Definition at line 2187 of file mongo.c.

References bson_errprintf, mongo_client(), and mongo_set_write_concern().

MONGO_EXPORT double mongo_count ( mongo conn,
const char *  db,
const char *  coll,
const bson query 
)

Definition at line 3283 of file mongo.c.

References cmd, MONGO_ERROR, MONGO_OK, mongo_run_command(), and out.

MONGO_EXPORT int mongo_create_capped_collection ( mongo conn,
const char *  db,
const char *  collection,
int  size,
int  max,
bson out 
)

Definition at line 3262 of file mongo.c.

References b, and mongo_run_command().

MONGO_EXPORT int mongo_create_index ( mongo conn,
const char *  ns,
const bson key,
const char *  name,
int  options,
bson out 
)
MONGO_EXPORT bson_bool_t mongo_create_simple_index ( mongo conn,
const char *  ns,
const char *  field,
int  options,
bson out 
)

Definition at line 3249 of file mongo.c.

References b, and mongo_create_index().

MONGO_EXPORT mongo_cursor* mongo_cursor_alloc ( void  )

Definition at line 1849 of file mongo.c.

Referenced by mongo_find().

MONGO_EXPORT const bson* mongo_cursor_bson ( mongo_cursor cursor)

Definition at line 3094 of file mongo.c.

References mongo_cursor::current.

static int mongo_cursor_bson_valid ( mongo_cursor cursor,
const bson bson 
)
static
MONGO_EXPORT const char* mongo_cursor_data ( mongo_cursor cursor)

Definition at line 3090 of file mongo.c.

References mongo_cursor::current, and bson::data.

MONGO_EXPORT void mongo_cursor_dealloc ( mongo_cursor cursor)

Definition at line 1854 of file mongo.c.

MONGO_EXPORT int mongo_cursor_destroy ( mongo_cursor cursor)
static int mongo_cursor_get_more ( mongo_cursor cursor)
static
MONGO_EXPORT void mongo_cursor_init ( mongo_cursor cursor,
mongo conn,
const char *  ns 
)

Definition at line 3062 of file mongo.c.

References mongo_cursor::conn, conn, mongo_cursor::current, bson::data, and mongo_cursor::ns.

Referenced by mongo_find(), and mongo_find_one().

MONGO_EXPORT int mongo_cursor_next ( mongo_cursor cursor)
static int mongo_cursor_op_query ( mongo_cursor cursor)
static
MONGO_EXPORT void mongo_cursor_set_fields ( mongo_cursor cursor,
const bson fields 
)

Definition at line 3074 of file mongo.c.

References mongo_cursor::fields, and fields.

Referenced by mongo_find(), and mongo_find_one().

MONGO_EXPORT void mongo_cursor_set_limit ( mongo_cursor cursor,
int  limit 
)

Definition at line 3082 of file mongo.c.

References mongo_cursor::limit, and limit.

Referenced by mongo_find(), and mongo_find_one().

MONGO_EXPORT void mongo_cursor_set_options ( mongo_cursor cursor,
int  options 
)

Definition at line 3086 of file mongo.c.

References mongo_cursor::options, and options.

Referenced by mongo_find().

MONGO_EXPORT void mongo_cursor_set_query ( mongo_cursor cursor,
const bson query 
)

Definition at line 3070 of file mongo.c.

References mongo_cursor::query, and query.

Referenced by mongo_find(), and mongo_find_one().

MONGO_EXPORT void mongo_cursor_set_skip ( mongo_cursor cursor,
int  skip 
)

Definition at line 3078 of file mongo.c.

References mongo_cursor::skip, and skip.

Referenced by mongo_find().

static char* mongo_data_append ( char *  start,
const void *  data,
size_t  len 
)
static
static char* mongo_data_append32 ( char *  start,
const void *  data 
)
static
static char* mongo_data_append64 ( char *  start,
const void *  data 
)
static

Definition at line 2124 of file mongo.c.

References bson_little_endian64().

Referenced by mongo_cursor_destroy(), and mongo_cursor_get_more().

MONGO_EXPORT void mongo_dealloc ( mongo conn)

Definition at line 1775 of file mongo.c.

MONGO_EXPORT void mongo_destroy ( mongo conn)
MONGO_EXPORT void mongo_disconnect ( mongo conn)
int mongo_env_close_socket ( SOCKET  socket)
static int mongo_env_read_socket ( mongo conn,
void *  buf,
size_t  len 
)
static

Definition at line 1622 of file mongo.c.

References __mongo_set_error(), errno, MONGO_ERROR, MONGO_IO_ERROR, MONGO_OK, and mongo::sock.

Referenced by mongo_read_response().

static int mongo_env_set_socket_op_timeout ( mongo conn,
int  millis 
)
static
static int mongo_env_sock_init ( void  )
static

Definition at line 1595 of file mongo.c.

Referenced by mongo_init_sockets().

static int mongo_env_socket_connect ( mongo conn,
const char *  host,
int  port 
)
static
static int mongo_env_unix_socket_connect ( mongo conn,
const char *  sock_path 
)
static
static int mongo_env_write_socket ( mongo conn,
const void *  buf,
size_t  len 
)
static
MONGO_EXPORT mongo_cursor* mongo_find ( mongo conn,
const char *  ns,
const bson query,
const bson fields,
int  limit,
int  skip,
int  options 
)
MONGO_EXPORT int mongo_find_one ( mongo conn,
const char *  ns,
const bson query,
const bson fields,
bson out 
)
MONGO_EXPORT int mongo_get_err ( mongo conn)

Definition at line 1779 of file mongo.c.

References mongo::err.

MONGO_EXPORT const char* mongo_get_host ( mongo conn,
int  i 
)
MONGO_EXPORT int mongo_get_host_count ( mongo conn)

Definition at line 1815 of file mongo.c.

References mongo_replica_set::hosts, mongo_host_port::next, and mongo::replica_set.

MONGO_EXPORT int mongo_get_op_timeout ( mongo conn)

Definition at line 1789 of file mongo.c.

References mongo::op_timeout_ms.

MONGO_EXPORT const char* mongo_get_primary ( mongo conn)

Definition at line 1801 of file mongo.c.

References _get_host_port(), mongo::connected, mongo_host_port::host, and mongo::primary.

MONGO_EXPORT int mongo_get_server_err ( mongo conn)

Definition at line 1859 of file mongo.c.

References mongo::lasterrcode.

MONGO_EXPORT const char* mongo_get_server_err_string ( mongo conn)

Definition at line 1864 of file mongo.c.

References mongo::lasterrstr.

MONGO_EXPORT SOCKET mongo_get_socket ( mongo conn)

Definition at line 1809 of file mongo.c.

References mongo::sock.

MONGO_EXPORT void mongo_init ( mongo conn)
MONGO_EXPORT void mongo_init_sockets ( void  )

Definition at line 2156 of file mongo.c.

References mongo_env_sock_init().

MONGO_EXPORT int mongo_insert ( mongo conn,
const char *  ns,
const bson bson,
mongo_write_concern custom_write_concern 
)
MONGO_EXPORT int mongo_insert_batch ( mongo conn,
const char *  ns,
const bson **  bsons,
int  count,
mongo_write_concern custom_write_concern,
int  flags 
)
MONGO_EXPORT int mongo_is_connected ( mongo conn)

Definition at line 1784 of file mongo.c.

References mongo::connected.

static mongo_message* mongo_message_create ( size_t  len,
int  id,
int  responseTo,
int  op 
)
static
static int mongo_message_send ( mongo conn,
mongo_message mm 
)
static
static int mongo_message_send_and_check_write_concern ( mongo conn,
const char *  ns,
mongo_message mm,
mongo_write_concern write_concern 
)
static
static char* mongo_ns_to_cmd_db ( const char *  ns)
static

Definition at line 1890 of file mongo.c.

References current, and len.

Referenced by mongo_check_last_error().

void mongo_parse_host ( const char *  host_string,
mongo_host_port host_port 
)

Utility function for converting a host-port string to a mongo_host_port.

Parameters
host_stringa string containing either a host or a host and port separated by a colon.
host_portthe mongo_host_port object to write the result to.

Definition at line 2253 of file mongo.c.

References mongo_host_port::host, len, MONGO_DEFAULT_PORT, and mongo_host_port::port.

Referenced by mongo_replica_set_check_seed().

static int mongo_pass_digest ( mongo conn,
const char *  user,
const char *  pass,
char  hex_digest[33] 
)
static
static int mongo_read_response ( mongo conn,
mongo_reply **  reply 
)
static
MONGO_EXPORT int mongo_reconnect ( mongo conn)
MONGO_EXPORT int mongo_remove ( mongo conn,
const char *  ns,
const bson cond,
mongo_write_concern custom_write_concern 
)
static void mongo_replica_set_add_node ( mongo_host_port **  list,
const char *  host,
int  port 
)
static
MONGO_EXPORT void mongo_replica_set_add_seed ( mongo conn,
const char *  host,
int  port 
)
static int mongo_replica_set_check_host ( mongo conn)
static
static void mongo_replica_set_check_seed ( mongo conn)
static
MONGO_EXPORT int mongo_replica_set_client ( mongo conn)
static void mongo_replica_set_free_list ( mongo_host_port **  list)
static

Definition at line 2231 of file mongo.c.

References mongo_host_port::next.

Referenced by mongo_destroy(), mongo_disconnect(), and mongo_reconnect().

MONGO_EXPORT void mongo_replica_set_init ( mongo conn,
const char *  name 
)
MONGO_EXPORT void mongo_replset_add_seed ( mongo conn,
const char *  host,
int  port 
)
MONGO_EXPORT int mongo_replset_connect ( mongo conn)

Definition at line 2420 of file mongo.c.

References bson_errprintf, mongo_replica_set_client(), and mongo_set_write_concern().

MONGO_EXPORT void mongo_replset_init ( mongo conn,
const char *  name 
)

Definition at line 2210 of file mongo.c.

References bson_errprintf, and mongo_replica_set_init().

MONGO_EXPORT int mongo_run_command ( mongo conn,
const char *  db,
const bson command,
bson out 
)
static void mongo_set_last_error ( mongo conn,
bson_iterator it,
bson obj 
)
static
MONGO_EXPORT int mongo_set_op_timeout ( mongo conn,
int  millis 
)
MONGO_EXPORT void mongo_set_write_concern ( mongo conn,
mongo_write_concern write_concern 
)

Definition at line 2844 of file mongo.c.

References mongo::write_concern, and write_concern.

Referenced by mongo_connect(), mongo_init(), and mongo_replset_connect().

MONGO_EXPORT int mongo_simple_int_command ( mongo conn,
const char *  db,
const char *  cmdstr,
int  arg,
bson out 
)
MONGO_EXPORT int mongo_simple_str_command ( mongo conn,
const char *  db,
const char *  cmdstr,
const char *  arg,
bson out 
)

Definition at line 3352 of file mongo.c.

References cmd, and mongo_run_command().

Referenced by mongo_cmd_drop_collection().

MONGO_EXPORT int mongo_update ( mongo conn,
const char *  ns,
const bson cond,
const bson op,
int  flags,
mongo_write_concern custom_write_concern 
)
MONGO_EXPORT int mongo_validate_ns ( mongo conn,
const char *  ns 
)

Definition at line 1906 of file mongo.c.

References __mongo_set_error(), bson_sprintf, current, MONGO_ERROR, MONGO_NS_INVALID, MONGO_OK, and ns.

Referenced by mongo_insert(), and mongo_insert_batch().

MONGO_EXPORT mongo_write_concern* mongo_write_concern_alloc ( void  )

Definition at line 1839 of file mongo.c.

MONGO_EXPORT void mongo_write_concern_dealloc ( mongo_write_concern write_concern)

Definition at line 1844 of file mongo.c.

MONGO_EXPORT void mongo_write_concern_destroy ( mongo_write_concern write_concern)

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

Definition at line 2833 of file mongo.c.

References mongo_write_concern::cmd.

MONGO_EXPORT int mongo_write_concern_finish ( mongo_write_concern write_concern)
MONGO_EXPORT bson* mongo_write_concern_get_cmd ( mongo_write_concern write_concern)

Definition at line 2870 of file mongo.c.

References mongo_write_concern::cmd.

MONGO_EXPORT int mongo_write_concern_get_fsync ( mongo_write_concern write_concern)

Definition at line 2862 of file mongo.c.

References mongo_write_concern::fsync.

MONGO_EXPORT int mongo_write_concern_get_j ( mongo_write_concern write_concern)

Definition at line 2858 of file mongo.c.

References mongo_write_concern::j.

MONGO_EXPORT const char* mongo_write_concern_get_mode ( mongo_write_concern write_concern)

Definition at line 2866 of file mongo.c.

References mongo_write_concern::mode.

MONGO_EXPORT int mongo_write_concern_get_w ( mongo_write_concern write_concern)

Definition at line 2850 of file mongo.c.

References mongo_write_concern::w.

MONGO_EXPORT int mongo_write_concern_get_wtimeout ( mongo_write_concern write_concern)

Definition at line 2854 of file mongo.c.

References mongo_write_concern::wtimeout.

MONGO_EXPORT void mongo_write_concern_init ( mongo_write_concern write_concern)

Definition at line 2778 of file mongo.c.

MONGO_EXPORT void mongo_write_concern_set_fsync ( mongo_write_concern write_concern,
int  fsync 
)

Definition at line 2887 of file mongo.c.

References mongo_write_concern::fsync, and fsync.

MONGO_EXPORT void mongo_write_concern_set_j ( mongo_write_concern write_concern,
int  j 
)

Definition at line 2883 of file mongo.c.

References mongo_write_concern::j, and j.

MONGO_EXPORT void mongo_write_concern_set_mode ( mongo_write_concern write_concern,
const char *  mode 
)

Definition at line 2892 of file mongo.c.

References mongo_write_concern::mode, and mode.

MONGO_EXPORT void mongo_write_concern_set_w ( mongo_write_concern write_concern,
int  w 
)

Definition at line 2874 of file mongo.c.

References mongo_write_concern::w, and w.

MONGO_EXPORT void mongo_write_concern_set_wtimeout ( mongo_write_concern write_concern,
int  wtimeout 
)

Definition at line 2878 of file mongo.c.

References mongo_write_concern::wtimeout, and wtimeout.

static void rpmmgoFini ( void *  _mgo)
static

Definition at line 3548 of file mongo.c.

References _free().

Referenced by rpmmgoGetPool().

static rpmmgo rpmmgoGetPool ( rpmioPool  pool)
static

Definition at line 3560 of file mongo.c.

References _rpmmgo_debug, _rpmmgoPool, rpmioGetPool(), rpmioNewPool(), and rpmmgoFini().

Referenced by rpmmgoNew().

rpmmgo rpmmgoNew ( const char *  fn,
int  flags 
)

Create and load a mongo wrapper.

Parameters
fnmongo file
flagsmongo flags
Returns
new mongo wrapper

Definition at line 3576 of file mongo.c.

References rpmmgoGetPool(), rpmmgoLink(), and xstrdup().

Variable Documentation

int _rpmmgo_debug = 0

Definition at line 42 of file mongo.c.

Referenced by rpmmgoGetPool().

rpmmgo _rpmmgoI

Definition at line 45 of file mongo.c.

Referenced by rpmioClean().

rpmioPool _rpmmgoPool = NULL

Definition at line 3558 of file mongo.c.

Referenced by rpmioClean(), and rpmmgoGetPool().

Definition at line 521 of file mongo.c.

Referenced by gridfile_writer_init().

Definition at line 519 of file mongo.c.

Referenced by chunk_new().

const int one = 1
static

Definition at line 49 of file mongo.c.

Referenced by orderListIndexCmp(), rpmHeadersIdentical(), and rpmVersionCompare().

const int ONE = 1
static

Definition at line 2021 of file mongo.c.

mongo_write_concern WC1 = { 1, 0, 0, 0, 0, &WC1_cmd }
static

Definition at line 2165 of file mongo.c.

bson WC1_cmd
static
Initial value:
= {
WC1_data, WC1_data, 128, 1, 0
}
static char WC1_data[]
Definition: mongo.c:2161

Definition at line 2162 of file mongo.c.

char WC1_data[] = {23,0,0,0,16,103,101,116,108,97,115,116,101,114,114,111,114,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0}
static

Definition at line 2161 of file mongo.c.

const int zero = 0
static

Definition at line 48 of file mongo.c.

const int ZERO = 0
static

Definition at line 2020 of file mongo.c.

Referenced by rpmgitCmdStatus().