| 92 | |
| 93 | |
| 94 | cMultipartParser::cMultipartParser(const AString & a_ContentType, cCallbacks & a_Callbacks) : |
| 95 | m_Callbacks(a_Callbacks), |
| 96 | m_IsValid(true), |
| 97 | m_EnvelopeParser(*this), |
| 98 | m_HasHadData(false) |
| 99 | { |
| 100 | // Check that the content type is multipart: |
| 101 | AString ContentType(a_ContentType); |
| 102 | if (strncmp(ContentType.c_str(), "multipart/", 10) != 0) |
| 103 | { |
| 104 | m_IsValid = false; |
| 105 | return; |
| 106 | } |
| 107 | size_t idxSC = ContentType.find(';', 10); |
| 108 | if (idxSC == AString::npos) |
| 109 | { |
| 110 | m_IsValid = false; |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | // Find the multipart boundary: |
| 115 | ContentType.erase(0, idxSC + 1); |
| 116 | cNameValueParser CTParser(ContentType.c_str(), ContentType.size()); |
| 117 | CTParser.Finish(); |
| 118 | if (!CTParser.IsValid()) |
| 119 | { |
| 120 | m_IsValid = false; |
| 121 | return; |
| 122 | } |
| 123 | m_Boundary = CTParser["boundary"]; |
| 124 | m_IsValid = !m_Boundary.empty(); |
| 125 | if (!m_IsValid) |
| 126 | { |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | // Set the envelope parser for parsing the body, so that our Parse() function parses the ignored prefix data as a body |
| 131 | m_EnvelopeParser.SetIsInHeaders(false); |
| 132 | |
| 133 | // Append an initial CRLF to the incoming data, so that a body starting with the boundary line will get caught |
| 134 | m_IncomingData.assign("\r\n"); |
| 135 | |
| 136 | /* |
| 137 | m_Boundary = AString("\r\n--") + m_Boundary |
| 138 | m_BoundaryEnd = m_Boundary + "--\r\n"; |
| 139 | m_Boundary = m_Boundary + "\r\n"; |
| 140 | */ |
| 141 | } |
| 142 | |
| 143 | |
| 144 | |