| 149 | } // namespace |
| 150 | |
| 151 | std::string parse(Value root, connection_options& opts) { |
| 152 | std::ostringstream addr; |
| 153 | |
| 154 | validate(objectValue, root, "configuration"); |
| 155 | |
| 156 | string scheme = get_string(root, "scheme", "amqps"); |
| 157 | if (scheme != "amqp" && scheme != "amqps") { |
| 158 | throw err(msg() << "'scheme' must be \"amqp\" or \"amqps\""); |
| 159 | } |
| 160 | |
| 161 | string host = get_string(root, "host", "localhost"); |
| 162 | opts.virtual_host(host.c_str()); |
| 163 | addr << host << ":"; |
| 164 | |
| 165 | Value port = root.get("port", scheme); |
| 166 | switch (port.type()) { |
| 167 | case stringValue: |
| 168 | addr << port.asString(); break; |
| 169 | case intValue: |
| 170 | case uintValue: |
| 171 | addr << port.asUInt(); break; |
| 172 | default: |
| 173 | throw err(msg() << "'port' expected string or uint, found " << port.type()); |
| 174 | } |
| 175 | |
| 176 | Value user = get(stringValue, root, "user"); |
| 177 | if (!user.isNull()) opts.user(user.asString()); |
| 178 | Value password = get(stringValue, root, "password"); |
| 179 | if (!password.isNull()) opts.password(password.asString()); |
| 180 | |
| 181 | parse_sasl(root, opts); |
| 182 | parse_tls(scheme, root, opts); |
| 183 | |
| 184 | return addr.str(); |
| 185 | } |
| 186 | |
| 187 | bool config_file(std::ifstream& f, std::string& name) { |
| 188 | const char *env_path = getenv(ENV_VAR.c_str()); |