@@ -182,6 +182,9 @@ cachedb_con *mongo_con_init(str *url)
182
182
void mongo_free_connection (cachedb_pool_con * con )
183
183
{
184
184
mongo_con * mcon = (mongo_con * )con ;
185
+
186
+ if (!mcon )
187
+ return ;
185
188
186
189
mongoc_collection_destroy (mcon -> collection );
187
190
mongoc_database_destroy (mcon -> database );
@@ -208,6 +211,9 @@ int mongo_con_get(cachedb_con *con, str *attr, str *val)
208
211
char * p ;
209
212
int ret = 0 ;
210
213
214
+ if (!con )
215
+ return -1 ;
216
+
211
217
LM_DBG ("find %.*s in %s\n" , attr -> len , attr -> s ,
212
218
MONGO_NAMESPACE (con ));
213
219
@@ -295,6 +301,9 @@ int mongo_con_set(cachedb_con *con, str *attr, str *val, int expires)
295
301
struct timeval start ;
296
302
int ret = 0 ;
297
303
304
+ if (!con )
305
+ return -1 ;
306
+
298
307
query = bson_new ();
299
308
bson_append_utf8 (query , MDB_PK , MDB_PKLEN , attr -> s , attr -> len );
300
309
@@ -329,6 +338,9 @@ int mongo_con_remove(cachedb_con *con, str *attr)
329
338
struct timeval start ;
330
339
int ret = 0 ;
331
340
341
+ if (!con )
342
+ return -1 ;
343
+
332
344
doc = bson_new ();
333
345
bson_append_utf8 (doc , MDB_PK , MDB_PKLEN , attr -> s , attr -> len );
334
346
@@ -368,6 +380,9 @@ int mongo_raw_find(cachedb_con *con, bson_t *raw_query, bson_iter_t *ns,
368
380
int i , len , csz = 0 , ret = -1 ;
369
381
const char * p ;
370
382
383
+ if (!con )
384
+ return -1 ;
385
+
371
386
if (bson_iter_type (ns ) != BSON_TYPE_UTF8 ) {
372
387
LM_ERR ("collection name must be a string (%d)!\n" , bson_iter_type (ns ));
373
388
return -1 ;
@@ -519,6 +534,9 @@ int mongo_raw_update(cachedb_con *con, bson_t *raw_query, bson_iter_t *ns)
519
534
const bson_value_t * v ;
520
535
int ret , count = 0 ;
521
536
537
+ if (!con )
538
+ return -1 ;
539
+
522
540
if (bson_iter_type (ns ) != BSON_TYPE_UTF8 ) {
523
541
LM_ERR ("collection name must be a string (%d)!\n" , bson_iter_type (ns ));
524
542
return -1 ;
@@ -624,6 +642,9 @@ int mongo_raw_insert(cachedb_con *con, bson_t *raw_query, bson_iter_t *ns)
624
642
const bson_value_t * v ;
625
643
int ret , count = 0 ;
626
644
645
+ if (!con )
646
+ return -1 ;
647
+
627
648
if (bson_iter_type (ns ) != BSON_TYPE_UTF8 ) {
628
649
LM_ERR ("collection name must be a string (%d)!\n" , bson_iter_type (ns ));
629
650
return -1 ;
@@ -708,6 +729,9 @@ int mongo_raw_remove(cachedb_con *con, bson_t *raw_query, bson_iter_t *ns)
708
729
const bson_value_t * v ;
709
730
int ret , count = 0 ;
710
731
732
+ if (!con )
733
+ return -1 ;
734
+
711
735
if (bson_iter_type (ns ) != BSON_TYPE_UTF8 ) {
712
736
LM_ERR ("collection name must be a string (%d)!\n" , bson_iter_type (ns ));
713
737
return -1 ;
@@ -807,6 +831,9 @@ int mongo_con_raw_query(cachedb_con *con, str *qstr, cdb_raw_entry ***reply,
807
831
const char * p ;
808
832
int csz = 0 , i , len ;
809
833
834
+ if (!con )
835
+ return -1 ;
836
+
810
837
LM_DBG ("Get operation on namespace %s\n" , MONGO_NAMESPACE (con ));
811
838
start_expire_timer (start ,mongo_exec_threshold );
812
839
@@ -966,6 +993,9 @@ int mongo_con_add(cachedb_con *con, str *attr, int val, int expires, int *new_va
966
993
struct timeval start ;
967
994
int ret = 0 ;
968
995
996
+ if (!con )
997
+ return -1 ;
998
+
969
999
cmd = bson_new ();
970
1000
bson_append_utf8 (cmd , "findAndModify" , 13 ,
971
1001
mongoc_collection_get_name (MONGO_COLLECTION (con )), -1 );
@@ -1032,6 +1062,9 @@ int mongo_con_get_counter(cachedb_con *con, str *attr, int *val)
1032
1062
struct timeval start ;
1033
1063
int ret = -2 ;
1034
1064
1065
+ if (!con )
1066
+ return -1 ;
1067
+
1035
1068
query = bson_new ();
1036
1069
#if MONGOC_CHECK_VERSION (1 , 5 , 0 )
1037
1070
bson_append_utf8 (query , MDB_PK , MDB_PKLEN , attr -> s , attr -> len );
@@ -1217,6 +1250,9 @@ int mongo_db_query_trans(cachedb_con *con, const str *table, const db_key_t *_k,
1217
1250
char * strf , * stro ;
1218
1251
str st ;
1219
1252
1253
+ if (!con )
1254
+ return -1 ;
1255
+
1220
1256
* _r = NULL ;
1221
1257
1222
1258
filter = bson_new ();
@@ -1516,6 +1552,9 @@ int mongo_db_insert_trans(cachedb_con *con, const str *table,
1516
1552
mongoc_collection_t * col = NULL ;
1517
1553
struct timeval start ;
1518
1554
1555
+ if (!con )
1556
+ return -1 ;
1557
+
1519
1558
doc = bson_new ();
1520
1559
if (kvo_to_bson (_k , _v , NULL , _n , doc ) != 0 ) {
1521
1560
LM_ERR ("failed to build bson\n" );
@@ -1565,6 +1604,9 @@ int mongo_db_delete_trans(cachedb_con *con, const str *table,
1565
1604
mongoc_collection_t * col = NULL ;
1566
1605
struct timeval start ;
1567
1606
1607
+ if (!con )
1608
+ return -1 ;
1609
+
1568
1610
doc = bson_new ();
1569
1611
if (kvo_to_bson (_k , _v , _o , _n , doc ) != 0 ) {
1570
1612
LM_ERR ("failed to build bson\n" );
@@ -1615,6 +1657,9 @@ int mongo_db_update_trans(cachedb_con *con, const str *table,
1615
1657
mongoc_collection_t * col = NULL ;
1616
1658
struct timeval start ;
1617
1659
1660
+ if (!con )
1661
+ return -1 ;
1662
+
1618
1663
query = bson_new ();
1619
1664
if (kvo_to_bson (_k , _v , _o , _n , query ) != 0 ) {
1620
1665
LM_ERR ("failed to build query bson\n" );
@@ -1677,6 +1722,9 @@ int mongo_truncate(cachedb_con *con)
1677
1722
struct timeval start ;
1678
1723
int ret = 0 ;
1679
1724
1725
+ if (!con )
1726
+ return -1 ;
1727
+
1680
1728
start_expire_timer (start , mongo_exec_threshold );
1681
1729
if (!mongoc_collection_remove (MONGO_COLLECTION (con ),
1682
1730
MONGOC_REMOVE_NONE , & empty_doc , NULL , & error )) {
@@ -1894,6 +1942,9 @@ int mongo_con_query(cachedb_con *con, const cdb_filter_t *filter,
1894
1942
const bson_t * doc ;
1895
1943
struct timeval start ;
1896
1944
1945
+ if (!con )
1946
+ return -1 ;
1947
+
1897
1948
LM_DBG ("find all in %s\n" , MONGO_NAMESPACE (con ));
1898
1949
1899
1950
cdb_res_init (res );
@@ -2074,6 +2125,9 @@ int mongo_con_update(cachedb_con *con, const cdb_filter_t *row_filter,
2074
2125
cdb_pair_t * pair ;
2075
2126
str key ;
2076
2127
2128
+ if (!con )
2129
+ return -1 ;
2130
+
2077
2131
if (mongo_cdb_filter_to_bson (row_filter , & filter ) != 0 ) {
2078
2132
LM_ERR ("failed to build bson filter\n" );
2079
2133
return -1 ;
0 commit comments