| 138 | } |
| 139 | |
| 140 | int ErasureCodeLrc::layers_parse(const string &description_string, |
| 141 | json_spirit::mArray description, |
| 142 | ostream *ss) |
| 143 | { |
| 144 | int position = 0; |
| 145 | for (vector<json_spirit::mValue>::iterator i = description.begin(); |
| 146 | i != description.end(); |
| 147 | ++i, position++) { |
| 148 | if (i->type() != json_spirit::array_type) { |
| 149 | stringstream json_string; |
| 150 | json_spirit::write(*i, json_string); |
| 151 | *ss << "each element of the array " |
| 152 | << description_string << " must be a JSON array but " |
| 153 | << json_string.str() << " at position " << position |
| 154 | << " is of type " << i->type() << " instead" << std::endl; |
| 155 | return ERROR_LRC_ARRAY; |
| 156 | } |
| 157 | json_spirit::mArray layer_json = i->get_array(); |
| 158 | ErasureCodeProfile profile; |
| 159 | int index = 0; |
| 160 | for (vector<json_spirit::mValue>::iterator j = layer_json.begin(); |
| 161 | j != layer_json.end(); |
| 162 | ++j, ++index) { |
| 163 | if (index == 0) { |
| 164 | if (j->type() != json_spirit::str_type) { |
| 165 | stringstream element; |
| 166 | json_spirit::write(*j, element); |
| 167 | *ss << "the first element of the entry " |
| 168 | << element.str() << " (first is zero) " |
| 169 | << position << " in " << description_string |
| 170 | << " is of type " << (*j).type() << " instead of string" << std::endl; |
| 171 | return ERROR_LRC_STR; |
| 172 | } |
| 173 | layers.push_back(Layer(j->get_str())); |
| 174 | Layer &layer = layers.back(); |
| 175 | layer.chunks_map = j->get_str(); |
| 176 | } else if(index == 1) { |
| 177 | Layer &layer = layers.back(); |
| 178 | if (j->type() != json_spirit::str_type && |
| 179 | j->type() != json_spirit::obj_type) { |
| 180 | stringstream element; |
| 181 | json_spirit::write(*j, element); |
| 182 | *ss << "the second element of the entry " |
| 183 | << element.str() << " (first is zero) " |
| 184 | << position << " in " << description_string |
| 185 | << " is of type " << (*j).type() << " instead of string or object" |
| 186 | << std::endl; |
| 187 | return ERROR_LRC_CONFIG_OPTIONS; |
| 188 | } |
| 189 | if (j->type() == json_spirit::str_type) { |
| 190 | int err = get_json_str_map(j->get_str(), *ss, &layer.profile); |
| 191 | if (err) |
| 192 | return err; |
| 193 | } else if (j->type() == json_spirit::obj_type) { |
| 194 | json_spirit::mObject o = j->get_obj(); |
| 195 | |
| 196 | for (map<string, json_spirit::mValue>::iterator i = o.begin(); |
| 197 | i != o.end(); |