Changeset 996 for pjproject/trunk
- Timestamp:
- Feb 23, 2007 1:07:54 AM (18 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/include/pjlib-util/stun_endpoint.h
r992 r996 62 62 * Create a STUN endpoint instance. 63 63 */ 64 PJ_DECL(pj_status_t) pj_stun_endp t_create(pj_pool_factory *factory,65 unsigned options,66 pj_ioqueue_t *ioqueue,67 pj_timer_heap_t *timer_heap,68 pj_stun_endpoint **p_endpt);64 PJ_DECL(pj_status_t) pj_stun_endpoint_create(pj_pool_factory *factory, 65 unsigned options, 66 pj_ioqueue_t *ioqueue, 67 pj_timer_heap_t *timer_heap, 68 pj_stun_endpoint **p_endpt); 69 69 70 70 /** 71 71 * Destroy STUN endpoint instance. 72 72 */ 73 PJ_DECL(pj_status_t) pj_stun_endp t_destroy(pj_stun_endpoint *endpt);73 PJ_DECL(pj_status_t) pj_stun_endpoint_destroy(pj_stun_endpoint *endpt); 74 74 75 75 -
pjproject/trunk/pjlib-util/include/pjlib-util/stun_msg.h
r993 r996 1196 1196 * @param buffer Buffer where the printable string output will 1197 1197 * be printed on. 1198 * @param length On input, specify the maximum length of the buffer.1199 * On output, it will be filled up with the actual1200 * length of the output string.1198 * @param length Specify the maximum length of the buffer. 1199 * @param printed_len Optional pointer, which on output will be filled 1200 * up with the actual length of the output string. 1201 1201 * 1202 1202 * @return The message string output. … … 1204 1204 PJ_DECL(char*) pj_stun_msg_dump(const pj_stun_msg *msg, 1205 1205 char *buffer, 1206 unsigned *length); 1206 unsigned length, 1207 unsigned *printed_len); 1207 1208 1208 1209 -
pjproject/trunk/pjlib-util/include/pjlib-util/stun_transaction.h
r993 r996 103 103 * @param endpt The STUN endpoint, which will be used to retrieve 104 104 * various settings for the transaction. 105 * @param pool Pool to be used to allocate memory from. 105 106 * @param cb Callback structure, to be used by the transaction 106 107 * to send message and to notify the application about … … 111 112 */ 112 113 PJ_DECL(pj_status_t) pj_stun_client_tsx_create( pj_stun_endpoint *endpt, 114 pj_pool_t *pool, 113 115 const pj_stun_tsx_cb *cb, 114 116 pj_stun_client_tsx **p_tsx); … … 169 171 * @param retransmit Should this message be retransmitted by the 170 172 * STUN transaction. 171 * @param msg The STUN message. 173 * @param pkt The STUN packet to send. 174 * @param pkt_len Length of STUN packet. 172 175 * 173 176 * @return PJ_SUCCESS on success or the appropriate error code. … … 175 178 PJ_DECL(pj_status_t) pj_stun_client_tsx_send_msg(pj_stun_client_tsx *tsx, 176 179 pj_bool_t retransmit, 177 const pj_stun_msg *msg); 180 void *pkt, 181 unsigned pkt_len); 182 178 183 179 184 … … 197 202 * @return PJ_SUCCESS on success or the appropriate error code. 198 203 */ 199 PJ_DECL(pj_status_t) pj_stun_client_tsx_on_rx_pkt(pj_stun_client_tsx *tsx,200 const void *packet,201 pj_size_t pkt_size,202 unsigned *parsed_len);203 204 205 /**206 * Notify the STUN transaction about the arrival of STUN response.207 * If the STUN response contains a final error (300 and greater), the208 * transaction will be terminated and callback will be called. If the209 * STUN response contains response code 100-299, retransmission210 * will cease, but application must still call this function again211 * with a final response later to allow the transaction to complete.212 *213 * @param tsx The STUN client transaction instance.214 * @param packet The incoming packet.215 * @param pkt_size Size of the incoming packet.216 * @param parsed_len Optional pointer to receive the number of bytes217 * that have been parsed from the incoming packet218 * for the STUN message. This is useful if the219 * STUN transaction is running over stream oriented220 * socket such as TCP or TLS.221 *222 * @return PJ_SUCCESS on success or the appropriate error code.223 */224 204 PJ_DECL(pj_status_t) pj_stun_client_tsx_on_rx_msg(pj_stun_client_tsx *tsx, 225 205 const pj_stun_msg *msg); -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_endpoint.c
r992 r996 26 26 * Create a STUN endpoint instance. 27 27 */ 28 PJ_DEF(pj_status_t) pj_stun_endp t_create( pj_pool_factory *factory,29 unsigned options,30 pj_ioqueue_t *ioqueue,31 pj_timer_heap_t *timer_heap,32 pj_stun_endpoint **p_endpt)28 PJ_DEF(pj_status_t) pj_stun_endpoint_create( pj_pool_factory *factory, 29 unsigned options, 30 pj_ioqueue_t *ioqueue, 31 pj_timer_heap_t *timer_heap, 32 pj_stun_endpoint **p_endpt) 33 33 { 34 34 pj_pool_t *pool; … … 58 58 * Destroy STUN endpoint instance. 59 59 */ 60 PJ_DEF(pj_status_t) pj_stun_endp t_destroy(pj_stun_endpoint *endpt)60 PJ_DEF(pj_status_t) pj_stun_endpoint_destroy(pj_stun_endpoint *endpt) 61 61 { 62 62 PJ_ASSERT_RETURN(endpt, PJ_EINVAL); -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_msg.c
r992 r996 1333 1333 pj_stun_msg_hdr *hdr; 1334 1334 1335 PJ_ASSERT_RETURN(pdu && pdu_len > sizeof(pj_stun_msg_hdr), 1336 PJLIB_UTIL_ESTUNINMSGLEN); 1335 PJ_ASSERT_RETURN(pdu, PJ_EINVAL); 1336 1337 if (pdu_len < sizeof(pj_stun_msg_hdr)) 1338 return PJLIB_UTIL_ESTUNINMSGLEN; 1337 1339 1338 1340 PJ_UNUSED_ARG(options); -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_msg_dump.c
r993 r996 33 33 int len; 34 34 35 len = pj_ansi_snprintf( buffer, end-p,35 len = pj_ansi_snprintf(p, end-p, 36 36 " %s: length=%d", 37 37 pj_stun_get_attr_name(ahdr->type), … … 59 59 60 60 if (attr->addr.addr.sa_family == PJ_AF_INET) { 61 len = pj_ansi_snprintf( buffer, end-p,61 len = pj_ansi_snprintf(p, end-p, 62 62 ", IPv4 addr=%s:%d\n", 63 63 pj_inet_ntoa(attr->addr.ipv4.sin_addr), … … 65 65 66 66 } else if (attr->addr.addr.sa_family == PJ_AF_INET6) { 67 len = pj_ansi_snprintf( buffer, end-p,67 len = pj_ansi_snprintf(p, end-p, 68 68 ", IPv6 addr present\n"); 69 69 } else { 70 len = pj_ansi_snprintf( buffer, end-p,70 len = pj_ansi_snprintf(p, end-p, 71 71 ", INVALID ADDRESS FAMILY!\n"); 72 72 } … … 88 88 89 89 attr = (const pj_stun_generic_uint_attr*)ahdr; 90 len = pj_ansi_snprintf( buffer, end-p,91 ", value=%d ( %x)\n",90 len = pj_ansi_snprintf(p, end-p, 91 ", value=%d (0x%x)\n", 92 92 (pj_uint32_t)attr->value, 93 93 (pj_uint32_t)attr->value); … … 104 104 105 105 attr = (pj_stun_generic_string_attr*)ahdr; 106 len = pj_ansi_snprintf( buffer, end-p,106 len = pj_ansi_snprintf(p, end-p, 107 107 ", value=\"%.*s\"\n", 108 108 (int)attr->value.slen, … … 116 116 117 117 attr = (const pj_stun_error_code_attr*) ahdr; 118 len = pj_ansi_snprintf( buffer, end-p,118 len = pj_ansi_snprintf(p, end-p, 119 119 ", err_code=%d, reason=\"%.*s\"\n", 120 120 attr->err_class*100 + attr->number, … … 131 131 attr = (const pj_stun_unknown_attr*) ahdr; 132 132 133 len = pj_ansi_snprintf( buffer, end-p,133 len = pj_ansi_snprintf(p, end-p, 134 134 ", unknown list:"); 135 135 APPLY(); 136 136 137 137 for (j=0; j<attr->attr_count; ++j) { 138 len = pj_ansi_snprintf( buffer, end-p,138 len = pj_ansi_snprintf(p, end-p, 139 139 " %d", 140 140 (int)attr->attrs[j]); … … 148 148 case PJ_STUN_ATTR_USE_CANDIDATE: 149 149 default: 150 len = pj_ansi_snprintf( buffer, end-p, "\n");150 len = pj_ansi_snprintf(p, end-p, "\n"); 151 151 152 152 break; … … 167 167 PJ_DEF(char*) pj_stun_msg_dump(const pj_stun_msg *msg, 168 168 char *buffer, 169 unsigned *length) 169 unsigned length, 170 unsigned *printed_len) 170 171 { 171 172 char *p, *end; … … 176 177 177 178 p = buffer; 178 end = buffer + (*length);179 end = buffer + length; 179 180 180 181 len = pj_ansi_snprintf(p, end-p, "STUN %s %s\n", … … 184 185 185 186 len = pj_ansi_snprintf(p, end-p, 186 " Hdr: length=%d, magic=%x, tsx_id=%x %x %x\n"187 187 " Hdr: length=%d, magic=%08x, tsx_id=%08x %08x %08x\n" 188 " Attributes:\n", 188 189 msg->hdr.length, 189 190 msg->hdr.magic, … … 200 201 on_return: 201 202 *p = '\0'; 202 *length = (p-buffer); 203 if (printed_len) 204 *printed_len = (p-buffer); 203 205 return buffer; 204 206 -
pjproject/trunk/pjlib-util/src/pjlib-util/stun_transaction.c
r993 r996 32 32 { 33 33 char obj_name[PJ_MAX_OBJ_NAME]; 34 pj_pool_t *pool;35 34 pj_stun_endpoint *endpt; 36 35 pj_stun_tsx_cb cb; 37 36 void *user_data; 38 37 39 pj_ uint32_t tsx_id[4];40 38 pj_bool_t complete; 39 \ 41 40 pj_bool_t require_retransmit; 42 41 pj_timer_entry timer; … … 44 43 pj_time_val retransmit_time; 45 44 46 pj_uint8_t last_pkt[PJ_STUN_MAX_PKT_LEN];45 void *last_pkt; 47 46 unsigned last_pkt_size; 48 47 }; … … 66 65 */ 67 66 PJ_DEF(pj_status_t) pj_stun_client_tsx_create(pj_stun_endpoint *endpt, 67 pj_pool_t *pool, 68 68 const pj_stun_tsx_cb *cb, 69 69 pj_stun_client_tsx **p_tsx) 70 70 { 71 pj_pool_t *pool;72 71 pj_stun_client_tsx *tsx; 73 72 … … 75 74 PJ_ASSERT_RETURN(cb->on_send_msg, PJ_EINVAL); 76 75 77 pool = pj_pool_create(endpt->pf, "tsx", 1000, 1000, NULL);78 76 tsx = PJ_POOL_ZALLOC_TYPE(pool, pj_stun_client_tsx); 79 tsx->pool = pool;80 77 tsx->endpt = endpt; 81 78 pj_memcpy(&tsx->cb, cb, sizeof(*cb)); … … 84 81 tsx->timer.user_data = tsx; 85 82 86 pj_ansi_snprintf(tsx->obj_name, sizeof(tsx->obj_name), "stuntsx%p", pool);83 pj_ansi_snprintf(tsx->obj_name, sizeof(tsx->obj_name), "stuntsx%p", tsx); 87 84 88 85 *p_tsx = tsx; … … 104 101 tsx->timer.id = 0; 105 102 } 106 pj_pool_release(tsx->pool);107 103 return PJ_SUCCESS; 104 } 105 106 107 /* 108 * Check if transaction has completed. 109 */ 110 PJ_DEF(pj_bool_t) pj_stun_client_tsx_is_complete(pj_stun_client_tsx *tsx) 111 { 112 PJ_ASSERT_RETURN(tsx, PJ_FALSE); 113 return tsx->complete; 108 114 } 109 115 … … 146 152 tsx->retransmit_time.msec = tsx->endpt->rto_msec; 147 153 148 } else if (tsx->transmit_count < PJ_STUN_MAX_RETRANSMIT_COUNT ) {154 } else if (tsx->transmit_count < PJ_STUN_MAX_RETRANSMIT_COUNT-1) { 149 155 unsigned msec; 150 156 151 157 msec = PJ_TIME_VAL_MSEC(tsx->retransmit_time); 152 msec = (msec >>1) + 100;158 msec = (msec << 1) + 100; 153 159 tsx->retransmit_time.sec = msec / 1000; 154 tsx->retransmit_time.msec = msec % 100 ;160 tsx->retransmit_time.msec = msec % 1000; 155 161 156 162 } else { … … 162 168 * cancel it (as opposed to when schedule_timer() failed we cannot 163 169 * cancel transmission). 164 */ 170 */; 165 171 status = pj_timer_heap_schedule(tsx->endpt->timer_heap, &tsx->timer, 166 172 &tsx->retransmit_time); … … 169 175 return status; 170 176 } 177 tsx->timer.id = TIMER_ACTIVE; 171 178 } 172 179 … … 196 203 PJ_DEF(pj_status_t) pj_stun_client_tsx_send_msg(pj_stun_client_tsx *tsx, 197 204 pj_bool_t retransmit, 198 const pj_stun_msg *msg) 199 { 200 pj_status_t status; 201 202 PJ_ASSERT_RETURN(tsx && msg, PJ_EINVAL); 203 PJ_ASSERT_RETURN(tsx->timer.id != 0, PJ_EBUSY); 205 void *pkt, 206 unsigned pkt_len) 207 { 208 PJ_ASSERT_RETURN(tsx && pkt && pkt_len, PJ_EINVAL); 209 PJ_ASSERT_RETURN(tsx->timer.id == 0, PJ_EBUSY); 204 210 205 211 /* Encode message */ 206 status = pj_stun_msg_encode(msg, tsx->last_pkt, sizeof(tsx->last_pkt), 207 0, &tsx->last_pkt_size); 208 if (status != PJ_SUCCESS) { 209 stun_perror(tsx, "STUN msg_encode() failed", status); 210 return status; 211 } 212 213 /* Update STUN transaction ID */ 214 tsx->tsx_id[0] = msg->hdr.magic; 215 pj_memcpy(&tsx->tsx_id[1], msg->hdr.tsx_id, 12); 212 tsx->last_pkt = pkt; 213 tsx->last_pkt_size = pkt_len; 216 214 217 215 /* Update STUN retransmit flag */ … … 236 234 tsx->timer.id = 0; 237 235 PJ_LOG(4,(tsx->obj_name, "STUN timeout waiting for response")); 236 tsx->complete = PJ_TRUE; 238 237 if (tsx->cb.on_complete) { 239 238 tsx->cb.on_complete(tsx, PJLIB_UTIL_ESTUNNOTRESPOND, NULL); … … 246 245 if (status != PJ_SUCCESS) { 247 246 tsx->timer.id = 0; 247 tsx->complete = PJ_TRUE; 248 248 if (tsx->cb.on_complete) { 249 249 tsx->cb.on_complete(tsx, status, NULL); … … 272 272 } 273 273 274 /* Compare response's transaction ID */275 if (msg->hdr.magic != tsx->tsx_id[0] ||276 pj_memcmp(msg->hdr.tsx_id, &tsx->tsx_id[1], 12) != 0)277 {278 return PJLIB_UTIL_ESTUNINVALIDID;279 }280 274 281 275 /* We have a response with matching transaction ID. … … 312 306 313 307 /* Call callback */ 308 tsx->complete = PJ_TRUE; 314 309 if (tsx->cb.on_complete) { 315 310 tsx->cb.on_complete(tsx, status, msg); … … 320 315 } 321 316 322 323 /*324 * Notify the STUN transaction about the arrival of STUN response.325 */326 PJ_DEF(pj_status_t) pj_stun_client_tsx_on_rx_pkt(pj_stun_client_tsx *tsx,327 const void *packet,328 pj_size_t pkt_size,329 unsigned *parsed_len)330 {331 pj_stun_msg *msg;332 pj_status_t status;333 334 PJ_ASSERT_RETURN(tsx && packet && pkt_size, PJ_EINVAL);335 336 /* Try to parse the message */337 status = pj_stun_msg_decode(tsx->pool, (const pj_uint8_t*)packet,338 pkt_size, 0, &msg, parsed_len,339 NULL, NULL, NULL);340 if (status != PJ_SUCCESS) {341 stun_perror(tsx, "STUN msg_decode() error", status);342 return status;343 }344 345 return pj_stun_client_tsx_on_rx_msg(tsx, msg);346 }347 -
pjproject/trunk/pjlib-util/src/pjstun-client/client_main.c
r993 r996 19 19 #include <pjlib-util.h> 20 20 #include <pjlib.h> 21 #include "stun_session.h" 22 23 #include <conio.h> 21 24 22 25 23 26 #define THIS_FILE "client_main.c" 24 #define MAX_THREADS 825 27 28 29 static my_perror(const char *title, pj_status_t status) 30 { 31 char errmsg[PJ_ERR_MSG_SIZE]; 32 pj_strerror(status, errmsg, sizeof(errmsg)); 33 34 PJ_LOG(3,(THIS_FILE, "%s: %s", title, errmsg)); 35 } 36 37 static pj_status_t on_send_msg(pj_stun_tx_data *tdata, 38 const void *pkt, 39 pj_size_t pkt_size, 40 unsigned addr_len, 41 const pj_sockaddr_t *dst_addr) 42 { 43 pj_sock_t sock; 44 pj_ssize_t len; 45 pj_status_t status; 46 47 sock = (pj_sock_t) pj_stun_session_get_user_data(tdata->sess); 48 49 len = pkt_size; 50 status = pj_sock_sendto(sock, pkt, &len, 0, dst_addr, addr_len); 51 52 if (status != PJ_SUCCESS) 53 my_perror("Error sending packet", status); 54 55 return status; 56 } 57 58 static void on_bind_response(pj_stun_session *sess, 59 pj_status_t status, 60 pj_stun_tx_data *request, 61 const pj_stun_msg *response) 62 { 63 my_perror("on_bind_response()", status); 64 } 65 66 int main() 67 { 68 pj_stun_endpoint *endpt = NULL; 69 pj_pool_t *pool = NULL; 70 pj_caching_pool cp; 71 pj_timer_heap_t *th = NULL; 72 pj_stun_session *sess; 73 pj_sock_t sock = PJ_INVALID_SOCKET; 74 pj_sockaddr_in addr; 75 pj_stun_session_cb stun_cb; 76 pj_stun_tx_data *tdata; 77 pj_str_t s; 78 pj_status_t status; 79 80 status = pj_init(); 81 status = pjlib_util_init(); 82 83 pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); 84 85 pool = pj_pool_create(&cp.factory, NULL, 1000, 1000, NULL); 86 87 status = pj_timer_heap_create(pool, 1000, &th); 88 pj_assert(status == PJ_SUCCESS); 89 90 status = pj_stun_endpoint_create(&cp.factory, 0, NULL, th, &endpt); 91 pj_assert(status == PJ_SUCCESS); 92 93 status = pj_sock_socket(PJ_AF_INET, PJ_SOCK_DGRAM, 0, &sock); 94 pj_assert(status == PJ_SUCCESS); 95 96 status = pj_sockaddr_in_init(&addr, pj_cstr(&s, "127.0.0.1"), PJ_STUN_PORT); 97 pj_assert(status == PJ_SUCCESS); 98 99 pj_memset(&stun_cb, 0, sizeof(stun_cb)); 100 stun_cb.on_send_msg = &on_send_msg; 101 stun_cb.on_bind_response = &on_bind_response; 102 103 status = pj_stun_session_create(endpt, NULL, &stun_cb, &sess); 104 pj_assert(status == PJ_SUCCESS); 105 106 pj_stun_session_set_user_data(sess, (void*)sock); 107 108 status = pj_stun_session_create_bind_req(sess, &tdata); 109 pj_assert(status == PJ_SUCCESS); 110 111 status = pj_stun_session_send_msg(sess, 0, sizeof(addr), &addr, tdata); 112 pj_assert(status == PJ_SUCCESS); 113 114 while (1) { 115 pj_fd_set_t rset; 116 int n; 117 pj_time_val timeout; 118 119 if (kbhit()) { 120 if (_getch()==27) 121 break; 122 } 123 124 PJ_FD_ZERO(&rset); 125 PJ_FD_SET(sock, &rset); 126 127 timeout.sec = 0; timeout.msec = 100; 128 129 n = pj_sock_select(FD_SETSIZE, &rset, NULL, NULL, &timeout); 130 131 if (PJ_FD_ISSET(sock, &rset)) { 132 char pkt[512]; 133 pj_ssize_t len; 134 135 len = sizeof(pkt); 136 status = pj_sock_recv(sock, pkt, &len, 0); 137 if (status == PJ_SUCCESS) { 138 pj_stun_session_on_rx_pkt(sess, pkt, len, NULL); 139 } 140 } 141 142 pj_timer_heap_poll(th, NULL); 143 } 144 145 on_return: 146 if (sock != PJ_INVALID_SOCKET) 147 pj_sock_close(sock); 148 if (endpt) 149 pj_stun_endpoint_destroy(endpt); 150 if (th) 151 pj_timer_heap_destroy(th); 152 if (pool) 153 pj_pool_release(pool); 154 pj_caching_pool_destroy(&cp); 155 156 return 0; 157 } 158 159 -
pjproject/trunk/pjlib-util/src/pjstun-client/stun_session.c
r993 r996 27 27 void *user_data; 28 28 29 pj_str_t realm; 30 pj_str_t username; 31 pj_str_t password; 32 33 pj_bool_t fingerprint_enabled; 29 /* Long term credential */ 30 pj_str_t l_realm; 31 pj_str_t l_username; 32 pj_str_t l_password; 33 34 /* Short term credential */ 35 pj_str_t s_username; 36 pj_str_t s_password; 34 37 35 38 pj_stun_tx_data pending_request_list; … … 65 68 66 69 static void tsx_on_complete(pj_stun_client_tsx *tsx, 67 68 70 pj_status_t status, 71 const pj_stun_msg *response); 69 72 static pj_status_t tsx_on_send_msg(pj_stun_client_tsx *tsx, 70 73 const void *stun_pkt, … … 165 168 static pj_status_t session_apply_req(pj_stun_session *sess, 166 169 pj_pool_t *pool, 170 unsigned options, 167 171 pj_stun_msg *msg) 168 172 { … … 172 176 * Section 8.3.1. Formulating the Request Message 173 177 */ 174 if ( sess->realm.slen || sess->username.slen) {178 if (options & PJ_STUN_USE_LONG_TERM_CRED) { 175 179 pj_stun_generic_string_attr *auname; 176 180 pj_stun_msg_integrity_attr *amsgi; 181 pj_stun_generic_string_attr *arealm; 177 182 178 183 /* Create and add USERNAME attribute */ 179 184 status = pj_stun_generic_string_attr_create(sess->pool, 180 185 PJ_STUN_ATTR_USERNAME, 181 &sess-> username,186 &sess->l_username, 182 187 &auname); 183 188 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); … … 186 191 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 187 192 188 if (sess->realm.slen) { 189 /* Add REALM only when long term credential is used */ 190 pj_stun_generic_string_attr *arealm; 191 status = pj_stun_generic_string_attr_create(sess->pool, 192 PJ_STUN_ATTR_REALM, 193 &sess->realm, 194 &arealm); 195 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 196 197 status = pj_stun_msg_add_attr(msg, &arealm->hdr); 198 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 199 } 193 /* Add REALM only when long term credential is used */ 194 status = pj_stun_generic_string_attr_create(sess->pool, 195 PJ_STUN_ATTR_REALM, 196 &sess->l_realm, 197 &arealm); 198 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 199 200 status = pj_stun_msg_add_attr(msg, &arealm->hdr); 201 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 200 202 201 203 /* Add MESSAGE-INTEGRITY attribute */ … … 206 208 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 207 209 208 PJ_TODO(COMPUTE_MESSAGE_INTEGRITY); 209 210 PJ_TODO(COMPUTE_MESSAGE_INTEGRITY1); 211 212 } else if (options & PJ_STUN_USE_SHORT_TERM_CRED) { 213 pj_stun_generic_string_attr *auname; 214 pj_stun_msg_integrity_attr *amsgi; 215 216 /* Create and add USERNAME attribute */ 217 status = pj_stun_generic_string_attr_create(sess->pool, 218 PJ_STUN_ATTR_USERNAME, 219 &sess->s_username, 220 &auname); 221 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 222 223 status = pj_stun_msg_add_attr(msg, &auname->hdr); 224 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 225 226 /* Add MESSAGE-INTEGRITY attribute */ 227 status = pj_stun_msg_integrity_attr_create(sess->pool, &amsgi); 228 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 229 230 status = pj_stun_msg_add_attr(msg, &amsgi->hdr); 231 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 232 233 PJ_TODO(COMPUTE_MESSAGE_INTEGRITY2); 210 234 } 211 235 212 236 /* Add FINGERPRINT attribute if necessary */ 213 if ( sess->fingerprint_enabled) {237 if (options & PJ_STUN_USE_FINGERPRINT) { 214 238 pj_stun_fingerprint_attr *af; 215 239 … … 227 251 228 252 229 230 231 253 static void tsx_on_complete(pj_stun_client_tsx *tsx, 254 pj_status_t status, 255 const pj_stun_msg *response) 256 { 257 pj_stun_tx_data *tdata; 258 259 tdata = (pj_stun_tx_data*) pj_stun_client_tsx_get_data(tsx); 260 261 switch (PJ_STUN_GET_METHOD(tdata->msg->hdr.type)) { 262 case PJ_STUN_BINDING_METHOD: 263 tdata->sess->cb.on_bind_response(tdata->sess, status, tdata, response); 264 break; 265 case PJ_STUN_ALLOCATE_METHOD: 266 tdata->sess->cb.on_allocate_response(tdata->sess, status, 267 tdata, response); 268 break; 269 case PJ_STUN_SET_ACTIVE_DESTINATION_METHOD: 270 tdata->sess->cb.on_set_active_destination_response(tdata->sess, status, 271 tdata, response); 272 break; 273 case PJ_STUN_CONNECT_METHOD: 274 tdata->sess->cb.on_connect_response(tdata->sess, status, tdata, 275 response); 276 break; 277 default: 278 pj_assert(!"Unknown method"); 279 break; 280 } 281 } 282 283 static pj_status_t tsx_on_send_msg(pj_stun_client_tsx *tsx, 284 const void *stun_pkt, 285 pj_size_t pkt_size) 286 { 287 pj_stun_tx_data *tdata; 288 289 tdata = (pj_stun_tx_data*) pj_stun_client_tsx_get_data(tsx); 290 291 return tdata->sess->cb.on_send_msg(tdata, stun_pkt, pkt_size, 292 tdata->addr_len, tdata->dst_addr); 293 } 294 295 /* **************************************************************************/ 232 296 233 297 PJ_DEF(pj_status_t) pj_stun_session_create( pj_stun_endpoint *endpt, … … 261 325 { 262 326 PJ_ASSERT_RETURN(sess, PJ_EINVAL); 327 263 328 pj_pool_release(sess->pool); 264 329 … … 281 346 } 282 347 283 PJ_DEF(pj_status_t) pj_stun_session_set_credential( pj_stun_session *sess, 284 const pj_str_t *realm, 285 const pj_str_t *user, 286 const pj_str_t *passwd) 287 { 288 pj_str_t empty = { NULL, 0 }; 348 PJ_DEF(pj_status_t) 349 pj_stun_session_set_long_term_credential(pj_stun_session *sess, 350 const pj_str_t *realm, 351 const pj_str_t *user, 352 const pj_str_t *passwd) 353 { 354 pj_str_t nil = { NULL, 0 }; 289 355 290 356 PJ_ASSERT_RETURN(sess, PJ_EINVAL); 291 pj_strdup_with_null(sess->pool, &sess->realm, realm ? realm : &empty); 292 pj_strdup_with_null(sess->pool, &sess->username, user ? user : &empty); 293 pj_strdup_with_null(sess->pool, &sess->password, passwd ? passwd : &empty); 294 295 return PJ_SUCCESS; 296 } 297 298 PJ_DEF(pj_status_t) pj_stun_session_enable_fingerprint(pj_stun_session *sess, 299 pj_bool_t enabled) 300 { 357 pj_strdup_with_null(sess->pool, &sess->l_realm, realm ? realm : &nil); 358 pj_strdup_with_null(sess->pool, &sess->l_username, user ? user : &nil); 359 pj_strdup_with_null(sess->pool, &sess->l_password, passwd ? passwd : &nil); 360 361 return PJ_SUCCESS; 362 } 363 364 365 PJ_DEF(pj_status_t) 366 pj_stun_session_set_short_term_credential(pj_stun_session *sess, 367 const pj_str_t *user, 368 const pj_str_t *passwd) 369 { 370 pj_str_t nil = { NULL, 0 }; 371 301 372 PJ_ASSERT_RETURN(sess, PJ_EINVAL); 302 sess->fingerprint_enabled = enabled; 373 pj_strdup_with_null(sess->pool, &sess->s_username, user ? user : &nil); 374 pj_strdup_with_null(sess->pool, &sess->s_password, passwd ? passwd : &nil); 375 303 376 return PJ_SUCCESS; 304 377 } … … 308 381 pj_stun_tx_data **p_tdata) 309 382 { 310 pj_pool_t *pool;311 383 pj_stun_tx_data *tdata; 312 384 pj_status_t status; … … 318 390 return status; 319 391 320 status = session_apply_req(sess, pool, tdata->msg);321 if (status != PJ_SUCCESS) {322 destroy_tdata(tdata);323 return status;324 }325 326 392 *p_tdata = tdata; 327 393 return PJ_SUCCESS; … … 368 434 369 435 PJ_DEF(pj_status_t) pj_stun_session_send_msg( pj_stun_session *sess, 436 unsigned options, 370 437 unsigned addr_len, 371 438 const pj_sockaddr_t *server, … … 376 443 PJ_ASSERT_RETURN(sess && addr_len && server && tdata, PJ_EINVAL); 377 444 445 /* Allocate packet */ 446 tdata->max_len = PJ_STUN_MAX_PKT_LEN; 447 tdata->pkt = pj_pool_alloc(tdata->pool, tdata->max_len); 448 378 449 if (PJ_LOG_MAX_LEVEL >= 5) { 379 char buf[512]; 380 unsigned buflen = sizeof(buf); 450 char *buf = (char*) tdata->pkt; 381 451 const char *dst_name; 382 452 int dst_port; … … 398 468 PJ_LOG(5,(SNAME(sess), 399 469 "Sending STUN message to %s:%d:\n" 400 "%s\n", 470 "--- begin STUN message ---\n" 471 "%s" 472 "--- end of STUN message ---\n", 401 473 dst_name, dst_port, 402 pj_stun_msg_dump(tdata->msg, buf, &buflen))); 403 } 404 474 pj_stun_msg_dump(tdata->msg, buf, tdata->max_len, NULL))); 475 } 476 477 /* Apply options */ 478 status = session_apply_req(sess, tdata->pool, options, tdata->msg); 479 if (status != PJ_SUCCESS) { 480 LOG_ERR_(sess, "Error applying options", status); 481 destroy_tdata(tdata); 482 return status; 483 } 484 485 /* Encode message */ 486 status = pj_stun_msg_encode(tdata->msg, tdata->pkt, tdata->max_len, 487 0, &tdata->pkt_size); 488 if (status != PJ_SUCCESS) { 489 LOG_ERR_(sess, "STUN encode() error", status); 490 destroy_tdata(tdata); 491 return status; 492 } 405 493 406 494 /* If this is a STUN request message, then send the request with … … 410 498 411 499 /* Create STUN client transaction */ 412 status = pj_stun_client_tsx_create(sess->endpt, &tsx_cb,413 &t data->client_tsx);500 status = pj_stun_client_tsx_create(sess->endpt, tdata->pool, 501 &tsx_cb, &tdata->client_tsx); 414 502 PJ_ASSERT_RETURN(status==PJ_SUCCESS, status); 415 503 pj_stun_client_tsx_set_data(tdata->client_tsx, (void*)tdata); 504 505 /* Save the remote address */ 506 tdata->addr_len = addr_len; 507 tdata->dst_addr = server; 416 508 417 509 /* Send the request! */ 418 510 status = pj_stun_client_tsx_send_msg(tdata->client_tsx, PJ_TRUE, 419 tdata-> msg);511 tdata->pkt, tdata->pkt_size); 420 512 if (status != PJ_SUCCESS && status != PJ_EPENDING) { 421 513 LOG_ERR_(sess, "Error sending STUN request", status); 514 destroy_tdata(tdata); 422 515 return status; 423 516 } … … 428 521 } else { 429 522 /* Otherwise for non-request message, send directly to transport. */ 430 status = sess->cb.on_send_msg(tdata, addr_len, server); 523 status = sess->cb.on_send_msg(tdata, tdata->pkt, tdata->pkt_size, 524 addr_len, server); 525 526 if (status != PJ_SUCCESS && status != PJ_EPENDING) { 527 LOG_ERR_(sess, "Error sending STUN request", status); 528 destroy_tdata(tdata); 529 return status; 530 } 431 531 } 432 532 … … 442 542 { 443 543 pj_stun_msg *msg; 544 pj_pool_t *tmp_pool; 545 char *dump; 444 546 pj_status_t status; 445 547 446 548 PJ_ASSERT_RETURN(sess && packet && pkt_size, PJ_EINVAL); 447 549 550 tmp_pool = pj_pool_create(sess->endpt->pf, "tmpstun", 1024, 1024, NULL); 551 if (!tmp_pool) 552 return PJ_ENOMEM; 553 448 554 /* Try to parse the message */ 449 status = pj_stun_msg_decode(t sx->pool, (const pj_uint8_t*)packet,555 status = pj_stun_msg_decode(tmp_pool, (const pj_uint8_t*)packet, 450 556 pkt_size, 0, &msg, parsed_len, 451 557 NULL, NULL, NULL); 452 558 if (status != PJ_SUCCESS) { 453 559 LOG_ERR_(sess, "STUN msg_decode() error", status); 560 pj_pool_release(tmp_pool); 454 561 return status; 455 562 } 563 564 dump = pj_pool_alloc(tmp_pool, PJ_STUN_MAX_PKT_LEN); 565 566 PJ_LOG(4,(SNAME(sess), 567 "RX STUN message:\n" 568 "--- begin STUN message ---" 569 "%s" 570 "--- end of STUN message ---\n", 571 pj_stun_msg_dump(msg, dump, PJ_STUN_MAX_PKT_LEN, NULL))); 572 456 573 457 574 if (PJ_STUN_IS_RESPONSE(msg->hdr.type) || … … 464 581 if (tdata == NULL) { 465 582 LOG_ERR_(sess, "STUN error finding transaction", PJ_ENOTFOUND); 583 pj_pool_release(tmp_pool); 466 584 return PJ_ENOTFOUND; 467 585 } … … 472 590 */ 473 591 status = pj_stun_client_tsx_on_rx_msg(tdata->client_tsx, msg); 474 if (status != PJ_SUCCESS) 592 if (status != PJ_SUCCESS) { 593 pj_pool_release(tmp_pool); 475 594 return status; 595 } 476 596 477 597 /* If transaction has completed, destroy the transmit data. … … 483 603 } 484 604 605 pj_pool_release(tmp_pool); 485 606 return PJ_SUCCESS; 486 607 487 608 } else if (PJ_STUN_IS_REQUEST(msg->hdr.type)) { 488 609 610 PJ_TODO(HANDLE_INCOMING_STUN_REQUEST); 489 611 490 612 } else if (PJ_STUN_IS_INDICATION(msg->hdr.type)) { 491 613 614 PJ_TODO(HANDLE_INCOMING_STUN_INDICATION); 492 615 493 616 } else { 494 617 pj_assert(!"Unexpected!"); 495 return PJ_EBUG; 496 } 497 498 } 499 618 } 619 620 pj_pool_release(tmp_pool); 621 return PJ_ENOTSUP; 622 } 623 -
pjproject/trunk/pjlib-util/src/pjstun-client/stun_session.h
r993 r996 26 26 27 27 28 /** Forward declaration for pj_stun_tx_data */ 28 29 typedef struct pj_stun_tx_data pj_stun_tx_data; 30 31 /** Forward declaration for pj_stun_session */ 29 32 typedef struct pj_stun_session pj_stun_session; 30 33 34 /** 35 * This is the callback to be registered to pj_stun_session, to send 36 * outgoing message and to receive various notifications from the STUN 37 * session. 38 */ 31 39 typedef struct pj_stun_session_cb 32 40 { 41 /** 42 * Callback to be called by the STUN session to send outgoing message. 43 * 44 * @param tdata The STUN transmit data containing the original 45 * STUN message 46 * @param pkt Packet to be sent. 47 * @param pkt_size Size of the packet to be sent. 48 * @param addr_len Length of destination address. 49 * @param dst_addr The destination address. 50 * 51 * @return The callback should return the status of the 52 * packet sending. 53 */ 33 54 pj_status_t (*on_send_msg)(pj_stun_tx_data *tdata, 55 const void *pkt, 56 pj_size_t pkt_size, 34 57 unsigned addr_len, 35 58 const pj_sockaddr_t *dst_addr); 36 59 37 void (*on_bind_response)(void *user_data, pj_status_t status, pj_stun_msg *response); 38 void (*on_allocate_response)(void *user_data, pj_status_t status, pj_stun_msg *response); 39 void (*on_set_active_destination_response)(void *user_data, pj_status_t status, pj_stun_msg *response); 40 void (*on_connect_response)(void *user_data, pj_status_t status, pj_stun_msg *response); 60 /** 61 * Callback to be called when Binding response is received or the 62 * transaction has timed out. 63 * 64 * @param sess The STUN session. 65 * @param status Status of the request. If the value if not 66 * PJ_SUCCESS, the transaction has timed-out 67 * or other error has occurred, and the response 68 * argument may be NULL. 69 * @param request The original STUN request. 70 * @param response The response message, on successful transaction. 71 */ 72 void (*on_bind_response)(pj_stun_session *sess, 73 pj_status_t status, 74 pj_stun_tx_data *request, 75 const pj_stun_msg *response); 76 77 /** 78 * Callback to be called when Allocate response is received or the 79 * transaction has timed out. 80 * 81 * @param sess The STUN session. 82 * @param status Status of the request. If the value if not 83 * PJ_SUCCESS, the transaction has timed-out 84 * or other error has occurred, and the response 85 * argument may be NULL. 86 * @param request The original STUN request. 87 * @param response The response message, on successful transaction. 88 */ 89 void (*on_allocate_response)(pj_stun_session *sess, 90 pj_status_t status, 91 pj_stun_tx_data *request, 92 const pj_stun_msg *response); 93 94 /** 95 * Callback to be called when Set Active Destination response is received 96 * or the transaction has timed out. 97 * 98 * @param sess The STUN session. 99 * @param status Status of the request. If the value if not 100 * PJ_SUCCESS, the transaction has timed-out 101 * or other error has occurred, and the response 102 * argument may be NULL. 103 * @param request The original STUN request. 104 * @param response The response message, on successful transaction. 105 */ 106 void (*on_set_active_destination_response)(pj_stun_session *sess, 107 pj_status_t status, 108 pj_stun_tx_data *request, 109 const pj_stun_msg *response); 110 111 /** 112 * Callback to be called when Connect response is received or the 113 * transaction has timed out. 114 * 115 * @param sess The STUN session. 116 * @param status Status of the request. If the value if not 117 * PJ_SUCCESS, the transaction has timed-out 118 * or other error has occurred, and the response 119 * argument may be NULL. 120 * @param request The original STUN request. 121 * @param response The response message, on successful transaction. 122 */ 123 void (*on_connect_response)( pj_stun_session *sess, 124 pj_status_t status, 125 pj_stun_tx_data *request, 126 const pj_stun_msg *response); 41 127 } pj_stun_session_cb; 42 128 43 129 130 /** 131 * This structure describe the outgoing STUN transmit data to carry the 132 * message to be sent. 133 */ 44 134 struct pj_stun_tx_data 45 135 { 46 136 PJ_DECL_LIST_MEMBER(struct pj_stun_tx_data); 47 137 48 pj_pool_t *pool; 49 pj_stun_session *sess; 50 pj_stun_msg *msg; 51 void *user_data; 52 53 pj_stun_client_tsx *client_tsx; 54 pj_uint8_t client_key[12]; 138 pj_pool_t *pool; /**< Pool. */ 139 pj_stun_session *sess; /**< The STUN session. */ 140 pj_stun_msg *msg; /**< The STUN message. */ 141 void *user_data; /**< Arbitrary user data. */ 142 143 pj_stun_client_tsx *client_tsx; /**< Client STUN transaction. */ 144 pj_uint8_t client_key[12];/**< Client transaction key. */ 145 146 void *pkt; /**< The STUN packet. */ 147 unsigned max_len; /**< Length of packet buffer. */ 148 unsigned pkt_size; /**< The actual length of STUN pkt. */ 149 150 unsigned addr_len; /**< Length of destination address. */ 151 const pj_sockaddr_t *dst_addr; /**< Destination address. */ 55 152 }; 56 153 57 154 155 /** 156 * Options that can be specified when creating or sending outgoing STUN 157 * messages. These options may be specified as bitmask. 158 */ 159 enum pj_stun_session_option 160 { 161 /** 162 * Add short term credential to the message. This option may not be used 163 * together with PJ_STUN_USE_LONG_TERM_CRED option. 164 */ 165 PJ_STUN_USE_SHORT_TERM_CRED = 1, 166 167 /** 168 * Add long term credential to the message. This option may not be used 169 * together with PJ_STUN_USE_SHORT_TERM_CRED option. 170 */ 171 PJ_STUN_USE_LONG_TERM_CRED = 2, 172 173 /** 174 * Add STUN fingerprint to the message. 175 */ 176 PJ_STUN_USE_FINGERPRINT = 4 177 }; 178 179 180 /** 181 * Create a STUN session. 182 * 183 * @param endpt The STUN endpoint, to be used to register timers etc. 184 * @param name Optional name to be associated with this instance. The 185 * name will be used for example for logging purpose. 186 * @param cb Session callback. 187 * @param p_sess Pointer to receive STUN session instance. 188 * 189 * @return PJ_SUCCESS on success, or the appropriate error code. 190 */ 58 191 PJ_DECL(pj_status_t) pj_stun_session_create(pj_stun_endpoint *endpt, 59 192 const char *name, … … 61 194 pj_stun_session **p_sess); 62 195 196 /** 197 * Destroy the STUN session. 198 * 199 * @param sess The STUN session instance. 200 * 201 * @return PJ_SUCCESS on success, or the appropriate error code. 202 */ 63 203 PJ_DECL(pj_status_t) pj_stun_session_destroy(pj_stun_session *sess); 64 204 205 /** 206 * Associated an arbitrary data with this STUN session. The user data may 207 * be retrieved later with pj_stun_session_get_user_data() function. 208 * 209 * @param sess The STUN session instance. 210 * 211 * @return PJ_SUCCESS on success, or the appropriate error code. 212 */ 65 213 PJ_DECL(pj_status_t) pj_stun_session_set_user_data(pj_stun_session *sess, 66 214 void *user_data); 67 215 216 /** 217 * Retrieve the user data previously associated to this STUN session with 218 * pj_stun_session_set_user_data(). 219 * 220 * @param sess The STUN session instance. 221 * 222 * @return The user data associated with this STUN session. 223 */ 68 224 PJ_DECL(void*) pj_stun_session_get_user_data(pj_stun_session *sess); 69 225 70 PJ_DECL(pj_status_t) pj_stun_session_set_credential(pj_stun_session *sess, 71 const pj_str_t *realm, 72 const pj_str_t *user, 73 const pj_str_t *passwd); 74 75 PJ_DECL(pj_status_t) pj_stun_session_enable_fingerprint(pj_stun_session *sess, 76 pj_bool_t enabled); 77 226 /** 227 * Save a long term credential to be used by this STUN session when sending 228 * outgoing messages. After long term credential is configured, application 229 * may specify PJ_STUN_USE_LONG_TERM_CRED option when sending outgoing STUN 230 * message to send the long term credential in the message. 231 * 232 * @param sess The STUN session instance. 233 * @param realm Realm of the long term credential. 234 * @param user The user name. 235 * @param passwd The pain-text password. 236 * 237 * @return PJ_SUCCESS on success, or the appropriate error code. 238 */ 239 PJ_DECL(pj_status_t) 240 pj_stun_session_set_long_term_credential(pj_stun_session *sess, 241 const pj_str_t *realm, 242 const pj_str_t *user, 243 const pj_str_t *passwd); 244 245 246 /** 247 * Save a short term credential to be used by this STUN session when sending 248 * outgoing messages. After short term credential is configured, application 249 * may specify PJ_STUN_USE_SHORT_TERM_CRED option when sending outgoing STUN 250 * message to send the short term credential in the message. 251 * 252 * @param sess The STUN session instance. 253 * @param user The user name. 254 * @param passwd The pain-text password. 255 * 256 * @return PJ_SUCCESS on success, or the appropriate error code. 257 */ 258 PJ_DECL(pj_status_t) 259 pj_stun_session_set_short_term_credential(pj_stun_session *sess, 260 const pj_str_t *user, 261 const pj_str_t *passwd); 262 263 /** 264 * Create a STUN Bind request message. After the message has been 265 * successfully created, application can send the message by calling 266 * pj_stun_session_send_msg(). 267 * 268 * @param sess The STUN session instance. 269 * @param p_tdata Pointer to receive STUN transmit data instance containing 270 * the request. 271 * 272 * @return PJ_SUCCESS on success, or the appropriate error code. 273 */ 78 274 PJ_DECL(pj_status_t) pj_stun_session_create_bind_req(pj_stun_session *sess, 79 275 pj_stun_tx_data **p_tdata); 80 276 277 /** 278 * Create a STUN Allocate request message. After the message has been 279 * successfully created, application can send the message by calling 280 * pj_stun_session_send_msg(). 281 * 282 * @param sess The STUN session instance. 283 * @param p_tdata Pointer to receive STUN transmit data instance containing 284 * the request. 285 * 286 * @return PJ_SUCCESS on success, or the appropriate error code. 287 */ 81 288 PJ_DECL(pj_status_t) pj_stun_session_create_allocate_req(pj_stun_session *sess, 82 289 pj_stun_tx_data **p_tdata); 83 290 291 /** 292 * Create a STUN Set Active Destination request message. After the message 293 * has been successfully created, application can send the message by calling 294 * pj_stun_session_send_msg(). 295 * 296 * @param sess The STUN session instance. 297 * @param p_tdata Pointer to receive STUN transmit data instance containing 298 * the request. 299 * 300 * @return PJ_SUCCESS on success, or the appropriate error code. 301 */ 84 302 PJ_DECL(pj_status_t) 85 303 pj_stun_session_create_set_active_destination_req(pj_stun_session *sess, 86 304 pj_stun_tx_data **p_tdata); 87 305 306 /** 307 * Create a STUN Connect request message. After the message has been 308 * successfully created, application can send the message by calling 309 * pj_stun_session_send_msg(). 310 * 311 * @param sess The STUN session instance. 312 * @param p_tdata Pointer to receive STUN transmit data instance containing 313 * the request. 314 * 315 * @return PJ_SUCCESS on success, or the appropriate error code. 316 */ 88 317 PJ_DECL(pj_status_t) pj_stun_session_create_connect_req(pj_stun_session *sess, 89 318 pj_stun_tx_data **p_tdata); 90 319 91 PJ_DECL(pj_status_t) 320 /** 321 * Create a STUN Connection Status Indication message. After the message 322 * has been successfully created, application can send the message by calling 323 * pj_stun_session_send_msg(). 324 * 325 * @param sess The STUN session instance. 326 * @param p_tdata Pointer to receive STUN transmit data instance containing 327 * the message. 328 * 329 * @return PJ_SUCCESS on success, or the appropriate error code. 330 */ 331 PJ_DECL(pj_status_t) 92 332 pj_stun_session_create_connection_status_ind(pj_stun_session *sess, 93 333 pj_stun_tx_data **p_tdata); 94 334 335 /** 336 * Create a STUN Send Indication message. After the message has been 337 * successfully created, application can send the message by calling 338 * pj_stun_session_send_msg(). 339 * 340 * @param sess The STUN session instance. 341 * @param p_tdata Pointer to receive STUN transmit data instance containing 342 * the message. 343 * 344 * @return PJ_SUCCESS on success, or the appropriate error code. 345 */ 95 346 PJ_DECL(pj_status_t) pj_stun_session_create_send_ind(pj_stun_session *sess, 96 347 pj_stun_tx_data **p_tdata); 97 348 349 /** 350 * Create a STUN Data Indication message. After the message has been 351 * successfully created, application can send the message by calling 352 * pj_stun_session_send_msg(). 353 * 354 * @param sess The STUN session instance. 355 * @param p_tdata Pointer to receive STUN transmit data instance containing 356 * the message. 357 * 358 * @return PJ_SUCCESS on success, or the appropriate error code. 359 */ 98 360 PJ_DECL(pj_status_t) pj_stun_session_create_data_ind(pj_stun_session *sess, 99 361 pj_stun_tx_data **p_tdata); 100 362 363 /** 364 * Send STUN message to the specified destination. This function will encode 365 * the pj_stun_msg instance to a packet buffer, and add credential or 366 * fingerprint if necessary. If the message is a request, the session will 367 * also create and manage a STUN client transaction to be used to manage the 368 * retransmission of the request. After the message has been encoded and 369 * transaction is setup, the \a on_send_msg() callback of pj_stun_session_cb 370 * (which is registered when the STUN session is created) will be called 371 * to actually send the message to the wire. 372 * 373 * @param sess The STUN session instance. 374 * @param options Optional flags, from pj_stun_session_option. 375 * @param addr_len Length of destination address. 376 * @param dst_addr The destination socket address. 377 * @param tdata The STUN transmit data containing the STUN message to 378 * be sent. 379 * 380 * @return PJ_SUCCESS on success, or the appropriate error code. 381 */ 101 382 PJ_DECL(pj_status_t) pj_stun_session_send_msg(pj_stun_session *sess, 383 unsigned options, 102 384 unsigned addr_len, 103 const pj_sockaddr_t * server,385 const pj_sockaddr_t *dst_addr, 104 386 pj_stun_tx_data *tdata); 105 387 388 /** 389 * Application must call this function to notify the STUN session about 390 * the arrival of STUN packet. The STUN packet MUST have been checked 391 * first with #pj_stun_msg_check() to verify that this is indeed a valid 392 * STUN packet. 393 * 394 * The STUN session will decode the packet into pj_stun_msg, and process 395 * the message accordingly. If the message is a response, it will search 396 * through the outstanding STUN client transactions for a matching 397 * transaction ID and hand over the response to the transaction. 398 * 399 * On successful message processing, application will be notified about 400 * the message via one of the pj_stun_session_cb callback. 401 * 402 * @param sess The STUN session instance. 403 * @param packet The packet containing STUN message. 404 * @param pkt_size Size of the packet. 405 * @param parsed_len Optional pointer to receive the size of the parsed 406 * STUN message (useful if packet is received via a 407 * stream oriented protocol). 408 * 409 * @return PJ_SUCCESS on success, or the appropriate error code. 410 */ 106 411 PJ_DECL(pj_status_t) pj_stun_session_on_rx_pkt(pj_stun_session *sess, 107 412 const void *packet, -
pjproject/trunk/pjlib-util/src/pjstun-srv/server_main.c
r992 r996 101 101 pj_status_t status; 102 102 103 /* Print to log */ 104 PJ_LOG(4,(THIS_FILE, "TX STUN message: \n" 105 "--- begin STUN message ---\n" 106 "%s" 107 "--- end of STUN message ---\n", 108 pj_stun_msg_dump(msg, svc->tx_pkt, sizeof(svc->tx_pkt), NULL))); 109 103 110 /* Encode packet */ 104 111 tx_pkt_len = sizeof(svc->tx_pkt); … … 221 228 unsigned uattr_cnt; 222 229 pj_uint16_t uattr_types[16]; 230 char dump[512]; 223 231 pj_status_t status; 224 232 … … 242 250 } 243 251 244 PJ_LOG(4,(THIS_FILE, "RX STUN %s %s message", 245 pj_stun_get_method_name(rx_msg->hdr.type), 246 pj_stun_get_class_name(rx_msg->hdr.type))); 252 PJ_LOG(4,(THIS_FILE, "RX STUN message: \n" 253 "--- begin STUN message ---\n" 254 "%s" 255 "--- end of STUN message ---\n", 256 pj_stun_msg_dump(rx_msg, dump, sizeof(dump), NULL))); 247 257 248 258 if (PJ_STUN_IS_REQUEST(rx_msg->hdr.type)) { -
pjproject/trunk/pjlib/src/pj/errno.c
r974 r996 153 153 pj_assert(buf && bufsize); 154 154 155 if (statcode < PJ_ERRNO_START + PJ_ERRNO_SPACE_SIZE) { 155 if (statcode == PJ_SUCCESS) { 156 len = pj_ansi_snprintf( buf, bufsize, "Success"); 157 158 } else if (statcode < PJ_ERRNO_START + PJ_ERRNO_SPACE_SIZE) { 156 159 len = pj_ansi_snprintf( buf, bufsize, "Unknown error %d", statcode); 157 160
Note: See TracChangeset
for help on using the changeset viewer.