本文整理汇总了C++中pjsip_endpt_create_pool函数的典型用法代码示例。如果您正苦于以下问题:C++ pjsip_endpt_create_pool函数的具体用法?C++ pjsip_endpt_create_pool怎么用?C++ pjsip_endpt_create_pool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pjsip_endpt_create_pool函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: parse_test
static int parse_test(void)
{
unsigned i;
for (i=0; i<PJ_ARRAY_SIZE(p_tests); ++i) {
pj_pool_t *pool;
pjsip_media_type ctype;
pjsip_msg_body *body;
pj_str_t str;
int rc;
pool = pjsip_endpt_create_pool(endpt, NULL, 512, 512);
init_media_type(&ctype, p_tests[i].ctype, p_tests[i].csubtype,
p_tests[i].boundary);
pj_strdup2_with_null(pool, &str, p_tests[i].msg);
body = pjsip_multipart_parse(pool, str.ptr, str.slen, &ctype, 0);
if (!body)
return -100;
if (p_tests[i].verify) {
rc = p_tests[i].verify(pool, body);
} else {
rc = 0;
}
pj_pool_release(pool);
if (rc)
return rc;
}
return 0;
}
开发者ID:carlosdelfino,项目名称:WorkshopTelefoniaAutomacao,代码行数:34,代码来源:multipart_test.c
示例2: mod_ua_load
/*
* mod_ua_load()
*
* Called when module is being loaded by endpoint.
*/
static pj_status_t mod_ua_load(pjsip_endpoint *endpt)
{
pj_status_t status;
/* Initialize the user agent. */
mod_ua.endpt = endpt;
mod_ua.pool = pjsip_endpt_create_pool( endpt, "ua%p", PJSIP_POOL_LEN_UA,
PJSIP_POOL_INC_UA);
if (mod_ua.pool == NULL)
return PJ_ENOMEM;
status = pj_mutex_create_recursive(mod_ua.pool, " ua%p", &mod_ua.mutex);
if (status != PJ_SUCCESS)
return status;
mod_ua.dlg_table = pj_hash_create(mod_ua.pool, PJSIP_MAX_DIALOG_COUNT);
if (mod_ua.dlg_table == NULL)
return PJ_ENOMEM;
pj_list_init(&mod_ua.free_dlgset_nodes);
/* Initialize dialog lock. */
status = pj_thread_local_alloc(&pjsip_dlg_lock_tls_id);
if (status != PJ_SUCCESS)
return status;
pj_thread_local_set(pjsip_dlg_lock_tls_id, NULL);
return PJ_SUCCESS;
}
开发者ID:nishantjr,项目名称:pjproject,代码行数:36,代码来源:sip_ua_layer.c
示例3: msg_err_test
int msg_err_test(void)
{
pj_pool_t *pool;
unsigned i;
PJ_LOG(3,(THIS_FILE, "Testing parsing error"));
pool = pjsip_endpt_create_pool(endpt, "msgerrtest", 4000, 4000);
for (i=0; i<PJ_ARRAY_SIZE(test_entries); ++i) {
pjsip_parser_err_report err_list, *e;
PJ_LOG(3,(THIS_FILE, " Parsing msg %d", i));
pj_list_init(&err_list);
pjsip_parse_msg(pool, test_entries[i].msg,
strlen(test_entries[i].msg), &err_list);
e = err_list.next;
while (e != &err_list) {
PJ_LOG(3,(THIS_FILE,
" reported syntax error at line %d col %d for %.*s",
e->line, e->col,
(int)e->hname.slen,
e->hname.ptr));
e = e->next;
}
}
pj_pool_release(pool);
return 0;
}
开发者ID:avble,项目名称:natClientEx,代码行数:31,代码来源:msg_err_test.c
示例4: mod_init
/*
* Module initialization.
* This will be called by endpoint when it initializes all modules.
*/
static pj_status_t mod_init( pjsip_endpoint *endpt,
struct pjsip_module *mod, pj_uint32_t id )
{
pj_pool_t *pool;
pool = pjsip_endpt_create_pool(endpt, "esubmgr", MGR_POOL_SIZE, MGR_POOL_INC);
if (!pool)
return -1;
/* Manager initialization: create hash table and mutex. */
mgr.pool = pool;
mgr.endpt = endpt;
mgr.ht = pj_hash_create(pool, HASH_TABLE_SIZE);
if (!mgr.ht)
return -1;
mgr.mutex = pj_mutex_create(pool, "esubmgr", PJ_MUTEX_SIMPLE);
if (!mgr.mutex)
return -1;
/* Attach manager to module. */
mod->mod_data = &mgr;
/* Init package list. */
pj_list_init(&mgr.pkg_list);
/* Init Allow-Events header. */
mgr.allow_events = pjsip_allow_events_hdr_create(mgr.pool);
/* Save the module ID. */
mod_id = id;
pjsip_event_notify_init_parser();
return 0;
}
开发者ID:svn2github,项目名称:pjproject,代码行数:39,代码来源:event_notify.c
示例5: PJ_DEF
PJ_DEF(pj_status_t) pjsip_publishc_create( pjsip_endpoint *endpt,
const pjsip_publishc_opt *opt,
void *token,
pjsip_publishc_cb *cb,
pjsip_publishc **p_pubc)
{
pj_pool_t *pool;
pjsip_publishc *pubc;
pjsip_publishc_opt default_opt;
pj_status_t status;
/* Verify arguments. */
PJ_ASSERT_RETURN(endpt && cb && p_pubc, PJ_EINVAL);
pool = pjsip_endpt_create_pool(endpt, "pubc%p", 1024, 1024);
PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
pubc = PJ_POOL_ZALLOC_T(pool, pjsip_publishc);
pubc->pool = pool;
pubc->endpt = endpt;
pubc->token = token;
pubc->cb = cb;
pubc->expires = PJSIP_PUBC_EXPIRATION_NOT_SPECIFIED;
if (!opt) {
pjsip_publishc_opt_default(&default_opt);
opt = &default_opt;
}
pj_memcpy(&pubc->opt, opt, sizeof(*opt));
pj_list_init(&pubc->pending_reqs);
pj_list_init(&pubc->pending_reqs_empty);
status = pj_mutex_create_recursive(pubc->pool, "pubc%p", &pubc->mutex);
if (status != PJ_SUCCESS) {
pj_pool_release(pool);
return status;
}
status = pjsip_auth_clt_init(&pubc->auth_sess, endpt, pubc->pool, 0);
if (status != PJ_SUCCESS) {
pj_mutex_destroy(pubc->mutex);
pj_pool_release(pool);
return status;
}
pj_list_init(&pubc->route_set);
pj_list_init(&pubc->usr_hdr);
/* Done */
*p_pubc = pubc;
return PJ_SUCCESS;
}
开发者ID:0x0B501E7E,项目名称:pjproject,代码行数:53,代码来源:publishc.c
示例6: PJ_DEF
PJ_DEF(pj_status_t) pjsip_regc_create( pjsip_endpoint *endpt, void *token,
pjsip_regc_cb *cb,
pjsip_regc **p_regc)
{
pj_pool_t *pool;
pjsip_regc *regc;
pj_status_t status;
/* Verify arguments. */
PJ_ASSERT_RETURN(endpt && cb && p_regc, PJ_EINVAL);
pool = pjsip_endpt_create_pool(endpt, "regc%p", 1024, 1024);
PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
regc = PJ_POOL_ZALLOC_T(pool, pjsip_regc);
regc->pool = pool;
regc->endpt = endpt;
regc->token = token;
regc->cb = cb;
regc->expires = PJSIP_REGC_EXPIRATION_NOT_SPECIFIED;
regc->add_xuid_param = pjsip_cfg()->regc.add_xuid_param;
status = pj_lock_create_recursive_mutex(pool, pool->obj_name,
®c->lock);
if (status != PJ_SUCCESS) {
pj_pool_release(pool);
return status;
}
status = pj_atomic_create(pool, 0, ®c->busy_ctr);
if (status != PJ_SUCCESS) {
pj_lock_destroy(regc->lock);
pj_pool_release(pool);
return status;
}
status = pjsip_auth_clt_init(®c->auth_sess, endpt, regc->pool, 0);
if (status != PJ_SUCCESS)
return status;
pj_list_init(®c->route_set);
pj_list_init(®c->hdr_list);
pj_list_init(®c->contact_hdr_list);
pj_list_init(®c->removed_contact_hdr_list);
/* Done */
*p_regc = regc;
return PJ_SUCCESS;
}
开发者ID:iamroger,项目名称:voip,代码行数:50,代码来源:sip_reg.c
示例7: tcp_start_read
/*
* This utility function creates receive data buffers and start
* asynchronous recv() operations from the socket. It is called after
* accept() or connect() operation complete.
*/
static pj_status_t tcp_start_read(struct tcp_transport *tcp)
{
pj_pool_t *pool;
pj_ssize_t size;
pj_sockaddr *rem_addr;
void *readbuf[1];
pj_status_t status;
/* Init rdata */
pool = pjsip_endpt_create_pool(tcp->base.endpt,
"rtd%p",
PJSIP_POOL_RDATA_LEN,
PJSIP_POOL_RDATA_INC);
if (!pool) {
tcp_perror(tcp->base.obj_name, "Unable to create pool", PJ_ENOMEM);
return PJ_ENOMEM;
}
tcp->rdata.tp_info.pool = pool;
tcp->rdata.tp_info.transport = &tcp->base;
tcp->rdata.tp_info.tp_data = tcp;
tcp->rdata.tp_info.op_key.rdata = &tcp->rdata;
pj_ioqueue_op_key_init(&tcp->rdata.tp_info.op_key.op_key,
sizeof(pj_ioqueue_op_key_t));
tcp->rdata.pkt_info.src_addr = tcp->base.key.rem_addr;
tcp->rdata.pkt_info.src_addr_len = sizeof(tcp->rdata.pkt_info.src_addr);
rem_addr = &tcp->base.key.rem_addr;
pj_sockaddr_print(rem_addr, tcp->rdata.pkt_info.src_name,
sizeof(tcp->rdata.pkt_info.src_name), 0);
tcp->rdata.pkt_info.src_port = pj_sockaddr_get_port(rem_addr);
size = sizeof(tcp->rdata.pkt_info.packet);
readbuf[0] = tcp->rdata.pkt_info.packet;
status = pj_activesock_start_read2(tcp->asock, tcp->base.pool, size,
readbuf, 0);
if (status != PJ_SUCCESS && status != PJ_EPENDING) {
PJ_LOG(4, (tcp->base.obj_name,
"pj_activesock_start_read() error, status=%d",
status));
return status;
}
return PJ_SUCCESS;
}
开发者ID:ChrisKwon,项目名称:spore,代码行数:51,代码来源:sip_transport_tcp.c
示例8: tls_start_read
/*
* This utility function creates receive data buffers and start
* asynchronous recv() operations from the socket. It is called after
* accept() or connect() operation complete.
*/
static pj_status_t tls_start_read(struct tls_transport *tls)
{
pj_pool_t *pool;
pj_ssize_t size;
pj_sockaddr_in *rem_addr;
void *readbuf[1];
pj_status_t status;
/* Init rdata */
pool = pjsip_endpt_create_pool(tls->base.endpt,
"rtd%p",
PJSIP_POOL_RDATA_LEN,
PJSIP_POOL_RDATA_INC);
if (!pool) {
tls_perror(tls->base.obj_name, "Unable to create pool", PJ_ENOMEM);
return PJ_ENOMEM;
}
tls->rdata.tp_info.pool = pool;
tls->rdata.tp_info.transport = &tls->base;
tls->rdata.tp_info.tp_data = tls;
tls->rdata.tp_info.op_key.rdata = &tls->rdata;
pj_ioqueue_op_key_init(&tls->rdata.tp_info.op_key.op_key,
sizeof(pj_ioqueue_op_key_t));
tls->rdata.pkt_info.src_addr = tls->base.key.rem_addr;
tls->rdata.pkt_info.src_addr_len = sizeof(pj_sockaddr_in);
rem_addr = (pj_sockaddr_in*) &tls->base.key.rem_addr;
pj_ansi_strcpy(tls->rdata.pkt_info.src_name,
pj_inet_ntoa(rem_addr->sin_addr));
tls->rdata.pkt_info.src_port = pj_ntohs(rem_addr->sin_port);
size = sizeof(tls->rdata.pkt_info.packet);
readbuf[0] = tls->rdata.pkt_info.packet;
status = pj_ssl_sock_start_read2(tls->ssock, tls->base.pool, size,
readbuf, 0);
if (status != PJ_SUCCESS && status != PJ_EPENDING) {
PJ_LOG(4, (tls->base.obj_name,
"pj_ssl_sock_start_read() error, status=%d",
status));
return status;
}
return PJ_SUCCESS;
}
开发者ID:conght,项目名称:BLM-Lib,代码行数:51,代码来源:sip_transport_tls.c
示例9: pjsip_messaging_create_session
pjsip_messaging_create_session( pjsip_endpoint *endpt, const pj_str_t *param_from,
const pj_str_t *param_to )
{
pj_pool_t *pool;
pjsip_messaging_session *ses;
pj_str_t tmp, to;
pool = pjsip_endpt_create_pool(endpt, "imsess", 1024, 1024);
if (!pool)
return NULL;
ses = pj_pool_calloc(pool, 1, sizeof(pjsip_messaging_session));
ses->pool = pool;
ses->endpt = endpt;
ses->call_id = pjsip_cid_hdr_create(pool);
pj_create_unique_string(pool, &ses->call_id->id);
ses->cseq = pjsip_cseq_hdr_create(pool);
ses->cseq->cseq = pj_rand();
ses->cseq->method = message_method;
ses->from = pjsip_from_hdr_create(pool);
pj_strdup_with_null(pool, &tmp, param_from);
ses->from->uri = pjsip_parse_uri(pool, tmp.ptr, tmp.slen, PJSIP_PARSE_URI_AS_NAMEADDR);
if (ses->from->uri == NULL) {
pjsip_endpt_destroy_pool(endpt, pool);
return NULL;
}
pj_create_unique_string(pool, &ses->from->tag);
ses->to = pjsip_to_hdr_create(pool);
pj_strdup_with_null(pool, &to, param_from);
ses->to->uri = pjsip_parse_uri(pool, to.ptr, to.slen, PJSIP_PARSE_URI_AS_NAMEADDR);
if (ses->to->uri == NULL) {
pjsip_endpt_destroy_pool(endpt, pool);
return NULL;
}
PJ_LOG(4,(THIS_FILE, "IM session created: recipient=%s", to.ptr));
return ses;
}
开发者ID:svn2github,项目名称:pjproject,代码行数:42,代码来源:messaging.c
示例10: PJ_DEF
/*
* Create new transmit buffer.
*/
PJ_DEF(pj_status_t) pjsip_tx_data_create( pjsip_tpmgr *mgr,
pjsip_tx_data **p_tdata )
{
pj_pool_t *pool;
pjsip_tx_data *tdata;
pj_status_t status;
PJ_ASSERT_RETURN(mgr && p_tdata, PJ_EINVAL);
pool = pjsip_endpt_create_pool( mgr->endpt, "tdta%p",
PJSIP_POOL_LEN_TDATA,
PJSIP_POOL_INC_TDATA );
if (!pool)
return PJ_ENOMEM;
tdata = PJ_POOL_ZALLOC_T(pool, pjsip_tx_data);
tdata->pool = pool;
tdata->mgr = mgr;
pj_memcpy(tdata->obj_name, pool->obj_name, PJ_MAX_OBJ_NAME);
status = pj_atomic_create(tdata->pool, 0, &tdata->ref_cnt);
if (status != PJ_SUCCESS) {
pjsip_endpt_release_pool( mgr->endpt, tdata->pool );
return status;
}
//status = pj_lock_create_simple_mutex(pool, "tdta%p", &tdata->lock);
status = pj_lock_create_null_mutex(pool, "tdta%p", &tdata->lock);
if (status != PJ_SUCCESS) {
pjsip_endpt_release_pool( mgr->endpt, tdata->pool );
return status;
}
pj_ioqueue_op_key_init(&tdata->op_key.key, sizeof(tdata->op_key.key));
#if defined(PJ_DEBUG) && PJ_DEBUG!=0
pj_atomic_inc( tdata->mgr->tdata_counter );
#endif
*p_tdata = tdata;
return PJ_SUCCESS;
}
开发者ID:ambush276,项目名称:rifle,代码行数:45,代码来源:sip_transport.c
示例11: simple_uri_test
static int simple_uri_test(void)
{
unsigned i;
pj_pool_t *pool;
pj_status_t status;
PJ_LOG(3,(THIS_FILE, " simple test"));
for (i=0; i<PJ_ARRAY_SIZE(uri_test_array); ++i) {
pool = pjsip_endpt_create_pool(endpt, "", POOL_SIZE, POOL_SIZE);
status = do_uri_test(pool, &uri_test_array[i]);
pjsip_endpt_release_pool(endpt, pool);
if (status != PJ_SUCCESS) {
PJ_LOG(3,(THIS_FILE, " error %d when testing entry %d",
status, i));
return status;
}
}
return 0;
}
开发者ID:Netrounds,项目名称:pjproject-old,代码行数:20,代码来源:uri_test.c
示例12: permanent_contact_validate
/*! \brief Helper function which validates a permanent contact */
static int permanent_contact_validate(void *data)
{
const char *value = data;
pj_pool_t *pool;
pj_str_t contact_uri;
static const pj_str_t HCONTACT = { "Contact", 7 };
pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "Permanent Contact Validation", 256, 256);
if (!pool) {
return -1;
}
pj_strdup2_with_null(pool, &contact_uri, value);
if (!pjsip_parse_hdr(pool, &HCONTACT, contact_uri.ptr, contact_uri.slen, NULL)) {
pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
return -1;
}
pjsip_endpt_release_pool(ast_sip_get_pjsip_endpoint(), pool);
return 0;
}
开发者ID:lyx2014,项目名称:Asterisk,代码行数:22,代码来源:location.c
示例13: pjsip_endpt_create_pool
/* Helper function to create "incoming" packet */
struct recv_list *create_incoming_packet( struct loop_transport *loop,
pjsip_tx_data *tdata )
{
pj_pool_t *pool;
struct recv_list *pkt;
pool = pjsip_endpt_create_pool(loop->base.endpt, "rdata",
PJSIP_POOL_RDATA_LEN,
PJSIP_POOL_RDATA_INC+5);
if (!pool)
return NULL;
pkt = pj_pool_zalloc(pool, sizeof(struct recv_list));
/* Initialize rdata. */
pkt->rdata.tp_info.pool = pool;
pkt->rdata.tp_info.transport = &loop->base;
/* Copy the packet. */
pj_memcpy(pkt->rdata.pkt_info.packet, tdata->buf.start,
tdata->buf.cur - tdata->buf.start);
pkt->rdata.pkt_info.len = tdata->buf.cur - tdata->buf.start;
/* "Source address" info. */
pkt->rdata.pkt_info.src_addr_len = sizeof(pj_sockaddr_in);
if (loop->base.key.type == PJSIP_TRANSPORT_LOOP)
pj_ansi_strcpy(pkt->rdata.pkt_info.src_name, ADDR_LOOP);
else
pj_ansi_strcpy(pkt->rdata.pkt_info.src_name, ADDR_LOOP_DGRAM);
pkt->rdata.pkt_info.src_port = loop->base.local_name.port;
/* When do we need to "deliver" this packet. */
pj_gettimeofday(&pkt->rdata.pkt_info.timestamp);
pkt->rdata.pkt_info.timestamp.msec += loop->recv_delay;
pj_time_val_normalize(&pkt->rdata.pkt_info.timestamp);
/* Done. */
return pkt;
}
开发者ID:tibastral,项目名称:symphonie,代码行数:41,代码来源:sip_transport_loop.c
示例14: PJ_DEF
PJ_DEF(pj_status_t) pjsip_publishc_create( pjsip_endpoint *endpt,
unsigned options,
void *token,
pjsip_publishc_cb *cb,
pjsip_publishc **p_pubc)
{
pj_pool_t *pool;
pjsip_publishc *pubc;
pj_status_t status;
/* Verify arguments. */
PJ_ASSERT_RETURN(endpt && cb && p_pubc, PJ_EINVAL);
PJ_ASSERT_RETURN(options == 0, PJ_EINVAL);
PJ_UNUSED_ARG(options);
pool = pjsip_endpt_create_pool(endpt, "pubc%p", 1024, 1024);
PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
pubc = PJ_POOL_ZALLOC_T(pool, pjsip_publishc);
pubc->pool = pool;
pubc->endpt = endpt;
pubc->token = token;
pubc->cb = cb;
pubc->expires = PJSIP_PUBC_EXPIRATION_NOT_SPECIFIED;
status = pjsip_auth_clt_init(&pubc->auth_sess, endpt, pubc->pool, 0);
if (status != PJ_SUCCESS)
return status;
pj_list_init(&pubc->route_set);
/* Done */
*p_pubc = pubc;
return PJ_SUCCESS;
}
开发者ID:svn2github,项目名称:pjproject,代码行数:37,代码来源:publishc.c
示例15: tcp_create
/*
* Common function to create TCP transport, called when pending accept() and
* pending connect() complete.
*/
static pj_status_t tcp_create( struct tcp_listener *listener,
pj_pool_t *pool,
pj_sock_t sock, pj_bool_t is_server,
const pj_sockaddr *local,
const pj_sockaddr *remote,
struct tcp_transport **p_tcp)
{
struct tcp_transport *tcp;
pj_ioqueue_t *ioqueue;
pj_activesock_cfg asock_cfg;
pj_activesock_cb tcp_callback;
const pj_str_t ka_pkt = PJSIP_TCP_KEEP_ALIVE_DATA;
char print_addr[PJ_INET6_ADDRSTRLEN+10];
pj_status_t status;
PJ_ASSERT_RETURN(sock != PJ_INVALID_SOCKET, PJ_EINVAL);
if (pool == NULL) {
pool = pjsip_endpt_create_pool(listener->endpt, "tcp",
POOL_TP_INIT, POOL_TP_INC);
PJ_ASSERT_RETURN(pool != NULL, PJ_ENOMEM);
}
/*
* Create and initialize basic transport structure.
*/
tcp = PJ_POOL_ZALLOC_T(pool, struct tcp_transport);
tcp->is_server = is_server;
tcp->sock = sock;
/*tcp->listener = listener;*/
pj_list_init(&tcp->delayed_list);
tcp->base.pool = pool;
pj_ansi_snprintf(tcp->base.obj_name, PJ_MAX_OBJ_NAME,
(is_server ? "tcps%p" :"tcpc%p"), tcp);
status = pj_atomic_create(pool, 0, &tcp->base.ref_cnt);
if (status != PJ_SUCCESS) {
goto on_error;
}
status = pj_lock_create_recursive_mutex(pool, "tcp", &tcp->base.lock);
if (status != PJ_SUCCESS) {
goto on_error;
}
tcp->base.key.type = listener->factory.type;
pj_sockaddr_cp(&tcp->base.key.rem_addr, remote);
tcp->base.type_name = (char*)pjsip_transport_get_type_name(
(pjsip_transport_type_e)tcp->base.key.type);
tcp->base.flag = pjsip_transport_get_flag_from_type(
(pjsip_transport_type_e)tcp->base.key.type);
tcp->base.info = (char*) pj_pool_alloc(pool, 64);
pj_ansi_snprintf(tcp->base.info, 64, "%s to %s",
tcp->base.type_name,
pj_sockaddr_print(remote, print_addr,
sizeof(print_addr), 3));
tcp->base.addr_len = pj_sockaddr_get_len(remote);
pj_sockaddr_cp(&tcp->base.local_addr, local);
sockaddr_to_host_port(pool, &tcp->base.local_name, local);
sockaddr_to_host_port(pool, &tcp->base.remote_name, remote);
tcp->base.dir = is_server? PJSIP_TP_DIR_INCOMING : PJSIP_TP_DIR_OUTGOING;
tcp->base.endpt = listener->endpt;
tcp->base.tpmgr = listener->tpmgr;
tcp->base.send_msg = &tcp_send_msg;
tcp->base.do_shutdown = &tcp_shutdown;
tcp->base.destroy = &tcp_destroy_transport;
/* Create active socket */
pj_activesock_cfg_default(&asock_cfg);
asock_cfg.async_cnt = 1;
pj_bzero(&tcp_callback, sizeof(tcp_callback));
tcp_callback.on_data_read = &on_data_read;
tcp_callback.on_data_sent = &on_data_sent;
tcp_callback.on_connect_complete = &on_connect_complete;
ioqueue = pjsip_endpt_get_ioqueue(listener->endpt);
status = pj_activesock_create(pool, sock, pj_SOCK_STREAM(), &asock_cfg,
ioqueue, &tcp_callback, tcp, &tcp->asock);
if (status != PJ_SUCCESS) {
goto on_error;
}
/* Register transport to transport manager */
status = pjsip_transport_register(listener->tpmgr, &tcp->base);
if (status != PJ_SUCCESS) {
goto on_error;
}
tcp->is_registered = PJ_TRUE;
//.........这里部分代码省略.........
开发者ID:ChrisKwon,项目名称:spore,代码行数:101,代码来源:sip_transport_tcp.c
示例16: PJ_DEF
/*
* This is the public API to create, initialize, register, and start the
* TCP listener.
*/
PJ_DEF(pj_status_t) pjsip_tcp_transport_start3(
pjsip_endpoint *endpt,
const pjsip_tcp_transport_cfg *cfg,
pjsip_tpfactory **p_factory
)
{
pj_pool_t *pool;
pj_sock_t sock = PJ_INVALID_SOCKET;
struct tcp_listener *listener;
pj_activesock_cfg asock_cfg;
pj_activesock_cb listener_cb;
pj_sockaddr *listener_addr;
int addr_len;
pj_status_t status;
/* Sanity check */
PJ_ASSERT_RETURN(endpt && cfg->async_cnt, PJ_EINVAL);
/* Verify that address given in a_name (if any) is valid */
if (cfg->addr_name.host.slen) {
pj_sockaddr tmp;
status = pj_sockaddr_init(cfg->af, &tmp, &cfg->addr_name.host,
(pj_uint16_t)cfg->addr_name.port);
if (status != PJ_SUCCESS || !pj_sockaddr_has_addr(&tmp) ||
(cfg->af==pj_AF_INET() &&
tmp.ipv4.sin_addr.s_addr==PJ_INADDR_NONE))
{
/* Invalid address */
return PJ_EINVAL;
}
}
pool = pjsip_endpt_create_pool(endpt, "tcplis", POOL_LIS_INIT,
POOL_LIS_INC);
PJ_ASSERT_RETURN(pool, PJ_ENOMEM);
listener = PJ_POOL_ZALLOC_T(pool, struct tcp_listener);
listener->factory.pool = pool;
listener->factory.type = cfg->af==pj_AF_INET() ? PJSIP_TRANSPORT_TCP :
PJSIP_TRANSPORT_TCP6;
listener->factory.type_name = (char*)
pjsip_transport_get_type_name(listener->factory.type);
listener->factory.flag =
pjsip_transport_get_flag_from_type(listener->factory.type);
listener->qos_type = cfg->qos_type;
pj_memcpy(&listener->qos_params, &cfg->qos_params,
sizeof(cfg->qos_params));
pj_ansi_strcpy(listener->factory.obj_name, "tcplis");
if (listener->factory.type==PJSIP_TRANSPORT_TCP6)
pj_ansi_strcat(listener->factory.obj_name, "6");
status = pj_lock_create_recursive_mutex(pool, listener->factory.obj_name,
&listener->factory.lock);
if (status != PJ_SUCCESS)
goto on_error;
/* Create socket */
status = pj_sock_socket(cfg->af, pj_SOCK_STREAM(), 0, &sock);
if (status != PJ_SUCCESS)
goto on_error;
/* Apply QoS, if specified */
status = pj_sock_apply_qos2(sock, cfg->qos_type, &cfg->qos_params,
2, listener->factory.obj_name,
"SIP TCP listener socket");
/* Bind address may be different than factory.local_addr because
* factory.local_addr will be resolved below.
*/
pj_sockaddr_cp(&listener->bound_addr, &cfg->bind_addr);
/* Bind socket */
listener_addr = &listener->factory.local_addr;
pj_sockaddr_cp(listener_addr, &cfg->bind_addr);
status = pj_sock_bind(sock, listener_addr,
pj_sockaddr_get_len(listener_addr));
if (status != PJ_SUCCESS)
goto on_error;
/* Retrieve the bound address */
addr_len = pj_sockaddr_get_len(listener_addr);
status = pj_sock_getsockname(sock, listener_addr, &addr_len);
if (status != PJ_SUCCESS)
goto on_error;
/* If published host/IP is specified, then use that address as the
* listener advertised address.
*/
if (cfg->addr_name.host.slen) {
/* Copy the address */
listener->factory.addr_name = cfg->addr_name;
//.........这里部分代码省略.........
开发者ID:ChrisKwon,项目名称:spore,代码行数:101,代码来源:sip_transport_tcp.c
示例17: pool_
SipIceTransport::SipIceTransport(pjsip_endpoint* endpt, pj_pool_t& /* pool */,
long /* t_type */,
const std::shared_ptr<IceTransport>& ice,
int comp_id)
: pool_(nullptr, pj_pool_release)
, rxPool_(nullptr, pj_pool_release)
, trData_()
, rdata_()
, ice_(ice)
, comp_id_(comp_id)
{
trData_.self = this;
if (not ice or not ice->isRunning())
throw std::logic_error("ice transport must exist and negotiation completed");
RING_DBG("[email protected]%p {tr=%p}", this, &trData_.base);
auto& base = trData_.base;
pool_.reset(pjsip_endpt_create_pool(endpt, "SipIceTransport.pool", POOL_TP_INIT, POOL_TP_INC));
if (not pool_)
throw std::bad_alloc();
auto pool = pool_.get();
pj_ansi_snprintf(base.obj_name, PJ_MAX_OBJ_NAME, "SipIceTransport");
base.endpt = endpt;
base.tpmgr = pjsip_endpt_get_tpmgr(endpt);
base.pool = pool;
rdata_.tp_info.pool = pool;
// FIXME: not destroyed in case of exception
if (pj_atomic_create(pool, 0, &base.ref_cnt) != PJ_SUCCESS)
throw std::runtime_error("Can't create PJSIP atomic.");
// FIXME: not destroyed in case of exception
if (pj_lock_create_recursive_mutex(pool, "SipIceTransport.mutex", &base.lock) != PJ_SUCCESS)
throw std::runtime_error("Can't create PJSIP mutex.");
auto remote = ice->getRemoteAddress(comp_id);
RING_DBG("SipIceTransport: remote is %s", remote.toString(true).c_str());
pj_sockaddr_cp(&base.key.rem_addr, remote.pjPtr());
base.key.type = PJSIP_TRANSPORT_UDP;//t_type;
base.type_name = (char*)pjsip_transport_get_type_name((pjsip_transport_type_e)base.key.type);
base.flag = pjsip_transport_get_flag_from_type((pjsip_transport_type_e)base.key.type);
base.info = (char*) pj_pool_alloc(pool, TRANSPORT_INFO_LENGTH);
char print_addr[PJ_INET6_ADDRSTRLEN+10];
pj_ansi_snprintf(base.info, TRANSPORT_INFO_LENGTH, "%s to %s",
base.type_name,
pj_sockaddr_print(remote.pjPtr(), print_addr,
sizeof(print_addr), 3));
base.addr_len = remote.getLength();
base.dir = PJSIP_TP_DIR_NONE;//is_server? PJSIP_TP_DIR_INCOMING : PJSIP_TP_DIR_OUTGOING;
base.data = nullptr;
/* Set initial local address */
auto local = ice->getDefaultLocalAddress();
pj_sockaddr_cp(&base.local_addr, local.pjPtr());
sockaddr_to_host_port(pool, &base.local_name, &base.local_addr);
sockaddr_to_host_port(pool, &base.remote_name, remote.pjPtr());
base.send_msg = [](pjsip_transport *transport,
pjsip_tx_data *tdata,
const pj_sockaddr_t *rem_addr, int addr_len,
void *token, pjsip_transport_callback callback) {
auto& this_ = reinterpret_cast<TransportData*>(transport)->self;
return this_->send(tdata, rem_addr, addr_len, token, callback);
};
base.do_shutdown = [](pjsip_transport *transport) -> pj_status_t {
auto& this_ = reinterpret_cast<TransportData*>(transport)->self;
RING_WARN("[email protected]%p: shutdown", this_);
return PJ_SUCCESS;
};
base.destroy = [](pjsip_transport *transport) -> pj_status_t {
auto& this_ = reinterpret_cast<TransportData*>(transport)->self;
RING_WARN("[email protected]%p: destroy", this_);
delete this_;
return PJ_SUCCESS;
};
/* Init rdata */
rxPool_.reset(pjsip_endpt_create_pool(base.endpt,
"SipIceTransport.rtd%p",
PJSIP_POOL_RDATA_LEN,
PJSIP_POOL_RDATA_INC));
if (not rxPool_)
throw std::bad_alloc();
auto rx_pool = rxPool_.get();
rdata_.tp_info.pool = rx_pool;
rdata_.tp_info.transport = &base;
rdata_.tp_info.tp_data = this;
rdata_.tp_info.op_key.rdata = &rdata_;
pj_ioqueue_op_key_init(&rdata_.tp_info.op_key.op_key, sizeof(pj_ioqueue_op_key_t));
rdata_.pkt_info.src_addr = base.key.rem_addr;
rdata_.pkt_info.src_addr_len = sizeof(rdata_.pkt_info.src_addr);
auto rem_addr = &base.key.rem_addr;
pj_sockaddr_print(rem_addr, rdata_.pkt_info.src_name, sizeof(rdata_.pkt_info.src_name), 0);
//.........这里部分代码省略.........
开发者ID:alexzah,项目名称:ring-daemon,代码行数:101,代码来源:sip_transport_ice.cpp
示例18: PJ_DEF
/*
* This is the public API to create, initialize, register, and start the
* TCP listener.
*/
PJ_DEF(pj_status_t) pjsip_tcp_transport_start2(pjsip_endpoint *endpt,
const pj_sockaddr_in *local,
const pjsip_host_port *a_name,
unsigned async_cnt,
pjsip_tpfactory **p_factory)
{
pj_pool_t *pool;
pj_sock_t sock = PJ_INVALID_SOCKET;
struct tcp_listener *listener;
pj_activesock_cfg asock_cfg;
pj_activesock_cb listener_cb;
pj_sockaddr_in *listener_addr;
int addr_len;
pj_status_t status;
/* Sanity check */
PJ_ASSERT_RETURN(endpt && async_cnt, PJ_EINVAL);
/* Verify that address given in a_name (if any) is valid */
if (a_name && a_name->host.slen) {
pj_sockaddr_in tmp;
status = pj_sockaddr_in_init(&tmp, &a_name->host,
(pj_uint16_t)a_name->port);
if (status != PJ_SUCCESS || tmp.sin_addr.s_addr == PJ_INADDR_ANY ||
tmp.sin_addr.s_addr == PJ_INADDR_NONE)
{
/* Invalid address */
return PJ_EINVAL;
}
}
pool = pjsip_endpt_create_pool(endpt, "tcplis", POOL_LIS_INIT,
POOL_LIS_INC);
PJ_ASSERT_RETURN(pool, PJ_ENOMEM);
listener = PJ_POOL_ZALLOC_T(pool, struct tcp_listener);
listener->factory.pool = pool;
listener->factory.type = PJSIP_TRANSPORT_TCP;
listener->factory.type_name = "tcp";
listener->factory.flag =
pjsip_transport_get_flag_from_type(PJSIP_TRANSPORT_TCP);
pj_ansi_strcpy(listener->factory.obj_name, "tcplis");
status = pj_lock_create_recursive_mutex(pool, "tcplis",
&listener->factory.lock);
if (status != PJ_SUCCESS)
goto on_error;
/* Create and bind socket */
status = pj_sock_socket(pj_AF_INET(), pj_SOCK_STREAM(), 0, &sock);
if (status != PJ_SUCCESS)
goto on_error;
listener_addr = (pj_sockaddr_in*)&listener->factory.local_addr;
if (local) {
pj_memcpy(listener_addr, local, sizeof(pj_sockaddr_in));
} else {
pj_sockaddr_in_init(listener_addr, NULL, 0);
}
status = pj_sock_bind(sock, listener_addr, sizeof(pj_sockaddr_in));
if (status != PJ_SUCCESS)
goto on_error;
/* Retrieve the bound address */
addr_len = sizeof(pj_sockaddr_in);
status = pj_sock_getsockname(sock, listener_addr, &addr_len);
if (status != PJ_SUCCESS)
goto on_error;
/* If published host/IP is specified, then use that address as the
* listener advertised address.
*/
if (a_name && a_name->host.slen) {
/* Copy the address */
listener->factory.addr_name = *a_name;
pj_strdup(listener->factory.pool, &listener->factory.addr_name.host,
&a_name->host);
listener->factory.addr_name.port = a_name->port;
} else {
/* No published address is given, use the bound address */
/* If the address returns 0.0.0.0, use the default
* interface address as the transport's address.
*/
if (listener_addr->sin_addr.s_addr == 0) {
pj_sockaddr hostip;
status = pj_gethostip(pj_AF_INET(), &hostip);
if (status != PJ_SUCCESS)
goto on_error;
//.........这里部分代码省略.........
开发者ID:Jopie64,项目名称:pjsip,代码行数:101,代码来源:sip_transport_tcp.c
示例19: rx_task
static int rx_task(void *data)
{
RAII_VAR(struct rx_task_data *, task_data, data, ao2_cleanup);
RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
int added = 0, updated = 0, deleted = 0;
pjsip_contact_hdr *contact_hdr = NULL;
struct registrar_contact_details details = { 0, };
pjsip_tx_data *tdata;
pjsip_response_addr addr;
const char *aor_name = ast_sorcery_object_get_id(task_data->aor);
/* Retrieve the current contacts, we'll need to know whether to update or not */
contacts = ast_sip_location_retrieve_aor_contacts(task_data->aor);
/* So we don't count static contacts against max_contacts we prune them out from the container */
ao2_callback(contacts, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, registrar_prune_static, NULL);
if (registrar_validate_contacts(task_data->rdata, contacts, task_data->aor, &added, &updated, &deleted)) {
/* The provided Contact headers do not conform to the specification */
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), task_data->rdata, 400, NULL, NULL, NULL);
ast_sip_report_failed_acl(task_data->endpoint, task_data->rdata, "registrar_invalid_contacts_provided");
ast_log(LOG_WARNING, "Failed to validate contacts in REGISTER request from '%s'\n",
ast_sorcery_object_get_id(task_data->endpoint));
return PJ_TRUE;
}
if ((MAX(added - deleted, 0) + (!task_data->aor->remove_existing ? ao2_container_count(contacts) : 0)) > task_data->aor->max_contacts) {
/* Enforce the maximum number of contacts */
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), task_data->rdata, 403, NULL, NULL, NULL);
ast_sip_report_failed_acl(task_data->endpoint, task_data->rdata, "registrar_attempt_exceeds_maximum_configured_contacts");
ast_log(LOG_WARNING, "Registration attempt from endpoint '%s' to AOR '%s' will exceed max contacts of %d\n",
ast_sorcery_object_get_id(task_data->endpoint), ast_sorcery_object_get_id(task_data->aor), task_data->aor->max_contacts);
return PJ_TRUE;
}
if (!(details.pool = pjsip_endpt_create_pool(ast_sip_get_pjsip_endpoint(), "Contact Comparison", 256, 256))) {
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), task_data->rdata, 500, NULL, NULL, NULL);
return PJ_TRUE;
}
/* Iterate each provided Contact header and add, update, or delete */
while ((contact_hdr = pjsip_msg_find_hdr(task_data->rdata->msg_info.msg, PJSIP_H_CONTACT, contact_hdr ? contact_hdr->next : NULL))) {
int expiration;
char contact_uri[PJSIP_MAX_URL_SIZE];
RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
if (contact_hdr->star) {
/* A star means to unregister everything, so do so for the possible contacts */
ao2_callback(contacts, OBJ_NODATA | OBJ_MULTIPLE, registrar_delete_contact, (void *)aor_name);
break;
}
if (!PJSIP_URI_SCHEME_IS_SIP(contact_hdr->uri) && !PJSIP_URI_SCHEME_IS_SIPS(contact_hdr->uri)) {
/* This registrar only currently supports sip: and sips: URI schemes */
continue;
}
expiration = registrar_get_expiration(task_data->aor, contact_hdr, task_data->rdata);
details.uri = pjsip_uri_get_uri(contact_hdr->uri);
pjsip_uri_print(PJSIP_URI_IN_CONTACT_HDR, details.uri, contact_uri, sizeof(contact_uri));
if (!(contact = ao2_callback(contacts, OBJ_UNLINK, registrar_find_contact, &details))) {
/* If they are actually trying to delete a contact that does not exist... be forgiving */
if (!expiration) {
ast_verb(3, "Attempted to remove non-existent contact '%s' from AOR '%s' by request\n",
contact_uri, aor_name);
continue;
}
ast_sip_location_add_contact(task_data->aor, contact_uri, ast_tvadd(ast_tvnow(), ast_samp2tv(expiration, 1)));
ast_verb(3, "Added contact '%s' to AOR '%s' with expiration of %d seconds\n",
contact_uri, aor_name, expiration);
ast_test_suite_event_notify("AOR_CONTACT_ADDED",
"Contact: %s\r\n"
"AOR: %s\r\n"
"Expiration: %d",
contact_uri,
aor_name,
expiration);
} else if (expiration) {
RAII_VAR(struct ast_sip_contact *, updated, ast_sorcery_copy(ast_sip_get_sorcery(), contact), ao2_cleanup);
updated->expiration_time = ast_tvadd(ast_tvnow(), ast_samp2tv(expiration, 1));
updated->qualify_frequency = task_data->aor->qualify_frequency;
updated->authenticate_qualify = task_data->aor->authenticate_qualify;
ast_sip_location_update_contact(updated);
ast_debug(3, "Refreshed contact '%s' on AOR '%s' with new expiration of %d seconds\n",
contact_uri, aor_name, expiration);
ast_test_suite_event_notify("AOR_CONTACT_REFRESHED",
"Contact: %s\r\n"
"AOR: %s\r\n"
"Expiration: %d",
contact_uri,
aor_name,
expiration);
} else {
ast_sip_location_delete_contact(contact);
ast_verb(3, "Removed contact '%s' from AOR '%s' due to request\n", contact_uri, aor_name);
ast_test_suite_event_notify("AOR_CONTACT_REMOVED",
//.........这里部分代码省略.........
开发者ID:hardikk,项目名称:asterisk,代码行数:101,代码来源:res_pjsip_registrar.c
示例20: resolve_test
/*
* Main test entry.
*/
int resolve_test(void)
{
pj_pool_t *pool;
pj_dns_resolver *resv;
pj_str_t nameserver;
pj_uint16_t port = 5353;
pj_status_t status;
pool = pjsip_endpt_create_pool(endpt, NULL, 4000, 4000);
status = pjsip_endpt_create_resolver(endpt, &resv);
nameserver = pj_str("192.168
|
请发表评论