2 * Copyright 2010-2013 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 #ifndef _B_HTTP_FORM_H_
6 #define _B_HTTP_FORM_H_
16 B_HTTP_FORM_URL_ENCODED
,
21 enum form_content_type
{
31 // Empty constructor is only kept for compatibility with map<>::operator[],
32 // but never used (see BHttpForm::operator[] which does the necessary
35 #if (__GNUC__ >= 6) || defined(__clang__)
36 friend class std::pair
<const BString
, BHttpFormData
>;
38 friend class std::map
<BString
, BHttpFormData
>;
42 BHttpFormData(const BString
& name
,
43 const BString
& value
);
44 BHttpFormData(const BString
& name
,
46 BHttpFormData(const BString
& name
,
47 const void* buffer
, ssize_t size
);
48 BHttpFormData(const BHttpFormData
& other
);
51 // Retrieve data informations
52 bool InitCheck() const;
54 const BString
& Name() const;
55 const BString
& String() const;
56 const BPath
& File() const;
57 const void* Buffer() const;
58 ssize_t
BufferSize() const;
61 const BString
& Filename() const;
62 const BString
& MimeType() const;
63 form_content_type
Type() const;
66 status_t
MarkAsFile(const BString
& filename
,
67 const BString
& mimeType
= "");
69 status_t
CopyBuffer();
71 // Overloaded operators
72 BHttpFormData
& operator=(const BHttpFormData
& other
);
75 form_content_type fDataType
;
82 const void* fBufferValue
;
94 typedef std::map
<BString
, BHttpFormData
> FormStorage
;
98 BHttpForm(const BHttpForm
& other
);
99 BHttpForm(const BString
& formString
);
102 // Form string parsing
103 void ParseString(const BString
& formString
);
104 BString
RawData() const;
107 status_t
AddString(const BString
& name
,
108 const BString
& value
);
109 status_t
AddInt(const BString
& name
, int32 value
);
110 status_t
AddFile(const BString
& fieldName
,
112 status_t
AddBuffer(const BString
& fieldName
,
113 const void* buffer
, ssize_t size
);
114 status_t
AddBufferCopy(const BString
& fieldName
,
115 const void* buffer
, ssize_t size
);
117 // Mark a field as a filename
118 void MarkAsFile(const BString
& fieldName
,
119 const BString
& filename
,
120 const BString
& mimeType
);
121 void MarkAsFile(const BString
& fieldName
,
122 const BString
& filename
);
123 void UnmarkAsFile(const BString
& fieldName
);
126 void SetFormType(form_type type
);
129 bool HasField(const BString
& name
) const;
132 BString
GetMultipartHeader(const BString
& fieldName
) const;
133 form_content_type
GetType(const BString
& fieldname
) const;
136 form_type
GetFormType() const;
137 const BString
& GetMultipartBoundary() const;
138 BString
GetMultipartFooter() const;
139 ssize_t
ContentLength() const;
142 Iterator
GetIterator();
147 // Overloaded operators
148 BHttpFormData
& operator[](const BString
& name
);
151 void _ExtractNameValuePair(const BString
& string
, int32
* index
);
152 void _GenerateMultipartBoundary();
153 BString
_GetMultipartHeader(const BHttpFormData
* element
) const;
154 form_content_type
_GetType(FormStorage::const_iterator it
) const;
155 void _Erase(FormStorage::iterator it
);
158 friend class Iterator
;
162 BString fMultipartBoundary
;
166 class BHttpForm::Iterator
{
168 Iterator(const Iterator
& other
);
170 BHttpFormData
* Next();
171 bool HasNext() const;
173 BString
MultipartHeader();
175 Iterator
& operator=(const Iterator
& other
);
178 Iterator(BHttpForm
* form
);
182 friend class BHttpForm
;
185 BHttpForm::FormStorage::iterator
187 BHttpFormData
* fElement
;
188 BHttpFormData
* fPrevElement
;
191 #endif // _B_HTTP_FORM_H_