PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 35ms 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
 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
 7#include <boost/enable_shared_from_this.hpp>
 8#include <boost/function.hpp>
 9#include <boost/noncopyable.hpp>
10#include <boost/shared_ptr.hpp>
11
12#include "http.h"
13
14namespace Mordor {
15
16class BodyPart;
17class Stream;
18
19struct MissingMultipartBoundaryException : virtual HTTP::Exception, virtual StreamException
20{};
21struct InvalidMultipartBoundaryException : virtual HTTP::Exception
22{};
23
24class Multipart : public boost::enable_shared_from_this<Multipart>, boost::noncopyable
25{
26    friend class BodyPart;
27public:
28    typedef boost::shared_ptr<Multipart> ptr;
29
30    static std::string randomBoundary();
31
32    Multipart(boost::shared_ptr<Stream> stream, std::string boundary);
33
34    boost::shared_ptr<BodyPart> nextPart();
35    void finish();
36
37    boost::function<void ()> multipartFinished;
38
39private:
40    void partDone();
41
42private:
43    boost::shared_ptr<Stream> m_stream;
44    std::string m_boundary;
45    boost::shared_ptr<BodyPart> m_currentPart;
46    bool m_finished;
47    bool m_firstPart;
48};
49
50class BodyPart
51{
52    friend class Multipart;
53public:
54    typedef boost::shared_ptr<BodyPart> ptr;
55
56private:
57    BodyPart(Multipart::ptr multipart);
58
59public:
60    HTTP::EntityHeaders &headers();
61    boost::shared_ptr<Stream> stream();
62    Multipart::ptr multipart();
63
64private:
65    HTTP::EntityHeaders m_headers;
66    Multipart::ptr m_multipart;
67    boost::shared_ptr<Stream> m_stream;
68    Multipart::ptr m_childMultipart;
69};
70
71}
72
73#endif