1
//=============================================================================
3
// Contents: Definitions for DwParameter
4
// Maintainer: Doug Sauder <dwsauder@fwb.gulf.net>
5
// WWW: http://www.fwb.gulf.net/~dwsauder/mimepp.html
7
// Copyright (c) 1996, 1997 Douglas W. Sauder
8
// All rights reserved.
10
// IN NO EVENT SHALL DOUGLAS W. SAUDER BE LIABLE TO ANY PARTY FOR DIRECT,
11
// INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
12
// THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF DOUGLAS W. SAUDER
13
// HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
// DOUGLAS W. SAUDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT
16
// NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17
// PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
18
// BASIS, AND DOUGLAS W. SAUDER HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
19
// SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
21
//=============================================================================
23
#define DW_IMPLEMENTATION
25
#include <mimelib/config.h>
26
#include <mimelib/debug.h>
30
#include <mimelib/string.h>
31
#include <mimelib/param.h>
32
#include <mimelib/token.h>
35
const char* const DwParameter::sClassName = "DwParameter";
38
DwParameter* (*DwParameter::sNewParameter)(const DwString&,
39
DwMessageComponent*) = 0;
42
DwParameter* DwParameter::NewParameter(const DwString& aStr,
43
DwMessageComponent* aParent)
46
return sNewParameter(aStr, aParent);
49
return new DwParameter(aStr, aParent);
54
DwParameter::DwParameter()
57
mClassId = kCidParameter;
58
mClassName = sClassName;
62
DwParameter::DwParameter(const DwParameter& aParam)
63
: DwMessageComponent(aParam),
64
mAttribute(aParam.mAttribute),
65
mValue(aParam.mValue),
66
mForceNoQuotes(aParam.mForceNoQuotes)
69
mClassId = kCidParameter;
70
mClassName = sClassName;
74
DwParameter::DwParameter(const DwString& aStr, DwMessageComponent* aParent)
75
: DwMessageComponent(aStr, aParent)
78
mClassId = kCidParameter;
79
mClassName = sClassName;
80
mForceNoQuotes = false;
84
DwParameter::~DwParameter()
89
const DwParameter& DwParameter::operator = (const DwParameter& aParam)
91
if (this == &aParam) return *this;
92
DwMessageComponent::operator = (aParam);
93
mAttribute = aParam.mAttribute;
94
mValue = aParam.mValue;
95
mForceNoQuotes = aParam.mForceNoQuotes;
101
const DwString& DwParameter::Attribute() const
107
void DwParameter::SetAttribute(const DwString& aAttribute)
109
mAttribute = aAttribute;
114
const DwString& DwParameter::Value() const
120
void DwParameter::SetValue(const DwString& aValue, bool forceNoQuote)
123
mForceNoQuotes = forceNoQuote;
128
DwParameter* DwParameter::Next() const
134
void DwParameter::SetNext(DwParameter* aParam)
140
void DwParameter::Parse()
143
mAttribute = mValue = "";
144
if (mString.length() == 0) return;
145
DwRfc1521Tokenizer tokenizer(mString);
148
while (!found && tokenizer.Type() != eTkNull) {
149
if (tokenizer.Type() == eTkToken) {
150
mAttribute = tokenizer.Token();
157
while (!found && tokenizer.Type() != eTkNull) {
158
if (tokenizer.Type() == eTkTspecial
159
&& tokenizer.Token()[0] == '=') {
166
while (!found && tokenizer.Type() != eTkNull) {
167
if (tokenizer.Type() == eTkToken) {
168
mValue = tokenizer.Token();
171
else if (tokenizer.Type() == eTkQuotedString) {
172
tokenizer.StripDelimiters();
173
mValue = tokenizer.Token();
178
// Some nonstandard MIME implementations use single quotes to quote
179
// the boundary string. This is incorrect, but we will try to detect
180
// it and work with it.
182
// If the first character and last character of the boundary string
183
// are single quote, strip them off.
184
if (DwStrcasecmp(mAttribute, "boundary") == 0) {
185
size_t len = mValue.length();
186
if (len > 2 && mValue[0] == '\'' && mValue[len-1] == '\'') {
187
mValue = mValue.substr(1, len-2);
193
void DwParameter::Assemble()
195
if (mIsModified == 0) return;
197
mString += mAttribute;
198
bool noQuotes = mForceNoQuotes || (DwStrcasecmp(mAttribute, "micalg") == 0);
210
DwMessageComponent* DwParameter::Clone() const
212
return new DwParameter(*this);
216
#if defined (DW_DEBUG_VERSION)
217
void DwParameter::PrintDebugInfo(std::ostream& aStrm, int /*aDepth*/) const
220
"--------------- Debug info for DwParameter class ---------------\n";
221
_PrintDebugInfo(aStrm);
224
void DwParameter::PrintDebugInfo(std::ostream& , int ) const {}
225
#endif // defined (DW_DEBUG_VERSION)
228
#if defined (DW_DEBUG_VERSION)
229
void DwParameter::_PrintDebugInfo(std::ostream& aStrm) const
231
DwMessageComponent::_PrintDebugInfo(aStrm);
232
aStrm << "Attribute: " << mAttribute << '\n';
233
aStrm << "Value: " << mValue << '\n';
235
aStrm << "Next parameter: " << mNext->ObjectId() << '\n';
238
aStrm << "Next parameter: " << "(none)\n";
242
void DwParameter::_PrintDebugInfo(std::ostream& ) const {}
243
#endif // defined (DW_DEBUG_VERSION)
246
void DwParameter::CheckInvariants() const
248
#if defined (DW_DEBUG_VERSION)
249
DwMessageComponent::CheckInvariants();
250
mAttribute.CheckInvariants();
251
mValue.CheckInvariants();
252
#endif // defined (DW_DEBUG_VERSION)