1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 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 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 19 #ifndef RTSP_PARSER_H_ 20 #define RTSP_PARSER_H_ 21 22 #include "rtsp_par_com_basic_ds.h" 23 #include "rtsp_par_com_message.h" 24 25 class RTSPParser 26 { 27 private: 28 29 RTSPParser(const RTSPParser &); 30 RTSPParser & operator= (const RTSPParser &); 31 32 public: 33 34 typedef enum 35 { 36 IS_WAITING_FOR_REQUEST_MEMORY, 37 IS_LOOKING_FOR_END_OF_REQUEST, 38 IS_WAITING_FOR_DATA, 39 IS_REQUEST_IS_READY, 40 IS_WAITING_FOR_ENTITY_BODY_MEMORY, 41 IS_ERROR_REQUEST_TOO_BIG, 42 IS_SKIPPING_OVER_ENTITY_BODY, 43 IS_STARTING_TO_FILL_OUT_ENTITY_BODY, 44 IS_CONTINUING_TO_FILL_OUT_ENTITY_BODY, 45 IS_ENTITY_BODY_IS_READY, 46 IS_INTERNAL_ERROR, 47 IS_START_LOOKING_FOR_RESYNC, 48 IS_LOOKING_FOR_RESYNC, 49 IS_WAITING_FOR_EMBEDDED_DATA_MEMORY, 50 IS_EMBEDDED_DATA_IS_READY, 51 IS_SKIPPING_OVER_EMBEDDED_DATA, 52 IS_STARTING_TO_FILL_OUT_EMBEDDED_DATA, 53 IS_CONTINUING_TO_FILL_OUT_EMBEDDED_DATA 54 55 56 } InternalState; 57 58 typedef enum 59 { 60 WAITING_FOR_DATA, 61 WAITING_FOR_REQUEST_MEMORY, 62 REQUEST_IS_READY, 63 WAITING_FOR_ENTITY_BODY_MEMORY, 64 ENTITY_BODY_IS_READY, 65 ERROR_REQUEST_TOO_BIG, 66 WAITING_FOR_EMBEDDED_DATA_MEMORY, 67 EMBEDDED_DATA_IS_READY, 68 INTERNAL_ERROR 69 } ParserState; 70 71 72 OSCL_IMPORT_REF RTSPParser(); 73 74 protected: 75 76 InternalState internalState; 77 78 char mainBuffer[ RTSP_PARSER_BUFFER_SIZE + 3 ]; 79 char * mainBufferEntry; 80 char * mainBufferSpace; 81 int mainBufferSizeUsed; 82 83 RTSPIncomingMessage * requestStruct; 84 85 StrPtrLen dataBufferSpec; 86 87 uint32 ebFullSizeExpected; 88 uint32 ebSizeCoveredSoFar; 89 uint32 ebCurrentIndex; 90 uint32 ebCurrentOffset; 91 OsclMemoryFragment * entityBody; 92 93 char * eorptr; 94 95 96 // for field repetitions 97 // 98 StrPtrLen fields[ RTSP_HUGE_NUMBER_OF_FIELDS_IN_PARSER ]; 99 uint32 numFieldsUsed; 100 101 void continueProcessing(); 102 void lookForEndOfRequest(); 103 void lookForResync(); 104 void skipOverEntityBody(); 105 void startFillingOutEntityBody(); 106 void dealWithLineContinuations(RTSPIncomingMessage *); 107 void dealWithFieldRepetitions(RTSPIncomingMessage *); 108 void skipOverEmbeddedData(); 109 void startFillingOutEmbeddedData(); 110 111 public: 112 113 114 ParserState 115 OSCL_IMPORT_REF getState(); 116 117 118 // to get the address and size of data 119 // to be written to Parser's raw buffer 120 // 121 OSCL_IMPORT_REF const StrPtrLen * 122 getDataBufferSpec(); 123 124 // to register that data buffer has been 125 // written 126 // 127 OSCL_IMPORT_REF bool 128 registerDataBufferWritten(uint32 sizeWritten); 129 130 // to register the RTSPIncomingMessage structure to 131 // be filled out 132 // 133 OSCL_IMPORT_REF bool 134 registerNewRequestStruct(RTSPIncomingMessage * newRequestStruct); 135 136 // to register the RTSPEntityBody buffer 137 // that the entity body should be written into 138 // 139 OSCL_IMPORT_REF bool 140 registerEntityBody(RTSPEntityBody * newBody); 141 142 // to register the RTSPEntityBody buffer 143 // that the embedded data should be written into 144 // 145 OSCL_IMPORT_REF bool 146 registerEmbeddedDataMemory(RTSPEntityBody * newBody); 147 148 // to flush the currently available information // and make a request out of 149 // whatever was 150 // available 151 OSCL_IMPORT_REF void flush(void); 152 OSCL_IMPORT_REF bool parseEntityBody(RTSPEntityBody * entityBody); 153 }; 154 155 156 #endif // RTSP_PARSER_H_ 157