+namespace SGCONF
+{
+
+class CONFIG_ACTION : public ACTION
+{
+ public:
+ CONFIG_ACTION(CONFIG & config,
+ const std::string & paramDescription)
+ : m_config(config),
+ m_description(paramDescription)
+ {}
+
+ virtual ACTION * Clone() const { return new CONFIG_ACTION(*this); }
+
+ virtual std::string ParamDescription() const { return m_description; }
+ virtual std::string DefaultDescription() const { return ""; }
+ virtual OPTION_BLOCK & Suboptions() { return m_suboptions; }
+ virtual PARSER_STATE Parse(int argc, char ** argv);
+
+ private:
+ CONFIG & m_config;
+ std::string m_description;
+ OPTION_BLOCK m_suboptions;
+
+ void ParseCredentials(const std::string & credentials);
+ void ParseHostAndPort(const std::string & hostAndPort);
+};
+
+PARSER_STATE CONFIG_ACTION::Parse(int argc, char ** argv)
+{
+if (argc == 0 ||
+ argv == NULL ||
+ *argv == NULL)
+ throw ERROR("Missing argument.");
+char * pos = strchr(*argv, '@');
+if (pos != NULL)
+ {
+ ParseCredentials(std::string(*argv, pos));
+ ParseHostAndPort(std::string(pos + 1));
+ }
+else
+ {
+ ParseHostAndPort(std::string(*argv));
+ }
+return PARSER_STATE(false, --argc, ++argv);
+}
+
+void CONFIG_ACTION::ParseCredentials(const std::string & credentials)
+{
+std::string::size_type pos = credentials.find_first_of(':');
+if (pos != std::string::npos)
+ {
+ m_config.userName = credentials.substr(0, pos);
+ m_config.userPass = credentials.substr(pos + 1);
+ }
+else
+ {
+ m_config.userName = credentials;
+ }
+}
+
+void CONFIG_ACTION::ParseHostAndPort(const std::string & hostAndPort)
+{
+std::string::size_type pos = hostAndPort.find_first_of(':');
+if (pos != std::string::npos)
+ {
+ m_config.server = hostAndPort.substr(0, pos);
+ uint16_t port = 0;
+ if (str2x(hostAndPort.substr(pos + 1), port))
+ throw ERROR("Invalid port value: '" + hostAndPort.substr(pos + 1) + "'");
+ m_config.port = port;
+ }
+else
+ {
+ m_config.server = hostAndPort;
+ }
+}
+
+inline
+CONFIG_ACTION * MakeParamAction(CONFIG & config,
+ const std::string & paramDescription)
+{
+return new CONFIG_ACTION(config, paramDescription);
+}
+
+} // namespace SGCONF
+