- Timestamp:
- Mar 8, 2007 6:58:04 PM (18 years ago)
- Location:
- pjproject/trunk/pjlib-util
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/build/pjstun_srv_test.dsp
r1040 r1049 100 100 # Begin Source File 101 101 102 SOURCE="..\src\pjstun-srv-test\turn_usage.c" 103 # End Source File 104 # Begin Source File 105 102 106 SOURCE="..\src\pjstun-srv-test\usage.c" 103 107 # End Source File -
pjproject/trunk/pjlib-util/include/pjlib-util/stun_msg.h
r1037 r1049 339 339 PJ_STUN_ATTR_REALM = 0x0014,/**< REALM attribute. */ 340 340 PJ_STUN_ATTR_NONCE = 0x0015,/**< NONCE attribute. */ 341 PJ_STUN_ATTR_RELAY_ADDR ESS= 0x0016,/**< RELAY-ADDRESS attribute. */342 PJ_STUN_ATTR_REQ UESTED_ADDR_TYPE= 0x0017,/**< REQUESTED-ADDRESS-TYPE */343 PJ_STUN_ATTR_REQ UESTED_PORT_PROPS=0x0018,/**< REQUESTED-PORT-PROPS */344 PJ_STUN_ATTR_REQ UESTED_TRANSPORT= 0x0019,/**< REQUESTED-TRANSPORT */345 PJ_STUN_ATTR_XOR_MAPPED_ADDR ESS= 0x0020,/**< XOR-MAPPED-ADDRESS */341 PJ_STUN_ATTR_RELAY_ADDR = 0x0016,/**< RELAY-ADDRESS attribute. */ 342 PJ_STUN_ATTR_REQ_ADDR_TYPE = 0x0017,/**< REQUESTED-ADDRESS-TYPE */ 343 PJ_STUN_ATTR_REQ_PORT_PROPS = 0x0018,/**< REQUESTED-PORT-PROPS */ 344 PJ_STUN_ATTR_REQ_TRANSPORT = 0x0019,/**< REQUESTED-TRANSPORT */ 345 PJ_STUN_ATTR_XOR_MAPPED_ADDR = 0x0020,/**< XOR-MAPPED-ADDRESS */ 346 346 PJ_STUN_ATTR_TIMER_VAL = 0x0021,/**< TIMER-VAL attribute. */ 347 PJ_STUN_ATTR_REQ UESTED_IP= 0x0022,/**< REQUESTED-IP attribute */347 PJ_STUN_ATTR_REQ_IP = 0x0022,/**< REQUESTED-IP attribute */ 348 348 PJ_STUN_ATTR_XOR_REFLECTED_FROM = 0x0023,/**< XOR-REFLECTED-FROM */ 349 349 PJ_STUN_ATTR_PRIORITY = 0x0024,/**< PRIORITY */ … … 391 391 PJ_STUN_STATUS_CONNECTION_FAILURE = 446, /**< Connection Failure */ 392 392 PJ_STUN_STATUS_CONNECTION_TIMEOUT = 447, /**< Connection Timeout */ 393 PJ_STUN_STATUS_ALLOCATION_QUOTA_REACHED = 486, /**< Allocation Quota Reached (TURN) */ 393 394 PJ_STUN_STATUS_SERVER_ERROR = 500, /**< Server Error */ 395 PJ_STUN_STATUS_INSUFFICIENT_CAPACITY = 507, /**< Insufficient Capacity (TURN) */ 394 396 PJ_STUN_STATUS_GLOBAL_FAILURE = 600 /**< Global Failure */ 395 397 } pj_stun_status; … … 934 936 \endverbatim 935 937 */ 936 typedef struct pj_stun_uint_attr pj_stun_req uested_addr_type;938 typedef struct pj_stun_uint_attr pj_stun_req_addr_type; 937 939 938 940 /** … … 954 956 \endverbatim 955 957 */ 956 typedef struct pj_stun_uint_attr pj_stun_req uested_port_props_attr;958 typedef struct pj_stun_uint_attr pj_stun_req_port_props_attr; 957 959 958 960 … … 963 965 * unsigned integer. Its values are: 0x0000 for UDP and 0x0000 for TCP. 964 966 */ 965 typedef struct pj_stun_uint_attr pj_stun_req uested_transport_attr;967 typedef struct pj_stun_uint_attr pj_stun_req_transport_attr; 966 968 967 969 … … 971 973 * specific IP address be allocated to it. 972 974 */ 973 typedef struct pj_stun_ip_addr_attr pj_stun_req uested_ip_attr;975 typedef struct pj_stun_ip_addr_attr pj_stun_req_ip_attr; 974 976 975 977 /** -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_msg.c
r1040 r1049 72 72 { PJ_STUN_STATUS_CONNECTION_FAILURE, "Connection Failure"}, 73 73 { PJ_STUN_STATUS_CONNECTION_TIMEOUT, "Connection Timeout"}, 74 { PJ_STUN_STATUS_ALLOCATION_QUOTA_REACHED, "Allocation Quota Reached"}, 74 75 { PJ_STUN_STATUS_SERVER_ERROR, "Server Error"}, 76 { PJ_STUN_STATUS_INSUFFICIENT_CAPACITY, "Insufficient Capacity"}, 75 77 { PJ_STUN_STATUS_GLOBAL_FAILURE, "Global Failure"} 76 78 }; -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_msg_dump.c
r1038 r1049 70 70 case PJ_STUN_ATTR_REFLECTED_FROM: 71 71 case PJ_STUN_ATTR_REMOTE_ADDRESS: 72 case PJ_STUN_ATTR_RELAY_ADDR ESS:73 case PJ_STUN_ATTR_XOR_MAPPED_ADDR ESS:74 case PJ_STUN_ATTR_REQ UESTED_IP:72 case PJ_STUN_ATTR_RELAY_ADDR: 73 case PJ_STUN_ATTR_XOR_MAPPED_ADDR: 74 case PJ_STUN_ATTR_REQ_IP: 75 75 case PJ_STUN_ATTR_XOR_REFLECTED_FROM: 76 76 case PJ_STUN_ATTR_XOR_INTERNAL_ADDR: … … 100 100 case PJ_STUN_ATTR_LIFETIME: 101 101 case PJ_STUN_ATTR_BANDWIDTH: 102 case PJ_STUN_ATTR_REQ UESTED_ADDR_TYPE:103 case PJ_STUN_ATTR_REQ UESTED_PORT_PROPS:104 case PJ_STUN_ATTR_REQ UESTED_TRANSPORT:102 case PJ_STUN_ATTR_REQ_ADDR_TYPE: 103 case PJ_STUN_ATTR_REQ_PORT_PROPS: 104 case PJ_STUN_ATTR_REQ_TRANSPORT: 105 105 case PJ_STUN_ATTR_TIMER_VAL: 106 106 case PJ_STUN_ATTR_PRIORITY: -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_session.c
r1040 r1049 177 177 &tdata->res_timer); 178 178 tdata->res_timer.id = PJ_FALSE; 179 pj_list_erase(tdata); 179 180 } 180 181 pj_pool_release(tdata->pool); … … 348 349 { 349 350 PJ_ASSERT_RETURN(sess, PJ_EINVAL); 351 352 pj_mutex_lock(sess->mutex); 353 while (!pj_list_empty(&sess->pending_request_list)) { 354 pj_stun_tx_data *tdata = sess->pending_request_list.next; 355 destroy_tdata(tdata); 356 } 357 while (!pj_list_empty(&sess->cached_response_list)) { 358 pj_stun_tx_data *tdata = sess->cached_response_list.next; 359 destroy_tdata(tdata); 360 } 361 pj_mutex_unlock(sess->mutex); 350 362 351 363 pj_mutex_destroy(sess->mutex); -
pjproject/trunk/pjlib-util/src/pjstun-srv-test/bind_usage.c
r1040 r1049 26 26 const pj_sockaddr_t *src_addr, 27 27 unsigned src_addr_len); 28 static void usage_on_destroy(pj_stun_usage *usage); 28 29 static pj_status_t sess_on_send_msg(pj_stun_session *sess, 29 30 const void *pkt, … … 38 39 unsigned src_addr_len); 39 40 41 struct bind_usage 42 { 43 pj_pool_t *pool; 44 pj_stun_usage *usage; 45 pj_stun_session *session; 46 }; 47 48 40 49 PJ_DEF(pj_status_t) pj_stun_bind_usage_create(pj_stun_server *srv, 41 50 const pj_str_t *ip_addr, … … 43 52 pj_stun_usage **p_bu) 44 53 { 54 pj_pool_t *pool; 55 struct bind_usage *bu; 45 56 pj_stun_server_info *si; 46 pj_stun_session *session;47 pj_stun_usage *usage;48 57 pj_stun_usage_cb usage_cb; 49 58 pj_stun_session_cb sess_cb; … … 53 62 si = pj_stun_server_get_info(srv); 54 63 64 pool = pj_pool_create(si->pf, "bind%p", 128, 128, NULL); 65 bu = PJ_POOL_ZALLOC_T(pool, struct bind_usage); 66 bu->pool = pool; 67 55 68 status = pj_sockaddr_in_init(&local_addr, ip_addr, (pj_uint16_t)port); 56 69 if (status != PJ_SUCCESS) … … 59 72 pj_bzero(&usage_cb, sizeof(usage_cb)); 60 73 usage_cb.on_rx_data = &usage_on_rx_data; 74 usage_cb.on_destroy = &usage_on_destroy; 61 75 62 76 status = pj_stun_usage_create(srv, "bind%p", &usage_cb, 63 77 PJ_AF_INET, PJ_SOCK_DGRAM, 0, 64 78 &local_addr, sizeof(local_addr), 65 &usage); 66 if (status != PJ_SUCCESS) 67 return status; 79 &bu->usage); 80 if (status != PJ_SUCCESS) { 81 pj_pool_release(pool); 82 return status; 83 } 68 84 69 85 pj_bzero(&sess_cb, sizeof(sess_cb)); … … 71 87 sess_cb.on_rx_request = &sess_on_rx_request; 72 88 status = pj_stun_session_create(si->endpt, "bind%p", &sess_cb, PJ_FALSE, 73 &session); 74 if (status != PJ_SUCCESS) { 75 pj_stun_usage_destroy(usage); 76 return status; 77 } 78 79 pj_stun_usage_set_user_data(usage, session); 80 pj_stun_session_set_user_data(session, usage); 81 82 *p_bu = usage; 89 &bu->session); 90 if (status != PJ_SUCCESS) { 91 pj_stun_usage_destroy(bu->usage); 92 return status; 93 } 94 95 pj_stun_usage_set_user_data(bu->usage, bu); 96 pj_stun_session_set_user_data(bu->session, bu); 97 98 if (p_bu) 99 *p_bu = bu->usage; 83 100 84 101 return PJ_SUCCESS; … … 92 109 unsigned src_addr_len) 93 110 { 111 struct bind_usage *bu; 94 112 pj_stun_session *session; 95 113 pj_status_t status; 96 114 97 session = (pj_stun_session*) pj_stun_usage_get_user_data(usage); 115 bu = (struct bind_usage*) pj_stun_usage_get_user_data(usage); 116 session = bu->session; 98 117 99 118 /* Handle packet to session */ … … 114 133 unsigned addr_len) 115 134 { 135 struct bind_usage *bu; 116 136 pj_stun_usage *usage; 117 137 118 usage = pj_stun_session_get_user_data(sess); 138 bu = (struct bind_usage*) pj_stun_session_get_user_data(sess); 139 usage = bu->usage; 119 140 120 141 return pj_stun_usage_sendto(usage, pkt, pkt_size, 0, … … 156 177 status = 157 178 pj_stun_msg_add_ip_addr_attr(tdata->pool, tdata->msg, 158 PJ_STUN_ATTR_XOR_MAPPED_ADDR ESS,179 PJ_STUN_ATTR_XOR_MAPPED_ADDR, 159 180 PJ_TRUE, 160 181 src_addr, src_addr_len); … … 173 194 } 174 195 196 static void usage_on_destroy(pj_stun_usage *usage) 197 { 198 struct bind_usage *bu; 199 200 bu = (struct bind_usage*) pj_stun_usage_get_user_data(usage); 201 if (bu==NULL) 202 return; 203 204 pj_stun_session_destroy(bu->session); 205 pj_pool_release(bu->pool); 206 } -
pjproject/trunk/pjlib-util/src/pjstun-srv-test/main.c
r1040 r1049 18 18 */ 19 19 #include "server.h" 20 21 #define THIS_FILE "main.c" 20 22 21 23 struct options … … 42 44 43 45 44 static void server_main( void)46 static void server_main(pj_stun_server *srv) 45 47 { 46 48 int quit = 0; … … 50 52 51 53 printf("Menu:\n" 54 " d Dump status\n" 52 55 " q Quit\n" 53 56 "Choice:"); 54 57 55 58 fgets(line, sizeof(line), stdin); 56 if (line[0] == 'q') 59 if (line[0] == 'q') { 57 60 quit = 1; 61 } else if (line[0] == 'd') { 62 pj_stun_server_info *si = pj_stun_server_get_info(srv); 63 pj_pool_factory_dump(si->pf, PJ_TRUE); 64 } 58 65 } 59 66 } … … 72 79 pj_caching_pool cp; 73 80 pj_stun_server *srv; 74 pj_stun_usage *bu;75 81 pj_status_t status; 76 82 … … 117 123 } 118 124 119 status = pj_stun_bind_usage_create(srv, NULL, 3478, &bu);125 status = pj_stun_bind_usage_create(srv, NULL, 3478, NULL); 120 126 if (status != PJ_SUCCESS) { 121 127 pj_stun_perror(THIS_FILE, "Unable to create bind usage", status); … … 123 129 } 124 130 125 server_main( );131 server_main(srv); 126 132 127 pj_stun_usage_destroy(bu);128 133 pj_stun_server_destroy(srv); 129 134 pj_pool_factory_dump(&cp.factory, PJ_TRUE); -
pjproject/trunk/pjlib-util/src/pjstun-srv-test/server.c
r1040 r1049 30 30 pj_bool_t thread_quit_flag; 31 31 pj_thread_t **threads; 32 33 unsigned usage_cnt; 34 pj_stun_usage *usage[32]; 32 35 }; 33 36 … … 110 113 111 114 115 pj_status_t pj_stun_server_register_usage(pj_stun_server *srv, 116 pj_stun_usage *usage) 117 { 118 unsigned i; 119 120 for (i=0; i<PJ_ARRAY_SIZE(srv->usage); ++i) { 121 if (srv->usage[i] == usage) 122 return PJ_SUCCESS; 123 } 124 125 for (i=0; i<PJ_ARRAY_SIZE(srv->usage); ++i) { 126 if (srv->usage[i] == NULL) 127 break; 128 } 129 130 if (i == PJ_ARRAY_SIZE(srv->usage)) 131 return PJ_ETOOMANY; 132 133 srv->usage[i] = usage; 134 ++srv->usage_cnt; 135 136 return PJ_SUCCESS; 137 } 138 139 pj_status_t pj_stun_server_unregister_usage(pj_stun_server *srv, 140 pj_stun_usage *usage) 141 { 142 unsigned i; 143 144 for (i=0; i<PJ_ARRAY_SIZE(srv->usage); ++i) { 145 if (srv->usage[i] == usage) 146 break; 147 } 148 149 if (i != PJ_ARRAY_SIZE(srv->usage)) { 150 srv->usage[i] = NULL; 151 --srv->usage_cnt; 152 return PJ_SUCCESS; 153 } 154 155 return PJ_ENOTFOUND; 156 } 157 158 112 159 PJ_DEF(pj_status_t) pj_stun_server_destroy(pj_stun_server *srv) 113 160 { 114 161 unsigned i; 162 163 for (i=0; i<PJ_ARRAY_SIZE(srv->usage); ++i) { 164 if (!srv->usage[i]) 165 continue; 166 167 pj_stun_usage_destroy(srv->usage[i]); 168 pj_stun_server_unregister_usage(srv, srv->usage[i]); 169 } 115 170 116 171 srv->thread_quit_flag = PJ_TRUE; -
pjproject/trunk/pjlib-util/src/pjstun-srv-test/server.h
r1040 r1049 48 48 const pj_sockaddr_t *src_addr, 49 49 unsigned src_addr_len); 50 void (*on_destroy)(pj_stun_usage *usage); 50 51 } pj_stun_usage_cb; 51 52 … … 118 119 119 120 121 122 pj_status_t pj_stun_server_register_usage(pj_stun_server *srv, 123 pj_stun_usage *usage); 124 pj_status_t pj_stun_server_unregister_usage(pj_stun_server *srv, 125 pj_stun_usage *usage); 126 127 120 128 #endif /* __STUN_SERVER_H__ */ 121 129 -
pjproject/trunk/pjlib-util/src/pjstun-srv-test/usage.c
r1040 r1049 31 31 { 32 32 pj_pool_t *pool; 33 pj_stun_server *srv; 33 34 pj_mutex_t *mutex; 34 35 pj_stun_usage_cb cb; … … 76 77 usage = PJ_POOL_ZALLOC_T(pool, pj_stun_usage); 77 78 usage->pool = pool; 79 usage->srv = srv; 78 80 79 81 status = pj_mutex_create_simple(pool, name, &usage->mutex); … … 130 132 } 131 133 134 pj_stun_server_register_usage(srv, usage); 135 132 136 *p_usage = usage; 133 137 return PJ_SUCCESS; … … 144 148 PJ_DEF(pj_status_t) pj_stun_usage_destroy(pj_stun_usage *usage) 145 149 { 150 pj_stun_server_unregister_usage(usage->srv, usage); 151 if (usage->cb.on_destroy) 152 (*usage->cb.on_destroy)(usage); 153 146 154 if (usage->key) { 147 155 pj_ioqueue_unregister(usage->key);
Note: See TracChangeset
for help on using the changeset viewer.