• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012, 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 #include <media/stagefright/foundation/ABase.h>
18 #include <media/stagefright/foundation/AString.h>
19 #include <utils/KeyedVector.h>
20 #include <utils/RefBase.h>
21 
22 namespace android {
23 
24 // Encapsulates an "HTTP/RTSP style" response, i.e. a status line,
25 // key/value pairs making up the headers and an optional body/content.
26 struct ParsedMessage : public RefBase {
27     static sp<ParsedMessage> Parse(
28             const char *data, size_t size, bool noMoreData, size_t *length);
29 
30     bool findString(const char *name, AString *value) const;
31     bool findInt32(const char *name, int32_t *value) const;
32 
33     const char *getContent() const;
34 
35     bool getRequestField(size_t index, AString *field) const;
36     bool getStatusCode(int32_t *statusCode) const;
37 
38     AString debugString() const;
39 
40     static bool GetAttribute(const char *s, const char *key, AString *value);
41 
42     static bool GetInt32Attribute(
43             const char *s, const char *key, int32_t *value);
44 
45 
46 protected:
47     virtual ~ParsedMessage();
48 
49 private:
50     KeyedVector<AString, AString> mDict;
51     AString mContent;
52 
53     ParsedMessage();
54 
55     ssize_t parse(const char *data, size_t size, bool noMoreData);
56 
57     DISALLOW_EVIL_CONSTRUCTORS(ParsedMessage);
58 };
59 
60 }  // namespace android
61