diff --git a/include/linphone/api/c-content.h b/include/linphone/api/c-content.h index 6114875a3..214755d5b 100644 --- a/include/linphone/api/c-content.h +++ b/include/linphone/api/c-content.h @@ -38,55 +38,55 @@ * @param[in] content #LinphoneContent object. * @return The same #LinphoneContent object. **/ -LINPHONE_PUBLIC LinphoneContent * linphone_content_ref(LinphoneContent *content); +LINPHONE_PUBLIC LinphoneContent *linphone_content_ref (LinphoneContent *content); /** * Release reference to the content. * @param[in] content #LinphoneContent object. **/ -LINPHONE_PUBLIC void linphone_content_unref(LinphoneContent *content); +LINPHONE_PUBLIC void linphone_content_unref (LinphoneContent *content); /** * Retrieve the user pointer associated with the content. * @param[in] content #LinphoneContent object. * @return The user pointer associated with the content. **/ -LINPHONE_PUBLIC void *linphone_content_get_user_data(const LinphoneContent *content); +LINPHONE_PUBLIC void *linphone_content_get_user_data (const LinphoneContent *content); /** * Assign a user pointer to the content. * @param[in] content #LinphoneContent object. * @param[in] ud The user pointer to associate with the content. **/ -LINPHONE_PUBLIC void linphone_content_set_user_data(LinphoneContent *content, void *ud); +LINPHONE_PUBLIC void linphone_content_set_user_data (LinphoneContent *content, void *user_data); /** * Get the mime type of the content data. * @param[in] content #LinphoneContent object. * @return The mime type of the content data, for example "application". */ -LINPHONE_PUBLIC const char * linphone_content_get_type(const LinphoneContent *content); +LINPHONE_PUBLIC const char *linphone_content_get_type (const LinphoneContent *content); /** * Set the mime type of the content data. * @param[in] content #LinphoneContent object. * @param[in] type The mime type of the content data, for example "application". */ -LINPHONE_PUBLIC void linphone_content_set_type(LinphoneContent *content, const char *type); +LINPHONE_PUBLIC void linphone_content_set_type (LinphoneContent *content, const char *type); /** * Get the mime subtype of the content data. * @param[in] content #LinphoneContent object. * @return The mime subtype of the content data, for example "html". */ -LINPHONE_PUBLIC const char * linphone_content_get_subtype(const LinphoneContent *content); +LINPHONE_PUBLIC const char *linphone_content_get_subtype (const LinphoneContent *content); /** * Set the mime subtype of the content data. * @param[in] content #LinphoneContent object. * @param[in] subtype The mime subtype of the content data, for example "html". */ -LINPHONE_PUBLIC void linphone_content_set_subtype(LinphoneContent *content, const char *subtype); +LINPHONE_PUBLIC void linphone_content_set_subtype (LinphoneContent *content, const char *subtype); /** * Adds a parameter to the ContentType header. @@ -94,14 +94,18 @@ LINPHONE_PUBLIC void linphone_content_set_subtype(LinphoneContent *content, cons * @param[in] name the name of the parameter to add. * @param[in] value the value of the parameter to add. */ -LINPHONE_PUBLIC void linphone_content_add_content_type_parameter(LinphoneContent *content, const char *name, const char *value); +LINPHONE_PUBLIC void linphone_content_add_content_type_parameter ( + LinphoneContent *content, + const char *name, + const char *value +); /** * Get the content data buffer, usually a string. * @param[in] content #LinphoneContent object. * @return The content data buffer. */ -LINPHONE_PUBLIC uint8_t * linphone_content_get_buffer(const LinphoneContent *content); +LINPHONE_PUBLIC uint8_t *linphone_content_get_buffer (const LinphoneContent *content); /** * Set the content data buffer, usually a string. @@ -109,70 +113,70 @@ LINPHONE_PUBLIC uint8_t * linphone_content_get_buffer(const LinphoneContent *con * @param[in] buffer The content data buffer. * @param[in] size The size of the content data buffer. */ -LINPHONE_PUBLIC void linphone_content_set_buffer(LinphoneContent *content, const uint8_t *buffer, size_t size); +LINPHONE_PUBLIC void linphone_content_set_buffer (LinphoneContent *content, const uint8_t *buffer, size_t size); /** * Get the string content data buffer. * @param[in] content #LinphoneContent object * @return The string content data buffer. */ -LINPHONE_PUBLIC const char * linphone_content_get_string_buffer(const LinphoneContent *content); +LINPHONE_PUBLIC const char *linphone_content_get_string_buffer (const LinphoneContent *content); /** * Set the string content data buffer. * @param[in] content #LinphoneContent object. * @param[in] buffer The string content data buffer. */ -LINPHONE_PUBLIC void linphone_content_set_string_buffer(LinphoneContent *content, const char *buffer); +LINPHONE_PUBLIC void linphone_content_set_string_buffer (LinphoneContent *content, const char *buffer); /** * 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 buffer size. */ -LINPHONE_PUBLIC size_t linphone_content_get_size(const LinphoneContent *content); +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 buffer size. */ -LINPHONE_PUBLIC void linphone_content_set_size(LinphoneContent *content, size_t size); +LINPHONE_PUBLIC void linphone_content_set_size (LinphoneContent *content, size_t size); /** * Get the encoding of the data buffer, for example "gzip". * @param[in] content #LinphoneContent object. * @return The encoding of the data buffer. */ -LINPHONE_PUBLIC const char * linphone_content_get_encoding(const LinphoneContent *content); +LINPHONE_PUBLIC const char *linphone_content_get_encoding (const LinphoneContent *content); /** * Set the encoding of the data buffer, for example "gzip". * @param[in] content #LinphoneContent object. * @param[in] encoding The encoding of the data buffer. */ -LINPHONE_PUBLIC void linphone_content_set_encoding(LinphoneContent *content, const char *encoding); +LINPHONE_PUBLIC void linphone_content_set_encoding (LinphoneContent *content, const char *encoding); /** * Get the name associated with a RCS file transfer message. It is used to store the original filename of the file to be downloaded from server. * @param[in] content #LinphoneContent object. * @return The name of the content. */ -LINPHONE_PUBLIC const char * linphone_content_get_name(const LinphoneContent *content); +LINPHONE_PUBLIC const char *linphone_content_get_name (const LinphoneContent *content); /** * Set the name associated with a RCS file transfer message. It is used to store the original filename of the file to be downloaded from server. * @param[in] content #LinphoneContent object. * @param[in] name The name of the content. */ -LINPHONE_PUBLIC void linphone_content_set_name(LinphoneContent *content, const char *name); +LINPHONE_PUBLIC void linphone_content_set_name (LinphoneContent *content, const char *name); /** * Tell whether a content is a multipart content. * @param[in] content #LinphoneContent object. * @return A boolean value telling whether the content is multipart or not. */ -LINPHONE_PUBLIC bool_t linphone_content_is_multipart(const LinphoneContent *content); +LINPHONE_PUBLIC bool_t linphone_content_is_multipart (const LinphoneContent *content); /** * Get a part from a multipart content according to its index. @@ -180,7 +184,7 @@ LINPHONE_PUBLIC bool_t linphone_content_is_multipart(const LinphoneContent *cont * @param[in] idx The index of the part to get. * @return A #LinphoneContent object holding the part if found, NULL otherwise. */ -LINPHONE_PUBLIC LinphoneContent * linphone_content_get_part(const LinphoneContent *content, int idx); +LINPHONE_PUBLIC LinphoneContent *linphone_content_get_part (const LinphoneContent *content, int idx); /** * Find a part from a multipart content looking for a part header with a specified value. @@ -189,7 +193,11 @@ LINPHONE_PUBLIC LinphoneContent * linphone_content_get_part(const LinphoneConten * @param[in] header_value The value of the header to look for. * @return A #LinphoneContent object object the part if found, NULL otherwise. */ -LINPHONE_PUBLIC LinphoneContent * linphone_content_find_part_by_header(const LinphoneContent *content, const char *header_name, const char *header_value); +LINPHONE_PUBLIC LinphoneContent *linphone_content_find_part_by_header ( + const LinphoneContent *content, + const char *header_name, + const char *header_value +); /** * Get a custom header value of a content. @@ -197,29 +205,29 @@ LINPHONE_PUBLIC LinphoneContent * linphone_content_find_part_by_header(const Lin * @param[in] header_name The name of the header to get the value from. * @return The value of the header if found, NULL otherwise. */ -LINPHONE_PUBLIC const char * linphone_content_get_custom_header(const LinphoneContent *content, const char *header_name); +LINPHONE_PUBLIC const char *linphone_content_get_custom_header (const LinphoneContent *content, const char *header_name); /** * Get the key associated with a RCS file transfer message if encrypted * @param[in] content #LinphoneContent object. * @return The key to encrypt/decrypt the file associated to this content. */ -LINPHONE_PUBLIC const char *linphone_content_get_key(const LinphoneContent *content); +LINPHONE_PUBLIC const char *linphone_content_get_key (const LinphoneContent *content); /** * Get the size of key associated with a RCS file transfer message if encrypted * @param[in] content #LinphoneContent object. * @return The key size in bytes */ -LINPHONE_PUBLIC size_t linphone_content_get_key_size(const LinphoneContent *content); +LINPHONE_PUBLIC size_t linphone_content_get_key_size (const LinphoneContent *content); /** * Set the key associated with a RCS file transfer message if encrypted * @param[in] content #LinphoneContent object. * @param[in] key The key to be used to encrypt/decrypt file associated to this content. - * @param[in] keyLength The lengh of the key. + * @param[in] key_length The lengh of the key. */ -LINPHONE_PUBLIC void linphone_content_set_key(LinphoneContent *content, const char *key, const size_t keyLength); +LINPHONE_PUBLIC void linphone_content_set_key (LinphoneContent *content, const char *key, const size_t key_length); /** * @} @@ -229,4 +237,4 @@ LINPHONE_PUBLIC void linphone_content_set_key(LinphoneContent *content, const ch } #endif // ifdef __cplusplus -#endif // ifndef _L_C_CONTENT_H_ \ No newline at end of file +#endif // ifndef _L_C_CONTENT_H_ diff --git a/src/c-wrapper/api/c-address.cpp b/src/c-wrapper/api/c-address.cpp index a07fec135..dbbe793bc 100644 --- a/src/c-wrapper/api/c-address.cpp +++ b/src/c-wrapper/api/c-address.cpp @@ -131,11 +131,11 @@ void linphone_address_clean (LinphoneAddress *address) { } char *linphone_address_as_string (const LinphoneAddress *address) { - return ms_strdup(L_GET_CPP_PTR_FROM_C_OBJECT(address)->asString().c_str()); + return bctbx_strdup(L_GET_CPP_PTR_FROM_C_OBJECT(address)->asString().c_str()); } char *linphone_address_as_string_uri_only (const LinphoneAddress *address) { - return ms_strdup(L_GET_CPP_PTR_FROM_C_OBJECT(address)->asStringUriOnly().c_str()); + return bctbx_strdup(L_GET_CPP_PTR_FROM_C_OBJECT(address)->asStringUriOnly().c_str()); } bool_t linphone_address_weak_equal (const LinphoneAddress *address1, const LinphoneAddress *address2) { diff --git a/src/c-wrapper/api/c-chat-message.cpp b/src/c-wrapper/api/c-chat-message.cpp index a8e8f923f..12314bf52 100644 --- a/src/c-wrapper/api/c-chat-message.cpp +++ b/src/c-wrapper/api/c-chat-message.cpp @@ -43,7 +43,9 @@ static void _linphone_chat_message_constructor (LinphoneChatMessage *msg); static void _linphone_chat_message_destructor (LinphoneChatMessage *msg); L_DECLARE_C_OBJECT_IMPL_WITH_XTORS(ChatMessage, - _linphone_chat_message_constructor, _linphone_chat_message_destructor, + _linphone_chat_message_constructor, + _linphone_chat_message_destructor, + LinphoneChatMessageCbs *cbs; LinphoneAddress *from; // cache for shared_ptr
LinphoneAddress *to; // cache for shared_ptr diff --git a/src/c-wrapper/api/c-content.cpp b/src/c-wrapper/api/c-content.cpp index 0d92a6243..a75eda44d 100644 --- a/src/c-wrapper/api/c-content.cpp +++ b/src/c-wrapper/api/c-content.cpp @@ -21,167 +21,161 @@ #include "linphone/wrapper_utils.h" #include "c-wrapper/c-wrapper.h" - -#include "content/content.h" #include "content/content-type.h" -#include "content/header/header-param.h" -#include "content/header/header.h" -#include "content/content-manager.h" #include "content/file-content.h" #include "content/file-transfer-content.h" +#include "content/header/header-param.h" // ============================================================================= using namespace std; -L_DECLARE_C_CLONABLE_OBJECT_IMPL(Content, - void *cryptoContext; /**< crypto context used to encrypt file for RCS file transfer */ - mutable char *name; - mutable char *type; - mutable char *subtype; - mutable char *body; +static void _linphone_content_constructor (LinphoneContent *content); +static void _linphone_content_destructor (LinphoneContent *content); + +L_DECLARE_C_CLONABLE_OBJECT_IMPL_WITH_XTORS(Content, + _linphone_content_constructor, + _linphone_content_destructor, + + void *cryptoContext; // Used to encrypt file for RCS file transfer. + mutable size_t size; - mutable char *encoding; mutable char *key; + + struct Cache { + string name; + string type; + string subtype; + string encoding; + } mutable cache; ) +static void _linphone_content_constructor (LinphoneContent *content) { + new(&content->cache) LinphoneContent::Cache(); +} + +static void _linphone_content_destructor (LinphoneContent *content) { + content->cache.~Cache(); +} + // ============================================================================= // Reference and user data handling functions. // ============================================================================= -LinphoneContent * linphone_content_ref(LinphoneContent *content) { +LinphoneContent *linphone_content_ref (LinphoneContent *content) { belle_sip_object_ref(content); return content; } -void linphone_content_unref(LinphoneContent *content) { +void linphone_content_unref (LinphoneContent *content) { belle_sip_object_unref(content); } -void *linphone_content_get_user_data(const LinphoneContent *content) { +void *linphone_content_get_user_data (const LinphoneContent *content) { return L_GET_USER_DATA_FROM_C_OBJECT(content); } -void linphone_content_set_user_data(LinphoneContent *content, void *ud) { - return L_SET_USER_DATA_FROM_C_OBJECT(content, ud); +void linphone_content_set_user_data (LinphoneContent *content, void *user_data) { + return L_SET_USER_DATA_FROM_C_OBJECT(content, user_data); } // ============================================================================= -const char * linphone_content_get_type(const LinphoneContent *content) { - if (content->type) bctbx_free(content->type); - content->type = bctbx_strdup(L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType().getType())); - return content->type; +const char *linphone_content_get_type (const LinphoneContent *content) { + return L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType().getType().c_str(); } -void linphone_content_set_type(LinphoneContent *content, const char *type) { - LinphonePrivate::ContentType ct = L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType(); - ct.setType(L_C_TO_STRING(type)); - L_GET_CPP_PTR_FROM_C_OBJECT(content)->setContentType(ct); +void linphone_content_set_type (LinphoneContent *content, const char *type) { + LinphonePrivate::ContentType contentType = L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType(); + contentType.setType(L_C_TO_STRING(type)); + L_GET_CPP_PTR_FROM_C_OBJECT(content)->setContentType(contentType); } -const char * linphone_content_get_subtype(const LinphoneContent *content) { - if (content->subtype) bctbx_free(content->subtype); - content->subtype = bctbx_strdup(L_STRING_TO_C(L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType().getSubType())); - return content->subtype; +const char *linphone_content_get_subtype (const LinphoneContent *content) { + return L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType().getSubType().c_str(); } -void linphone_content_set_subtype(LinphoneContent *content, const char *subtype) { - LinphonePrivate::ContentType ct = L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType(); - ct.setSubType(L_C_TO_STRING(subtype)); - L_GET_CPP_PTR_FROM_C_OBJECT(content)->setContentType(ct); +void linphone_content_set_subtype (LinphoneContent *content, const char *subtype) { + LinphonePrivate::ContentType contentType = L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType(); + contentType.setSubType(L_C_TO_STRING(subtype)); + L_GET_CPP_PTR_FROM_C_OBJECT(content)->setContentType(contentType); } -void linphone_content_add_content_type_parameter(LinphoneContent *content, const char *name, const char *value) { - LinphonePrivate::ContentType ct = L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType(); - ct.addParameter(L_C_TO_STRING(name), L_C_TO_STRING(value)); - L_GET_CPP_PTR_FROM_C_OBJECT(content)->setContentType(ct); +void linphone_content_add_content_type_parameter (LinphoneContent *content, const char *name, const char *value) { + LinphonePrivate::ContentType contentType = L_GET_CPP_PTR_FROM_C_OBJECT(content)->getContentType(); + contentType.addParameter(L_C_TO_STRING(name), L_C_TO_STRING(value)); + L_GET_CPP_PTR_FROM_C_OBJECT(content)->setContentType(contentType); } -uint8_t * linphone_content_get_buffer(const LinphoneContent *content) { +uint8_t *linphone_content_get_buffer (const LinphoneContent *content) { return (uint8_t *)linphone_content_get_string_buffer(content); } -void linphone_content_set_buffer(LinphoneContent *content, const uint8_t *buffer, size_t size) { +void linphone_content_set_buffer (LinphoneContent *content, const uint8_t *buffer, size_t size) { L_GET_CPP_PTR_FROM_C_OBJECT(content)->setBody(buffer, size); } -const char * linphone_content_get_string_buffer(const LinphoneContent *content) { - if (content->body) bctbx_free(content->body); - content->body = bctbx_strdup(L_GET_CPP_PTR_FROM_C_OBJECT(content)->getBodyAsUtf8String().c_str()); - return content->body; +const char *linphone_content_get_string_buffer (const LinphoneContent *content) { + return L_GET_CPP_PTR_FROM_C_OBJECT(content)->getBodyAsUtf8String().c_str(); } -void linphone_content_set_string_buffer(LinphoneContent *content, const char *buffer) { +void linphone_content_set_string_buffer (LinphoneContent *content, const char *buffer) { L_GET_CPP_PTR_FROM_C_OBJECT(content)->setBodyFromUtf8(L_C_TO_STRING(buffer)); } -size_t linphone_content_get_size(const LinphoneContent *content) { - const LinphonePrivate::Content *c = L_GET_CPP_PTR_FROM_C_OBJECT(content); - size_t size = 0; - if (c->isFile()) { - const LinphonePrivate::FileContent *fc = static_cast