1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
/*
* Copyright (c) 2010-2022 Belledonne Communications SARL.
*
* This file is part of Liblinphone
* (see https://gitlab.linphone.org/BC/public/liblinphone).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "linphone/core.h"
#include "c-wrapper/c-wrapper.h"
// TODO: From coreapi. Remove me later.
#include "private.h"
static void linphone_buffer_destroy(LinphoneBuffer *buffer) {
if (buffer->content) belle_sip_free(buffer->content);
}
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneBuffer);
BELLE_SIP_INSTANCIATE_VPTR(LinphoneBuffer,
belle_sip_object_t,
(belle_sip_object_destroy_t)linphone_buffer_destroy,
NULL, // clone
NULL, // marshal
TRUE);
LinphoneBuffer *linphone_buffer_new(void) {
LinphoneBuffer *buffer = belle_sip_object_new(LinphoneBuffer);
belle_sip_object_ref(buffer);
return buffer;
}
LinphoneBuffer *linphone_buffer_new_from_data(const uint8_t *data, size_t size) {
LinphoneBuffer *buffer = linphone_buffer_new();
linphone_buffer_set_content(buffer, data, size);
return buffer;
}
LinphoneBuffer *linphone_buffer_new_from_string(const char *data) {
LinphoneBuffer *buffer = linphone_buffer_new();
linphone_buffer_set_string_content(buffer, data);
return buffer;
}
LinphoneBuffer *linphone_buffer_ref(LinphoneBuffer *buffer) {
belle_sip_object_ref(buffer);
return buffer;
}
void linphone_buffer_unref(LinphoneBuffer *buffer) {
belle_sip_object_unref(buffer);
}
void *linphone_buffer_get_user_data(const LinphoneBuffer *buffer) {
return buffer->user_data;
}
void linphone_buffer_set_user_data(LinphoneBuffer *buffer, void *ud) {
buffer->user_data = ud;
}
const uint8_t *linphone_buffer_get_content(const LinphoneBuffer *buffer) {
return buffer->content;
}
void linphone_buffer_set_content(LinphoneBuffer *buffer, const uint8_t *content, size_t size) {
buffer->size = size;
if (buffer->content) belle_sip_free(buffer->content);
buffer->content = reinterpret_cast<uint8_t *>(belle_sip_malloc(size + 1));
memcpy(buffer->content, content, size);
((char *)buffer->content)[size] = '\0';
}
const char *linphone_buffer_get_string_content(const LinphoneBuffer *buffer) {
return (const char *)buffer->content;
}
void linphone_buffer_set_string_content(LinphoneBuffer *buffer, const char *content) {
buffer->size = strlen(content);
if (buffer->content) belle_sip_free(buffer->content);
buffer->content = (uint8_t *)belle_sip_strdup(content);
}
size_t linphone_buffer_get_size(const LinphoneBuffer *buffer) {
return buffer->size;
}
void linphone_buffer_set_size(LinphoneBuffer *buffer, size_t size) {
buffer->size = size;
}
bool_t linphone_buffer_is_empty(const LinphoneBuffer *buffer) {
return (buffer->size == 0) ? TRUE : FALSE;
}
|