Changeset 1877 for pjproject/trunk/pjnath/src/pjturn-srv/server.c
- Timestamp:
- Mar 19, 2008 11:00:30 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjturn-srv/server.c
r1869 r1877 41 41 const pj_uint8_t *pkt, 42 42 unsigned pkt_len, 43 const pj_stun_ msg *msg,43 const pj_stun_rx_data *rdata, 44 44 const pj_sockaddr_t *src_addr, 45 45 unsigned src_addr_len); … … 148 148 srv->core.cred.data.dyn_cred.user_data = srv; 149 149 srv->core.cred.data.dyn_cred.get_auth = &pj_turn_get_auth; 150 srv->core.cred.data.dyn_cred.get_cred = &pj_turn_get_cred;151 150 srv->core.cred.data.dyn_cred.get_password = &pj_turn_get_password; 152 151 srv->core.cred.data.dyn_cred.verify_nonce = &pj_turn_verify_nonce; … … 369 368 370 369 pj_stun_session_set_user_data(sess, lis); 371 pj_stun_session_set_credential(sess, &srv->core.cred); 370 pj_stun_session_set_credential(sess, PJ_STUN_AUTH_LONG_TERM, 371 &srv->core.cred); 372 372 373 373 srv->core.stun_sess[index] = sess; … … 484 484 485 485 /* Respond to STUN request */ 486 static pj_status_t stun_respond(pj_turn_srv *srv, 487 pj_stun_session *sess, 488 const pj_stun_msg *req, 486 static pj_status_t stun_respond(pj_stun_session *sess, 487 const pj_stun_rx_data *rdata, 489 488 unsigned code, 490 489 const char *errmsg, … … 498 497 499 498 /* Create response */ 500 status = pj_stun_session_create_res(sess, r eq, code,499 status = pj_stun_session_create_res(sess, rdata, code, 501 500 (errmsg?pj_cstr(&reason,errmsg):NULL), 502 501 &tdata); … … 504 503 return status; 505 504 506 /* Store the credential for future lookup. */507 if (pj_stun_auth_valid_for_msg(tdata->msg)) {508 pj_turn_srv_put_cred(srv, req, tdata);509 }510 511 505 /* Send the response */ 512 506 return pj_stun_session_send_msg(sess, cache, dst_addr, addr_len, tdata); 513 }514 515 516 /*517 * Store the credential to put placed for the specified message for518 * future retrieval.519 */520 PJ_DEF(pj_status_t) pj_turn_srv_put_cred(pj_turn_srv *srv,521 const pj_stun_msg *req,522 pj_stun_tx_data *response)523 {524 pj_stun_username_attr *user;525 pj_stun_realm_attr *realm;526 pj_stun_nonce_attr *nonce;527 struct saved_cred *saved_cred;528 pj_status_t status;529 530 realm = (pj_stun_realm_attr*)531 pj_stun_msg_find_attr(req, PJ_STUN_ATTR_REALM, 0);532 PJ_ASSERT_RETURN(realm != NULL, PJ_EBUG);533 534 user = (pj_stun_username_attr*)535 pj_stun_msg_find_attr(req, PJ_STUN_ATTR_USERNAME, 0);536 PJ_ASSERT_RETURN(user != NULL, PJ_EBUG);537 538 nonce = (pj_stun_nonce_attr*)539 pj_stun_msg_find_attr(req, PJ_STUN_ATTR_NONCE, 0);540 PJ_ASSERT_RETURN(nonce != NULL, PJ_EBUG);541 542 saved_cred = PJ_POOL_ALLOC_T(response->pool, struct saved_cred);543 544 /* Lookup the password */545 status = pj_turn_get_password(response->msg, NULL, &realm->value,546 &user->value, response->pool,547 &saved_cred->data_type,548 &saved_cred->data);549 if (status != PJ_SUCCESS)550 return status;551 552 /* Store credential */553 pj_strdup(response->pool, &saved_cred->username, &user->value);554 pj_strdup(response->pool, &saved_cred->realm, &realm->value);555 pj_strdup(response->pool, &saved_cred->nonce, &nonce->value);556 557 pj_thread_local_set(srv->core.tls_key, response->msg);558 pj_thread_local_set(srv->core.tls_data, saved_cred);559 560 return PJ_SUCCESS;561 }562 563 564 /**565 * Retrieve previously stored credential for the specified message.566 */567 PJ_DEF(pj_status_t) pj_turn_srv_get_cred(const pj_stun_msg *msg,568 void *user_data,569 pj_pool_t *pool,570 pj_str_t *realm,571 pj_str_t *username,572 pj_str_t *nonce,573 int *data_type,574 pj_str_t *data)575 {576 pj_turn_srv *srv;577 const pj_stun_msg *saved_msg;578 struct saved_cred *saved_cred;579 580 PJ_UNUSED_ARG(pool);581 582 srv = (pj_turn_srv*)user_data;583 584 /* Lookup stored message and make sure it's for the same message */585 saved_msg = (const pj_stun_msg*)586 pj_thread_local_get(srv->core.tls_key);587 PJ_ASSERT_RETURN(saved_msg==msg, PJ_ENOTFOUND);588 589 /* Lookup saved credential */590 saved_cred = (struct saved_cred*)591 pj_thread_local_get(srv->core.tls_data);592 PJ_ASSERT_RETURN(saved_cred != NULL, PJ_ENOTFOUND);593 594 595 *realm = saved_cred->realm;596 *username = saved_cred->username;597 *nonce = saved_cred->nonce;598 *data_type = saved_cred->data_type;599 *data = saved_cred->data;600 601 602 /* Don't clear saved_cred as this may be called more than once */603 604 return PJ_SUCCESS;605 507 } 606 508 … … 613 515 const pj_uint8_t *pkt, 614 516 unsigned pkt_len, 615 const pj_stun_ msg *msg,517 const pj_stun_rx_data *rdata, 616 518 const pj_sockaddr_t *src_addr, 617 519 unsigned src_addr_len) 618 520 { 619 521 pj_turn_listener *listener; 522 const pj_stun_msg *msg = rdata->msg; 620 523 pj_turn_srv *srv; 621 524 pj_turn_allocation *alloc; … … 630 533 /* Respond any requests other than ALLOCATE with 437 response */ 631 534 if (msg->hdr.type != PJ_STUN_ALLOCATE_REQUEST) { 632 stun_respond(s rv, sess, msg, PJ_STUN_SC_ALLOCATION_MISMATCH,535 stun_respond(sess, rdata, PJ_STUN_SC_ALLOCATION_MISMATCH, 633 536 NULL, PJ_FALSE, src_addr, src_addr_len); 634 537 return PJ_SUCCESS; … … 639 542 */ 640 543 status = pj_turn_allocation_create(listener, src_addr, src_addr_len, 641 msg, sess, &alloc);544 rdata, sess, &alloc); 642 545 if (status != PJ_SUCCESS) { 643 546 /* STUN response has been sent, no need to reply here */
Note: See TracChangeset
for help on using the changeset viewer.