Ignore:
Timestamp:
Mar 19, 2008 11:00:30 PM (16 years ago)
Author:
bennylp
Message:

Related to ticket #485: huge changeset to update STUN relating to managing authentication. See the ticket for the details

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/src/pjturn-srv/allocation.c

    r1854 r1877  
    7373                                      const pj_uint8_t *pkt, 
    7474                                      unsigned pkt_len, 
    75                                       const pj_stun_msg *msg, 
     75                                      const pj_stun_rx_data *rdata, 
    7676                                      const pj_sockaddr_t *src_addr, 
    7777                                      unsigned src_addr_len); 
     
    9898static pj_status_t parse_allocate_req(alloc_request *cfg, 
    9999                                      pj_stun_session *sess, 
    100                                       const pj_stun_msg *req, 
     100                                      const pj_stun_rx_data *rdata, 
    101101                                      const pj_sockaddr_t *src_addr, 
    102102                                      unsigned src_addr_len) 
    103103{ 
     104    const pj_stun_msg *req = rdata->msg; 
    104105    pj_stun_bandwidth_attr *attr_bw; 
    105106    pj_stun_req_transport_attr *attr_req_tp; 
     
    121122    /* Check if we can satisfy the bandwidth */ 
    122123    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, 
    124126                                "Invalid bandwidth", PJ_TRUE, 
    125127                                src_addr, src_addr_len); 
     
    131133                  pj_stun_msg_find_attr(req, PJ_STUN_ATTR_REQ_TRANSPORT, 0); 
    132134    if (attr_req_tp == NULL) { 
    133         pj_stun_session_respond(sess, req, PJ_STUN_SC_BAD_REQUEST, 
     135        pj_stun_session_respond(sess, rdata, PJ_STUN_SC_BAD_REQUEST, 
    134136                                "Missing REQUESTED-TRANSPORT attribute",  
    135137                                PJ_TRUE, src_addr, src_addr_len); 
     
    141143    /* Can only support UDP for now */ 
    142144    if (cfg->tp_type != PJ_TURN_TP_UDP) { 
    143         pj_stun_session_respond(sess, req, PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO, 
     145        pj_stun_session_respond(sess, rdata, PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO, 
    144146                                NULL, PJ_TRUE, src_addr, src_addr_len); 
    145147        return PJ_STATUS_FROM_STUN_CODE(PJ_STUN_SC_UNSUPP_TRANSPORT_PROTO); 
     
    152154    if (attr_res_token) { 
    153155        /* We don't support RESERVATION-TOKEN for now */ 
    154         pj_stun_session_respond(sess, req,  
     156        pj_stun_session_respond(sess, rdata,  
    155157                                PJ_STUN_SC_BAD_REQUEST, 
    156158                                "RESERVATION-TOKEN is not supported", PJ_TRUE,  
     
    164166    if (attr_rpp) { 
    165167        /* We don't support REQUESTED-PROPS for now */ 
    166         pj_stun_session_respond(sess, req,  
     168        pj_stun_session_respond(sess, rdata,  
    167169                                PJ_STUN_SC_BAD_REQUEST, 
    168170                                "REQUESTED-PROPS is not supported", PJ_TRUE,  
     
    177179        cfg->lifetime = attr_lifetime->value; 
    178180        if (cfg->lifetime < MIN_LIFETIME) { 
    179             pj_stun_session_respond(sess, req, PJ_STUN_SC_BAD_REQUEST, 
     181            pj_stun_session_respond(sess, rdata, PJ_STUN_SC_BAD_REQUEST, 
    180182                                    "LIFETIME too short", PJ_TRUE,  
    181183                                    src_addr, src_addr_len); 
     
    195197static pj_status_t send_allocate_response(pj_turn_allocation *alloc, 
    196198                                          pj_stun_session *srv_sess, 
    197                                           const pj_stun_msg *msg) 
     199                                          const pj_stun_rx_data *rdata) 
    198200{ 
    199201    pj_stun_tx_data *tdata; 
     
    201203 
    202204    /* 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); 
    204206    if (status != PJ_SUCCESS) 
    205207        return status; 
     
    285287                                              const pj_sockaddr_t *src_addr, 
    286288                                              unsigned src_addr_len, 
    287                                               const pj_stun_msg *msg, 
     289                                              const pj_stun_rx_data *rdata, 
    288290                                              pj_stun_session *srv_sess, 
    289291                                              pj_turn_allocation **p_alloc) 
    290292{ 
    291293    pj_turn_srv *srv = listener->server; 
     294    const pj_stun_msg *msg = rdata->msg; 
    292295    pj_pool_t *pool; 
    293296    alloc_request req; 
     
    298301 
    299302    /* 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); 
    301304    if (status != PJ_SUCCESS) 
    302305        return status; 
     
    355358 
    356359    /* 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); 
    358362 
    359363    /* Create the relay resource */ 
     
    367371 
    368372    /* Respond to ALLOCATE request */ 
    369     status = send_allocate_response(alloc, srv_sess, msg); 
     373    status = send_allocate_response(alloc, srv_sess, rdata); 
    370374    if (status != PJ_SUCCESS) 
    371375        goto on_error; 
     
    384388    /* Send reply to the ALLOCATE request */ 
    385389    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,  
    387391                            PJ_TRUE, src_addr, src_addr_len); 
    388392 
     
    710714/* Create and send error response */ 
    711715static void send_reply_err(pj_turn_allocation *alloc, 
    712                            const pj_stun_msg *req, 
     716                           const pj_stun_rx_data *rdata, 
    713717                           pj_bool_t cache,  
    714718                           int code, const char *errmsg) 
     
    716720    pj_status_t status; 
    717721 
    718     status = pj_stun_session_respond(alloc->sess, req, code, errmsg, cache, 
     722    status = pj_stun_session_respond(alloc->sess, rdata, code, errmsg, cache, 
    719723                                     &alloc->hkey.clt_addr, 
    720724                                     pj_sockaddr_get_len(&alloc->hkey.clt_addr.addr)); 
     
    727731/* Create and send successful response */ 
    728732static void send_reply_ok(pj_turn_allocation *alloc, 
    729                           const pj_stun_msg *req) 
     733                          const pj_stun_rx_data *rdata) 
    730734{ 
    731735    pj_status_t status; 
     
    733737    pj_stun_tx_data *tdata; 
    734738 
    735     status = pj_stun_session_create_res(alloc->sess, req, 0, NULL, &tdata); 
     739    status = pj_stun_session_create_res(alloc->sess, rdata, 0, NULL, &tdata); 
    736740    if (status != PJ_SUCCESS) { 
    737741        alloc_err(alloc, "Error creating STUN success response", status); 
     
    10731077                                      const pj_uint8_t *pkt, 
    10741078                                      unsigned pkt_len, 
    1075                                       const pj_stun_msg *msg, 
     1079                                      const pj_stun_rx_data *rdata, 
    10761080                                      const pj_sockaddr_t *src_addr, 
    10771081                                      unsigned src_addr_len) 
    10781082{ 
     1083    const pj_stun_msg *msg = rdata->msg; 
    10791084    pj_turn_allocation *alloc; 
    10801085 
     
    10891094    if (alloc->relay.lifetime == 0) { 
    10901095        /* Reject with 437 if we're shutting down */ 
    1091         send_reply_err(alloc, msg, PJ_TRUE,  
     1096        send_reply_err(alloc, rdata, PJ_TRUE,  
    10921097                       PJ_STUN_SC_ALLOCATION_MISMATCH, NULL); 
    10931098        return PJ_SUCCESS; 
     
    11161121 
    11171122            /* Respond first */ 
    1118             send_reply_ok(alloc, msg); 
     1123            send_reply_ok(alloc, rdata); 
    11191124 
    11201125            /* Shutdown allocation */ 
     
    11421147 
    11431148            /* Send reply */ 
    1144             send_reply_ok(alloc, msg); 
     1149            send_reply_ok(alloc, rdata); 
    11451150        } 
    11461151 
     
    11591164 
    11601165        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); 
    11621168            return PJ_SUCCESS; 
    11631169        } 
     
    11721178            if (pj_sockaddr_cmp(&p1->hkey.peer_addr, &peer_attr->sockaddr)) { 
    11731179                /* Address mismatch. Send 400 */ 
    1174                 send_reply_err(alloc, msg, PJ_TRUE,  
     1180                send_reply_err(alloc, rdata, PJ_TRUE,  
    11751181                               PJ_STUN_SC_BAD_REQUEST,  
    11761182                               "Peer address mismatch"); 
     
    11911197                                       pj_sockaddr_get_len(&peer_attr->sockaddr)); 
    11921198        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,  
    11941200                           "Peer address already assigned a channel number"); 
    11951201            return PJ_SUCCESS; 
     
    12111217 
    12121218        /* Reply */ 
    1213         send_reply_ok(alloc, msg); 
     1219        send_reply_ok(alloc, rdata); 
    12141220 
    12151221        return PJ_SUCCESS; 
     
    12181224 
    12191225        /* 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); 
    12211228 
    12221229    } else { 
    12231230 
    12241231        /* 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); 
    12261233 
    12271234    } 
Note: See TracChangeset for help on using the changeset viewer.