Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35eebbab authored by Andreas Huber's avatar Andreas Huber Committed by Android (Google) Code Review
Browse files

Merge "Add a user-agent header to our RTSP requests."

parents 654cf011 b0e7381c
Loading
Loading
Loading
Loading
+27 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,8 @@


#include "ARTSPConnection.h"
#include "ARTSPConnection.h"


#include <cutils/properties.h>

#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ABuffer.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/AMessage.h>
@@ -44,6 +46,7 @@ ARTSPConnection::ARTSPConnection()
      mConnectionID(0),
      mConnectionID(0),
      mNextCSeq(0),
      mNextCSeq(0),
      mReceiveResponseEventPending(false) {
      mReceiveResponseEventPending(false) {
    MakeUserAgent(&mUserAgent);
}
}


ARTSPConnection::~ARTSPConnection() {
ARTSPConnection::~ARTSPConnection() {
@@ -378,6 +381,7 @@ void ARTSPConnection::onSendRequest(const sp<AMessage> &msg) {
    reply->setString("original-request", request.c_str(), request.size());
    reply->setString("original-request", request.c_str(), request.size());


    addAuthentication(&request);
    addAuthentication(&request);
    addUserAgent(&request);


    // Find the boundary between headers and the body.
    // Find the boundary between headers and the body.
    ssize_t i = request.find("\r\n\r\n");
    ssize_t i = request.find("\r\n\r\n");
@@ -979,4 +983,27 @@ void ARTSPConnection::addAuthentication(AString *request) {
#endif
#endif
}
}


// static
void ARTSPConnection::MakeUserAgent(AString *userAgent) {
    userAgent->clear();
    userAgent->setTo("User-Agent: stagefright/1.1 (Linux;Android ");

#if (PROPERTY_VALUE_MAX < 8)
#error "PROPERTY_VALUE_MAX must be at least 8"
#endif

    char value[PROPERTY_VALUE_MAX];
    property_get("ro.build.version.release", value, "Unknown");
    userAgent->append(value);
    userAgent->append(")\r\n");
}

void ARTSPConnection::addUserAgent(AString *request) const {
    // Find the boundary between headers and the body.
    ssize_t i = request->find("\r\n\r\n");
    CHECK_GE(i, 0);

    request->insert(mUserAgent, i + 2);
}

}  // namespace android
}  // namespace android
+6 −0
Original line number Original line Diff line number Diff line
@@ -87,6 +87,8 @@ private:


    sp<AMessage> mObserveBinaryMessage;
    sp<AMessage> mObserveBinaryMessage;


    AString mUserAgent;

    void onConnect(const sp<AMessage> &msg);
    void onConnect(const sp<AMessage> &msg);
    void onDisconnect(const sp<AMessage> &msg);
    void onDisconnect(const sp<AMessage> &msg);
    void onCompleteConnection(const sp<AMessage> &msg);
    void onCompleteConnection(const sp<AMessage> &msg);
@@ -106,6 +108,8 @@ private:
    bool parseAuthMethod(const sp<ARTSPResponse> &response);
    bool parseAuthMethod(const sp<ARTSPResponse> &response);
    void addAuthentication(AString *request);
    void addAuthentication(AString *request);


    void addUserAgent(AString *request) const;

    status_t findPendingRequest(
    status_t findPendingRequest(
            const sp<ARTSPResponse> &response, ssize_t *index) const;
            const sp<ARTSPResponse> &response, ssize_t *index) const;


@@ -114,6 +118,8 @@ private:
    static bool ParseSingleUnsignedLong(
    static bool ParseSingleUnsignedLong(
            const char *from, unsigned long *x);
            const char *from, unsigned long *x);


    static void MakeUserAgent(AString *userAgent);

    DISALLOW_EVIL_CONSTRUCTORS(ARTSPConnection);
    DISALLOW_EVIL_CONSTRUCTORS(ARTSPConnection);
};
};