src/CLIParser.h
branchv_0
changeset 20 ad21bff45051
parent 17 b9dcb7aa75e1
child 29 97fe991ad2cb
equal deleted inserted replaced
19:7a9a52e949b9 20:ad21bff45051
    83 		using namespace options;
    83 		using namespace options;
    84 
    84 
    85 		// Parse the connection string and convert it to options:
    85 		// Parse the connection string and convert it to options:
    86 		if (connectionString.size()) {
    86 		if (connectionString.size()) {
    87 			std::string connectionStringBytes = convertor.to_bytes(connectionString);
    87 			std::string connectionStringBytes = convertor.to_bytes(connectionString);
    88 			std::regex pattern("(tcp|udp|sctp)://(([^:]+)|\\[([0-9a-fA-F:]+)\\]):([0-9]+)|(uds)://(.*)");
    88 			std::regex pattern("(tcp|udp|sctp)://(([^:]+)|\\[([0-9a-fA-F:]+(%[a-zA-Z0-9]+))\\]):([0-9]+)|(uds)://(.*)");
    89 			//                  1                23          4                   5        6       7
    89 			//                  1                23          4             5                    6        7       8
    90 			std::smatch match;
    90 			std::smatch match;
    91 			if (std::regex_match(connectionStringBytes, match, pattern)) {
    91 			if (std::regex_match(connectionStringBytes, match, pattern)) {
    92 				setIfMissing(c.options, OPTION_PROTOCOL, match[1], false);
    92 				setIfMissing(c.options, OPTION_PROTOCOL, match[1], false);
    93 				setIfMissing(c.options, OPTION_PROTOCOL, match[6], false);
    93 				setIfMissing(c.options, OPTION_PROTOCOL, match[7], false);
    94 				setIfMissing(c.options, OPTION_HOST, match[3], false);
    94 				setIfMissing(c.options, OPTION_HOST, match[3], false);
    95 				setIfMissing(c.options, OPTION_HOST, match[4], false);
    95 				setIfMissing(c.options, OPTION_HOST, match[4], false);
    96 				setIfMissing(c.options, OPTION_PORT, match[5], false);
    96 				setIfMissing(c.options, OPTION_PORT, match[6], false);
    97 				setIfMissing(c.options, OPTION_PATH, match[7], false);
    97 				setIfMissing(c.options, OPTION_PATH, match[8], false);
    98 				if (match[1] == PROTOCOL_TCP) setIfMissing(c.options, OPTION_MODE, MODE_STREAM);
    98 				if (match[1] == PROTOCOL_TCP) setIfMissing(c.options, OPTION_MODE, MODE_STREAM);
    99 			} else {
    99 			} else {
   100 				throw relpipe::cli::RelpipeCLIException(L"Invalid connection string: " + connectionString, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
   100 				throw relpipe::cli::RelpipeCLIException(L"Invalid connection string: " + connectionString, relpipe::cli::CLI::EXIT_CODE_BAD_CLI_ARGUMENTS);
   101 			}
   101 			}
   102 		}
   102 		}