PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/mordor/http/multipart.h

http://github.com/mozy/mordor
C Header | 73 lines | 53 code | 18 blank | 2 comment | 0 complexity | 5cd76a1ac1b615f4de2858c4a61ddbcb MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #ifndef __MORDOR_MULTIPART_H__
  2. #define __MORDOR_MULTIPART_H__
  3. // Copyright (c) 2009 - Mozy, Inc.
  4. // This implementation comply with http://www.rfc-editor.org/rfc/rfc2046.txt
  5. #include <string>
  6. #include <boost/enable_shared_from_this.hpp>
  7. #include <boost/function.hpp>
  8. #include <boost/noncopyable.hpp>
  9. #include <boost/shared_ptr.hpp>
  10. #include "http.h"
  11. namespace Mordor {
  12. class BodyPart;
  13. class Stream;
  14. struct MissingMultipartBoundaryException : virtual HTTP::Exception, virtual StreamException
  15. {};
  16. struct InvalidMultipartBoundaryException : virtual HTTP::Exception
  17. {};
  18. class Multipart : public boost::enable_shared_from_this<Multipart>, boost::noncopyable
  19. {
  20. friend class BodyPart;
  21. public:
  22. typedef boost::shared_ptr<Multipart> ptr;
  23. static std::string randomBoundary();
  24. Multipart(boost::shared_ptr<Stream> stream, std::string boundary);
  25. boost::shared_ptr<BodyPart> nextPart();
  26. void finish();
  27. boost::function<void ()> multipartFinished;
  28. private:
  29. void partDone();
  30. private:
  31. boost::shared_ptr<Stream> m_stream;
  32. std::string m_boundary;
  33. boost::shared_ptr<BodyPart> m_currentPart;
  34. bool m_finished;
  35. bool m_firstPart;
  36. };
  37. class BodyPart
  38. {
  39. friend class Multipart;
  40. public:
  41. typedef boost::shared_ptr<BodyPart> ptr;
  42. private:
  43. BodyPart(Multipart::ptr multipart);
  44. public:
  45. HTTP::EntityHeaders &headers();
  46. boost::shared_ptr<Stream> stream();
  47. Multipart::ptr multipart();
  48. private:
  49. HTTP::EntityHeaders m_headers;
  50. Multipart::ptr m_multipart;
  51. boost::shared_ptr<Stream> m_stream;
  52. Multipart::ptr m_childMultipart;
  53. };
  54. }
  55. #endif