mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-02-07 14:18:25 +00:00
A LinphoneContent object now owns all its data fields including the buffer.
A normal LinphoneContent object will now copy the data from the given buffer when calling linphone_content_set_buffer(). However LinphoneContent objects converted from LinphoneContentPrivate structures do not own its data fields.
This commit is contained in:
parent
7c0a5ee770
commit
9cabfe37dd
8 changed files with 46 additions and 52 deletions
|
|
@ -23,27 +23,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
|
||||
static void linphone_content_destroy(LinphoneContent *content) {
|
||||
if (content->lcp.type) belle_sip_free(content->lcp.type);
|
||||
if (content->lcp.subtype) belle_sip_free(content->lcp.subtype);
|
||||
if (content->lcp.data) belle_sip_free(content->lcp.data);
|
||||
if (content->lcp.encoding) belle_sip_free(content->lcp.encoding);
|
||||
if (content->lcp.name) belle_sip_free(content->lcp.name);
|
||||
if (content->owned_fields == TRUE) {
|
||||
if (content->lcp.type) belle_sip_free(content->lcp.type);
|
||||
if (content->lcp.subtype) belle_sip_free(content->lcp.subtype);
|
||||
if (content->lcp.data) belle_sip_free(content->lcp.data);
|
||||
if (content->lcp.encoding) belle_sip_free(content->lcp.encoding);
|
||||
if (content->lcp.name) belle_sip_free(content->lcp.name);
|
||||
}
|
||||
}
|
||||
|
||||
static void linphone_content_clone(LinphoneContent *obj, const LinphoneContent *ref) {
|
||||
void *data;
|
||||
linphone_content_set_type(obj, linphone_content_get_type(ref));
|
||||
linphone_content_set_subtype(obj, linphone_content_get_subtype(ref));
|
||||
linphone_content_set_encoding(obj, linphone_content_get_encoding(ref));
|
||||
linphone_content_set_name(obj, linphone_content_get_name(ref));
|
||||
linphone_content_set_size(obj, linphone_content_get_size(ref));
|
||||
data = linphone_content_get_data(ref);
|
||||
if (data != NULL) {
|
||||
size_t size = linphone_content_get_size(ref);
|
||||
void *objdata = belle_sip_malloc(size + 1);
|
||||
memcpy(objdata, data, size);
|
||||
((char *)objdata)[size] = '\0';
|
||||
linphone_content_set_data(obj, objdata);
|
||||
if (linphone_content_get_buffer(ref) != NULL) {
|
||||
linphone_content_set_buffer(obj, linphone_content_get_buffer(ref), linphone_content_get_size(ref));
|
||||
} else {
|
||||
linphone_content_set_size(obj, linphone_content_get_size(ref));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -107,12 +104,15 @@ void linphone_content_set_subtype(LinphoneContent *content, const char *subtype)
|
|||
}
|
||||
}
|
||||
|
||||
void * linphone_content_get_data(const LinphoneContent *content) {
|
||||
void * linphone_content_get_buffer(const LinphoneContent *content) {
|
||||
return content->lcp.data;
|
||||
}
|
||||
|
||||
void linphone_content_set_data(LinphoneContent *content, void *data) {
|
||||
content->lcp.data = data;
|
||||
void linphone_content_set_buffer(LinphoneContent *content, const void *buffer, size_t size) {
|
||||
content->lcp.size = size;
|
||||
content->lcp.data = belle_sip_malloc(size + 1);
|
||||
memcpy(content->lcp.data, buffer, size);
|
||||
((char *)content->lcp.data)[size] = '\0';
|
||||
}
|
||||
|
||||
size_t linphone_content_get_size(const LinphoneContent *content) {
|
||||
|
|
@ -156,6 +156,7 @@ void linphone_content_set_name(LinphoneContent *content, const char *name) {
|
|||
LinphoneContent * linphone_content_new(void) {
|
||||
LinphoneContent *content = belle_sip_object_new(LinphoneContent);
|
||||
belle_sip_object_ref(content);
|
||||
content->owned_fields = TRUE;
|
||||
return content;
|
||||
}
|
||||
|
||||
|
|
@ -165,16 +166,15 @@ LinphoneContent * linphone_content_copy(const LinphoneContent *ref) {
|
|||
|
||||
LinphoneContent * linphone_content_from_sal_body(const SalBody *ref) {
|
||||
if (ref && ref->type) {
|
||||
void *objdata;
|
||||
LinphoneContent *content = linphone_content_new();
|
||||
linphone_content_set_type(content, ref->type);
|
||||
linphone_content_set_subtype(content, ref->subtype);
|
||||
linphone_content_set_encoding(content, ref->encoding);
|
||||
linphone_content_set_size(content, ref->size);
|
||||
objdata = belle_sip_malloc(ref->size + 1);
|
||||
memcpy(objdata, ref->data, ref->size);
|
||||
((char *)objdata)[ref->size] = '\0';
|
||||
linphone_content_set_data(content, objdata);
|
||||
if (ref->data != NULL) {
|
||||
linphone_content_set_buffer(content, ref->data, ref->size);
|
||||
} else {
|
||||
linphone_content_set_size(content, ref->size);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
return NULL;
|
||||
|
|
@ -184,7 +184,7 @@ SalBody *sal_body_from_content(SalBody *body, const LinphoneContent *content) {
|
|||
if (content && linphone_content_get_type(content)) {
|
||||
body->type = linphone_content_get_type(content);
|
||||
body->subtype = linphone_content_get_subtype(content);
|
||||
body->data = linphone_content_get_data(content);
|
||||
body->data = linphone_content_get_buffer(content);
|
||||
body->size = linphone_content_get_size(content);
|
||||
body->encoding = linphone_content_get_encoding(content);
|
||||
return body;
|
||||
|
|
@ -197,6 +197,7 @@ SalBody *sal_body_from_content(SalBody *body, const LinphoneContent *content) {
|
|||
LinphoneContent * linphone_content_private_to_linphone_content(const LinphoneContentPrivate *lcp) {
|
||||
LinphoneContent *content = belle_sip_object_new(LinphoneContent);
|
||||
memcpy(&content->lcp, lcp, sizeof(LinphoneContentPrivate));
|
||||
content->owned_fields = FALSE;
|
||||
return content;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -150,26 +150,26 @@ LINPHONE_PUBLIC void linphone_content_set_subtype(LinphoneContent *content, cons
|
|||
* @param[in] content LinphoneContent object.
|
||||
* @return The content data buffer.
|
||||
*/
|
||||
LINPHONE_PUBLIC void * linphone_content_get_data(const LinphoneContent *content);
|
||||
LINPHONE_PUBLIC void * linphone_content_get_buffer(const LinphoneContent *content);
|
||||
|
||||
/**
|
||||
* Set the content data buffer, usually a string.
|
||||
* @param[in] content LinphoneContent object.
|
||||
* @param[in] data The content data buffer.
|
||||
*/
|
||||
LINPHONE_PUBLIC void linphone_content_set_data(LinphoneContent *content, void *data);
|
||||
LINPHONE_PUBLIC void linphone_content_set_buffer(LinphoneContent *content, const void *buffer, size_t size);
|
||||
|
||||
/**
|
||||
* Get the content data size, excluding null character despite null character is always set for convenience.
|
||||
* Get the content data buffer size, excluding null character despite null character is always set for convenience.
|
||||
* @param[in] content LinphoneContent object.
|
||||
* @return The content data size.
|
||||
* @return The content data buffer size.
|
||||
*/
|
||||
LINPHONE_PUBLIC size_t linphone_content_get_size(const LinphoneContent *content);
|
||||
|
||||
/**
|
||||
* Set the content data size, excluding null character despite null character is always set for convenience.
|
||||
* @param[in] content LinphoneContent object
|
||||
* @param[in] size The content data size.
|
||||
* @param[in] size The content data buffer size.
|
||||
*/
|
||||
LINPHONE_PUBLIC void linphone_content_set_size(LinphoneContent *content, size_t size);
|
||||
|
||||
|
|
|
|||
|
|
@ -909,6 +909,7 @@ struct _LinphoneContent {
|
|||
belle_sip_object_t base;
|
||||
void *user_data;
|
||||
struct _LinphoneContentPrivate lcp;
|
||||
bool_t owned_fields;
|
||||
};
|
||||
|
||||
BELLE_SIP_DECLARE_VPTR(LinphoneContent);
|
||||
|
|
|
|||
|
|
@ -331,8 +331,7 @@ static int send_report(LinphoneCall* call, reporting_session_report_t * report,
|
|||
append_to_buffer(&buffer, &size, &offset, "\r\n");
|
||||
}
|
||||
|
||||
linphone_content_set_data(content, buffer);
|
||||
linphone_content_set_size(content, strlen(buffer));
|
||||
linphone_content_set_buffer(content, buffer, strlen(buffer));
|
||||
|
||||
if (call->log->reporting.on_report_sent != NULL){
|
||||
call->log->reporting.on_report_sent(
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ const char *liblinphone_tester_get_notify_content(void){
|
|||
void linphone_notify_received(LinphoneCore *lc, LinphoneEvent *lev, const char *eventname, const LinphoneContent *content){
|
||||
LinphoneCoreManager *mgr;
|
||||
CU_ASSERT_PTR_NOT_NULL_FATAL(content);
|
||||
CU_ASSERT_TRUE(strcmp(notify_content,(const char*)linphone_content_get_data(content))==0);
|
||||
CU_ASSERT_TRUE(strcmp(notify_content,(const char*)linphone_content_get_buffer(content))==0);
|
||||
mgr=get_manager(lc);
|
||||
mgr->stat.number_of_NotifyReceived++;
|
||||
}
|
||||
|
|
@ -54,8 +54,7 @@ void linphone_subscription_state_change(LinphoneCore *lc, LinphoneEvent *lev, Li
|
|||
content = linphone_core_create_content(lc);
|
||||
linphone_content_set_type(content,"application");
|
||||
linphone_content_set_subtype(content,"somexml2");
|
||||
linphone_content_set_data(content,belle_sip_strdup(notify_content));
|
||||
linphone_content_set_size(content,strlen(notify_content));
|
||||
linphone_content_set_buffer(content,notify_content,strlen(notify_content));
|
||||
|
||||
ms_message("Subscription state [%s] from [%s]",linphone_subscription_state_to_string(state),from);
|
||||
ms_free(from);
|
||||
|
|
@ -134,8 +133,7 @@ static void subscribe_test_declined(void) {
|
|||
content = linphone_core_create_content(marie->lc);
|
||||
linphone_content_set_type(content,"application");
|
||||
linphone_content_set_subtype(content,"somexml");
|
||||
linphone_content_set_data(content,belle_sip_strdup(subscribe_content));
|
||||
linphone_content_set_size(content,strlen(subscribe_content));
|
||||
linphone_content_set_buffer(content,subscribe_content,strlen(subscribe_content));
|
||||
|
||||
pauline->decline_subscribe=TRUE;
|
||||
|
||||
|
|
@ -182,8 +180,7 @@ static void subscribe_test_with_args(bool_t terminated_by_subscriber, RefreshTes
|
|||
content = linphone_core_create_content(marie->lc);
|
||||
linphone_content_set_type(content,"application");
|
||||
linphone_content_set_subtype(content,"somexml");
|
||||
linphone_content_set_data(content,belle_sip_strdup(subscribe_content));
|
||||
linphone_content_set_size(content,strlen(subscribe_content));
|
||||
linphone_content_set_buffer(content,subscribe_content,strlen(subscribe_content));
|
||||
|
||||
lev=linphone_core_subscribe(marie->lc,pauline->identity,"dodo",expires,content);
|
||||
|
||||
|
|
@ -236,8 +233,7 @@ static void subscribe_test_with_args2(bool_t terminated_by_subscriber, RefreshTe
|
|||
content = linphone_core_create_content(marie->lc);
|
||||
linphone_content_set_type(content,"application");
|
||||
linphone_content_set_subtype(content,"somexml");
|
||||
linphone_content_set_data(content,belle_sip_strdup(subscribe_content));
|
||||
linphone_content_set_size(content,strlen(subscribe_content));
|
||||
linphone_content_set_buffer(content,subscribe_content,strlen(subscribe_content));
|
||||
|
||||
lev=linphone_core_create_subscribe(marie->lc,pauline->identity,"dodo",expires);
|
||||
linphone_event_add_custom_header(lev,"My-Header","pouet");
|
||||
|
|
@ -315,8 +311,7 @@ static void publish_test_with_args(bool_t refresh, int expires){
|
|||
content = linphone_core_create_content(marie->lc);
|
||||
linphone_content_set_type(content,"application");
|
||||
linphone_content_set_subtype(content,"somexml");
|
||||
linphone_content_set_data(content,belle_sip_strdup(subscribe_content));
|
||||
linphone_content_set_size(content,strlen(subscribe_content));
|
||||
linphone_content_set_buffer(content,subscribe_content,strlen(subscribe_content));
|
||||
|
||||
lp_config_set_int(marie->lc->config,"sip","refresh_generic_publish",refresh);
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,7 @@ static void subscribe_forking(void) {
|
|||
content = linphone_core_create_content(marie->lc);
|
||||
linphone_content_set_type(content,"application");
|
||||
linphone_content_set_subtype(content,"somexml");
|
||||
linphone_content_set_data(content, belle_sip_strdup(liblinphone_tester_get_subscribe_content()));
|
||||
linphone_content_set_size(content, strlen(liblinphone_tester_get_subscribe_content()));
|
||||
linphone_content_set_buffer(content, liblinphone_tester_get_subscribe_content(), strlen(liblinphone_tester_get_subscribe_content()));
|
||||
|
||||
lev=linphone_core_subscribe(marie->lc,pauline->identity,"dodo",expires,content);
|
||||
|
||||
|
|
|
|||
|
|
@ -836,8 +836,7 @@ static void info_message_with_args(bool_t with_content) {
|
|||
LinphoneContent* ct=linphone_core_create_content(marie->lc);
|
||||
linphone_content_set_type(ct,"application");
|
||||
linphone_content_set_subtype(ct,"somexml");
|
||||
linphone_content_set_data(ct,belle_sip_strdup(info_content));
|
||||
linphone_content_set_size(ct,strlen(info_content));
|
||||
linphone_content_set_buffer(ct,info_content,strlen(info_content));
|
||||
linphone_info_message_set_content(info,ct);
|
||||
linphone_content_unref(ct);
|
||||
}
|
||||
|
|
@ -863,12 +862,12 @@ static void info_message_with_args(bool_t with_content) {
|
|||
if (with_content){
|
||||
CU_ASSERT_PTR_NOT_NULL(content);
|
||||
if (content) {
|
||||
CU_ASSERT_PTR_NOT_NULL(linphone_content_get_data(content));
|
||||
CU_ASSERT_PTR_NOT_NULL(linphone_content_get_buffer(content));
|
||||
CU_ASSERT_PTR_NOT_NULL(linphone_content_get_type(content));
|
||||
CU_ASSERT_PTR_NOT_NULL(linphone_content_get_subtype(content));
|
||||
if (linphone_content_get_type(content)) CU_ASSERT_TRUE(strcmp(linphone_content_get_type(content),"application")==0);
|
||||
if (linphone_content_get_subtype(content)) CU_ASSERT_TRUE(strcmp(linphone_content_get_subtype(content),"somexml")==0);
|
||||
if (linphone_content_get_data(content))CU_ASSERT_TRUE(strcmp((const char*)linphone_content_get_data(content),info_content)==0);
|
||||
if (linphone_content_get_buffer(content))CU_ASSERT_TRUE(strcmp((const char*)linphone_content_get_buffer(content),info_content)==0);
|
||||
CU_ASSERT_EQUAL(linphone_content_get_size(content),strlen(info_content));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#define __strstr(x, y) ((x==NULL)?NULL:strstr(x,y))
|
||||
|
||||
void on_report_send_mandatory(const LinphoneCall *call, int stream_type, const LinphoneContent *content){
|
||||
char * body = (char *)linphone_content_get_data(content);
|
||||
char * body = (char *)linphone_content_get_buffer(content);
|
||||
char * remote_metrics_start = __strstr(body, "RemoteMetrics:");
|
||||
reporting_session_report_t * report = call->log->reporting.reports[stream_type];
|
||||
MediaStream * ms;
|
||||
|
|
@ -91,7 +91,7 @@ char * on_report_send_verify_metrics(const reporting_content_metrics_t *metrics,
|
|||
}
|
||||
|
||||
void on_report_send_with_rtcp_xr_local(const LinphoneCall *call, int stream_type, const LinphoneContent *content){
|
||||
char * body = (char*)linphone_content_get_data(content);
|
||||
char * body = (char*)linphone_content_get_buffer(content);
|
||||
char * remote_metrics_start = __strstr(body, "RemoteMetrics:");
|
||||
reporting_session_report_t * report = call->log->reporting.reports[stream_type];
|
||||
on_report_send_mandatory(call,stream_type,content);
|
||||
|
|
@ -99,7 +99,7 @@ void on_report_send_with_rtcp_xr_local(const LinphoneCall *call, int stream_type
|
|||
CU_ASSERT_TRUE(!remote_metrics_start || on_report_send_verify_metrics(&report->local_metrics,body) < remote_metrics_start);
|
||||
}
|
||||
void on_report_send_with_rtcp_xr_remote(const LinphoneCall *call, int stream_type, const LinphoneContent *content){
|
||||
char * body = (char*)linphone_content_get_data(content);
|
||||
char * body = (char*)linphone_content_get_buffer(content);
|
||||
reporting_session_report_t * report = call->log->reporting.reports[stream_type];
|
||||
|
||||
on_report_send_mandatory(call,stream_type,content);
|
||||
|
|
@ -214,7 +214,7 @@ static void quality_reporting_not_sent_if_low_bandwidth() {
|
|||
}
|
||||
|
||||
void on_report_send_remove_fields(const LinphoneCall *call, int stream_type, const LinphoneContent *content){
|
||||
char *body = (char*)linphone_content_get_data(content);
|
||||
char *body = (char*)linphone_content_get_buffer(content);
|
||||
/*corrupt start of the report*/
|
||||
strncpy(body, "corrupted report is corrupted", strlen("corrupted report is corrupted"));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue