本文整理汇总了C++中pj_str函数的典型用法代码示例。如果您正苦于以下问题:C++ pj_str函数的具体用法?C++ pj_str怎么用?C++ pj_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pj_str函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: keep_alive_test
/*
* Keep-alive test.
*/
static int keep_alive_test(pj_stun_config *cfg)
{
struct stun_srv *srv;
struct stun_client *client;
pj_sockaddr_in mapped_addr;
pj_stun_sock_info info;
pj_str_t srv_addr;
pj_time_val timeout, t;
int i, ret = 0;
pj_status_t status;
PJ_LOG(3,(THIS_FILE, " normal operation"));
status = create_client(cfg, &client, PJ_TRUE);
if (status != PJ_SUCCESS)
return -310;
status = create_server(client->pool, cfg->ioqueue, RESPOND_STUN|WITH_XOR_MAPPED, &srv);
if (status != PJ_SUCCESS) {
destroy_client(client);
return -320;
}
/*
* Part 1: initial Binding resolution.
*/
PJ_LOG(3,(THIS_FILE, " initial Binding request"));
srv_addr = pj_str("127.0.0.1");
status = pj_stun_sock_start(client->sock, &srv_addr,
pj_ntohs(srv->addr.ipv4.sin_port), NULL);
if (status != PJ_SUCCESS) {
destroy_server(srv);
destroy_client(client);
return -330;
}
/* Wait until on_status() callback is called with success status */
pj_gettimeofday(&timeout);
timeout.sec += 60;
do {
handle_events(cfg, 100);
pj_gettimeofday(&t);
} while (client->on_status_cnt==0 && PJ_TIME_VAL_LT(t, timeout));
/* Check that callback with correct operation is called */
if (client->last_op != PJ_STUN_SOCK_BINDING_OP) {
PJ_LOG(3,(THIS_FILE, " error: expecting Binding operation status"));
ret = -340;
goto on_return;
}
if (client->last_status != PJ_SUCCESS) {
PJ_LOG(3,(THIS_FILE, " error: expecting PJ_SUCCESS status"));
ret = -350;
goto on_return;
}
/* Check that client doesn't receive anything */
if (client->on_rx_data_cnt != 0) {
PJ_LOG(3,(THIS_FILE, " error: client shouldn't have received anything"));
ret = -370;
goto on_return;
}
/* Get info */
pj_bzero(&info, sizeof(info));
pj_stun_sock_get_info(client->sock, &info);
/* Check that we have server address */
if (!pj_sockaddr_has_addr(&info.srv_addr)) {
PJ_LOG(3,(THIS_FILE, " error: missing server address"));
ret = -380;
goto on_return;
}
/* .. and bound address port must not be zero */
if (pj_sockaddr_get_port(&info.bound_addr)==0) {
PJ_LOG(3,(THIS_FILE, " error: bound address is zero"));
ret = -381;
goto on_return;
}
/* .. and mapped address */
if (!pj_sockaddr_has_addr(&info.mapped_addr)) {
PJ_LOG(3,(THIS_FILE, " error: missing mapped address"));
ret = -382;
goto on_return;
}
/* verify the mapped address */
pj_sockaddr_in_init(&mapped_addr, &srv->ip_to_send, srv->port_to_send);
if (pj_sockaddr_cmp(&info.mapped_addr, &mapped_addr) != 0) {
PJ_LOG(3,(THIS_FILE, " error: mapped address mismatched"));
ret = -383;
goto on_return;
}
/* .. and at least one alias */
if (info.alias_cnt == 0) {
PJ_LOG(3,(THIS_FILE, " error: must have at least one alias"));
ret = -384;
goto on_return;
//.........这里部分代码省略.........
示例2: PJ_DEF
/*
* Initialize and start SRTP session with the given parameters.
*/
PJ_DEF(pj_status_t) pjmedia_transport_srtp_start(
pjmedia_transport *tp,
const pjmedia_srtp_crypto *tx,
const pjmedia_srtp_crypto *rx)
{
transport_srtp *srtp = (transport_srtp*) tp;
srtp_policy_t tx_;
srtp_policy_t rx_;
err_status_t err;
int cr_tx_idx = 0;
int au_tx_idx = 0;
int cr_rx_idx = 0;
int au_rx_idx = 0;
int crypto_suites_cnt;
pj_status_t status = PJ_SUCCESS;
PJ_ASSERT_RETURN(tp && tx && rx, PJ_EINVAL);
pj_lock_acquire(srtp->mutex);
if (srtp->session_inited) {
pjmedia_transport_srtp_stop(tp);
}
crypto_suites_cnt = sizeof(crypto_suites)/sizeof(crypto_suites[0]);
/* Get encryption and authentication method */
cr_tx_idx = au_tx_idx = get_crypto_idx(&tx->name);
if (tx->flags & PJMEDIA_SRTP_NO_ENCRYPTION)
cr_tx_idx = 0;
if (tx->flags & PJMEDIA_SRTP_NO_AUTHENTICATION)
au_tx_idx = 0;
cr_rx_idx = au_rx_idx = get_crypto_idx(&rx->name);
if (rx->flags & PJMEDIA_SRTP_NO_ENCRYPTION)
cr_rx_idx = 0;
if (rx->flags & PJMEDIA_SRTP_NO_AUTHENTICATION)
au_rx_idx = 0;
/* Check whether the crypto-suite requested is supported */
if (cr_tx_idx == -1 || cr_rx_idx == -1 || au_tx_idx == -1 ||
au_rx_idx == -1)
{
status = PJMEDIA_SRTP_ENOTSUPCRYPTO;
goto on_return;
}
/* If all options points to 'NULL' method, just bypass SRTP */
if (cr_tx_idx == 0 && cr_rx_idx == 0 && au_tx_idx == 0 && au_rx_idx == 0) {
srtp->bypass_srtp = PJ_TRUE;
goto on_return;
}
/* Check key length */
if (tx->key.slen != (pj_ssize_t)crypto_suites[cr_tx_idx].cipher_key_len ||
rx->key.slen != (pj_ssize_t)crypto_suites[cr_rx_idx].cipher_key_len)
{
status = PJMEDIA_SRTP_EINKEYLEN;
goto on_return;
}
/* Init transmit direction */
pj_bzero(&tx_, sizeof(srtp_policy_t));
pj_memmove(srtp->tx_key, tx->key.ptr, tx->key.slen);
if (cr_tx_idx && au_tx_idx)
tx_.rtp.sec_serv = sec_serv_conf_and_auth;
else if (cr_tx_idx)
tx_.rtp.sec_serv = sec_serv_conf;
else if (au_tx_idx)
tx_.rtp.sec_serv = sec_serv_auth;
else
tx_.rtp.sec_serv = sec_serv_none;
tx_.key = (uint8_t*)srtp->tx_key;
tx_.ssrc.type = ssrc_any_outbound;
tx_.ssrc.value = 0;
tx_.rtp.cipher_type = crypto_suites[cr_tx_idx].cipher_type;
tx_.rtp.cipher_key_len = crypto_suites[cr_tx_idx].cipher_key_len;
tx_.rtp.auth_type = crypto_suites[au_tx_idx].auth_type;
tx_.rtp.auth_key_len = crypto_suites[au_tx_idx].auth_key_len;
tx_.rtp.auth_tag_len = crypto_suites[au_tx_idx].srtp_auth_tag_len;
tx_.rtcp = tx_.rtp;
tx_.rtcp.auth_tag_len = crypto_suites[au_tx_idx].srtcp_auth_tag_len;
tx_.next = NULL;
err = srtp_create(&srtp->srtp_tx_ctx, &tx_);
if (err != err_status_ok) {
status = PJMEDIA_ERRNO_FROM_LIBSRTP(err);
goto on_return;
}
srtp->tx_policy = *tx;
pj_strset(&srtp->tx_policy.key, srtp->tx_key, tx->key.slen);
srtp->tx_policy.name=pj_str(crypto_suites[get_crypto_idx(&tx->name)].name);
/* Init receive direction */
pj_bzero(&rx_, sizeof(srtp_policy_t));
pj_memmove(srtp->rx_key, rx->key.ptr, rx->key.slen);
if (cr_rx_idx && au_rx_idx)
//.........这里部分代码省略.........
示例3: PJ_DEF
/* Get IP interface for sending to the specified destination */
PJ_DEF(pj_status_t) pj_getipinterface(int af,
const pj_str_t *dst,
pj_sockaddr *itf_addr,
pj_bool_t allow_resolve,
pj_sockaddr *p_dst_addr)
{
pj_sockaddr dst_addr;
pj_sock_t fd;
int len;
pj_uint8_t zero[64];
pj_status_t status;
pj_sockaddr_init(af, &dst_addr, NULL, 53);
status = pj_inet_pton(af, dst, pj_sockaddr_get_addr(&dst_addr));
if (status != PJ_SUCCESS) {
/* "dst" is not an IP address. */
if (allow_resolve) {
status = pj_sockaddr_init(af, &dst_addr, dst, 53);
} else {
pj_str_t cp;
if (af == PJ_AF_INET) {
cp = pj_str("1.1.1.1");
} else {
cp = pj_str("1::1");
}
status = pj_sockaddr_init(af, &dst_addr, &cp, 53);
}
if (status != PJ_SUCCESS)
return status;
}
/* Create UDP socket and connect() to the destination IP */
status = pj_sock_socket(af, pj_SOCK_DGRAM(), 0, &fd);
if (status != PJ_SUCCESS) {
return status;
}
status = pj_sock_connect(fd, &dst_addr, pj_sockaddr_get_len(&dst_addr));
if (status != PJ_SUCCESS) {
pj_sock_close(fd);
return status;
}
len = sizeof(*itf_addr);
status = pj_sock_getsockname(fd, itf_addr, &len);
if (status != PJ_SUCCESS) {
pj_sock_close(fd);
return status;
}
pj_sock_close(fd);
/* Check that the address returned is not zero */
pj_bzero(zero, sizeof(zero));
if (pj_memcmp(pj_sockaddr_get_addr(itf_addr), zero,
pj_sockaddr_get_addr_len(itf_addr))==0)
{
return PJ_ENOTFOUND;
}
if (p_dst_addr)
*p_dst_addr = dst_addr;
return PJ_SUCCESS;
}
示例4: PJ_DECL
//Wrap start & stop
PJ_DECL(pj_status_t) csipsimple_init(pjsua_config *ua_cfg,
pjsua_logging_config *log_cfg, pjsua_media_config *media_cfg,
csipsimple_config *css_cfg, jobject context) {
pj_status_t result;
/* Create memory pool for application. */
css_var.pool = pjsua_pool_create("css", 1000, 1000);
PJ_ASSERT_RETURN(css_var.pool, PJ_ENOMEM);
// Finalize configuration
log_cfg->cb = &pj_android_log_msg;
if (css_cfg->turn_username.slen) {
media_cfg->turn_auth_cred.type = PJ_STUN_AUTH_CRED_STATIC;
media_cfg->turn_auth_cred.data.static_cred.realm = pj_str("*");
pj_strdup_with_null(css_var.pool,
&media_cfg->turn_auth_cred.data.static_cred.username,
&css_cfg->turn_username);
if (css_cfg->turn_password.slen) {
media_cfg->turn_auth_cred.data.static_cred.data_type =
PJ_STUN_PASSWD_PLAIN;
pj_strdup_with_null(css_var.pool,
&media_cfg->turn_auth_cred.data.static_cred.data,
&css_cfg->turn_password);
}
}
// Static cfg
extern pj_bool_t pjsip_use_compact_form;
extern pj_bool_t pjsip_include_allow_hdr_in_dlg;
extern pj_bool_t pjmedia_add_rtpmap_for_static_pt;
extern pj_bool_t pjsua_no_update;
pjsua_no_update = css_cfg->use_no_update ? PJ_TRUE : PJ_FALSE;
pjsip_use_compact_form =
css_cfg->use_compact_form_headers ? PJ_TRUE : PJ_FALSE;
/* do not transmit Allow header */
pjsip_include_allow_hdr_in_dlg =
css_cfg->use_compact_form_headers ? PJ_FALSE : PJ_TRUE;
/* Do not include rtpmap for static payload types (<96) */
pjmedia_add_rtpmap_for_static_pt =
css_cfg->use_compact_form_sdp ? PJ_FALSE : PJ_TRUE;
css_tcp_keep_alive_interval = css_cfg->tcp_keep_alive_interval;
css_tls_keep_alive_interval = css_cfg->tls_keep_alive_interval;
// Audio codec cfg
css_var.extra_aud_codecs_cnt = css_cfg->extra_aud_codecs_cnt;
unsigned i;
for (i = 0; i < css_cfg->extra_aud_codecs_cnt; i++) {
dynamic_factory *css_codec = &css_var.extra_aud_codecs[i];
dynamic_factory *cfg_codec = &css_cfg->extra_aud_codecs[i];
pj_strdup_with_null(css_var.pool, &css_codec->shared_lib_path,
&cfg_codec->shared_lib_path);
pj_strdup_with_null(css_var.pool, &css_codec->init_factory_name,
&cfg_codec->init_factory_name);
}
// Video codec cfg -- For now only destroy is useful but for future
// hopefully vid codec mgr will behaves as audio does
// Also in this case destroy will become obsolete
css_var.extra_vid_codecs_cnt = css_cfg->extra_vid_codecs_cnt;
for (i = 0; i < css_cfg->extra_vid_codecs_cnt; i++) {
dynamic_factory *css_codec = &css_var.extra_vid_codecs[i];
dynamic_factory *cfg_codec = &css_cfg->extra_vid_codecs[i];
pj_strdup_with_null(css_var.pool, &css_codec->shared_lib_path,
&cfg_codec->shared_lib_path);
pj_strdup_with_null(css_var.pool, &css_codec->init_factory_name,
&cfg_codec->init_factory_name);
css_codec = &css_var.extra_vid_codecs_destroy[i];
cfg_codec = &css_cfg->extra_vid_codecs_destroy[i];
pj_strdup_with_null(css_var.pool, &css_codec->shared_lib_path,
&cfg_codec->shared_lib_path);
pj_strdup_with_null(css_var.pool, &css_codec->init_factory_name,
&cfg_codec->init_factory_name);
}
// ZRTP cfg
css_var.default_use_zrtp = css_cfg->use_zrtp;
ua_cfg->cb.on_create_media_transport = &on_transport_created_wrapper;
#if defined(PJMEDIA_HAS_ZRTP) && PJMEDIA_HAS_ZRTP!=0
pj_ansi_snprintf(css_var.zid_file, sizeof(css_var.zid_file),
"%.*s/simple.zid", css_cfg->storage_folder.slen,
css_cfg->storage_folder.ptr);
#endif
JNIEnv *jni_env = 0;
ATTACH_JVM(jni_env);
css_var.context = (*jni_env)->NewGlobalRef(jni_env, context);
DETACH_JVM(jni_env);
//.........这里部分代码省略.........
示例5: parse_attr_crypto
/* Parse crypto attribute line */
static pj_status_t parse_attr_crypto(pj_pool_t *pool,
const pjmedia_sdp_attr *attr,
pjmedia_srtp_crypto *crypto,
int *tag)
{
pj_str_t input;
char *token;
int token_len;
pj_str_t tmp;
pj_status_t status;
int itmp;
pj_bzero(crypto, sizeof(*crypto));
pj_strdup_with_null(pool, &input, &attr->value);
/* Tag */
token = strtok(input.ptr, " ");
if (!token) {
PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting tag"));
return PJMEDIA_SDP_EINATTR;
}
token_len = pj_ansi_strlen(token);
/* Tag must not use leading zeroes. */
if (token_len > 1 && *token == '0')
return PJMEDIA_SDP_EINATTR;
/* Tag must be decimal, i.e: contains only digit '0'-'9'. */
for (itmp = 0; itmp < token_len; ++itmp)
if (!pj_isdigit(token[itmp]))
return PJMEDIA_SDP_EINATTR;
/* Get tag value. */
*tag = atoi(token);
/* Crypto-suite */
token = strtok(NULL, " ");
if (!token) {
PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting crypto suite"));
return PJMEDIA_SDP_EINATTR;
}
crypto->name = pj_str(token);
/* Key method */
token = strtok(NULL, ":");
if (!token) {
PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting key method"));
return PJMEDIA_SDP_EINATTR;
}
if (pj_ansi_stricmp(token, "inline")) {
PJ_LOG(4,(THIS_FILE, "Attribute crypto key method '%s' not supported!",
token));
return PJMEDIA_SDP_EINATTR;
}
/* Key */
token = strtok(NULL, "| ");
if (!token) {
PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting key"));
return PJMEDIA_SDP_EINATTR;
}
tmp = pj_str(token);
if (PJ_BASE64_TO_BASE256_LEN(tmp.slen) > MAX_KEY_LEN) {
PJ_LOG(4,(THIS_FILE, "Key too long"));
return PJMEDIA_SRTP_EINKEYLEN;
}
/* Decode key */
crypto->key.ptr = (char*) pj_pool_zalloc(pool, MAX_KEY_LEN);
itmp = MAX_KEY_LEN;
status = pj_base64_decode(&tmp, (pj_uint8_t*)crypto->key.ptr,
&itmp);
if (status != PJ_SUCCESS) {
PJ_LOG(4,(THIS_FILE, "Failed decoding crypto key from base64"));
return status;
}
crypto->key.slen = itmp;
return PJ_SUCCESS;
}
示例6: tu_on_tsx_state
//.........这里部分代码省略.........
status = pjsip_endpt_create_response_fwd(global.endpt, rdata, 0,
&tdata);
if (status != PJ_SUCCESS) {
app_perror("Error creating response", status);
return;
}
/* Get topmost Via header of the new response */
hvia = (pjsip_via_hdr*) pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA,
NULL);
if (hvia == NULL) {
/* Invalid response! Just drop it */
pjsip_tx_data_dec_ref(tdata);
return;
}
/* Calculate the address to forward the response */
pj_bzero(&res_addr, sizeof(res_addr));
res_addr.dst_host.type = PJSIP_TRANSPORT_UDP;
res_addr.dst_host.flag =
pjsip_transport_get_flag_from_type(PJSIP_TRANSPORT_UDP);
/* Destination address is Via's received param */
res_addr.dst_host.addr.host = hvia->recvd_param;
if (res_addr.dst_host.addr.host.slen == 0) {
/* Someone has messed up our Via header! */
res_addr.dst_host.addr.host = hvia->sent_by.host;
}
/* Destination port is the rport */
if (hvia->rport_param != 0 && hvia->rport_param != -1)
res_addr.dst_host.addr.port = hvia->rport_param;
if (res_addr.dst_host.addr.port == 0) {
/* Ugh, original sender didn't put rport!
* At best, can only send the response to the port in Via.
*/
res_addr.dst_host.addr.port = hvia->sent_by.port;
}
/* Forward response with the UAS transaction */
pjsip_tsx_send_msg(uac_data->uas_tsx, tdata);
}
/* If UAC transaction is terminated, terminate the UAS as well.
* This could happen because of:
* - timeout on the UAC side
* - receipt of 2xx response to INVITE
*/
if (tsx->state == PJSIP_TSX_STATE_TERMINATED && uac_data &&
uac_data->uas_tsx)
{
pjsip_transaction *uas_tsx;
struct uas_data *uas_data;
uas_tsx = uac_data->uas_tsx;
uas_data = (struct uas_data*) uas_tsx->mod_data[mod_tu.id];
uas_data->uac_tsx = NULL;
if (event->body.tsx_state.type == PJSIP_EVENT_TIMER) {
/* Send 408/Timeout if this is an INVITE transaction, since
* we must have sent provisional response before. For non
* INVITE transaction, just destroy it.
*/
if (tsx->method.id == PJSIP_INVITE_METHOD) {
pjsip_tx_data *tdata = uas_tsx->last_tx;
tdata->msg->line.status.code = PJSIP_SC_REQUEST_TIMEOUT;
tdata->msg->line.status.reason = pj_str("Request timed out");
tdata->msg->body = NULL;
pjsip_tx_data_add_ref(tdata);
pjsip_tx_data_invalidate_msg(tdata);
pjsip_tsx_send_msg(uas_tsx, tdata);
} else {
/* For non-INVITE, just destroy the UAS transaction */
pjsip_tsx_terminate(uas_tsx, PJSIP_SC_REQUEST_TIMEOUT);
}
} else if (event->body.tsx_state.type == PJSIP_EVENT_RX_MSG) {
if (uas_tsx->state < PJSIP_TSX_STATE_TERMINATED) {
pjsip_msg *msg;
int code;
msg = event->body.tsx_state.src.rdata->msg_info.msg;
code = msg->line.status.code;
uac_data->uas_tsx = NULL;
pjsip_tsx_terminate(uas_tsx, code);
}
}
}
}
示例7: create_stream
/*
* Create stream based on the codec, dir, remote address, etc.
*/
static pj_status_t create_stream( pj_pool_t *pool,
pjmedia_endpt *med_endpt,
const pjmedia_codec_info *codec_info,
pjmedia_dir dir,
pj_uint16_t local_port,
const pj_sockaddr_in *rem_addr,
#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
pj_bool_t use_srtp,
const pj_str_t *crypto_suite,
const pj_str_t *srtp_tx_key,
const pj_str_t *srtp_rx_key,
#endif
pjmedia_stream **p_stream )
{
pjmedia_stream_info info;
pjmedia_transport *transport = NULL;
pj_status_t status;
#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
pjmedia_transport *srtp_tp = NULL;
#endif
/* Reset stream info. */
pj_bzero(&info, sizeof(info));
/* Initialize stream info formats */
info.type = PJMEDIA_TYPE_AUDIO;
info.dir = dir;
pj_memcpy(&info.fmt, codec_info, sizeof(pjmedia_codec_info));
info.tx_pt = codec_info->pt;
info.rx_pt = codec_info->pt;
info.ssrc = pj_rand();
#if PJMEDIA_HAS_RTCP_XR && PJMEDIA_STREAM_ENABLE_XR
/* Set default RTCP XR enabled/disabled */
info.rtcp_xr_enabled = PJ_TRUE;
#endif
/* Copy remote address */
pj_memcpy(&info.rem_addr, rem_addr, sizeof(pj_sockaddr_in));
/* If remote address is not set, set to an arbitrary address
* (otherwise stream will assert).
*/
if (info.rem_addr.addr.sa_family == 0) {
const pj_str_t addr = pj_str("127.0.0.1");
pj_sockaddr_in_init(&info.rem_addr.ipv4, &addr, 0);
}
/* Create media transport */
status = pjmedia_transport_udp_create(med_endpt, NULL, local_port,
0, &transport);
if (status != PJ_SUCCESS)
return status;
#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
/* Check if SRTP enabled */
if (use_srtp) {
pjmedia_srtp_crypto tx_plc, rx_plc;
status = pjmedia_transport_srtp_create(med_endpt, transport,
NULL, &srtp_tp);
if (status != PJ_SUCCESS)
return status;
pj_bzero(&tx_plc, sizeof(pjmedia_srtp_crypto));
pj_bzero(&rx_plc, sizeof(pjmedia_srtp_crypto));
tx_plc.key = *srtp_tx_key;
tx_plc.name = *crypto_suite;
rx_plc.key = *srtp_rx_key;
rx_plc.name = *crypto_suite;
status = pjmedia_transport_srtp_start(srtp_tp, &tx_plc, &rx_plc);
if (status != PJ_SUCCESS)
return status;
transport = srtp_tp;
}
#endif
/* Now that the stream info is initialized, we can create the
* stream.
*/
status = pjmedia_stream_create( med_endpt, pool, &info,
transport,
NULL, p_stream);
if (status != PJ_SUCCESS) {
app_perror(THIS_FILE, "Error creating stream", status);
pjmedia_transport_close(transport);
return status;
}
//.........这里部分代码省略.........
示例8: main
/*
* main()
*/
int main(int argc, char *argv[])
{
pj_caching_pool cp;
pjmedia_endpt *med_endpt;
pj_pool_t *pool;
pjmedia_port *rec_file_port = NULL, *play_file_port = NULL;
pjmedia_master_port *master_port = NULL;
pjmedia_snd_port *snd_port = NULL;
pjmedia_stream *stream = NULL;
pjmedia_port *stream_port;
char tmp[10];
pj_status_t status;
#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
/* SRTP variables */
pj_bool_t use_srtp = PJ_FALSE;
char tmp_tx_key[64];
char tmp_rx_key[64];
pj_str_t srtp_tx_key = {NULL, 0};
pj_str_t srtp_rx_key = {NULL, 0};
pj_str_t srtp_crypto_suite = {NULL, 0};
int tmp_key_len;
#endif
/* Default values */
const pjmedia_codec_info *codec_info;
pjmedia_codec_param codec_param;
pjmedia_dir dir = PJMEDIA_DIR_DECODING;
pj_sockaddr_in remote_addr;
pj_uint16_t local_port = 4000;
char *codec_id = NULL;
char *rec_file = NULL;
char *play_file = NULL;
enum {
OPT_CODEC = 'c',
OPT_LOCAL_PORT = 'p',
OPT_REMOTE = 'r',
OPT_PLAY_FILE = 'w',
OPT_RECORD_FILE = 'R',
OPT_SEND_RECV = 'b',
OPT_SEND_ONLY = 's',
OPT_RECV_ONLY = 'i',
#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
OPT_USE_SRTP = 'S',
#endif
OPT_SRTP_TX_KEY = 'x',
OPT_SRTP_RX_KEY = 'y',
OPT_HELP = 'h',
};
struct pj_getopt_option long_options[] = {
{ "codec", 1, 0, OPT_CODEC },
{ "local-port", 1, 0, OPT_LOCAL_PORT },
{ "remote", 1, 0, OPT_REMOTE },
{ "play-file", 1, 0, OPT_PLAY_FILE },
{ "record-file", 1, 0, OPT_RECORD_FILE },
{ "send-recv", 0, 0, OPT_SEND_RECV },
{ "send-only", 0, 0, OPT_SEND_ONLY },
{ "recv-only", 0, 0, OPT_RECV_ONLY },
#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0)
{ "use-srtp", 2, 0, OPT_USE_SRTP },
{ "srtp-tx-key", 1, 0, OPT_SRTP_TX_KEY },
{ "srtp-rx-key", 1, 0, OPT_SRTP_RX_KEY },
#endif
{ "help", 0, 0, OPT_HELP },
{ NULL, 0, 0, 0 },
};
int c;
int option_index;
pj_bzero(&remote_addr, sizeof(remote_addr));
/* init PJLIB : */
status = pj_init();
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
/* Parse arguments */
pj_optind = 0;
while((c=pj_getopt_long(argc,argv, "h", long_options, &option_index))!=-1) {
switch (c) {
case OPT_CODEC:
codec_id = pj_optarg;
break;
case OPT_LOCAL_PORT:
local_port = (pj_uint16_t) atoi(pj_optarg);
if (local_port < 1) {
printf("Error: invalid local port %s\n", pj_optarg);
return 1;
}
break;
//.........这里部分代码省略.........
示例9: parse_fmtp
/*
* Parse fmtp for specified format/payload type.
*/
static void parse_fmtp( pj_pool_t *pool,
const pjmedia_sdp_media *m,
unsigned pt,
pjmedia_codec_fmtp *fmtp)
{
const pjmedia_sdp_attr *attr;
pjmedia_sdp_fmtp sdp_fmtp;
char *p, *p_end, fmt_buf[8];
pj_str_t fmt;
pj_assert(m && fmtp);
pj_bzero(fmtp, sizeof(pjmedia_codec_fmtp));
/* Get "fmtp" attribute for the format */
pj_ansi_sprintf(fmt_buf, "%d", pt);
fmt = pj_str(fmt_buf);
attr = pjmedia_sdp_media_find_attr2(m, "fmtp", &fmt);
if (attr == NULL)
return;
/* Parse "fmtp" attribute */
if (pjmedia_sdp_attr_get_fmtp(attr, &sdp_fmtp) != PJ_SUCCESS)
return;
/* Prepare parsing */
p = sdp_fmtp.fmt_param.ptr;
p_end = p + sdp_fmtp.fmt_param.slen;
/* Parse */
while (p < p_end) {
char *token, *start, *end;
/* Skip whitespaces */
while (p < p_end && (*p == ' ' || *p == '\t')) ++p;
if (p == p_end)
break;
/* Get token */
start = p;
while (p < p_end && *p != ';' && *p != '=') ++p;
end = p - 1;
/* Right trim */
while (end >= start && (*end == ' ' || *end == '\t' ||
*end == '\r' || *end == '\n' ))
--end;
/* Forward a char after trimming */
++end;
/* Store token */
if (end > start) {
token = (char*)pj_pool_alloc(pool, end - start);
pj_ansi_strncpy(token, start, end - start);
if (*p == '=')
/* Got param name */
pj_strset(&fmtp->param[fmtp->cnt].name, token, end - start);
else
/* Got param value */
pj_strset(&fmtp->param[fmtp->cnt++].val, token, end - start);
} else if (*p != '=') {
++fmtp->cnt;
}
/* Next */
++p;
}
}
示例10: https_client_test
static int https_client_test(unsigned ms_timeout)
{
pj_pool_t *pool = NULL;
pj_ioqueue_t *ioqueue = NULL;
pj_timer_heap_t *timer = NULL;
pj_ssl_sock_t *ssock = NULL;
pj_ssl_sock_param param;
pj_status_t status;
struct test_state state = {0};
pj_sockaddr local_addr, rem_addr;
pj_str_t tmp_st;
pool = pj_pool_create(mem, "https_get", 256, 256, NULL);
status = pj_ioqueue_create(pool, 4, &ioqueue);
if (status != PJ_SUCCESS) {
goto on_return;
}
status = pj_timer_heap_create(pool, 4, &timer);
if (status != PJ_SUCCESS) {
goto on_return;
}
state.pool = pool;
state.send_str = HTTP_REQ;
state.send_str_len = pj_ansi_strlen(state.send_str);
state.is_verbose = PJ_TRUE;
pj_ssl_sock_param_default(¶m);
param.cb.on_connect_complete = &ssl_on_connect_complete;
param.cb.on_data_read = &ssl_on_data_read;
param.cb.on_data_sent = &ssl_on_data_sent;
param.ioqueue = ioqueue;
param.user_data = &state;
param.server_name = pj_str((char*)HTTP_SERVER_ADDR);
param.timer_heap = timer;
param.timeout.sec = 0;
param.timeout.msec = ms_timeout;
param.proto = PJ_SSL_SOCK_PROTO_SSL23;
pj_time_val_normalize(¶m.timeout);
status = pj_ssl_sock_create(pool, ¶m, &ssock);
if (status != PJ_SUCCESS) {
goto on_return;
}
pj_sockaddr_init(PJ_AF_INET, &local_addr, pj_strset2(&tmp_st, "0.0.0.0"), 0);
pj_sockaddr_init(PJ_AF_INET, &rem_addr, pj_strset2(&tmp_st, HTTP_SERVER_ADDR), HTTP_SERVER_PORT);
status = pj_ssl_sock_start_connect(ssock, pool, &local_addr, &rem_addr, sizeof(rem_addr));
if (status == PJ_SUCCESS) {
ssl_on_connect_complete(ssock, PJ_SUCCESS);
} else if (status == PJ_EPENDING) {
status = PJ_SUCCESS;
} else {
goto on_return;
}
/* Wait until everything has been sent/received */
while (state.err == PJ_SUCCESS && !state.done) {
#ifdef PJ_SYMBIAN
pj_symbianos_poll(-1, 1000);
#else
pj_time_val delay = {0, 100};
pj_ioqueue_poll(ioqueue, &delay);
pj_timer_heap_poll(timer, &delay);
#endif
}
if (state.err) {
status = state.err;
goto on_return;
}
PJ_LOG(3, ("", "...Done!"));
PJ_LOG(3, ("", ".....Sent/recv: %d/%d bytes", state.sent, state.recv));
on_return:
if (ssock && !state.err && !state.done)
pj_ssl_sock_close(ssock);
if (ioqueue)
pj_ioqueue_destroy(ioqueue);
if (timer)
pj_timer_heap_destroy(timer);
if (pool)
pj_pool_release(pool);
return status;
}
示例11: parse_attr_crypto
/* Parse crypto attribute line */
static pj_status_t parse_attr_crypto(pj_pool_t *pool,
const pjmedia_sdp_attr *attr,
pjmedia_srtp_crypto *crypto,
int *tag)
{
pj_str_t input;
char *token;
pj_str_t tmp;
pj_status_t status;
int itmp;
pj_bzero(crypto, sizeof(*crypto));
pj_strdup_with_null(pool, &input, &attr->value);
/* Tag */
token = strtok(input.ptr, " ");
if (!token) {
PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting tag"));
return PJMEDIA_SDP_EINATTR;
}
*tag = atoi(token);
if (*tag == 0)
return PJMEDIA_SDP_EINATTR;
/* Crypto-suite */
token = strtok(NULL, " ");
if (!token) {
PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting crypto suite"));
return PJMEDIA_SDP_EINATTR;
}
crypto->name = pj_str(token);
/* Key method */
token = strtok(NULL, ":");
if (!token) {
PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting key method"));
return PJMEDIA_SDP_EINATTR;
}
if (pj_ansi_stricmp(token, "inline")) {
PJ_LOG(4,(THIS_FILE, "Attribute crypto key method '%s' not supported!",
token));
return PJMEDIA_SDP_EINATTR;
}
/* Key */
token = strtok(NULL, "| ");
if (!token) {
PJ_LOG(4,(THIS_FILE, "Attribute crypto expecting key"));
return PJMEDIA_SDP_EINATTR;
}
tmp = pj_str(token);
crypto->key.ptr = (char*) pj_pool_zalloc(pool, MAX_KEY_LEN);
/* Decode key */
itmp = MAX_KEY_LEN;
status = pj_base64_decode(&tmp, (pj_uint8_t*)crypto->key.ptr,
&itmp);
if (status != PJ_SUCCESS) {
PJ_LOG(4,(THIS_FILE, "Failed decoding crypto key from base64"));
return status;
}
crypto->key.slen = itmp;
return PJ_SUCCESS;
}
示例12: main
/* main()
*
* If called with argument, treat argument as SIP URL to be called.
* Otherwise wait for incoming calls.
*/
int main(int argc, char *argv[])
{
struct pj_getopt_option long_options[] = {
{ "local-port", 1, 0, 'p' },
{ "tcp", 0, 0, 't' },
{ "ipv6", 0, 0, '6' },
{ "help", 0, 0, 'h' }
};
int c, option_index;
pj_log_set_level(5);
pj_init();
sip_af = pj_AF_INET();
pj_optind = 0;
while ((c = pj_getopt_long(argc, argv, "p:t6h", long_options,
&option_index)) != -1)
{
switch (c) {
case 'p':
sip_port = atoi(pj_optarg);
break;
case 't':
sip_tcp = PJ_TRUE;
break;
case 'h':
usage();
return 0;
case '6':
sip_af = pj_AF_INET6();
break;
default:
PJ_LOG(1,(THIS_FILE,
"Argument \"%s\" is not valid. Use --help to see help",
argv[pj_optind-1]));
return -1;
}
}
if (init_stack())
goto on_error;
/* If URL is specified, then make call immediately. */
if (pj_optind != argc) {
pj_sockaddr hostaddr;
char hostip[PJ_INET6_ADDRSTRLEN+2];
char temp[80];
call_t *call;
pj_str_t dst_uri = pj_str(argv[pj_optind]);
pj_str_t local_uri;
pjsip_dialog *dlg;
pj_status_t status;
pjsip_tx_data *tdata;
if (pj_gethostip(sip_af, &hostaddr) != PJ_SUCCESS) {
PJ_LOG(1,(THIS_FILE, "Unable to retrieve local host IP"));
goto on_error;
}
pj_sockaddr_print(&hostaddr, hostip, sizeof(hostip), 2);
pj_ansi_sprintf(temp, "<sip:[email protected]%s:%d>",
hostip, sip_port);
local_uri = pj_str(temp);
call = &app.call[0];
status = pjsip_dlg_create_uac( pjsip_ua_instance(),
&local_uri, /* local URI */
&local_uri, /* local Contact */
&dst_uri, /* remote URI */
&dst_uri, /* remote target */
&dlg); /* dialog */
if (status != PJ_SUCCESS) {
app_perror(THIS_FILE, "Unable to create UAC dialog", status);
return 1;
}
status = pjsip_inv_create_uac( dlg, NULL, 0, &call->inv);
if (status != PJ_SUCCESS) goto on_error;
call->inv->mod_data[mod_sipecho.id] = call;
status = pjsip_inv_invite(call->inv, &tdata);
if (status != PJ_SUCCESS) goto on_error;
status = pjsip_inv_send_msg(call->inv, tdata);
if (status != PJ_SUCCESS) goto on_error;
puts("Press ENTER to quit...");
} else {
puts("Ready for incoming calls. Press ENTER to quit...");
}
//.........这里部分代码省略.........
示例13: on_rx_request
static pj_bool_t on_rx_request( pjsip_rx_data *rdata )
{
pj_sockaddr hostaddr;
char temp[80], hostip[PJ_INET6_ADDRSTRLEN];
pj_str_t local_uri;
pjsip_dialog *dlg;
pjsip_rdata_sdp_info *sdp_info;
pjmedia_sdp_session *answer = NULL;
pjsip_tx_data *tdata = NULL;
call_t *call = NULL;
unsigned i;
pj_status_t status;
PJ_LOG(3,(THIS_FILE, "RX %.*s from %s",
(int)rdata->msg_info.msg->line.req.method.name.slen,
rdata->msg_info.msg->line.req.method.name.ptr,
rdata->pkt_info.src_name));
if (rdata->msg_info.msg->line.req.method.id == PJSIP_REGISTER_METHOD) {
/* Let me be a registrar! */
pjsip_hdr hdr_list, *h;
pjsip_msg *msg;
int expires = -1;
pj_list_init(&hdr_list);
msg = rdata->msg_info.msg;
h = (pjsip_hdr*)pjsip_msg_find_hdr(msg, PJSIP_H_EXPIRES, NULL);
if (h) {
expires = ((pjsip_expires_hdr*)h)->ivalue;
pj_list_push_back(&hdr_list, pjsip_hdr_clone(rdata->tp_info.pool, h));
PJ_LOG(3,(THIS_FILE, " Expires=%d", expires));
}
if (expires != 0) {
h = (pjsip_hdr*)pjsip_msg_find_hdr(msg, PJSIP_H_CONTACT, NULL);
if (h)
pj_list_push_back(&hdr_list, pjsip_hdr_clone(rdata->tp_info.pool, h));
}
pjsip_endpt_respond(app.sip_endpt, &mod_sipecho, rdata, 200, NULL,
&hdr_list, NULL, NULL);
return PJ_TRUE;
}
if (rdata->msg_info.msg->line.req.method.id != PJSIP_INVITE_METHOD) {
if (rdata->msg_info.msg->line.req.method.id != PJSIP_ACK_METHOD) {
pj_str_t reason = pj_str("Go away");
pjsip_endpt_respond_stateless( app.sip_endpt, rdata,
400, &reason,
NULL, NULL);
}
return PJ_TRUE;
}
sdp_info = pjsip_rdata_get_sdp_info(rdata);
if (!sdp_info || !sdp_info->sdp) {
pj_str_t reason = pj_str("Require valid offer");
pjsip_endpt_respond_stateless( app.sip_endpt, rdata,
400, &reason,
NULL, NULL);
}
for (i=0; i<MAX_CALLS; ++i) {
if (app.call[i].inv == NULL) {
call = &app.call[i];
break;
}
}
if (i==MAX_CALLS) {
pj_str_t reason = pj_str("We're full");
pjsip_endpt_respond_stateless( app.sip_endpt, rdata,
PJSIP_SC_BUSY_HERE, &reason,
NULL, NULL);
return PJ_TRUE;
}
/* Generate Contact URI */
status = pj_gethostip(sip_af, &hostaddr);
if (status != PJ_SUCCESS) {
app_perror(THIS_FILE, "Unable to retrieve local host IP", status);
return PJ_TRUE;
}
pj_sockaddr_print(&hostaddr, hostip, sizeof(hostip), 2);
pj_ansi_sprintf(temp, "<sip:[email protected]%s:%d>", hostip, sip_port);
local_uri = pj_str(temp);
status = pjsip_dlg_create_uas( pjsip_ua_instance(), rdata,
&local_uri, &dlg);
if (status == PJ_SUCCESS)
answer = create_answer((int)(call-app.call), dlg->pool, sdp_info->sdp);
if (status == PJ_SUCCESS)
status = pjsip_inv_create_uas( dlg, rdata, answer, 0, &call->inv);
if (status == PJ_SUCCESS)
status = pjsip_inv_initial_answer(call->inv, rdata, 100,
NULL, NULL, &tdata);
if (status == PJ_SUCCESS)
status = pjsip_inv_send_msg(call->inv, tdata);
if (status == PJ_SUCCESS)
//.........这里部分代码省略.........
示例14: PJ_DEF
/*
* pjmedia_audiodev_strerror()
*/
PJ_DEF(pj_str_t) pjmedia_audiodev_strerror(pj_status_t statcode,
char *buf, pj_size_t bufsize )
{
pj_str_t errstr;
#if defined(PJ_HAS_ERROR_STRING) && (PJ_HAS_ERROR_STRING != 0)
/* See if the error comes from Core Audio. */
#if PJMEDIA_AUDIO_DEV_HAS_COREAUDIO
if (statcode >= PJMEDIA_AUDIODEV_COREAUDIO_ERRNO_START &&
statcode <= PJMEDIA_AUDIODEV_COREAUDIO_ERRNO_END)
{
int ca_err = PJMEDIA_AUDIODEV_COREAUDIO_ERRNO_START - statcode;
PJ_UNUSED_ARG(ca_err);
// TODO: create more helpful error messages
errstr.ptr = buf;
pj_strcpy2(&errstr, "Core audio error");
return errstr;
} else
#endif
/* See if the error comes from PortAudio. */
#if PJMEDIA_AUDIO_DEV_HAS_PORTAUDIO
if (statcode >= PJMEDIA_AUDIODEV_PORTAUDIO_ERRNO_START &&
statcode <= PJMEDIA_AUDIODEV_PORTAUDIO_ERRNO_END)
{
//int pa_err = statcode - PJMEDIA_ERRNO_FROM_PORTAUDIO(0);
int pa_err = PJMEDIA_AUDIODEV_PORTAUDIO_ERRNO_START - statcode;
pj_str_t msg;
msg.ptr = (char*)Pa_GetErrorText(pa_err);
msg.slen = pj_ansi_strlen(msg.ptr);
errstr.ptr = buf;
pj_strncpy_with_null(&errstr, &msg, bufsize);
return errstr;
} else
#endif /* PJMEDIA_SOUND_IMPLEMENTATION */
/* See if the error comes from WMME */
#if PJMEDIA_AUDIO_DEV_HAS_WMME
if ((statcode >= PJMEDIA_AUDIODEV_WMME_IN_ERROR_START &&
statcode < PJMEDIA_AUDIODEV_WMME_IN_ERROR_END) ||
(statcode >= PJMEDIA_AUDIODEV_WMME_OUT_ERROR_START &&
statcode < PJMEDIA_AUDIODEV_WMME_OUT_ERROR_END))
{
MMRESULT native_err, mr;
MMRESULT (WINAPI *waveGetErrText)(UINT mmrError, LPTSTR pszText, UINT cchText);
PJ_DECL_UNICODE_TEMP_BUF(wbuf, 80)
if (statcode >= PJMEDIA_AUDIODEV_WMME_IN_ERROR_START &&
statcode <= PJMEDIA_AUDIODEV_WMME_IN_ERROR_END)
{
native_err = statcode - PJMEDIA_AUDIODEV_WMME_IN_ERROR_START;
waveGetErrText = &waveInGetErrorText;
} else {
native_err = statcode - PJMEDIA_AUDIODEV_WMME_OUT_ERROR_START;
waveGetErrText = &waveOutGetErrorText;
}
#if PJ_NATIVE_STRING_IS_UNICODE
mr = (*waveGetErrText)(native_err, wbuf, PJ_ARRAY_SIZE(wbuf));
if (mr == MMSYSERR_NOERROR) {
int len = wcslen(wbuf);
pj_unicode_to_ansi(wbuf, len, buf, bufsize);
}
#else
mr = (*waveGetErrText)(native_err, buf, bufsize);
#endif
if (mr==MMSYSERR_NOERROR) {
errstr.ptr = buf;
errstr.slen = pj_ansi_strlen(buf);
return errstr;
} else {
pj_ansi_snprintf(buf, bufsize, "MMSYSTEM native error %d",
native_err);
return pj_str(buf);
}
} else
示例15: im_on_rx_request
/*
* Handler to receive incoming MESSAGE
*/
static pj_bool_t im_on_rx_request(pjsip_rx_data *rdata)
{
pj_str_t from, to;
pjsip_accept_hdr *accept_hdr;
pjsip_msg *msg;
msg = rdata->msg_info.msg;
/* Only want to handle MESSAGE requests. */
if (pjsip_method_cmp(&msg->line.req.method, &pjsip_message_method) != 0) {
return PJ_FALSE;
}
/* Should not have any transaction attached to rdata. */
PJ_ASSERT_RETURN(pjsip_rdata_get_tsx(rdata)==NULL, PJ_FALSE);
/* Should not have any dialog attached to rdata. */
PJ_ASSERT_RETURN(pjsip_rdata_get_dlg(rdata)==NULL, PJ_FALSE);
/* Check if we can accept the message. */
if (!pjsua_im_accept_pager(rdata, &accept_hdr)) {
pjsip_hdr hdr_list;
pj_list_init(&hdr_list);
pj_list_push_back(&hdr_list, accept_hdr);
pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata,
PJSIP_SC_NOT_ACCEPTABLE_HERE, NULL,
&hdr_list, NULL);
return PJ_TRUE;
}
/* Respond with 200 first, so that remote doesn't retransmit in case
* the UI takes too long to process the message.
*/
pjsip_endpt_respond( pjsua_var.endpt, NULL, rdata, 200, NULL,
NULL, NULL, NULL);
/* For the source URI, we use Contact header if present, since
* Contact header contains the port number information. If this is
* not available, then use From header.
*/
from.ptr = (char*)pj_pool_alloc(rdata->tp_info.pool, PJSIP_MAX_URL_SIZE);
from.slen = pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR,
rdata->msg_info.from->uri,
from.ptr, PJSIP_MAX_URL_SIZE);
if (from.slen < 1)
from = pj_str("<--URI is too long-->");
/* Build the To text. */
to.ptr = (char*) pj_pool_alloc(rdata->tp_info.pool, PJSIP_MAX_URL_SIZE);
to.slen = pjsip_uri_print( PJSIP_URI_IN_FROMTO_HDR,
rdata->msg_info.to->uri,
to.ptr, PJSIP_MAX_URL_SIZE);
if (to.slen < 1)
to = pj_str("<--URI is too long-->");
/* Process pager. */
pjsua_im_process_pager(-1, &from, &to, rdata);
/* Done. */
return PJ_TRUE;
}