Пример #1
0
void MythRAOPConnection::ProcessRequest(const QStringList &header,
                                        const QByteArray &content)
{
    if (header.isEmpty())
        return;

    RawHash tags = FindTags(header);

    if (!tags.contains("CSeq"))
    {
        LOG(VB_GENERAL, LOG_ERR, LOC + "ProcessRequest: Didn't find CSeq");
        return;
    }

    *m_textStream << "RTSP/1.0 200 OK\r\n";

    QString option = header[0].left(header[0].indexOf(" "));

    // process RTP-info field
    bool gotRTP = false;
    uint16_t RTPseq;
    uint64_t RTPtimestamp;
    if (tags.contains("RTP-Info"))
    {
        gotRTP = true;
        QString data = tags["RTP-Info"];
        QStringList items = data.split(";");
        foreach (QString item, items)
        {
            if (item.startsWith("seq"))
            {
                RTPseq = item.mid(item.indexOf("=") + 1).trimmed().toUShort();
            }
            else if (item.startsWith("rtptime"))
            {
                RTPtimestamp = item.mid(item.indexOf("=") + 1).trimmed().toUInt();
            }
        }
        LOG(VB_GENERAL, LOG_INFO, LOC + QString("RTP-Info: seq=%1 rtptime=%2")
            .arg(RTPseq).arg(RTPtimestamp));
    }
    void FixFile(const boost::filesystem::path& file)
    {
        std::cout<<"   -"<<file.filename()<<std::endl;

        std::string raw;
        {
            std::ostringstream tmp;
            std::ifstream is(file.string().c_str());
            tmp<<is.rdbuf();
            is.close();
            raw=tmp.str();
        }

        std::string subtree=file.string().substr(m_srcDir.string().size());
        boost::filesystem::path outFile=m_outDir/subtree;
        boost::filesystem::create_directories(outFile.parent_path());
        std::cout<<"  outfile: "<<outFile.string()<<std::endl;

        std::ofstream of(outFile.string().c_str(), std::ios::out);

        if (!of.is_open())
        {
            std::cout<<"Failed to open file "<<outFile.string()<<std::endl;
            exit(1);
        }

        std::vector< std::pair<size_t, size_t> > objects;
        FindTags(raw, objects);

        size_t index=0;
        for (size_t i=0; i<objects.size(); ++i)
        {
            while (index<objects[i].first)
            {
                of<<raw[index++];
            }


            std::string xmlSrc=raw.substr(objects[i].first, objects[i].second-objects[i].first);
            try
            {
                std::vector<char> blob;
                Safir::Dob::Typesystem::ToolSupport::XmlToBinary(m_rep.get(), xmlSrc.c_str(), blob);

                std::ostringstream xmlDest;
                Safir::Dob::Typesystem::ToolSupport::BinaryToXml(m_rep.get(), &blob[0], xmlDest);
                of<<xmlDest.str();

//                std::string xml=xmlDest.str();
//                if (boost::starts_with(xml, "<?xml")) //remove <?xml version="1.0" encoding="utf-8"?>
//                {
//                    of<<xml.substr(xml.find("?>")+2);

//                }
//                else
//                {
//                    of<<xmlDest.str();
//                }
            }
            catch (const Safir::Dob::Typesystem::ToolSupport::ParseError& err)
            {
                std::cout<<err.what()<<" while parsing: "<<std::endl<<xmlSrc<<std::endl;
                exit(1);
            }

            index=objects[i].second;
        }

        while (index<raw.size())
        {
            of<<raw[index++];
        }

        of.close();
    }