Commit a0b22b83 authored by jehan's avatar jehan

-add a test function to unconditionally reject maessage with 488

-add max-forward to ack sent by ict
parent 6e2b7ee4
......@@ -494,6 +494,7 @@ BELLESIP_EXPORT void belle_sip_header_extension_set_value(belle_sip_header_exten
typedef struct _belle_sip_header_max_forwards belle_sip_header_max_forwards_t;
BELLESIP_EXPORT belle_sip_header_max_forwards_t* belle_sip_header_max_forwards_new();
BELLESIP_EXPORT belle_sip_header_max_forwards_t* belle_sip_header_max_forwards_create(int value);
BELLESIP_EXPORT belle_sip_header_max_forwards_t* belle_sip_header_max_forwards_parse (const char* max_forwards) ;
BELLESIP_EXPORT int belle_sip_header_max_forwards_get_max_forwards(const belle_sip_header_max_forwards_t* max_forwards);
......
......@@ -70,6 +70,14 @@ BELLESIP_EXPORT int belle_sip_provider_add_authorization(belle_sip_provider_t *p
**/
BELLESIP_EXPORT void belle_sip_provider_set_recv_error(belle_sip_provider_t *prov, int recv_error);
/**
* Can be used to unconditionally answer to incoming sip messages. By default 480 is answered.
* Can be enhanced by a new method belle_sip_provider_set_unconditional_answer to allows user to provide answer code
* @param prov
* @param enable 0 to disable
**/
BELLESIP_EXPORT void belle_sip_provider_enable_unconditional_answer(belle_sip_provider_t *prov, int enable);
/**
* Provides access to a specific dialog
* @param prov object
......
......@@ -1261,6 +1261,12 @@ GET_SET_INT(belle_sip_header_max_forwards,max_forwards,int)
int belle_sip_header_max_forwards_decrement_max_forwards(belle_sip_header_max_forwards_t* max_forwards) {
return max_forwards->max_forwards--;
}
belle_sip_header_max_forwards_t* belle_sip_header_max_forwards_create(int value) {
belle_sip_header_max_forwards_t* max_forwards=belle_sip_header_max_forwards_new();
max_forwards->max_forwards=value;
return max_forwards;
}
/**************************
* Subscription state header object inherent from parameters
****************************
......
......@@ -514,6 +514,7 @@ struct belle_sip_provider{
belle_sip_list_t *auth_contexts;
unsigned char rport_enabled; /*0 if rport should not be set in via header*/
unsigned char nat_helper;
unsigned char unconditional_answer_enabled;
};
belle_sip_provider_t *belle_sip_provider_new(belle_sip_stack_t *s, belle_sip_listening_point_t *lp);
......
......@@ -68,6 +68,7 @@ static belle_sip_request_t *make_ack(belle_sip_ict_t *obj, belle_sip_response_t
belle_sip_util_copy_headers((belle_sip_message_t*)resp,(belle_sip_message_t*)obj->ack,BELLE_SIP_TO,FALSE);
belle_sip_util_copy_headers((belle_sip_message_t*)base->request,(belle_sip_message_t*)obj->ack,BELLE_SIP_CONTACT,TRUE);
belle_sip_util_copy_headers((belle_sip_message_t*)base->request,(belle_sip_message_t*)obj->ack,BELLE_SIP_ROUTE,TRUE);
belle_sip_util_copy_headers((belle_sip_message_t*)base->request,(belle_sip_message_t*)obj->ack,BELLE_SIP_MAX_FORWARDS,FALSE);
belle_sip_message_add_header((belle_sip_message_t*)obj->ack,
(belle_sip_header_t*)belle_sip_header_cseq_create(
belle_sip_header_cseq_get_seq_number((belle_sip_header_cseq_t*)belle_sip_message_get_header((belle_sip_message_t*)base->request,BELLE_SIP_CSEQ)),
......
......@@ -109,10 +109,16 @@ static void belle_sip_provider_dispatch_request(belle_sip_provider_t* prov, bell
return;
}
}
ev.source=prov;
ev.server_transaction=NULL;
ev.request=req;
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(prov->listeners,process_request_event,&ev);
if (prov->unconditional_answer_enabled && strcmp("ACK",method)!=0) { /*always answer 480 in this case*/
belle_sip_server_transaction_t *tr=belle_sip_provider_create_server_transaction(prov,req);
belle_sip_server_transaction_send_response(tr,belle_sip_response_create_from_request(req,480));
return;
} else {
ev.source=prov;
ev.server_transaction=NULL;
ev.request=req;
BELLE_SIP_PROVIDER_INVOKE_LISTENERS(prov->listeners,process_request_event,&ev);
}
}
}
......@@ -982,4 +988,7 @@ void belle_sip_provider_enable_nat_helper(belle_sip_provider_t *prov, int enable
int belle_sip_provider_nat_helper_enabled(const belle_sip_provider_t *prov){
return prov->nat_helper;
}
void belle_sip_provider_enable_unconditional_answer(belle_sip_provider_t *prov, int enable) {
prov->unconditional_answer_enabled=enable;
}
......@@ -179,12 +179,14 @@ static void test_via_header(void) {
CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_branch(L_via),"z9hG4bK368560724");
belle_sip_object_unref(BELLE_SIP_OBJECT(L_via));
L_via = belle_sip_header_via_parse("Via: SIP/2.0/UDP 192.168.0.19:5062;rport;received=192.169.0.4;branch=z9hG4bK368560724, SIP/2.0/UDP 192.168.0.19:5062");
L_via = belle_sip_header_via_parse("Via: SIP/2.0/UDP 192.168.0.19:5062;received=192.169.0.4;rport=1234;branch=z9hG4bK368560724, SIP/2.0/UDP 192.168.0.19:5062");
l_next = belle_sip_header_get_next(BELLE_SIP_HEADER(L_via));
L_next_via = BELLE_SIP_HEADER_VIA(l_next);
CU_ASSERT_PTR_NOT_NULL(L_next_via);
CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_host(L_next_via),"192.168.0.19");
CU_ASSERT_STRING_EQUAL(belle_sip_header_via_get_received(L_via),"192.169.0.4");
CU_ASSERT_EQUAL(belle_sip_header_via_get_rport(L_via),1234);
belle_sip_object_unref(BELLE_SIP_OBJECT(L_via));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment