| 100 | | class fld_value : public structured_value |
| 101 | | { |
| 102 | | std::string fld; |
| 103 | | db::user::const_ptr u; |
| 104 | | public: |
| 105 | | fld_value(std::string fld, db::user::const_ptr u) |
| 106 | | : fld(fld), u(u) |
| 107 | | {} |
| 108 | | value::const_ptr get(std::string var) const { |
| 109 | | size_t col = fld.find(':'); |
| 110 | | value::ptr rv; |
| 111 | | /**/ if (var == "name") |
| 112 | | rv.reset(new string_value |
| 113 | | (quote(fld.substr(0,col), false))); |
| 114 | | else if (var == "body") |
| 115 | | { |
| 116 | | std::string s = fld.substr(col+1); |
| 117 | | s = decode_unstructured(s); |
| 118 | | rv.reset(new string_value(quote(s, !u))); |
| 119 | | } |
| 120 | | return rv; |
| 121 | | } |
| 122 | | }; |
| 123 | | |
| 124 | | class hdr_seq : public sequential_value |
| 125 | | { |
| 126 | | msg::msg::const_ptr m; |
| 127 | | db::user::const_ptr u; |
| 128 | | |
| 129 | | class vit : public virtual_iterator |
| 130 | | { |
| 131 | | msg::msg::field_iterator it; |
| 132 | | mutable value::const_ptr cur; |
| 133 | | db::user::const_ptr u; |
| 134 | | |
| 135 | | vit(msg::msg::field_iterator it, value::const_ptr cur, |
| 136 | | db::user::const_ptr u) |
| 137 | | : it(it) |
| 138 | | , cur(cur) |
| 139 | | , u(u) |
| 140 | | {} |
| 141 | | public: |
| 142 | | vit(msg::msg::field_iterator it, db::user::const_ptr u) |
| 143 | | : it(it) |
| 144 | | , u(u) |
| 145 | | {} |
| 146 | | virtual_iterator *clone() const { |
| 147 | | return new vit(it, cur, u); |
| 148 | | } |
| 149 | | value::const_ptr get() const { |
| 150 | | if (!cur) cur.reset(new fld_value(*it, u)); |
| 151 | | return cur; |
| 152 | | } |
| 153 | | void next() { |
| 154 | | it++; |
| 155 | | cur.reset(); |
| 156 | | } |
| 157 | | bool eq(const virtual_iterator &o_) const { |
| 158 | | const vit *o = dynamic_cast<const vit *>(&o_); |
| 159 | | return o ? it == o->it : false; |
| 160 | | } |
| 161 | | }; |
| 162 | | |
| 163 | | public: |
| 164 | | hdr_seq(msg::msg::const_ptr m, db::user::const_ptr u) |
| 165 | | : m(m) |
| 166 | | , u(u) |
| 167 | | {} |
| 168 | | const_iterator begin() const { |
| 169 | | return const_iterator |
| 170 | | (new vit(m->fields_begin(), u)); |
| 171 | | } |
| 172 | | const_iterator end() const { |
| 173 | | return const_iterator |
| 174 | | (new vit(m->fields_end(), u)); |
| 175 | | } |
| 176 | | }; |