Commit affd0215 authored by Guillaume BIENKOWSKI's avatar Guillaume BIENKOWSKI

Add the ability to use a file:// protocol for provisioning

parent 90b51017
......@@ -52,11 +52,32 @@ static void linphone_remote_provisioning_apply(LinphoneCore *lc, const char *xml
}
}
static int linphone_remote_provisioning_load_file( LinphoneCore* lc, const char* file_path){
int status = -1;
FILE* f = fopen(file_path, "r");
if( f ){
fseek(f, 0, SEEK_END);
long fsize = ftell(f);
fseek(f, 0, SEEK_SET);
char* provisioning = ms_malloc(fsize + 1);
fread(provisioning, fsize, 1, f);
fclose(f);
linphone_remote_provisioning_apply(lc, provisioning);
status = 0;
} else {
ms_error("Couldn't open file %s for provisioning", file_path);
}
return status;
}
static void belle_request_process_response_event(void *ctx, const belle_http_response_event_t *event) {
LinphoneCore *lc = (LinphoneCore *)ctx;
belle_sip_message_t *body = BELLE_SIP_MESSAGE(event->response);
const char *message = belle_sip_message_get_body(body);
if (belle_http_response_get_status_code(event->response) == 200) {
linphone_remote_provisioning_apply(lc, message);
} else {
......@@ -80,23 +101,31 @@ static void belle_request_process_auth_requested(void *ctx, belle_sip_auth_event
}
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);
belle_http_request_listener_callbacks_t belle_request_listener = {
belle_request_process_response_event,
belle_request_process_io_error,
belle_request_process_timeout,
belle_request_process_auth_requested
};
belle_http_request_listener_t *listener = belle_http_request_listener_create_from_callbacks(&belle_request_listener, lc);
belle_http_request_t *request;
if (uri==NULL) {
belle_sip_error("Invalid provisioning URI [%s]",remote_provisioning_uri);
return -1;
const char* file_path = strstr(remote_provisioning_uri, "file://");
if( file_path == remote_provisioning_uri ){
// We allow for 'local remote-provisioning' in case the file is to be opened from the hard drive
file_path += strlen("file://");
return linphone_remote_provisioning_load_file(lc, file_path);
} else {
belle_generic_uri_t *uri=belle_generic_uri_parse(remote_provisioning_uri);
belle_http_request_listener_callbacks_t belle_request_listener = {
belle_request_process_response_event,
belle_request_process_io_error,
belle_request_process_timeout,
belle_request_process_auth_requested
};
belle_http_request_listener_t *listener = belle_http_request_listener_create_from_callbacks(&belle_request_listener, lc);
belle_http_request_t *request;
if (uri==NULL) {
belle_sip_error("Invalid provisioning URI [%s]",remote_provisioning_uri);
return -1;
}
request=belle_http_request_create("GET",uri, NULL);
belle_http_provider_send_request(lc->http_provider, request, listener);
return 0;
}
request=belle_http_request_create("GET",uri, NULL);
belle_http_provider_send_request(lc->http_provider, request, listener);
return 0;
}
void linphone_core_set_provisioning_uri(LinphoneCore *lc, const char *uri) {
......
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns="http://www.linphone.org/xsds/lpconfig.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.linphone.org/xsds/lpconfig.xsd lpconfig.xsd">
<section name="app">
<entry name="show_login_view" overwrite="true">0</entry>
<entry name="pushnotification_preference" overwrite="true">1</entry>
</section>
<section name="misc">
<entry name="transient_provisioning" overwrite="true">1</entry>
<entry name="tester_file_ok" overwrite="true">1</entry>
</section>
</config>
[misc]
config-uri=file://./rcfiles/marie_remote_localfile2_rc
/*
liblinphone_tester - liblinphone test suite
Copyright (C) 2013 Belledonne Communications SARL
liblinphone_tester - liblinphone test suite
Copyright (C) 2013 Belledonne Communications SARL
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
......@@ -29,9 +29,9 @@ void linphone_configuration_status(LinphoneCore *lc, LinphoneConfiguringState st
if (status == LinphoneConfiguringSkipped) {
counters->number_of_LinphoneConfiguringSkipped++;
} else if (status == LinphoneConfiguringFailed) {
counters->number_of_LinphoneConfiguringFailed++;
counters->number_of_LinphoneConfiguringFailed++;
} else if (status == LinphoneConfiguringSuccessful) {
counters->number_of_LinphoneConfiguringSuccessful++;
counters->number_of_LinphoneConfiguringSuccessful++;
}
}
......@@ -89,6 +89,18 @@ static void remote_provisioning_default_values(void) {
linphone_core_manager_destroy(marie);
}
static void remote_provisioning_file(void) {
LinphoneCoreManager* marie = linphone_core_manager_new2("marie_remote_localfile_rc", FALSE);
const LpConfig* conf;
CU_ASSERT_TRUE(wait_for(marie->lc,NULL,&marie->stat.number_of_LinphoneConfiguringSuccessful,1));
conf = linphone_core_get_config( marie->lc );
CU_ASSERT_EQUAL( lp_config_get_int(conf,"misc","tester_file_ok", 0), 1 );
linphone_core_manager_destroy(marie);
}
test_t remote_provisioning_tests[] = {
{ "Remote provisioning skipped", remote_provisioning_skipped },
{ "Remote provisioning successful behind http", remote_provisioning_http },
......@@ -96,7 +108,8 @@ test_t remote_provisioning_tests[] = {
{ "Remote provisioning 404 not found", remote_provisioning_not_found },
{ "Remote provisioning invalid", remote_provisioning_invalid },
{ "Remote provisioning transient successful", remote_provisioning_transient },
{ "Remote provisioning default values", remote_provisioning_default_values }
{ "Remote provisioning default values", remote_provisioning_default_values },
{ "Remote provisioning from file", remote_provisioning_file }
};
test_suite_t remote_provisioning_test_suite = {
......
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