void linphone_xml_rpc_session_send_request(LinphoneXmlRpcSession *session, LinphoneXmlRpcRequest *request) { belle_http_request_listener_callbacks_t cbs = { 0 }; belle_http_request_listener_t *l; belle_generic_uri_t *uri; belle_http_request_t *req; belle_sip_memory_body_handler_t *bh; const char *data; LinphoneContent *content; linphone_xml_rpc_request_ref(request); uri = belle_generic_uri_parse(session->url); if (!uri) { ms_error("Could not send request, URL %s is invalid", session->url); process_io_error_from_post_xml_rpc_request(request, NULL); return; } req = belle_http_request_create("POST", uri, belle_sip_header_content_type_create("text", "xml"), NULL); if (!req) { belle_sip_object_unref(uri); process_io_error_from_post_xml_rpc_request(request, NULL); } content = linphone_content_new(); linphone_content_set_type(content, "text"); linphone_content_set_subtype(content, "xml"); linphone_content_set_string_buffer(content, linphone_xml_rpc_request_get_content(request)); data = linphone_xml_rpc_request_get_content(request); bh = belle_sip_memory_body_handler_new_copy_from_buffer(data, strlen(data), NULL, NULL); belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(req), BELLE_SIP_BODY_HANDLER(bh)); cbs.process_response = process_response_from_post_xml_rpc_request; cbs.process_io_error = process_io_error_from_post_xml_rpc_request; cbs.process_auth_requested = process_auth_requested_from_post_xml_rpc_request; l = belle_http_request_listener_create_from_callbacks(&cbs, request); belle_http_provider_send_request(session->core->http_provider, req, l); linphone_content_unref(content); }
int main(int argc, char *argv[]){ belle_http_provider_t *prov; belle_http_request_t *req; belle_generic_uri_t *uri; belle_http_request_listener_callbacks_t cbs={0}; if (argc<2){ fprintf(stderr,"Usage:\n%s <http uri> [--debug]\n",argv[0]); return -1; } if (argc==3){ if (strcmp(argv[2],"--debug")==0){ belle_sip_set_log_level(BELLE_SIP_LOG_DEBUG); } } stack=belle_sip_stack_new(NULL); prov=belle_sip_stack_create_http_provider(stack,"0.0.0.0"); uri=belle_generic_uri_parse(argv[1]); if (!uri){ fprintf(stderr,"Bad uri %s\n",argv[1]); return -1; } cbs.process_response=process_response; cbs.process_io_error=process_io_error; cbs.process_timeout=process_timeout; req=belle_http_request_create("GET",uri,NULL); belle_http_provider_send_request(prov,req,belle_http_request_listener_create_from_callbacks(&cbs,NULL)); belle_sip_stack_main(stack); belle_sip_object_unref(prov); belle_sip_object_unref(stack); return 0; }
void linphone_xml_rpc_session_send_request(LinphoneXmlRpcSession *session, LinphoneXmlRpcRequest *request) { belle_http_request_listener_callbacks_t cbs = { 0 }; belle_http_request_listener_t *l; belle_generic_uri_t *uri; belle_http_request_t *req; belle_sip_memory_body_handler_t *bh; const char *data; linphone_xml_rpc_request_ref(request); uri = belle_generic_uri_parse(session->url); if (!uri) { ms_error("Could not send request, URL %s is invalid", session->url); process_io_error_from_post_xml_rpc_request(request, NULL); return; } req = belle_http_request_create("POST", uri, belle_sip_header_content_type_create("text", "xml"), NULL); if (!req) { belle_sip_object_unref(uri); process_io_error_from_post_xml_rpc_request(request, NULL); return; } data = linphone_xml_rpc_request_get_content(request); bh = belle_sip_memory_body_handler_new_copy_from_buffer(data, strlen(data), NULL, NULL); belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(req), BELLE_SIP_BODY_HANDLER(bh)); cbs.process_response = process_response_from_post_xml_rpc_request; cbs.process_io_error = process_io_error_from_post_xml_rpc_request; cbs.process_auth_requested = process_auth_requested_from_post_xml_rpc_request; l = belle_http_request_listener_create_from_callbacks(&cbs, request); belle_http_provider_send_request(session->core->http_provider, req, l); /*ensure that the listener object will be destroyed with the request*/ belle_sip_object_data_set(BELLE_SIP_OBJECT(request), "listener", l, belle_sip_object_unref); /*prevent destruction of the session while there are still pending http requests*/ belle_sip_object_data_set(BELLE_SIP_OBJECT(request), "session", belle_sip_object_ref(session), belle_sip_object_unref); }
int linphone_remote_provisioning_download_and_apply(LinphoneCore *lc, const char *remote_provisioning_uri) { belle_generic_uri_t *uri=belle_generic_uri_parse(remote_provisioning_uri); const char* scheme = uri ? belle_generic_uri_get_scheme(uri) : NULL; if( scheme && (strcmp(scheme,"file") == 0) ){ // We allow for 'local remote-provisioning' in case the file is to be opened from the hard drive. const char* file_path = remote_provisioning_uri + strlen("file://"); // skip scheme return linphone_remote_provisioning_load_file(lc, file_path); } else if( scheme && strncmp(scheme, "http", 4) == 0 ) { belle_http_request_listener_callbacks_t belle_request_listener={0}; belle_http_request_listener_t *listener; belle_http_request_t *request; belle_request_listener.process_response=belle_request_process_response_event; belle_request_listener.process_auth_requested=belle_request_process_auth_requested; belle_request_listener.process_io_error=belle_request_process_io_error; belle_request_listener.process_timeout=belle_request_process_timeout; listener = belle_http_request_listener_create_from_callbacks(&belle_request_listener, lc); request=belle_http_request_create("GET",uri, NULL); return belle_http_provider_send_request(lc->http_provider, request, listener); } else { ms_error("Invalid provisioning URI [%s] (missing scheme?)",remote_provisioning_uri); return -1; } }
static void one_get(const char *url,http_counters_t* counters, int *counter){ belle_http_request_listener_callbacks_t cbs={0}; belle_http_request_listener_t *l; belle_generic_uri_t *uri; belle_http_request_t *req; uri=belle_generic_uri_parse(url); req=belle_http_request_create("GET", uri, belle_sip_header_create("User-Agent","belle-sip/"PACKAGE_VERSION), NULL); cbs.process_response=process_response; cbs.process_io_error=process_io_error; cbs.process_auth_requested=process_auth_requested; l=belle_http_request_listener_create_from_callbacks(&cbs,counters); belle_http_provider_send_request(prov,req,l); wait_for(stack,counter,1,3000); belle_sip_object_unref(l); }
static void prepare_query(CardDavRequest *request) { belle_http_request_listener_callbacks_t cbs = { 0 }; belle_http_request_listener_t *l = NULL; belle_generic_uri_t *uri = NULL; belle_http_request_t *req = NULL; belle_sip_memory_body_handler_t *bh = NULL; belle_sip_stack_t *stack = NULL; belle_http_provider_t *http_provider = NULL; belle_sip_set_log_level(BELLE_SIP_LOG_MESSAGE); uri = belle_generic_uri_parse(request->url); if (!uri) { belle_sip_error("Could not send request, URL %s is invalid", request->url); return; } req = belle_http_request_create(request->method, uri, belle_sip_header_content_type_create("application", "xml; charset=utf-8"), belle_sip_header_create("Depth", request->depth), NULL); if (!req) { belle_sip_object_unref(uri); belle_sip_error("Could not create request"); return; } bh = belle_sip_memory_body_handler_new_copy_from_buffer(request->body, strlen(request->body), NULL, NULL); belle_sip_message_set_body_handler(BELLE_SIP_MESSAGE(req), BELLE_SIP_BODY_HANDLER(bh)); cbs.process_response = process_response_from_post_xml_rpc_request; cbs.process_io_error = process_io_error_from_post_xml_rpc_request; cbs.process_auth_requested = process_auth_requested_from_post_xml_rpc_request; l = belle_http_request_listener_create_from_callbacks(&cbs, request); stack = belle_sip_stack_new(NULL); http_provider = belle_sip_stack_create_http_provider(stack, "0.0.0.0"); request->request_in_progress = 1; belle_http_provider_send_request(http_provider, req, l); while (request->request_in_progress) { belle_sip_stack_sleep(stack, 0); } }
static int http_channel_context_handle_authentication(belle_http_channel_context_t *ctx, belle_http_request_t *req){ const char *realm=NULL; belle_sip_auth_event_t *ev=NULL; belle_http_response_t *resp=belle_http_request_get_response(req); const char *username=NULL; const char *passwd=NULL; const char *ha1=NULL; char computed_ha1[33]; belle_sip_header_www_authenticate_t* authenticate; int ret=0; if (req->auth_attempt_count>1){ req->auth_attempt_count=0; return -1; } if (resp == NULL ) { belle_sip_error("Missing response for req [%p], cannot authenticate", req); return -1; } if (!(authenticate = belle_sip_message_get_header_by_type(resp,belle_sip_header_www_authenticate_t))) { if (belle_sip_message_get_header_by_type(resp,belle_sip_header_proxy_authenticate_t)) { belle_sip_error("Proxy authentication not supported yet, cannot authenticate for resp [%p]", resp); } belle_sip_error("Missing auth header in response [%p], cannot authenticate", resp); return -1; } if (strcasecmp("Digest",belle_sip_header_www_authenticate_get_scheme(authenticate)) != 0) { belle_sip_error("Unsupported auth scheme [%s] in response [%p], cannot authenticate", belle_sip_header_www_authenticate_get_scheme(authenticate),resp); return -1; } /*find if username, passwd were already supplied in original request uri*/ if (req->orig_uri){ username=belle_generic_uri_get_user(req->orig_uri); passwd=belle_generic_uri_get_user_password(req->orig_uri); } realm = belle_sip_header_www_authenticate_get_realm(authenticate); if (!username || !passwd) { ev=belle_sip_auth_event_create((belle_sip_object_t*)ctx->provider,realm,NULL); BELLE_HTTP_REQUEST_INVOKE_LISTENER(req,process_auth_requested,ev); username=ev->username; passwd=ev->passwd; ha1=ev->ha1; } if (!ha1 && username && passwd) { belle_sip_auth_helper_compute_ha1(username,realm,passwd, computed_ha1); ha1=computed_ha1; } else if (!ha1){ belle_sip_error("No auth info found for request [%p], cannot authenticate",req); ret=-1; } if (ha1) { belle_http_header_authorization_t* authorization; req->auth_attempt_count++; authorization = belle_http_auth_helper_create_authorization(authenticate); /*select first qop mode*/ belle_sip_header_authorization_set_qop(BELLE_SIP_HEADER_AUTHORIZATION(authorization),belle_sip_header_www_authenticate_get_qop_first(authenticate)); belle_sip_header_authorization_set_nonce_count(BELLE_SIP_HEADER_AUTHORIZATION(authorization),1); /*we don't store nonce count for now*/ belle_sip_header_authorization_set_username(BELLE_SIP_HEADER_AUTHORIZATION(authorization),username); belle_http_header_authorization_set_uri(authorization,belle_http_request_get_uri(req)); if (belle_sip_auth_helper_fill_authorization(BELLE_SIP_HEADER_AUTHORIZATION(authorization),belle_http_request_get_method(req),ha1)) { belle_sip_error("Cannot fill auth header for request [%p]",req); if (authorization) belle_sip_object_unref(authorization); ret=-1; } else { belle_sip_message_remove_header(BELLE_SIP_MESSAGE(req),BELLE_HTTP_AUTHORIZATION); belle_sip_message_add_header(BELLE_SIP_MESSAGE(req),BELLE_SIP_HEADER(authorization)); belle_http_provider_send_request(ctx->provider,req,NULL); } } if (ev) belle_sip_auth_event_destroy(ev); return ret; }
static void reenqueue_request(belle_http_request_t *req, belle_http_provider_t *prov){ belle_http_provider_send_request(prov,req,req->listener); }