Style fixes to HttpForm
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010 Haiku Inc. All rights reserved.
|
* Copyright 2010-2013 Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _B_HTTP_FORM_H_
|
#ifndef _B_HTTP_FORM_H_
|
||||||
@@ -125,8 +125,7 @@ public:
|
|||||||
bool HasField(const BString& name) const;
|
bool HasField(const BString& name) const;
|
||||||
|
|
||||||
// Form retrieve
|
// Form retrieve
|
||||||
BString GetMultipartHeader(const BString& fieldName)
|
BString GetMultipartHeader(const BString& fieldName) const;
|
||||||
const;
|
|
||||||
form_content_type GetType(const BString& fieldname) const;
|
form_content_type GetType(const BString& fieldname) const;
|
||||||
|
|
||||||
// Form informations
|
// Form informations
|
||||||
@@ -145,11 +144,9 @@ public:
|
|||||||
BHttpFormData& operator[](const BString& name);
|
BHttpFormData& operator[](const BString& name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _ExtractNameValuePair(const BString& string,
|
void _ExtractNameValuePair(const BString& string, int32* index);
|
||||||
int32* index);
|
|
||||||
void _GenerateMultipartBoundary();
|
void _GenerateMultipartBoundary();
|
||||||
BString _GetMultipartHeader(
|
BString _GetMultipartHeader(const BHttpFormData* element) const;
|
||||||
const BHttpFormData* element) const;
|
|
||||||
form_content_type _GetType(FormStorage::const_iterator it) const;
|
form_content_type _GetType(FormStorage::const_iterator it) const;
|
||||||
void _Erase(FormStorage::iterator it);
|
void _Erase(FormStorage::iterator it);
|
||||||
|
|
||||||
@@ -162,7 +159,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BHttpForm::Iterator {
|
class BHttpForm::Iterator {
|
||||||
public:
|
public:
|
||||||
Iterator(const Iterator& other);
|
Iterator(const Iterator& other);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010 Haiku Inc. All rights reserved.
|
* Copyright 2010-2013 Haiku Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -7,22 +7,24 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <HttpForm.h>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
#include <HttpForm.h>
|
|
||||||
#include <NodeInfo.h>
|
#include <NodeInfo.h>
|
||||||
#include <TypeConstants.h>
|
#include <TypeConstants.h>
|
||||||
#include <Url.h>
|
#include <Url.h>
|
||||||
|
|
||||||
|
|
||||||
static int32 kBoundaryRandomSize = 16;
|
static int32 kBoundaryRandomSize = 16;
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -- BHttpFormData
|
// #pragma mark - BHttpFormData
|
||||||
|
|
||||||
|
|
||||||
BHttpFormData::BHttpFormData()
|
BHttpFormData::BHttpFormData()
|
||||||
@@ -93,7 +95,7 @@ BHttpFormData::~BHttpFormData()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark Retrieve data informations
|
// #pragma mark - Retrieve data informations
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -169,7 +171,9 @@ BHttpFormData::Type() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark Change behavior
|
// #pragma mark - Change behavior
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BHttpFormData::MarkAsFile(const BString& filename, const BString& mimeType)
|
BHttpFormData::MarkAsFile(const BString& filename, const BString& mimeType)
|
||||||
{
|
{
|
||||||
@@ -232,23 +236,26 @@ BHttpFormData::operator=(const BHttpFormData& other)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -- BHttpForm
|
// #pragma mark - BHttpForm
|
||||||
|
|
||||||
|
|
||||||
BHttpForm::BHttpForm()
|
BHttpForm::BHttpForm()
|
||||||
: fType(B_HTTP_FORM_URL_ENCODED)
|
:
|
||||||
|
fType(B_HTTP_FORM_URL_ENCODED)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BHttpForm::BHttpForm(const BHttpForm&)
|
BHttpForm::BHttpForm(const BHttpForm& other)
|
||||||
: fType(B_HTTP_FORM_URL_ENCODED)
|
:
|
||||||
|
fType(B_HTTP_FORM_URL_ENCODED)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BHttpForm::BHttpForm(const BString& formString)
|
BHttpForm::BHttpForm(const BString& formString)
|
||||||
: fType(B_HTTP_FORM_URL_ENCODED)
|
:
|
||||||
|
fType(B_HTTP_FORM_URL_ENCODED)
|
||||||
{
|
{
|
||||||
ParseString(formString);
|
ParseString(formString);
|
||||||
}
|
}
|
||||||
@@ -260,7 +267,7 @@ BHttpForm::~BHttpForm()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark Form string parsing
|
// #pragma mark - Form string parsing
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -268,9 +275,8 @@ BHttpForm::ParseString(const BString& formString)
|
|||||||
{
|
{
|
||||||
int32 index = 0;
|
int32 index = 0;
|
||||||
|
|
||||||
while (index < formString.Length()) {
|
while (index < formString.Length())
|
||||||
_ExtractNameValuePair(formString, &index);
|
_ExtractNameValuePair(formString, &index);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -338,8 +344,8 @@ BHttpForm::RawData() const
|
|||||||
result.Append(readBuffer, readSize);
|
result.Append(readBuffer, readSize);
|
||||||
readSize = upFile.Read(readBuffer, 1024);
|
readSize = upFile.Read(readBuffer, 1024);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case B_HTTPFORM_BUFFER:
|
case B_HTTPFORM_BUFFER:
|
||||||
result.Append(
|
result.Append(
|
||||||
@@ -358,7 +364,7 @@ BHttpForm::RawData() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark Form add
|
// #pragma mark - Form add
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
@@ -428,7 +434,7 @@ BHttpForm::AddBufferCopy(const BString& fieldName, const void* buffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark Mark a field as a filename
|
// #pragma mark - Mark a field as a filename
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -465,7 +471,7 @@ BHttpForm::UnmarkAsFile(const BString& fieldName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark Change form type
|
// #pragma mark - Change form type
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -478,7 +484,7 @@ BHttpForm::SetFormType(form_type type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark Form test
|
// #pragma mark - Form test
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -488,7 +494,7 @@ BHttpForm::HasField(const BString& name) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark Form retrieve
|
// #pragma mark - Form retrieve
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
@@ -552,8 +558,8 @@ BHttpForm::ContentLength() const
|
|||||||
BFile upFile(c->File().Path(), B_READ_ONLY);
|
BFile upFile(c->File().Path(), B_READ_ONLY);
|
||||||
upFile.Seek(0, SEEK_END);
|
upFile.Seek(0, SEEK_END);
|
||||||
contentLength += upFile.Position();
|
contentLength += upFile.Position();
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case B_HTTPFORM_BUFFER:
|
case B_HTTPFORM_BUFFER:
|
||||||
contentLength += c->BufferSize();
|
contentLength += c->BufferSize();
|
||||||
@@ -579,7 +585,7 @@ BHttpForm::GetIterator()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark Form clear
|
// #pragma mark - Form clear
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -589,7 +595,7 @@ BHttpForm::Clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark Overloaded operators
|
// #pragma mark - Overloaded operators
|
||||||
|
|
||||||
|
|
||||||
BHttpFormData&
|
BHttpFormData&
|
||||||
@@ -651,7 +657,7 @@ BHttpForm::_GenerateMultipartBoundary()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark Field information access by std iterator
|
// #pragma mark - Field information access by std iterator
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
@@ -679,8 +685,9 @@ BHttpForm::_GetMultipartHeader(const BHttpFormData* element) const
|
|||||||
result << tempMime;
|
result << tempMime;
|
||||||
else
|
else
|
||||||
result << "application/octet-stream";
|
result << "application/octet-stream";
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case B_HTTPFORM_STRING:
|
case B_HTTPFORM_STRING:
|
||||||
case B_HTTPFORM_BUFFER:
|
case B_HTTPFORM_BUFFER:
|
||||||
@@ -696,15 +703,17 @@ BHttpForm::_GetMultipartHeader(const BHttpFormData* element) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
result << "\r\n\r\n";
|
result << "\r\n\r\n";
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -- Iterator
|
// #pragma mark - Iterator
|
||||||
|
|
||||||
|
|
||||||
BHttpForm::Iterator::Iterator(BHttpForm* form)
|
BHttpForm::Iterator::Iterator(BHttpForm* form)
|
||||||
: fElement(NULL)
|
:
|
||||||
|
fElement(NULL)
|
||||||
{
|
{
|
||||||
fForm = form;
|
fForm = form;
|
||||||
fStdIterator = form->fFields.begin();
|
fStdIterator = form->fFields.begin();
|
||||||
|
|||||||
Reference in New Issue
Block a user