@@ -47,6 +47,26 @@ int imc_send_message(str *src, str *dst, str *headers, str *body);
4747int imc_room_broadcast (imc_room_p room , str * ctype , str * body );
4848void imc_inv_callback ( struct cell * t , int type , struct tmcb_params * ps );
4949
50+ static int imc_body_print_user (str * body , const char * fmt , str * user )
51+ {
52+ body -> s = imc_body_buf ;
53+ body -> len = snprintf (body -> s , IMC_BUF_SIZE , fmt , user -> len , user -> s );
54+
55+ if (body -> len < 0 )
56+ {
57+ LM_ERR ("unable to print message\n" );
58+ body -> len = 0 ;
59+ return -1 ;
60+ }
61+ if (body -> len >= IMC_BUF_SIZE )
62+ {
63+ LM_ERR ("buffer size overflow\n" );
64+ body -> len = 0 ;
65+ return -1 ;
66+ }
67+ return body -> len ;
68+ }
69+
5070/**
5171 * parse cmd
5272 */
@@ -221,10 +241,8 @@ int imc_handle_create(struct sip_msg* msg, imc_cmd_t *cmd,
221241 }
222242 LM_DBG ("added as member [%.*s]\n" ,member -> uri .len , member -> uri .s );
223243 /* send info message */
224- body .s = imc_body_buf ;
225- body .len = snprintf (body .s , IMC_BUF_SIZE ,
226- "*** <%.*s> has joined the room" ,
227- member -> uri .len , member -> uri .s );
244+ body .len = imc_body_print_user (& body ,
245+ "*** <%.*s> has joined the room" , & member -> uri );
228246 if (body .len > 0 )
229247 imc_room_broadcast (room , & imc_hdr_ctype , & body );
230248
@@ -323,9 +341,8 @@ int imc_handle_join(struct sip_msg* msg, imc_cmd_t *cmd,
323341
324342build_inform :
325343 /* send info message */
326- body .s = imc_body_buf ;
327- body .len = snprintf (body .s , IMC_BUF_SIZE , "*** <%.*s> has joined the room" ,
328- member -> uri .len , member -> uri .s );
344+ body .len = imc_body_print_user (& body , "*** <%.*s> has joined the room" ,
345+ & member -> uri );
329346 if (body .len > 0 )
330347 imc_room_broadcast (room , & imc_hdr_ctype , & body );
331348
@@ -550,9 +567,8 @@ int imc_handle_accept(struct sip_msg* msg, imc_cmd_t *cmd,
550567 member -> flags &= ~IMC_MEMBER_INVITED ;
551568
552569 /* send info message */
553- body .s = imc_body_buf ;
554- body .len = snprintf (body .s , IMC_BUF_SIZE , "*** <%.*s> has joined the room" ,
555- member -> uri .len , member -> uri .s );
570+ body .len = imc_body_print_user (& body , "*** <%.*s> has joined the room" ,
571+ & member -> uri );
556572 if (body .len > 0 )
557573 imc_room_broadcast (room , & imc_hdr_ctype , & body );
558574
@@ -690,9 +706,8 @@ int imc_handle_remove(struct sip_msg* msg, imc_cmd_t *cmd,
690706 member -> flags |= IMC_MEMBER_DELETED ;
691707 imc_del_member (room , & inv_uri .user , & inv_uri .host );
692708
693- body .s = imc_body_buf ;
694- body .len = snprintf (body .s , IMC_BUF_SIZE , "*** <%.*s> has joined the room" ,
695- member -> uri .len , member -> uri .s );
709+ body .len = imc_body_print_user (& body , "*** <%.*s> has joined the room" ,
710+ & member -> uri );
696711 if (body .len > 0 )
697712 imc_room_broadcast (room , & imc_hdr_ctype , & body );
698713
@@ -741,10 +756,8 @@ int imc_handle_deny(struct sip_msg* msg, imc_cmd_t *cmd,
741756
742757#if 0
743758 /* send info message */
744- body .s = imc_body_buf ;
745- body .len = snprintf (body .s , IMC_BUF_SIZE ,
746- "The user [%.*s] has denied the invitation" ,
747- src -> user .len , src -> user .s );
759+ body .len = imc_body_print_user (& body ,
760+ "The user [%.*s] has denied the invitation" , & src -> user );
748761 if (body .len > 0 )
749762 imc_send_message (& room -> uri , & memeber -> uri , & imc_hdr_ctype , & body );
750763#endif
@@ -923,10 +936,8 @@ int imc_handle_exit(struct sip_msg* msg, imc_cmd_t *cmd,
923936 /* delete user */
924937 member -> flags |= IMC_MEMBER_DELETED ;
925938 imc_del_member (room , & src -> user , & src -> host );
926- body .s = imc_body_buf ;
927- body .len = snprintf (body .s , IMC_BUF_SIZE ,
928- "The user [%.*s] has left the room" ,
929- src -> user .len , src -> user .s );
939+ body .len = imc_body_print_user (& body ,
940+ "The user [%.*s] has left the room" , & src -> user );
930941 if (body .len > 0 )
931942 imc_room_broadcast (room , & imc_hdr_ctype , & body );
932943 }
0 commit comments