@@ -703,19 +703,38 @@ start_base_connect()
703
703
bufferevent_setcb (main_ctl -> connect_bev , recv_cb , NULL , connect_event_cb , NULL );
704
704
}
705
705
706
- void
707
- login ()
708
- {
709
- char * lg_msg = NULL ;
710
- int len = login_request_marshal (& lg_msg ); //marshal login request
711
- if ( !lg_msg ) {
712
- debug (LOG_ERR ,
713
- "error: login_request_marshal failed, it should never be happenned" );
714
- exit (0 );
706
+ static int prepare_login_message (char * * msg_out , int * len_out ) {
707
+ if (!msg_out || !len_out ) {
708
+ debug (LOG_ERR , "Invalid output parameters" );
709
+ return -1 ;
715
710
}
716
-
717
- send_msg_frp_server (NULL , TypeLogin , lg_msg , len , & main_ctl -> stream );
718
- SAFE_FREE (lg_msg );
711
+
712
+ int msg_len = login_request_marshal (msg_out );
713
+ if (msg_len <= 0 || !* msg_out ) {
714
+ debug (LOG_ERR , "Failed to marshal login request" );
715
+ return -1 ;
716
+ }
717
+
718
+ * len_out = msg_len ;
719
+ return 0 ;
720
+ }
721
+
722
+ void login (void ) {
723
+ char * login_msg = NULL ;
724
+ int msg_len = 0 ;
725
+
726
+ // Prepare login message
727
+ if (prepare_login_message (& login_msg , & msg_len ) != 0 ) {
728
+ debug (LOG_ERR , "Failed to prepare login message" );
729
+ exit (1 );
730
+ }
731
+
732
+ // Send login request
733
+ debug (LOG_DEBUG , "Sending login request: length=%d" , msg_len );
734
+ send_msg_frp_server (NULL , TypeLogin , login_msg , msg_len , & main_ctl -> stream );
735
+
736
+ // Cleanup
737
+ SAFE_FREE (login_msg );
719
738
}
720
739
721
740
static int prepare_message (const enum msg_type type ,
0 commit comments