Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
1 /*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
17 #ifndef A_RTSP_CONNECTION_H_
19 #define A_RTSP_CONNECTION_H_
21 #include <media/stagefright/foundation/AHandler.h>
22 #include <media/stagefright/foundation/AString.h>
24 namespace android {
26 struct ABuffer;
28 struct ARTSPResponse : public RefBase {
29 unsigned long mStatusCode;
30 AString mStatusLine;
31 KeyedVector<AString,AString> mHeaders;
32 sp<ABuffer> mContent;
33 };
35 struct ARTSPConnection : public AHandler {
36 ARTSPConnection(bool uidValid = false, uid_t uid = 0);
38 void connect(const char *url, const sp<AMessage> &reply);
39 void disconnect(const sp<AMessage> &reply);
41 void sendRequest(const char *request, const sp<AMessage> &reply);
43 void observeBinaryData(const sp<AMessage> &reply);
45 static bool ParseURL(
46 const char *url, AString *host, unsigned *port, AString *path,
47 AString *user, AString *pass);
49 protected:
50 virtual ~ARTSPConnection();
51 virtual void onMessageReceived(const sp<AMessage> &msg);
53 private:
54 enum State {
55 DISCONNECTED,
56 CONNECTING,
57 CONNECTED,
58 };
60 enum {
61 kWhatConnect = 'conn',
62 kWhatDisconnect = 'disc',
63 kWhatCompleteConnection = 'comc',
64 kWhatSendRequest = 'sreq',
65 kWhatReceiveResponse = 'rres',
66 kWhatObserveBinaryData = 'obin',
67 };
69 enum AuthType {
70 NONE,
71 BASIC,
72 DIGEST
73 };
75 static const int64_t kSelectTimeoutUs;
76 static const int64_t kSelectTimeoutRetries;
78 bool mUIDValid;
79 uid_t mUID;
80 State mState;
81 AString mUser, mPass;
82 AuthType mAuthType;
83 AString mNonce;
84 int mSocket;
85 int32_t mConnectionID;
86 int32_t mNextCSeq;
87 bool mReceiveResponseEventPending;
88 int64_t mNumSelectTimeoutRetries;
90 KeyedVector<int32_t, sp<AMessage> > mPendingRequests;
92 sp<AMessage> mObserveBinaryMessage;
94 AString mUserAgent;
96 void performDisconnect();
98 void onConnect(const sp<AMessage> &msg);
99 void onDisconnect(const sp<AMessage> &msg);
100 void onCompleteConnection(const sp<AMessage> &msg);
101 void onSendRequest(const sp<AMessage> &msg);
102 void onReceiveResponse();
104 void flushPendingRequests();
105 void postReceiveResponseEvent();
107 // Return false iff something went unrecoverably wrong.
108 bool receiveRTSPResponse();
109 status_t receive(void *data, size_t size);
110 bool receiveLine(AString *line);
111 sp<ABuffer> receiveBinaryData();
112 bool notifyResponseListener(const sp<ARTSPResponse> &response);
114 bool parseAuthMethod(const sp<ARTSPResponse> &response);
115 void addAuthentication(AString *request);
117 void addUserAgent(AString *request) const;
119 status_t findPendingRequest(
120 const sp<ARTSPResponse> &response, ssize_t *index) const;
122 bool handleServerRequest(const sp<ARTSPResponse> &request);
124 static bool ParseSingleUnsignedLong(
125 const char *from, unsigned long *x);
127 static void MakeUserAgent(AString *userAgent);
129 DISALLOW_EVIL_CONSTRUCTORS(ARTSPConnection);
130 };
132 } // namespace android
134 #endif // A_RTSP_CONNECTION_H_