318{
321
322 __input = &_input;
323 __contentLength = _contentLength;
324 __remainder = _contentLength;
325
326 ByteString boundary = "--";
327 {
328 ByteString strOrgBoundary = getBoundary(_contentType);
329 if (strOrgBoundary.isEmpty()) {
330 appendWarning(L"Error! invalid boundary");
331 return;
332 }
333 boundary = boundary + strOrgBoundary;
334 }
335
336 __DCL_ASSERT(__bufferSize > (
size_t)(boundary.length() + 2));
337
339
340 if(!readInput()) {
341 appendWarning(L"Warning! Input data empty");
342 return;
343 }
344
345 bool bNextPart = getFirstBoundary(boundary);
346
347 while(bNextPart) {
348 HttpFormData::PartHeader header;
349 if (!getPartHeader(header)) {
350 appendWarning(L"Warning! not found boundary delimiter");
351 break;
352 }
353
355
356
357
358
359
360
361
362 if (header.filename.isEmpty()) {
363
364 ByteStringBuilder value;
365
368 DataState ds = dsNeedMoreData;
369 while((ds = getDataBlock(boundary, _begin, _end)) == dsNeedMoreData) {
370 if (_begin < _end) {
371 value.append(_begin, _end);
372 }
373
374 if (!readInput()) {
375
376 break;
377 }
378 }
379
380 if (ds == dsNeedMoreData) {
381
382
383
384 String strMsg = header.name
385 + L": invalid data, discarded";
386 appendWarning(strMsg);
388
389 bNextPart = false;
390 }
391 else {
392
393
394 if (_begin < _end) {
395 value.append(_begin, _end);
396 }
397
398 (_mapForm[header.name]).add(UTF8Decoder::decode(value));
399
400 if (ds == dsBeforeCloseBoundary)
401 bNextPart = false;
402 }
403 }
404 else {
405
406 void* pCallbackData =
NULL;
407 String strCallbackError;
408 if (!_mapFormFile.onFileStart(
409 header,
410 &pCallbackData,
411 strCallbackError
412 )) {
413
414 throw new HttpFormDataDecoderException(
415 HttpFormDataDecoderException::eFormDataCallbackError,
416 strCallbackError
417 );
418 }
419
422 DataState ds = dsNeedMoreData;
423 while((ds = getDataBlock(boundary, _begin, _end)) == dsNeedMoreData) {
424 if (_begin < _end) {
425
426 if (!_mapFormFile.onFileData(
427 _begin,
428 _end - _begin,
429 pCallbackData,
430 strCallbackError
431 )) {
432 throw new HttpFormDataDecoderException(
433 HttpFormDataDecoderException::eFormDataCallbackError,
434 strCallbackError
435 );
436 }
437 }
438
439 try {
440 if (!readInput()) {
441
442 break;
443 }
444 }
445 catch (HttpFormDataDecoderException* e) {
446 if (!_mapFormFile.onFileEnd(
447 header,
448 pCallbackData,
449 false,
450 strCallbackError
451 )) {
452 __DCL_TRACE1(L
"HttpFormData::onFileEnd: %ls\n", strCallbackError.data());
453 }
454
455 throw e;
456 }
457 }
458
459 if (ds == dsNeedMoreData) {
460
461
462
463 String strMsg = header.name
464 + L":\"" + header.filename
465 + L"\": invalid data, discarded";
466
467 appendWarning(strMsg);
469
470 if (!_mapFormFile.onFileEnd(
471 header,
472 pCallbackData,
473 false,
474 strCallbackError
475 )) {
476 __DCL_TRACE1(L
"HttpFormData::onFileEnd: %ls\n", strCallbackError.data());
477 }
478
479 bNextPart = false;
480 }
481 else {
482
483 if (_begin < _end) {
484 if (!_mapFormFile.onFileData(
485 _begin,
486 _end - _begin,
487 pCallbackData,
488 strCallbackError
489 )) {
490 throw new HttpFormDataDecoderException(
491 HttpFormDataDecoderException::eFormDataCallbackError,
492 strCallbackError
493 );
494 }
495 }
496
497 if (!_mapFormFile.onFileEnd(
498 header,
499 pCallbackData,
500 true,
501 strCallbackError
502 )) {
503 throw new HttpFormDataDecoderException(
504 HttpFormDataDecoderException::eFormDataCallbackError,
505 strCallbackError
506 );
507 }
508
509 if (ds == dsBeforeCloseBoundary)
510 bNextPart = false;
511 }
512 }
513 }
514}
#define __DCL_TRACE1_N(fmt, arg)
#define __DCL_TRACE1(fmt, arg1)
#define __DCL_ASSERT(expr)