/[debian]/mimetic/branches/upstream/current/mimetic/contentdisposition.cxx
ViewVC logotype

Contents of /mimetic/branches/upstream/current/mimetic/contentdisposition.cxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 128 - (show annotations)
Sat Feb 25 16:49:20 2006 UTC (15 years, 5 months ago) by gregoa
File size: 3521 byte(s)
[svn-inject] Installing original source of mimetic
1 /***************************************************************************
2 copyright : (C) 2002-2005 by Stefano Barbato
3 email : stefano@codesink.org
4
5 $Id: contentdisposition.cxx,v 1.3 2005/02/24 10:04:24 tat Exp $
6 ***************************************************************************/
7
8 /***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16 #include <mimetic/contentdisposition.h>
17 #include <mimetic/tokenizer.h>
18 #include <mimetic/utils.h>
19
20 namespace mimetic
21 {
22 using namespace std;
23
24 const char ContentDisposition::label[] = "Content-Disposition";
25
26 ContentDisposition::ContentDisposition()
27 {
28 }
29
30
31 ContentDisposition::ContentDisposition(const char* cstr)
32 {
33 set(cstr);
34 }
35
36 ContentDisposition::ContentDisposition(const string& val)
37 {
38 set(val);
39 }
40
41 void ContentDisposition::type(const string& stype)
42 {
43 m_type = stype;
44 }
45
46 const istring& ContentDisposition::type() const
47 {
48 return m_type;
49 }
50
51 const ContentDisposition::ParamList& ContentDisposition::paramList() const
52 {
53 return m_paramList;
54 }
55
56 ContentDisposition::ParamList& ContentDisposition::paramList()
57 {
58 return m_paramList;
59 }
60
61 const string& ContentDisposition::param(const string& field) const
62 {
63 ParamList::const_iterator bit = m_paramList.begin(), eit = m_paramList.end();
64 for(; bit != eit; ++bit)
65 {
66 if(bit->name() == field)
67 return bit->value();
68 }
69 return nullstring;
70 }
71
72 void ContentDisposition::param(const std::string& name, const std::string& val)
73 {
74 ParamList::iterator bit = m_paramList.begin(), eit = m_paramList.end();
75 for(; bit != eit; ++bit)
76 {
77 if(bit->name() == name)
78 {
79 bit->value(val);
80 return;
81 }
82 }
83 m_paramList.push_back(Param(name, val));
84 }
85
86 void ContentDisposition::set(const string& val)
87 {
88 string type;
89 StringTokenizer stok(&val, ";");
90 if(!stok.next(type))
91 return;
92 m_type = type;
93
94 string sparam;
95 while(stok.next(sparam))
96 {
97 Param p(sparam);
98 m_paramList.push_back(p);
99 }
100 }
101
102 string ContentDisposition::str() const
103 {
104 string ostr = m_type;
105 ParamList::const_iterator bit, eit;
106 bit = m_paramList.begin();
107 eit = m_paramList.end();
108 for(; bit != eit; ++bit)
109 ostr += "; " + bit->name() + "=\""
110 + bit->value() + "\"";
111 return ostr;
112 }
113
114 ostream& ContentDisposition::write(ostream& os, int fold) const
115 {
116 os << "Content-Disposition: " << m_type;
117 ParamList::const_iterator bit, eit;
118 bit = m_paramList.begin();
119 eit = m_paramList.end();
120 for(; bit != eit; ++bit)
121 if(fold)
122 os << ";" << crlf << "\t" << bit->name()
123 << "=\"" << bit->value() << "\"";
124 else
125 os << "; " << bit->name() << "=\""
126 << bit->value() << "\"";
127
128 os << crlf;
129 return os;
130 }
131
132
133 FieldValue* ContentDisposition::clone() const
134 {
135 return new ContentDisposition(*this);
136 }
137
138 }

  ViewVC Help
Powered by ViewVC 1.1.26