22 #include <arpa/inet.h>
23 #include <sys/types.h>
24 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <netinet/tcp.h>
36 #define _RPMMGO_INTERNAL
49 static const int one = 1;
92 static char *_strlwr(
char *
str);
152 const char *content_type,
int flags );
186 const char *remotename,
187 const char *contenttype,
int flags );
199 const char *remotename,
const char *contenttype,
int flags );
466 *s = toupper((
unsigned char)*s);
472 static char *_strlwr(
char *
str)
476 *s = tolower((
unsigned char)*s);
495 memset( gfile, 0,
sizeof (
gridfile ) );
509 *targetBuf = (
char *) srcData;
524 gridfs_write_filter = writeFilter;
525 gridfs_read_filter = readFilter;
526 gridfs_pending_data_size = pendingDataNeededSize;
530 bson *
b = bson_alloc();
531 size_t dataBufLen = 0;
537 bson_append_oid(b,
"files_id", &
id);
538 bson_append_int(b,
"n", chunkNumber);
539 bson_append_binary(b,
"data",
BSON_BIN_BINARY, *dataBuf, (
int)dataBufLen);
546 bson_destroy(oChunk);
547 bson_dealloc(oChunk);
565 gfs->
dbname = (
const char*)bson_malloc((
int)strlen(dbname) + 1);
566 strcpy((
char*)gfs->
dbname, dbname);
569 if (prefix == NULL) {
572 gfs->
prefix = (
const char*)bson_malloc((
int)strlen(prefix) + 1);
573 strcpy((
char*)gfs->
prefix, prefix);
576 gfs->
files_ns = (
const char*)bson_malloc((
int)(strlen(prefix) + strlen(dbname) + strlen(
".files") + 2));
577 strcpy((
char*)gfs->
files_ns, dbname);
579 strcat((
char*)gfs->
files_ns, prefix);
580 strcat((
char*)gfs->
files_ns,
".files");
583 gfs->
chunks_ns = (
const char*)bson_malloc((
int)(strlen(prefix) + strlen(dbname) + strlen(
".chunks") + 2));
587 strcat((
char*)gfs->
chunks_ns,
".chunks");
590 bson_append_int(&b,
"filename", 1);
600 bson_append_int(&b,
"files_id", 1);
601 bson_append_int(&b,
"n", 1);
615 if( gfs == NULL )
return;
617 bson_free((
char*)gfs->
dbname);
621 bson_free((
char*)gfs->
prefix);
648 strUpperCase = (
char *) bson_malloc( (
int) strlen( str ) + 1 );
649 strcpy(strUpperCase, str);
651 res = bson_append_string( b, name, strUpperCase );
652 bson_free( strUpperCase );
655 return bson_append_string( b, name, str );
672 bson_append_oid(command,
"filemd5", &
id);
673 bson_append_string(command,
"root", gfs->
prefix);
674 bson_finish(command);
676 bson_destroy(command);
683 bson_append_oid(ret,
"_id", &
id);
684 if (name != NULL && *name !=
'\0') {
687 bson_append_long(ret,
"length", length);
688 bson_append_int(ret,
"chunkSize", chunkSize);
690 bson_append_date(ret,
"uploadDate", d);
691 if( !( flags & GRIDFILE_NOMD5 ) ) {
692 if (bson_find(it, res,
"md5") !=
BSON_EOO )
693 bson_append_string(ret,
"md5", bson_iterator_string(it));
695 bson_append_string(ret,
"md5",
"");
698 bson_append_string(ret,
"md5",
"");
700 if (contenttype != NULL && *contenttype !=
'\0') {
701 bson_append_string(ret,
"contentType", contenttype);
704 if (name != NULL && *name !=
'\0') {
705 bson_append_string(ret,
"realFilename", name);
708 bson_append_int(ret,
"flags", flags);
712 bson_append_oid(q,
"_id", &
id);
746 if (strcmp(filename,
"-") == 0) {
749 fd = fopen(filename,
"rb");
756 if (remotename == NULL || *remotename ==
'\0') {
757 remotename = filename;
767 while( chunkLen != 0 ) {
769 if( bytes_written != chunkLen )
break;
804 bson_find(it, file,
"_id");
805 id = *bson_iterator_oid(it);
809 bson_append_oid(b,
"_id", &
id);
816 bson_append_oid(b,
"files_id", &
id);
833 bson_init(uploadDate);
834 bson_append_int(uploadDate,
"uploadDate", - 1);
835 bson_finish(uploadDate);
837 bson_init(finalQuery);
838 bson_append_bson(finalQuery,
"query", query);
839 bson_append_bson(finalQuery,
"orderby", uploadDate);
840 bson_finish(finalQuery);
843 bson_destroy(uploadDate);
844 bson_destroy(finalQuery);
883 gfile->
meta = bson_alloc();
884 if (gfile->
meta == NULL) {
887 bson_copy(gfile->
meta, meta);
889 bson_init_empty(gfile->
meta);
928 if (bson_find(it, gfile->
meta,
"chunkSize") !=
BSON_EOO)
929 if (bson_iterator_type(it) ==
BSON_INT)
930 gfile->
chunkSize = bson_iterator_int(it);
932 gfile->
chunkSize = (int)bson_iterator_long(it);
941 if (bson_iterator_type(it) ==
BSON_INT)
953 gfile->
flags = bson_iterator_int(it);
980 bson_oid_gen(&(gfile->
id));
991 gfile->
remote_name = (
char*)bson_malloc((
int)strlen(remote_name) + 1);
994 gfile->
content_type = (
char*)bson_malloc((
int)strlen(content_type) + 1);
1007 bson_destroy(gfile->
meta);
1008 bson_dealloc(gfile->
meta);
1019 if (bson_iterator_type(it) ==
BSON_OID)
1020 return *bson_iterator_oid(it);
1036 return bson_iterator_string(it);
1037 if (bson_find(it, gfile->
meta,
"filename") !=
BSON_EOO)
1038 return bson_iterator_string(it);
1048 else if (bson_find(it, gfile->
meta,
"chunkSize") !=
BSON_EOO)
1049 return bson_iterator_int(it);
1057 return MAX( estimatedLen, gfile->
length );
1063 if ( bson_find(it, gfile->
meta,
"contentType") !=
BSON_EOO )
1064 return bson_iterator_string(it);
1072 if (bson_find(it, gfile->
meta,
"uploadDate") !=
BSON_EOO)
1073 return bson_iterator_date(it);
1082 return bson_iterator_string(it);
1092 return gfile->
flags;
1099 return bson_iterator_value(it);
1108 return bson_iterator_bool(it);
1116 if (bson_find(it, gfile->
meta,
"metadata") !=
BSON_EOO)
1117 bson_iterator_subobject_init(it, out, copyData);
1119 bson_init_empty(out);
1133 if (bson_iterator_type(it) ==
BSON_INT)
1140 if (bson_find(it, gfile->
meta,
"chunkSize") !=
BSON_EOO)
1141 if (bson_iterator_type(it) ==
BSON_INT)
1142 chunkSize = bson_iterator_int(it);
1144 chunkSize = (int)bson_iterator_long(it);
1148 numchunks = ((double)length / (
double)chunkSize);
1149 return (numchunks - (
int)numchunks > 0) ? (
int)(numchunks + 1): (
int)(numchunks);
1154 bson_append_int(q,
"n", chunk_num);
1155 bson_append_oid(q,
"files_id",
id);
1162 char* targetBuf = NULL;
1166 size_t finish_position_after_flush;
1174 if (finish_position_after_flush > gfile->
length)
1175 gfile->
length = finish_position_after_flush;
1181 bson_free( targetBuf );
1187 const char *chunk_data;
1190 char* targetBuffer = NULL;
1191 size_t targetBufferLen = 0;
1197 bson_destroy( &chk );
1201 if( bson_find(it, &chk,
"data") !=
BSON_EOO){
1202 chunk_len = bson_iterator_bin_len(it);
1203 chunk_data = bson_iterator_bin_data(it);
1207 if( targetBufferLen ) {
1208 memcpy(gfile->
pending_data, targetBuffer, targetBufferLen);
1211 bson_destroy( &chk );
1214 bson_destroy( &chk );
1215 if( targetBuffer && targetBuffer != chunk_data )
1216 bson_free( targetBuffer );
1224 size_t buf_pos, buf_bytes_to_write;
1226 char* targetBuf = NULL;
1227 int memAllocated = 0;
1237 memcpy( &gfile->
pending_data[buf_pos], data, buf_bytes_to_write);
1238 if ( buf_bytes_to_write + buf_pos > gfile->
pending_len ) {
1239 gfile->
pending_len = buf_bytes_to_write + buf_pos;
1241 gfile->
pos += buf_bytes_to_write;
1243 bytes_left -= buf_bytes_to_write;
1244 data += buf_bytes_to_write;
1252 memAllocated = targetBuf !=
data;
1257 if( res !=
MONGO_OK )
return length - bytes_left;
1269 if ( bytes_left > 0 ) {
1274 return length - bytes_left;
1275 memcpy( gfile->
pending_data, data, (
size_t) bytes_left );
1278 gfile->
pos += bytes_left;
1282 bson_free( targetBuf );
1295 bson_append_oid(query,
"files_id", &
id);
1296 bson_append_int(query,
"n", n);
1300 bson_destroy(query);
1302 bson_copy(out, bson_shared_empty());
1315 id = *bson_iterator_oid(it);
1320 bson_append_oid(query,
"files_id", &
id);
1322 bson_append_int(query,
"n", (
int)start);
1325 bson_append_int(gte,
"$gte", (
int)start);
1327 bson_append_bson(query,
"n", gte);
1333 bson_append_int(orderby,
"n", 1);
1334 bson_finish(orderby);
1337 bson_append_bson(command,
"query", query);
1338 bson_append_bson(command,
"orderby", orderby);
1339 bson_finish(command);
1343 bson_destroy(command);
1344 bson_destroy(query);
1345 bson_destroy(orderby);
1366 size = MIN( contentlength - gfile->
pos, size );
1369 first_chunk = (int)((gfile->
pos) / chunksize);
1370 total_chunks = (int)((gfile->
pos + size - 1) / chunksize) - first_chunk + 1;
1373 gfile->
pos += realSize;
1374 if( --total_chunks <= 0) {
1378 bytes_left -= realSize;
1389 gfile->
pos += realSize;
1401 realSize = MIN( totalBytesToRead, gfile->
pending_len - ofs );
1403 memcpy( buf, chunk_data, (
size_t)realSize );
1410 size_t *targetBufLen,
gridfs_offset *bytes_left,
int chunkNo);
1415 char* targetBuf = NULL;
1416 size_t targetBufLen = 0;
1417 int allocatedMem = 0;
1420 for (i = 0; i < total_chunks; i++) {
1426 if( allocatedMem ) {
1427 bson_free( targetBuf );
1433 size_t *targetBufLen,
gridfs_offset *bytes_left,
int chunkNo){
1436 const char *chunk_data;
1438 if( bson_find(it, chunk,
"data") !=
BSON_EOO ) {
1439 chunk_len = bson_iterator_bin_len(it);
1440 chunk_data = bson_iterator_bin_data(it);
1441 if(
gridfs_read_filter( targetBuf, targetBufLen, chunk_data, (
size_t)chunk_len, gfile->
flags ) != 0)
return 0;
1442 *allocatedMem = *targetBuf != chunk_data;
1443 chunk_data = *targetBuf;
1445 chunk_data += (gfile->
pos) % chunksize;
1446 *targetBufLen -= (size_t)( (gfile->
pos) % chunksize );
1448 if (*bytes_left > *targetBufLen) {
1449 memcpy(*buf, chunk_data, *targetBufLen);
1450 *bytes_left -= *targetBufLen;
1451 *buf += *targetBufLen;
1452 return *targetBufLen;
1454 memcpy(*buf, chunk_data, (
size_t)(*bytes_left));
1458 bson_fatal_msg( 0,
"Chunk object doesn't have 'data' attribute" );
1470 newPos = MIN( length, offset );
1473 if (gfile->
pending_len && (newPos >= (gfile->
chunk_num + 1) * chunkSize || newPos < gfile->chunk_num * chunkSize) &&
1475 gfile->
pos = newPos;
1481 size_t data_read, data_written = 0;
1486 if( data_read > 0 ){
1487 data_written = fwrite( buffer,
sizeof(
char), data_read, stream );
1488 total_written += data_written;
1490 }
while(( data_read > 0 ) && ( data_written == data_read ));
1492 return total_written;
1501 bson_append_oid(q,
"files_id", &
id);
1502 if( deleteFromChunk >= 0 ) {
1503 bson_append_start_object( q,
"n" );
1504 bson_append_int( q,
"$gte", deleteFromChunk );
1505 bson_append_finish_object( q );
1515 int deleteFromChunk;
1547 newSize = fileSize + bytesToExpand;
1550 buf = (
char*)bson_malloc( (
size_t)bufSize );
1552 memset( buf, 0, (
size_t)bufSize );
1555 while( curPos < newSize ) {
1556 toWrite = bufSize - curPos % bufSize;
1557 if( toWrite + curPos > newSize ) {
1558 toWrite = newSize - curPos;
1573 if( newSize <= fileSize ) {
1582 #define INVALID_SOCKET (-1)
1588 # define NI_MAXSERV 32
1592 return close( socket );
1600 const char *cbuf = buf;
1604 int flags = MSG_NOSIGNAL;
1608 ssize_t sent = send( conn->
sock, cbuf, len, flags );
1625 ssize_t sent = recv( conn->
sock, cbuf, len, 0 );
1626 if ( sent == 0 || sent == -1 ) {
1639 tv.tv_sec = millis / 1000;
1640 tv.tv_usec = ( millis % 1000 ) * 1000;
1642 if ( setsockopt( conn->
sock, SOL_SOCKET, SO_RCVTIMEO, &tv,
sizeof( tv ) ) == -1 ) {
1648 if ( setsockopt( conn->
sock, SOL_SOCKET, SO_SNDTIMEO, &tv,
sizeof( tv ) ) == -1 ) {
1657 struct sockaddr_un addr = {};
1662 conn->
sock = socket( AF_UNIX, SOCK_STREAM, 0 );
1668 addr.sun_family = AF_UNIX;
1669 strncpy( addr.sun_path, sock_path,
sizeof(addr.sun_path) - 1 );
1670 len =
sizeof( addr );
1672 status = connect( conn->
sock, (
struct sockaddr *) &addr, len );
1689 struct addrinfo ai_hints;
1690 struct addrinfo *ai_list = NULL;
1691 struct addrinfo *ai_ptr = NULL;
1699 sprintf(port_str,
"%d",port);
1703 memset( &ai_hints, 0,
sizeof( ai_hints ) );
1704 #ifdef AI_ADDRCONFIG
1705 ai_hints.ai_flags = AI_ADDRCONFIG;
1707 ai_hints.ai_family = AF_UNSPEC;
1708 ai_hints.ai_socktype = SOCK_STREAM;
1710 status = getaddrinfo( host, port_str, &ai_hints, &ai_list );
1711 if ( status != 0 ) {
1712 bson_errprintf(
"getaddrinfo failed: %s", gai_strerror( status ) );
1717 for ( ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next ) {
1718 conn->
sock = socket( ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol );
1723 status = connect( conn->
sock, ai_ptr->ai_addr, ai_ptr->ai_addrlen );
1724 if ( status != 0 ) {
1732 if ( setsockopt( conn->
sock, SOL_SOCKET, SO_NOSIGPIPE,
1733 (
void * ) &flag,
sizeof( flag ) ) == -1 ) {
1741 if ( ai_ptr->ai_protocol == IPPROTO_TCP ) {
1743 if ( setsockopt( conn->
sock, IPPROTO_TCP, TCP_NODELAY,
1744 (
void * ) &flag,
sizeof( flag ) ) == -1 ) {
1757 freeaddrinfo( ai_list );
1771 return (
mongo* )bson_malloc(
sizeof(
mongo ) );
1795 static char _hp[
sizeof(hp->
host)+12];
1831 for (hp = r->
hosts; hp; hp = hp->
next) {
1845 bson_free( write_concern );
1855 bson_free( cursor );
1870 size_t str_size = 1;
1874 str_size = strlen( str ) + 1;
1876 memcpy( conn->
errstr, str, str_size );
1878 conn->
errstr[str_size-1] =
'\0';
1892 char *cmd_db_name = NULL;
1895 for( current = (
char *)ns; *current !=
'.'; current++ ) {
1899 cmd_db_name = (
char *)bson_malloc( len + 6 );
1900 strncpy( cmd_db_name, ns, len );
1901 strncpy( cmd_db_name + len,
".$cmd", 6 );
1909 const char *db_name =
ns;
1910 char *collection_name = NULL;
1921 for( current = (
char *)ns; *current !=
'\0'; current++ ) {
1922 if( *current ==
'.' ) {
1929 if( *current ==
'.' ) {
1936 if( *current ==
'\0' ) {
1946 if( collection_name - 1 == db_name ) {
1952 for( current = (
char *)db_name; *current !=
'.'; current++ ) {
1953 switch( *current ) {
1959 "Database name may not contain ' ', '$', '/', or '\\'", 0 );
1972 for( current = collection_name; *current !=
'\0'; current++ ) {
1975 if( last && *last ==
'.' && *current ==
'.' ) {
1977 "Collection may not contain two consecutive '.'", 0 );
1982 if( *current ==
'$' ) {
1984 "Collection may not contain '$'", 0 );
1992 if( ns_len > 128 ) {
1993 bson_sprintf( errmsg,
"Namespace too long; has %d but must <= 128.",
2000 if( *(current - 1) ==
'.' ) {
2002 "Collection may not end with '.'", 0 );
2012 const char *result_string = bson_iterator_string( it );
2014 memcpy( conn->
lasterrstr, result_string, len );
2016 if( bson_find( iter, obj,
"code" ) !=
BSON_NULL )
2025 if( len >= INT32_MAX) {
2080 if ( len <
sizeof( head )+
sizeof( fields ) || len > 64*1024*1024 )
2115 memcpy( start , data , len );
2140 if( bson_find( &it, &out,
"ismaster" ) )
2141 ismaster = bson_iterator_bool( &it );
2142 if( bson_find( &it, &out,
"maxBsonObjectSize" ) )
2143 max_bson_size = bson_iterator_int( &it );
2146 bson_destroy( &out );
2161 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};
2168 memset( conn, 0,
sizeof(
mongo ) );
2189 bson_errprintf(
"WARNING: mongo_connect() is deprecated, please use mongo_client()\n");
2202 conn->
replica_set->
name = (
char * )bson_malloc( strlen( name ) + 1 );
2211 bson_errprintf(
"WARNING: mongo_replset_init() is deprecated, please use mongo_replica_set_init()\n");
2218 host_port->
next = NULL;
2225 while( p->
next != NULL )
2227 p->
next = host_port;
2235 while( node != NULL ) {
2249 bson_errprintf(
"WARNING: mongo_replset_add_seed() is deprecated, please use mongo_replica_set_add_seed()\n");
2254 int len, idx, split;
2255 len = split = idx = 0;
2259 if( *( host_string + len ) ==
'\0' )
2261 if( *( host_string + len ) ==
':' )
2269 idx = split ? split :
len;
2270 memcpy( host_port->
host, host_string, idx );
2271 memcpy( host_port->
host + idx,
"\0", 1 );
2273 host_port->
port = atoi( host_string + idx + 1 );
2283 const char *host_string;
2288 if( bson_find( it, out,
"hosts" ) ) {
2289 data = bson_iterator_value( it );
2290 bson_iterator_from_buffer( it_sub, data );
2294 while( bson_iterator_next( it_sub ) ) {
2295 host_string = bson_iterator_string( it_sub );
2302 host_port->
host, host_port->
port );
2304 bson_free( host_port );
2325 const char *set_name;
2329 if( bson_find( it, out,
"ismaster" ) )
2330 ismaster = bson_iterator_bool( it );
2332 if( bson_find( it, out,
"maxBsonObjectSize" ) )
2333 max_bson_size = bson_iterator_int( it );
2336 if( bson_find( it, out,
"setName" ) ) {
2337 set_name = bson_iterator_string( it );
2339 bson_destroy( out );
2346 bson_destroy( out );
2370 while( node != NULL ) {
2388 while( node != NULL ) {
2422 bson_errprintf(
"WARNING: mongo_replset_connect() is deprecated, please use mongo_replica_set_client()\n");
2499 size = bson_size( bson );
2549 res =
mongo_find_one( conn, cmd_ns, write_concern->
cmd, bson_shared_empty( ), response );
2550 bson_free( cmd_ns );
2553 (bson_find( it, response,
"$err" ) ==
BSON_STRING ||
2554 bson_find( it, response,
"err" ) ==
BSON_STRING)) {
2557 "See conn->lasterrstr for details.", 0 );
2562 bson_destroy( response );
2570 if( custom_write_concern ) {
2576 if ( *write_concern && (*write_concern)->
w < 1 ) {
2579 if( *write_concern && !((*write_concern)->cmd) ) {
2581 "Must call mongo_write_concern_finish() before using *write_concern.", 0 );
2594 if( write_concern ) {
2628 + 1 + bson_size( bson )
2651 size_t overhead = 16 + 4 + strlen( ns ) + 1;
2652 size_t size = overhead;
2657 for( i=0; i<count; i++ ) {
2658 size += bson_size( bsons[i] );
2686 for( i=0; i<count; i++ ) {
2786 if( write_concern->
cmd ) {
2787 bson_destroy( write_concern->
cmd );
2788 command = write_concern->
cmd;
2791 command = bson_alloc();
2797 bson_init( command );
2799 bson_append_int( command,
"getlasterror", 1 );
2801 if( write_concern->
mode ) {
2802 bson_append_string( command,
"w", write_concern->
mode );
2805 else if( write_concern->
w && write_concern->
w > 1 ) {
2806 bson_append_int( command,
"w", write_concern->
w );
2810 bson_append_int( command,
"wtimeout", write_concern->
wtimeout );
2813 if( write_concern->
j ) {
2814 bson_append_int( command,
"j", write_concern->
j );
2817 if( write_concern->
fsync ) {
2818 bson_append_int( command,
"fsync", write_concern->
fsync );
2821 bson_finish( command );
2834 if( !write_concern )
2837 if( write_concern->
cmd ) {
2838 bson_destroy( write_concern->
cmd );
2839 bson_dealloc( write_concern->
cmd );
2840 write_concern->
cmd = NULL;
2851 return write_concern->
w;
2859 return write_concern->
j;
2863 return write_concern->
fsync;
2867 return write_concern->
mode;
2871 return write_concern->
cmd;
2875 write_concern->
w =
w;
2884 write_concern->
j =
j;
2907 if( ! cursor->
query )
2908 cursor->
query = bson_shared_empty( );
2913 cursor->
fields = bson_shared_empty( );
2919 strlen( cursor->
ns ) + 1 +
2921 bson_size( cursor->
query ) +
2922 bson_size( cursor->
fields ) ,
2951 if( bson_find( &it, &temp,
"$err" ) ) {
2970 else if( ! cursor->
reply ) {
2980 size_t sl = strlen( cursor->
ns )+1;
2984 if( cursor->
limit > 0 )
3003 bson_free( cursor->
reply );
3054 ret = bson_copy(out, &cursor->
current);
3056 bson_init_zero(out);
3065 cursor->
ns = (
const char * )bson_malloc( strlen( ns ) + 1 );
3066 strncpy( (
char * )cursor->
ns, ns, strlen( ns ) + 1 );
3108 if( !cursor->
reply )
3135 if ( next_object >= message_end ) {
3162 if ( !cursor )
return result;
3183 bson_free( cursor->
reply );
3184 bson_free( (
void * )cursor->
ns );
3187 bson_free( cursor );
3194 #define INDEX_NAME_BUFFER_SIZE 255
3195 #define INDEX_NAME_MAX_LENGTH (INDEX_NAME_BUFFER_SIZE - 1)
3207 bson_iterator_init( &it, key );
3210 strncat( default_name, bson_iterator_key( &it ), remaining );
3211 len = strlen( default_name );
3213 strncat( default_name, ( bson_iterator_int( &it ) < 0 ) ?
"_-1" :
"_1", remaining );
3214 len = strlen( default_name );
3219 bson_append_bson( &b,
"key", key );
3220 bson_append_string( &b,
"ns", ns );
3221 bson_append_string( &b,
"name", name ? name : default_name );
3223 bson_append_bool( &b,
"unique", 1 );
3225 bson_append_bool( &b,
"dropDups", 1 );
3227 bson_append_bool( &b,
"background", 1 );
3229 bson_append_bool( &b,
"sparse", 1 );
3232 strncpy( idxns, ns, 1024-16 );
3233 p = strchr( idxns,
'.' );
3238 strcpy( p,
".system.indexes" );
3245 *strchr( idxns,
'.' ) =
'\0';
3254 bson_append_int( b, field, 1 );
3269 bson_append_string( b,
"create", collection );
3270 bson_append_bool( b,
"capped", 1 );
3271 bson_append_int( b,
"size", size );
3273 bson_append_int( b,
"max", size );
3289 bson_append_string( cmd,
"count", coll );
3290 if ( query && bson_size( query ) > 5 )
3291 bson_append_bson( cmd,
"query", query );
3296 if( bson_find( it, out,
"n" ) )
3297 count = bson_iterator_double( it );
3299 bson_destroy( out );
3300 bson_destroy( cmd );
3308 size_t sl = strlen( db );
3309 char *
ns = (
char*) bson_malloc( sl + 5 + 1 );
3313 strcpy( ns+sl,
".$cmd" );
3315 res =
mongo_find_one( conn, ns, command, bson_shared_empty( ), response );
3318 if (res ==
MONGO_OK && (!bson_find( it, response,
"ok" ) || !bson_iterator_bool( it )) ) {
3320 bson_destroy( response );
3328 bson_init_zero(out);
3330 bson_destroy(response);
3342 bson_append_int( cmd, cmdstr, arg );
3347 bson_destroy( cmd );
3353 const char *cmdstr,
const char *
arg,
bson *
out ) {
3358 bson_append_string( &cmd, cmdstr, arg );
3359 bson_finish( &cmd );
3363 bson_destroy( &cmd );
3381 bson *realout,
const char *cmdtype ) {
3388 bson_init_zero(out);
3393 haserror = ( bson_find( it, out,
"err" ) !=
BSON_NULL );
3400 bson_destroy( out );
3423 if (bson_find( it, out,
"ismaster") !=
BSON_EOO )
3424 ismaster = bson_iterator_bool( it );
3428 bson_destroy( out );
3430 bson_init_zero(realout);
3437 if( strlen( user ) >= INT32_MAX || strlen( pass ) >= INT32_MAX ) {
3443 const char * _digest = NULL;
3449 strncpy(hex_digest, _digest, 32+1);
3450 _digest =
_free(_digest);
3459 char hex_digest[33];
3460 char *
ns = bson_malloc( strlen( db ) + strlen(
".system.users" ) + 1 );
3464 strcpy( ns+strlen( db ),
".system.users" );
3472 bson_init( &user_obj );
3473 bson_append_string( &user_obj,
"user", user );
3474 bson_finish( &user_obj );
3476 bson_init( &pass_obj );
3477 bson_append_start_object( &pass_obj,
"$set" );
3478 bson_append_string( &pass_obj,
"pwd", hex_digest );
3479 bson_append_finish_object( &pass_obj );
3480 bson_finish( &pass_obj );
3485 bson_destroy( &user_obj );
3486 bson_destroy( &pass_obj );
3497 char hex_digest[32+1];
3501 if (bson_find(&it, &from_db,
"nonce") !=
BSON_EOO )
3502 nonce = bson_iterator_string( &it );
3514 if( strlen( nonce ) >= INT32_MAX || strlen( user ) >= INT32_MAX ) {
3520 const char * _digest = NULL;
3526 strncpy(hex_digest, _digest, 32+1);
3527 hex_digest[32] =
'\0';
3528 _digest =
_free(_digest);
3532 bson_append_int( &cmd,
"authenticate", 1 );
3533 bson_append_string( &cmd,
"user", user );
3534 bson_append_string( &cmd,
"nonce", nonce );
3535 bson_append_string( &cmd,
"key", hex_digest );
3536 bson_finish( &cmd );
3540 bson_destroy( &from_db );
3541 bson_destroy( &cmd );
3554 mgo->fn =
_free(mgo->fn);
3566 if (_rpmmgoPool == NULL) {
3572 memset(((
char *)mgo)+
sizeof(mgo->_item), 0,
sizeof(*mgo)-
sizeof(mgo->_item));
static char * mongo_data_append32(char *start, const void *data)
MONGO_EXPORT int mongo_get_err(mongo *conn)
int w
Number of total replica write copies to complete including the primary.
int options
Bitfield containing cursor options.
rpmmgo rpmmgoLink(rpmmgo mgo)
Reference a mongo wrapper instance.
const char const double d
MONGO_EXPORT void gridfs_dealloc(gridfs *gfs)
MONGO_EXPORT void mongo_write_concern_set_wtimeout(mongo_write_concern *write_concern, int wtimeout)
const char * chunks_ns
The namespace where the file's metadata is stored
gridfs_offset length
The gridfile's content type
MONGO_EXPORT void mongo_replica_set_add_seed(mongo *conn, const char *host, int port)
MONGO_EXPORT bson_bool_t gridfile_get_boolean(const gridfile *gfile, const char *name)
Returns a boolean field in GridFile specified by name.
SOCKET sock
Socket file descriptor.
const char const char * coll
MONGO_EXPORT bson_oid_t gridfile_get_id(const gridfile *gfile)
Returns the _id in GridFile specified by name.
static rpmmgo rpmmgoGetPool(rpmioPool pool)
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)
An error occurred while reading or writing on the socket.
MONGO_EXPORT gridfs_offset gridfile_get_contentlength(const gridfile *gfile)
Returns the length of GridFile's data.
MONGO_EXPORT int gridfile_init(gridfs *gfs, const bson *meta, gridfile *gfile)
Initializes a GridFile containing the GridFS and file bson.
const char const char size_t len
const bson * query
Bitfield containing cursor options.
int max_bson_size
Largest BSON object allowed on this connection.
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.
static void mongo_set_last_error(mongo *conn, bson_iterator *it, bson *obj)
MONGO_EXPORT void gridfs_destroy(gridfs *gfs)
Destroys a GridFS object.
A key or a string is not valid UTF-8.
const char const char * cmd
MONGO_EXPORT gridfs_offset gridfile_write_file(gridfile *gfile, FILE *stream)
Writes the GridFile to a stream.
mongo_host_port * seeds
List of seeds provided by the user.
MONGO_EXPORT int gridfs_init(mongo *client, const char *dbname, const char *prefix, gridfs *gfs)
Initializes a GridFS object.
MONGO_EXPORT int mongo_cursor_destroy(mongo_cursor *cursor)
int err
Bitfield representing errors or warnings on this buffer.
const char const bson mongo_write_concern * custom_write_concern
MONGO_EXPORT const char * mongo_get_primary(mongo *conn)
char * xstrdup(const char *str)
The command returned with 'ok' value of 0.
MONGO_EXPORT bson * mongo_write_concern_get_cmd(mongo_write_concern *write_concern)
MONGO_EXPORT SOCKET mongo_get_socket(mongo *conn)
MONGO_EXPORT int mongo_connect(mongo *conn, const char *host, int port)
DIGEST_CTX rpmDigestInit(pgpHashAlgo hashalgo, rpmDigestFlags flags)
Initialize digest context.
bson_sprintf_func bson_sprintf
const char const bson * cond
MONGO_EXPORT void gridfile_dealloc(gridfile *gf)
static int mongo_env_read_socket(mongo *conn, void *buf, size_t len)
MONGO_EXPORT int mongo_remove(mongo *conn, const char *ns, const bson *cond, mongo_write_concern *custom_write_concern)
MONGO_EXPORT void mongo_cursor_set_fields(mongo_cursor *cursor, const bson *fields)
static int mongo_message_send(mongo *conn, mongo_message *mm)
MONGO_EXPORT const char * mongo_get_host(mongo *conn, int i)
static gridfs_offset gridfile_load_from_chunks(gridfile *gfile, int total_chunks, gridfs_offset chunksize, mongo_cursor *chunks, char *buf, gridfs_offset bytes_left)
MONGO_EXPORT int gridfs_remove_filename(gridfs *gfs, const char *filename)
Removes the files referenced by filename from the db.
mongo_write_concern * write_concern
static char * mongo_data_append64(char *start, const void *data)
gridfs_offset pos
The GridFile's bson object where all its metadata is located
MONGO_EXPORT int mongo_check_connection(mongo *conn)
const char const char * field
int bson_iterator_string_len(const bson_iterator *i)
Get the string length of the BSON object currently pointed to by the iterator.
MONGO_EXPORT void mongo_cursor_set_limit(mongo_cursor *cursor, int limit)
const char * ns
owned by cursor
MONGO_EXPORT int mongo_write_concern_get_fsync(mongo_write_concern *write_concern)
int bson_init_size(bson *b, int size)
Initialize a BSON object for building and allocate a data buffer of a given size. ...
static size_t gridfs_default_pending_data_size(int flags)
bson * cmd
The BSON object representing the getlasterror command.
BSON object has not been finished.
rpmmgo rpmmgoNew(const char *fn, int flags)
Create and load a mongo wrapper.
const char bson_date_t millis
MONGO_EXPORT void mongo_replset_init(mongo *conn, const char *name)
const char * files_ns
The prefix of the GridFS's collections, default is NULL
static bson * chunk_new(bson_oid_t id, int chunkNumber, char **dataBuf, const char *srcData, size_t len, int flags)
bson bson_bool_t copyData
MONGO_EXPORT gridfs_offset gridfile_truncate(gridfile *gfile, gridfs_offset newSize)
MONGO_EXPORT int mongo_find_one(mongo *conn, const char *ns, const bson *query, const bson *fields, bson *out)
MONGO_EXPORT void gridfile_get_metadata(const gridfile *gfile, bson *metadata, bson_bool_t copyData)
Returns the metadata of GridFile.
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 mongo_env_set_socket_op_timeout(mongo *conn, int millis)
int chunk_num
The length of this gridfile
int dataSize
The number of bytes allocated to char *data.
bson_bool_t caseInsensitive
MONGO_EXPORT const char * mongo_cursor_data(mongo_cursor *cursor)
BSON not valid for the specified op.
bson_oid_t id
The position is the offset in the file
MONGO_EXPORT int mongo_set_op_timeout(mongo *conn, int millis)
int chunkSize
Store here special flags such as: No MD5 calculation and Zlib Compression enabled ...
int op_timeout_ms
Read and write timeout in milliseconds.
int lasterrcode
getlasterror code from the server.
static void gridfile_init_flags(gridfile *gfile)
mongo_replica_set * replica_set
replica_set object if connected to a replica set.
char * data
Pointer to a block of data in this BSON object.
MONGO_EXPORT const char * gridfile_get_filename(const gridfile *gfile)
Returns the filename of GridFile.
static int mongo_message_send_and_check_write_concern(mongo *conn, const char *ns, mongo_message *mm, mongo_write_concern *write_concern)
MONGO_EXPORT gridfs_offset gridfile_write_buffer(gridfile *gfile, const char *data, gridfs_offset length)
Write to a GridFS file incrementally.
static int mongo_env_sock_init(void)
Given rs name doesn't match this replica set.
MONGO_EXPORT int gridfile_get_flags(const gridfile *gfile)
gets the flags of the GridFile
static int mongo_cursor_op_query(mongo_cursor *cursor)
int flags
Length of pending_data buffer
MONGO_EXPORT mongo_write_concern * mongo_write_concern_alloc(void)
int limit
Bitfield containing cursor options.
static char * mongo_data_append(char *start, const void *data, size_t len)
The server returned an '$err' object, indicating query failure.
MONGO_EXPORT const char * gridfile_get_field(gridfile *gfile, const char *name)
Returns the field in GridFile specified by name.
Yet Another syslog(3) API clone.
static int mongo_check_last_error(mongo *conn, const char *ns, mongo_write_concern *write_concern)
MONGO_EXPORT void mongo_init_sockets(void)
MONGO_EXPORT void mongo_write_concern_set_w(mongo_write_concern *write_concern, int w)
MONGO_EXPORT void gridfs_set_caseInsensitive(gridfs *gfs, bson_bool_t newValue)
Sets the caseInsensitive flag value of gfs.
mongo * conn
connection is not owned by cursor
static void chunk_free(bson *oChunk)
int rpmDigestUpdate(DIGEST_CTX ctx, const void *data, size_t len)
Update context with next plain text buffer.
mongo_reply_fields fields
static void rpmmgoFini(void *_mgo)
char errstr[128]
String version of error.
static gridfs_chunk_filter_func gridfs_write_filter
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
MONGO_EXPORT int mongo_get_host_count(mongo *conn)
MONGO_EXPORT int mongo_cmd_drop_collection(mongo *conn, const char *db, const char *collection, bson *out)
MONGO_EXPORT void mongo_disconnect(mongo *conn)
static int gridfile_flush_pendingchunk(gridfile *gfile)
MONGO_EXPORT void mongo_cmd_reset_error(mongo *conn, const char *db)
static void gridfile_init_chunkSize(gridfile *gfile)
MONGO_EXPORT const char * gridfile_get_md5(const gridfile *gfile)
Returns the MD5 of GridFile.
MONGO_EXPORT void mongo_write_concern_init(mongo_write_concern *write_concern)
#define MONGO_DEFAULT_PORT
MONGO_EXPORT mongo_cursor * mongo_cursor_alloc(void)
The cursor has timed out or is not recognized.
bson_printf_func bson_errprintf
static int mongo_env_socket_connect(mongo *conn, const char *host, int port)
Tailable cursor still alive but no data.
static gridfs_chunk_filter_func gridfs_read_filter
const char const bson * command
const char const bson * data
MONGO_EXPORT void mongo_clear_errors(mongo *conn)
MONGO_EXPORT void mongo_cursor_set_query(mongo_cursor *cursor, const bson *query)
static void gridfile_prepare_chunk_key_bson(bson *q, bson_oid_t *id, int chunk_num)
MONGO_EXPORT void mongo_replset_add_seed(mongo *conn, const char *host, int port)
MONGO_EXPORT void mongo_write_concern_destroy(mongo_write_concern *write_concern)
Free the write_concern object (specifically, the BSON object that it holds).
const char const bson const bson int limit
int seen
Number returned so far.
The name for the ns (database or collection) is invalid.
MONGO_EXPORT void __mongo_set_error(mongo *conn, mongo_error_t err, const char *str, int errcode)
static mongo_write_concern WC1
size_t pending_len
A buffer storing data still to be written to chunks
mongo_host_port * primary
Primary connection info.
int errcode
Most recent errno or WSAGetLastError().
static int mongo_pass_digest(mongo *conn, const char *user, const char *pass, char hex_digest[33])
static int mongo_bson_valid(mongo *conn, const bson *bson, int write)
MONGO_EXPORT int mongo_write_concern_get_j(mongo_write_concern *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_reply * reply
reply is owned by cursor
MONGO_EXPORT void mongo_write_concern_set_fsync(mongo_write_concern *write_concern, int fsync)
MONGO_EXPORT int gridfile_get_chunksize(const gridfile *gfile)
Returns the size of the chunks of the GridFile.
MONGO_EXPORT int mongo_cursor_next(mongo_cursor *cursor)
MONGO_EXPORT int mongo_cmd_get_last_error(mongo *conn, const char *db, bson *out)
MONGO_EXPORT int mongo_is_connected(mongo *conn)
mongo_cursor_error_t err
Errors on this cursor.
const char const bson const bson int int skip
const char const bson const bson * fields
#define INDEX_NAME_BUFFER_SIZE
const char const char const char * pass
static int mongo_replica_set_check_host(mongo *conn)
BSON object exceeds max BSON size.
static int gridfile_remove_chunks(gridfile *gfile, int deleteFromChunk)
const char const char * user
int mongo_env_close_socket(SOCKET socket)
MONGO_EXPORT int mongo_insert(mongo *conn, const char *ns, const bson *bson, mongo_write_concern *custom_write_concern)
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.
static const char * _get_host_port(mongo_host_port *hp)
static int mongo_choose_write_concern(mongo *conn, mongo_write_concern *custom_write_concern, mongo_write_concern **write_concern)
char * pending_data
The number of the current chunk being written to
Write with given write_concern returned an error.
MONGO_EXPORT int mongo_cmd_get_prev_error(mongo *conn, const char *db, bson *out)
MONGO_EXPORT int mongo_run_command(mongo *conn, const char *db, const bson *command, bson *out)
char * name
Name of the replica set.
MONGO_EXPORT int mongo_cmd_drop_db(mongo *conn, const char *db)
MONGO_EXPORT void gridfile_get_descriptor(gridfile *gf, bson *out)
MONGO_EXPORT void gridfile_set_flags(gridfile *gfile, int flags)
Sets the flags of the GridFile.
const char const bson const bson * op
MONGO_EXPORT bson_date_t gridfile_get_uploaddate(const gridfile *gfile)
Returns the upload date of GridFile.
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.
const char const char * collection
#define INDEX_NAME_MAX_LENGTH
static int mongo_cmd_get_error_helper(mongo *conn, const char *db, bson *realout, const char *cmdtype)
MONGO_EXPORT gridfile * gridfile_create(void)
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.
MONGO_EXPORT int gridfile_get_numchunks(const gridfile *gfile)
Returns the number of chunks in the GridFile.
static int gridfile_load_pending_data_with_pos_chunk(gridfile *gfile)
const char const char int arg
MONGO_EXPORT gridfs_offset gridfile_set_size(gridfile *gfile, gridfs_offset newSize)
static int mongo_env_write_socket(mongo *conn, const void *buf, size_t len)
void bson_little_endian32(void *outp, const void *inp)
MONGO_EXPORT void mongo_init(mongo *conn)
MONGO_EXPORT int mongo_simple_str_command(mongo *conn, const char *db, const char *cmdstr, const char *arg, bson *out)
MONGO_EXPORT int mongo_replica_set_client(mongo *conn)
char lasterrstr[128]
getlasterror string from the server.
MONGO_EXPORT const char * gridfile_get_contenttype(const gridfile *gfile)
Returns the MIME type of the GridFile.
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_simple_int_command(mongo *conn, const char *db, const char *cmdstr, int arg, bson *out)
const char const bson int mongo_write_concern int flags
Can't find primary in replica set.
MONGO_EXPORT bson_bool_t mongo_create_simple_index(mongo *conn, const char *ns, const char *field, int options, bson *out)
MONGO_EXPORT void mongo_write_concern_set_j(mongo_write_concern *write_concern, int j)
The response is not the expected length.
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.
MONGO_EXPORT void mongo_set_write_concern(mongo *conn, mongo_write_concern *write_concern)
mongo_host_port * hosts
List of host/ports given by the replica set.
bson_bool_t connected
Connection status.
const char * prefix
The root database name
int wtimeout
Number of milliseconds before replication timeout.
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.
void bson_fatal_msg(int ok, const char *msg)
Exit fatally with an error message.
MONGO_EXPORT void mongo_cursor_set_options(mongo_cursor *cursor, int options)
Warning: key starts with '$' character.
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.
int skip
Bitfield containing cursor options.
MONGO_EXPORT bson_bool_t mongo_cmd_authenticate(mongo *conn, const char *db, const char *user, const char *pass)
int flags
Flags used internally by this drivers.
An error occured while calling getaddrinfo().
bson_bool_t finished
When finished, the BSON object can no longer be modified.
MONGO_EXPORT double mongo_count(mongo *conn, const char *db, const char *coll, const bson *query)
const char const bson * query
static int snprintf(char *buf, int nb, const char *fmt,...)
MONGO_EXPORT void mongo_replica_set_init(mongo *conn, const char *name)
const char const bson * key
const bson * fields
Bitfield containing cursor options.
static const char * prefix[]
Tables for prefixing and suffixing patterns, according to the -w, -x, and -F options.
const char const bson const bson bson * out
const char const char int int max
static int mongo_check_is_master(mongo *conn)
Initial query has been sent.
rpmioPool rpmioNewPool(const char *name, size_t size, int limit, int flags, char *(*dbg)(void *item), void(*init)(void *item), void(*fini)(void *item))
Create a memory pool.
MONGO_EXPORT bson_bool_t gridfs_get_caseInsensitive(const gridfs *gfs)
Returns the caseInsensitive flag value of gfs.
MONGO_EXPORT gridfs_offset gridfile_expand(gridfile *gfile, gridfs_offset bytesToExpand)
bson * meta
The GridFS where the GridFile is located
MONGO_EXPORT void gridfile_destroy(gridfile *gfile)
Destroys the GridFile.
MONGO_EXPORT bson_bool_t gridfile_exists(const gridfile *gfile)
Returns whether or not the GridFile exists.
const char * dbname
The client to db-connection.
MONGO_EXPORT gridfs * gridfs_alloc(void)
const char const char size_t size
static void mongo_replica_set_add_node(mongo_host_port **list, const char *host, int port)
int j
If non-zero, block until the journal sync.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
MONGO_EXPORT int mongo_create_capped_collection(mongo *conn, const char *db, const char *collection, int size, int max, bson *out)
MONGO_EXPORT void mongo_cursor_init(mongo_cursor *cursor, mongo *conn, const char *ns)
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
Warning: connected to a non-master node (read-only).
MONGO_EXPORT void gridfs_set_chunk_filter_funcs(gridfs_chunk_filter_func writeFilter, gridfs_chunk_filter_func readFilter, gridfs_pending_data_size_func pendingDataNeededSize)
static gridfs_offset gridfile_read_from_pending_buffer(gridfile *gfile, gridfs_offset totalBytesToRead, char *buf, int *first_chunk)
static int mongo_cursor_get_more(mongo_cursor *cursor)
static int mongo_cursor_bson_valid(mongo_cursor *cursor, const bson *bson)
static int mongo_read_response(mongo *conn, mongo_reply **reply)
MONGO_EXPORT const bson * mongo_cursor_bson(mongo_cursor *cursor)
static int mongo_env_unix_socket_connect(mongo *conn, const char *sock_path)
MONGO_EXPORT const char * mongo_write_concern_get_mode(mongo_write_concern *write_concern)
MONGO_EXPORT void mongo_cursor_set_skip(mongo_cursor *cursor, int skip)
MONGO_EXPORT int mongo_validate_ns(mongo *conn, const char *ns)
MONGO_EXPORT void mongo_write_concern_dealloc(mongo_write_concern *write_concern)
MONGO_EXPORT void mongo_destroy(mongo *conn)
struct mongo_host_port * next
bson_bool_t primary_connected
Primary node connection status.
char * remote_name
The files_id of the gridfile
MONGO_EXPORT int mongo_write_concern_get_w(mongo_write_concern *write_concern)
MONGO_EXPORT void mongo_cursor_dealloc(mongo_cursor *cursor)
static mongo_message * mongo_message_create(size_t len, int id, int responseTo, int op)
int rpmDigestFinal(DIGEST_CTX ctx, void *datap, size_t *lenp, int asAscii)
Return digest and destroy context.
MONGO_EXPORT int mongo_replset_connect(mongo *conn)
const char * mode
Either "majority" or a getlasterrormode.
#define MONGO_DEFAULT_MAX_BSON_SIZE
bson current
This cursor's current bson object.
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 ...
MONGO_EXPORT int mongo_cmd_add_user(mongo *conn, const char *db, const char *user, const char *pass)
mongo_error_t err
Most recent driver error code.
void bson_little_endian64(void *outp, const void *inp)
MONGO_EXPORT void gridfile_get_chunk(gridfile *gfile, int n, bson *out)
Returns chunk n of GridFile.
MONGO_EXPORT void mongo_write_concern_set_mode(mongo_write_concern *write_concern, const char *mode)
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 update...
char * content_type
The name of the gridfile as a string
An error occured while calling connect().
MONGO_EXPORT int mongo_client(mongo *conn, const char *host, int port)
MONGO_EXPORT int mongo_write_concern_get_wtimeout(mongo_write_concern *write_concern)
const char const bson const bson int int int options
MONGO_EXPORT int mongo_get_server_err(mongo *conn)
int bson_init_finished_data(bson *b, char *data, bson_bool_t ownsData)
Initialize a BSON object for reading and set its data pointer to the provided char*.
static int bson_append_string_uppercase(bson *b, const char *name, const char *str, bson_bool_t upperCase)
static void gridfile_init_length(gridfile *gfile)
static void mongo_replica_set_free_list(mongo_host_port **list)
The cursor has no more results.
MONGO_EXPORT int mongo_create_index(mongo *conn, const char *ns, const bson *key, const char *name, int options, bson *out)
MONGO_EXPORT int mongo_reconnect(mongo *conn)
Supplied write concern object is invalid.
static void mongo_replica_set_check_seed(mongo *conn)
size_t(* gridfs_pending_data_size_func)(int flags)
static char * _strupr(char *str)
MONGO_EXPORT int mongo_get_op_timeout(mongo *conn)
static int gridfs_default_chunk_filter(char **targetBuf, size_t *targetLen, const char *srcData, size_t srcLen, int flags)
mongo_cursor_destroy should free cursor.
int fsync
Same a j with journaling enabled; otherwise, call fsync.
int(* gridfs_chunk_filter_func)(char **targetBuf, size_t *targetLen, const char *srcBuf, size_t srcLen, int flags)
MONGO_EXPORT const char * mongo_get_server_err_string(mongo *conn)
MONGO_EXPORT bson_bool_t mongo_cmd_ismaster(mongo *conn, bson *realout)
static char * mongo_ns_to_cmd_db(const char *ns)
mongo_write_concern * write_concern
The default write concern.
MONGO_EXPORT mongo * mongo_alloc(void)
MONGO_EXPORT void mongo_dealloc(mongo *conn)
MONGO_EXPORT mongo_cursor * mongo_find(mongo *conn, const char *ns, const bson *query, const bson *fields, int limit, int skip, int options)
static gridfs_pending_data_size_func gridfs_pending_data_size
MONGO_EXPORT int mongo_write_concern_finish(mongo_write_concern *write_concern)
Something is wrong with the BSON provided.