Group PJSUA_LIB_ACC¶
- group PJSUA_LIB_ACC
PJSUA Accounts management.
PJSUA accounts provide identity (or identities) of the user who is currently using the application. In SIP terms, the identity is used as the From header in outgoing requests.
PJSUA-API supports creating and managing multiple accounts. The maximum number of accounts is limited by a compile time constant
PJSUA_MAX_ACC
.Account may or may not have client registration associated with it. An account is also associated with route set and some authentication credentials, which are used when sending SIP request messages using the account. An account also has presence’s online status, which will be reported to remote peer when they subscribe to the account’s presence, or which is published to a presence server if presence publication is enabled for the account.
At least one account MUST be created in the application. If no user association is required, application can create a userless account by calling pjsua_acc_add_local(). A userless account identifies local endpoint instead of a particular user, and it correspond with a particular transport instance.
Also one account must be set as the default account, which is used as the account to use when PJSUA fails to match a request with any other accounts.
When sending outgoing SIP requests (such as making calls or sending instant messages), normally PJSUA requires the application to specify which account to use for the request. If no account is specified, PJSUA may be able to select the account by matching the destination domain name, and fall back to default account when no match is found.
Defines
-
PJSUA_MAX_ACC¶
Maximum accounts.
-
PJSUA_REG_INTERVAL¶
Default registration interval.
-
PJSUA_UNREG_TIMEOUT¶
Default maximum time to wait for account unregistration transactions to complete during library shutdown sequence.
Default: 4000 (4 seconds)
-
PJSUA_PUBLISH_EXPIRATION¶
Default PUBLISH expiration
-
PJSUA_DEFAULT_ACC_PRIORITY¶
Default account priority.
-
PJSUA_UNPUBLISH_MAX_WAIT_TIME_MSEC¶
Maximum time to wait for unpublication transaction(s) to complete during shutdown process, before sending unregistration. The library tries to wait for the unpublication (un-PUBLISH) to complete before sending REGISTER request to unregister the account, during library shutdown process. If the value is set too short, it is possible that the unregistration is sent before unpublication completes, causing unpublication request to fail.
Default: 2000 (2 seconds)
-
PJSUA_REG_RETRY_INTERVAL¶
Default auto retry re-registration interval, in seconds. Set to 0 to disable this. Application can set the timer on per account basis by setting the pjsua_acc_config.reg_retry_interval field instead.
Default: 300 (5 minutes)
-
PJSUA_CONTACT_REWRITE_METHOD¶
This macro specifies the default value for contact_rewrite_method field in pjsua_acc_config. It specifies how Contact update will be done with the registration, if allow_contact_rewrite is enabled in the account config. See pjsua_contact_rewrite_method for the options.
Value PJSUA_CONTACT_REWRITE_UNREGISTER(1) is the legacy behavior.
Default value: PJSUA_CONTACT_REWRITE_NO_UNREG(2) | PJSUA_CONTACT_REWRITE_ALWAYS_UPDATE(4)
-
PJSUA_REG_USE_OUTBOUND_PROXY¶
Bit value used in pjsua_acc_config.reg_use_proxy field to indicate that the global outbound proxy list should be added to the REGISTER request.
-
PJSUA_REG_USE_ACC_PROXY¶
Bit value used in pjsua_acc_config.reg_use_proxy field to indicate that the account proxy list should be added to the REGISTER request.
-
PJSUA_CALL_HOLD_TYPE_DEFAULT¶
Specify the default call hold type to be used in pjsua_acc_config.
Default is PJSUA_CALL_HOLD_TYPE_RFC3264, and there’s no reason to change this except if you’re communicating with an old/non-standard peer.
Enums
-
enum pjsua_call_hold_type¶
This enumeration specifies how we should offer call hold request to remote peer. The default value is set by compile time constant PJSUA_CALL_HOLD_TYPE_DEFAULT, and application may control the setting on per-account basis by manipulating call_hold_type field in pjsua_acc_config.
Values:
-
enumerator PJSUA_CALL_HOLD_TYPE_RFC3264¶
This will follow RFC 3264 recommendation to use a=sendonly, a=recvonly, and a=inactive attribute as means to signal call hold status. This is the correct value to use.
-
enumerator PJSUA_CALL_HOLD_TYPE_RFC2543¶
This will use the old and deprecated method as specified in RFC 2543, and will offer c=0.0.0.0 in the SDP instead. Using this has many drawbacks such as inability to keep the media transport alive while the call is being put on hold, and should only be used if remote does not understand RFC 3264 style call hold offer.
-
enumerator PJSUA_CALL_HOLD_TYPE_RFC3264¶
-
enum pjsua_stun_use¶
This enumeration controls the use of STUN in the account.
Values:
-
enumerator PJSUA_STUN_USE_DEFAULT¶
Follow the default setting in the global pjsua_config.
-
enumerator PJSUA_STUN_USE_DISABLED¶
Disable STUN. If STUN is not enabled in the global pjsua_config, this setting has no effect.
-
enumerator PJSUA_STUN_RETRY_ON_FAILURE¶
Retry other STUN servers if the STUN server selected during startup (pjsua_init()) or after calling pjsua_update_stun_servers() is unavailable during runtime. This setting is valid only for account’s media STUN setting and if the call is using UDP media transport.
-
enumerator PJSUA_STUN_USE_DEFAULT¶
-
enum pjsua_ice_config_use¶
This enumeration controls the use of ICE settings in the account.
Values:
-
enumerator PJSUA_ICE_CONFIG_USE_DEFAULT¶
Use the default settings in the global pjsua_media_config.
-
enumerator PJSUA_ICE_CONFIG_USE_CUSTOM¶
Use the custom pjsua_ice_config setting in the account.
-
enumerator PJSUA_ICE_CONFIG_USE_DEFAULT¶
-
enum pjsua_turn_config_use¶
This enumeration controls the use of TURN settings in the account.
Values:
-
enumerator PJSUA_TURN_CONFIG_USE_DEFAULT¶
Use the default setting in the global pjsua_media_config.
-
enumerator PJSUA_TURN_CONFIG_USE_CUSTOM¶
Use the custom pjsua_turn_config setting in the account.
-
enumerator PJSUA_TURN_CONFIG_USE_DEFAULT¶
Functions
-
void pjsua_ice_config_from_media_config(pj_pool_t *pool, pjsua_ice_config *dst, const pjsua_media_config *src)¶
Initialize ICE config from a media config. If the pool argument is NULL, a simple memcpy() will be used.
- Parameters
pool – Memory to duplicate strings.
dst – Destination config.
src – Source config.
-
void pjsua_ice_config_dup(pj_pool_t *pool, pjsua_ice_config *dst, const pjsua_ice_config *src)¶
Clone. If the pool argument is NULL, a simple memcpy() will be used.
- Parameters
pool – Memory to duplicate strings.
dst – Destination config.
src – Source config.
-
void pjsua_turn_config_from_media_config(pj_pool_t *pool, pjsua_turn_config *dst, const pjsua_media_config *src)¶
Initialize TURN config from a media config. If the pool argument is NULL, a simple memcpy() will be used.
- Parameters
pool – Memory to duplicate strings.
dst – Destination config.
src – Source config.
-
void pjsua_turn_config_dup(pj_pool_t *pool, pjsua_turn_config *dst, const pjsua_turn_config *src)¶
Clone. If the pool argument is NULL, a simple memcpy() will be used.
- Parameters
pool – Memory to duplicate strings.
dst – Destination config.
src – Source config.
-
void pjsua_srtp_opt_default(pjsua_srtp_opt *cfg)¶
Call this function to initialize SRTP config with default values.
- Parameters
cfg – The SRTP config to be initialized.
-
void pjsua_srtp_opt_dup(pj_pool_t *pool, pjsua_srtp_opt *dst, const pjsua_srtp_opt *src, pj_bool_t check_str)¶
Duplicate SRTP transport setting. If the pool argument is NULL, a simple memcpy() will be used.
- Parameters
pool – Memory to duplicate strings.
dst – Destination setting.
src – Source setting.
check_str – If set to TRUE, the function will check if strings are identical before copying. Identical strings will not be duplicated. If set to FALSE, all strings will be duplicated.
-
void pjsua_acc_config_default(pjsua_acc_config *cfg)¶
Call this function to initialize account config with default values.
- Parameters
cfg – The account config to be initialized.
-
void pjsua_acc_config_dup(pj_pool_t *pool, pjsua_acc_config *dst, const pjsua_acc_config *src)¶
Duplicate account config.
- Parameters
pool – Pool to be used for duplicating the config.
dst – Destination configuration.
src – Source configuration.
-
unsigned pjsua_acc_get_count(void)¶
Get number of current accounts.
- Returns
Current number of accounts.
-
pj_bool_t pjsua_acc_is_valid(pjsua_acc_id acc_id)¶
Check if the specified account ID is valid.
- Parameters
acc_id – Account ID to check.
- Returns
Non-zero if account ID is valid.
-
pj_status_t pjsua_acc_set_default(pjsua_acc_id acc_id)¶
Set default account to be used when incoming and outgoing requests doesn’t match any accounts.
- Parameters
acc_id – The account ID to be used as default.
- Returns
PJ_SUCCESS on success.
-
pjsua_acc_id pjsua_acc_get_default(void)¶
Get default account to be used when receiving incoming requests (calls), when the destination of the incoming call doesn’t match any other accounts.
- Returns
The default account ID, or PJSUA_INVALID_ID if no default account is configured.
-
pj_status_t pjsua_acc_add(const pjsua_acc_config *acc_cfg, pj_bool_t is_default, pjsua_acc_id *p_acc_id)¶
Add a new account to pjsua. PJSUA must have been initialized (with pjsua_init()) before calling this function. If registration is configured for this account, this function would also start the SIP registration session with the SIP registrar server. This SIP registration session will be maintained internally by the library, and application doesn’t need to do anything to maintain the registration session.
- Parameters
acc_cfg – Account configuration.
is_default – If non-zero, this account will be set as the default account. The default account will be used when sending outgoing requests (e.g. making call) when no account is specified, and when receiving incoming requests when the request does not match any accounts. It is recommended that default account is set to local/LAN account.
p_acc_id – Pointer to receive account ID of the new account.
- Returns
PJ_SUCCESS on success, or the appropriate error code.
-
pj_status_t pjsua_acc_add_local(pjsua_transport_id tid, pj_bool_t is_default, pjsua_acc_id *p_acc_id)¶
Add a local account. A local account is used to identify local endpoint instead of a specific user, and for this reason, a transport ID is needed to obtain the local address information.
- Parameters
tid – Transport ID to generate account address.
is_default – If non-zero, this account will be set as the default account. The default account will be used when sending outgoing requests (e.g. making call) when no account is specified, and when receiving incoming requests when the request does not match any accounts. It is recommended that default account is set to local/LAN account.
p_acc_id – Pointer to receive account ID of the new account.
- Returns
PJ_SUCCESS on success, or the appropriate error code.
-
pj_status_t pjsua_acc_set_user_data(pjsua_acc_id acc_id, void *user_data)¶
Set arbitrary data to be associated with the account.
- Parameters
acc_id – The account ID.
user_data – User/application data.
- Returns
PJ_SUCCESS on success, or the appropriate error code.
-
void *pjsua_acc_get_user_data(pjsua_acc_id acc_id)¶
Retrieve arbitrary data associated with the account.
- Parameters
acc_id – The account ID.
- Returns
The user data. In the case where the account ID is not valid, NULL is returned.
-
pj_status_t pjsua_acc_del(pjsua_acc_id acc_id)¶
Delete an account. This will unregister the account from the SIP server, if necessary, and terminate server side presence subscriptions associated with this account.
- Parameters
acc_id – Id of the account to be deleted.
- Returns
PJ_SUCCESS on success, or the appropriate error code.
-
pj_status_t pjsua_acc_get_config(pjsua_acc_id acc_id, pj_pool_t *pool, pjsua_acc_config *acc_cfg)¶
Get current config for the account. This will copy current account setting to the specified parameter. Note that all pointers in the settings will point to the original settings in the account and application must not modify the values in any way. Application must also take care that these data is only valid until the account is destroyed.
- Parameters
acc_id – The account ID.
pool – Pool to duplicate the config.
acc_cfg – Structure to receive the settings.
- Returns
PJ_SUCCESS on success, or the appropriate error code.
-
pj_status_t pjsua_acc_modify(pjsua_acc_id acc_id, const pjsua_acc_config *acc_cfg)¶
Modify account configuration setting. This function may trigger unregistration (of old account setting) and re-registration (of the new account setting), e.g: changing account ID, credential, registar, or proxy setting.
Note:
when the new config triggers unregistration, the pjsua callback on_reg_state()/on_reg_state2() for the unregistration will not be called and any failure in the unregistration will be ignored, so if application needs to be sure about the unregistration status, it should unregister manually and wait for the callback before calling this function
when the new config triggers re-registration and the re-registration fails, the account setting will not be reverted back to the old setting and the account will be in unregistered state.
- Parameters
acc_id – Id of the account to be modified.
acc_cfg – New account configuration.
- Returns
PJ_SUCCESS on success, or the appropriate error code.
-
pj_status_t pjsua_acc_set_online_status(pjsua_acc_id acc_id, pj_bool_t is_online)¶
Modify account’s presence status to be advertised to remote/presence subscribers. This would trigger the sending of outgoing NOTIFY request if there are server side presence subscription for this account, and/or outgoing PUBLISH if presence publication is enabled for this account.
See also
- Parameters
acc_id – The account ID.
is_online – True of false.
- Returns
PJ_SUCCESS on success, or the appropriate error code.
-
pj_status_t pjsua_acc_set_online_status2(pjsua_acc_id acc_id, pj_bool_t is_online, const pjrpid_element *pr)¶
Modify account’s presence status to be advertised to remote/presence subscribers. This would trigger the sending of outgoing NOTIFY request if there are server side presence subscription for this account, and/or outgoing PUBLISH if presence publication is enabled for this account.
See also
- Parameters
acc_id – The account ID.
is_online – True of false.
pr – Extended information in subset of RPID format which allows setting custom presence text.
- Returns
PJ_SUCCESS on success, or the appropriate error code.
-
pj_status_t pjsua_acc_set_registration(pjsua_acc_id acc_id, pj_bool_t renew)¶
Update registration or perform unregistration. If registration is configured for this account, then initial SIP REGISTER will be sent when the account is added with pjsua_acc_add(). Application normally only need to call this function if it wants to manually update the registration or to unregister from the server.
- Parameters
acc_id – The account ID.
renew – If renew argument is zero, this will start unregistration process.
- Returns
PJ_SUCCESS on success, or the appropriate error code.
-
pj_status_t pjsua_acc_get_info(pjsua_acc_id acc_id, pjsua_acc_info *info)¶
Get information about the specified account.
- Parameters
acc_id – Account identification.
info – Pointer to receive account information.
- Returns
PJ_SUCCESS on success, or the appropriate error code.
-
pj_status_t pjsua_enum_accs(pjsua_acc_id ids[], unsigned *count)¶
Enumerate all account currently active in the library. This will fill the array with the account Ids, and application can then query the account information for each id with pjsua_acc_get_info().
See also
- Parameters
ids – Array of account IDs to be initialized.
count – In input, specifies the maximum number of elements. On return, it contains the actual number of elements.
- Returns
PJ_SUCCESS on success, or the appropriate error code.
-
pj_status_t pjsua_acc_enum_info(pjsua_acc_info info[], unsigned *count)¶
Enumerate account informations.
- Parameters
info – Array of account infos to be initialized.
count – In input, specifies the maximum number of elements. On return, it contains the actual number of elements.
- Returns
PJ_SUCCESS on success, or the appropriate error code.
-
pjsua_acc_id pjsua_acc_find_for_outgoing(const pj_str_t *url)¶
This is an internal function to find the most appropriate account to used to reach to the specified URL.
- Parameters
url – The remote URL to reach.
- Returns
Account id.
-
pjsua_acc_id pjsua_acc_find_for_incoming(pjsip_rx_data *rdata)¶
This is an internal function to find the most appropriate account to be used to handle incoming calls.
- Parameters
rdata – The incoming request message.
- Returns
Account id.
-
pj_status_t pjsua_acc_create_request(pjsua_acc_id acc_id, const pjsip_method *method, const pj_str_t *target, pjsip_tx_data **p_tdata)¶
Create arbitrary requests using the account. Application should only use this function to create auxiliary requests outside dialog, such as OPTIONS, and use the call or presence API to create dialog related requests.
- Parameters
acc_id – The account ID.
method – The SIP method of the request.
target – Target URI.
p_tdata – Pointer to receive the request.
- Returns
PJ_SUCCESS or the error code.
-
pj_status_t pjsua_acc_create_uac_contact(pj_pool_t *pool, pj_str_t *contact, pjsua_acc_id acc_id, const pj_str_t *uri)¶
Create a suitable Contact header value, based on the specified target URI for the specified account.
- Parameters
pool – Pool to allocate memory for the string.
contact – The string where the Contact will be stored.
acc_id – Account ID.
uri – Destination URI of the request.
- Returns
PJ_SUCCESS on success, other on error.
-
pj_status_t pjsua_acc_create_uas_contact(pj_pool_t *pool, pj_str_t *contact, pjsua_acc_id acc_id, pjsip_rx_data *rdata)¶
Create a suitable Contact header value, based on the information in the incoming request.
- Parameters
pool – Pool to allocate memory for the string.
contact – The string where the Contact will be stored.
acc_id – Account ID.
rdata – Incoming request.
- Returns
PJ_SUCCESS on success, other on error.
-
pj_status_t pjsua_acc_set_transport(pjsua_acc_id acc_id, pjsua_transport_id tp_id)¶
Lock/bind this account to a specific transport/listener. Normally application shouldn’t need to do this, as transports will be selected automatically by the stack according to the destination.
When account is locked/bound to a specific transport, all outgoing requests from this account will use the specified transport (this includes SIP registration, dialog (call and event subscription), and out-of-dialog requests such as MESSAGE).
Note that transport_id may be specified in pjsua_acc_config too.
- Parameters
acc_id – The account ID.
tp_id – The transport ID.
- Returns
PJ_SUCCESS on success.
-
struct pjsua_ice_config¶
- #include <pjsua.h>
ICE setting. This setting is used in the pjsua_acc_config.
-
struct pjsua_turn_config¶
- #include <pjsua.h>
TURN setting. This setting is used in the pjsua_acc_config.
-
struct pjsua_acc_config¶
- #include <pjsua.h>
This structure describes account configuration to be specified when adding a new account with pjsua_acc_add(). Application MUST initialize this structure first by calling pjsua_acc_config_default().
-
struct pjsua_acc_info¶
- #include <pjsua.h>
Account info. Application can query account info by calling pjsua_acc_get_info().
-
PJSUA_MAX_ACC¶