30
30
#include <common-atomic-private.h>
31
31
#include <common-oid-private.h>
32
32
33
+ #include <mlib/config.h>
34
+
33
35
#include <stdio.h>
34
36
35
37
#define ALPHA 0.2
@@ -556,28 +558,34 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
556
558
}
557
559
} else if (strcmp ("isWritablePrimary" , bson_iter_key (& iter )) == 0 ||
558
560
strcmp (HANDSHAKE_RESPONSE_LEGACY_HELLO , bson_iter_key (& iter )) == 0 ) {
559
- if (!BSON_ITER_HOLDS_BOOL (& iter ))
561
+ if (!BSON_ITER_HOLDS_BOOL (& iter )) {
560
562
GOTO (typefailure );
563
+ }
561
564
is_primary = bson_iter_bool (& iter );
562
565
} else if (strcmp ("helloOk" , bson_iter_key (& iter )) == 0 ) {
563
- if (!BSON_ITER_HOLDS_BOOL (& iter ))
566
+ if (!BSON_ITER_HOLDS_BOOL (& iter )) {
564
567
GOTO (typefailure );
568
+ }
565
569
sd -> hello_ok = bson_iter_bool (& iter );
566
570
} else if (strcmp ("me" , bson_iter_key (& iter )) == 0 ) {
567
- if (!BSON_ITER_HOLDS_UTF8 (& iter ))
571
+ if (!BSON_ITER_HOLDS_UTF8 (& iter )) {
568
572
GOTO (typefailure );
573
+ }
569
574
sd -> me = bson_iter_utf8 (& iter , NULL );
570
575
} else if (strcmp ("maxMessageSizeBytes" , bson_iter_key (& iter )) == 0 ) {
571
- if (!BSON_ITER_HOLDS_INT32 (& iter ))
576
+ if (!BSON_ITER_HOLDS_INT32 (& iter )) {
572
577
GOTO (typefailure );
578
+ }
573
579
sd -> max_msg_size = bson_iter_int32 (& iter );
574
580
} else if (strcmp ("maxBsonObjectSize" , bson_iter_key (& iter )) == 0 ) {
575
- if (!BSON_ITER_HOLDS_INT32 (& iter ))
581
+ if (!BSON_ITER_HOLDS_INT32 (& iter )) {
576
582
GOTO (typefailure );
583
+ }
577
584
sd -> max_bson_obj_size = bson_iter_int32 (& iter );
578
585
} else if (strcmp ("maxWriteBatchSize" , bson_iter_key (& iter )) == 0 ) {
579
- if (!BSON_ITER_HOLDS_INT32 (& iter ))
586
+ if (!BSON_ITER_HOLDS_INT32 (& iter )) {
580
587
GOTO (typefailure );
588
+ }
581
589
sd -> max_write_batch_size = bson_iter_int32 (& iter );
582
590
} else if (strcmp ("logicalSessionTimeoutMinutes" , bson_iter_key (& iter )) == 0 ) {
583
591
if (BSON_ITER_HOLDS_NUMBER (& iter )) {
@@ -589,68 +597,81 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
589
597
GOTO (typefailure );
590
598
}
591
599
} else if (strcmp ("minWireVersion" , bson_iter_key (& iter )) == 0 ) {
592
- if (!BSON_ITER_HOLDS_INT32 (& iter ))
600
+ if (!BSON_ITER_HOLDS_INT32 (& iter )) {
593
601
GOTO (typefailure );
602
+ }
594
603
sd -> min_wire_version = bson_iter_int32 (& iter );
595
604
} else if (strcmp ("maxWireVersion" , bson_iter_key (& iter )) == 0 ) {
596
- if (!BSON_ITER_HOLDS_INT32 (& iter ))
605
+ if (!BSON_ITER_HOLDS_INT32 (& iter )) {
597
606
GOTO (typefailure );
607
+ }
598
608
sd -> max_wire_version = bson_iter_int32 (& iter );
599
609
} else if (strcmp ("msg" , bson_iter_key (& iter )) == 0 ) {
600
610
const char * msg ;
601
- if (!BSON_ITER_HOLDS_UTF8 (& iter ))
611
+ if (!BSON_ITER_HOLDS_UTF8 (& iter )) {
602
612
GOTO (typefailure );
613
+ }
603
614
msg = bson_iter_utf8 (& iter , NULL );
604
615
if (msg && 0 == strcmp (msg , "isdbgrid" )) {
605
616
is_shard = true;
606
617
}
607
618
} else if (strcmp ("setName" , bson_iter_key (& iter )) == 0 ) {
608
- if (!BSON_ITER_HOLDS_UTF8 (& iter ))
619
+ if (!BSON_ITER_HOLDS_UTF8 (& iter )) {
609
620
GOTO (typefailure );
621
+ }
610
622
sd -> set_name = bson_iter_utf8 (& iter , NULL );
611
623
} else if (strcmp ("setVersion" , bson_iter_key (& iter )) == 0 ) {
612
624
mongoc_server_description_set_set_version (sd , bson_iter_as_int64 (& iter ));
613
625
} else if (strcmp ("electionId" , bson_iter_key (& iter )) == 0 ) {
614
- if (!BSON_ITER_HOLDS_OID (& iter ))
626
+ if (!BSON_ITER_HOLDS_OID (& iter )) {
615
627
GOTO (typefailure );
628
+ }
616
629
mongoc_server_description_set_election_id (sd , bson_iter_oid (& iter ));
617
630
} else if (strcmp ("secondary" , bson_iter_key (& iter )) == 0 ) {
618
- if (!BSON_ITER_HOLDS_BOOL (& iter ))
631
+ if (!BSON_ITER_HOLDS_BOOL (& iter )) {
619
632
GOTO (typefailure );
633
+ }
620
634
is_secondary = bson_iter_bool (& iter );
621
635
} else if (strcmp ("hosts" , bson_iter_key (& iter )) == 0 ) {
622
- if (!BSON_ITER_HOLDS_ARRAY (& iter ))
636
+ if (!BSON_ITER_HOLDS_ARRAY (& iter )) {
623
637
GOTO (typefailure );
638
+ }
624
639
bson_iter_array (& iter , & len , & bytes );
625
640
bson_destroy (& sd -> hosts );
626
641
BSON_ASSERT (bson_init_static (& sd -> hosts , bytes , len ));
627
642
} else if (strcmp ("passives" , bson_iter_key (& iter )) == 0 ) {
628
- if (!BSON_ITER_HOLDS_ARRAY (& iter ))
643
+ if (!BSON_ITER_HOLDS_ARRAY (& iter )) {
629
644
GOTO (typefailure );
645
+ }
630
646
bson_iter_array (& iter , & len , & bytes );
631
647
bson_destroy (& sd -> passives );
632
648
BSON_ASSERT (bson_init_static (& sd -> passives , bytes , len ));
633
649
} else if (strcmp ("arbiters" , bson_iter_key (& iter )) == 0 ) {
634
- if (!BSON_ITER_HOLDS_ARRAY (& iter ))
650
+ if (!BSON_ITER_HOLDS_ARRAY (& iter )) {
635
651
GOTO (typefailure );
652
+ }
636
653
bson_iter_array (& iter , & len , & bytes );
637
654
bson_destroy (& sd -> arbiters );
638
655
BSON_ASSERT (bson_init_static (& sd -> arbiters , bytes , len ));
639
656
} else if (strcmp ("primary" , bson_iter_key (& iter )) == 0 ) {
640
- if (!BSON_ITER_HOLDS_UTF8 (& iter ))
657
+ if (!BSON_ITER_HOLDS_UTF8 (& iter )) {
641
658
GOTO (typefailure );
659
+ }
642
660
sd -> current_primary = bson_iter_utf8 (& iter , NULL );
643
661
} else if (strcmp ("arbiterOnly" , bson_iter_key (& iter )) == 0 ) {
644
- if (!BSON_ITER_HOLDS_BOOL (& iter ))
662
+ if (!BSON_ITER_HOLDS_BOOL (& iter )) {
645
663
GOTO (typefailure );
664
+ }
646
665
is_arbiter = bson_iter_bool (& iter );
647
666
} else if (strcmp ("isreplicaset" , bson_iter_key (& iter )) == 0 ) {
648
- if (!BSON_ITER_HOLDS_BOOL (& iter ))
667
+ if (!BSON_ITER_HOLDS_BOOL (& iter )) {
649
668
GOTO (typefailure );
669
+ }
650
670
is_replicaset = bson_iter_bool (& iter );
651
671
} else if (strcmp ("tags" , bson_iter_key (& iter )) == 0 ) {
652
- if (!BSON_ITER_HOLDS_DOCUMENT (& iter ))
672
+ if (!BSON_ITER_HOLDS_DOCUMENT (& iter )) {
653
673
GOTO (typefailure );
674
+ }
654
675
bson_iter_document (& iter , & len , & bytes );
655
676
bson_destroy (& sd -> tags );
656
677
BSON_ASSERT (bson_init_static (& sd -> tags , bytes , len ));
@@ -664,8 +685,9 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
664
685
665
686
sd -> last_write_date_ms = bson_iter_date_time (& child );
666
687
} else if (strcmp ("compression" , bson_iter_key (& iter )) == 0 ) {
667
- if (!BSON_ITER_HOLDS_ARRAY (& iter ))
688
+ if (!BSON_ITER_HOLDS_ARRAY (& iter )) {
668
689
GOTO (typefailure );
690
+ }
669
691
bson_iter_array (& iter , & len , & bytes );
670
692
bson_destroy (& sd -> compressors );
671
693
BSON_ASSERT (bson_init_static (& sd -> compressors , bytes , len ));
@@ -681,12 +703,14 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
681
703
mongoc_server_description_set_topology_version (sd , & incoming_topology_version );
682
704
bson_destroy (& incoming_topology_version );
683
705
} else if (strcmp ("serviceId" , bson_iter_key (& iter )) == 0 ) {
684
- if (!BSON_ITER_HOLDS_OID (& iter ))
706
+ if (!BSON_ITER_HOLDS_OID (& iter )) {
685
707
GOTO (typefailure );
708
+ }
686
709
bson_oid_copy_unsafe (bson_iter_oid (& iter ), & sd -> service_id );
687
710
} else if (strcmp ("connectionId" , bson_iter_key (& iter )) == 0 ) {
688
- if (!BSON_ITER_HOLDS_NUMBER (& iter ))
711
+ if (!BSON_ITER_HOLDS_NUMBER (& iter )) {
689
712
GOTO (typefailure );
713
+ }
690
714
sd -> server_connection_id = bson_iter_as_int64 (& iter );
691
715
}
692
716
}
0 commit comments