Commit 70bc90cc authored by jehan's avatar jehan

fix refresher for subscribes uses

parent 40c9a6c6
......@@ -716,7 +716,7 @@ int belle_sip_dialog_handle_ack(belle_sip_dialog_t *obj, belle_sip_request_t *ac
/*
belle_sip_response_t
*/
belle_sip_hop_t * belle_sip_response_get_return_hop(belle_sip_response_t *msg);
belle_sip_hop_t* belle_sip_response_get_return_hop(belle_sip_response_t *msg);
#define IS_TOKEN(token) \
(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token)))->chars ?\
......
......@@ -394,7 +394,7 @@ void belle_sip_main_loop_iterate(belle_sip_main_loop_t *ml){
if (revents!=0 || (s->timeout>=0 && cur>=s->expire_ms)){
char *objdesc=belle_sip_object_to_string((belle_sip_object_t*)s);
s->expired=TRUE;
if (s->timeout>0)/*to avoid too many traces*/ belle_sip_message("source %s notified revents=%u, timeout=%i",objdesc,revents,s->timeout);
if (s->timeout>0)/*to avoid too many traces*/ belle_sip_debug("source %s notified revents=%u, timeout=%i",objdesc,revents,s->timeout);
belle_sip_free(objdesc);
ret=s->notify(s->data,revents);
if (ret==BELLE_SIP_STOP || s->oneshot){
......
......@@ -449,6 +449,21 @@ belle_sip_request_t *belle_sip_dialog_create_ack(belle_sip_dialog_t *obj, unsign
return NULL;
}
ack=belle_sip_dialog_create_request(obj,"ACK");
/*
22 Usage of HTTP Authentication
22.1 Framework
While a server can legitimately challenge most SIP requests, there
are two requests defined by this document that require special
handling for authentication: ACK and CANCEL.
Under an authentication scheme that uses responses to carry values
used to compute nonces (such as Digest), some problems come up for
any requests that take no response, including ACK. For this reason,
any credentials in the INVITE that were accepted by a server MUST be
accepted by that server for the ACK. UACs creating an ACK message
will duplicate all of the Authorization and Proxy-Authorization
header field values that appeared in the INVITE to which the ACK
corresponds. Servers MUST NOT attempt to challenge an ACK.
*/
if (ack){
const belle_sip_list_t *aut=belle_sip_message_get_headers((belle_sip_message_t*)obj->last_out_invite,"Authorization");
const belle_sip_list_t *prx_aut=belle_sip_message_get_headers((belle_sip_message_t*)obj->last_out_invite,"Proxy-Authorization");
......
......@@ -551,19 +551,13 @@ void belle_sip_response_fill_for_dialog(belle_sip_response_t *obj, belle_sip_req
}
}
belle_sip_hop_t * belle_sip_response_get_return_hop(belle_sip_response_t *msg){
belle_sip_hop_t* belle_sip_response_get_return_hop(belle_sip_response_t *msg){
belle_sip_header_via_t *via=BELLE_SIP_HEADER_VIA(belle_sip_message_get_header(BELLE_SIP_MESSAGE(msg),"via"));
const char *host;
const char *transport;
int port;
transport=belle_sip_strdup(belle_sip_header_via_get_transport_lowercase(via));
host=belle_sip_header_via_get_received(via);
if (host==NULL)
host=belle_sip_header_via_get_host(via);
port=belle_sip_header_via_get_rport(via);
if (port==-1)
port=belle_sip_header_via_get_listening_port(via);
return belle_sip_hop_new(transport,host,port);
const char *host=belle_sip_header_via_get_received(via)?belle_sip_header_via_get_received(via):belle_sip_header_via_get_received(via);
int port=belle_sip_header_via_get_rport(via)>0?belle_sip_header_via_get_rport(via):belle_sip_header_via_get_listening_port(via);
belle_sip_hop_t* hop=belle_sip_hop_new(belle_sip_header_via_get_transport_lowercase(via),host,port);
return hop;
}
int belle_sip_response_fix_contact(const belle_sip_response_t* response,belle_sip_header_contact_t* contact) {
......
......@@ -58,7 +58,7 @@ static void belle_sip_authorization_destroy(authorization_context_t* object) {
static void belle_sip_provider_uninit(belle_sip_provider_t *p){
p->listeners=belle_sip_list_free(p->listeners);
p->listeners=belle_sip_list_free(p->internal_listeners);
p->internal_listeners=belle_sip_list_free(p->internal_listeners);
p->client_transactions=belle_sip_list_free_with_data(p->client_transactions,belle_sip_object_unref);
p->server_transactions=belle_sip_list_free_with_data(p->server_transactions,belle_sip_object_unref);
p->auth_contexts=belle_sip_list_free_with_data(p->auth_contexts,(void(*)(void*))belle_sip_authorization_destroy);
......@@ -506,7 +506,7 @@ void belle_sip_provider_send_request(belle_sip_provider_t *p, belle_sip_request_
}
void belle_sip_provider_send_response(belle_sip_provider_t *p, belle_sip_response_t *resp){
belle_sip_hop_t *hop;
belle_sip_hop_t* hop;
belle_sip_channel_t *chan;
belle_sip_header_to_t *to=(belle_sip_header_to_t*)belle_sip_message_get_header((belle_sip_message_t*)resp,"to");
......@@ -518,6 +518,7 @@ void belle_sip_provider_send_response(belle_sip_provider_t *p, belle_sip_respons
hop=belle_sip_response_get_return_hop(resp);
chan=belle_sip_provider_get_channel(p,hop->host, hop->port, hop->transport);
if (chan) belle_sip_channel_queue_message(chan,BELLE_SIP_MESSAGE(resp));
belle_sip_object_unref(hop);
}
......@@ -722,6 +723,27 @@ int belle_sip_provider_add_authorization(belle_sip_provider_t *p, belle_sip_requ
return-1;
}
request_method=belle_sip_request_get_method(request);
/*22 Usage of HTTP Authentication
22.1 Framework
While a server can legitimately challenge most SIP requests, there
are two requests defined by this document that require special
handling for authentication: ACK and CANCEL.
Under an authentication scheme that uses responses to carry values
used to compute nonces (such as Digest), some problems come up for
any requests that take no response, including ACK. For this reason,
any credentials in the INVITE that were accepted by a server MUST be
accepted by that server for the ACK. UACs creating an ACK message
will duplicate all of the Authorization and Proxy-Authorization
header field values that appeared in the INVITE to which the ACK
corresponds. Servers MUST NOT attempt to challenge an ACK.
Although the CANCEL method does take a response (a 2xx), servers MUST
NOT attempt to challenge CANCEL requests since these requests cannot
be resubmitted. Generally, a CANCEL request SHOULD be accepted by a
server if it comes from the same hop that sent the request being
canceled (provided that some sort of transport or network layer
security association, as described in Section 26.2.1, is in place).
*/
if (strcmp("CANCEL",request_method)==0 || strcmp("ACK",request_method)==0) {
belle_sip_debug("no authorization header needed for method [%s]",request_method);
......
......@@ -45,7 +45,7 @@ static void process_io_error(void *user_ctx, const belle_sip_io_error_event_t *e
/*first stop timer if any*/
belle_sip_refresher_stop(refresher);
refresher->listener(refresher,refresher->user_data,503, "io error");
if (refresher->listener) refresher->listener(refresher,refresher->user_data,503, "io error");
return;
} else if (belle_sip_object_is_instance_of(BELLE_SIP_OBJECT(belle_sip_io_error_event_get_source(event)),BELLE_SIP_TYPE_ID(belle_sip_provider_t))) {
/*something went wrong on this provider, checking if my channel is still up*/
......@@ -59,7 +59,7 @@ static void process_io_error(void *user_ctx, const belle_sip_io_error_event_t *e
,refresher->transaction->base.channel
,belle_sip_channel_state_to_string(belle_sip_channel_get_state(refresher->transaction->base.channel)));
belle_sip_refresher_stop(refresher);
refresher->listener(refresher,refresher->user_data,503, "io error");
if (refresher->listener) refresher->listener(refresher,refresher->user_data,503, "io error");
}
return;
}else {
......@@ -108,7 +108,7 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even
default:
break;
}
refresher->listener(refresher,refresher->user_data,response_code, belle_sip_response_get_reason_phrase(response));
if (refresher->listener) refresher->listener(refresher,refresher->user_data,response_code, belle_sip_response_get_reason_phrase(response));
}
static void process_timeout(void *user_ctx, const belle_sip_timeout_event_t *event) {
......@@ -120,7 +120,7 @@ static void process_timeout(void *user_ctx, const belle_sip_timeout_event_t *eve
/*first stop timer if any*/
belle_sip_refresher_stop(refresher);
refresher->listener(refresher,refresher->user_data,408, "timeout");
if (refresher->listener) refresher->listener(refresher,refresher->user_data,408, "timeout");
return;
}
static void process_transaction_terminated(void *user_ctx, const belle_sip_transaction_terminated_event_t *event) {
......@@ -144,6 +144,7 @@ void belle_sip_refresher_set_listener(belle_sip_refresher_t* refresher, belle_si
int belle_sip_refresher_refresh(belle_sip_refresher_t* refresher,int expires) {
belle_sip_request_t*old_request=belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(refresher->transaction));
belle_sip_response_t*old_response=belle_sip_transaction_get_response(BELLE_SIP_TRANSACTION(refresher->transaction));
belle_sip_dialog_t* dialog = belle_sip_transaction_get_dialog(BELLE_SIP_TRANSACTION(refresher->transaction));
belle_sip_client_transaction_t* client_transaction;
belle_sip_request_t* request;
......@@ -168,7 +169,7 @@ int belle_sip_refresher_refresh(belle_sip_refresher_t* refresher,int expires) {
}
belle_sip_provider_add_authorization(prov,request,NULL,NULL);
belle_sip_provider_add_authorization(prov,request,old_response,NULL);
} else {
belle_sip_error("Unexpected dialog state [%s] for dialog [%p], cannot refresh [%s]"
,belle_sip_dialog_state_to_string(belle_sip_dialog_get_state(dialog))
......
......@@ -149,10 +149,10 @@ void belle_sip_server_transaction_send_response(belle_sip_server_transaction_t *
belle_sip_object_ref(resp);
if (!base->last_response){
belle_sip_hop_t *hop;
hop=belle_sip_response_get_return_hop(resp);
belle_sip_hop_t* hop=belle_sip_response_get_return_hop(resp);
base->channel=belle_sip_provider_get_channel(base->provider,hop->host, hop->port, hop->transport);
belle_sip_object_ref(base->channel);
belle_sip_object_unref(hop);
}
status_code=belle_sip_response_get_status_code(resp);
if (status_code!=100){
......
......@@ -126,8 +126,8 @@ static int on_udp_data(belle_sip_udp_listening_point_t *lp, unsigned int events)
}
if (chan){
/*notify the channel*/
belle_sip_debug("Notifying udp channel, local [%s:%i] remote [%s:%i]",
chan->local_ip,
belle_sip_debug("Notifying udp channel, local [%s:%i] remote [%s:%i]"
,chan->local_ip
,chan->local_port
,chan->peer_name
,chan->peer_port);
......
......@@ -346,16 +346,29 @@ static void simple_call_with_delay(void){
do_simple_call();
belle_sip_stack_set_tx_delay(stack,0);
}
/*static void simple_call_udp_tcp_with_delay(void){
belle_sip_listening_point_t* lp=belle_sip_provider_get_listening_point(prov,"tls");
belle_sip_object_ref(lp);
belle_sip_stack_set_tx_delay(stack,2000);
belle_sip_provider_remove_listening_point(prov,lp);
do_simple_call();
belle_sip_stack_set_tx_delay(stack,0);
belle_sip_provider_add_listening_point(prov,lp);
belle_sip_object_unref(lp);
}*/
int belle_sip_dialog_test_suite(){
CU_pSuite pSuite = CU_add_suite("Dialog", init, uninit);
if (NULL == CU_add_test(pSuite, "simple-call", simple_call)) {
if (NULL == CU_add_test(pSuite, "simple_call", simple_call)) {
return CU_get_error();
}
if (NULL == CU_add_test(pSuite, "simple-call-with-delay", simple_call_with_delay)) {
if (NULL == CU_add_test(pSuite, "simple_call_with_delay", simple_call_with_delay)) {
return CU_get_error();
}
/* if (NULL == CU_add_test(pSuite, "simple_call_udp_tcp_with_delay", simple_call_udp_tcp_with_delay)) {
return CU_get_error();
}*/
return 0;
}
......@@ -100,7 +100,7 @@ static void compute_response_auth_qop(const char* username
belle_sip_auth_helper_compute_ha2(method,uri,ha2);
belle_sip_auth_helper_compute_response_qop_auth(ha1, nonce,nonce_count, cnonce,qop,ha2,response);
}
#define MAX_NC_COUNT 3
static void server_process_request_event(void *obj, const belle_sip_request_event_t *event){
endpoint_t* endpoint = (endpoint_t*)obj;
belle_sip_server_transaction_t* server_transaction =belle_sip_provider_create_server_transaction(endpoint->provider,belle_sip_request_event_get_request(event));
......@@ -156,17 +156,23 @@ static void server_process_request_event(void *obj, const belle_sip_request_even
belle_sip_free((void*)auth_uri);
auth_ok=strcmp(belle_sip_header_authorization_get_response(authorization),local_resp)==0;
}
if (auth_ok) {
if (endpoint->auth == digest) {
sprintf(endpoint->nonce,"%p",authorization); //*change the nonce for next auth*/
if (auth_ok && endpoint->nonce_count<MAX_NC_COUNT ) {/*revoke nonce after MAX_NC_COUNT uses*/
if (endpoint->auth == digest ) {
sprintf(endpoint->nonce,"%p",authorization); //*change the nonce for next auth*/
} else {
endpoint->nonce_count++;
}
} else {
auth_ok=0;
www_authenticate=belle_sip_header_www_authenticate_parse(raw_authenticate_digest);
sprintf(endpoint->nonce,"%p",authorization); //*change the nonce for next auth*/
belle_sip_header_www_authenticate_set_nonce(www_authenticate,endpoint->nonce);
if (endpoint->auth == digest_auth) {
belle_sip_header_www_authenticate_add_qop(www_authenticate,"auth");
if (endpoint->nonce_count>=MAX_NC_COUNT) {
belle_sip_header_www_authenticate_set_stale(www_authenticate,1);
endpoint->nonce_count=1;
}
}
}
}
......
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