| 339 | |
| 340 | |
| 341 | void HTMLForm::readMultipart(std::istream& istr, PartHandler& handler) |
| 342 | { |
| 343 | static const int eof = std::char_traits<char>::eof(); |
| 344 | |
| 345 | int fields = 0; |
| 346 | MultipartReader reader(istr, _boundary); |
| 347 | while (reader.hasNextPart()) |
| 348 | { |
| 349 | if (_fieldLimit > 0 && fields == _fieldLimit) |
| 350 | throw HTMLFormException("Too many form fields"); |
| 351 | MessageHeader header; |
| 352 | reader.nextPart(header); |
| 353 | std::string disp; |
| 354 | NameValueCollection params; |
| 355 | if (header.has("Content-Disposition")) |
| 356 | { |
| 357 | std::string cd = header.get("Content-Disposition"); |
| 358 | MessageHeader::splitParameters(cd, disp, params); |
| 359 | } |
| 360 | if (params.has("filename")) |
| 361 | { |
| 362 | handler.handlePart(header, reader.stream()); |
| 363 | // Ensure that the complete part has been read. |
| 364 | while (reader.stream().good()) reader.stream().get(); |
| 365 | } |
| 366 | else |
| 367 | { |
| 368 | std::string name = params["name"]; |
| 369 | std::string value; |
| 370 | std::istream& istr = reader.stream(); |
| 371 | int ch = istr.get(); |
| 372 | while (ch != eof) |
| 373 | { |
| 374 | if (value.size() < _valueLengthLimit) |
| 375 | value += (char) ch; |
| 376 | else |
| 377 | throw HTMLFormException("Field value too long"); |
| 378 | ch = istr.get(); |
| 379 | } |
| 380 | add(name, value); |
| 381 | } |
| 382 | ++fields; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | |
| 387 | void HTMLForm::writeUrl(std::ostream& ostr) |
nothing calls this directly
no test coverage detected