• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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  */
16 
17 #ifndef HTTP_STREAM_H_
18 
19 #define HTTP_STREAM_H_
20 
21 #include <sys/types.h>
22 
23 #include <media/stagefright/MediaErrors.h>
24 #include <media/stagefright/stagefright_string.h>
25 #include <utils/KeyedVector.h>
26 
27 namespace android {
28 
29 class HTTPStream {
30 public:
31     HTTPStream();
32     ~HTTPStream();
33 
34     status_t connect(const char *server, int port = 80);
35     status_t disconnect();
36 
37     status_t send(const char *data, size_t size);
38 
39     // Assumes data is a '\0' terminated string.
40     status_t send(const char *data);
41 
42     // Receive up to "size" bytes of data.
43     ssize_t receive(void *data, size_t size);
44 
45     status_t receive_header(int *http_status);
46 
47     // The header key used to retrieve the status line.
48     static const char *kStatusKey;
49 
50     bool find_header_value(
51             const string &key, string *value) const;
52 
53 private:
54     enum State {
55         READY,
56         CONNECTED
57     };
58 
59     State mState;
60     int mSocket;
61 
62     KeyedVector<string, string> mHeaders;
63 
64     // Receive a line of data terminated by CRLF, line will be '\0' terminated
65     // _excluding_ the termianting CRLF.
66     status_t receive_line(char *line, size_t size);
67 
68     HTTPStream(const HTTPStream &);
69     HTTPStream &operator=(const HTTPStream &);
70 };
71 
72 }  // namespace android
73 
74 #endif  // HTTP_STREAM_H_
75