本文整理汇总了C++中PJ_UNUSED_ARG函数的典型用法代码示例。如果您正苦于以下问题:C++ PJ_UNUSED_ARG函数的具体用法?C++ PJ_UNUSED_ARG怎么用?C++ PJ_UNUSED_ARG使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PJ_UNUSED_ARG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ioqueue_init_key
static pj_status_t ioqueue_init_key( pj_pool_t *pool,
pj_ioqueue_t *ioqueue,
pj_ioqueue_key_t *key,
pj_sock_t sock,
pj_grp_lock_t *grp_lock,
void *user_data,
const pj_ioqueue_callback *cb)
{
pj_status_t rc;
int optlen;
PJ_UNUSED_ARG(pool);
key->ioqueue = ioqueue;
key->fd = sock;
key->user_data = user_data;
pj_list_init(&key->read_list);
pj_list_init(&key->write_list);
#if PJ_HAS_TCP
pj_list_init(&key->accept_list);
key->connecting = 0;
#endif
/* Save callback. */
pj_memcpy(&key->cb, cb, sizeof(pj_ioqueue_callback));
#if PJ_IOQUEUE_HAS_SAFE_UNREG
/* Set initial reference count to 1 */
pj_assert(key->ref_count == 0);
++key->ref_count;
key->closing = 0;
#endif
rc = pj_ioqueue_set_concurrency(key, ioqueue->default_concurrency);
if (rc != PJ_SUCCESS)
return rc;
/* Get socket type. When socket type is datagram, some optimization
* will be performed during send to allow parallel send operations.
*/
optlen = sizeof(key->fd_type);
rc = pj_sock_getsockopt(sock, pj_SOL_SOCKET(), pj_SO_TYPE(),
&key->fd_type, &optlen);
if (rc != PJ_SUCCESS)
key->fd_type = pj_SOCK_STREAM();
/* Create mutex for the key. */
#if !PJ_IOQUEUE_HAS_SAFE_UNREG
rc = pj_lock_create_simple_mutex(poll, NULL, &key->lock);
#endif
if (rc != PJ_SUCCESS)
return rc;
/* Group lock */
key->grp_lock = grp_lock;
if (key->grp_lock) {
pj_grp_lock_add_ref_dbg(key->grp_lock, "ioqueue", 0);
}
return PJ_SUCCESS;
}
示例2: PJ_DEF
/*
* pj_ioqueue_create()
*/
PJ_DEF(pj_status_t) pj_ioqueue_create( pj_pool_t *pool,
pj_size_t max_fd,
pj_ioqueue_t **p_ioqueue)
{
pj_ioqueue_t *ioqueue;
unsigned i;
pj_status_t rc;
PJ_UNUSED_ARG(max_fd);
PJ_ASSERT_RETURN(pool && p_ioqueue, PJ_EINVAL);
rc = sizeof(union operation_key);
/* Check that sizeof(pj_ioqueue_op_key_t) makes sense. */
PJ_ASSERT_RETURN(sizeof(pj_ioqueue_op_key_t)-sizeof(void*) >=
sizeof(union operation_key), PJ_EBUG);
/* Create IOCP */
ioqueue = pj_pool_zalloc(pool, sizeof(*ioqueue));
ioqueue->iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);
if (ioqueue->iocp == NULL)
return PJ_RETURN_OS_ERROR(GetLastError());
/* Create IOCP mutex */
rc = pj_lock_create_recursive_mutex(pool, NULL, &ioqueue->lock);
if (rc != PJ_SUCCESS) {
CloseHandle(ioqueue->iocp);
return rc;
}
ioqueue->auto_delete_lock = PJ_TRUE;
ioqueue->default_concurrency = PJ_IOQUEUE_DEFAULT_ALLOW_CONCURRENCY;
#if PJ_IOQUEUE_HAS_SAFE_UNREG
/*
* Create and initialize key pools.
*/
pj_list_init(&ioqueue->active_list);
pj_list_init(&ioqueue->free_list);
pj_list_init(&ioqueue->closing_list);
/* Preallocate keys according to max_fd setting, and put them
* in free_list.
*/
for (i=0; i<max_fd; ++i) {
pj_ioqueue_key_t *key;
key = pj_pool_alloc(pool, sizeof(pj_ioqueue_key_t));
rc = pj_atomic_create(pool, 0, &key->ref_count);
if (rc != PJ_SUCCESS) {
key = ioqueue->free_list.next;
while (key != &ioqueue->free_list) {
pj_atomic_destroy(key->ref_count);
pj_mutex_destroy(key->mutex);
key = key->next;
}
CloseHandle(ioqueue->iocp);
return rc;
}
rc = pj_mutex_create_recursive(pool, "ioqkey", &key->mutex);
if (rc != PJ_SUCCESS) {
pj_atomic_destroy(key->ref_count);
key = ioqueue->free_list.next;
while (key != &ioqueue->free_list) {
pj_atomic_destroy(key->ref_count);
pj_mutex_destroy(key->mutex);
key = key->next;
}
CloseHandle(ioqueue->iocp);
return rc;
}
pj_list_push_back(&ioqueue->free_list, key);
}
#endif
*p_ioqueue = ioqueue;
PJ_LOG(4, ("pjlib", "WinNT IOCP I/O Queue created (%p)", ioqueue));
return PJ_SUCCESS;
}
示例3: PJ_DEF
/*
* pj_thread_resume()
*/
PJ_DEF(pj_status_t) pj_thread_resume(pj_thread_t *p)
{
PJ_UNUSED_ARG(p);
return PJ_EINVALIDOP;
}
示例4: pj_vpx_codec_decode
static pj_status_t pj_vpx_codec_decode(pjmedia_vid_codec *codec,
pj_size_t pkt_count,
pjmedia_frame packets[],
unsigned out_size,
pjmedia_frame *output) {
vpx_private *vpx = (vpx_private*) codec->codec_data;
vpx_image_t *img;
vpx_codec_iter_t iter;
int i, res;
PJ_ASSERT_RETURN(codec && pkt_count > 0 && packets && output, PJ_EINVAL);
vpx->dec_frame_len = 0;
/* TODO : packet parsing is absolutely incomplete here !!!!
* We should manage extensions, partitions etc
* */
for (i = 0; i < pkt_count; ++i) {
pj_uint8_t *data;
pj_uint8_t extended_bit, s_bit, partition_id;
unsigned extension_len = 0;
unsigned payload_size = packets[i].size;
if(payload_size == 0) {
continue;
}
data = packets[i].buf;
extended_bit = (*data) & 0x80;
s_bit = (*data) & 0x20;
partition_id = (*data) & 0x1F;
PJ_UNUSED_ARG(s_bit);
PJ_UNUSED_ARG(partition_id);
/* First octet is for */
/* |X|R|N|S|PartID | */
if(extended_bit) {
pj_uint8_t i_bit, l_bit, t_bit, k_bit;
(data)++;
extension_len++;
i_bit = (*data) & 0x80;
l_bit = (*data) & 0x40;
t_bit = (*data) & 0x20;
k_bit = (*data) & 0x10;
if(payload_size <= 1) {
PJ_LOG(4, (THIS_FILE, "Error decoding VP8 extended attributes"));
continue;
}
/* We have extension in octet 2 */
/* |I|L|T|K| RSV | */
if (i_bit) {
data++;
if(payload_size <= 2){
PJ_LOG(4, (THIS_FILE, "Error decoding VP8 extended picture ID attribute"));
continue;
}
// I present check M flag for long picture ID
if ((*data) & 0x80) {
data++;
}
}
if (l_bit) {
data++;
}
if (t_bit || k_bit) {
data++;
}
}
data++;
payload_size = packets[i].size - (data - (pj_uint8_t*)packets[i].buf);
//PJ_LOG(4, (THIS_FILE, "Unpack RTP %d size %d, start %d", i, packets[i].size, s[0] & 0x10));
if((vpx->dec_frame_len + payload_size) < vpx->dec_buf_size) {
pj_memcpy(vpx->dec_buf + vpx->dec_frame_len, data, payload_size);
vpx->dec_frame_len += payload_size;
} else {
PJ_LOG(1, (THIS_FILE, "Buffer is too small"));
}
}
if(vpx->dec_frame_len == 0){
PJ_LOG(1, (THIS_FILE, "No content for these packets"));
return PJ_SUCCESS;
}
res = vpx_codec_decode(&vpx->decoder, vpx->dec_buf, vpx->dec_frame_len, NULL, VPX_DL_REALTIME);
switch (res) {
case VPX_CODEC_UNSUP_BITSTREAM:
case VPX_CODEC_UNSUP_FEATURE:
case VPX_CODEC_CORRUPT_FRAME:
/* Fatal errors to the stream, request a keyframe to see if we can recover */
PJ_LOG(4, (THIS_FILE, "Fatal error decoding stream: (%d) %s", res, vpx_codec_err_to_string(res)));
pjmedia_event event;
pjmedia_event_init(&event, PJMEDIA_EVENT_KEYFRAME_MISSING, NULL, codec);
pjmedia_event_publish(NULL, codec, &event, 0);
return PJMEDIA_CODEC_EBADBITSTREAM;
case VPX_CODEC_OK:
break;
//.........这里部分代码省略.........
示例5: PJ_UNUSED_ARG
TInt CPjTimeoutTimer::RunError(TInt aError)
{
PJ_UNUSED_ARG(aError);
return KErrNone;
}
示例6: tel_uri_cmp
/* Compare two tel: URI */
static int tel_uri_cmp( pjsip_uri_context_e context,
const pjsip_tel_uri *url1, const pjsip_tel_uri *url2)
{
int result;
PJ_UNUSED_ARG(context);
/* Scheme must match. */
if (url1->vptr != url2->vptr)
return -1;
/* Compare number. */
result = pjsip_tel_nb_cmp(&url1->number, &url2->number);
if (result != 0)
return result;
/* Compare phone-context as hostname or as as global nb. */
if (url1->context.slen) {
if (*url1->context.ptr != '+')
result = pj_stricmp(&url1->context, &url2->context);
else
result = pjsip_tel_nb_cmp(&url1->context, &url2->context);
if (result != 0)
return result;
} else if (url2->context.slen)
return -1;
/* Compare extension. */
if (url1->ext_param.slen) {
result = pjsip_tel_nb_cmp(&url1->ext_param, &url2->ext_param);
if (result != 0)
return result;
}
/* Compare isub bytes by bytes. */
if (url1->isub_param.slen) {
result = pj_stricmp(&url1->isub_param, &url2->isub_param);
if (result != 0)
return result;
}
/* Other parameters are compared regardless of the order.
* If one URI has parameter not found in the other URI, the URIs are
* not equal.
*/
if (url1->other_param.next != &url1->other_param) {
const pjsip_param *p1, *p2;
int cnt1 = 0, cnt2 = 0;
p1 = url1->other_param.next;
while (p1 != &url1->other_param) {
p2 = pjsip_param_cfind(&url2->other_param, &p1->name);
if (!p2 )
return 1;
result = pj_stricmp(&p1->value, &p2->value);
if (result != 0)
return result;
p1 = p1->next;
++cnt1;
}
p2 = url2->other_param.next;
while (p2 != &url2->other_param)
++cnt2, p2 = p2->next;
if (cnt1 < cnt2)
return -1;
else if (cnt1 > cnt2)
return 1;
} else if (url2->other_param.next != &url2->other_param)
return -1;
/* Equal. */
return 0;
}
示例7: PJ_DEF
/*
* Destroy the transmit data.
*/
PJ_DEF(void) pj_stun_msg_destroy_tdata( pj_stun_session *sess,
pj_stun_tx_data *tdata)
{
PJ_UNUSED_ARG(sess);
destroy_tdata(tdata, PJ_FALSE);
}
示例8: PJ_UNUSED_ARG
static const pj_str_t *tel_uri_get_scheme( const pjsip_tel_uri *uri )
{
PJ_UNUSED_ARG(uri);
return &pjsip_parser_const()->pjsip_TEL_STR;
}
示例9: PJ_DEF
/* Create m=video SDP media line */
PJ_DEF(pj_status_t) pjmedia_endpt_create_video_sdp(pjmedia_endpt *endpt,
pj_pool_t *pool,
const pjmedia_sock_info *si,
unsigned options,
pjmedia_sdp_media **p_m)
{
const pj_str_t STR_VIDEO = { "video", 5 };
pjmedia_sdp_media *m;
pjmedia_vid_codec_info codec_info[PJMEDIA_VID_CODEC_MGR_MAX_CODECS];
unsigned codec_prio[PJMEDIA_VID_CODEC_MGR_MAX_CODECS];
pjmedia_sdp_attr *attr;
unsigned cnt, i;
unsigned max_bitrate = 0;
pj_status_t status;
PJ_UNUSED_ARG(options);
/* Make sure video codec manager is instantiated */
if (!pjmedia_vid_codec_mgr_instance())
pjmedia_vid_codec_mgr_create(endpt->pool, NULL);
/* Create and init basic SDP media */
m = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_media);
status = init_sdp_media(m, pool, &STR_VIDEO, si);
if (status != PJ_SUCCESS)
return status;
cnt = PJ_ARRAY_SIZE(codec_info);
status = pjmedia_vid_codec_mgr_enum_codecs(NULL, &cnt,
codec_info, codec_prio);
/* Check that there are not too many codecs */
PJ_ASSERT_RETURN(0 <= PJMEDIA_MAX_SDP_FMT,
PJ_ETOOMANY);
/* Add format, rtpmap, and fmtp (when applicable) for each codec */
for (i=0; i<cnt; ++i) {
pjmedia_sdp_rtpmap rtpmap;
pjmedia_vid_codec_param codec_param;
pj_str_t *fmt;
pjmedia_video_format_detail *vfd;
pj_bzero(&rtpmap, sizeof(rtpmap));
if (codec_prio[i] == PJMEDIA_CODEC_PRIO_DISABLED)
break;
if (i > PJMEDIA_MAX_SDP_FMT) {
/* Too many codecs, perhaps it is better to tell application by
* returning appropriate status code.
*/
PJ_PERROR(3,(THIS_FILE, PJ_ETOOMANY,
"Skipping some video codecs"));
break;
}
/* Must support RTP packetization and bidirectional */
if ((codec_info[i].packings & PJMEDIA_VID_PACKING_PACKETS) == 0 ||
codec_info[i].dir != PJMEDIA_DIR_ENCODING_DECODING)
{
continue;
}
pjmedia_vid_codec_mgr_get_default_param(NULL, &codec_info[i],
&codec_param);
fmt = &m->desc.fmt[m->desc.fmt_count++];
fmt->ptr = (char*) pj_pool_alloc(pool, 8);
fmt->slen = pj_utoa(codec_info[i].pt, fmt->ptr);
rtpmap.pt = *fmt;
/* Encoding name */
rtpmap.enc_name = codec_info[i].encoding_name;
/* Clock rate */
rtpmap.clock_rate = codec_info[i].clock_rate;
if (codec_info[i].pt >= 96 || pjmedia_add_rtpmap_for_static_pt) {
pjmedia_sdp_rtpmap_to_attr(pool, &rtpmap, &attr);
m->attr[m->attr_count++] = attr;
}
/* Add fmtp params */
if (codec_param.dec_fmtp.cnt > 0) {
enum { MAX_FMTP_STR_LEN = 160 };
char buf[MAX_FMTP_STR_LEN];
unsigned buf_len = 0, j;
pjmedia_codec_fmtp *dec_fmtp = &codec_param.dec_fmtp;
/* Print codec PT */
buf_len += pj_ansi_snprintf(buf,
MAX_FMTP_STR_LEN - buf_len,
"%d",
codec_info[i].pt);
for (j = 0; j < dec_fmtp->cnt; ++j) {
pj_size_t test_len = 2;
//.........这里部分代码省略.........
示例10: PJ_DEF
/*
* pj_ioqueue_sendto()
*
* Start asynchronous write() to the descriptor.
*/
PJ_DEF(pj_status_t) pj_ioqueue_sendto( pj_ioqueue_key_t *key,
pj_ioqueue_op_key_t *op_key,
const void *data,
pj_ssize_t *length,
pj_uint32_t flags,
const pj_sockaddr_t *addr,
int addrlen)
{
struct write_operation *write_op;
unsigned retry;
pj_bool_t restart_retry = PJ_FALSE;
pj_status_t status;
pj_ssize_t sent;
PJ_ASSERT_RETURN(key && op_key && data && length, PJ_EINVAL);
PJ_CHECK_STACK();
#if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \
PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0
retry_on_restart:
#else
PJ_UNUSED_ARG(restart_retry);
#endif
/* Check if key is closing. */
if (IS_CLOSING(key))
return PJ_ECANCELLED;
/* We can not use PJ_IOQUEUE_ALWAYS_ASYNC for socket write */
flags &= ~(PJ_IOQUEUE_ALWAYS_ASYNC);
/* Fast track:
* Try to send data immediately, only if there's no pending write!
* Note:
* We are speculating that the list is empty here without properly
* acquiring ioqueue's mutex first. This is intentional, to maximize
* performance via parallelism.
*
* This should be safe, because:
* - by convention, we require caller to make sure that the
* key is not unregistered while other threads are invoking
* an operation on the same key.
* - pj_list_empty() is safe to be invoked by multiple threads,
* even when other threads are modifying the list.
*/
if (pj_list_empty(&key->write_list)) {
/*
* See if data can be sent immediately.
*/
sent = *length;
status = pj_sock_sendto(key->fd, data, &sent, flags, addr, addrlen);
if (status == PJ_SUCCESS) {
/* Success! */
*length = sent;
return PJ_SUCCESS;
} else {
/* If error is not EWOULDBLOCK (or EAGAIN on Linux), report
* the error to caller.
*/
if (status != PJ_STATUS_FROM_OS(PJ_BLOCKING_ERROR_VAL)) {
#if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \
PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0
/* Special treatment for dead UDP sockets here, see ticket #1107 */
if (status==PJ_STATUS_FROM_OS(EPIPE) && !IS_CLOSING(key) &&
key->fd_type==pj_SOCK_DGRAM() && !restart_retry)
{
PJ_PERROR(4,(THIS_FILE, status,
"Send error for socket %d, retrying",
key->fd));
replace_udp_sock(key);
restart_retry = PJ_TRUE;
goto retry_on_restart;
}
#endif
return status;
}
}
}
/*
* Check that address storage can hold the address parameter.
*/
PJ_ASSERT_RETURN(addrlen <= (int)sizeof(pj_sockaddr_in), PJ_EBUG);
/*
* Schedule asynchronous send.
*/
write_op = (struct write_operation*)op_key;
/* Spin if write_op has pending operation */
for (retry=0; write_op->op != 0 && retry<PENDING_RETRY; ++retry)
pj_thread_sleep(0);
/* Last chance */
if (write_op->op) {
//.........这里部分代码省略.........
示例11: PJ_DEF
/* Resolve the IP address of local machine */
PJ_DEF(pj_status_t) pj_gethostip(int af, pj_sockaddr *addr)
{
unsigned i, count, cand_cnt;
enum {
CAND_CNT = 8,
/* Weighting to be applied to found addresses */
WEIGHT_HOSTNAME = 1, /* hostname IP is not always valid! */
WEIGHT_DEF_ROUTE = 2,
WEIGHT_INTERFACE = 1,
WEIGHT_LOOPBACK = -5,
WEIGHT_LINK_LOCAL = -4,
WEIGHT_DISABLED = -50,
MIN_WEIGHT = WEIGHT_DISABLED+1 /* minimum weight to use */
};
/* candidates: */
pj_sockaddr cand_addr[CAND_CNT];
int cand_weight[CAND_CNT];
int selected_cand;
char strip[PJ_INET6_ADDRSTRLEN+10];
/* Special IPv4 addresses. */
struct spec_ipv4_t
{
pj_uint32_t addr;
pj_uint32_t mask;
int weight;
} spec_ipv4[] =
{
/* 127.0.0.0/8, loopback addr will be used if there is no other
* addresses.
*/
{ 0x7f000000, 0xFF000000, WEIGHT_LOOPBACK },
/* 0.0.0.0/8, special IP that doesn't seem to be practically useful */
{ 0x00000000, 0xFF000000, WEIGHT_DISABLED },
/* 169.254.0.0/16, a zeroconf/link-local address, which has higher
* priority than loopback and will be used if there is no other
* valid addresses.
*/
{ 0xa9fe0000, 0xFFFF0000, WEIGHT_LINK_LOCAL }
};
/* Special IPv6 addresses */
struct spec_ipv6_t
{
pj_uint8_t addr[16];
pj_uint8_t mask[16];
int weight;
} spec_ipv6[] =
{
/* Loopback address, ::1/128 */
{ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
WEIGHT_LOOPBACK
},
/* Link local, fe80::/10 */
{ {0xfe,0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0xff,0xc0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
WEIGHT_LINK_LOCAL
},
/* Disabled, ::/128 */
{ {0x0,0x0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
WEIGHT_DISABLED
}
};
pj_addrinfo ai;
pj_status_t status;
/* May not be used if TRACE_ is disabled */
PJ_UNUSED_ARG(strip);
#ifdef _MSC_VER
/* Get rid of "uninitialized he variable" with MS compilers */
pj_bzero(&ai, sizeof(ai));
#endif
cand_cnt = 0;
pj_bzero(cand_addr, sizeof(cand_addr));
pj_bzero(cand_weight, sizeof(cand_weight));
for (i=0; i<PJ_ARRAY_SIZE(cand_addr); ++i) {
cand_addr[i].addr.sa_family = (pj_uint16_t)af;
PJ_SOCKADDR_RESET_LEN(&cand_addr[i]);
}
addr->addr.sa_family = (pj_uint16_t)af;
PJ_SOCKADDR_RESET_LEN(addr);
#if !defined(PJ_GETHOSTIP_DISABLE_LOCAL_RESOLUTION) || \
PJ_GETHOSTIP_DISABLE_LOCAL_RESOLUTION == 0
/* Get hostname's IP address */
count = 1;
status = pj_getaddrinfo(af, pj_gethostname(), &count, &ai);
if (status == PJ_SUCCESS) {
//.........这里部分代码省略.........
示例12: on_request_complete
/*
* Callback upon request completion.
*/
static void on_request_complete(pj_stun_session *stun_sess,
pj_status_t status,
void *token,
pj_stun_tx_data *tdata,
const pj_stun_msg *response,
const pj_sockaddr_t *src_addr,
unsigned src_addr_len)
{
nat_detect_session *sess;
pj_stun_sockaddr_attr *mattr = NULL;
pj_stun_changed_addr_attr *ca = NULL;
pj_uint32_t *tsx_id;
int cmp;
unsigned test_id;
PJ_UNUSED_ARG(token);
PJ_UNUSED_ARG(tdata);
PJ_UNUSED_ARG(src_addr);
PJ_UNUSED_ARG(src_addr_len);
sess = (nat_detect_session*) pj_stun_session_get_user_data(stun_sess);
pj_mutex_lock(sess->mutex);
/* Find errors in the response */
if (status == PJ_SUCCESS) {
/* Check error message */
if (PJ_STUN_IS_ERROR_RESPONSE(response->hdr.type)) {
pj_stun_errcode_attr *eattr;
int err_code;
eattr = (pj_stun_errcode_attr*)
pj_stun_msg_find_attr(response, PJ_STUN_ATTR_ERROR_CODE, 0);
if (eattr != NULL)
err_code = eattr->err_code;
else
err_code = PJ_STUN_SC_SERVER_ERROR;
status = PJ_STATUS_FROM_STUN_CODE(err_code);
} else {
/* Get MAPPED-ADDRESS or XOR-MAPPED-ADDRESS */
mattr = (pj_stun_sockaddr_attr*)
pj_stun_msg_find_attr(response, PJ_STUN_ATTR_XOR_MAPPED_ADDR, 0);
if (mattr == NULL) {
mattr = (pj_stun_sockaddr_attr*)
pj_stun_msg_find_attr(response, PJ_STUN_ATTR_MAPPED_ADDR, 0);
}
if (mattr == NULL) {
status = PJNATH_ESTUNNOMAPPEDADDR;
}
/* Get CHANGED-ADDRESS attribute */
ca = (pj_stun_changed_addr_attr*)
pj_stun_msg_find_attr(response, PJ_STUN_ATTR_CHANGED_ADDR, 0);
if (ca == NULL) {
status = PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_SERVER_ERROR);
}
}
}
/* Save the result */
tsx_id = (pj_uint32_t*) tdata->msg->hdr.tsx_id;
test_id = tsx_id[2];
if (test_id >= ST_MAX) {
PJ_LOG(4,(sess->pool->obj_name, "Invalid transaction ID %u in response",
test_id));
end_session(sess, PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_SERVER_ERROR),
PJ_STUN_NAT_TYPE_ERR_UNKNOWN);
goto on_return;
}
PJ_LOG(5,(sess->pool->obj_name, "Completed %s, status=%d",
test_names[test_id], status));
sess->result[test_id].complete = PJ_TRUE;
sess->result[test_id].status = status;
if (status == PJ_SUCCESS) {
pj_memcpy(&sess->result[test_id].ma, &mattr->sockaddr.ipv4,
sizeof(pj_sockaddr_in));
pj_memcpy(&sess->result[test_id].ca, &ca->sockaddr.ipv4,
sizeof(pj_sockaddr_in));
}
/* Send Test 1B only when Test 2 completes. Must not send Test 1B
* before Test 2 completes to avoid creating mapping on the NAT.
*/
if (!sess->result[ST_TEST_1B].executed &&
sess->result[ST_TEST_2].complete &&
//.........这里部分代码省略.........
示例13: on_accept_complete
/*
* This callback is called by active socket when pending accept() operation
* has completed.
*/
static pj_bool_t on_accept_complete(pj_activesock_t *asock,
pj_sock_t sock,
const pj_sockaddr_t *src_addr,
int src_addr_len)
{
struct tcp_listener *listener;
struct tcp_transport *tcp;
char addr[PJ_INET6_ADDRSTRLEN+10];
pjsip_tp_state_callback state_cb;
pj_sockaddr tmp_src_addr;
pj_status_t status;
PJ_UNUSED_ARG(src_addr_len);
listener = (struct tcp_listener*) pj_activesock_get_user_data(asock);
PJ_ASSERT_RETURN(sock != PJ_INVALID_SOCKET, PJ_TRUE);
PJ_LOG(4,(listener->factory.obj_name,
"TCP listener %.*s:%d: got incoming TCP connection "
"from %s, sock=%d",
(int)listener->factory.addr_name.host.slen,
listener->factory.addr_name.host.ptr,
listener->factory.addr_name.port,
pj_sockaddr_print(src_addr, addr, sizeof(addr), 3),
sock));
/* Apply QoS, if specified */
status = pj_sock_apply_qos2(sock, listener->qos_type,
&listener->qos_params,
2, listener->factory.obj_name,
"incoming SIP TCP socket");
/* tcp_create() expect pj_sockaddr, so copy src_addr to temporary var,
* just in case.
*/
pj_bzero(&tmp_src_addr, sizeof(tmp_src_addr));
pj_sockaddr_cp(&tmp_src_addr, src_addr);
/*
* Incoming connection!
* Create TCP transport for the new socket.
*/
status = tcp_create( listener, NULL, sock, PJ_TRUE,
&listener->factory.local_addr,
&tmp_src_addr, &tcp);
if (status == PJ_SUCCESS) {
status = tcp_start_read(tcp);
if (status != PJ_SUCCESS) {
PJ_LOG(3,(tcp->base.obj_name, "New transport cancelled"));
tcp_destroy(&tcp->base, status);
} else {
/* Start keep-alive timer */
if (PJSIP_TCP_KEEP_ALIVE_INTERVAL) {
pj_time_val delay = {PJSIP_TCP_KEEP_ALIVE_INTERVAL, 0};
pjsip_endpt_schedule_timer(listener->endpt,
&tcp->ka_timer,
&delay);
tcp->ka_timer.id = PJ_TRUE;
pj_gettimeofday(&tcp->last_activity);
}
/* Notify application of transport state accepted */
state_cb = pjsip_tpmgr_get_state_cb(tcp->base.tpmgr);
if (state_cb) {
pjsip_transport_state_info state_info;
pj_bzero(&state_info, sizeof(state_info));
(*state_cb)(&tcp->base, PJSIP_TP_STATE_CONNECTED, &state_info);
}
}
}
return PJ_TRUE;
}
示例14: ioqueue_on_accept_complete
static void ioqueue_on_accept_complete(pj_ioqueue_key_t *key,
pj_ioqueue_op_key_t *op_key,
pj_sock_t new_sock,
pj_status_t status)
{
pj_activesock_t *asock = (pj_activesock_t*) pj_ioqueue_get_user_data(key);
struct accept_op *accept_op = (struct accept_op*) op_key;
PJ_UNUSED_ARG(new_sock);
/* Ignore if we've been shutdown */
if (asock->shutdown)
return;
do {
if (status == asock->last_err && status != PJ_SUCCESS) {
asock->err_counter++;
if (asock->err_counter >= PJ_ACTIVESOCK_MAX_CONSECUTIVE_ACCEPT_ERROR) {
PJ_LOG(3, ("", "Received %d consecutive errors: %d for the accept()"
" operation, stopping further ioqueue accepts.",
asock->err_counter, asock->last_err));
if ((status == PJ_STATUS_FROM_OS(OSERR_EWOULDBLOCK)) &&
(asock->cb.on_accept_complete2))
{
(*asock->cb.on_accept_complete2)(asock,
accept_op->new_sock,
&accept_op->rem_addr,
accept_op->rem_addr_len,
PJ_ESOCKETSTOP);
}
return;
}
} else {
asock->err_counter = 0;
asock->last_err = status;
}
if (status==PJ_SUCCESS && (asock->cb.on_accept_complete2 ||
asock->cb.on_accept_complete)) {
pj_bool_t ret;
/* Notify callback */
if (asock->cb.on_accept_complete2) {
ret = (*asock->cb.on_accept_complete2)(asock,
accept_op->new_sock,
&accept_op->rem_addr,
accept_op->rem_addr_len,
status);
} else {
ret = (*asock->cb.on_accept_complete)(asock,
accept_op->new_sock,
&accept_op->rem_addr,
accept_op->rem_addr_len);
}
/* If callback returns false, we have been destroyed! */
if (!ret)
return;
#if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \
PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0
activesock_create_iphone_os_stream(asock);
#endif
} else if (status==PJ_SUCCESS) {
/* Application doesn't handle the new socket, we need to
* close it to avoid resource leak.
*/
pj_sock_close(accept_op->new_sock);
}
/* Don't start another accept() if we've been shutdown */
if (asock->shutdown)
return;
/* Prepare next accept() */
accept_op->new_sock = PJ_INVALID_SOCKET;
accept_op->rem_addr_len = sizeof(accept_op->rem_addr);
status = pj_ioqueue_accept(asock->key, op_key, &accept_op->new_sock,
NULL, &accept_op->rem_addr,
&accept_op->rem_addr_len);
} while (status != PJ_EPENDING && status != PJ_ECANCELLED);
}
示例15: PJ_DEF
//.........这里部分代码省略.........
query->naptr[0].res_type = pj_str("_sip._udp.");
else {
pj_assert(!"Unknown transport type");
query->naptr[0].res_type = pj_str("_sip._udp.");
}
} else {
/* Otherwise if port is specified, start with A (or AAAA) host
* resolution
*/
query->query_type = PJ_DNS_TYPE_A;
query->naptr[0].res_type.slen = 0;
query->req.def_port = target->addr.port;
}
/* Start the asynchronous query */
PJ_LOG(5, (query->objname,
"Starting async DNS %s query: target=%.*s%.*s, transport=%s, "
"port=%d",
pj_dns_get_type_name(query->query_type),
(int)query->naptr[0].res_type.slen,
query->naptr[0].res_type.ptr,
(int)query->naptr[0].name.slen, query->naptr[0].name.ptr,
pjsip_transport_get_type_name(target->type),
target->addr.port));
if (query->query_type == PJ_DNS_TYPE_SRV) {
int opt = 0;
if (af == pj_AF_UNSPEC())
opt = PJ_DNS_SRV_FALLBACK_A | PJ_DNS_SRV_FALLBACK_AAAA |
PJ_DNS_SRV_RESOLVE_AAAA;
else if (af == pj_AF_INET6())
opt = PJ_DNS_SRV_FALLBACK_AAAA | PJ_DNS_SRV_RESOLVE_AAAA_ONLY;
else /* af == pj_AF_INET() */
opt = PJ_DNS_SRV_FALLBACK_A;
status = pj_dns_srv_resolve(&query->naptr[0].name,
&query->naptr[0].res_type,
query->req.def_port, pool, resolver->res,
opt, query, &srv_resolver_cb, NULL);
} else if (query->query_type == PJ_DNS_TYPE_A) {
/* Resolve DNS A record if address family is not fixed to IPv6 */
if (af != pj_AF_INET6()) {
/* If there will be DNS AAAA query too, let's setup a dummy one
* here, otherwise app callback may be called immediately (before
* DNS AAAA query is sent) when DNS A record is available in the
* cache.
*/
if (af == pj_AF_UNSPEC())
query->object6 = (pj_dns_async_query*)0x1;
status = pj_dns_resolver_start_query(resolver->res,
&query->naptr[0].name,
PJ_DNS_TYPE_A, 0,
&dns_a_callback,
query, &query->object);
}
/* Resolve DNS AAAA record if address family is not fixed to IPv4 */
if (af != pj_AF_INET() && status == PJ_SUCCESS) {
status = pj_dns_resolver_start_query(resolver->res,
&query->naptr[0].name,
PJ_DNS_TYPE_AAAA, 0,
&dns_aaaa_callback,
query, &query->object6);
}
} else {
pj_assert(!"Unexpected");
status = PJ_EBUG;
}
if (status != PJ_SUCCESS)
goto on_error;
return;
#else /* PJSIP_HAS_RESOLVER */
PJ_UNUSED_ARG(pool);
PJ_UNUSED_ARG(query);
PJ_UNUSED_ARG(srv_name);
#endif /* PJSIP_HAS_RESOLVER */
on_error:
if (status != PJ_SUCCESS) {
char errmsg[PJ_ERR_MSG_SIZE];
PJ_LOG(4,(THIS_FILE, "Failed to resolve '%.*s'. Err=%d (%s)",
(int)target->addr.host.slen,
target->addr.host.ptr,
status,
pj_strerror(status,errmsg,sizeof(errmsg)).ptr));
(*cb)(status, token, NULL);
return;
}
}