Changeset 105
- Timestamp:
- Dec 26, 2005 12:52:19 PM (19 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 17 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/build/pjlib_test.dsp
r65 r105 51 51 LINK32=link.exe 52 52 # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 53 # ADD LINK32 netapi32.lib mswsock.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console / debug /machine:I386 /out:"../bin/pjlib-test-i386-win32-vc6-release.exe"53 # ADD LINK32 netapi32.lib mswsock.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /profile /debug /machine:I386 /out:"../bin/pjlib-test-i386-win32-vc6-release.exe" 54 54 55 55 !ELSEIF "$(CFG)" == "pjlib_test - Win32 Debug" -
pjproject/trunk/pjsip/build/test_pjsip.dsp
r74 r105 94 94 # Begin Source File 95 95 96 SOURCE="..\src\test-pjsip\msg .c"96 SOURCE="..\src\test-pjsip\msg_test.c" 97 97 # End Source File 98 98 # Begin Source File … … 102 102 # Begin Source File 103 103 104 SOURCE="..\src\test-pjsip\uri .c"104 SOURCE="..\src\test-pjsip\uri_test.c" 105 105 # End Source File 106 106 # End Group -
pjproject/trunk/pjsip/include/pjsip/sip_config.h
r82 r105 30 30 #define PJSIP_MAX_TRANSPORTS (PJ_IOQUEUE_MAX_HANDLES) 31 31 #define PJSIP_MAX_PKT_LEN 1500 32 #define PJSIP_POOL_ LEN_RDATA 250033 #define PJSIP_POOL_ INC_RDATA 51232 #define PJSIP_POOL_RDATA_LEN 4000 33 #define PJSIP_POOL_RDATA_INC 4000 34 34 #define PJSIP_POOL_LEN_TRANSPORT 512 35 35 #define PJSIP_POOL_INC_TRANSPORT 512 -
pjproject/trunk/pjsip/include/pjsip/sip_endpoint.h
r65 r105 249 249 PJ_DECL(void) pjsip_endpt_resolve( pjsip_endpoint *endpt, 250 250 pj_pool_t *pool, 251 pjsip_host_ port*target,251 pjsip_host_info *target, 252 252 void *token, 253 253 pjsip_resolver_callback *cb); … … 281 281 PJ_DECL(pj_status_t) pjsip_endpt_alloc_transport( pjsip_endpoint *endpt, 282 282 pjsip_transport_type_e type, 283 const pj_sockaddr_in *remote, 283 const pj_sockaddr *remote, 284 int addr_len, 284 285 pjsip_transport **p_transport); 285 286 -
pjproject/trunk/pjsip/include/pjsip/sip_resolve.h
r65 r105 60 60 61 61 /** The server's address. */ 62 pj_sockaddr_in addr; 62 pj_sockaddr addr; 63 64 /** Address length. */ 65 int addr_len; 63 66 64 67 } entry[PJSIP_MAX_RESOLVED_ADDRESSES]; … … 108 111 PJ_DECL(void) pjsip_resolve( pjsip_resolver_t *resolver, 109 112 pj_pool_t *pool, 110 pjsip_host_ port*target,113 pjsip_host_info *target, 111 114 void *token, 112 115 pjsip_resolver_callback *cb); -
pjproject/trunk/pjsip/include/pjsip/sip_transaction.h
r65 r105 108 108 */ 109 109 pjsip_tsx_transport_state_e transport_state;/**< Transport's state. */ 110 pjsip_host_ portdest_name; /**< Destination address. */110 pjsip_host_info dest_name; /**< Destination address. */ 111 111 pjsip_server_addresses remote_addr; /**< Addresses resolved. */ 112 112 int current_addr; /**< Address currently used. */ -
pjproject/trunk/pjsip/include/pjsip/sip_transport.h
r65 r105 175 175 176 176 /** The source address from which the packet was received. */ 177 pj_sockaddr _inaddr;177 pj_sockaddr src_addr; 178 178 179 179 /** The length of the source address. */ 180 int addr_len; 180 int src_addr_len; 181 182 /** The IP source address string (NULL terminated). */ 183 char src_name[16]; 184 185 /** The IP source port number. */ 186 int src_port; 181 187 182 188 } pkt_info; … … 408 414 int tracing; /**< Tracing enabled? */ 409 415 410 pjsip_transport_type_e type; /**< Transport type. */ 411 char type_name[8]; /**< Type name. */ 416 /** Key for indexing this transport in hash table. */ 417 struct { 418 pjsip_transport_type_e type; /**< Transport type. */ 419 pj_sockaddr rem_addr; /**< Remote addr (zero for UDP) */ 420 } key; 421 422 char *type_name; /**< Type name. */ 412 423 unsigned flag; /**< #pjsip_transport_flags_e */ 413 414 pj_sockaddr_in local_addr; /**< Bound address. */ 415 pj_sockaddr_in public_addr; /**< STUN addres. */ 416 pj_sockaddr_in rem_addr; /**< Remote addr (zero for UDP) */ 417 424 char *info; /**< Transport info/description.*/ 425 426 int addr_len; /**< Length of addresses. */ 427 pj_sockaddr local_addr; /**< Bound address. */ 428 pjsip_host_port local_name; /**< Published name (eg. STUN). */ 429 pjsip_host_port remote_name; /**< Remote address name. */ 430 418 431 pjsip_endpoint *endpt; /**< Endpoint instance. */ 419 432 pjsip_tpmgr *tpmgr; /**< Transport manager. */ … … 429 442 * caller when pending send operation completes. 430 443 * @param rem_addr The remote destination address. 444 * @param addr_len Size of remote address. 431 445 * @param callback If supplied, the callback will be called 432 446 * once a pending transmission has completed. If … … 447 461 pj_status_t (*send_msg)(pjsip_transport *transport, 448 462 pjsip_tx_data *tdata, 449 const pj_sockaddr_in *rem_addr, 463 const pj_sockaddr_t *rem_addr, 464 int addr_len, 450 465 void *token, 451 466 void (*callback)(pjsip_transport *transport, … … 523 538 unsigned flag; 524 539 525 pj_sockaddr _inlocal_addr;526 pj _sockaddr_in public_addr;540 pj_sockaddr local_addr; 541 pjsip_host_port addr_name; 527 542 528 543 /** … … 532 547 pjsip_tpmgr *mgr, 533 548 pjsip_endpoint *endpt, 534 const pj_sockaddr _in*rem_addr,549 const pj_sockaddr *rem_addr, 535 550 pjsip_transport **transport); 536 551 … … 608 623 */ 609 624 PJ_DECL(pj_status_t) pjsip_tpmgr_alloc_transport( pjsip_tpmgr *mgr, 610 pjsip_transport_type_e type, 611 const pj_sockaddr_in *remote, 612 pjsip_transport **p_transport ); 625 pjsip_transport_type_e type, 626 const pj_sockaddr_t *remote, 627 int addr_len, 628 pjsip_transport **p_transport ); 613 629 614 630 … … 618 634 PJ_DECL(pj_status_t) pjsip_transport_send( pjsip_transport *tr, 619 635 pjsip_tx_data *tdata, 620 const pj_sockaddr_in *addr, 636 const pj_sockaddr_t *addr, 637 int addr_len, 621 638 void *token, 622 639 void (*cb)(void *token, -
pjproject/trunk/pjsip/include/pjsip/sip_transport_udp.h
r65 r105 29 29 * @param endpt The SIP endpoint. 30 30 * @param local Local address to bind. 31 * @param pub_addr Public address to advertise. 31 * @param a_name Published address (only the host and port portion is 32 * used). If this argument is NULL, then the bound address 33 * will be used as the published address. 32 34 * @param async_cnt Number of simultaneous async operations. 33 35 * @param p_transport Pointer to receive the transport. … … 39 41 PJ_DECL(pj_status_t) pjsip_udp_transport_start(pjsip_endpoint *endpt, 40 42 const pj_sockaddr_in *local, 41 const pj _sockaddr_in *pub_addr,43 const pjsip_host_port *a_name, 42 44 unsigned async_cnt, 43 45 pjsip_transport **p_transport); … … 48 50 * @param endpt The SIP endpoint. 49 51 * @param sock UDP socket to use. 50 * @param pub_addr Public address to advertise. 52 * @param a_name Published address (only the host and port portion is 53 * used). 51 54 * @param async_cnt Number of simultaneous async operations. 52 55 * @param p_transport Pointer to receive the transport. … … 58 61 PJ_DECL(pj_status_t) pjsip_udp_transport_attach(pjsip_endpoint *endpt, 59 62 pj_sock_t sock, 60 const pj _sockaddr_in *pub_addr,63 const pjsip_host_port *a_name, 61 64 unsigned async_cnt, 62 65 pjsip_transport **p_transport); -
pjproject/trunk/pjsip/include/pjsip/sip_types.h
r65 r105 146 146 typedef struct pjsip_host_port 147 147 { 148 unsigned flag; /**< Flags of pjsip_transport_flags_e (not used in Via). */ 149 unsigned type; /**< Transport type (pjsip_transport_type_e), or zero. */ 150 pj_str_t host; /**< Host part. */ 148 pj_str_t host; /**< Host part or IP address. */ 151 149 int port; /**< Port number. */ 152 150 } pjsip_host_port; 151 152 /** 153 * Host information. 154 */ 155 typedef struct pjsip_host_info 156 { 157 unsigned flag; /**< Flags of pjsip_transport_flags_e. */ 158 pjsip_transport_type_e type; /**< Transport type. */ 159 pjsip_host_port addr; /**< Address information. */ 160 } pjsip_host_info; 153 161 154 162 -
pjproject/trunk/pjsip/include/pjsip/sip_util.h
r65 r105 181 181 const pjsip_transport *tr, 182 182 const pjsip_via_hdr *via, 183 pjsip_host_ port*addr);183 pjsip_host_info *addr); 184 184 185 185 /** -
pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c
r82 r105 726 726 727 727 if (status != PJ_SUCCESS) { 728 const char *src_addr = pj_inet_ntoa(rdata->pkt_info.addr.sin_addr);729 int port = pj_ntohs(rdata->pkt_info.addr.sin_port);728 const char *src_addr = rdata->pkt_info.src_name; 729 int port = rdata->pkt_info.src_port; 730 730 PJSIP_ENDPT_LOG_ERROR((endpt, "transport", status, 731 731 "Src.addr=%s:%d, packet:--\n" … … 741 741 */ 742 742 if (msg->type == PJSIP_RESPONSE_MSG) { 743 const pj_sockaddr_in *addr; 744 const char *addr_addr; 743 const pj_str_t *addr_addr; 745 744 int port = rdata->msg_info.via->sent_by.port; 746 745 pj_bool_t mismatch = PJ_FALSE; 747 746 if (port == 0) { 748 747 int type; 749 type = rdata->tp_info.transport-> type;748 type = rdata->tp_info.transport->key.type; 750 749 port = pjsip_transport_get_default_port_for_type(type); 751 750 } 752 addr = &rdata->tp_info.transport->public_addr; 753 addr_addr = pj_inet_ntoa(addr->sin_addr); 754 if (pj_strcmp2(&rdata->msg_info.via->sent_by.host, addr_addr) != 0) 751 addr_addr = &rdata->tp_info.transport->local_name.host; 752 if (pj_strcmp(&rdata->msg_info.via->sent_by.host, addr_addr) != 0) 755 753 mismatch = PJ_TRUE; 756 else if (port != pj_ntohs(addr->sin_port)) {754 else if (port != rdata->tp_info.transport->local_name.port) { 757 755 /* Port or address mismatch, we should discard response */ 758 756 /* But we saw one implementation (we don't want to name it to … … 762 760 * both the port in sent-by and rport. We try to be lenient here! 763 761 */ 764 if (rdata->msg_info.via->rport_param != pj_sockaddr_in_get_port(addr))762 if (rdata->msg_info.via->rport_param != rdata->tp_info.transport->local_name.port) 765 763 mismatch = PJ_TRUE; 766 764 else { … … 959 957 PJ_DEF(void) pjsip_endpt_resolve( pjsip_endpoint *endpt, 960 958 pj_pool_t *pool, 961 pjsip_host_ port*target,959 pjsip_host_info *target, 962 960 void *token, 963 961 pjsip_resolver_callback *cb) … … 988 986 PJ_DEF(pj_status_t) pjsip_endpt_alloc_transport( pjsip_endpoint *endpt, 989 987 pjsip_transport_type_e type, 990 const pj_sockaddr_in *remote, 988 const pj_sockaddr *remote, 989 int addr_len, 991 990 pjsip_transport **p_transport) 992 991 { 993 992 PJ_LOG(5, (THIS_FILE, "pjsip_endpt_alloc_transport()")); 994 return pjsip_tpmgr_alloc_transport( endpt->transport_mgr, type, remote,995 p_transport);993 return pjsip_tpmgr_alloc_transport( endpt->transport_mgr, type, 994 remote, addr_len, p_transport); 996 995 } 997 996 -
pjproject/trunk/pjsip/src/pjsip/sip_resolve.c
r65 r105 57 57 PJ_DEF(void) pjsip_resolve( pjsip_resolver_t *resolver, 58 58 pj_pool_t *pool, 59 pjsip_host_ port*target,59 pjsip_host_info *target, 60 60 void *token, 61 61 pjsip_resolver_callback *cb) … … 73 73 74 74 /* Is it IP address or hostname?. */ 75 is_ip_addr = is_str_ip(&target-> host);75 is_ip_addr = is_str_ip(&target->addr.host); 76 76 77 77 /* Set the transport type if not explicitly specified. … … 79 79 */ 80 80 if (type == PJSIP_TRANSPORT_UNSPECIFIED) { 81 if (is_ip_addr || (target-> port != 0)) {81 if (is_ip_addr || (target->addr.port != 0)) { 82 82 #if PJ_HAS_TCP 83 83 if (target->flag & PJSIP_TRANSPORT_SECURE) … … 104 104 105 105 /* Set the port number if not specified. */ 106 if (target-> port == 0) {107 target-> port = pjsip_transport_get_default_port_for_type(type);106 if (target->addr.port == 0) { 107 target->addr.port = pjsip_transport_get_default_port_for_type(type); 108 108 } 109 109 110 110 /* Resolve hostname. */ 111 111 if (!is_ip_addr) { 112 status = pj_sockaddr_in_init(&svr_addr.entry[0].addr, &target->host, 113 (pj_uint16_t)target->port); 112 status = pj_sockaddr_in_init((pj_sockaddr_in*)&svr_addr.entry[0].addr, 113 &target->addr.host, 114 (pj_uint16_t)target->addr.port); 114 115 } else { 115 status = pj_sockaddr_in_init(&svr_addr.entry[0].addr, &target->host, 116 (pj_uint16_t)target->port); 116 status = pj_sockaddr_in_init((pj_sockaddr_in*)&svr_addr.entry[0].addr, 117 &target->addr.host, 118 (pj_uint16_t)target->addr.port); 117 119 pj_assert(status == PJ_SUCCESS); 118 120 } … … 121 123 svr_addr.count = (status == PJ_SUCCESS) ? 1 : 0; 122 124 svr_addr.entry[0].type = type; 125 svr_addr.entry[0].addr_len = sizeof(pj_sockaddr_in); 123 126 (*cb)(status, token, &svr_addr); 124 127 } -
pjproject/trunk/pjsip/src/pjsip/sip_transaction.c
r65 r105 499 499 static pj_status_t tsx_process_route( pjsip_transaction *tsx, 500 500 pjsip_tx_data *tdata, 501 pjsip_host_ port*send_addr )501 pjsip_host_info *send_addr ) 502 502 { 503 503 const pjsip_uri *new_request_uri, *target_uri; … … 596 596 const pjsip_url *url = (const pjsip_url*)pjsip_uri_get_uri(uri); 597 597 send_addr->flag |= (PJSIP_TRANSPORT_SECURE | PJSIP_TRANSPORT_RELIABLE); 598 pj_strdup(tdata->pool, &send_addr-> host, &url->host);599 send_addr-> port = url->port;598 pj_strdup(tdata->pool, &send_addr->addr.host, &url->host); 599 send_addr->addr.port = url->port; 600 600 send_addr->type = 601 601 pjsip_transport_get_type_from_name(&url->transport_param); … … 604 604 pjsip_uri *uri = (pjsip_uri*) target_uri; 605 605 const pjsip_url *url = (const pjsip_url*)pjsip_uri_get_uri(uri); 606 pj_strdup(tdata->pool, &send_addr-> host, &url->host);607 send_addr-> port = url->port;606 pj_strdup(tdata->pool, &send_addr->addr.host, &url->host); 607 send_addr->addr.port = url->port; 608 608 send_addr->type = 609 609 pjsip_transport_get_type_from_name(&url->transport_param); … … 651 651 struct tsx_lock_data lck; 652 652 653 pj_memcpy(addr, tsx->dest_name. host.ptr, tsx->dest_name.host.slen);654 addr[tsx->dest_name. host.slen] = '\0';653 pj_memcpy(addr, tsx->dest_name.addr.host.ptr, tsx->dest_name.addr.host.slen); 654 addr[tsx->dest_name.addr.host.slen] = '\0'; 655 655 656 656 … … 658 658 PJ_LOG(4, (tsx->obj_name, "%s connected to %s:%d", 659 659 tr->type_name, 660 addr, tsx->dest_name. port));660 addr, tsx->dest_name.addr.port)); 661 661 } else { 662 662 PJ_LOG(4, (tsx->obj_name, "%s unable to connect to %s:%d, status=%d", 663 663 tr->type_name, 664 addr, tsx->dest_name. port, status));664 addr, tsx->dest_name.addr.port, status)); 665 665 } 666 666 … … 738 738 739 739 /* Create/find the transport for the remote address. */ 740 PJ_LOG(5,(tsx->obj_name, "tsx getting transport for %s:%d",741 pj_inet_ntoa(addr->entry[0].addr.sin_addr),742 pj_ntohs(addr->entry[0].addr.sin_port)));743 744 740 tsx->transport_state = PJSIP_TSX_TRANSPORT_STATE_CONNECTING; 745 741 status = pjsip_endpt_alloc_transport( tsx->endpt, addr->entry[0].type, 746 742 &addr->entry[0].addr, 743 addr->entry[0].addr_len, 747 744 &tp); 748 745 tsx_transport_callback(tp, tsx, status); … … 852 849 */ 853 850 PJ_LOG(5,(tsx->obj_name, "tsx resolving destination %.*s:%d", 854 tsx->dest_name. host.slen,855 tsx->dest_name. host.ptr,856 tsx->dest_name. port));851 tsx->dest_name.addr.host.slen, 852 tsx->dest_name.addr.host.ptr, 853 tsx->dest_name.addr.port)); 857 854 858 855 tsx->transport_state = PJSIP_TSX_TRANSPORT_STATE_RESOLVING; … … 942 939 tsx->current_addr = 0; 943 940 tsx->remote_addr.count = 1; 944 tsx->remote_addr.entry[0].type = tsx->transport-> type;941 tsx->remote_addr.entry[0].type = tsx->transport->key.type; 945 942 pj_memcpy(&tsx->remote_addr.entry[0].addr, 946 &rdata->pkt_info. addr, rdata->pkt_info.addr_len);943 &rdata->pkt_info.src_addr, rdata->pkt_info.src_addr_len); 947 944 948 945 } else { … … 965 962 */ 966 963 PJ_LOG(5,(tsx->obj_name, "tsx resolving destination %.*s:%d", 967 tsx->dest_name. host.slen,968 tsx->dest_name. host.ptr,969 tsx->dest_name. port));964 tsx->dest_name.addr.host.slen, 965 tsx->dest_name.addr.host.ptr, 966 tsx->dest_name.addr.port)); 970 967 971 968 tsx->transport_state = PJSIP_TSX_TRANSPORT_STATE_RESOLVING; … … 1024 1021 { 1025 1022 pjsip_msg *msg; 1026 pjsip_host_ portdest_addr;1023 pjsip_host_info dest_addr; 1027 1024 pjsip_via_hdr *via; 1028 1025 struct tsx_lock_data lck; … … 1060 1057 if (dest_addr.type == tsx->dest_name.type && 1061 1058 dest_addr.flag == tsx->dest_name.flag && 1062 dest_addr. port == tsx->dest_name.port &&1063 pj_stricmp(&dest_addr. host, &tsx->dest_name.host) == 0)1059 dest_addr.addr.port == tsx->dest_name.addr.port && 1060 pj_stricmp(&dest_addr.addr.host, &tsx->dest_name.addr.host) == 0) 1064 1061 { 1065 1062 /* Equal destination. We can use current transport. */ … … 1072 1069 /* New destination; we'll have to resolve host and create new transport. */ 1073 1070 pj_memcpy(&tsx->dest_name, &dest_addr, sizeof(dest_addr)); 1074 pj_strdup(tsx->pool, &tsx->dest_name. host, &dest_addr.host);1071 pj_strdup(tsx->pool, &tsx->dest_name.addr.host, &dest_addr.addr.host); 1075 1072 1076 1073 PJ_LOG(5,(tsx->obj_name, "tsx resolving destination %.*s:%d", 1077 tsx->dest_name. host.slen,1078 tsx->dest_name. host.ptr,1079 tsx->dest_name. port));1074 tsx->dest_name.addr.host.slen, 1075 tsx->dest_name.addr.host.ptr, 1076 tsx->dest_name.addr.port)); 1080 1077 1081 1078 tsx->transport_state = PJSIP_TSX_TRANSPORT_STATE_RESOLVING; … … 1216 1213 */ 1217 1214 if (tdata->msg->type == PJSIP_REQUEST_MSG) { 1218 const pj_sockaddr_in *addr_name;1219 1215 pjsip_via_hdr *via = (pjsip_via_hdr*) 1220 1216 pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); … … 1226 1222 /* Don't update Via sent-by on retransmission. */ 1227 1223 if (via->sent_by.host.slen == 0) { 1228 addr_name = &tsx->transport->public_addr;1229 1224 pj_strdup2(tdata->pool, &via->transport, 1230 1225 tsx->transport->type_name); 1231 pj_strdup 2(tdata->pool, &via->sent_by.host,1232 pj_inet_ntoa(addr_name->sin_addr));1233 via->sent_by.port = pj_ntohs(addr_name->sin_port);1226 pj_strdup(tdata->pool, &via->sent_by.host, 1227 &tsx->transport->local_name.host); 1228 via->sent_by.port = tsx->transport->local_name.port; 1234 1229 } 1235 1230 } … … 1243 1238 status = pjsip_transport_send(tsx->transport, tdata, 1244 1239 &tsx->remote_addr.entry[tsx->current_addr].addr, 1240 tsx->remote_addr.entry[tsx->current_addr].addr_len, 1245 1241 tsx, &tsx_on_send_complete); 1246 1242 if (status != PJ_SUCCESS && status != PJ_EPENDING) { -
pjproject/trunk/pjsip/src/pjsip/sip_transport.c
r80 r105 47 47 }; 48 48 49 50 51 49 /***************************************************************************** 52 50 * … … 82 80 unsigned i; 83 81 82 /* Sanity check. 83 * Check that transport_names[] are indexed on transport type. 84 */ 85 PJ_ASSERT_RETURN(transport_names[PJSIP_TRANSPORT_UDP].type == 86 PJSIP_TRANSPORT_UDP, PJSIP_TRANSPORT_UNSPECIFIED); 87 88 /* Get transport type from name. */ 84 89 for (i=0; i<PJ_ARRAY_SIZE(transport_names); ++i) { 85 90 if (pj_stricmp(name, &transport_names[i].name) == 0) { … … 101 106 unsigned i; 102 107 108 /* Sanity check. 109 * Check that transport_names[] are indexed on transport type. 110 */ 111 PJ_ASSERT_RETURN(transport_names[PJSIP_TRANSPORT_UDP].type == 112 PJSIP_TRANSPORT_UDP, PJSIP_TRANSPORT_UNSPECIFIED); 113 114 /* Get the transport type for the specified flags. */ 103 115 for (i=0; i<PJ_ARRAY_SIZE(transport_names); ++i) { 104 116 if (transport_names[i].flag == flag) { … … 114 126 pjsip_transport_get_flag_from_type( pjsip_transport_type_e type ) 115 127 { 128 /* Sanity check. 129 * Check that transport_names[] are indexed on transport type. 130 */ 131 PJ_ASSERT_RETURN(transport_names[PJSIP_TRANSPORT_UDP].type == 132 PJSIP_TRANSPORT_UDP, 0); 133 134 /* Check that argument is valid. */ 116 135 PJ_ASSERT_RETURN(type < PJ_ARRAY_SIZE(transport_names), 0); 136 137 /* Return transport flag. */ 117 138 return transport_names[type].flag; 118 139 } … … 124 145 pjsip_transport_get_default_port_for_type(pjsip_transport_type_e type) 125 146 { 147 /* Sanity check. 148 * Check that transport_names[] are indexed on transport type. 149 */ 150 PJ_ASSERT_RETURN(transport_names[PJSIP_TRANSPORT_UDP].type == 151 PJSIP_TRANSPORT_UDP, 0); 152 153 /* Check that argument is valid. */ 126 154 PJ_ASSERT_RETURN(type < PJ_ARRAY_SIZE(transport_names), 5060); 155 156 /* Return the port. */ 127 157 return transport_names[type].port; 128 158 } … … 225 255 *****************************************************************************/ 226 256 227 /*228 * Transport key for indexing in the hash table.229 */230 typedef struct transport_key231 {232 pj_uint8_t type;233 pj_uint8_t zero;234 pj_uint16_t port;235 pj_uint32_t addr;236 } transport_key;237 238 257 239 258 /***************************************************************************** … … 270 289 PJ_DEF(pj_status_t) pjsip_transport_send( pjsip_transport *tr, 271 290 pjsip_tx_data *tdata, 272 const pj_sockaddr_in *addr, 291 const pj_sockaddr *addr, 292 int addr_len, 273 293 void *token, 274 294 void (*cb)(void *token, … … 318 338 319 339 /* Send to transport. */ 320 status = (*tr->send_msg)(tr, tdata, addr, (void*)tdata,340 status = (*tr->send_msg)(tr, tdata, addr, addr_len, (void*)tdata, 321 341 &transport_send_callback); 322 342 … … 396 416 pjsip_transport *tp ) 397 417 { 398 transport_key key;418 int key_len; 399 419 400 420 /* Init. */ … … 407 427 * Register to hash table. 408 428 */ 409 key.type = (pj_uint8_t)tp->type; 410 key.zero = 0; 411 key.addr = pj_ntohl(tp->rem_addr.sin_addr.s_addr); 412 key.port = pj_ntohs(tp->rem_addr.sin_port); 413 429 key_len = sizeof(tp->key.type) + tp->addr_len; 414 430 pj_lock_acquire(mgr->lock); 415 pj_hash_set(tp->pool, mgr->table, & key, sizeof(key), tp);431 pj_hash_set(tp->pool, mgr->table, &tp->key, key_len, tp); 416 432 pj_lock_release(mgr->lock); 417 433 … … 426 442 pjsip_transport *tp) 427 443 { 428 transport_key key; 429 444 int key_len; 445 446 /* Must have no user. */ 430 447 PJ_ASSERT_RETURN(pj_atomic_get(tp->ref_cnt) == 0, PJSIP_EBUSY); 431 448 … … 445 462 * Unregister from hash table. 446 463 */ 447 key.type = (pj_uint8_t)tp->type; 448 key.zero = 0; 449 key.addr = pj_ntohl(tp->rem_addr.sin_addr.s_addr); 450 key.port = pj_ntohs(tp->rem_addr.sin_port); 451 452 pj_hash_set(tp->pool, mgr->table, &key, sizeof(key), NULL); 464 key_len = sizeof(tp->key.type) + tp->addr_len; 465 pj_hash_set(tp->pool, mgr->table, &tp->key, key_len, NULL); 453 466 454 467 pj_lock_release(mgr->lock); … … 602 615 { 603 616 pjsip_transport *tr = rdata->tp_info.transport; 604 pj_str_t s;605 617 606 618 char *current_pkt; … … 683 695 * MUST add received parameter to the via. 684 696 */ 685 s = pj_str(pj_inet_ntoa(rdata->pkt_info.addr.sin_addr)); 686 if (pj_strcmp(&s, &rdata->msg_info.via->sent_by.host) != 0) { 687 pj_strdup(rdata->tp_info.pool, 688 &rdata->msg_info.via->recvd_param, &s); 697 if (pj_strcmp2(&rdata->msg_info.via->sent_by.host, 698 rdata->pkt_info.src_name) != 0) 699 { 700 pj_strdup2(rdata->tp_info.pool, 701 &rdata->msg_info.via->recvd_param, 702 rdata->pkt_info.src_name); 689 703 } 690 704 … … 693 707 */ 694 708 if (rdata->msg_info.via->rport_param == 0) { 695 rdata->msg_info.via->rport_param = 696 pj_ntohs(rdata->pkt_info.addr.sin_port); 709 rdata->msg_info.via->rport_param = rdata->pkt_info.src_port; 697 710 } 698 711 … … 736 749 PJ_DEF(pj_status_t) pjsip_tpmgr_alloc_transport( pjsip_tpmgr *mgr, 737 750 pjsip_transport_type_e type, 738 const pj_sockaddr_in *remote, 751 const pj_sockaddr_t *remote, 752 int addr_len, 739 753 pjsip_transport **p_transport) 740 754 { 741 transport_key key; 755 struct transport_key 756 { 757 pjsip_transport_type_e type; 758 pj_sockaddr addr; 759 } key; 760 int key_len; 742 761 pjsip_transport *transport; 743 762 pjsip_tpfactory *factory; … … 746 765 pj_lock_acquire(mgr->lock); 747 766 767 key_len = sizeof(key.type) + addr_len; 768 748 769 /* First try to get exact destination. */ 749 key.type = (pj_uint8_t)type; 750 key.zero = 0; 751 key.addr = pj_ntohl(remote->sin_addr.s_addr); 752 key.port = pj_ntohs(remote->sin_port); 753 754 transport = pj_hash_get(mgr->table, &key, sizeof(key)); 755 if (transport != NULL) { 770 key.type = type; 771 pj_memcpy(&key.addr, remote, addr_len); 772 773 transport = pj_hash_get(mgr->table, &key, key_len); 774 if (transport == NULL) { 756 775 unsigned flag = pjsip_transport_get_flag_from_type(type); 757 758 /* For datagram transports, try lookup with zero address. */ 759 if (flag & PJSIP_TRANSPORT_DATAGRAM) { 760 key.addr = 0; 761 key.port = 0; 762 763 transport = pj_hash_get(mgr->table, &key, sizeof(key)); 776 const pj_sockaddr *remote_addr = (const pj_sockaddr*)remote; 777 778 /* For datagram transports, try lookup with zero address. 779 */ 780 if ( (flag & PJSIP_TRANSPORT_DATAGRAM) && 781 (remote_addr->sa_family == PJ_AF_INET)) 782 { 783 pj_sockaddr_in *addr = (pj_sockaddr_in*)&key.addr; 784 785 pj_memset(addr, 0, sizeof(pj_sockaddr_in)); 786 addr->sin_family = PJ_AF_INET; 787 addr->sin_addr.s_addr = 0; 788 addr->sin_port = 0; 789 790 key_len = sizeof(key.type) + sizeof(pj_sockaddr_in); 791 transport = pj_hash_get(mgr->table, &key, key_len); 764 792 } 765 793 } … … 816 844 817 845 do { 818 char src_addr[128], dst_addr[128]; 819 int src_port, dst_port; 820 pjsip_transport *t; 821 822 t = pj_hash_this(mgr->table, itr); 823 pj_native_strcpy(src_addr, pj_inet_ntoa(t->local_addr.sin_addr)); 824 src_port = pj_ntohs(t->local_addr.sin_port); 825 826 pj_native_strcpy(dst_addr, pj_inet_ntoa(t->rem_addr.sin_addr)); 827 dst_port = pj_ntohs(t->rem_addr.sin_port); 828 829 PJ_LOG(3, (THIS_FILE, " %s %s %s:%d --> %s:%d (refcnt=%d)", 830 t->type_name, 846 pjsip_transport *t = pj_hash_this(mgr->table, itr); 847 848 PJ_LOG(3, (THIS_FILE, " %s %s (refcnt=%d)", 831 849 t->obj_name, 832 src_addr, src_port, 833 dst_addr, dst_port, 850 t->info, 834 851 pj_atomic_get(t->ref_cnt))); 835 852 -
pjproject/trunk/pjsip/src/pjsip/sip_transport_udp.c
r65 r105 41 41 42 42 /* 43 * on_read_complete()43 * udp_on_read_complete() 44 44 * 45 45 * This is callback notification from ioqueue that a pending recvfrom() 46 46 * operation has completed. 47 47 */ 48 static void on_read_complete( pj_ioqueue_key_t *key,49 50 48 static void udp_on_read_complete( pj_ioqueue_key_t *key, 49 pj_ioqueue_op_key_t *op_key, 50 pj_ssize_t bytes_read) 51 51 { 52 52 enum { MAX_IMMEDIATE_PACKET = 10 }; … … 73 73 if (bytes_read > 0) { 74 74 pj_size_t size_eaten; 75 75 const pj_sockaddr_in *src_addr = 76 (pj_sockaddr_in*)&rdata->pkt_info.src_addr; 77 78 /* Init pkt_info part. */ 76 79 rdata->pkt_info.len = bytes_read; 77 80 rdata->pkt_info.zero = 0; 78 81 pj_gettimeofday(&rdata->pkt_info.timestamp); 82 pj_native_strcpy(rdata->pkt_info.src_name, 83 pj_inet_ntoa(src_addr->sin_addr)); 84 rdata->pkt_info.src_port = pj_ntohs(src_addr->sin_port); 79 85 80 86 size_eaten = … … 110 116 /* Read next packet. */ 111 117 bytes_read = sizeof(rdata->pkt_info.packet); 112 rdata->pkt_info. addr_len = sizeof(rdata->pkt_info.addr);118 rdata->pkt_info.src_addr_len = sizeof(rdata->pkt_info.src_addr); 113 119 status = pj_ioqueue_recvfrom(key, op_key, 114 120 rdata->pkt_info.packet, 115 121 &bytes_read, flags, 116 &rdata->pkt_info. addr,117 &rdata->pkt_info. addr_len);122 &rdata->pkt_info.src_addr, 123 &rdata->pkt_info.src_addr_len); 118 124 119 125 if (status == PJ_SUCCESS) { … … 150 156 151 157 /* 152 * on_write_complete()158 * udp_on_write_complete() 153 159 * 154 160 * This is callback notification from ioqueue that a pending sendto() 155 161 * operation has completed. 156 162 */ 157 static void on_write_complete( pj_ioqueue_key_t *key,158 159 163 static void udp_on_write_complete( pj_ioqueue_key_t *key, 164 pj_ioqueue_op_key_t *op_key, 165 pj_ssize_t bytes_sent) 160 166 { 161 167 struct udp_transport *tp = pj_ioqueue_get_user_data(key); … … 170 176 171 177 /* 172 * transport_send_msg()178 * udp_send_msg() 173 179 * 174 180 * This function is called by transport manager (by transport->send_msg()) 175 181 * to send outgoing message. 176 182 */ 177 static pj_status_t transport_send_msg( pjsip_transport *transport, 178 pjsip_tx_data *tdata, 179 const pj_sockaddr_in *rem_addr, 180 void *token, 181 void (*callback)(pjsip_transport*, 182 void *token, 183 pj_ssize_t)) 183 static pj_status_t udp_send_msg( pjsip_transport *transport, 184 pjsip_tx_data *tdata, 185 const pj_sockaddr_t *rem_addr, 186 int addr_len, 187 void *token, 188 void (*callback)(pjsip_transport*, 189 void *token, 190 pj_ssize_t)) 184 191 { 185 192 struct udp_transport *tp = (struct udp_transport*)transport; … … 198 205 return pj_ioqueue_sendto(tp->key, (pj_ioqueue_op_key_t*)&tdata->op_key, 199 206 tdata->buf.start, &size, 0, 200 rem_addr, (rem_addr ? sizeof(pj_sockaddr_in):0));201 } 202 203 /* 204 * transport_destroy()207 rem_addr, addr_len); 208 } 209 210 /* 211 * udp_destroy() 205 212 * 206 213 * This function is called by transport manager (by transport->destroy()). 207 214 */ 208 static pj_status_t transport_destroy( pjsip_transport *transport )215 static pj_status_t udp_destroy( pjsip_transport *transport ) 209 216 { 210 217 struct udp_transport *tp = (struct udp_transport*)transport; … … 250 257 PJ_DEF(pj_status_t) pjsip_udp_transport_attach( pjsip_endpoint *endpt, 251 258 pj_sock_t sock, 252 const pj _sockaddr_in *pub_addr,259 const pjsip_host_port *a_name, 253 260 unsigned async_cnt, 254 261 pjsip_transport **p_transport) … … 259 266 pj_ioqueue_callback ioqueue_cb; 260 267 unsigned i; 261 int addrlen;262 268 pj_status_t status; 263 269 264 270 /* Create pool. */ 265 271 pool = pjsip_endpt_create_pool(endpt, "udp%p", PJSIP_POOL_LEN_TRANSPORT, 266 272 PJSIP_POOL_INC_TRANSPORT); 267 273 if (!pool) 268 274 return PJ_ENOMEM; 269 275 276 /* Create the UDP transport object. */ 270 277 tp = pj_pool_zalloc(pool, sizeof(struct udp_transport)); 278 279 /* Save pool. */ 271 280 tp->base.pool = pool; 272 tp->base.endpt = endpt; 273 274 /* Init type, type_name, and flag */ 275 tp->base.type = PJSIP_TRANSPORT_UDP; 276 pj_native_strcpy(tp->base.type_name, "UDP"); 277 tp->base.flag = pjsip_transport_get_flag_from_type(PJSIP_TRANSPORT_UDP); 278 279 /* Init addresses. */ 280 addrlen = sizeof(tp->base.local_addr); 281 status = pj_sock_getsockname(sock, &tp->base.local_addr, &addrlen); 282 if (status != PJ_SUCCESS) { 283 pjsip_endpt_destroy_pool(endpt, pool); 284 return status; 285 } 286 pj_memcpy(&tp->base.public_addr, pub_addr, sizeof(pj_sockaddr_in)); 287 tp->base.rem_addr.sin_family = PJ_AF_INET; 281 282 /* Object name. */ 283 pj_sprintf(tp->base.obj_name, "udp%p", tp); 288 284 289 285 /* Init reference counter. */ … … 296 292 if (status != PJ_SUCCESS) 297 293 goto on_error; 294 295 /* Set type. */ 296 tp->base.key.type = PJSIP_TRANSPORT_UDP; 297 298 /* Remote address is left zero (except the family) */ 299 tp->base.key.rem_addr.sa_family = PJ_AF_INET; 300 301 /* Type name. */ 302 tp->base.type_name = "UDP"; 303 304 /* Transport flag */ 305 tp->base.flag = pjsip_transport_get_flag_from_type(PJSIP_TRANSPORT_UDP); 306 307 308 /* Length of addressess. */ 309 tp->base.addr_len = sizeof(pj_sockaddr_in); 310 311 /* Init local address. */ 312 status = pj_sock_getsockname(sock, &tp->base.local_addr, 313 &tp->base.addr_len); 314 if (status != PJ_SUCCESS) 315 goto on_error; 316 317 /* Init address name (published address) */ 318 pj_strdup_with_null(pool, &tp->base.local_name.host, &a_name->host); 319 tp->base.local_name.port = a_name->port; 320 321 /* Init remote name. */ 322 tp->base.remote_name.host = pj_str("0.0.0.0"); 323 tp->base.remote_name.port = 0; 324 325 /* Transport info. */ 326 tp->base.info = pj_pool_alloc(pool, 80); 327 pj_sprintf(tp->base.info, "udp %s:%d [published as %s:%d]", 328 pj_inet_ntoa(((pj_sockaddr_in*)&tp->base.local_addr)->sin_addr), 329 pj_ntohs(((pj_sockaddr_in*)&tp->base.local_addr)->sin_port), 330 tp->base.local_name.host, 331 tp->base.local_name.port); 332 333 /* Set endpoint. */ 334 tp->base.endpt = endpt; 335 336 /* Transport manager and timer will be initialized by tpmgr */ 298 337 299 338 /* Attach socket. */ … … 303 342 ioqueue = pjsip_endpt_get_ioqueue(endpt); 304 343 pj_memset(&ioqueue_cb, 0, sizeof(ioqueue_cb)); 305 ioqueue_cb.on_read_complete = & on_read_complete;306 ioqueue_cb.on_write_complete = & on_write_complete;344 ioqueue_cb.on_read_complete = &udp_on_read_complete; 345 ioqueue_cb.on_write_complete = &udp_on_write_complete; 307 346 status = pj_ioqueue_register_sock(pool, ioqueue, tp->sock, tp, 308 347 &ioqueue_cb, &tp->key); … … 311 350 312 351 /* Set functions. */ 313 tp->base.send_msg = & transport_send_msg;314 tp->base.destroy = & transport_destroy;352 tp->base.send_msg = &udp_send_msg; 353 tp->base.destroy = &udp_destroy; 315 354 316 355 /* This is a permanent transport, so we initialize the ref count … … 331 370 for (i=0; i<async_cnt; ++i) { 332 371 pj_pool_t *rdata_pool = pjsip_endpt_create_pool(endpt, "rtd%p", 333 PJSIP_POOL_ LEN_RDATA,334 PJSIP_POOL_ INC_RDATA);372 PJSIP_POOL_RDATA_LEN, 373 PJSIP_POOL_RDATA_INC); 335 374 if (!rdata_pool) { 336 375 pj_atomic_set(tp->base.ref_cnt, 0); … … 340 379 341 380 tp->rdata[i] = pj_pool_zalloc(rdata_pool, sizeof(pjsip_rx_data)); 381 382 /* Init tp_info part. */ 342 383 tp->rdata[i]->tp_info.pool = rdata_pool; 343 384 tp->rdata[i]->tp_info.transport = &tp->base; … … 353 394 354 395 size = sizeof(tp->rdata[i]->pkt_info.packet); 355 tp->rdata[i]->pkt_info. addr_len = sizeof(tp->rdata[i]->pkt_info.addr);396 tp->rdata[i]->pkt_info.src_addr_len = sizeof(tp->rdata[i]->pkt_info.src_addr); 356 397 status = pj_ioqueue_recvfrom(tp->key, 357 398 &tp->rdata[i]->tp_info.op_key.op_key, 358 399 tp->rdata[i]->pkt_info.packet, 359 400 &size, PJ_IOQUEUE_ALWAYS_ASYNC, 360 &tp->rdata[i]->pkt_info. addr,361 &tp->rdata[i]->pkt_info. addr_len);401 &tp->rdata[i]->pkt_info.src_addr, 402 &tp->rdata[i]->pkt_info.src_addr_len); 362 403 if (status == PJ_SUCCESS) { 363 404 pj_assert(!"Shouldn't happen because PJ_IOQUEUE_ALWAYS_ASYNC!"); 364 on_read_complete(tp->key, &tp->rdata[i]->tp_info.op_key.op_key,365 405 udp_on_read_complete(tp->key, &tp->rdata[i]->tp_info.op_key.op_key, 406 size); 366 407 } else if (status != PJ_EPENDING) { 367 408 /* Error! */ … … 376 417 377 418 on_error: 378 transport_destroy((pjsip_transport*)tp);419 udp_destroy((pjsip_transport*)tp); 379 420 return status; 380 421 } … … 383 424 * pjsip_udp_transport_start() 384 425 * 385 * Start an UDP transport/listener.426 * Create a UDP socket in the specified address and start a transport. 386 427 */ 387 428 PJ_DEF(pj_status_t) pjsip_udp_transport_start( pjsip_endpoint *endpt, 388 429 const pj_sockaddr_in *local, 389 const pj _sockaddr_in *pub_addr,430 const pjsip_host_port *a_name, 390 431 unsigned async_cnt, 391 432 pjsip_transport **p_transport) … … 393 434 pj_sock_t sock; 394 435 pj_status_t status; 436 char addr_buf[16]; 437 pjsip_host_port bound_name; 395 438 396 439 status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &sock); … … 404 447 } 405 448 406 return pjsip_udp_transport_attach( endpt, sock, pub_addr, async_cnt, 449 if (a_name == NULL) { 450 a_name = &bound_name; 451 bound_name.host.ptr = addr_buf; 452 pj_strcpy2(&bound_name.host, pj_inet_ntoa(local->sin_addr)); 453 bound_name.port = pj_ntohs(local->sin_port); 454 } 455 456 return pjsip_udp_transport_attach( endpt, sock, a_name, async_cnt, 407 457 p_transport ); 408 458 } -
pjproject/trunk/pjsip/src/pjsip/sip_util.c
r74 r105 677 677 const pjsip_transport *req_transport, 678 678 const pjsip_via_hdr *via, 679 pjsip_host_ port*send_addr)679 pjsip_host_info *send_addr) 680 680 { 681 681 /* Determine the destination address (section 18.2.2): … … 689 689 */ 690 690 send_addr->flag = req_transport->flag; 691 send_addr->type = req_transport-> type;691 send_addr->type = req_transport->key.type; 692 692 693 693 if (PJSIP_TRANSPORT_IS_RELIABLE(req_transport)) { 694 const pj_sockaddr_in *remote_addr; 695 remote_addr = &req_transport->rem_addr; 696 pj_strdup2(pool, &send_addr->host, 697 pj_inet_ntoa(remote_addr->sin_addr)); 698 send_addr->port = pj_sockaddr_in_get_port(remote_addr); 694 pj_strdup( pool, &send_addr->addr.host, 695 &req_transport->remote_name.host); 696 send_addr->addr.port = req_transport->remote_name.port; 699 697 700 698 } else { 701 699 /* Set the host part */ 702 700 if (via->maddr_param.slen) { 703 pj_strdup(pool, &send_addr-> host, &via->maddr_param);701 pj_strdup(pool, &send_addr->addr.host, &via->maddr_param); 704 702 } else if (via->recvd_param.slen) { 705 pj_strdup(pool, &send_addr-> host, &via->recvd_param);703 pj_strdup(pool, &send_addr->addr.host, &via->recvd_param); 706 704 } else { 707 pj_strdup(pool, &send_addr-> host, &via->sent_by.host);705 pj_strdup(pool, &send_addr->addr.host, &via->sent_by.host); 708 706 } 709 707 710 708 /* Set the port */ 711 send_addr-> port = via->sent_by.port;709 send_addr->addr.port = via->sent_by.port; 712 710 } 713 711
Note: See TracChangeset
for help on using the changeset viewer.