+bool CONFIGPROTO::Bind()
+{
+ const hostent * he = gethostbyname(m_bindAddress.c_str());
+ if (he == NULL)
+ {
+ m_errorStr = "Failed to resolve name '" + m_bindAddress + "': '" + hstrerror(h_errno) + "'.";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
+ m_logger(m_errorStr);
+ return false;
+ }
+
+ char ** ptr = he->h_addr_list;
+ while (*ptr != NULL)
+ {
+ struct sockaddr_in listenAddr;
+ listenAddr.sin_family = PF_INET;
+ listenAddr.sin_port = htons(m_port);
+ listenAddr.sin_addr.s_addr = *reinterpret_cast<in_addr_t *>(*ptr);
+
+ printfd(__FILE__, "Trying to bind to %s:%d\n", inet_ntostring(listenAddr.sin_addr.s_addr).c_str(), m_port);
+
+ if (bind(m_listenSocket, reinterpret_cast<sockaddr *>(&listenAddr), sizeof(listenAddr)) == 0)
+ return true;
+
+ m_errorStr = std::string("Cannot bind listen socket: '") + strerror(errno) + "'.";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
+ m_logger(m_errorStr);
+
+ ++ptr;
+ }
+
+ return false;
+}
+
+void CONFIGPROTO::RegisterParsers()
+{
+ assert(m_settings != NULL);
+ assert(m_store != NULL);
+ assert(m_admins != NULL);
+ assert(m_users != NULL);
+ assert(m_tariffs != NULL);
+ assert(m_services != NULL);
+ assert(m_corporations != NULL);
+
+ SP::GET_SERVER_INFO::FACTORY::Register(m_registry, *m_settings, *m_users, *m_tariffs);
+
+ SP::GET_ADMINS::FACTORY::Register(m_registry, *m_admins);
+ SP::ADD_ADMIN::FACTORY::Register(m_registry, *m_admins);
+ SP::DEL_ADMIN::FACTORY::Register(m_registry, *m_admins);
+ SP::CHG_ADMIN::FACTORY::Register(m_registry, *m_admins);
+
+ SP::GET_TARIFFS::FACTORY::Register(m_registry, *m_tariffs);
+ SP::ADD_TARIFF::FACTORY::Register(m_registry, *m_tariffs);
+ SP::DEL_TARIFF::FACTORY::Register(m_registry, *m_tariffs, *m_users);
+ SP::CHG_TARIFF::FACTORY::Register(m_registry, *m_tariffs);
+
+ SP::GET_USERS::FACTORY::Register(m_registry, *m_users);
+ SP::GET_USER::FACTORY::Register(m_registry, *m_users);
+ SP::ADD_USER::FACTORY::Register(m_registry, *m_users);
+ SP::DEL_USER::FACTORY::Register(m_registry, *m_users);
+ SP::CHG_USER::FACTORY::Register(m_registry, *m_users, *m_store, *m_tariffs);
+ SP::CHECK_USER::FACTORY::Register(m_registry, *m_users);
+
+ SP::GET_SERVICES::FACTORY::Register(m_registry, *m_services);
+ SP::GET_SERVICE::FACTORY::Register(m_registry, *m_services);
+ SP::ADD_SERVICE::FACTORY::Register(m_registry, *m_services);
+ SP::DEL_SERVICE::FACTORY::Register(m_registry, *m_services);
+ SP::CHG_SERVICE::FACTORY::Register(m_registry, *m_services);
+
+ SP::SEND_MESSAGE::FACTORY::Register(m_registry, *m_users);
+
+ SP::AUTH_BY::FACTORY::Register(m_registry, *m_users);
+
+ SP::USER_INFO::FACTORY::Register(m_registry, *m_users);
+}
+