Changeset 1877 for pjproject/trunk/pjnath/src/pjturn-srv/allocation.c
- Timestamp:
- Mar 19, 2008 11:00:30 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjnath/src/pjturn-srv/allocation.c
r1854 r1877 73 73 const pj_uint8_t *pkt, 74 74 unsigned pkt_len, 75 const pj_stun_ msg *msg,75 const pj_stun_rx_data *rdata, 76 76 const pj_sockaddr_t *src_addr, 77 77 unsigned src_addr_len); … … 98 98 static pj_status_t parse_allocate_req(alloc_request *cfg, 99 99 pj_stun_session *sess, 100 const pj_stun_ msg *req,100 const pj_stun_rx_data *rdata, 101 101 const pj_sockaddr_t *src_addr, 102 102 unsigned src_addr_len) 103 103 { 104 const pj_stun_msg *req = rdata->msg; 104 105 pj_stun_bandwidth_attr *attr_bw; 105 106 pj_stun_req_transport_attr *attr_req_tp; … … 121 122 /* Check if we can satisfy the bandwidth */ 122 123 if (cfg->bandwidth > MAX_CLIENT_BANDWIDTH) { 123 pj_stun_session_respond(sess, req, PJ_STUN_SC_ALLOCATION_QUOTA_REACHED, 124 pj_stun_session_respond(sess, rdata, 125 PJ_STUN_SC_ALLOCATION_QUOTA_REACHED, 124 126 "Invalid bandwidth", PJ_TRUE, 125 127 src_addr, src_addr_len); … … 131 133 pj_stun_msg_find_attr(req, PJ_STUN_ATTR_REQ_TRANSPORT, 0); 132 134 if (attr_req_tp == NULL) { 133 pj_stun_session_respond(sess, r eq, PJ_STUN_SC_BAD_REQUEST,135 pj_stun_session_respond(sess, rdata, PJ_STUN_SC_BAD_REQUEST, 134 136 "Missing REQUESTED-TRANSPORT attribute", 135 137 PJ_TRUE, src_addr, src_addr_len); … … 141 143 /* Can only support UDP for now */ 142 144 if (cfg->tp_type != PJ_TURN_TP_UDP) { 143 pj_stun_session_respond(sess, r eq, PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO,145 pj_stun_session_respond(sess, rdata, PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO, 144 146 NULL, PJ_TRUE, src_addr, src_addr_len); 145 147 return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO); … … 152 154 if (attr_res_token) { 153 155 /* We don't support RESERVATION-TOKEN for now */ 154 pj_stun_session_respond(sess, r eq,156 pj_stun_session_respond(sess, rdata, 155 157 PJ_STUN_SC_BAD_REQUEST, 156 158 "RESERVATION-TOKEN is not supported", PJ_TRUE, … … 164 166 if (attr_rpp) { 165 167 /* We don't support REQUESTED-PROPS for now */ 166 pj_stun_session_respond(sess, r eq,168 pj_stun_session_respond(sess, rdata, 167 169 PJ_STUN_SC_BAD_REQUEST, 168 170 "REQUESTED-PROPS is not supported", PJ_TRUE, … … 177 179 cfg->lifetime = attr_lifetime->value; 178 180 if (cfg->lifetime < MIN_LIFETIME) { 179 pj_stun_session_respond(sess, r eq, PJ_STUN_SC_BAD_REQUEST,181 pj_stun_session_respond(sess, rdata, PJ_STUN_SC_BAD_REQUEST, 180 182 "LIFETIME too short", PJ_TRUE, 181 183 src_addr, src_addr_len); … … 195 197 static pj_status_t send_allocate_response(pj_turn_allocation *alloc, 196 198 pj_stun_session *srv_sess, 197 const pj_stun_ msg *msg)199 const pj_stun_rx_data *rdata) 198 200 { 199 201 pj_stun_tx_data *tdata; … … 201 203 202 204 /* Respond the original ALLOCATE request */ 203 status = pj_stun_session_create_res(srv_sess, msg, 0, NULL, &tdata);205 status = pj_stun_session_create_res(srv_sess, rdata, 0, NULL, &tdata); 204 206 if (status != PJ_SUCCESS) 205 207 return status; … … 285 287 const pj_sockaddr_t *src_addr, 286 288 unsigned src_addr_len, 287 const pj_stun_ msg *msg,289 const pj_stun_rx_data *rdata, 288 290 pj_stun_session *srv_sess, 289 291 pj_turn_allocation **p_alloc) 290 292 { 291 293 pj_turn_srv *srv = listener->server; 294 const pj_stun_msg *msg = rdata->msg; 292 295 pj_pool_t *pool; 293 296 alloc_request req; … … 298 301 299 302 /* Parse ALLOCATE request */ 300 status = parse_allocate_req(&req, srv_sess, msg, src_addr, src_addr_len);303 status = parse_allocate_req(&req, srv_sess, rdata, src_addr, src_addr_len); 301 304 if (status != PJ_SUCCESS) 302 305 return status; … … 355 358 356 359 /* Attach authentication credential to STUN session */ 357 pj_stun_session_set_credential(alloc->sess, &alloc->cred); 360 pj_stun_session_set_credential(alloc->sess, PJ_STUN_AUTH_LONG_TERM, 361 &alloc->cred); 358 362 359 363 /* Create the relay resource */ … … 367 371 368 372 /* Respond to ALLOCATE request */ 369 status = send_allocate_response(alloc, srv_sess, msg);373 status = send_allocate_response(alloc, srv_sess, rdata); 370 374 if (status != PJ_SUCCESS) 371 375 goto on_error; … … 384 388 /* Send reply to the ALLOCATE request */ 385 389 pj_strerror(status, str_tmp, sizeof(str_tmp)); 386 pj_stun_session_respond(srv_sess, msg, PJ_STUN_SC_BAD_REQUEST, str_tmp,390 pj_stun_session_respond(srv_sess, rdata, PJ_STUN_SC_BAD_REQUEST, str_tmp, 387 391 PJ_TRUE, src_addr, src_addr_len); 388 392 … … 710 714 /* Create and send error response */ 711 715 static void send_reply_err(pj_turn_allocation *alloc, 712 const pj_stun_ msg *req,716 const pj_stun_rx_data *rdata, 713 717 pj_bool_t cache, 714 718 int code, const char *errmsg) … … 716 720 pj_status_t status; 717 721 718 status = pj_stun_session_respond(alloc->sess, r eq, code, errmsg, cache,722 status = pj_stun_session_respond(alloc->sess, rdata, code, errmsg, cache, 719 723 &alloc->hkey.clt_addr, 720 724 pj_sockaddr_get_len(&alloc->hkey.clt_addr.addr)); … … 727 731 /* Create and send successful response */ 728 732 static void send_reply_ok(pj_turn_allocation *alloc, 729 const pj_stun_ msg *req)733 const pj_stun_rx_data *rdata) 730 734 { 731 735 pj_status_t status; … … 733 737 pj_stun_tx_data *tdata; 734 738 735 status = pj_stun_session_create_res(alloc->sess, r eq, 0, NULL, &tdata);739 status = pj_stun_session_create_res(alloc->sess, rdata, 0, NULL, &tdata); 736 740 if (status != PJ_SUCCESS) { 737 741 alloc_err(alloc, "Error creating STUN success response", status); … … 1073 1077 const pj_uint8_t *pkt, 1074 1078 unsigned pkt_len, 1075 const pj_stun_ msg *msg,1079 const pj_stun_rx_data *rdata, 1076 1080 const pj_sockaddr_t *src_addr, 1077 1081 unsigned src_addr_len) 1078 1082 { 1083 const pj_stun_msg *msg = rdata->msg; 1079 1084 pj_turn_allocation *alloc; 1080 1085 … … 1089 1094 if (alloc->relay.lifetime == 0) { 1090 1095 /* Reject with 437 if we're shutting down */ 1091 send_reply_err(alloc, msg, PJ_TRUE,1096 send_reply_err(alloc, rdata, PJ_TRUE, 1092 1097 PJ_STUN_SC_ALLOCATION_MISMATCH, NULL); 1093 1098 return PJ_SUCCESS; … … 1116 1121 1117 1122 /* Respond first */ 1118 send_reply_ok(alloc, msg);1123 send_reply_ok(alloc, rdata); 1119 1124 1120 1125 /* Shutdown allocation */ … … 1142 1147 1143 1148 /* Send reply */ 1144 send_reply_ok(alloc, msg);1149 send_reply_ok(alloc, rdata); 1145 1150 } 1146 1151 … … 1159 1164 1160 1165 if (!ch_attr || !peer_attr) { 1161 send_reply_err(alloc, msg, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST, NULL); 1166 send_reply_err(alloc, rdata, PJ_TRUE, 1167 PJ_STUN_SC_BAD_REQUEST, NULL); 1162 1168 return PJ_SUCCESS; 1163 1169 } … … 1172 1178 if (pj_sockaddr_cmp(&p1->hkey.peer_addr, &peer_attr->sockaddr)) { 1173 1179 /* Address mismatch. Send 400 */ 1174 send_reply_err(alloc, msg, PJ_TRUE,1180 send_reply_err(alloc, rdata, PJ_TRUE, 1175 1181 PJ_STUN_SC_BAD_REQUEST, 1176 1182 "Peer address mismatch"); … … 1191 1197 pj_sockaddr_get_len(&peer_attr->sockaddr)); 1192 1198 if (p2 && p2->channel != PJ_TURN_INVALID_CHANNEL) { 1193 send_reply_err(alloc, msg, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST,1199 send_reply_err(alloc, rdata, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST, 1194 1200 "Peer address already assigned a channel number"); 1195 1201 return PJ_SUCCESS; … … 1211 1217 1212 1218 /* Reply */ 1213 send_reply_ok(alloc, msg);1219 send_reply_ok(alloc, rdata); 1214 1220 1215 1221 return PJ_SUCCESS; … … 1218 1224 1219 1225 /* Respond with 437 (section 6.3 turn-07) */ 1220 send_reply_err(alloc, msg, PJ_TRUE, PJ_STUN_SC_ALLOCATION_MISMATCH, NULL); 1226 send_reply_err(alloc, rdata, PJ_TRUE, PJ_STUN_SC_ALLOCATION_MISMATCH, 1227 NULL); 1221 1228 1222 1229 } else { 1223 1230 1224 1231 /* Respond with Bad Request? */ 1225 send_reply_err(alloc, msg, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST, NULL);1232 send_reply_err(alloc, rdata, PJ_TRUE, PJ_STUN_SC_BAD_REQUEST, NULL); 1226 1233 1227 1234 }
Note: See TracChangeset
for help on using the changeset viewer.