Ejemplo n.º 1
0
void NTPClient::query(const boost::asio::ip::udp::resolver::query &query)
{
    m_response.reset();
    shared_ptr<ConnectionScope> scope(OS_NEW ConnectionScope(m_service, get_this_ptr()));
    scope->extendTimeout(boost::posix_time::milliseconds(m_timeout));
    m_resolver->async_resolve(query, boost::bind(&NTPClient::resolveCallback, get_this_ptr(), boost::asio::placeholders::error, boost::asio::placeholders::iterator, scope));
}
Ejemplo n.º 2
0
shared_ptr<IRCRoom::UserDetails> IRCRoom::ensureUser(shared_ptr<IRCUser> user)
{
	if(user == nullptr)
	{
		OS_ASSERTFALSE();
		return nullptr;
	}

	OS_LOCK(*m_cs);

	shared_ptr<IRCRoom::UserDetails> userDetails;

	Users::iterator i = m_users.find(user->getID());
	if(i != m_users.end())
	{
		userDetails = i->second.second;		
	}
	else
	{
		userDetails.reset(OS_NEW UserDetails(get_this_ptr(), m_cs));
		m_users[user->getID()] = std::make_pair(user, userDetails);
		m_modified = true;
	}

	OS_ASSERT(userDetails != nullptr);
	return userDetails;
}
Ejemplo n.º 3
0
shared_ptr<IRCConnection> IRCSession::openConnection(shared_ptr<TCPSocket> socket)
{
	if(socket == nullptr)
	{
		OS_ASSERTFALSE();
		return nullptr;
	}

	OS_LOCK(m_dataCS);

	shared_ptr<IRCConnection> connection = m_connection.lock();
	if(connection != nullptr)
		return connection;

	shared_ptr<ConnectionsManager> connectionsManager = m_connectionsManager.lock();
	if(connectionsManager == nullptr)
		return nullptr;

	clear();
	
	initLoginRequest();

	connection.reset(OS_NEW IRCConnection(get_this_ptr(), socket, connectionsManager));
	connectionsManager->addConnection(connection, true);
	m_connection = connection;

	return connection;
}
Ejemplo n.º 4
0
bool IRCSession::requestChannelsList()
{
	std::string command;
	command.append("LIST");
	command.append(OS_IRC_COMMANDS_TERMINATOR);

	return addRequest(shared_ptr<IIRCCommand>(OS_NEW IRCCommandRaw(get_this_ptr(), command)), true);
}
Ejemplo n.º 5
0
void IRCSession::notifyCommand(shared_ptr<IIRCCommand> command)
{
	OS_ASSERT(command != nullptr);
	OS_ASSERT(command->getSession() == get_this_ptr());

	OS_LOCK(m_signalsCS);
	m_commandsSignal(command);
}
Ejemplo n.º 6
0
void IRCRoom::notifyModified(const boost::signal<void (shared_ptr<IRCRoom>)> &callback, bool force)
{
	OS_LOCK(*m_cs);

	if(m_modified || force)
	{
		m_modified = false;
		callback(get_this_ptr());
	}
}
Ejemplo n.º 7
0
shared_ptr<LanguageCulture> LanguageCulture::addCulture(const String &id)
{
	Cultures::const_iterator i = m_cultures.find(String(id).to_lower());
	if(i != m_cultures.end())
		return i->second;

	shared_ptr<LanguageCulture> culture(OS_NEW LanguageCulture(get_this_ptr()));
	m_cultures[String(id).to_lower()] = culture;

	return culture;
}
Ejemplo n.º 8
0
bool IHttpDirectory::addDirectory(shared_ptr<IHttpDirectory> directory)
{
	OS_LOCK(m_cs);

	if(directory == nullptr)
		return false;

	OS_EXCEPT_IF(hasDirectory(directory->getName()), "Duplicated directory");

	directory->m_parent = get_this_ptr();
	m_directories.push_back(directory->getName(), directory);

	return true;
}
Ejemplo n.º 9
0
bool IRCSession::leaveChannel(const std::string &channel)
{
	if(channel.empty())
	{
		OS_ASSERTFALSE();
		return false;
	}

	std::string command;
	command.append("PART " + channel);
	command.append(OS_IRC_COMMANDS_TERMINATOR);

	return addRequest(shared_ptr<IIRCCommand>(OS_NEW IRCCommandRaw(get_this_ptr(), command)), true);	
}
Ejemplo n.º 10
0
bool LanguageCulture::getTranslationDerivedAvaible()
{
	shared_ptr<LanguageCulture> current = get_this_ptr();
	for(;;)
	{
		if( (current == nullptr) || (current->getID() == _S("inv")) )
			return false;

		if(current->getTranslationAvaible())
			return true;

		current = current->getParent();
	}

	return false;
}
Ejemplo n.º 11
0
void OMLItem::add(shared_ptr<OMLItem> i)
{
	// Qui compatto + tag "text" consecutivi. Soprattutto per fare che un
	// http://www.alfa[beta]gamma.com venga rappresentato in un'unico 'item', per far s che le regex lo individuino.
	if(i->getTagName() == OMLItem::ITEM_TAG_TEXT)
	{
		if( (m_lastAdded) && (m_lastAdded->getTagName() == OMLItem::ITEM_TAG_TEXT) )
		{
			m_lastAdded->setParam(OMLItem::ITEM_PARAM_TEXT, m_lastAdded->getParam(OMLItem::ITEM_PARAM_TEXT) + i->getParam(OMLItem::ITEM_PARAM_TEXT));
			return;
		}
	}

	i->m_parent = get_this_ptr();
	m_childs.push_back(i);
	m_lastAdded = i;
}
Ejemplo n.º 12
0
bool IRCSession::handleResponse(const std::string &command)
{
	IRCParser parser;
	shared_ptr<IIRCCommand> response = parser.parse(get_this_ptr(), command);
	if(response != nullptr)
	{
		processResponse(response);
		notifyCommand(response);

	    shared_ptr<IIRCCommand> reply = response->getReply();
		if(reply != nullptr)
			addRequest(reply, false);
	}
	else
	{
		OS_LOG_DEBUG(_S("Unknown IRC command '") + command + _S("'"));
	}

	return parser.getAlive();
}
Ejemplo n.º 13
0
HttpPath IHttpDirectory::getPath() const
{
	OS_LOCK(m_cs);

	String path;

	shared_ptr<const IHttpDirectory> directory = get_this_ptr();
	while(directory != nullptr)
	{
		String name = directory->getName();

		OS_ASSERT((name.empty() == false) || (directory->getParent() == nullptr));
		if(name.empty() == false)
			path.insert(0, (OS_HTTP_PATH_SEPARATOR + name).c_str());
		
		directory = directory->getParent();			
	}	

	return path;
}
Ejemplo n.º 14
0
shared_ptr<IRCChannel> IRCSession::ensureChannel(const std::string &name)
{
	OS_LOCK(m_dataCS);

	shared_ptr<IRCChannel> channel;

	Channels::const_iterator i = m_channels.find(name);
	if(i != m_channels.end())
	{
		channel = i->second;
	}
	else
	{
		channel.reset(OS_NEW IRCChannel(get_this_ptr(), name));		
		m_channels[name] = channel;
	}

	OS_ASSERT(channel != nullptr);
	return channel;
}
Ejemplo n.º 15
0
shared_ptr<IRCUser> IRCSession::ensureUser(const std::string &name)
{
	OS_LOCK(m_dataCS);

	shared_ptr<IRCUser> user;

	Users::const_iterator i = m_users.find(name);
	if(i != m_users.end())
	{
		user = i->second;
	}
	else
	{
		user.reset(OS_NEW IRCUser(get_this_ptr(), m_usersID));
		m_users[name] = user;
		m_usersID++;
	}

	OS_ASSERT(user != nullptr);
	return user;
}
Ejemplo n.º 16
0
bool IRCSession::initLoginRequest()
{
	std::string nick = getNick();
	std::string user = getUser();
	if(user.empty())
		user = nick;
	std::string clientName = getClientName();

	OS_ASSERT(nick.empty() == false);
	OS_ASSERT(user.empty() == false);
	OS_ASSERT(clientName.empty() == false);

	std::string command;
	command.append("PASS NOPASS");
	command.append(OS_IRC_COMMANDS_TERMINATOR);	
	command.append("NICK " + nick);
	command.append(OS_IRC_COMMANDS_TERMINATOR);			
	command.append("USER " + user + " USING " + clientName + " :" + nick);
	command.append(OS_IRC_COMMANDS_TERMINATOR);

	return addRequest(shared_ptr<IIRCCommand>(OS_NEW IRCCommandRaw(get_this_ptr(), command)), false);
}
Ejemplo n.º 17
0
void NTPClient::requestCallback(const boost::system::error_code &e, size_t transferredBytes, shared_ptr<ConnectionScope> scope)
{
    scope->cancelTimeout();

    if(e)
        throw boost::system::system_error(e);

    if(transferredBytes != sizeof(Packet))
        OS_EXCEPTION("request error");

    OS_ZEROMEMORY(&m_responsePacket, sizeof(FullPacket));

    boost::asio::ip::udp::endpoint localEndpoint;
    m_socket->async_receive_from(boost::asio::buffer(&m_responsePacket, sizeof(FullPacket)), localEndpoint, boost::bind(&NTPClient::responseCallback, get_this_ptr(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, NTPTime::GetCurrentTime(), scope->extendTimeout()));
}
Ejemplo n.º 18
0
void NTPClient::resolveCallback(const boost::system::error_code &e, boost::asio::ip::udp::resolver::iterator endpoint, shared_ptr<ConnectionScope> scope)
{
    scope->cancelTimeout();

    if(e)
        throw boost::system::system_error(e);

    OS_ZEROMEMORY(&m_requestPacket, sizeof(Packet));
    m_requestPacket.liVnMode = 27; //Encoded representation which represents NTP Client Request & NTP version 3.0 (i.e. LI=0, VN=3, Mode=3)
    m_requestPacket.transmit_time = NTPTime::GetCurrentTime();

    m_socket->async_send_to(boost::asio::buffer(&m_requestPacket, sizeof(Packet)), *endpoint, boost::bind(&NTPClient::requestCallback, get_this_ptr(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, scope->extendTimeout()));
}
Ejemplo n.º 19
0
void LanguageCulture::parse(shared_ptr<XMLNode> node)
{
	if(node->getName() == _S("culture"))
	{
		m_id = node->getAttributeString(_S("id"));

		m_englishName = node->getAttributeString(_S("englishName"));
		m_nativeName = node->getAttributeString(_S("nativeName"));
		m_isNeutralCulture = conversions::from_utf16<bool>(node->getAttributeString(_S("isNeutralCulture")));
		m_defaultNotNeutral = node->getAttributeString(_S("defaultNotNeutral"));
		m_isoName = node->getAttributeString(_S("isoName"));
		m_lcid = conversions::from_utf16<uint32>(node->getAttributeString(_S("LCID")));

		m_defaultTimeOffset = conversions::from_utf16<int32>(node->getAttributeString(_S("defaultTimeOffset")));

		LanguageManager::instance()->getCultures()[String(getID()).to_lower()] = get_this_ptr();

		shared_ptr<XMLNode> nodeCultures = node->getNode(_S("cultures"));
		if(nodeCultures != nullptr)
		{
			shared_ptr<XMLNodes> childs = nodeCultures->getNodes();
			for(XMLNodes::const_iterator i = childs->begin(); i != childs->end(); ++i)
			{
				shared_ptr<XMLNode> subNode = *i;

				OS_ASSERT(subNode->getName() == _S("culture"));

				shared_ptr<LanguageCulture> subCulture(OS_NEW LanguageCulture(get_this_ptr()));
				subCulture->parse(subNode);
				m_cultures[String(subCulture->getID()).to_lower()] = subCulture;
			}
		}

		shared_ptr<XMLNode> nodeDataTimeFormatInfo = node->getNode(_S("dateTimeFormatInfo"));
		if(nodeDataTimeFormatInfo != nullptr)
		{
			//m_calendarWeekRule = nodeDataTimeFormatInfo->getAttributeString(_S("calendarWeekRule"));
			//m_dateSeparator = nodeDataTimeFormatInfo->getAttributeString(_S("dateSeparator"));
			//m_timeSeparator = nodeDataTimeFormatInfo->getAttributeString(_S("timeSeparator"));
			m_amDesignator = nodeDataTimeFormatInfo->getAttributeString(_S("amDesignator"));
			m_pmDesignator = nodeDataTimeFormatInfo->getAttributeString(_S("pmDesignator"));

			m_longDatePattern = nodeDataTimeFormatInfo->getAttributeString(_S("longDatePattern"));
			m_shortDatePattern = nodeDataTimeFormatInfo->getAttributeString(_S("shortDatePattern"));
			m_longTimePattern = nodeDataTimeFormatInfo->getAttributeString(_S("longTimePattern"));
			m_shortTimePattern = nodeDataTimeFormatInfo->getAttributeString(_S("shortTimePattern"));

			shared_ptr<XMLNode> nodeDayNames = nodeDataTimeFormatInfo->getNode(_S("dayNames"));
			if(nodeDayNames != nullptr)
			{
				shared_ptr<XMLNodes> childs = nodeDayNames->getNodes();
				for(XMLNodes::const_iterator i = childs->begin(); i != childs->end(); ++i)
				{
					shared_ptr<XMLNode> nodeDayName = *i;

					uint32 index = conversions::from_utf16<uint32>(nodeDayName->getAttributeString(_S("index")));
					String name = nodeDayName->getAttributeString(_S("name"));
					String abbreviated = nodeDayName->getAttributeString(_S("abbreviated"));

					OS_ASSERT(index < 7);
					m_dayNamesLong[index] = name;
					m_dayNamesShort[index] = abbreviated;
				}
			}

			shared_ptr<XMLNode> nodeMonthNames = nodeDataTimeFormatInfo->getNode(_S("monthNames"));
			{
				shared_ptr<XMLNodes> childs = nodeMonthNames->getNodes();
				for(XMLNodes::const_iterator i = childs->begin(); i != childs->end(); ++i)
				{
					shared_ptr<XMLNode> nodeMonthName = *i;

					uint32 index = conversions::from_utf16<uint32>(nodeMonthName->getAttributeString(_S("index")));
					String name = nodeMonthName->getAttributeString(_S("name"));
					String abbreviated = nodeMonthName->getAttributeString(_S("abbreviated"));

					OS_ASSERT(index < 12);
					m_monthNamesLong[index] = name;
					m_monthNamesShort[index] = abbreviated;
				}
			}

		}
	}
}
Ejemplo n.º 20
0
void ExtensionsExtension::executeContexts(bool loaded)
{
	for(CodeContexts::const_iterator i = m_contexts.begin(); i != m_contexts.end(); (*i)->execute(get_this_ptr(), loaded), ++i);
}
Ejemplo n.º 21
0
bool ExtensionsExtension::init(const ExtensionID &id, const Path &path)
{
	OS_ASSERT(path.empty() == false);
	OS_ASSERT(m_path.empty());

	m_path = path;

	//String filename = utils::makeFilePath(path, id.toUTF16() + ".xml"); // 0.13
	String filename = utils::makeFilePath(path, OS_MANIFESTXML); // 0.14
	if(FileSystem::instance()->fileExists(filename) == false)
		return false;
	
	shared_ptr<XMLDocument> document(OS_NEW XMLDocument(XMLSchema::fromFile(utils::makeFilePath(utils::makeFolderPath(Options::instance()->getSharePath(), OS_SCHEMAS_PATH), OS_EXTENSIONS_EXTENSION_SCHEMA))));
	if(document->parseFile(filename) == false)
		return false;

	String languagesPath = utils::makeFolderPath(path.path(), OS_LANGUAGES_PATH);
	if(FileSystem::instance()->directoryExists(languagesPath))
	{
		m_languageFolder.reset(OS_NEW LanguageFolder());
		m_languageFolder->addPath(languagesPath);
	}

	String htdocsPath = utils::makeFolderPath(path.path(), OS_HTDOCS_PATH);
	if(FileSystem::instance()->directoryExists(htdocsPath))
	{
		// TODO: Qui dovrei fare un'opzione a livello di xml extension, che stabilisce il nome della virtual-directory. Se omesso, è l'ID.
		// Per ora, forzo l'unico caso in cui mi servirebbe.
		String virtualName = id.toUTF16();
		if(id.toUTF16() == OS_EXTENSIONS_CORE)
			virtualName = OS_HTDOCS_PATH;

		m_httpDirectory.reset(OS_NEW HttpPhysicalDirectory(virtualName, htdocsPath));
	}

	// Auto-discovery IdeSkinSimple
	String skinsPath = utils::makeFolderPath(path.path(), "skins");
	{
		if(FileSystem::instance()->directoryExists(skinsPath))
		{
			StringList skins;
			FileSystem::instance()->getFiles(skinsPath, skins, false);
			for(StringList::const_iterator i = skins.begin(); i != skins.end(); ++i)
			{
				String config = "/skins/" + *i;
				String title = FileSystem::instance()->getFileTitle(*i);
				shared_ptr<IdeSkinSimple> skin(OS_NEW IdeSkinSimple());
				if(skin->init(get_this_ptr(), config, title))
					m_skins.push_back(skin);
			}
		}
	}

	shared_ptr<XMLNode> root = document->getRoot();

	if(root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_ID) != id.getString()) // Ensure that the directory name is equal to ID.
		return false;

	m_id = id;
	m_name = root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_NAME);	
	m_description = root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_DESCRIPTION);
	m_content = root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_CONTENT);
	m_category = root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_CATEGORY);
	m_tags = root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_TAGS);
	m_trust = root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_TRUST);
	m_author = root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_AUTHOR);
	m_versionCode = root->getAttributeInt32(OS_EXTENSION_XML_NODE_ROOT_VERSION_CODE);
	m_versionName = root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_VERSION_NAME);
	m_compatibility = root->getAttributeInt32(OS_EXTENSION_XML_NODE_ROOT_COMPATIBILITY);
	/*
	if(m_version.fromString(root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_VERSION).to_ascii()) == false)
		return false;
	String compatibility = root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_COMPATIBILITY);
	if( (compatibility.empty() == false) && (m_compatibility.fromString(compatibility.to_ascii()) == false) )
		return false;
	*/
	m_homepage = root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_HOMEPAGE);
	m_icon = root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_ICON);
	m_logo = root->getAttributeString(OS_EXTENSION_XML_NODE_ROOT_LOGO);
	
	NotificationsManager::instance()->notify(_S("Loading extension: ") + m_name);
	
	shared_ptr<XMLNode> nodeFiles = document->getRoot()->getNode(OS_EXTENSION_XML_NODE_SCRIPTS);
	if(nodeFiles != nullptr)
	{
		shared_ptr<XMLNodes> files = nodeFiles->getNodes();
		for(XMLNodes::const_iterator i = files->begin(); i != files->end(); ++i)
		{
			String scriptPath = utils::makeFilePath(path, (*i)->getAttributeString(OS_EXTENSION_XML_NODE_SCRIPT_PATH));
			String scriptLanguage = (*i)->getAttributeString(OS_EXTENSION_XML_NODE_SCRIPT_LANGUAGE);

			shared_ptr<IExtensionsCodeProvider> codeProvider = ExtensionsSystem::instance()->getCodeProvider(scriptLanguage);
			if(codeProvider == nullptr)
			{
				OS_LOG_ERROR(_S("Invalid script language '") + scriptLanguage + _S("'"));
				return false;
			}

			shared_ptr<IExtensionsCodeContext> context = codeProvider->createContext();
			if(context == nullptr)
			{
				OS_LOG_ERROR(_S("Cannot create context for script language '") + scriptLanguage + _S("'"));
				return false;
			}

			if(context->parseFile(scriptPath))
				m_contexts.push_back(context);				
			else
				OS_LOG_ERROR(_S("Cannot parse extension file '") + scriptPath + _S("'"));
		}
	}
	
	return true;
}
Ejemplo n.º 22
0
String OMLItem::getOsml(shared_ptr<OMLContext> context)
{
	return OMLManager::instance()->processItemForOsml(get_this_ptr(), context);
}
Ejemplo n.º 23
0
String OMLItem::getHtml(shared_ptr<OMLContext> context)
{
	// Chiedo al Manager di convertilo.
	return OMLManager::instance()->processItemForHtml(get_this_ptr(), context);
}