Skip to content

Commit

Permalink
Add siprec extension: handle incoming INVITE with siprec (#4132)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorooshm78 authored Jan 8, 2025
1 parent 709ecdc commit 67db8de
Show file tree
Hide file tree
Showing 19 changed files with 604 additions and 3 deletions.
12 changes: 12 additions & 0 deletions pjmedia/include/pjmedia/sdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,18 @@ PJ_DECL(pjmedia_sdp_attr*) pjmedia_sdp_attr_create_ssrc(pj_pool_t *pool,
const pj_str_t *cname);


/**
* Create a=label attribute.
*
* @param pool Pool to create the attribute.
* @param attr Attribute to create.
*
* @return SDP label attribute.
*/
PJ_DECL(pjmedia_sdp_attr*) pjmedia_sdp_attr_create_label(pj_pool_t *pool,
const pj_str_t *label_str);


/* **************************************************************************
* SDP CONNECTION INFO
****************************************************************************
Expand Down
15 changes: 15 additions & 0 deletions pjmedia/src/pjmedia/sdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,21 @@ PJ_DEF(pjmedia_sdp_attr*) pjmedia_sdp_attr_create_ssrc( pj_pool_t *pool,
}


PJ_DEF(pjmedia_sdp_attr*) pjmedia_sdp_attr_create_label(pj_pool_t *pool,
const pj_str_t *label_str)
{
pjmedia_sdp_attr *attr;

attr = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_attr);
attr->name = pj_str("label");
attr->value.ptr = (char *)pj_pool_alloc(pool, label_str->slen);
pj_memcpy(attr->value.ptr, label_str->ptr, label_str->slen);
attr->value.slen = label_str->slen;

return attr;
}


PJ_DEF(pj_status_t) pjmedia_sdp_attr_to_rtpmap(pj_pool_t *pool,
const pjmedia_sdp_attr *attr,
pjmedia_sdp_rtpmap **p_rtpmap)
Expand Down
2 changes: 1 addition & 1 deletion pjsip/build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export PJSIP_LDFLAGS += $(PJLIB_UTIL_LDLIB) \
export PJSIP_UA_SRCDIR = ../src/pjsip-ua
export PJSIP_UA_OBJS += $(OS_OBJS) $(M_OBJS) $(CC_OBJS) $(HOST_OBJS) \
sip_inv.o sip_reg.o sip_replaces.o sip_xfer.o \
sip_100rel.o sip_timer.o
sip_100rel.o sip_timer.o sip_siprec.o
export PJSIP_UA_CFLAGS += $(_CFLAGS)
export PJSIP_UA_CXXFLAGS += $(_CXXFLAGS)
export PJSIP_UA_LDFLAGS += $(PJSIP_SIMPLE_LDLIB) \
Expand Down
8 changes: 8 additions & 0 deletions pjsip/build/pjsip_ua.vcproj
Original file line number Diff line number Diff line change
Expand Up @@ -3468,6 +3468,10 @@
RelativePath="..\src\pjsip-ua\sip_timer.c"
>
</File>
<File
RelativePath="..\src\pjsip-ua\sip_siprec.c"
>
</File>
<File
RelativePath="..\src\pjsip-ua\sip_xfer.c"
>
Expand Down Expand Up @@ -3609,6 +3613,10 @@
RelativePath="..\include\pjsip-ua\sip_timer.h"
>
</File>
<File
RelativePath="..\include\pjsip-ua\sip_siprec.h"
>
</File>
<File
RelativePath="..\include\pjsip-ua\sip_xfer.h"
>
Expand Down
2 changes: 2 additions & 0 deletions pjsip/build/pjsip_ua.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@
<ClCompile Include="..\src\pjsip-ua\sip_reg.c" />
<ClCompile Include="..\src\pjsip-ua\sip_replaces.c" />
<ClCompile Include="..\src\pjsip-ua\sip_timer.c" />
<ClCompile Include="..\src\pjsip-ua\sip_siprec.c" />
<ClCompile Include="..\src\pjsip-ua\sip_xfer.c" />
</ItemGroup>
<ItemGroup>
Expand All @@ -687,6 +688,7 @@
<ClInclude Include="..\include\pjsip-ua\sip_regc.h" />
<ClInclude Include="..\include\pjsip-ua\sip_replaces.h" />
<ClInclude Include="..\include\pjsip-ua\sip_timer.h" />
<ClInclude Include="..\include\pjsip-ua\sip_siprec.h" />
<ClInclude Include="..\include\pjsip-ua\sip_xfer.h" />
<ClInclude Include="..\include\pjsip_ua.h" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions pjsip/build/pjsip_ua.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<ClCompile Include="..\src\pjsip-ua\sip_timer.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\pjsip-ua\sip_siprec.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\pjsip-ua\sip_xfer.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand All @@ -49,6 +52,9 @@
<ClInclude Include="..\include\pjsip-ua\sip_timer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\pjsip-ua\sip_siprec.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\pjsip-ua\sip_xfer.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down
10 changes: 10 additions & 0 deletions pjsip/include/pjsip-ua/sip_inv.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,17 @@ enum pjsip_inv_option
* Require trickle ICE support.
*/
PJSIP_INV_REQUIRE_TRICKLE_ICE = 512,

/**
* Require siprec support.
*/
PJSIP_INV_REQUIRE_SIPREC = 1024,

/**
* Indicate support for siprec
*/
PJSIP_INV_SUPPORT_SIPREC = 2048,

};

/* Forward declaration of Session Timers */
Expand Down
131 changes: 131 additions & 0 deletions pjsip/include/pjsip-ua/sip_siprec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (C) 2024 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2024 Green and Silver Leaves. (https://github.com/BSVN)
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __PJSIP_SIPREC_H__
#define __PJSIP_SIPREC_H__

/**
* @file sip_siprec.h
* @brief SIP Session Recording Protocol (siprec)
* support (RFC 7866 - Session Recording Protocol in SIP)
*/


#include <pjsip-ua/sip_inv.h>
#include <pjsip/sip_msg.h>

/**
* @defgroup PJSIP_SIPREC SIP Session Recording Protocol (siprec)
* support (RFC 7866 - Session Recording Protocol in SIP)
* @brief SIP Session Recording Protocol support
* (RFC 7866 - Session Recording Protocol in SIP)
* @{
*
* \section PJSIP_SIPREC_REFERENCE References
*
* References:
* - <A HREF="http://www.ietf.org/rfc/rfc7866.txt">
* RFC 7866: Session Recording Protocol (siprec)
* in the Session Initiation Protocol (SIP)</A>
*/
PJ_BEGIN_DECL

/**
* Initialize siprec module. This function must be called once during
* application initialization, to register siprec module to SIP endpoint.
*
* @param endpt The SIP endpoint instance.
*
* @return PJ_SUCCESS if module is successfully initialized.
*/
PJ_DECL(pj_status_t) pjsip_siprec_init_module(pjsip_endpoint *endpt);


/**
* Check if the value of Require header is equal to siprec.
*
* @param req_hdr Require header.
*
* @return PJ_TRUE if value of Require header is equal to siprec.
*/
PJ_DECL(pj_status_t)
pjsip_siprec_verify_require_hdr(pjsip_require_hdr *req_hdr);


/**
* Verifies that the incoming request has the siprec value
* in the Require header and "+sip.src" parameter exist in the Contact header.
* If both conditions are met, according to RFC 7866,
* the INVITE request is a siprec. Otherwise,
* no changes are made to the request. if INVITE request is a siprec
* must have media attribute label exist in the SDP
*
* @param rdata The incoming request to be verified.
* @param metadata The siprec metadata information
* @param sdp_offer The SDP media.
* @param options The options argument is bitmask combination of SIP
* features in pjsip_inv_option enumeration
* @param dlg The dialog instance.
* @param endpt Media endpoint instance.
* @param p_tdata Upon error, it will be filled with the final response
* to be sent to the request sender.
*
* @return The function returns the following:
* - If the request includes the value siprec in the Require header
* and also includes "+sip.src" in the Contact header.
* PJ_SUCCESS and set PJSIP_INV_REQUIRE_SIPREC to options
* - Upon error condition (as described by RFC 7866), the
* function returns non-PJ_SUCCESS, and \a p_tdata
* parameter SHOULD be set with a final response message
* to be sent to the sender of the request.
*/
PJ_DECL(pj_status_t) pjsip_siprec_verify_request(pjsip_rx_data *rdata,
pj_str_t *metadata,
pjmedia_sdp_session *sdp_offer,
unsigned *options,
pjsip_dialog *dlg,
pjsip_endpoint *endpt,
pjsip_tx_data **p_tdata);


/**
* Find siprec metadata information from the message body
* with "rs-metadata" Content-Type.
*
* @param pool Pool to allocate memory.
* @param body The message body.
* @param metadata If metadata is found, this variable will be
* populated with the extracted data.
*
* @return Return PJ_SUCCESS if metadata is found,
* otherwise return PJ_ENOTFOUND.
*/
PJ_DECL(pj_status_t) pjsip_siprec_get_metadata(pj_pool_t *pool,
pjsip_msg_body *body,
pj_str_t* metadata);


PJ_END_DECL


/**
* @}
*/


#endif /* __PJSIP_SIPREC_H__ */
1 change: 1 addition & 0 deletions pjsip/include/pjsip_ua.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <pjsip-ua/sip_xfer.h>
#include <pjsip-ua/sip_100rel.h>
#include <pjsip-ua/sip_timer.h>
#include <pjsip-ua/sip_siprec.h>


#endif /* __PJSIP_UA_H__ */
Expand Down
43 changes: 43 additions & 0 deletions pjsip/include/pjsua-lib/pjsua.h
Original file line number Diff line number Diff line change
Expand Up @@ -2140,6 +2140,32 @@ typedef enum pjsua_sip_timer_use
} pjsua_sip_timer_use;


/**
* This enumeration specifies the usage of SIPREC extension.
*/
typedef enum pjsua_sip_siprec_use
{
/**
* When this flag is specified, when a SIPREC request is received, it
* returns bad extension error. and SIPREC calls will not be established.
*/
PJSUA_SIP_SIPREC_INACTIVE,

/**
* When this flag is specified, when you want both regular calls and
* SIPREC calls to be established.
*/
PJSUA_SIP_SIPREC_OPTIONAL,

/**
* When this flag is specified, when you want only SIPREC calls to
* be established, and regular calls are rejected.
*/
PJSUA_SIP_SIPREC_MANDATORY,

} pjsua_sip_siprec_use;


/**
* This constants controls the use of 100rel extension.
*/
Expand Down Expand Up @@ -2343,6 +2369,15 @@ typedef struct pjsua_config
*/
pjsua_sip_timer_use use_timer;

/**
* Specify the usage of SIPREC sessions. See the
* #pjsua_sip_siprec_use for possible values. Note that this setting can be
* further customized in account configuration (#pjsua_acc_config).
*
* Default: PJSUA_SIP_SIPREC_INACTIVE
*/
pjsua_sip_siprec_use use_siprec;

/**
* Handle unsolicited NOTIFY requests containing message waiting
* indication (MWI) info. Unsolicited MWI is incoming NOTIFY requests
Expand Down Expand Up @@ -4065,6 +4100,14 @@ typedef struct pjsua_acc_config
*/
pjsua_sip_timer_use use_timer;

/**
* Specify the usage of SIPREC sessions. See the
* #pjsua_sip_siprec_use for possible values.
*
* Default: PJSUA_SIP_SIPREC_INACTIVE
*/
pjsua_sip_siprec_use use_siprec;

/**
* Specify Session Timer settings, see #pjsip_timer_setting.
*/
Expand Down
1 change: 1 addition & 0 deletions pjsip/include/pjsua-lib/pjsua_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ struct pjsua_call
unsigned hangup_code; /**< Hangup code. */
pj_str_t hangup_reason; /**< Hangup reason. */
pjsua_msg_data *hangup_msg_data;/**< Hangup message data. */
pj_str_t siprec_metadata;/** siprec metadata in body */
};


Expand Down
9 changes: 9 additions & 0 deletions pjsip/include/pjsua2/account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,14 @@ struct AccountCallConfig : public PersistentObject
*/
pjsua_sip_timer_use timerUse;

/**
* Specify the usage of SIPREC INVITE request. See the
* pjsua_sip_siprec_use for possible values.
*
* Default: PJSUA_SIP_SIPREC_INACTIVE
*/
pjsua_sip_siprec_use siprecUse;

/**
* Specify minimum Session Timer expiration period, in seconds.
* Must not be lower than 90. Default is 90.
Expand All @@ -363,6 +371,7 @@ struct AccountCallConfig : public PersistentObject
AccountCallConfig() : holdType(PJSUA_CALL_HOLD_TYPE_DEFAULT),
prackUse(PJSUA_100REL_NOT_USED),
timerUse(PJSUA_SIP_TIMER_OPTIONAL),
siprecUse(PJSUA_SIP_SIPREC_INACTIVE),
timerMinSESec(90),
timerSessExpiresSec(PJSIP_SESS_TIMER_DEF_SE)
{}
Expand Down
Loading

0 comments on commit 67db8de

Please sign in to comment.