@@ -2728,10 +2728,7 @@ static pj_status_t pjsua_regc_init(int acc_id)
2728
2728
pjsua_perror (THIS_FILE , "Unable to generate suitable Contact header"
2729
2729
" for registration" ,
2730
2730
status );
2731
- destroy_regc (acc , PJ_TRUE );
2732
- pj_pool_release (pool );
2733
- acc -> regc = NULL ;
2734
- return status ;
2731
+ goto on_return ;
2735
2732
}
2736
2733
2737
2734
pj_strdup_with_null (acc -> pool , & acc -> contact , & tmp_contact );
@@ -2748,37 +2745,72 @@ static pj_status_t pjsua_regc_init(int acc_id)
2748
2745
pjsua_perror (THIS_FILE ,
2749
2746
"Client registration initialization error" ,
2750
2747
status );
2751
- destroy_regc (acc , PJ_TRUE );
2752
- pj_pool_release (pool );
2753
-
2754
- return status ;
2748
+ goto on_return ;
2755
2749
}
2756
2750
2757
- pjsip_regc_set_reg_tsx_cb (acc -> regc , regc_tsx_cb );
2751
+ status = pjsip_regc_set_reg_tsx_cb (acc -> regc , regc_tsx_cb );
2752
+ if (status != PJ_SUCCESS ) {
2753
+ pjsua_perror (THIS_FILE ,
2754
+ "Failed setting registration callback" ,
2755
+ status );
2756
+ goto on_return ;
2757
+ }
2758
2758
2759
2759
/* Set client registration's transport based on acc's config. */
2760
2760
pjsua_init_tpselector (acc_id , & tp_sel );
2761
- pjsip_regc_set_transport (acc -> regc , & tp_sel );
2761
+ status = pjsip_regc_set_transport (acc -> regc , & tp_sel );
2762
+ if (status != PJ_SUCCESS ) {
2763
+ pjsua_perror (THIS_FILE ,
2764
+ "Failed setting registration transport" ,
2765
+ status );
2766
+ goto on_return ;
2767
+ }
2762
2768
2763
2769
if (acc -> cfg .use_shared_auth ) {
2764
- pjsip_regc_set_auth_sess (acc -> regc , & acc -> shared_auth_sess );
2770
+ status = pjsip_regc_set_auth_sess (acc -> regc , & acc -> shared_auth_sess );
2771
+ if (status != PJ_SUCCESS ) {
2772
+ pjsua_perror (THIS_FILE ,
2773
+ "Failed setting registration shared auth session" ,
2774
+ status );
2775
+ goto on_return ;
2776
+ }
2765
2777
}
2766
2778
2767
- /* Set credentials
2768
- */
2779
+ /* Set credentials */
2769
2780
if (acc -> cred_cnt ) {
2770
- pjsip_regc_set_credentials ( acc -> regc , acc -> cred_cnt , acc -> cred );
2781
+ status = pjsip_regc_set_credentials (acc -> regc , acc -> cred_cnt ,
2782
+ acc -> cred );
2783
+ if (status != PJ_SUCCESS ) {
2784
+ pjsua_perror (THIS_FILE ,
2785
+ "Failed setting credentials for registration" ,
2786
+ status );
2787
+ goto on_return ;
2788
+ }
2771
2789
}
2772
2790
2773
2791
/* Set delay before registration refresh */
2774
- pjsip_regc_set_delay_before_refresh (acc -> regc ,
2792
+ status = pjsip_regc_set_delay_before_refresh (
2793
+ acc -> regc ,
2775
2794
acc -> cfg .reg_delay_before_refresh );
2795
+ if (status != PJ_SUCCESS ) {
2796
+ /* Maybe too big, it will fallback to the default setting,
2797
+ * just print warning.
2798
+ */
2799
+ pjsua_perror (THIS_FILE ,
2800
+ "Warning: failed setting registration refresh delay" ,
2801
+ status );
2802
+ }
2776
2803
2777
2804
/* Set authentication preference */
2778
- pjsip_regc_set_prefs (acc -> regc , & acc -> cfg .auth_pref );
2805
+ status = pjsip_regc_set_prefs (acc -> regc , & acc -> cfg .auth_pref );
2806
+ if (status != PJ_SUCCESS ) {
2807
+ pjsua_perror (THIS_FILE ,
2808
+ "Failed setting registration auth preference" ,
2809
+ status );
2810
+ goto on_return ;
2811
+ }
2779
2812
2780
- /* Set route-set
2781
- */
2813
+ /* Set route-set */
2782
2814
if (acc -> cfg .reg_use_proxy ) {
2783
2815
pjsip_route_hdr route_set ;
2784
2816
const pjsip_route_hdr * r ;
@@ -2807,12 +2839,25 @@ static pj_status_t pjsua_regc_init(int acc_id)
2807
2839
}
2808
2840
}
2809
2841
2810
- if (!pj_list_empty (& route_set ))
2811
- pjsip_regc_set_route_set ( acc -> regc , & route_set );
2842
+ if (!pj_list_empty (& route_set )) {
2843
+ status = pjsip_regc_set_route_set ( acc -> regc , & route_set );
2844
+ if (status != PJ_SUCCESS ) {
2845
+ pjsua_perror (THIS_FILE ,
2846
+ "Failed setting registration route set" ,
2847
+ status );
2848
+ goto on_return ;
2849
+ }
2850
+ }
2812
2851
}
2813
2852
2814
2853
/* Add custom request headers specified in the account config */
2815
- pjsip_regc_add_headers (acc -> regc , & acc -> cfg .reg_hdr_list );
2854
+ status = pjsip_regc_add_headers (acc -> regc , & acc -> cfg .reg_hdr_list );
2855
+ if (status != PJ_SUCCESS ) {
2856
+ pjsua_perror (THIS_FILE ,
2857
+ "Failed setting registration custom headers" ,
2858
+ status );
2859
+ goto on_return ;
2860
+ }
2816
2861
2817
2862
/* Add other request headers. */
2818
2863
if (pjsua_var .ua_cfg .user_agent .slen ) {
@@ -2826,7 +2871,15 @@ static pj_status_t pjsua_regc_init(int acc_id)
2826
2871
& pjsua_var .ua_cfg .user_agent );
2827
2872
pj_list_push_back (& hdr_list , (pjsip_hdr * )h );
2828
2873
2829
- pjsip_regc_add_headers (acc -> regc , & hdr_list );
2874
+ status = pjsip_regc_add_headers (acc -> regc , & hdr_list );
2875
+ if (status != PJ_SUCCESS ) {
2876
+ /* Informational header, just print warning */
2877
+ pjsua_perror (THIS_FILE ,
2878
+ "Warning: failed setting registration "
2879
+ "user-agent header" ,
2880
+ status );
2881
+ status = PJ_SUCCESS ;
2882
+ }
2830
2883
}
2831
2884
2832
2885
/* If SIP outbound is used, add "Supported: outbound, path header" */
@@ -2844,12 +2897,26 @@ static pj_status_t pjsua_regc_init(int acc_id)
2844
2897
hsup -> values [0 ] = pj_str ("outbound" );
2845
2898
hsup -> values [1 ] = pj_str ("path" );
2846
2899
2847
- pjsip_regc_add_headers (acc -> regc , & hdr_list );
2900
+ status = pjsip_regc_add_headers (acc -> regc , & hdr_list );
2901
+ if (status != PJ_SUCCESS ) {
2902
+ pjsua_perror (THIS_FILE ,
2903
+ "Failed setting registration outbound support "
2904
+ "indication" ,
2905
+ status );
2906
+ goto on_return ;
2907
+ }
2848
2908
}
2849
2909
2850
- pj_pool_release (pool );
2910
+ on_return :
2911
+ if (status != PJ_SUCCESS ) {
2912
+ if (acc -> regc )
2913
+ destroy_regc (acc , PJ_TRUE );
2851
2914
2852
- return PJ_SUCCESS ;
2915
+ pjsua_perror (THIS_FILE , "Error initializing client registration" ,
2916
+ status );
2917
+ }
2918
+ pj_pool_release (pool );
2919
+ return status ;
2853
2920
}
2854
2921
2855
2922
pj_bool_t pjsua_sip_acc_is_using_ipv6 (pjsua_acc_id acc_id )
0 commit comments