static void cast_test(void) { belle_sip_stack_t *stack=belle_sip_stack_new(NULL); belle_sip_listening_point_t *lp=belle_sip_stack_create_listening_point(stack,"0.0.0.0",7060,"UDP"); belle_sip_provider_t *provider; belle_sip_request_t *req=belle_sip_request_new(); belle_sip_response_t *resp=belle_sip_response_new(); belle_sip_message_t *msg; int tmp; BC_ASSERT_PTR_NOT_NULL(stack); BC_ASSERT_PTR_NOT_NULL(lp); provider=belle_sip_stack_create_provider(stack,lp); BC_ASSERT_PTR_NOT_NULL(provider); BC_ASSERT_PTR_NOT_NULL(req); BC_ASSERT_PTR_NOT_NULL(resp); belle_sip_message("Casting belle_sip_request_t to belle_sip_message_t"); msg=BELLE_SIP_MESSAGE(req); BC_ASSERT_PTR_NOT_NULL(msg); belle_sip_message("Ok."); belle_sip_message("Casting belle_sip_response_t to belle_sip_message_t"); msg=BELLE_SIP_MESSAGE(resp); BC_ASSERT_PTR_NOT_NULL(msg); belle_sip_message("Ok."); tmp=BELLE_SIP_IS_INSTANCE_OF(req,belle_sip_response_t); belle_sip_message("Casting belle_sip_request_t to belle_sip_response_t: %s",tmp ? "yes" : "no"); BC_ASSERT_EQUAL(tmp,0,int,"%d"); belle_sip_object_unref(req); belle_sip_object_unref(resp); belle_sip_object_unref(provider); belle_sip_object_unref(stack); }
static int channel_on_auth_requested(belle_sip_channel_listener_t *obj, belle_sip_channel_t *chan, const char* distinguished_name){ belle_http_channel_context_t *ctx=BELLE_HTTP_CHANNEL_CONTEXT(obj); if (BELLE_SIP_IS_INSTANCE_OF(chan,belle_sip_tls_channel_t)) { belle_sip_auth_event_t* auth_event = belle_sip_auth_event_create((belle_sip_object_t*)ctx->provider,NULL,NULL); belle_sip_tls_channel_t *tls_chan=BELLE_SIP_TLS_CHANNEL(chan); belle_http_request_t *req=(belle_http_request_t*)chan->outgoing_messages->data; auth_event->mode=BELLE_SIP_AUTH_MODE_TLS; belle_sip_auth_event_set_distinguished_name(auth_event,distinguished_name); BELLE_HTTP_REQUEST_INVOKE_LISTENER(req,process_auth_requested,auth_event); belle_sip_tls_channel_set_client_certificates_chain(tls_chan,auth_event->cert); belle_sip_tls_channel_set_client_certificate_key(tls_chan,auth_event->key); belle_sip_auth_event_destroy(auth_event); } return 0; }
static void testHttp200Ok(void) { const char* raw_message = "HTTP/1.1 200 OK\r\n" "Date: Tue, 07 Jan 2014 09:28:43 GMT\r\n" "Server: Apache\r\n" "Last-Modified: Tue, 18 Aug 1998 20:19:11 GMT\r\n" "ETag: \"8982a60-14a17-335b3dcdcadc0\"\r\n" "Accept-Ranges: bytes\r\n" "Vary: Accept-Encoding\r\n" "Content-Encoding: gzip\r\n" "Content-Length: 6\r\n" "Keep-Alive: timeout=15, max=100\r\n" "Connection: Keep-Alive\r\n" "Content-Type: text/plain\r\n" "\r\n" "blabla"; char* marshaled_msg; belle_sip_message_t* msg = belle_sip_message_parse(raw_message); belle_http_response_t* http_response; belle_sip_header_extension_t* host_header; belle_sip_object_t* tmp; CU_ASSERT_PTR_NOT_NULL_FATAL(msg); marshaled_msg=belle_sip_object_to_string(BELLE_SIP_OBJECT(msg)); belle_sip_object_unref(msg); msg = belle_sip_message_parse(marshaled_msg); belle_sip_free(marshaled_msg); tmp=belle_sip_object_clone(BELLE_SIP_OBJECT(msg)); belle_sip_object_unref(msg); msg=BELLE_SIP_MESSAGE(tmp); CU_ASSERT_TRUE(BELLE_SIP_IS_INSTANCE_OF(msg,belle_http_response_t)); http_response=BELLE_HTTP_RESPONSE(msg); CU_ASSERT_EQUAL(belle_http_response_get_status_code(http_response),200); CU_ASSERT_STRING_EQUAL(belle_http_response_get_reason_phrase(http_response),"OK"); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"Date")); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"ETag")); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"Connection")); CU_ASSERT_PTR_NOT_NULL(host_header=BELLE_SIP_HEADER_EXTENSION(belle_sip_message_get_header(msg,"Server"))); CU_ASSERT_STRING_EQUAL(belle_sip_header_extension_get_value(host_header),"Apache"); belle_sip_object_unref(msg); }
static void testHttpGet(void) { const char* raw_message = "GET /index.php HTTP/1.1\r\n" "User-Agent: Wget/1.14 (darwin11.4.2)\r\n" "Accept: */*\r\n" "Host: www.linphone.org\r\n" "Connection: Keep-Alive\r\n" "\r\n"; char* marshaled_msg; belle_sip_message_t* msg = belle_sip_message_parse(raw_message); belle_http_request_t* http_request; belle_generic_uri_t* uri; belle_sip_header_extension_t* host_header; belle_sip_object_t* tmp; CU_ASSERT_PTR_NOT_NULL_FATAL(msg); marshaled_msg=belle_sip_object_to_string(BELLE_SIP_OBJECT(msg)); belle_sip_object_unref(msg); msg = belle_sip_message_parse(marshaled_msg); belle_sip_free(marshaled_msg); tmp=belle_sip_object_clone(BELLE_SIP_OBJECT(msg)); belle_sip_object_unref(msg); msg=BELLE_SIP_MESSAGE(tmp); CU_ASSERT_TRUE(BELLE_SIP_IS_INSTANCE_OF(msg,belle_http_request_t)); http_request=BELLE_HTTP_REQUEST(msg); CU_ASSERT_PTR_NOT_NULL_FATAL(uri=belle_http_request_get_uri(http_request)); CU_ASSERT_STRING_EQUAL(belle_generic_uri_get_path(uri),"/index.php"); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"User-Agent")); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"Accept")); CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(msg,"Connection")); CU_ASSERT_PTR_NOT_NULL(host_header=BELLE_SIP_HEADER_EXTENSION(belle_sip_message_get_header(msg,"Host"))); CU_ASSERT_STRING_EQUAL(belle_sip_header_extension_get_value(host_header),"www.linphone.org"); belle_sip_object_unref(msg); }
int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* authorization ,const char* method ,const char* ha1) { int auth_mode=0; char* uri; char ha2[16*2 + 1]; char response[16*2 + 1]; char cnonce[9]; response[32]=ha2[32]='\0'; if (belle_sip_header_authorization_get_scheme(authorization) != NULL && strcmp("Digest",belle_sip_header_authorization_get_scheme(authorization))!=0) { belle_sip_error("belle_sip_fill_authorization_header, unsupported schema [%s]" ,belle_sip_header_authorization_get_scheme(authorization)); return -1; } if (belle_sip_header_authorization_get_qop(authorization) && !(auth_mode=strcmp("auth",belle_sip_header_authorization_get_qop(authorization))==0)) { belle_sip_error("belle_sip_fill_authorization_header, unsupported qop [%s], use auth or nothing instead" ,belle_sip_header_authorization_get_qop(authorization)); return -1; } CHECK_IS_PRESENT(authorization,authorization,realm) CHECK_IS_PRESENT(authorization,authorization,nonce) if (BELLE_SIP_IS_INSTANCE_OF(authorization,belle_http_header_authorization_t)) { /*http case*/ if (!belle_http_header_authorization_get_uri(BELLE_HTTP_HEADER_AUTHORIZATION(authorization))) { belle_sip_error("parameter uri not found for http header authorization"); return-1; } } else { CHECK_IS_PRESENT(authorization,authorization,uri) } if (auth_mode) { CHECK_IS_PRESENT(authorization,authorization,nonce_count) if (!belle_sip_header_authorization_get_cnonce(authorization)) { snprintf(cnonce,sizeof(cnonce),"%08x",(short)(long)authorization^0x5555555); /*spseudo randomly genrated cnonce*/ belle_sip_header_authorization_set_cnonce(authorization,cnonce); } } if (!method) { belle_sip_error("belle_sip_fill_authorization_header, method not found "); return -1; } if (BELLE_SIP_IS_INSTANCE_OF(authorization,belle_http_header_authorization_t)) { /*http case*/ uri=belle_generic_uri_to_string(belle_http_header_authorization_get_uri(BELLE_HTTP_HEADER_AUTHORIZATION(authorization))); } else { uri=belle_sip_uri_to_string(belle_sip_header_authorization_get_uri(authorization)); } belle_sip_auth_helper_compute_ha2(method,uri,ha2); belle_sip_free(uri); if (auth_mode) { /*response=MD5(HA1:nonce:nonce_count:cnonce:qop:HA2)*/ belle_sip_auth_helper_compute_response_qop_auth(ha1 ,belle_sip_header_authorization_get_nonce(authorization) ,belle_sip_header_authorization_get_nonce_count(authorization) ,belle_sip_header_authorization_get_cnonce(authorization) ,belle_sip_header_authorization_get_qop(authorization) ,ha2 ,response); } else { /*response=MD5(ha1:nonce:ha2)*/ belle_sip_auth_helper_compute_response(ha1,belle_sip_header_authorization_get_nonce(authorization),ha2,response); } belle_sip_header_authorization_set_response(authorization,(const char*)response); return 0; }
bool_t sal_body_handler_is_multipart(const SalBodyHandler *body_handler) { if (BELLE_SIP_IS_INSTANCE_OF(body_handler, belle_sip_multipart_body_handler_t)) return TRUE; return FALSE; }