Esempio n. 1
0
void TraktorFeature::parsePlaylistEntries(
    QXmlStreamReader &xml,
    QString playlist_path,
    QSqlQuery query_insert_into_playlist,
    QSqlQuery query_insert_into_playlisttracks) {
    // In the database, the name of a playlist is specified by the unique path,
    // e.g., /someFolderA/someFolderB/playlistA"
    query_insert_into_playlist.bindValue(":name", playlist_path);

    if (!query_insert_into_playlist.exec()) {
        LOG_FAILED_QUERY(query_insert_into_playlist)
                << "Failed to insert playlist in TraktorTableModel:"
                << playlist_path;
        return;
    }

    // Get playlist id
    QSqlQuery id_query(m_database);
    id_query.prepare("select id from traktor_playlists where name=:path");
    id_query.bindValue(":path", playlist_path);

    if (!id_query.exec()) {
        LOG_FAILED_QUERY(id_query) << "Could not get inserted playlist id for Traktor playlist::"
                                   << playlist_path;
        return;
    }

    //playlist_id = id_query.lastInsertId().toInt();
    int playlist_id = -1;
    while (id_query.next()) {
        playlist_id = id_query.value(id_query.record().indexOf ("id")).toInt();
    }

    int playlist_position = 1;
    while (!xml.atEnd() && !m_cancelImport) {
        //read next XML element
        xml.readNext();
        if (xml.isStartElement()) {
            if (xml.name() == "PRIMARYKEY") {
                QXmlStreamAttributes attr = xml.attributes();
                QString key = attr.value("KEY").toString();
                QString type = attr.value("TYPE").toString();
                if (type == "TRACK") {
                    key.replace(QString(":"), QString(""));
                    //TODO: IFDEF
                    #if defined(__WINDOWS__)
                    key.insert(1,":");
                    #else
                    key.prepend("/Volumes/");
                    #endif

                    //insert to database
                    int track_id = -1;
                    QSqlQuery finder_query(m_database);
                    finder_query.prepare("select id from traktor_library where location=:path");
                    finder_query.bindValue(":path", key);

                    if (!finder_query.exec()) {
                        LOG_FAILED_QUERY(finder_query) << "Could not get track id:" << key;
                        continue;
                    }

                    if (finder_query.next()) {
                        track_id = finder_query.value(finder_query.record().indexOf ("id")).toInt();
                    }

                    query_insert_into_playlisttracks.bindValue(":playlist_id", playlist_id);
                    query_insert_into_playlisttracks.bindValue(":track_id", track_id);
                    query_insert_into_playlisttracks.bindValue(":position", playlist_position++);
                    if (!query_insert_into_playlisttracks.exec()) {
                        LOG_FAILED_QUERY(query_insert_into_playlisttracks)
                                << "trackid" << track_id << " with path " << key
                                << "playlistname; " << playlist_path <<" with ID " << playlist_id;
                    }
                }
            }
        }
        if (xml.isEndElement()) {
            //We leave the infinte loop, if twe have the closing "PLAYLIST" tag
            if (xml.name() == "PLAYLIST") {
                break;
            }
        }
    }
}
Esempio n. 2
0
void                                    main __P2(int, argc, char **, argv)
{
    struct sockaddr_in                      laddr,
                                            faddr;
    int                                     len,
                                            res,
                                            lport,
                                            fport;
    ident_t                                *id;
    char                                   *identifier,
                                           *opsys,
                                           *charset;

    puts("Welcome to the IDENT server tester, version 1.8\r\n");
    printf("(Linked with libident-%s)\r\n\n", id_version);

    fflush(stdout);

    len = sizeof(faddr);
    getpeername(0, (struct sockaddr *)&faddr, &len);

    len = sizeof(laddr);
    getsockname(0, (struct sockaddr *)&laddr, &len);

    printf("Connecting to Ident server at %s...\r\n", inet_ntoa(faddr.sin_addr));
    fflush(stdout);

#ifdef LOG_LOCAL3
    openlog("tidentd", 0, LOG_LOCAL3);
#else
    openlog("tidentd", 0);
#endif

    id = id_open(&laddr.sin_addr, &faddr.sin_addr, NULL);
    if (!id) {
	perror("id_open()");
	fflush(stderr);
	syslog(LOG_ERR, "Error: id_open(): host=%s, error=%m", gethost(&faddr.sin_addr));
	exit(1);
    }

    printf("Querying for lport %d, fport %d....\r\n",
	   (int)ntohs(faddr.sin_port), (int)ntohs(laddr.sin_port));
    fflush(stdout);

    if (id_query(id, ntohs(faddr.sin_port), ntohs(laddr.sin_port), 0) < 0) {
	perror("id_query()");
	fflush(stderr);
	syslog(LOG_ERR, "Error: id_query(): host=%s, error=%m", gethost(&faddr.sin_addr));
	exit(1);
    }

    printf("Reading response data...\r\n");
    fflush(stdout);

    res = id_parse(id, NULL, &lport, &fport, &identifier, &opsys, &charset);

    switch (res) {
	default:
	    perror("id_parse()");
	    syslog(LOG_ERR, "Error: id_parse(): host=%s, error=%m", gethost(&faddr.sin_addr));
	    break;

	case -2:
	    syslog(LOG_ERR, "Error: id_parse(): host=%s, Parse Error: %s",
		   gethost(&faddr.sin_addr),
		   identifier ? identifier : "<no information available>");

	    if (identifier)
		printf("Parse error on reply:\n  \"%s\"\n", identifier);
	    else
		printf("Unidentifiable parse error on reply.\n");
	    break;

	case -3:
	    syslog(LOG_ERR, "Error: id_parse(): host=%s, Illegal reply type: %s",
		   gethost(&faddr.sin_addr), identifier);

	    printf("Parse error in reply: Illegal reply type: %s\n", identifier);
	    break;

	case 0:
	    syslog(LOG_ERR, "Error: id_parse(): host=%s, NotReady", gethost(&faddr.sin_addr));
	    puts("Not ready. This should not happen...\r");
	    break;

	case 2:
	    syslog(LOG_INFO, "Reply: Error: host=%s, error=%s",
		   gethost(&faddr.sin_addr), identifier);

	    printf("Error response is:\r\n");
	    printf("   Lport........ %d\r\n", lport);
	    printf("   Fport........ %d\r\n", fport);
	    printf("   Error........ %s\r\n", identifier);
	    break;

	case 1:
	    if (charset)
		syslog(LOG_INFO,
		       "Reply: Userid: host=%s, opsys=%s, charset=%s, userid=%s",
		       gethost(&faddr.sin_addr), opsys, charset, identifier);
	    else
		syslog(LOG_INFO, "Reply: Userid: host=%s, opsys=%s, userid=%s",
		       gethost(&faddr.sin_addr), opsys, identifier);

	    printf("Userid response is:\r\n");
	    printf("   Lport........ %d\r\n", lport);
	    printf("   Fport........ %d\r\n", fport);
	    printf("   Opsys........ %s\r\n", opsys);
	    printf("   Charset...... %s\r\n", charset ? charset : "<not specified>");
	    printf("   Identifier... %s\r\n", identifier);

	    if (id_query(id, ntohs(faddr.sin_port), ntohs(laddr.sin_port), 0) >= 0) {
		if (id_parse(id, NULL, &lport, &fport, &identifier, &opsys, &charset) == 1)
		    printf("   Multiquery... Enabled\r\n");
	    }
    }

    fflush(stdout);
    sleep(1);
    exit(0);
}