~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to mimelib/param.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=============================================================================
2
 
// File:       param.cpp
3
 
// Contents:   Definitions for DwParameter
4
 
// Maintainer: Doug Sauder <dwsauder@fwb.gulf.net>
5
 
// WWW:        http://www.fwb.gulf.net/~dwsauder/mimepp.html
6
 
//
7
 
// Copyright (c) 1996, 1997 Douglas W. Sauder
8
 
// All rights reserved.
9
 
//
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.
14
 
//
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.
20
 
//
21
 
//=============================================================================
22
 
 
23
 
#define DW_IMPLEMENTATION
24
 
 
25
 
#include <mimelib/config.h>
26
 
#include <mimelib/debug.h>
27
 
#include <ctype.h>
28
 
#include <stdlib.h>
29
 
#include <string.h>
30
 
#include <mimelib/string.h>
31
 
#include <mimelib/param.h>
32
 
#include <mimelib/token.h>
33
 
 
34
 
 
35
 
const char* const DwParameter::sClassName = "DwParameter";
36
 
 
37
 
 
38
 
DwParameter* (*DwParameter::sNewParameter)(const DwString&,
39
 
    DwMessageComponent*) = 0;
40
 
 
41
 
 
42
 
DwParameter* DwParameter::NewParameter(const DwString& aStr,
43
 
    DwMessageComponent* aParent)
44
 
{
45
 
    if (sNewParameter) {
46
 
        return sNewParameter(aStr, aParent);
47
 
    }
48
 
    else {
49
 
        return new DwParameter(aStr, aParent);
50
 
    }
51
 
}
52
 
 
53
 
 
54
 
DwParameter::DwParameter()
55
 
{
56
 
    mNext = 0;
57
 
    mClassId = kCidParameter;
58
 
    mClassName = sClassName;
59
 
}
60
 
 
61
 
 
62
 
DwParameter::DwParameter(const DwParameter& aParam)
63
 
  : DwMessageComponent(aParam),
64
 
    mAttribute(aParam.mAttribute),
65
 
    mValue(aParam.mValue),
66
 
    mForceNoQuotes(aParam.mForceNoQuotes)
67
 
{
68
 
    mNext = 0;
69
 
    mClassId = kCidParameter;
70
 
    mClassName = sClassName;
71
 
}
72
 
 
73
 
 
74
 
DwParameter::DwParameter(const DwString& aStr, DwMessageComponent* aParent)
75
 
    : DwMessageComponent(aStr, aParent)
76
 
{
77
 
    mNext = 0;
78
 
    mClassId = kCidParameter;
79
 
    mClassName = sClassName;
80
 
    mForceNoQuotes = false;
81
 
}
82
 
 
83
 
 
84
 
DwParameter::~DwParameter()
85
 
{
86
 
}
87
 
 
88
 
 
89
 
const DwParameter& DwParameter::operator = (const DwParameter& aParam)
90
 
{
91
 
    if (this == &aParam) return *this;
92
 
    DwMessageComponent::operator = (aParam);
93
 
    mAttribute = aParam.mAttribute;
94
 
    mValue     = aParam.mValue;
95
 
    mForceNoQuotes = aParam.mForceNoQuotes;
96
 
    mNext      = 0;
97
 
    return *this;
98
 
}
99
 
 
100
 
 
101
 
const DwString& DwParameter::Attribute() const
102
 
{
103
 
    return mAttribute;
104
 
}
105
 
 
106
 
 
107
 
void DwParameter::SetAttribute(const DwString& aAttribute)
108
 
{
109
 
    mAttribute = aAttribute;
110
 
    SetModified();
111
 
}
112
 
 
113
 
 
114
 
const DwString& DwParameter::Value() const
115
 
{
116
 
    return mValue;
117
 
}
118
 
 
119
 
 
120
 
void DwParameter::SetValue(const DwString& aValue, bool forceNoQuote)
121
 
{
122
 
    mValue = aValue;
123
 
    mForceNoQuotes = forceNoQuote;
124
 
    SetModified();
125
 
}
126
 
 
127
 
 
128
 
DwParameter* DwParameter::Next() const
129
 
{
130
 
    return mNext;
131
 
}
132
 
 
133
 
 
134
 
void DwParameter::SetNext(DwParameter* aParam)
135
 
{
136
 
    mNext = aParam;
137
 
}
138
 
 
139
 
 
140
 
void DwParameter::Parse()
141
 
{
142
 
    mIsModified = 0;
143
 
    mAttribute = mValue = "";
144
 
    if (mString.length() == 0) return;
145
 
    DwRfc1521Tokenizer tokenizer(mString);
146
 
    // Get attribute
147
 
    int found = 0;
148
 
    while (!found && tokenizer.Type() != eTkNull) {
149
 
        if (tokenizer.Type() == eTkToken) {
150
 
            mAttribute = tokenizer.Token();
151
 
            found = 1;
152
 
        }
153
 
        ++tokenizer;
154
 
    }
155
 
    // Get '='
156
 
    found = 0;
157
 
    while (!found && tokenizer.Type() != eTkNull) {
158
 
        if (tokenizer.Type() == eTkTspecial
159
 
            && tokenizer.Token()[0] == '=') {
160
 
            found = 1;
161
 
        }
162
 
        ++tokenizer;
163
 
    }
164
 
    // Get value
165
 
    found = 0;
166
 
    while (!found && tokenizer.Type() != eTkNull) {
167
 
        if (tokenizer.Type() == eTkToken) {
168
 
            mValue = tokenizer.Token();
169
 
            found = 1;
170
 
        }
171
 
        else if (tokenizer.Type() == eTkQuotedString) {
172
 
            tokenizer.StripDelimiters();
173
 
            mValue = tokenizer.Token();
174
 
            found = 1;
175
 
        }
176
 
        ++tokenizer;
177
 
    }
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.
181
 
    //
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);
188
 
        }
189
 
    }
190
 
}
191
 
 
192
 
 
193
 
void DwParameter::Assemble()
194
 
{
195
 
    if (mIsModified == 0) return;
196
 
    mString = "";
197
 
    mString += mAttribute;
198
 
    bool noQuotes = mForceNoQuotes || (DwStrcasecmp(mAttribute, "micalg") == 0);
199
 
    if( noQuotes )
200
 
      mString += "=";
201
 
    else
202
 
      mString += "=\"";
203
 
    mString += mValue;
204
 
    if( !noQuotes )
205
 
      mString += "\"";
206
 
    mIsModified = 0;
207
 
}
208
 
 
209
 
 
210
 
DwMessageComponent* DwParameter::Clone() const
211
 
{
212
 
    return new DwParameter(*this);
213
 
}
214
 
 
215
 
 
216
 
#if defined (DW_DEBUG_VERSION)
217
 
void DwParameter::PrintDebugInfo(std::ostream& aStrm, int /*aDepth*/) const
218
 
{
219
 
    aStrm <<
220
 
    "--------------- Debug info for DwParameter class ---------------\n";
221
 
    _PrintDebugInfo(aStrm);
222
 
}
223
 
#else
224
 
void DwParameter::PrintDebugInfo(std::ostream& , int ) const {}
225
 
#endif // defined (DW_DEBUG_VERSION)
226
 
 
227
 
 
228
 
#if defined (DW_DEBUG_VERSION)
229
 
void DwParameter::_PrintDebugInfo(std::ostream& aStrm) const
230
 
{
231
 
    DwMessageComponent::_PrintDebugInfo(aStrm);
232
 
    aStrm << "Attribute:        " << mAttribute << '\n';
233
 
    aStrm << "Value:            " << mValue << '\n';
234
 
    if (mNext) {
235
 
        aStrm << "Next parameter:   " << mNext->ObjectId() << '\n';
236
 
    }
237
 
    else {
238
 
        aStrm << "Next parameter:   " << "(none)\n";
239
 
    }
240
 
}
241
 
#else
242
 
void DwParameter::_PrintDebugInfo(std::ostream& ) const {}
243
 
#endif // defined (DW_DEBUG_VERSION)
244
 
 
245
 
 
246
 
void DwParameter::CheckInvariants() const
247
 
{
248
 
#if defined (DW_DEBUG_VERSION)
249
 
    DwMessageComponent::CheckInvariants();
250
 
    mAttribute.CheckInvariants();
251
 
    mValue.CheckInvariants();
252
 
#endif // defined (DW_DEBUG_VERSION)
253
 
}
254