@@ -601,33 +601,33 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
601
601
* MUST treat this an authentication error." */
602
602
sd -> error .domain = MONGOC_ERROR_CLIENT ;
603
603
sd -> error .code = MONGOC_ERROR_CLIENT_AUTHENTICATE ;
604
- goto failure ;
604
+ GOTO ( authfailure ) ;
605
605
}
606
606
} else if (strcmp ("isWritablePrimary" , bson_iter_key (& iter )) == 0 ||
607
607
strcmp (HANDSHAKE_RESPONSE_LEGACY_HELLO ,
608
608
bson_iter_key (& iter )) == 0 ) {
609
609
if (!BSON_ITER_HOLDS_BOOL (& iter ))
610
- goto failure ;
610
+ GOTO ( typefailure ) ;
611
611
is_primary = bson_iter_bool (& iter );
612
612
} else if (strcmp ("helloOk" , bson_iter_key (& iter )) == 0 ) {
613
613
if (!BSON_ITER_HOLDS_BOOL (& iter ))
614
- goto failure ;
614
+ GOTO ( typefailure ) ;
615
615
sd -> hello_ok = bson_iter_bool (& iter );
616
616
} else if (strcmp ("me" , bson_iter_key (& iter )) == 0 ) {
617
617
if (!BSON_ITER_HOLDS_UTF8 (& iter ))
618
- goto failure ;
618
+ GOTO ( typefailure ) ;
619
619
sd -> me = bson_iter_utf8 (& iter , NULL );
620
620
} else if (strcmp ("maxMessageSizeBytes" , bson_iter_key (& iter )) == 0 ) {
621
621
if (!BSON_ITER_HOLDS_INT32 (& iter ))
622
- goto failure ;
622
+ GOTO ( typefailure ) ;
623
623
sd -> max_msg_size = bson_iter_int32 (& iter );
624
624
} else if (strcmp ("maxBsonObjectSize" , bson_iter_key (& iter )) == 0 ) {
625
625
if (!BSON_ITER_HOLDS_INT32 (& iter ))
626
- goto failure ;
626
+ GOTO ( typefailure ) ;
627
627
sd -> max_bson_obj_size = bson_iter_int32 (& iter );
628
628
} else if (strcmp ("maxWriteBatchSize" , bson_iter_key (& iter )) == 0 ) {
629
629
if (!BSON_ITER_HOLDS_INT32 (& iter ))
630
- goto failure ;
630
+ GOTO ( typefailure ) ;
631
631
sd -> max_write_batch_size = bson_iter_int32 (& iter );
632
632
} else if (strcmp ("logicalSessionTimeoutMinutes" ,
633
633
bson_iter_key (& iter )) == 0 ) {
@@ -637,72 +637,72 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
637
637
/* this arises executing standard JSON tests */
638
638
sd -> session_timeout_minutes = MONGOC_NO_SESSIONS ;
639
639
} else {
640
- goto failure ;
640
+ GOTO ( typefailure ) ;
641
641
}
642
642
} else if (strcmp ("minWireVersion" , bson_iter_key (& iter )) == 0 ) {
643
643
if (!BSON_ITER_HOLDS_INT32 (& iter ))
644
- goto failure ;
644
+ GOTO ( typefailure ) ;
645
645
sd -> min_wire_version = bson_iter_int32 (& iter );
646
646
} else if (strcmp ("maxWireVersion" , bson_iter_key (& iter )) == 0 ) {
647
647
if (!BSON_ITER_HOLDS_INT32 (& iter ))
648
- goto failure ;
648
+ GOTO ( typefailure ) ;
649
649
sd -> max_wire_version = bson_iter_int32 (& iter );
650
650
} else if (strcmp ("msg" , bson_iter_key (& iter )) == 0 ) {
651
651
const char * msg ;
652
652
if (!BSON_ITER_HOLDS_UTF8 (& iter ))
653
- goto failure ;
653
+ GOTO ( typefailure ) ;
654
654
msg = bson_iter_utf8 (& iter , NULL );
655
655
if (msg && 0 == strcmp (msg , "isdbgrid" )) {
656
656
is_shard = true;
657
657
}
658
658
} else if (strcmp ("setName" , bson_iter_key (& iter )) == 0 ) {
659
659
if (!BSON_ITER_HOLDS_UTF8 (& iter ))
660
- goto failure ;
660
+ GOTO ( typefailure ) ;
661
661
sd -> set_name = bson_iter_utf8 (& iter , NULL );
662
662
} else if (strcmp ("setVersion" , bson_iter_key (& iter )) == 0 ) {
663
663
mongoc_server_description_set_set_version (sd ,
664
664
bson_iter_as_int64 (& iter ));
665
665
} else if (strcmp ("electionId" , bson_iter_key (& iter )) == 0 ) {
666
666
if (!BSON_ITER_HOLDS_OID (& iter ))
667
- goto failure ;
667
+ GOTO ( typefailure ) ;
668
668
mongoc_server_description_set_election_id (sd , bson_iter_oid (& iter ));
669
669
} else if (strcmp ("secondary" , bson_iter_key (& iter )) == 0 ) {
670
670
if (!BSON_ITER_HOLDS_BOOL (& iter ))
671
- goto failure ;
671
+ GOTO ( typefailure ) ;
672
672
is_secondary = bson_iter_bool (& iter );
673
673
} else if (strcmp ("hosts" , bson_iter_key (& iter )) == 0 ) {
674
674
if (!BSON_ITER_HOLDS_ARRAY (& iter ))
675
- goto failure ;
675
+ GOTO ( typefailure ) ;
676
676
bson_iter_array (& iter , & len , & bytes );
677
677
bson_destroy (& sd -> hosts );
678
678
BSON_ASSERT (bson_init_static (& sd -> hosts , bytes , len ));
679
679
} else if (strcmp ("passives" , bson_iter_key (& iter )) == 0 ) {
680
680
if (!BSON_ITER_HOLDS_ARRAY (& iter ))
681
- goto failure ;
681
+ GOTO ( typefailure ) ;
682
682
bson_iter_array (& iter , & len , & bytes );
683
683
bson_destroy (& sd -> passives );
684
684
BSON_ASSERT (bson_init_static (& sd -> passives , bytes , len ));
685
685
} else if (strcmp ("arbiters" , bson_iter_key (& iter )) == 0 ) {
686
686
if (!BSON_ITER_HOLDS_ARRAY (& iter ))
687
- goto failure ;
687
+ GOTO ( typefailure ) ;
688
688
bson_iter_array (& iter , & len , & bytes );
689
689
bson_destroy (& sd -> arbiters );
690
690
BSON_ASSERT (bson_init_static (& sd -> arbiters , bytes , len ));
691
691
} else if (strcmp ("primary" , bson_iter_key (& iter )) == 0 ) {
692
692
if (!BSON_ITER_HOLDS_UTF8 (& iter ))
693
- goto failure ;
693
+ GOTO ( typefailure ) ;
694
694
sd -> current_primary = bson_iter_utf8 (& iter , NULL );
695
695
} else if (strcmp ("arbiterOnly" , bson_iter_key (& iter )) == 0 ) {
696
696
if (!BSON_ITER_HOLDS_BOOL (& iter ))
697
- goto failure ;
697
+ GOTO ( typefailure ) ;
698
698
is_arbiter = bson_iter_bool (& iter );
699
699
} else if (strcmp ("isreplicaset" , bson_iter_key (& iter )) == 0 ) {
700
700
if (!BSON_ITER_HOLDS_BOOL (& iter ))
701
- goto failure ;
701
+ GOTO ( typefailure ) ;
702
702
is_replicaset = bson_iter_bool (& iter );
703
703
} else if (strcmp ("tags" , bson_iter_key (& iter )) == 0 ) {
704
704
if (!BSON_ITER_HOLDS_DOCUMENT (& iter ))
705
- goto failure ;
705
+ GOTO ( typefailure ) ;
706
706
bson_iter_document (& iter , & len , & bytes );
707
707
bson_destroy (& sd -> tags );
708
708
BSON_ASSERT (bson_init_static (& sd -> tags , bytes , len ));
@@ -713,21 +713,21 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
713
713
!bson_iter_recurse (& iter , & child ) ||
714
714
!bson_iter_find (& child , "lastWriteDate" ) ||
715
715
!BSON_ITER_HOLDS_DATE_TIME (& child )) {
716
- goto failure ;
716
+ GOTO ( typefailure ) ;
717
717
}
718
718
719
719
sd -> last_write_date_ms = bson_iter_date_time (& child );
720
720
} else if (strcmp ("compression" , bson_iter_key (& iter )) == 0 ) {
721
721
if (!BSON_ITER_HOLDS_ARRAY (& iter ))
722
- goto failure ;
722
+ GOTO ( typefailure ) ;
723
723
bson_iter_array (& iter , & len , & bytes );
724
724
bson_destroy (& sd -> compressors );
725
725
BSON_ASSERT (bson_init_static (& sd -> compressors , bytes , len ));
726
726
} else if (strcmp ("topologyVersion" , bson_iter_key (& iter )) == 0 ) {
727
727
bson_t incoming_topology_version ;
728
728
729
729
if (!BSON_ITER_HOLDS_DOCUMENT (& iter )) {
730
- goto failure ;
730
+ GOTO ( typefailure ) ;
731
731
}
732
732
733
733
bson_iter_document (& iter , & len , & bytes );
@@ -737,11 +737,11 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
737
737
bson_destroy (& incoming_topology_version );
738
738
} else if (strcmp ("serviceId" , bson_iter_key (& iter )) == 0 ) {
739
739
if (!BSON_ITER_HOLDS_OID (& iter ))
740
- goto failure ;
740
+ GOTO ( typefailure ) ;
741
741
bson_oid_copy_unsafe (bson_iter_oid (& iter ), & sd -> service_id );
742
742
} else if (strcmp ("connectionId" , bson_iter_key (& iter )) == 0 ) {
743
743
if (!BSON_ITER_HOLDS_INT (& iter ))
744
- goto failure ;
744
+ GOTO ( typefailure ) ;
745
745
sd -> server_connection_id = bson_iter_as_int64 (& iter );
746
746
}
747
747
}
@@ -787,7 +787,14 @@ mongoc_server_description_handle_hello (mongoc_server_description_t *sd,
787
787
788
788
EXIT ;
789
789
790
- failure :
790
+ typefailure :
791
+ bson_set_error (& sd -> error ,
792
+ MONGOC_ERROR_STREAM ,
793
+ MONGOC_ERROR_STREAM_INVALID_TYPE ,
794
+ "unexpected type %s for field %s in hello response" ,
795
+ _mongoc_bson_type_to_str (bson_iter_type (& iter )),
796
+ bson_iter_key (& iter ));
797
+ authfailure :
791
798
sd -> type = MONGOC_SERVER_UNKNOWN ;
792
799
sd -> round_trip_time_msec = MONGOC_RTT_UNSET ;
793
800
0 commit comments