2 * Copyright 2010-2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Adrien Destugues, pulkomandy@pulkomandy.tk
7 * John Scipione, jscipione@gmail.com
10 * headers/os/net/HttpForm.h hrev46314
11 * src/kits/network/libnetapi/HttpForm.cpp hrev46314
18 \brief Management of HTTP form data
29 \var form_type B_HTTP_FORM_URL_ENCODED
34 \var form_type B_HTTP_FORM_MULTIPART
39 \enum form_content_type
45 \var form_content_type B_HTTPFORM_UNKNOWN
50 \var form_content_type B_HTTPFORM_STRING
55 \var form_content_type B_HTTPFORM_FILE
60 \var form_content_type B_HTTPFORM_BUFFER
67 \brief Stores a form data entry sent or received during an HTTP request.
69 Each element in a form is stored in an instance of this class. The values
70 can be either strings, arbitrary binary buffers, or a pointer to a file.
72 The latter allows reading data from the file as it is being sent through
73 the network, removing hte need to buffer the whole file contents in memory.
78 \fn BHttpFormData::BHttpFormData(const BString& name, const BString& value)
79 \brief Construct a BHttpFormData object with a string value.
84 \fn BHttpFormData::BHttpFormData(const BString& name, const BPath& value)
85 \brief Construct a BHttpFormData object which value is a file contents
90 \fn BHttpFormData::BHttpFormData(const BString& name, const void* buffer,
92 \brief Construct a BHttpFormData object which value is a binary buffer.
97 \fn bool BHttpFormData::InitCheck() const
98 \brief Checks the initialization of the object
100 \return \c false if attempting to construct a BHttpFormData with a \c NULL
106 \fn const BString& BHttpFormData::Name() const
107 \brief Get the form field name
112 \fn const BString& BHttpFormData::String() const
113 \brief Get the string value of a form field.
115 \return An empty string for buffer and file based fields.
120 \fn const BPath& BHttpFormData::File() const
121 \brief Get the file path of a form field.
123 \return An empty string for buffer and string based fields.
128 \fn const void* BHttpFormData::Buffer() const
129 \brief Get a pointer to the data of a form field.
131 \return An empty string for string and file based fields
136 \fn ssize_t BHttpFormData::BufferSize() const;
137 \brief Get the buffer size
139 \return 0 for string and file based fields.
144 \fn bool BHttpFormData::IsFile() const
145 \return \c true if the field data is a file.
150 \fn const BString& BHttpFormData::Filename() const;
151 \return The name of the file, for file based fields.
156 \fn const BString& BHttpFormData::MimeType() const
157 \return The MIME type of the data.
162 \fn form_content_type BHttpFormData::Type() const
163 \return The kind of field.
168 \fn status_t BHttpFormData::CopyBuffer()
169 \brief Make a copy of the internal buffer
171 The constructor for buffer-based fields does not copy the data given to it,
172 it just keeps a pointer. If you want to retain ownership of the data, call
173 this method so the buffer copies and releases it.
178 \fn status_t BHttpFormData::MarkAsFile(const BString& filename,
179 const BString& mimeType)
180 \brief Mark a field as a file.
185 \fn void BHttpFormData::UnmarkAsFile()
186 \brief Unmark a field as a file.
191 \fn status_t BHttpFormData::CopyBuffer()
196 \fn BHttpFormData& BHttpFormData::operator=(const BHttpFormData& other)
197 \brief Assignment operator.
204 \brief Container for all the BHttpFormData instances making up an HTTP form contents.
209 \fn BHttpForm::BHttpForm()
210 \brief Create a new form object.
215 \fn BHttpForm::BHttpForm(const BHttpForm& other)
216 \brief Create a new form object as a copy of \a other.
221 \fn BHttpForm::BHttpForm(const BString& formString)
222 \brief Create a new form object and parse the \a formString.
227 \fn BHttpForm::~BHttpForm()
228 \brief Clear the form and destroy the form object.
233 \fn void BHttpForm::ParseString(const BString& formString)
234 \brief Parse the \a formString.
239 \fn BString BHttpForm::RawData() const
240 \brief Return the form's raw data as a BString.
245 \fn status_t BHttpForm::AddString(const BString& fieldName,
246 const BString& value)
247 \brief Add a string to the form with the specified \a fieldName and \a value.
252 \fn status_t BHttpForm::AddInt(const BString& fieldName, int32 value)
253 \brief Add an int to the form with the specified \a fieldName and \a value.
258 \fn status_t BHttpForm::AddFile(const BString& fieldName, const BPath& file)
259 \brief Add a file to the form with the specified \a fieldName and \a value.
264 \fn status_t BHttpForm::AddBuffer(const BString& fieldName,
265 const void* buffer, ssize_t size)
266 \brief Add a buffer to the form with the specified \a fieldName and \a buffer
272 \fn status_t BHttpForm::AddBufferCopy(const BString& fieldName,
273 const void* buffer, ssize_t size)
278 \fn void BHttpForm::MarkAsFile(const BString& fieldName,
279 const BString& filename, const BString& mimeType)
284 \fn void BHttpForm::MarkAsFile(const BString& fieldName,
285 const BString& filename)
286 \brief Mark a field as a filename.
291 \fn void BHttpForm::UnmarkAsFile(const BString& fieldName)
292 \brief Unmark a field as a filename.
297 \fn void BHttpForm::SetFormType(form_type type)
298 \brief Change form type.
303 \fn bool BHttpForm::HasField(const BString& name) const
304 \brief Returns whether or not a form has a field with the specified \a name.
309 \fn BString BHttpForm::GetMultipartHeader(const BString& fieldName) const
314 \fn form_type BHttpForm::GetFormType() const
319 \fn const BString& BHttpForm::GetMultipartBoundary() const
324 \fn BString BHttpForm::GetMultipartFooter() const
329 \fn ssize_t BHttpForm::ContentLength() const
334 \fn BHttpForm::Iterator BHttpForm::GetIterator()
339 \fn void BHttpForm::Clear()
344 \fn BHttpFormData& BHttpForm::operator[](const BString& name)
349 \fn void BHttpForm::_ExtractNameValuePair(const BString& formString, int32* index)
354 \fn void BHttpForm::_GenerateMultipartBoundary()
359 \fn void BHttpForm::Clear()
364 \class BHttpForm::Iterator
366 \brief Form Iterator.
371 \fn BHttpForm::Iterator::Iterator(BHttpForm* form)
377 \fn BHttpForm::Iterator::Iterator(const Iterator& other);
378 \brief Copy contstructor.
383 \fn bool BHttpForm::Iterator::HasNext() const
388 \fn BHttpFormData* BHttpForm::Iterator::Next()
393 \fn void BHttpForm::Iterator::Remove()
398 \fn BString BHttpForm::Iterator::MultipartHeader()
403 \fn BHttpForm::Iterator& BHttpForm::Iterator::operator=(const Iterator& other)
404 \brief Assignment operator.