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