Changeset 1080 for pjproject/trunk/pjnath/src/pjnath/stun_session.c
- Timestamp:
- Mar 18, 2007 5:39:27 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath/stun_session.c
r1062 r1080 17 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 18 */ 19 #include <pj lib-util/stun_session.h>19 #include <pjnath/stun_session.h> 20 20 #include <pjlib.h> 21 21 22 22 struct pj_stun_session 23 23 { 24 pj_stun_ endpoint *endpt;24 pj_stun_config *cfg; 25 25 pj_pool_t *pool; 26 26 pj_mutex_t *mutex; … … 120 120 121 121 /* Create pool and initialize basic tdata attributes */ 122 pool = pj_pool_create(sess-> endpt->pf, "tdata%p",122 pool = pj_pool_create(sess->cfg->pf, "tdata%p", 123 123 TDATA_POOL_SIZE, TDATA_POOL_INC, NULL); 124 124 PJ_ASSERT_RETURN(pool, PJ_ENOMEM); … … 171 171 } 172 172 if (tdata->res_timer.id != PJ_FALSE) { 173 pj_timer_heap_cancel(tdata->sess-> endpt->timer_heap,173 pj_timer_heap_cancel(tdata->sess->cfg->timer_heap, 174 174 &tdata->res_timer); 175 175 tdata->res_timer.id = PJ_FALSE; … … 224 224 225 225 /* The server SHOULD include a SERVER attribute in all responses */ 226 if ( PJ_STUN_IS_RESPONSE(msg->hdr.type) ||227 PJ_STUN_IS_ERROR_RESPONSE(msg->hdr.type))226 if (sess->srv_name.slen && (PJ_STUN_IS_RESPONSE(msg->hdr.type) || 227 PJ_STUN_IS_ERROR_RESPONSE(msg->hdr.type))) 228 228 { 229 229 pj_stun_msg_add_string_attr(pool, msg, PJ_STUN_ATTR_SERVER, … … 301 301 /* **************************************************************************/ 302 302 303 PJ_DEF(pj_status_t) pj_stun_session_create( pj_stun_ endpoint *endpt,303 PJ_DEF(pj_status_t) pj_stun_session_create( pj_stun_config *cfg, 304 304 const char *name, 305 305 const pj_stun_session_cb *cb, … … 311 311 pj_status_t status; 312 312 313 PJ_ASSERT_RETURN( endpt&& cb && p_sess, PJ_EINVAL);313 PJ_ASSERT_RETURN(cfg && cb && p_sess, PJ_EINVAL); 314 314 315 315 if (name==NULL) 316 316 name = "sess%p"; 317 317 318 pool = pj_pool_create( endpt->pf, name, 4000, 4000, NULL);318 pool = pj_pool_create(cfg->pf, name, 4000, 4000, NULL); 319 319 PJ_ASSERT_RETURN(pool, PJ_ENOMEM); 320 320 321 321 sess = PJ_POOL_ZALLOC_T(pool, pj_stun_session); 322 sess-> endpt = endpt;322 sess->cfg = cfg; 323 323 sess->pool = pool; 324 324 pj_memcpy(&sess->cb, cb, sizeof(*cb)); … … 384 384 const pj_str_t *srv_name) 385 385 { 386 PJ_ASSERT_RETURN(sess && srv_name, PJ_EINVAL); 387 pj_strdup(sess->pool, &sess->srv_name, srv_name); 386 PJ_ASSERT_RETURN(sess, PJ_EINVAL); 387 if (srv_name) 388 pj_strdup(sess->pool, &sess->srv_name, srv_name); 389 else 390 sess->srv_name.slen = 0; 388 391 return PJ_SUCCESS; 389 392 } … … 490 493 char buf[512]; 491 494 492 if (dst->sa_family == PJ_AF_INET) { 493 const pj_sockaddr_in *dst4 = (const pj_sockaddr_in*)dst; 494 dst_name = pj_inet_ntoa(dst4->sin_addr); 495 dst_port = pj_ntohs(dst4->sin_port); 496 } else if (dst->sa_family == PJ_AF_INET6) { 497 const pj_sockaddr_in6 *dst6 = (const pj_sockaddr_in6*)dst; 495 if (dst->addr.sa_family == PJ_AF_INET) { 496 dst_name = pj_inet_ntoa(dst->ipv4.sin_addr); 497 dst_port = pj_ntohs(dst->ipv4.sin_port); 498 } else if (dst->addr.sa_family == PJ_AF_INET6) { 498 499 dst_name = "IPv6"; 499 dst_port = pj_ntohs(dst 6->sin6_port);500 dst_port = pj_ntohs(dst->ipv6.sin6_port); 500 501 } else { 501 502 LOG_ERR_(sess, "Invalid address family", PJ_EINVAL); … … 559 560 560 561 /* Create STUN client transaction */ 561 status = pj_stun_client_tsx_create(sess-> endpt, tdata->pool,562 status = pj_stun_client_tsx_create(sess->cfg, tdata->pool, 562 563 &tsx_cb, &tdata->client_tsx); 563 564 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); … … 593 594 &on_cache_timeout); 594 595 595 timeout.sec = sess-> endpt->res_cache_msec / 1000;596 timeout.msec = sess-> endpt->res_cache_msec % 1000;597 598 status = pj_timer_heap_schedule(sess-> endpt->timer_heap,596 timeout.sec = sess->cfg->res_cache_msec / 1000; 597 timeout.msec = sess->cfg->res_cache_msec % 1000; 598 599 status = pj_timer_heap_schedule(sess->cfg->timer_heap, 599 600 &tdata->res_timer, 600 601 &timeout); … … 830 831 PJ_ASSERT_RETURN(sess && packet && pkt_size, PJ_EINVAL); 831 832 832 tmp_pool = pj_pool_create(sess-> endpt->pf, "tmpstun", 1024, 1024, NULL);833 tmp_pool = pj_pool_create(sess->cfg->pf, "tmpstun", 1024, 1024, NULL); 833 834 if (!tmp_pool) 834 835 return PJ_ENOMEM;
Note: See TracChangeset
for help on using the changeset viewer.