Jelajahi Sumber

*** empty log message ***

Bogdan-Andrei Iancu 24 tahun lalu
induk
melakukan
b644f03169
2 mengubah file dengan 53 tambahan dan 5 penghapusan
  1. 4 4
      modules/tm/t_funcs.c
  2. 49 1
      msg_translator.c

+ 4 - 4
modules/tm/t_funcs.c

@@ -272,7 +272,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
    T->outbound_request[branch]->timeout         = RETR_T1;
    /* send the request */
    udp_send( T->outbound_request[branch]->buffer , T->outbound_request[branch]->bufflen , 
-		&(T->outbound_request[branch]->to) , sizeof(struct sockaddr_in) );
+		(struct sockaddr*)&(T->outbound_request[branch]->to) , sizeof(struct sockaddr_in) );
 }
 
 
@@ -506,19 +506,19 @@ int t_reply_matching( struct s_table *hash_table , struct sip_msg *p_msg , struc
    /* getting the hash_index from the brach param , via header*/
    begin = p_msg->via1->branch->value.s;
    for(  ; *begin!='.' ; begin++ );
-   hash_index = strtol( ++begin , &end , 10 );
+   hash_index = strtol( ++begin , &end , 16 );
    /*if the hash index is corect */
    if  ( *end=='.' && hash_index>=0 && hash_index<TABLE_ENTRIES-1 )
    {
       /* getting the entry label value */
       begin=end++ ;
-      entry_label = strtol( ++begin , &end , 10 );
+      entry_label = strtol( ++begin , &end , 16 );
       /* if the entry label also is corect */
       if  ( *end=='.' && entry_label>=0 )
       {
          /* getting the branch_id value */
          begin=end++ ;
-         branch_id = strtol( ++begin , &end , 10 );
+         branch_id = strtol( ++begin , &end , 16 );
          /* if the entry label also is corect */
           if  ( branch_id>=0 )
           {

+ 49 - 1
msg_translator.c

@@ -503,8 +503,56 @@ error:
 
 
 
-char * build_res_buf_from_sip_req(struct sip_msg* msg, unsigned int *returned_len)
+char * build_res_buf_from_sip_req(unsigned int code , char *text , struct sip_msg* msg, unsigned int *returned_len)
 {
+	char                    *buf=0, *p;
+	unsigned int       len,foo,i;
+	struct hdr_field  *hdr;
+
+	/*computes the lenght of the new response buffer*/
+	len = 0;
+	/* first line */
+	len += 3/*code*/ + 1/*space*/ + strlen(text) + 1/*new line*/;
+	/*headers that will be copied (TO, FROM, CSEQ,CALLID,VIA)*/
+	for ( hdr=msg->headers ; hdr ; hdr=hdr->next )
+		if ( hdr->type==HDR_VIA || hdr->type==HDR_FROM || hdr->type==HDR_CALLID || hdr->type==HDR_TO || hdr->type==HDR_CSEQ )
+			len += ((hdr->body.s+hdr->body.len ) - hdr->name.s ) +1;
+	/* end of message */
+	len += 1; /*new line*/
+
+	/*allocating mem*/
+	buf = (char*) malloc( len );
+	if (!buf)
+	{
+		LOG(L_ERR, "ERROR: build_res_buf_from_sip_req: out of memory\n");
+		goto error;
+	}
+
+	/* filling the buffer*/
+	/* first line */
+	for ( i=2 , foo = code  ;  i>=0  ;  i-- , foo=foo/10 )
+		*(p+i) = '0' + foo - ( foo/10 )*10;
+	p += 3;
+	*(p++) = ' ' ;
+	memcpy( p , text , strlen(text) );
+	p += strlen(text);
+	*(p++) = '\n';
+	/* headers*/
+	for ( hdr=msg->headers ; hdr ; hdr=hdr->next )
+		if ( hdr->type==HDR_VIA || hdr->type==HDR_FROM || hdr->type==HDR_CALLID || hdr->type==HDR_TO || hdr->type==HDR_CSEQ )
+		{
+			memcpy( p , hdr->name.s ,  ((hdr->body.s+hdr->body.len ) - hdr->name.s ) );
+			len += ((hdr->body.s+hdr->body.len ) - hdr->name.s );
+			*(p++) = '\n';
+		}
+
+	*(p++) = '\n';
+	*returned_len=len;
+	return buf;
+error:
+	if (buf) free(buf);
+	*returned_len=0;
+	return 0;
 }