Changeset 2693 for pjproject/trunk/pjnath/src/pjnath-test/server.c
- Timestamp:
- May 12, 2009 10:14:52 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjnath-test/server.c
r2591 r2693 354 354 pool = pj_pool_create(test_srv->stun_cfg->pf, NULL, 512, 512, NULL); 355 355 356 /* Find the client */ 357 for (i=0; i<test_srv->turn_alloc_cnt; i++) { 358 if (pj_sockaddr_cmp(&test_srv->turn_alloc[i].client_addr, src_addr)==0) 359 break; 360 } 361 362 363 if (pj_stun_msg_check((pj_uint8_t*)data, size, PJ_STUN_NO_FINGERPRINT_CHECK)!=PJ_SUCCESS) { 364 /* Not STUN message, this probably is a ChannelData */ 365 pj_turn_channel_data cd; 366 const pj_turn_channel_data *pcd = (const pj_turn_channel_data*)data; 367 pj_ssize_t sent; 368 369 if (i==test_srv->turn_alloc_cnt) { 370 /* Invalid data */ 371 PJ_LOG(1,(THIS_FILE, 372 "TURN Server received strayed data")); 373 goto on_return; 374 } 375 376 alloc = &test_srv->turn_alloc[i]; 377 378 cd.ch_number = pj_ntohs(pcd->ch_number); 379 cd.length = pj_ntohs(pcd->length); 380 381 /* For UDP check the packet length */ 382 if (size < cd.length+sizeof(cd)) { 383 PJ_LOG(1,(THIS_FILE, 384 "TURN Server: ChannelData discarded: UDP size error")); 385 goto on_return; 386 } 387 388 /* Lookup peer */ 389 for (i=0; i<alloc->perm_cnt; ++i) { 390 if (alloc->chnum[i] == cd.ch_number) 391 break; 392 } 393 394 if (i==alloc->perm_cnt) { 395 PJ_LOG(1,(THIS_FILE, 396 "TURN Server: ChannelData discarded: invalid channel number")); 397 goto on_return; 398 } 399 400 /* Relay the data to peer */ 401 sent = cd.length; 402 pj_activesock_sendto(alloc->sock, &alloc->send_key, 403 pcd+1, &sent, 0, 404 &alloc->perm[i], 405 pj_sockaddr_get_len(&alloc->perm[i])); 406 407 /* Done */ 408 goto on_return; 409 } 410 356 411 status = pj_stun_msg_decode(pool, (pj_uint8_t*)data, size, 357 412 PJ_STUN_IS_DATAGRAM | PJ_STUN_CHECK_PACKET | … … 365 420 } 366 421 367 /* Find the client */368 for (i=0; i<test_srv->turn_alloc_cnt; i++) {369 if (pj_sockaddr_cmp(&test_srv->turn_alloc[i].client_addr, src_addr)==0)370 break;371 }372 373 422 if (i==test_srv->turn_alloc_cnt) { 374 423 /* New client */ … … 515 564 } else 516 565 resp = create_success_response(test_srv, alloc, req, pool, 0, &auth_key); 566 } else if (req->hdr.type == PJ_STUN_CREATE_PERM_REQUEST) { 567 for (i=0; i<req->attr_count; ++i) { 568 if (req->attr[i]->type == PJ_STUN_ATTR_XOR_PEER_ADDR) { 569 pj_stun_xor_peer_addr_attr *pa = (pj_stun_xor_peer_addr_attr*)req->attr[i]; 570 unsigned j; 571 572 for (j=0; j<alloc->perm_cnt; ++j) { 573 if (pj_sockaddr_cmp(&alloc->perm[j], &pa->sockaddr)==0) 574 break; 575 } 576 577 if (j==alloc->perm_cnt && alloc->perm_cnt < MAX_TURN_PERM) { 578 char peer_info[PJ_INET6_ADDRSTRLEN]; 579 pj_sockaddr_print(&pa->sockaddr, peer_info, sizeof(peer_info), 3); 580 581 pj_sockaddr_cp(&alloc->perm[alloc->perm_cnt], &pa->sockaddr); 582 ++alloc->perm_cnt; 583 584 PJ_LOG(5,("", "Permission %s added to client %s, perm_cnt=%d", 585 peer_info, client_info, alloc->perm_cnt)); 586 } 587 588 } 589 } 590 resp = create_success_response(test_srv, alloc, req, pool, 0, &auth_key); 517 591 } else if (req->hdr.type == PJ_STUN_SEND_INDICATION) { 518 592 pj_stun_xor_peer_addr_attr *pa; … … 537 611 } 538 612 539 if (j==alloc->perm_cnt && alloc->perm_cnt < MAX_TURN_PERM) { 540 pj_sockaddr_cp(&alloc->perm[alloc->perm_cnt], &pa->sockaddr); 541 ++alloc->perm_cnt; 542 543 PJ_LOG(5,("", "Permission %s added to client %s, perm_cnt=%d", 613 if (j==alloc->perm_cnt) { 614 PJ_LOG(5,("", "SendIndication to %s is rejected (no permission)", 544 615 peer_info, client_info, alloc->perm_cnt)); 616 } else { 617 PJ_LOG(5,(THIS_FILE, "Relaying %d bytes data from client %s to peer %s, " 618 "perm_cnt=%d", 619 da->length, client_info, peer_info, alloc->perm_cnt)); 620 621 sent = da->length; 622 pj_activesock_sendto(alloc->sock, &alloc->send_key, 623 da->data, &sent, 0, 624 &pa->sockaddr, 625 pj_sockaddr_get_len(&pa->sockaddr)); 545 626 } 546 547 PJ_LOG(5,(THIS_FILE, "Relaying %d bytes data from client %s to peer %s, "548 "perm_cnt=%d",549 da->length, client_info, peer_info, alloc->perm_cnt));550 551 sent = da->length;552 pj_activesock_sendto(alloc->sock, &alloc->send_key,553 da->data, &sent, 0,554 &pa->sockaddr,555 pj_sockaddr_get_len(&pa->sockaddr));556 627 } else { 557 628 PJ_LOG(1,(THIS_FILE, "Invalid Send Indication from %s", client_info)); 558 629 } 630 } else if (req->hdr.type == PJ_STUN_CHANNEL_BIND_REQUEST) { 631 pj_stun_xor_peer_addr_attr *pa; 632 pj_stun_channel_number_attr *cna; 633 unsigned j, cn; 634 635 pa = (pj_stun_xor_peer_addr_attr*) 636 pj_stun_msg_find_attr(req, PJ_STUN_ATTR_XOR_PEER_ADDR, 0); 637 cna = (pj_stun_channel_number_attr*) 638 pj_stun_msg_find_attr(req, PJ_STUN_ATTR_CHANNEL_NUMBER, 0); 639 cn = PJ_STUN_GET_CH_NB(cna->value); 640 641 resp = create_success_response(test_srv, alloc, req, pool, 0, &auth_key); 642 643 for (j=0; j<alloc->perm_cnt; ++j) { 644 if (pj_sockaddr_cmp(&alloc->perm[j], &pa->sockaddr)==0) 645 break; 646 } 647 648 if (i==alloc->perm_cnt) { 649 if (alloc->perm_cnt==MAX_TURN_PERM) { 650 pj_stun_msg_create_response(pool, req, PJ_STUN_SC_INSUFFICIENT_CAPACITY, NULL, &resp); 651 goto send_pkt; 652 } 653 pj_sockaddr_cp(&alloc->perm[i], &pa->sockaddr); 654 ++alloc->perm_cnt; 655 } 656 alloc->chnum[i] = cn; 657 658 resp = create_success_response(test_srv, alloc, req, pool, 0, &auth_key); 659 559 660 } else if (PJ_STUN_IS_REQUEST(req->hdr.type)) { 560 661 pj_stun_msg_create_response(pool, req, PJ_STUN_SC_BAD_REQUEST, NULL, &resp);
Note: See TracChangeset
for help on using the changeset viewer.