diff --git a/coreapi/callbacks.c b/coreapi/callbacks.c index e83c4bac4..e2a672940 100644 --- a/coreapi/callbacks.c +++ b/coreapi/callbacks.c @@ -640,9 +640,11 @@ static void message_delivery_update(SalOp *op, SalMessageDeliveryStatus status){ } } -static void info_received(SalOp *op, SalBodyHandler *body_handler){ - LinphoneCore *lc=(LinphoneCore *)op->get_sal()->get_user_pointer(); - linphone_core_notify_info_message(lc,op,body_handler); +static void info_received(SalOp *op, SalBodyHandler *body_handler) { + LinphonePrivate::CallSession *session = reinterpret_cast(op->get_user_pointer()); + if (!session) + return; + L_GET_PRIVATE(session)->infoReceived(body_handler); } static void subscribe_response(SalOp *op, SalSubscribeStatus status, int will_retry){ diff --git a/coreapi/info.c b/coreapi/info.c index fb1cd4a17..5b12089bb 100644 --- a/coreapi/info.c +++ b/coreapi/info.c @@ -84,8 +84,10 @@ const char *linphone_info_message_get_header(const LinphoneInfoMessage *im, cons return sal_custom_header_find(im->headers,name); } -void linphone_info_message_set_content(LinphoneInfoMessage *im, const LinphoneContent *content){ - im->content=linphone_content_copy(content); +void linphone_info_message_set_content (LinphoneInfoMessage *im, const LinphoneContent *content) { + if (im->content) + linphone_content_unref(im->content); + im->content = linphone_content_copy(content); } const LinphoneContent * linphone_info_message_get_content(const LinphoneInfoMessage *im){ @@ -96,17 +98,11 @@ SalCustomHeader *linphone_info_message_get_headers (const LinphoneInfoMessage *i return im->headers; } -void linphone_core_notify_info_message ( - LinphoneCore* lc, - LinphonePrivate::SalOp *op, - SalBodyHandler *body_handler -) { - LinphoneCall *call=(LinphoneCall*)op->get_user_pointer(); - if (call){ - LinphoneInfoMessage *info=linphone_core_create_info_message(lc); - info->headers=sal_custom_header_clone(op->get_recv_custom_header()); - if (body_handler) info->content=linphone_content_from_sal_body_handler(body_handler); - linphone_call_notify_info_message_received(call, info); - linphone_info_message_unref(info); +void linphone_info_message_set_headers (LinphoneInfoMessage *im, const SalCustomHeader *headers) { + if (im->headers) { + sal_custom_header_free(im->headers); + im->headers = nullptr; } + if (headers) + im->headers = sal_custom_header_clone(headers); } diff --git a/coreapi/private.h b/coreapi/private.h index da493d8f5..7270f010b 100644 --- a/coreapi/private.h +++ b/coreapi/private.h @@ -1152,7 +1152,6 @@ const char *linphone_core_create_uuid(LinphoneCore *lc); void linphone_configure_op(LinphoneCore *lc, LinphonePrivate::SalOp *op, const LinphoneAddress *dest, SalCustomHeader *headers, bool_t with_contact); void linphone_configure_op_with_proxy(LinphoneCore *lc, LinphonePrivate::SalOp *op, const LinphoneAddress *dest, SalCustomHeader *headers, bool_t with_contact, LinphoneProxyConfig *proxy); void linphone_call_create_op(LinphoneCall *call); -void linphone_core_notify_info_message(LinphoneCore* lc,LinphonePrivate::SalOp *op, SalBodyHandler *body); LinphoneContent * linphone_content_new(void); LinphoneContent * linphone_content_copy(const LinphoneContent *ref); SalBodyHandler *sal_body_handler_from_content(const LinphoneContent *content); @@ -1586,6 +1585,7 @@ LinphoneNatPolicy * linphone_config_create_nat_policy_from_section(const Linphon SalCustomHeader *linphone_info_message_get_headers (const LinphoneInfoMessage *im); +void linphone_info_message_set_headers (LinphoneInfoMessage *im, const SalCustomHeader *headers); #ifdef __cplusplus diff --git a/include/linphone/info_message.h b/include/linphone/info_message.h index 06a59ee2a..ce92628e6 100644 --- a/include/linphone/info_message.h +++ b/include/linphone/info_message.h @@ -57,7 +57,7 @@ LINPHONE_PUBLIC const char *linphone_info_message_get_header(const LinphoneInfoM * @param content the content described as a #LinphoneContent structure. * All fields of the LinphoneContent are copied, thus the application can destroy/modify/recycloe the content object freely ater the function returns. **/ -LINPHONE_PUBLIC void linphone_info_message_set_content(LinphoneInfoMessage *im, const LinphoneContent *content); +LINPHONE_PUBLIC void linphone_info_message_set_content(LinphoneInfoMessage *im, const LinphoneContent *content); /** * Returns the info message's content as a #LinphoneContent structure. diff --git a/src/call/call-listener.h b/src/call/call-listener.h index 6a2feab41..44f721518 100644 --- a/src/call/call-listener.h +++ b/src/call/call-listener.h @@ -38,6 +38,7 @@ public: virtual void onCheckForAcceptation () = 0; virtual void onIncomingCallStarted () = 0; virtual void onIncomingCallToBeAdded () = 0; + virtual void onInfoReceived (const LinphoneInfoMessage *im) = 0; virtual void onEncryptionChanged (bool activated, const std::string &authToken) = 0; diff --git a/src/call/call-p.h b/src/call/call-p.h index 5c75fa610..a8e5666b2 100644 --- a/src/call/call-p.h +++ b/src/call/call-p.h @@ -77,6 +77,7 @@ private: void onCheckForAcceptation () override; void onIncomingCallStarted () override; void onIncomingCallToBeAdded () override; + void onInfoReceived (const LinphoneInfoMessage *im) override; void onEncryptionChanged (bool activated, const std::string &authToken) override; void onStatsUpdated (const LinphoneCallStats *stats) override; void onResetCurrentCall () override; diff --git a/src/call/call.cpp b/src/call/call.cpp index d371c5a1b..9d6341f04 100644 --- a/src/call/call.cpp +++ b/src/call/call.cpp @@ -177,6 +177,11 @@ void CallPrivate::onIncomingCallToBeAdded () { linphone_core_add_call(core, lcall); } +void CallPrivate::onInfoReceived (const LinphoneInfoMessage *im) { + if (lcall) + linphone_call_notify_info_message_received(lcall, im); +} + void CallPrivate::onEncryptionChanged (bool activated, const string &authToken) { if (lcall) linphone_call_notify_encryption_changed(lcall, activated, authToken.empty() ? nullptr : authToken.c_str()); diff --git a/src/conference/conference.cpp b/src/conference/conference.cpp index 7c930cc24..15424caef 100644 --- a/src/conference/conference.cpp +++ b/src/conference/conference.cpp @@ -170,6 +170,12 @@ void Conference::onIncomingCallSessionStarted (const shared_ptrcallListener->onIncomingCallStarted(); } +void Conference::onInfoReceived (const std::shared_ptr &session, const LinphoneInfoMessage *im) { + L_D(); + if (d->callListener) + d->callListener->onInfoReceived(im); +} + void Conference::onEncryptionChanged (const shared_ptr &session, bool activated, const string &authToken) { L_D(); if (d->callListener) diff --git a/src/conference/conference.h b/src/conference/conference.h index 467dde80c..de8e29de4 100644 --- a/src/conference/conference.h +++ b/src/conference/conference.h @@ -74,6 +74,7 @@ private: void onCallSessionStateChanged (const std::shared_ptr &session, LinphoneCallState state, const std::string &message) override; void onCheckForAcceptation (const std::shared_ptr &session) override; void onIncomingCallSessionStarted (const std::shared_ptr &session) override; + void onInfoReceived (const std::shared_ptr &session, const LinphoneInfoMessage *im) override; void onEncryptionChanged (const std::shared_ptr &session, bool activated, const std::string &authToken) override; void onStatsUpdated (const LinphoneCallStats *stats) override; void onResetCurrentSession (const std::shared_ptr &session) override; diff --git a/src/conference/session/call-session-listener.h b/src/conference/session/call-session-listener.h index a0d7e9520..0259138dd 100644 --- a/src/conference/session/call-session-listener.h +++ b/src/conference/session/call-session-listener.h @@ -38,6 +38,7 @@ public: virtual void onCallSessionStateChanged (const std::shared_ptr &session, LinphoneCallState state, const std::string &message) = 0; virtual void onCheckForAcceptation (const std::shared_ptr &session) = 0; virtual void onIncomingCallSessionStarted (const std::shared_ptr &session) = 0; + virtual void onInfoReceived (const std::shared_ptr &session, const LinphoneInfoMessage *im) = 0; virtual void onEncryptionChanged (const std::shared_ptr &session, bool activated, const std::string &authToken) = 0; diff --git a/src/conference/session/call-session-p.h b/src/conference/session/call-session-p.h index 6f7e0fc3f..a607f26ac 100644 --- a/src/conference/session/call-session-p.h +++ b/src/conference/session/call-session-p.h @@ -49,6 +49,7 @@ public: void ackBeingSent (LinphoneHeaders *headers); virtual void ackReceived (LinphoneHeaders *headers); virtual bool failure (); + void infoReceived (SalBodyHandler *bodyHandler); void pingReply (); virtual void remoteRinging (); virtual void terminated (); diff --git a/src/conference/session/call-session.cpp b/src/conference/session/call-session.cpp index b5d333881..d322ba057 100644 --- a/src/conference/session/call-session.cpp +++ b/src/conference/session/call-session.cpp @@ -322,6 +322,20 @@ bool CallSessionPrivate::failure () { return false; } +void CallSessionPrivate::infoReceived (SalBodyHandler *bodyHandler) { + L_Q(); + LinphoneInfoMessage *info = linphone_core_create_info_message(core); + linphone_info_message_set_headers(info, op->get_recv_custom_header()); + if (bodyHandler) { + LinphoneContent *content = linphone_content_from_sal_body_handler(bodyHandler); + linphone_info_message_set_content(info, content); + linphone_content_unref(content); + } + if (listener) + listener->onInfoReceived(q->getSharedFromThis(), info); + linphone_info_message_unref(info); +} + void CallSessionPrivate::pingReply () { L_Q(); if (state == LinphoneCallOutgoingInit) {