Esempio n. 1
0
bool Model::getPort(uint32_t* port)
{
	QueryBuilder query(&this->connection);

	query.put("SELECT port FROM configuration ORDER BY conf_id DESC LIMIT 1", false);

	if(mysql_real_query(&this->connection, (const char*)query.getQuery(), (unsigned long)query.getLength())) {
		finishWithError("Model::getPort", &this->connection);
		return false;
	}

	MYSQL_RES *result;

	if((result = mysql_store_result(&this->connection)) == NULL) {
		finishWithError("Model::getPort", &this->connection);
		return false;
	}

	int num_fields = mysql_num_fields(result);
	if(num_fields != 1) {
		finishWithError("Model::getPort", &this->connection);
		return false;
	}

	MYSQL_ROW row;

	if(!(row = mysql_fetch_row(result))) {
		finishWithError("Model::getPort", &this->connection);
		return false;
	}

	*port = atoi(row[0]);

	return true;
}
Esempio n. 2
0
bool Model::doesChatRoomExist(uint32_t chatRoomId, bool *gogel)
{
	printf("GOGEL!!!!!!!!!11one\n");

	QueryBuilder query(&this->connection);

	query.put("SELECT COUNT(chatroom_id) FROM chatrooms WHERE chatroom_id = ", false);
	query.put(chatRoomId);

	MODEL_LOG("Model::doesChatRoomExist: Sending query to database...\n");
	if(mysql_real_query(&this->connection, (const char*)query.getQuery(), (unsigned long)query.getLength())) {
		finishWithError("Model::getLastMessageId", &this->connection);
		return false;
	}

	MYSQL_RES *result;

	MODEL_LOG("Model::doesChatRoomExist: Storing results...\n");
	if((result = mysql_store_result(&this->connection)) == NULL) {
		finishWithError("Model::getLastMessageId", &this->connection);
		return false;
	}

	int num_fields = mysql_num_fields(result);
	MODEL_LOG("Model::doesChatRoomExist: Number of stored fields: %u.\n", num_fields);
	if(num_fields != 1) {
		finishWithError("Model::doesChatRoomExist", &this->connection);
		return false;
	}

	MYSQL_ROW row;

	MODEL_LOG("Model::doesChatRoomExist: Fetching row...\n");
	if(!(row = mysql_fetch_row(result))) {
		finishWithError("Model::doesChatRoomExist", &this->connection);
		return false;
	}

	if(row[0] != NULL) {
		if(atoi(row[0]) == 1) {
			*gogel = true;
		} else {
			*gogel = false;
		}
	} else {
		MODEL_LOG("Model::doesChatRoomExist: WTF?!\n");
		return false;
	}

	return true;
}
Esempio n. 3
0
bool Model::getLastMessageId(uint32_t chatRoomId, uint32_t* messageID)
{
	QueryBuilder query(&this->connection);

	query.put("SELECT MAX(message_id) FROM messages WHERE chatroom_id = ", false);
	query.put(chatRoomId);

	//query.printInfo();

	MODEL_LOG("Model::getLastMessageId: Sending query to database...\n");
	if(mysql_real_query(&this->connection, (const char*)query.getQuery(), (unsigned long)query.getLength())) {
		finishWithError("Model::getLastMessageId", &this->connection);
		return false;
	}

	MYSQL_RES *result;

	MODEL_LOG("Model::getLastMessageId: Storing results...\n");
	if((result = mysql_store_result(&this->connection)) == NULL) {
		finishWithError("Model::getLastMessageId", &this->connection);
		return false;
	}

	int num_fields = mysql_num_fields(result);
	MODEL_LOG("Model::getLastMessageId: Number of stored fields: %u.\n", num_fields);
	if(num_fields != 1) {
		finishWithError("Model::getLastMessageId", &this->connection);
		return false;
	}

	MYSQL_ROW row;

	MODEL_LOG("Model::getLastMessageId: Fetching row...\n");
	if(!(row = mysql_fetch_row(result))) {
		finishWithError("Model::getLastMessageId", &this->connection);
		return false;
	}

	if(row[0] != NULL) {
		*messageID = atoi(row[0]);
	} else {
		*messageID = 0;
	}

	return true;
}
Esempio n. 4
0
bool Model::connect(string host, string user, string password)
{
	if(!mysql_real_connect(&this->connection, host.c_str(), user.c_str(), password.c_str(), MODEL_DB_NAME, 0, NULL, 0))
	{
		finishWithError("Model::connect", &this->connection);
	    return false;
	}

	return true;
}
Esempio n. 5
0
bool Model::getNumOfMessages(uint32_t chatRoomId, uint32_t* numOfMessages)
{
	QueryBuilder query(&this->connection);

	query.put("SELECT COUNT(message_id) FROM messages WHERE chatroom_id = ", false);
	query.put(chatRoomId);

	//query.printInfo();

	if(mysql_real_query(&this->connection, (const char*)query.getQuery(), (unsigned long)query.getLength())) {

		MODEL_LOG("Model::getNumOfMessages: Sending query failed...\n");
		finishWithError("Model::getNumOfMessages", &this->connection);
		return false;
	}

	MYSQL_RES *result;

	if((result = mysql_store_result(&this->connection)) == NULL) {
		MODEL_LOG("Model::getNumOfMessages: Storing resuts failed...\n");
		finishWithError("Model::getNumOfMessages", &this->connection);
		return false;
	}

	int num_fields = mysql_num_fields(result);
	if(num_fields != 1) {
		MODEL_LOG("Model::getNumOfMessages: Reading number of fields failed...\n");
		finishWithError("Model::getNumOfMessages", &this->connection);
		return false;
	}

	MYSQL_ROW row;

	if(!(row = mysql_fetch_row(result))) {
		MODEL_LOG("Model::getNumOfMessages: Fetching row failed...\n");
		finishWithError("Model::getNumOfMessages", &this->connection);
		return false;
	}

	*numOfMessages = atoi(row[0]);

	return true;
}
Esempio n. 6
0
void
CoverFetcher::startFetch()
{
    DEBUG_FUNC_INFO

    // Static license Key. Thanks hydrogen ;-)
    const QString LICENSE( "11ZKJS8X1ETSTJ6MT802" );

    // reset all values
    m_coverAmazonUrls.clear();
    m_coverAsins.clear();
    m_coverUrls.clear();
    m_coverNames.clear();
    m_xml = QString::null;
    m_size = 2;

    if ( m_queries.isEmpty() ) {
        debug() << "m_queries is empty" << endl;
        finishWithError( i18n("No cover found") );
        return;
    }
    QString query = m_queries.front();
    m_queries.pop_front();

    // '&' breaks searching
    query.remove('&');

    QString locale = AmarokConfig::amazonLocale();
    QString tld;

    if( locale == "us" )
        tld = "com";
    else if( locale =="uk" )
        tld = "co.uk";
    else
        tld = locale;

    int mibenum = 106; // utf-8

    QString url;
    url = "http://ecs.amazonaws." + tld
        + "/onca/xml?Service=AWSECommerceService&Version=2007-10-29&Operation=ItemSearch&AssociateTag=webservices-20&AWSAccessKeyId=" + LICENSE
        + "&Keywords=" + KURL::encode_string_no_slash( query, mibenum )
        + "&SearchIndex=Music&ResponseGroup=Small,Images";
    debug() << url << endl;

    KIO::TransferJob* job = KIO::storedGet( url, false, false );
    connect( job, SIGNAL(result( KIO::Job* )), SLOT(finishedXmlFetch( KIO::Job* )) );

    Amarok::StatusBar::instance()->newProgressOperation( job );
}
Esempio n. 7
0
bool Model::newChatRoom(uint32_t chatRoomId)
{
	QueryBuilder query(&this->connection);

	query.put("INSERT INTO `ttchat`.`chatrooms` (`chatroom_id`, `last_message`) VALUES ('", false);
	query.put(chatRoomId);
	query.put("', '0')", false);

	if(mysql_real_query(&this->connection, (const char*)query.getQuery(), (unsigned long)query.getLength())) {
		finishWithError("Model::newChatroom", &this->connection);
		return false;
	}

	return true;
}
Esempio n. 8
0
bool Model::newMessage(uint32_t chatRoomId, Message message)
{
	QueryBuilder query(&this->connection);

	query.put("INSERT INTO `ttchat`.`messages` (`message_id`, `chatroom_id`, `message`, `user_ name`, `creation_date`) VALUES ('", false);
	query.put(message.id);
	query.put("', '", false);
	query.put(chatRoomId);
	query.put("', '", false);
	query.put(message.payload, message.payloadLength, true);
	query.put("', '", false);
	query.put(message.nick, sizeof(message.nick), true);
	query.put("', '", false);
	query.put(message.timestamp);
	query.put("')", false);

	if(mysql_real_query(&this->connection, (const char*)query.getQuery(), (unsigned long)query.getLength())) {
		finishWithError("Model::newMessage", &this->connection);
		return false;
	}

	return true;
}
Esempio n. 9
0
bool Model::getMessage(uint32_t chatRoomId, uint32_t messageId, Message *message)
{
	QueryBuilder query(&this->connection);

	if(!message) return false;

	query.put("SELECT `message_id`, `message`, `user_ name`, `creation_date` FROM messages WHERE chatroom_id = ", false);
	query.put(chatRoomId);
	query.put(" AND message_id = ", false);
	query.put(messageId);

	//query.printInfo();

	MODEL_LOG("Model::getMessage: Sending query to database...\n");
	if(mysql_real_query(&this->connection, (const char*)query.getQuery(), (unsigned long)query.getLength())) {
		finishWithError("Model::getMessage", &this->connection);
		return false;
	}

	MYSQL_RES *result;

	MODEL_LOG("Model::getMessage: Storing results...\n");
	if((result = mysql_store_result(&this->connection)) == NULL) {
		finishWithError("Model::getMessage", &this->connection);
		return false;
	}

	int num_fields;
	MYSQL_ROW row;
	unsigned long *lengths;

	MODEL_LOG("Model::getMessage: Fetching row...\n");
	row = mysql_fetch_row(result);
	if(!row) {
		printf("Model::getMessage: mysql_fetch_row failed.\n");
		finishWithError("Model::getMessage", &this->connection);
		return false;
	}

	MODEL_LOG("Model::getMessage: Getting number of fields...\n");
	num_fields = mysql_num_fields(result);
	if(num_fields != 4) {
		printf("Model::getMessage: mysql_num_fields returned unexpected number of fields (num_fields=%u).\n", num_fields);
		return false;
	}

	MODEL_LOG("Model::getMessage: Fetching lengths...\n");
	lengths = mysql_fetch_lengths(result);

	// Extract id
	if(lengths[0] <= 0) {
		printf("Model::getMessage: length of the ID field should be greater than zero.\n");
		return false;
	}
	message->id = atoi(row[0]);

	// Extract payload
	message->payload = (uint8_t*)malloc(lengths[1]);
	memcpy(message->payload, row[1], lengths[1]);
	message->payloadLength = lengths[1];

	// Extract nick
	if(lengths[2] != MESSAGE_NICK_LENGTH) {
		printf("Model::getMessage: unsupported length of the nick field..\n");
		return false;
	}
	memcpy(message->nick, row[2], MESSAGE_NICK_LENGTH);

	// Extract timestamp
	if(lengths[3] <= 0) {
		printf("Model::getMessage: length of the timestamp field should be greater than zero.\n");
		return false;
	}
	message->timestamp = atoi(row[3]);

	return true;
}