EasyRelaySession::EasyRelaySession(char* inURL, ClientType inClientType, const char* streamName, const char *inServerAddr)
:   fStreamName(NULL),
	fURL(NULL),
	fPushServerAddr(NULL),
	fRTSPClientHandle(NULL),
	fPusherHandle(NULL)
{
    this->SetTaskName("EasyRelaySession");

	//建立RTSPClient
    StrPtrLen theURL(inURL);

	fURL = NEW char[::strlen(inURL) + 2];
	::memset(fURL, 0 ,::strlen(inURL) + 2);

	::strcpy(fURL, inURL);

	if (streamName != NULL)
    {
		fStreamName.Ptr = NEW char[strlen(streamName) + 1];
		::memset(fStreamName.Ptr,0,strlen(streamName) + 1);
		::memcpy(fStreamName.Ptr, streamName, strlen(streamName));

		fStreamName.Len = strlen(streamName);
		fStreamName.Ptr[fStreamName.Len] = '\0';

		fRef.Set(fStreamName, this);
    }
Exemple #2
0
BinInputStreamType*
XSLTInputSource::makeStream() const
{
    BinInputStreamType*     theResult = 0;

    MemoryManager*  theManager = getMemoryManager();

    assert(theManager != 0 );

    if (m_stream != 0)
    {
        
        theResult = new (theManager) StdBinInputStream(*m_stream);
    }
    else if (m_node == 0)
    {
        const XalanDOMChar* const   theSystemId = getSystemId();

        if (theSystemId != 0)
        {
            XALAN_USING_XERCES(XMLURL)

            XMLURL  theURL(theManager);

            URISupport::getURLFromString(theSystemId, theURL, *theManager);

            theResult = theURL.makeNewStream();
        }
    }

    return theResult;
}
RTSPRelaySession::RTSPRelaySession(char* inURL, ClientType inClientType, UInt32 inOptionsIntervalInSec, 
								   Bool16 sendOptions, const char* streamName)
:   fLive555Client(NULL),
    //fTimeoutTask(this, 20000),
	fLive555LoopThread(NULL),
    fOptionsIntervalInSec(inOptionsIntervalInSec),
    
    fOptions(sendOptions),

	fReflectorSession(NULL),
	fStreamName(NULL),
	fURL(NULL)
{
    this->SetTaskName("RTSPRelaySession");

	//建立live555线程
	TaskScheduler* scheduler = BasicTaskScheduler::createNew();
	UsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler);

	fLive555LoopThread = NEW live555Thread(scheduler, env);
	fLive555Client = (QTSS_Object)easyRTSPClient::createNew(*env, inURL, this, inClientType);


    StrPtrLen theURL(inURL);

	fURL = NEW char[::strlen(inURL) + 2];
	::strcpy(fURL, inURL);

	if (streamName != NULL)
    {
		fStreamName.Ptr = NEW char[strlen(streamName) + 1];
		::memset(fStreamName.Ptr,0,strlen(streamName) + 1);
		::memcpy(fStreamName.Ptr, streamName, strlen(streamName));
		fStreamName.Len = strlen(streamName);
		fRef.Set(fStreamName, this);
    }
Exemple #4
0
//virtual
void MTAssetDetails::AddButtonClicked()
{
    MTWizardAddContract theWizard(this);

    theWizard.setWindowTitle(tr("Add Asset Contract"));

    QString qstrDefaultValue("https://raw.github.com/FellowTraveler/Open-Transactions/master/sample-data/sample-contracts/btc.otc");
    QVariant varDefault(qstrDefaultValue);

    theWizard.setField(QString("URL"), varDefault);

    if (QDialog::Accepted == theWizard.exec())
    {
        bool bIsImporting = theWizard.field("isImporting").toBool();
        bool bIsCreating  = theWizard.field("isCreating").toBool();

        if (bIsImporting)
        {
            bool bIsURL      = theWizard.field("isURL").toBool();
            bool bIsFilename = theWizard.field("isFilename").toBool();
            bool bIsContents = theWizard.field("isContents").toBool();

            if (bIsURL)
            {
                QString qstrURL = theWizard.field("URL").toString();
                // --------------------------------
                if (qstrURL.isEmpty())
                {
                    QMessageBox::warning(this, tr("URL is Empty"),
                        tr("No URL was provided."));

                    return;
                }

                QUrl theURL(qstrURL);
                // --------------------------------
                if (m_pDownloader)
                {
                    m_pDownloader->deleteLater();
                    m_pDownloader = NULL;
                }
                // --------------------------------
                m_pDownloader = new FileDownloader(theURL, this);

                connect(m_pDownloader, SIGNAL(downloaded()), SLOT(DownloadedURL()));
            }
            // --------------------------------
            else if (bIsFilename)
            {
                QString fileName = theWizard.field("Filename").toString();

                if (fileName.isEmpty())
                {
                    QMessageBox::warning(this, tr("Filename is Empty"),
                        tr("No filename was provided."));

                    return;
                }
                // -----------------------------------------------
                QString qstrContents;
                QFile plainFile(fileName);

                if (plainFile.open(QIODevice::ReadOnly))//| QIODevice::Text)) // Text flag translates /n/r to /n
                {
                    QTextStream in(&plainFile); // Todo security: check filesize here and place a maximum size.
                    qstrContents = in.readAll();

                    plainFile.close();
                    // ----------------------------
                    if (qstrContents.isEmpty())
                    {
                        QMessageBox::warning(this, tr("File Was Empty"),
                                             QString("%1: %2").arg(tr("File was apparently empty")).arg(fileName));
                        return;
                    }
                    // ----------------------------
                }
                else
                {
                    QMessageBox::warning(this, tr("Failed Reading File"),
                                         QString("%1: %2").arg(tr("Failed trying to read file")).arg(fileName));
                    return;
                }
                // -----------------------------------------------
                ImportContract(qstrContents);
            }
            // --------------------------------
            else if (bIsContents)
            {
                QString qstrContents = theWizard.getContents();

                if (qstrContents.isEmpty())
                {
                    QMessageBox::warning(this, tr("Empty Contract"),
                        tr("Failure Importing: Contract is Empty."));
                    return;
                }
                // -------------------------
                ImportContract(qstrContents);
            }
        }
        // --------------------------------
        else if (bIsCreating)
        {
            // Todo
        }
    }
}
//virtual
void MTAssetDetails::AddButtonClicked()
{
    MTWizardAddContract theWizard(this);

    theWizard.setWindowTitle(tr("Add Asset Contract"));

    QString qstrDefaultValue("https://raw.github.com/FellowTraveler/Open-Transactions/master/sample-data/sample-contracts/btc.otc");
    QVariant varDefault(qstrDefaultValue);

    theWizard.setField(QString("URL"), varDefault);
    theWizard.setField(QString("contractType"), QString("asset")); // So the wizard knows it's creating an asset contract.

    QString qstrDefaultContract(
                "<instrumentDefinition version=\"2.0\">\n"
                "\n"
                "<entity shortname=\"Fed\"\n"
                " longname=\"The Rothschilds\"\n"
                " email=\"[email protected]\"/>\n"
                        "\n"
                "<issue company=\"Federal Reserve, a private company\"\n"
                " email=\"[email protected]\"\n"
                " contractUrl=\"https://fed.gov/sucker\"\n"
                " type=\"currency\"/>\n"
                       "\n"
                "<currency name=\"US Dollars\" tla=\"USD\" symbol=\"$\" type=\"decimal\" factor=\"100\" decimalPower=\"2\" fraction=\"cents\"/>\n"
                                "\n"
                "</instrumentDefinition>\n"
    );

    theWizard.setField(QString("contractXML"), qstrDefaultContract);

    if (QDialog::Accepted == theWizard.exec())
    {
        bool bIsImporting = theWizard.field("isImporting").toBool();
        bool bIsCreating  = theWizard.field("isCreating").toBool();

        if (bIsImporting)
        {
            bool bIsURL      = theWizard.field("isURL").toBool();
            bool bIsFilename = theWizard.field("isFilename").toBool();
            bool bIsContents = theWizard.field("isContents").toBool();

            if (bIsURL)
            {
                QString qstrURL = theWizard.field("URL").toString();
                // --------------------------------
                if (qstrURL.isEmpty())
                {
                    QMessageBox::warning(this, tr("URL is Empty"),
                        tr("No URL was provided."));

                    return;
                }

                QUrl theURL(qstrURL);
                // --------------------------------
                if (m_pDownloader)
                {
                    m_pDownloader->deleteLater();
                    m_pDownloader = NULL;
                }
                // --------------------------------
                m_pDownloader = new FileDownloader(theURL, this);

                connect(m_pDownloader, SIGNAL(downloaded()), SLOT(DownloadedURL()));
            }
            // --------------------------------
            else if (bIsFilename)
            {
                QString fileName = theWizard.field("Filename").toString();

                if (fileName.isEmpty())
                {
                    QMessageBox::warning(this, tr("Filename is Empty"),
                        tr("No filename was provided."));

                    return;
                }
                // -----------------------------------------------
                QString qstrContents;
                QFile plainFile(fileName);

                if (plainFile.open(QIODevice::ReadOnly))//| QIODevice::Text)) // Text flag translates /n/r to /n
                {
                    QTextStream in(&plainFile); // Todo security: check filesize here and place a maximum size.
                    qstrContents = in.readAll();

                    plainFile.close();
                    // ----------------------------
                    if (qstrContents.isEmpty())
                    {
                        QMessageBox::warning(this, tr("File Was Empty"),
                                             QString("%1: %2").arg(tr("File was apparently empty")).arg(fileName));
                        return;
                    }
                    // ----------------------------
                }
                else
                {
                    QMessageBox::warning(this, tr("Failed Reading File"),
                                         QString("%1: %2").arg(tr("Failed trying to read file")).arg(fileName));
                    return;
                }
                // -----------------------------------------------
                ImportContract(qstrContents);
            }
            // --------------------------------
            else if (bIsContents)
            {
                QString qstrContents = theWizard.getContents();

                if (qstrContents.isEmpty())
                {
                    QMessageBox::warning(this, tr("Empty Contract"),
                        tr("Failure Importing: Contract is Empty."));
                    return;
                }
                // -------------------------
                ImportContract(qstrContents);
            }
        }
        // --------------------------------
        else if (bIsCreating)
        {
            QString qstrXMLContents = theWizard.field("contractXML").toString();
            QString qstrNymID       = theWizard.field("NymID").toString();

            std::string strContractID = opentxs::OTAPI_Wrap::It()->CreateAssetContract(qstrNymID.toStdString(),
                                                                                       qstrXMLContents.toStdString());

            if ("" == strContractID) {
                QMessageBox::warning(this, tr("Failed Creating Contract"),
                                     tr("Unable to create contract. Perhaps the XML contents were bad?"));
                return;
            }
            else {
                std::string strNewContract = opentxs::OTAPI_Wrap::It()->GetAssetType_Contract(strContractID);

                if ("" == strNewContract) {
                    QMessageBox::warning(this, tr("Unable to Load"),
                                         tr("While the contract was apparently created, Moneychanger is unable to load it up. (Strange.)"));
                    return;
                }
                else { // Success.
                    QString qstrContractID   = QString::fromStdString(strContractID);
                    QString qstrContractName = QString::fromStdString(opentxs::OTAPI_Wrap::It()->GetAssetType_Name(strContractID));

                    m_pOwner->m_map.insert(qstrContractID,
                                           qstrContractName);
                    m_pOwner->SetPreSelected(qstrContractID);
                    // ------------------------------------------------
                    emit newAssetAdded(qstrContractID);
                    return;
                }
            }
        }
    }
}
BroadcasterSession::BroadcasterSession( UInt32 inAddr, UInt16 inPort, char* inURL,
                                BroadcasterType inClientType,
                                UInt32 inDurationInSec, UInt32 inStartPlayTimeInSec,
                                UInt32 inRTCPIntervalInSec, UInt32 inOptionsIntervalInSec,
                                UInt32 inHTTPCookie, Bool16 inAppendJunkData, UInt32 inReadInterval,
                                UInt32 inSockRcvBufSize,
                                StrPtrLen *sdpSPLPtr,
                                char *namePtr,
                                char *passwordPtr,
                                Bool16  deepDebug,
                                Bool16 burst)
:   fSocket(NULL),
    fRTSPClient(NULL),
    fTimeoutTask(NULL, kIdleTimeoutInMsec),

    fDurationInSec(inDurationInSec),
    fStartPlayTimeInSec(inStartPlayTimeInSec),
    fRTCPIntervalInSec(inRTCPIntervalInSec),
    fOptionsIntervalInSec(inOptionsIntervalInSec),
    
    fState(kSendingAnnounce),
    fDeathState(kSendingAnnounce),
    fDeathReason(kDiedNormally),
    fNumSetups(0),
    fUDPSocketArray(NULL),
    
    fPlayTime(0),
    fTotalPlayTime(0),
    fLastRTCPTime(0),
    fTeardownImmediately(false),
    fAppendJunk(inAppendJunkData),
    fReadInterval(inReadInterval),
    fSockRcvBufSize(inSockRcvBufSize),
    fBurst(burst),
    fBurstTime(10),
    fStats(NULL),
    fPacketLen(0),
    fChannel(0)
//  fPacket(NULL)

{
    fTimeoutTask.SetTask(this);
    StrPtrLen theURL(inURL);
    fSDPParser.Parse(sdpSPLPtr->Ptr, sdpSPLPtr->Len);
    if (fBurst && deepDebug)
        printf("Burst Mode enabled: broadcast will be delayed for %"_U32BITARG_" seconds before starting\n", fBurstTime);
        
#if BROADCAST_SESSION_DEBUG

    qtss_printf("Connecting to: %s, port %d\n", inURL, inPort);

#endif  
    //
    // Construct the appropriate ClientSocket type depending on what type of client we are supposed to be
    switch (inClientType)
    {
        case kRTSPUDPBroadcasterType:
        {
            fControlType = kRawRTSPControlType;
            fTransportType = kUDPTransportType;
            fSocket = NEW TCPClientSocket(Socket::kNonBlockingSocketType);
            break;
        }
        case kRTSPTCPBroadcasterType:
        {
            fControlType = kRawRTSPControlType;
            fTransportType = kTCPTransportType;
            fSocket = NEW TCPClientSocket(Socket::kNonBlockingSocketType);
            break;
        }
        case kRTSPHTTPBroadcasterType:
        {
            fControlType = kRTSPHTTPControlType;
            fTransportType = kTCPTransportType;
            fSocket = NEW HTTPClientSocket(theURL, inHTTPCookie, Socket::kNonBlockingSocketType);
            break;
        }
        case kRTSPHTTPDropPostBroadcasterType:
        {
            fControlType = kRTSPHTTPDropPostControlType;
            fTransportType = kTCPTransportType;
            fSocket = NEW HTTPClientSocket(theURL, inHTTPCookie, Socket::kNonBlockingSocketType);
            break;
        }
        case kRTSPReliableUDPBroadcasterType:
        {
            Assert(0);
            break;
        }
        default:
        {
            qtss_printf("BroadcasterSession: Attempt to create unsupported client type.\n");
            ::exit(-1);
        }
    }
    
    fSocket->Set(inAddr, inPort);
    fSocket->GetSocket()->SetTask(this);

    int sndBufSize = 32 * 1024;
    int rcvBufSize=1024;
    ((TCPClientSocket*)fSocket)->SetOptions(sndBufSize,rcvBufSize);
    //
    // Construct the client object using this socket.
    Bool16 verbose = deepDebug;
    fRTSPClient = NEW RTSPClient(fSocket, verbose);
    fRTSPClient->Set(theURL);
    fRTSPClient->SetTransportMode(RTSPClient::kPushMode);
    fRTSPClient->SetName(namePtr);
    fRTSPClient->SetPassword(passwordPtr);

    //
    // Start the connection process going
    this->Signal(Task::kStartEvent);
}