Exemplo n.º 1
0
QString MusicDatabase::getFilename(int id) {

    if (this->connect()) {
        QString sqlQuery = QString("SELECT file_name FROM rebetikosongs.song WHERE rec_id = :id");

        // Execute the query
        QSqlQuery resultSet;
        resultSet.prepare( sqlQuery );
        resultSet.bindValue(":id", id);
        resultSet.exec();

        if (resultSet.size() > 0) {

            QString value;
            if (resultSet.next()) {
                QString normalized = normalizeUrl(resultSet.value(0).toString());
                value = Song::base_filename + normalized;
            }

            // Disconnect from database
            this->disconnect();

            // Return value
            return value;

        }

    }

    return QString("");
}
Exemplo n.º 2
0
 SourceCode *Interpreter::loadSourceCode(QString url) {
     url = normalizeUrl(url);
     SourceCode *source;
     if(!(source = sourceCodeIsAlreadyLoaded(url))) {
         source = LIU_SOURCE_CODE(url);
         sourceCodes()->set(Text::make(url), source);
         source->parse();
     }
     return source;
 }
Exemplo n.º 3
0
QHash<int, QString> MusicDatabase::getFilename(QList<int> ids) {

    QHash<int, QString> result;

    // Try to connect to database
    if (this->connect()) {

        // Build a string with all the parameters for binding
        QStringList inValuesBindings;
        for (int i = 0; i < ids.count(); i++) {

            inValuesBindings.push_back( QString(":id%1").arg(i) );

        }

        // Make the query
        QString sqlQuery = QString("SELECT file_name, rec_id FROM rebetikosongs.song WHERE rec_id IN (") + inValuesBindings.join(", ") + QString(")");

        // Prepare the query
        QSqlQuery resultSet;
        resultSet.prepare( sqlQuery );

        // Bind all values
        for (int i = 0; i < ids.count(); i++) {
            resultSet.bindValue(QString(":id%1").arg(i), ids[i]);
        }

        // Execute the query
        resultSet.exec();

        if (resultSet.size() > 0) {

            // Loop through result set and populate hash table with result records
            while (resultSet.next()) {
                QString value = resultSet.value(0).toString();
                int id = resultSet.value(1).toInt();
                result[id] = Song::base_filename + normalizeUrl( value );
            }

        }

        // Free result?
        resultSet.finish();

        // Disconnect from database
        this->disconnect();

    }

    return result;

}
Exemplo n.º 4
0
string CHtml::normalizeUrl(TRouteStruct & url)
{
	if (url.path.empty()) {
		return normalizeUrl("");
	} else {
		CController * controller = dynamic_cast<CController*>(Cws::app()->getComponent("controller"));
		if (controller) {
			return controller->createUrl(url);
		} else {
			return Cws::app()->createUrl(url);
		}
	}
}
Exemplo n.º 5
0
 SourceCode *Interpreter::sourceCodeIsAlreadyLoaded(QString url) {
     url = normalizeUrl(url);
     return sourceCodes()->hasKey(Text::make(url));
 }
Exemplo n.º 6
0
/**
@briesf 주어진 Domain/URL 이 statfilter 목록에 포함되는지 확인하고,
포함되는 경우 단말에 보낼 메시지를 버퍼에 저장하고, return 1.

@param keystr  DOMAIN/URL/MDN 값. 입력치.
@param notimesg 이 함수의 결과로 얻는 텍스트 메시지. 단말기에 전달되어야 할 공지 내용.
@param iport DOMAIN 의 port ?
@param iType keystr이 DOMAIN/URL/MDN 중 어느 타입인지 표시하는 것. URL-1, DOMAIN-2, MDN-3

@return 0 statfilter 목록에 포함되지 않는 경우.
*/
bool StatFilter::isBlocked(int iType , char *keystr, int iport,  char* notimesg)
{

	char strhashkey[256];

	notimesg[0] = 0;


	/**
	DOMAIN type 인 경우에는 keystr 값은  포트값이 포함되지 않는다. $HOST
	URL type 경우에는  keystr 값은  포트값이 포함된 URL 이다.  $EURL

	테스트 결과, 지오텔의 소스에서
	$HOST (즉, 도메인, type==2) 에는 포트값이 포함되지 않는다.  포트값이 80이든 아니든.
	$URL (즉, URL type==1) 에는 포트값이 포함된다 (당연).

	*/


	#ifdef DEBUG_NEWSTAT
	printf ("##STAT: org=%s type=%d port =%d : %s\n", keystr, iType, iport, hashkey);
	#endif

	int	notiIndex = -1;
	if (iType==FILTER_BY_MDN)
	{
		intMDN_t mdnKey = Util::phonenum2int(keystr);
		
		map<intMDN_t,  int>::const_iterator pos = mdnList.find(mdnKey);
		if (pos != mdnList.end())
		{
			notiIndex = pos->second;
		}
		if (notiIndex != -1) PAS_INFO3("StatFilter: MDN %s, %d, Res=%d", keystr, mdnKey, notiIndex);
		if (tracelog) tracelog->logprint(LVL_DEBUG, "MDN %s, %d, Res=%d\n", keystr, mdnKey, notiIndex);
		
	}
	else if (iType==FILTER_BY_URL)
	{
		//  Domain 이면 "호스트:포트" 형태의 키값을 만들어야 한다.
		// URL, DOMAIN 의 http:// 를 제거한다.
		normalizeUrl(keystr, iType, iport, strhashkey, sizeof(strhashkey)-1);
		string hashkey(strhashkey);
		
		map<string,  int>::const_iterator pos = urlList.find(hashkey);
		if (pos != urlList.end())
		{
			notiIndex = pos->second;
		}

		if (notiIndex != -1) PAS_INFO3("StatFilter: URL %s, %s, Res=%d", keystr, strhashkey, notiIndex);
		if (tracelog) tracelog->logprint(LVL_DEBUG, "URL %s, %s, Res=%d\n", keystr, strhashkey, notiIndex);
	}
	else if (iType==FILTER_BY_DOMAIN)
	{
		normalizeUrl(keystr, iType, iport, strhashkey, sizeof(strhashkey)-1);
		string hashkey(strhashkey);
		
		map<string,  int>::const_iterator pos = domainList.find(hashkey);
		if (pos != domainList.end())
		{
			notiIndex = pos->second;
		}
		if (notiIndex != -1) PAS_INFO3("StatFilter: DOMAIN %s, %s, Res=%d", keystr, strhashkey, notiIndex);
		if (tracelog) tracelog->logprint(LVL_DEBUG, "DOMAIN %s, %s, Res=%d\n", keystr, strhashkey, notiIndex);
	
	}
	

	if (notiIndex < 0)
		return false;
		
	if (BETWEEN(notiIndex, 0,  MAX_NOTIMESG))
	{
		strcpy(notimesg, notiMesgs[notiIndex].c_str());
	}

	if (notimesg[0] ) 
		return true;
	else 
		return false;
}
Exemplo n.º 7
0
/**
(k_)stat.cfg 의 한 라인을 파싱하고 처리하는 중요 함수.
readStatCfg()  에 있던 것을 하나의 함수로 분리함. 2006/8/11
*/
int StatFilter::parseLine(char *oneline)
{
	StrSplit split(3, 255);
	char *ch = 0;
	char url[256];
	
	ch = StrUtil::skipSpace(oneline);
	if (*ch == '#' || *ch == 0) return 0;

	//printf("%s\n", oneline);
	split.split(ch);
	//split.print();
	
	if (split.numFlds() < 3) return 0;
	
	char *first = split.fldVal(0);

	if (first[0] == 'D') {	/*-- filtering by Domain */
		
		normalizeUrl(split.fldVal(2), FILTER_BY_DOMAIN, 0, url, sizeof(url)-1);
		string urlkey(url);		
		int msgid =  (int)strtol(split.fldVal(1), 0, 10);
		domainList[urlkey] = msgid;
			
		//printf("Domain: %s %d\n", url, msgid);

	}
	else    if (first[0] == 'U') { /*-- filtering by URL */

		normalizeUrl(split.fldVal(2), FILTER_BY_URL, 0, url, sizeof(url)-1);

		string domainkey(url);		
		int msgid =  (int)strtol(split.fldVal(1), 0, 10);
		urlList[domainkey] = msgid;
			
		//printf("URL: %s %d\n", url, msgid);
	}
	else    if (first[0] == 'M') { /*-- filtering by MDN */

		intMDN_t mdnKey = Util::phonenum2int(split.fldVal(2));
		int msgid =  (int)strtol(split.fldVal(1), 0, 10);
		mdnList[mdnKey] = msgid;
		
		//printf("MDN: %d %d\n", mdnKey, msgid);
	}
	
	else    if (ISDIGIT(first[0])) {
		/*-- 공지 메시지 목록 저장  */
		int idx = (int)strtol(first, 0, 10);
		char *mesg = StrUtil::skipDigit(ch);
		mesg = StrUtil::skipSpace(mesg);

		if (idx <= MAX_NOTIMESG)
			notiMesgs[idx] = string(mesg);

	}
	else {
		return 0;
	}
	
	return 1;
}
Exemplo n.º 8
0
// . find the indirect matches in the list which match a sub path
//   of the url
long  Catdb::getIndirectMatches ( RdbList  *list ,
                                  Url      *url ,
                                  char    **matchRecs ,
                                  long     *matchRecSizes ,
                                  long      maxMatches ,
                                  char     *coll,
                                  long      collLen) {
    char  path[MAX_URL_LEN+1];
    long  pathLen;
    Url   partialUrl;
    key_t partialUrlKey;
    // start with the whole url...include real catid in indirect
    memcpy(path, url->getUrl(), url->getUrlLen());
    pathLen = url->getUrlLen();
    // loop looking for partial matches
    char *data       = NULL;
    long  dataSize   = 0;
    long  numMatches = 0;
    while ( numMatches < maxMatches ) {
        // make the partial url
        partialUrl.set(path, pathLen, true);
        normalizeUrl(&partialUrl, &partialUrl);
        // make the next key
        partialUrlKey = makeKey ( &partialUrl, false );
        // search for it
        listSearch ( list, partialUrlKey, &data, &dataSize );
        // store a hit
        if ( data && dataSize > 0 ) {
            // get the url
            char *x;
            long  xlen;
            // hit, check the url
            // for catdb, skip over the catids
            /*
            unsigned char numCatids = *data;
            // . point to stored url/site
            // . skip dataSize/fileNum
            long  skip = 1 + (4 * numCatids) + 4;
            x    = data + skip;
            xlen = dataSize - skip;
            */
            CatRec sr;
            sr.set ( url, data, dataSize, false);
            x    = sr.m_url;
            xlen = sr.m_urlLen;
            // ensure it's a sub-path
            if ( xlen <= url->getUrlLen() &&
                    strncasecmp(x, url->getUrl(), xlen) == 0 ) {
                //char msg[4096];
                //char *mp = msg;
                //mp += sprintf(mp, "For ");
                //memcpy(mp, url->getUrl(), url->getUrlLen());
                //mp += url->getUrlLen();
                //mp += sprintf(mp, " , got Indirect: ");
                //memcpy(mp, x, xlen);
                //mp += xlen;
                //*mp = '\0';
                //log ( LOG_INFO, "tagdb: %s", msg );
                matchRecs    [numMatches] = data;
                matchRecSizes[numMatches] = dataSize;
                numMatches++;
            }
        }
        // make the next partial url
        pathLen--;
        while ( pathLen > 3 && path[pathLen-1] != '/' )
            pathLen--;
        // check for end
        if ( pathLen <= 3 || strncmp(&path[pathLen-3], "://", 3) == 0 )
            break;
        // chop off the trailing /
        pathLen--;
    }
    return numMatches;
}