提交 10093b44 authored 作者: Daniel Swarbrick's avatar Daniel Swarbrick

mod_cdr_mongodb: update MongoDB driver to v0.6

上级 6533c9b9
# MongoDB C Driver History # MongoDB C Driver History
## 0.6
2012-6-3
** API CHANGE **
Version 0.6 supports write concern. This involves a backward-breaking
API change, as the write functions now take an optional write_concern
object.
The driver now also supports the MONGO_CONTINUE_ON_ERROR flag for
batch inserts.
The new function prototypes are as follows:
* int mongo_insert( mongo *conn, const char *ns, const bson *data,
mongo_write_concern *custom_write_concern );
* int mongo_insert_batch( mongo *conn, const char *ns,
const bson **data, int num, mongo_write_concern *custom_write_concern );
* int mongo_update( mongo *conn, const char *ns, const bson *cond,
const bson *op, int flags, mongo_write_concern *custom_write_concern,
int flags );
* int mongo_remove( mongo *conn, const char *ns, const bson *cond,
mongo_write_concern *custom_write_concern );
* Allow DBRefs (i.e., allows keys $ref, $id, and $db)
* Added mongo_create_capped_collection().
* Fixed some bugs in the SCons and Makefile build scripts.
* Fixes for SCons and Makefile shared library install targets.
* Other minor bug fixes.
## 0.5.2 ## 0.5.2
2012-5-4 2012-5-4
......
...@@ -9,17 +9,31 @@ by providing an interface for platform-specific modules. ...@@ -9,17 +9,31 @@ by providing an interface for platform-specific modules.
Until the 1.0 release, this driver should be considered alpha. Keep in mind that the API will be in flux until then. Until the 1.0 release, this driver should be considered alpha. Keep in mind that the API will be in flux until then.
# Documentation
Documentation exists in the project's `docs` folder. You can read the latest
docs online at (http://api.mongodb.org/c/current/).
The docs are built using Sphinx and Doxygen. If you have these tools installed, then
you can build the docs with scons:
scons docs
The html docs will appear in docs/html.
# Building # Building
First check out the version you want to build. *Always build from a particular tag, since HEAD may be First check out the version you want to build. *Always build from a particular tag, since HEAD may be
a work in progress.* For example, to build version 0.5.2, run: a work in progress.* For example, to build version 0.6, run:
git checkout v0.5.2 git checkout v0.6
You can then build the driver with scons: You can then build the driver with scons:
scons scons
For more build options, see the docs.
## Running the tests ## Running the tests
Make sure that you're running mongod on 127.0.0.1 on the default port (27017). The replica set Make sure that you're running mongod on 127.0.0.1 on the default port (27017). The replica set
test assumes a replica set with at least three nodes running at 127.0.0.1 and starting at port test assumes a replica set with at least three nodes running at 127.0.0.1 and starting at port
...@@ -35,14 +49,6 @@ Specific error codes and error strings are then stored in the `err` and `errstr` ...@@ -35,14 +49,6 @@ Specific error codes and error strings are then stored in the `err` and `errstr`
`mongo` and `bson` objects. It is the client's responsibility to check for errors and handle `mongo` and `bson` objects. It is the client's responsibility to check for errors and handle
them appropriately. them appropriately.
# Docs
The docs are built using Sphinx and Doxygen. If you have these tools installed, then
you can build the docs with scons:
scons docs
The html docs will appear in docs/html.
# ISSUES # ISSUES
You can report bugs, request new features, and view this driver's roadmap You can report bugs, request new features, and view this driver's roadmap
......
...@@ -32,7 +32,7 @@ static const int zero = 0; ...@@ -32,7 +32,7 @@ static const int zero = 0;
/* Custom standard function pointers. */ /* Custom standard function pointers. */
void *( *bson_malloc_func )( size_t ) = malloc; void *( *bson_malloc_func )( size_t ) = malloc;
void *( *bson_realloc_func )( void *, size_t ) = realloc; void *( *bson_realloc_func )( void *, size_t ) = realloc;
void ( *bson_free )( void * ) = free; void ( *bson_free_func )( void * ) = free;
#ifdef R_SAFETY_NET #ifdef R_SAFETY_NET
bson_printf_func bson_printf; bson_printf_func bson_printf;
#else #else
...@@ -308,7 +308,7 @@ MONGO_EXPORT void bson_print_raw( const char *data , int depth ) { ...@@ -308,7 +308,7 @@ MONGO_EXPORT void bson_print_raw( const char *data , int depth ) {
------------------------------ */ ------------------------------ */
MONGO_EXPORT bson_iterator* bson_iterator_create() { MONGO_EXPORT bson_iterator* bson_iterator_create() {
return (bson_iterator*)malloc(sizeof(bson_iterator*)); return ( bson_iterator* )malloc( sizeof( bson_iterator ) );
} }
MONGO_EXPORT void bson_iterator_dispose(bson_iterator* i) { MONGO_EXPORT void bson_iterator_dispose(bson_iterator* i) {
...@@ -973,6 +973,10 @@ MONGO_EXPORT bson_err_handler set_bson_err_handler( bson_err_handler func ) { ...@@ -973,6 +973,10 @@ MONGO_EXPORT bson_err_handler set_bson_err_handler( bson_err_handler func ) {
return old; return old;
} }
MONGO_EXPORT void bson_free( void *ptr ) {
bson_free_func( ptr );
}
MONGO_EXPORT void *bson_malloc( int size ) { MONGO_EXPORT void *bson_malloc( int size ) {
void *p; void *p;
p = bson_malloc_func( size ); p = bson_malloc_func( size );
......
...@@ -959,13 +959,15 @@ typedef int (*bson_sprintf_func)( char *, const char *, ... ); ...@@ -959,13 +959,15 @@ typedef int (*bson_sprintf_func)( char *, const char *, ... );
extern void *( *bson_malloc_func )( size_t ); extern void *( *bson_malloc_func )( size_t );
extern void *( *bson_realloc_func )( void *, size_t ); extern void *( *bson_realloc_func )( void *, size_t );
extern void ( *bson_free )( void * ); extern void ( *bson_free_func )( void * );
extern bson_printf_func bson_printf; extern bson_printf_func bson_printf;
extern bson_fprintf_func bson_fprintf; extern bson_fprintf_func bson_fprintf;
extern bson_sprintf_func bson_sprintf; extern bson_sprintf_func bson_sprintf;
extern bson_printf_func bson_errprintf; extern bson_printf_func bson_errprintf;
MONGO_EXPORT void bson_free( void *ptr );
/** /**
* Allocates memory and checks return value, exiting fatally if malloc() fails. * Allocates memory and checks return value, exiting fatally if malloc() fails.
* *
......
...@@ -101,6 +101,24 @@ static int isLegalUTF8( const unsigned char *source, int length ) { ...@@ -101,6 +101,24 @@ static int isLegalUTF8( const unsigned char *source, int length ) {
return 1; return 1;
} }
/* If the name is part of a db ref ($ref, $db, or $id), then return true. */
static int bson_string_is_db_ref( const unsigned char *string, const int length ) {
int result = 0;
if( length >= 4 ) {
if( string[1] == 'r' && string[2] == 'e' && string[3] == 'f' )
result = 1;
}
else if( length >= 3 ) {
if( string[1] == 'i' && string[2] == 'd' )
result = 1;
else if( string[1] == 'd' && string[2] == 'b' )
result = 1;
}
return result;
}
static int bson_validate_string( bson *b, const unsigned char *string, static int bson_validate_string( bson *b, const unsigned char *string,
const int length, const char check_utf8, const char check_dot, const int length, const char check_utf8, const char check_dot,
const char check_dollar ) { const char check_dollar ) {
...@@ -109,7 +127,8 @@ static int bson_validate_string( bson *b, const unsigned char *string, ...@@ -109,7 +127,8 @@ static int bson_validate_string( bson *b, const unsigned char *string,
int sequence_length = 1; int sequence_length = 1;
if( check_dollar && string[0] == '$' ) { if( check_dollar && string[0] == '$' ) {
b->err |= BSON_FIELD_INIT_DOLLAR; if( !bson_string_is_db_ref( string, length ) )
b->err |= BSON_FIELD_INIT_DOLLAR;
} }
while ( position < length ) { while ( position < length ) {
......
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
#include <ws2tcpip.h> // send,recv,socklen_t etc #include <ws2tcpip.h> // send,recv,socklen_t etc
#include <wspiapi.h> // addrinfo #include <wspiapi.h> // addrinfo
#else #else
#include <windows.h> #include <ws2tcpip.h> // send,recv,socklen_t etc
#include <winsock.h> #include <winsock2.h>
typedef int socklen_t; typedef int socklen_t;
#endif #endif
...@@ -33,11 +33,6 @@ typedef int socklen_t; ...@@ -33,11 +33,6 @@ typedef int socklen_t;
# define NI_MAXSERV 32 # define NI_MAXSERV 32
#endif #endif
static void mongo_clear_errors( mongo *conn ) {
conn->err = 0;
memset( conn->errstr, 0, MONGO_ERR_LEN );
}
int mongo_env_close_socket( int socket ) { int mongo_env_close_socket( int socket ) {
return closesocket( socket ); return closesocket( socket );
} }
......
...@@ -170,7 +170,7 @@ static int gridfs_insert_file( gridfs *gfs, const char *name, ...@@ -170,7 +170,7 @@ static int gridfs_insert_file( gridfs *gfs, const char *name,
bson_append_string( &ret, "contentType", contenttype ); bson_append_string( &ret, "contentType", contenttype );
} }
bson_finish( &ret ); bson_finish( &ret );
result = mongo_insert( gfs->client, gfs->files_ns, &ret ); result = mongo_insert( gfs->client, gfs->files_ns, &ret, NULL );
bson_destroy( &ret ); bson_destroy( &ret );
return result; return result;
...@@ -198,7 +198,7 @@ MONGO_EXPORT int gridfs_store_buffer( gridfs *gfs, const char *data, ...@@ -198,7 +198,7 @@ MONGO_EXPORT int gridfs_store_buffer( gridfs *gfs, const char *data,
chunkLen = DEFAULT_CHUNK_SIZE < ( unsigned int )( end - data_ptr ) ? chunkLen = DEFAULT_CHUNK_SIZE < ( unsigned int )( end - data_ptr ) ?
DEFAULT_CHUNK_SIZE : ( unsigned int )( end - data_ptr ); DEFAULT_CHUNK_SIZE : ( unsigned int )( end - data_ptr );
oChunk = chunk_new( id, chunkNumber, data_ptr, chunkLen ); oChunk = chunk_new( id, chunkNumber, data_ptr, chunkLen );
mongo_insert( gfs->client, gfs->chunks_ns, oChunk ); mongo_insert( gfs->client, gfs->chunks_ns, oChunk, NULL );
chunk_free( oChunk ); chunk_free( oChunk );
chunkNumber++; chunkNumber++;
data_ptr += chunkLen; data_ptr += chunkLen;
...@@ -259,7 +259,7 @@ MONGO_EXPORT void gridfile_write_buffer( gridfile *gfile, const char *data, ...@@ -259,7 +259,7 @@ MONGO_EXPORT void gridfile_write_buffer( gridfile *gfile, const char *data,
memcpy( buffer + gfile->pending_len, data, data_partial_len ); memcpy( buffer + gfile->pending_len, data, data_partial_len );
oChunk = chunk_new( gfile->id, gfile->chunk_num, buffer, DEFAULT_CHUNK_SIZE ); oChunk = chunk_new( gfile->id, gfile->chunk_num, buffer, DEFAULT_CHUNK_SIZE );
mongo_insert( gfile->gfs->client, gfile->gfs->chunks_ns, oChunk ); mongo_insert( gfile->gfs->client, gfile->gfs->chunks_ns, oChunk, NULL );
chunk_free( oChunk ); chunk_free( oChunk );
gfile->chunk_num++; gfile->chunk_num++;
gfile->length += DEFAULT_CHUNK_SIZE; gfile->length += DEFAULT_CHUNK_SIZE;
...@@ -272,7 +272,7 @@ MONGO_EXPORT void gridfile_write_buffer( gridfile *gfile, const char *data, ...@@ -272,7 +272,7 @@ MONGO_EXPORT void gridfile_write_buffer( gridfile *gfile, const char *data,
while( chunks_to_write > 0 ) { while( chunks_to_write > 0 ) {
oChunk = chunk_new( gfile->id, gfile->chunk_num, data, DEFAULT_CHUNK_SIZE ); oChunk = chunk_new( gfile->id, gfile->chunk_num, data, DEFAULT_CHUNK_SIZE );
mongo_insert( gfile->gfs->client, gfile->gfs->chunks_ns, oChunk ); mongo_insert( gfile->gfs->client, gfile->gfs->chunks_ns, oChunk, NULL );
chunk_free( oChunk ); chunk_free( oChunk );
gfile->chunk_num++; gfile->chunk_num++;
chunks_to_write--; chunks_to_write--;
...@@ -302,7 +302,7 @@ MONGO_EXPORT int gridfile_writer_done( gridfile *gfile ) { ...@@ -302,7 +302,7 @@ MONGO_EXPORT int gridfile_writer_done( gridfile *gfile ) {
int response; int response;
if( gfile->pending_data ) { if( gfile->pending_data ) {
oChunk = chunk_new( gfile->id, gfile->chunk_num, gfile->pending_data, gfile->pending_len ); oChunk = chunk_new( gfile->id, gfile->chunk_num, gfile->pending_data, gfile->pending_len );
mongo_insert( gfile->gfs->client, gfile->gfs->chunks_ns, oChunk ); mongo_insert( gfile->gfs->client, gfile->gfs->chunks_ns, oChunk, NULL );
chunk_free( oChunk ); chunk_free( oChunk );
bson_free( gfile->pending_data ); bson_free( gfile->pending_data );
gfile->length += gfile->pending_len; gfile->length += gfile->pending_len;
...@@ -344,7 +344,7 @@ int gridfs_store_file( gridfs *gfs, const char *filename, ...@@ -344,7 +344,7 @@ int gridfs_store_file( gridfs *gfs, const char *filename,
chunkLen = fread( buffer, 1, DEFAULT_CHUNK_SIZE, fd ); chunkLen = fread( buffer, 1, DEFAULT_CHUNK_SIZE, fd );
do { do {
oChunk = chunk_new( id, chunkNumber, buffer, chunkLen ); oChunk = chunk_new( id, chunkNumber, buffer, chunkLen );
mongo_insert( gfs->client, gfs->chunks_ns, oChunk ); mongo_insert( gfs->client, gfs->chunks_ns, oChunk, NULL );
chunk_free( oChunk ); chunk_free( oChunk );
length += chunkLen; length += chunkLen;
chunkNumber++; chunkNumber++;
...@@ -390,14 +390,14 @@ MONGO_EXPORT void gridfs_remove_filename( gridfs *gfs, const char *filename ) { ...@@ -390,14 +390,14 @@ MONGO_EXPORT void gridfs_remove_filename( gridfs *gfs, const char *filename ) {
bson_init( &b ); bson_init( &b );
bson_append_oid( &b, "_id", &id ); bson_append_oid( &b, "_id", &id );
bson_finish( &b ); bson_finish( &b );
mongo_remove( gfs->client, gfs->files_ns, &b ); mongo_remove( gfs->client, gfs->files_ns, &b, NULL );
bson_destroy( &b ); bson_destroy( &b );
/* Remove all chunks from the file with the specified id */ /* Remove all chunks from the file with the specified id */
bson_init( &b ); bson_init( &b );
bson_append_oid( &b, "files_id", &id ); bson_append_oid( &b, "files_id", &id );
bson_finish( &b ); bson_finish( &b );
mongo_remove( gfs->client, gfs->chunks_ns, &b ); mongo_remove( gfs->client, gfs->chunks_ns, &b, NULL );
bson_destroy( &b ); bson_destroy( &b );
} }
......
...@@ -295,7 +295,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) ...@@ -295,7 +295,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
switch_mutex_lock(globals.mongo_mutex); switch_mutex_lock(globals.mongo_mutex);
if (mongo_insert(globals.mongo_conn, globals.mongo_namespace, &cdr) != MONGO_OK) { if (mongo_insert(globals.mongo_conn, globals.mongo_namespace, &cdr, NULL) != MONGO_OK) {
if (globals.mongo_conn->err == MONGO_IO_ERROR) { if (globals.mongo_conn->err == MONGO_IO_ERROR) {
mongo_error_t db_status; mongo_error_t db_status;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "MongoDB connection failed; attempting reconnect...\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "MongoDB connection failed; attempting reconnect...\n");
...@@ -306,7 +306,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session) ...@@ -306,7 +306,7 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "MongoDB connection re-established.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "MongoDB connection re-established.\n");
if (mongo_insert(globals.mongo_conn, globals.mongo_namespace, &cdr) != MONGO_OK) { if (mongo_insert(globals.mongo_conn, globals.mongo_namespace, &cdr, NULL) != MONGO_OK) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mongo_insert: error code %d\n", globals.mongo_conn->err); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mongo_insert: error code %d\n", globals.mongo_conn->err);
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论