Repository: ossrs/srs
File: trunk/src/app/srs_app_gb28181_sip.cpp (C++)

Code before:
            return err;
        }
        
        // sip_session->set_sockaddr((sockaddr)*from);
        // sip_session->set_sockaddr_len(fromlen);

        if (sip_session->register_status() == SrsGb28181SipSessionUnkonw ||
            sip_session->alive_status() == SrsGb28181SipSessionUnkonw) {
            srs_trace("gb28181: %s client not registered or not alive", req->sip_auth_id.c_str());
            return err;
        }
        
        if (req->cmdtype == SrsSipCmdRespone){
            srs_trace("gb28181: INVITE response %s client status=%s", req->sip_auth_id.c_str(), req->status.c_str());

            if (req->status == "200") {
                srs_trace("gb28181: device unique id is %s@%s", sip_session->session_id().c_str(), req->sip_auth_id.c_str());
                send_ack(req, from, fromlen);
                SrsGb28181Device *device = sip_session->get_device_info(req->sip_auth_id);
                if (device){
                    device->invite_status = SrsGb28181SipSessionInviteOk;
                    device->req_inivate.copy(req);
                    device->invite_time = srs_get_system_time();
                }
                uint32_t ssrc_in_sdp = strtoul(srs_string_split(req->sdp_body_map["y"],",").at(0).c_str(), NULL, 10);//gb28181 protocol,sdp-type-y is the ssrc
                std::string sess_in_sdp = srs_string_split(srs_string_split(req->sdp_body_map["o"],",").at(0)," ").at(0);
                std::string chid_in_sdp = req->sip_auth_id;
                std::string channel_id_in_respond = sess_in_sdp+"@"+chid_in_sdp;//channel_id=sessid@chid
                srs_trace("gb28181: at the invite respond, the channel_id=%s",channel_id_in_respond.c_str());
                _srs_gb28181->update_ssrc_by_invite_respond(channel_id_in_respond,ssrc_in_sdp);

            }else if (req->status == "100") {
                //send_ack(req, from, fromlen);
                SrsGb28181Device *device = sip_session->get_device_info(req->sip_auth_id);
                if (device){
                    device->req_inivate.copy(req);
                    device->invite_status = SrsGb28181SipSessionTrying;
                    device->invite_time = srs_get_system_time();
                }
            }else{
                SrsGb28181Device *device = sip_session->get_device_info(req->sip_auth_id);
                if (device){
                    device->req_inivate.copy(req);
                    device->invite_status = SrsGb28181SipSessionUnkonw;
                    device->invite_time = srs_get_system_time();
                }
            }
        }
       
    }else if (req->is_bye()) {
        srs_trace("gb28181: request client id=%s, peer(%s, %d)", req->sip_auth_id.c_str(), 

Review comment (security):
sess_in_sdp and chid_in_sdp, retrieve them from the SIP signaling, they already exist.
sip_session->session_id()+"@"+req->sip_auth_id

`TRANS_BY_GPT3`

Code after:
        }
        
        // sip_session->set_sockaddr((sockaddr)*from);
        // sip_session->set_sockaddr_len(fromlen);

        if (sip_session->register_status() == SrsGb28181SipSessionUnkonw ||
            sip_session->alive_status() == SrsGb28181SipSessionUnkonw) {
            srs_trace("gb28181: %s client not registered or not alive", req->sip_auth_id.c_str());
            return err;
        }
        
        if (req->cmdtype == SrsSipCmdRespone){
            srs_trace("gb28181: INVITE response %s client status=%s", req->sip_auth_id.c_str(), req->status.c_str());

            if (req->status == "200") {
                srs_trace("gb28181: device unique id is %s@%s", sip_session->session_id().c_str(), req->sip_auth_id.c_str());
                // if srs is external realm, ssrc is generated by source realm rather than srs
                // so update ssrc to the y line in source realm '200 OK' response
                // actually, we should do this all the time
                if (req->y_ssrc != 0) {
                    _srs_gb28181->update_rtmpmuxer_to_newssrc_by_id(sip_session->session_id()+"@"+req->sip_auth_id, req->y_ssrc);
                    req->y_ssrc = 0;
                }
                send_ack(req, from, fromlen);
                SrsGb28181Device *device = sip_session->get_device_info(req->sip_auth_id);
                if (device){
                    device->invite_status = SrsGb28181SipSessionInviteOk;
                    device->req_inivate.copy(req);
                    device->invite_time = srs_get_system_time();
                }
            }else if (req->status == "100") {
                //send_ack(req, from, fromlen);
                SrsGb28181Device *device = sip_session->get_device_info(req->sip_auth_id);
                if (device){
                    device->req_inivate.copy(req);
                    device->invite_status = SrsGb28181SipSessionTrying;
                    device->invite_time = srs_get_system_time();
                }
            }else{
                SrsGb28181Device *device = sip_session->get_device_info(req->sip_auth_id);
                if (device){
                    device->req_inivate.copy(req);
                    device->invite_status = SrsGb28181SipSessionUnkonw;
                    device->invite_time = srs_get_system_time();
                }
            }
        }
       
    }else if (req->is_bye()) {
        srs_trace("gb28181: request client id=%s, peer(%s, %d)", req->sip_auth_id.c_str(), 
                        peer_ip.c_str(), peer_port);