libmusicbrainz-3.0.2/0000755000175000017500000000000011062700256013550 5ustar lukaslukaslibmusicbrainz-3.0.2/libmusicbrainz3.pc.cmake0000644000175000017500000000057310621172116020256 0ustar lukaslukasprefix=${CMAKE_INSTALL_PREFIX} exec_prefix=${EXEC_INSTALL_PREFIX} libdir=${LIB_INSTALL_DIR} includedir=${INCLUDE_INSTALL_DIR} Name: ${PROJECT_NAME} Description: The Musicbrainz Client Library. URL: http://musicbrainz.org/doc/libmusicbrainz Version: ${PROJECT_VERSION} Requires: neon >= 0.25, libdiscid Libs: -L${LIB_INSTALL_DIR} -lmusicbrainz3 Cflags: -I${INCLUDE_INSTALL_DIR} libmusicbrainz-3.0.2/AUTHORS.txt0000644000175000017500000000665310621320144015442 0ustar lukaslukasCredits ======= The following people have contributed to libmusicbrainz3: Lukáš Lalinský - Created the C++ implementation (based on python-musicbrainz2) and the C bindings. - CppUnit test suite. Matthias Friedrich - Design and documentation for the original Python implementation. - Autotools/libtool build system. The following people have contributed to the original libmusicbrainz2: Adam Wozniak - original CD-ROM TOC code Ben Wong - support for SGI Irix Bert Vermeulen - improved endian support Johnny Tevessen - brought in autoconf support Jukka Poikolainen - brought in Win32 TOC code Marc E E van Woerkom - support for FreeBSD, NetBSD, OpenBSD, Solaris and Win32/Cygwin Mark A Mankins - improved Netscape support Rick Bradey - support Linux 2 dot 2 kernel and -l command line option Robert Kaye - hacked it together in the first place - support for Win32/MS VC++ - coordination of the CD Index/MusicBrainz project - move the CD Index over to MusicBrainz - All the RDF/XML work in the client library Stephen van Egmond - support for BeOS Winston Chang - support for Solaris David W. Gray - cmd.dsp and added support for exporting the C++ interface in Win32 Alexey Zakhlestine - Supplied a patch compile this lib under BeOS Brian Reichert - Supplied a patch compile this lib under FreeBSD-4.3 Erik Gavert - A small browser launch patch. Patrick Mauritz - A patch to allow building mb_client from a different directory. Chris Gray - A patch to keep the trm stuff from crashing. Myers Carpenter - Added track duration queries to queries.h - Added all the python and debian support Matthias Friedrich - Provided a patch for fixing NetBSD cdrom TOC code Sander van Zoest - Wrote the perl bindings Philippe Normand - Supplied a couple of minor patches to the new build system Andreas Rottmann - Improve build system and debian support Tim Van Holder - Supplied a patch to fix some compile issues under cygwin Clayton O'Neill - Improved the mp3 sanity checking code in the lib/bitzi/mp3.c Juergen Kreileder - Supplied minimal patch for making sure that mb_client still works when CDO_CHECK_TYPE is defined. Martin Michlmayr - Supplied a number of patches that fixed minor issues with the reintegrated python bindings Ryan McCabe - Supplied a patch to fix pointer issues in comhttpsocket.cpp and comsocket.cpp on 64-bit architectures. -- $Id: AUTHORS.txt 9135 2007-05-12 11:09:24Z luks $ libmusicbrainz-3.0.2/INSTALL.txt0000644000175000017500000000231210621323602015411 0ustar lukaslukas================================================ Installation of the MusicBrainz Client Library ================================================ The instructions in this file should help you to build and install the MusicBrainz client library from source on your system. Dependencies ============ Before you start, make sure you have installed following libraries: * Neon -- HTTP client library http://www.webdav.org/neon/ * libdiscid -- library for calculating MusicBrainz discids http://musicbrainz.org/doc/libdiscid * (optional) CppUnit -- C++ unit testing framework http://cppunit.sourceforge.net/cppunit-wiki Building ======== Once you have installed all dependencies, you can compile the library: cmake . make To build and run the test suite use: make check And to install the built library run (as root): make install CMake Options ============= By default, the library will be installed to /usr/local. You can change this using the CMAKE_INSTALL_PREFIX option, for example: cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr . For overview of all available options use: cmake -L . or use a GUI. See http://www.cmake.org/HTML/RunningCMake.html for more details. libmusicbrainz-3.0.2/cmake/0000755000175000017500000000000011062700231014621 5ustar lukaslukaslibmusicbrainz-3.0.2/cmake/modules/0000755000175000017500000000000011062700232016272 5ustar lukaslukaslibmusicbrainz-3.0.2/cmake/modules/FindNeon.cmake0000644000175000017500000000124010621320144020771 0ustar lukaslukasINCLUDE(UsePkgConfig) PKGCONFIG(neon _NeonIncDir _NeonLinkDir _NeonLinkFlags _NeonCflags) FIND_PATH(NEON_INCLUDE_DIR ne_request.h ${_NeonIncDir} /usr/include/neon /usr/local/include/neon ) FIND_LIBRARY(NEON_LIBRARIES neon ${_NeonLinkDir} /usr/lib /usr/local/lib ) IF (NEON_INCLUDE_DIR AND NEON_LIBRARIES) SET(NEON_FOUND TRUE) ENDIF (NEON_INCLUDE_DIR AND NEON_LIBRARIES) IF (NEON_FOUND) IF (NOT Neon_FIND_QUIETLY) MESSAGE(STATUS "Found Neon: ${NEON_LIBRARIES}") ENDIF (NOT Neon_FIND_QUIETLY) ELSE (NEON_FOUND) IF (Neon_FIND_REQUIRED) MESSAGE(FATAL_ERROR "Could not find Neon") ENDIF (Neon_FIND_REQUIRED) ENDIF (NEON_FOUND) libmusicbrainz-3.0.2/cmake/modules/FindDiscId.cmake0000644000175000017500000000131610621320144021235 0ustar lukaslukasINCLUDE(UsePkgConfig) PKGCONFIG(libdiscid _DiscIdIncDir _DiscIdLinkDir _DiscIdLinkFlags _DiscIdCflags) FIND_PATH(DISCID_INCLUDE_DIR discid/discid.h ${_DiscIdIncDir} /usr/include /usr/local/include ) FIND_LIBRARY(DISCID_LIBRARIES discid ${_DiscIdLinkDir} /usr/lib /usr/local/lib ) IF (DISCID_INCLUDE_DIR AND DISCID_LIBRARIES) SET(DISCID_FOUND TRUE) ENDIF (DISCID_INCLUDE_DIR AND DISCID_LIBRARIES) IF (DISCID_FOUND) IF (NOT DiscId_FIND_QUIETLY) MESSAGE(STATUS "Found DiscId: ${DISCID_LIBRARIES}") ENDIF (NOT DiscId_FIND_QUIETLY) ELSE (DISCID_FOUND) IF (DiscId_FIND_REQUIRED) MESSAGE(FATAL_ERROR "Could not find DiscId") ENDIF (DiscId_FIND_REQUIRED) ENDIF (DISCID_FOUND) libmusicbrainz-3.0.2/cmake/modules/FindCppUnit.cmake0000644000175000017500000000134710621320144021464 0ustar lukaslukasINCLUDE(UsePkgConfig) PKGCONFIG(cppunit _CppUnitIncDir _CppUnitLinkDir _CppUnitLinkFlags _CppUnitCflags) FIND_PATH(CPPUNIT_INCLUDE_DIR cppunit/TestCase.h ${_CppUnitIncDir} /usr/local/include /usr/include ) FIND_LIBRARY(CPPUNIT_LIBRARIES cppunit ${_CppUnitLinkDir} /usr/local/lib /usr/lib ) IF (CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARIES) SET(CPPUNIT_FOUND TRUE) ENDIF (CPPUNIT_INCLUDE_DIR AND CPPUNIT_LIBRARIES) IF (CPPUNIT_FOUND) IF (NOT CppUnit_FIND_QUIETLY) MESSAGE(STATUS "Found CppUnit: ${CPPUNIT_LIBRARIES}") ENDIF (NOT CppUnit_FIND_QUIETLY) ELSE (CPPUNIT_FOUND) IF (CppUnit_FIND_REQUIRED) MESSAGE(FATAL_ERROR "Could not find CppUnit") ENDIF (CppUnit_FIND_REQUIRED) ENDIF (CPPUNIT_FOUND) libmusicbrainz-3.0.2/CMakeLists.txt0000644000175000017500000000525411062677574016336 0ustar lukaslukascmake_minimum_required(VERSION 2.4) PROJECT(libmusicbrainz3) SET(PROJECT_VERSION 3.0.2) # 1. If the library source code has changed at all since the last update, then increment revision. # 2. If any interfaces have been added, removed, or changed since the last update, increment current, and set revision to 0. # 3. If any interfaces have been added since the last public release, then increment age. # 4. If any interfaces have been removed since the last public release, then set age to 0. SET(musicbrainz3_SOVERSION_CURRENT 8) SET(musicbrainz3_SOVERSION_REVISION 0) SET(musicbrainz3_SOVERSION_AGE 2) MATH(EXPR musicbrainz3_SOVERSION_MAJOR "${musicbrainz3_SOVERSION_CURRENT} - ${musicbrainz3_SOVERSION_AGE}") MATH(EXPR musicbrainz3_SOVERSION_MINOR "${musicbrainz3_SOVERSION_AGE}") MATH(EXPR musicbrainz3_SOVERSION_PATCH "${musicbrainz3_SOVERSION_REVISION}") SET(musicbrainz3_VERSION ${musicbrainz3_SOVERSION_MAJOR}.${musicbrainz3_SOVERSION_MINOR}.${musicbrainz3_SOVERSION_PATCH}) SET(musicbrainz3_SOVERSION ${musicbrainz3_SOVERSION_MAJOR}) SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) FIND_PACKAGE(Neon REQUIRED) FIND_PACKAGE(CppUnit) FIND_PACKAGE(DiscId) SET(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)") SET(EXEC_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Installation prefix for executables and object code libraries" FORCE) SET(BIN_INSTALL_DIR ${EXEC_INSTALL_PREFIX}/bin CACHE PATH "Installation prefix for user executables" FORCE) SET(LIB_INSTALL_DIR ${EXEC_INSTALL_PREFIX}/lib${LIB_SUFFIX} CACHE PATH "Installation prefix for object code libraries" FORCE) SET(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include CACHE PATH "Installation prefix for C header files" FORCE) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libmusicbrainz3.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libmusicbrainz3.pc) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.cmake ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h) FILE(GLOB headers ${CMAKE_CURRENT_SOURCE_DIR}/include/musicbrainz3/*.h) INSTALL(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_DIR}/musicbrainz3) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libmusicbrainz3.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) ADD_SUBDIRECTORY(src) IF(CPPUNIT_FOUND) ADD_SUBDIRECTORY(test) ENDIF(CPPUNIT_FOUND) ADD_SUBDIRECTORY(examples) ADD_CUSTOM_TARGET(docs doxygen ) ADD_CUSTOM_TARGET(dist rm -rf "libmusicbrainz-${PROJECT_VERSION}" COMMAND svn export http://svn.musicbrainz.org/libmusicbrainz/trunk "libmusicbrainz-${PROJECT_VERSION}" COMMAND tar -zcvf "libmusicbrainz-${PROJECT_VERSION}.tar.gz" "libmusicbrainz-${PROJECT_VERSION}" ) libmusicbrainz-3.0.2/src/0000755000175000017500000000000011062700245014335 5ustar lukaslukaslibmusicbrainz-3.0.2/src/webservice.cpp0000644000175000017500000002313011032623306017175 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: webservice.cpp 9934 2008-07-02 06:57:10Z luks $ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; class WebService::WebServicePrivate { public: WebServicePrivate() {} std::string host; int port; std::string pathPrefix; std::string username; std::string password; std::string realm; std::string proxyHost; int proxyPort; std::string proxyUserName; std::string proxyPassword; }; static bool webServiceInitialized = false; static string systemProxyHost = string(); static int systemProxyPort = 0; static string systemProxyUserName = string(); static string systemProxyPassword = string(); static void webServiceInit() { if (webServiceInitialized) return; ne_sock_init(); // Parse http_proxy environmnent variable const char *http_proxy = getenv("http_proxy"); if (http_proxy) { debug("Found http_proxy environmnent variable \"%s\"", http_proxy); ne_uri uri; if (!ne_uri_parse(http_proxy, &uri)) { if (uri.host) systemProxyHost = string(uri.host); if (uri.port) systemProxyPort = uri.port; // neon 0.26 #ifdef NE_FEATURE_I18N if (uri.userinfo) { char *pos = strchr(uri.userinfo, ':'); if (pos) { *pos = '\0'; systemProxyUserName = string(uri.userinfo); systemProxyPassword = string(pos + 1); } else { systemProxyUserName = string(uri.userinfo); } } // neon 0.25 #else if (uri.authinfo) { char *pos = strchr(uri.authinfo, ':'); if (pos) { *pos = '\0'; systemProxyUserName = string(uri.authinfo); systemProxyPassword = string(pos + 1); } else { systemProxyUserName = string(uri.authinfo); } } #endif } ne_uri_free(&uri); } webServiceInitialized = true; } WebService::WebService(const std::string &host, const int port, const std::string &pathPrefix, const std::string &username, const std::string &password, const std::string &realm) { webServiceInit(); d = new WebServicePrivate(); d->host = host; d->port = port; d->pathPrefix = pathPrefix; d->username = username; d->password = password; d->realm = realm; d->proxyHost = systemProxyHost; d->proxyPort = systemProxyPort; d->proxyUserName = systemProxyUserName; d->proxyPassword = systemProxyPassword; } WebService::~WebService() { delete d; } int WebService::httpAuth(void *userdata, const char *realm, int attempts, char *username, char *password) { WebService *ws = (WebService *)userdata; strncpy(username, ws->d->username.c_str(), NE_ABUFSIZ); strncpy(password, ws->d->password.c_str(), NE_ABUFSIZ); return attempts; } int WebService::proxyAuth(void *userdata, const char *realm, int attempts, char *username, char *password) { WebService *ws = (WebService *)userdata; strncpy(username, ws->d->proxyUserName.c_str(), NE_ABUFSIZ); strncpy(password, ws->d->proxyPassword.c_str(), NE_ABUFSIZ); return attempts; } int WebService::httpResponseReader(void *userdata, const char *buf, size_t len) { string *str = (string *)userdata; str->append(buf, len); return 0; } string WebService::get(const std::string &entity, const std::string &id, const IIncludes::IncludeList &include, const IFilter::ParameterList &filter, const std::string &version) { ne_session *sess; ne_request *req; debug("Connecting to http://%s:%d", d->host.c_str(), d->port); sess = ne_session_create("http", d->host.c_str(), d->port); if (!sess) throw WebServiceError("ne_session_create() failed."); ne_set_server_auth(sess, httpAuth, this); ne_set_useragent(sess, PACKAGE"/"VERSION); // Use proxy server if (!d->proxyHost.empty()) { ne_session_proxy(sess, d->proxyHost.c_str(), d->proxyPort); ne_set_proxy_auth(sess, proxyAuth, this); } vector > params; params.push_back(pair("type", "xml")); string inc; for (IIncludes::IncludeList::const_iterator i = include.begin(); i != include.end(); i++) { if (!inc.empty()) inc += " "; inc += *i; } if (!inc.empty()) params.push_back(pair("inc", inc)); for (IFilter::ParameterList::const_iterator i = filter.begin(); i != filter.end(); i++) params.push_back(pair(i->first, i->second)); string uri = d->pathPrefix + "/" + version + "/" + entity + "/" + id + "?" + urlEncode(params); debug("GET %s", uri.c_str()); string response; req = ne_request_create(sess, "GET", uri.c_str()); ne_add_response_body_reader(req, ne_accept_2xx, httpResponseReader, &response); int result = ne_request_dispatch(req); int status = ne_get_status(req)->code; ne_request_destroy(req); string errorMessage = ne_get_error(sess); ne_session_destroy(sess); debug("Result: %d (%s)", result, errorMessage.c_str()); debug("Status: %d", status); debug("Response:\n%s", response.c_str()); switch (result) { case NE_OK: break; case NE_CONNECT: throw ConnectionError(errorMessage); case NE_TIMEOUT: throw TimeOutError(errorMessage); case NE_AUTH: throw AuthenticationError(errorMessage); default: throw WebServiceError(errorMessage); } switch (status) { case 200: break; case 400: throw RequestError(errorMessage); case 401: throw AuthenticationError(errorMessage); case 404: throw ResourceNotFoundError(errorMessage); default: throw WebServiceError(errorMessage); } return response; } void WebService::post(const std::string &entity, const std::string &id, const std::string &data, const std::string &version) { ne_session *sess; ne_request *req; debug("Connecting to http://%s:%d", d->host.c_str(), d->port); sess = ne_session_create("http", d->host.c_str(), d->port); if (!sess) throw WebServiceError("ne_session_create() failed."); ne_set_server_auth(sess, httpAuth, this); ne_set_useragent(sess, PACKAGE"/"VERSION); // Use proxy server if (!d->proxyHost.empty()) { ne_session_proxy(sess, d->proxyHost.c_str(), d->proxyPort); ne_set_proxy_auth(sess, proxyAuth, this); } string uri = d->pathPrefix + "/" + version + "/" + entity + "/" + id; debug("POST %s", uri.c_str()); debug("POST-BODY:\n%s", data.c_str()); req = ne_request_create(sess, "POST", uri.c_str()); // neon 0.26 and higher #ifdef NE_FEATURE_I18N ne_set_request_flag(req, NE_REQFLAG_IDEMPOTENT, 0); #endif ne_add_request_header(req, "Content-type", "application/x-www-form-urlencoded"); ne_set_request_body_buffer(req, data.c_str(), data.size()); int result = ne_request_dispatch(req); int status = ne_get_status(req)->code; ne_request_destroy(req); string errorMessage = ne_get_error(sess); ne_session_destroy(sess); debug("Result: %d (%s)", result, errorMessage.c_str()); debug("Status: %d", status); switch (result) { case NE_OK: break; case NE_CONNECT: throw ConnectionError(errorMessage); case NE_TIMEOUT: throw TimeOutError(errorMessage); case NE_AUTH: throw AuthenticationError(errorMessage); default: throw WebServiceError(errorMessage); } switch (status) { case 200: break; case 400: throw RequestError(errorMessage); case 401: throw AuthenticationError(errorMessage); case 404: throw ResourceNotFoundError(errorMessage); default: throw WebServiceError(errorMessage); } } void WebService::setHost(const std::string &value) { d->host = value; } std::string WebService::getHost() const { return d->host; } void WebService::setPort(const int value) { d->port = value; } int WebService::getPort() const { return d->port; } void WebService::setPathPrefix(const std::string &value) { d->pathPrefix = value; } std::string WebService::getPathPrefix() const { return d->pathPrefix; } void WebService::setUserName(const std::string &value) { d->username = value; } std::string WebService::getUserName() const { return d->username; } void WebService::setPassword(const std::string &value) { d->password = value; } std::string WebService::getPassword() const { return d->password; } void WebService::setRealm(const std::string &value) { d->realm = value; } std::string WebService::getRealm() const { return d->realm; } void WebService::setProxyHost(const std::string &value) { d->proxyHost = value; } std::string WebService::getProxyHost() const { return d->proxyHost; } void WebService::setProxyPort(const int value) { d->proxyPort = value; } int WebService::getProxyPort() const { return d->proxyPort; } void WebService::setProxyUserName(const std::string &value) { d->proxyUserName = value; } std::string WebService::getProxyPassword() const { return d->proxyPassword; } void WebService::setProxyPassword(const std::string &value) { d->proxyPassword = value; } libmusicbrainz-3.0.2/src/mbxmlparser.cpp0000644000175000017500000004353711032623210017402 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: mbxmlparser.cpp 9933 2008-07-02 06:56:08Z luks $ */ // TODO: support for namespaces and full MMD #include #include #include #include #include #include #include #include #include "xmlParser/xmlParser.h" using namespace std; using namespace MusicBrainz; class MbXmlParser::MbXmlParserPrivate { public: MbXmlParserPrivate(/*IFactory *factory*/)/* : factory(factory)*/ {} Relation *createRelation(XMLNode node, const string &targetType); void addRelationsToEntity(XMLNode listNode, Entity *entity); template void addToList(XMLNode listNode, TL &resultList, T *(MbXmlParserPrivate::*creator)(XMLNode)); void addArtistsToList(XMLNode listNode, ArtistList &resultList); void addArtistAliasesToList(XMLNode listNode, ArtistAliasList &resultList); void addDiscsToList(XMLNode listNode, DiscList &resultList); void addReleasesToList(XMLNode listNode, ReleaseList &resultList); void addReleaseEventsToList(XMLNode listNode, ReleaseEventList &resultList); void addTracksToList(XMLNode listNode, TrackList &resultList); void addUsersToList(XMLNode listNode, UserList &resultList); void addTagsToList(XMLNode listNode, TagList &resultList); void addLabelAliasesToList(XMLNode listNode, LabelAliasList &resultList); template void addResults(XMLNode listNode, TL &resultList, T *(MbXmlParserPrivate::*creator)(XMLNode)); void addArtistResults(XMLNode listNode, ArtistResultList &resultList); void addReleaseResults(XMLNode listNode, ReleaseResultList &resultList); void addTrackResults(XMLNode listNode, TrackResultList &resultList); Artist *createArtist(XMLNode artistNode); ArtistAlias *createArtistAlias(XMLNode artistAliasNode); Disc *createDisc(XMLNode artistNode); Release *createRelease(XMLNode releaseNode); ReleaseEvent *createReleaseEvent(XMLNode releaseNode); Track *createTrack(XMLNode releaseNode); User *createUser(XMLNode releaseNode); Tag *createTag(XMLNode releaseNode); Label *createLabel(XMLNode releaseNode); LabelAlias *createLabelAlias(XMLNode releaseNode); DefaultFactory factory; }; static bool getBoolAttr(XMLNode node, string name) { const char *value = node.getAttribute(name.c_str()); return value ? string(value) == string("true") : false; } static int getIntAttr(XMLNode node, string name, int def = 0) { const char *value = node.getAttribute(name.c_str()); return value ? atoi(value) : def; } static string getTextAttr(XMLNode node, string name, string def = "") { const char *value = node.getAttribute(name.c_str()); return value ? string(value) : string(def); } static string getUriAttr(XMLNode node, string name, string ns = NS_MMD_1) { const char *value = node.getAttribute(name.c_str()); if (!value) return string(); string text = string(value); return ns + extractFragment(text); } static string getIdAttr(XMLNode node, string name, string typeName) { string uriStr = getTextAttr(node, name); string prefix = "http://musicbrainz.org/" + typeName + "/"; return prefix + uriStr; } static vector getUriListAttr(XMLNode node, string name, string ns = NS_MMD_1) { vector uriList; const char *value = node.getAttribute(name.c_str()); if (!value) return uriList; string text = string(value); string::size_type pos = 0; while (pos < text.size()) { string::size_type end = text.find(' ', pos); if (pos == end) break; string word = extractFragment(text.substr(pos, end - pos)); uriList.push_back(ns + word); pos = text.find_first_not_of(' ', end); } return uriList; } static string getText(XMLNode node) { string text; for (int i = 0; i < node.nText(); i++) text += node.getText(i); return text; } static int getInt(XMLNode node, int def = 0) { string text = getText(node); return text.empty() ? def : atoi(text.c_str()); } Artist * MbXmlParser::MbXmlParserPrivate::createArtist(XMLNode artistNode) { Artist *artist = factory.newArtist(); artist->setId(getIdAttr(artistNode, "id", "artist")); artist->setType(getUriAttr(artistNode, "type")); for (int i = 0; i < artistNode.nChildNode(); i++) { XMLNode node = artistNode.getChildNode(i); string name = node.getName(); if (name == "name") { artist->setName(getText(node)); } else if (name == "sort-name") { artist->setSortName(getText(node)); } else if (name == "disambiguation") { artist->setDisambiguation(getText(node)); } else if (name == "life-span") { const char *begin = node.getAttribute("begin"); const char *end = node.getAttribute("end"); if (begin) artist->setBeginDate(string(begin)); if (end) artist->setEndDate(string(end)); } else if (name == "alias-list") { addArtistAliasesToList(node, artist->getAliases()); } else if (name == "release-list") { artist->setReleasesOffset(getIntAttr(node, "offset")); artist->setReleasesCount(getIntAttr(node, "count")); addReleasesToList(node, artist->getReleases()); } else if (name == "relation-list") { addRelationsToEntity(node, artist); } else if (name == "tag-list") { addTagsToList(node, artist->getTags()); } } return artist; } ArtistAlias * MbXmlParser::MbXmlParserPrivate::createArtistAlias(XMLNode node) { ArtistAlias *alias = factory.newArtistAlias(); alias->setType(getUriAttr(node, "type")); alias->setScript(getTextAttr(node, "script")); alias->setValue(getText(node)); return alias; } Label * MbXmlParser::MbXmlParserPrivate::createLabel(XMLNode labelNode) { Label *label = factory.newLabel(); label->setId(getIdAttr(labelNode, "id", "label")); label->setType(getUriAttr(labelNode, "type")); for (int i = 0; i < labelNode.nChildNode(); i++) { XMLNode node = labelNode.getChildNode(i); string name = node.getName(); if (name == "name") { label->setName(getText(node)); } else if (name == "sort-name") { label->setSortName(getText(node)); } else if (name == "disambiguation") { label->setDisambiguation(getText(node)); } else if (name == "life-span") { const char *begin = node.getAttribute("begin"); const char *end = node.getAttribute("end"); if (begin) label->setBeginDate(string(begin)); if (end) label->setEndDate(string(end)); } else if (name == "alias-list") { addLabelAliasesToList(node, label->getAliases()); } else if (name == "release-list") { label->setReleasesOffset(getIntAttr(node, "offset")); label->setReleasesCount(getIntAttr(node, "count")); addReleasesToList(node, label->getReleases()); } else if (name == "relation-list") { addRelationsToEntity(node, label); } else if (name == "tag-list") { addTagsToList(node, label->getTags()); } } return label; } LabelAlias * MbXmlParser::MbXmlParserPrivate::createLabelAlias(XMLNode node) { LabelAlias *alias = factory.newLabelAlias(); alias->setType(getUriAttr(node, "type")); alias->setScript(getTextAttr(node, "script")); alias->setValue(getText(node)); return alias; } Tag * MbXmlParser::MbXmlParserPrivate::createTag(XMLNode node) { Tag *tag = factory.newTag(); tag->setCount(getIntAttr(node, "count")); tag->setName(getText(node)); return tag; } string getResourceType(const string &type) { string resType = extractFragment(type); transform(resType.begin(), resType.end(), resType.begin(), (int(*)(int))tolower); return resType; } Relation * MbXmlParser::MbXmlParserPrivate::createRelation(XMLNode node, const string &targetType) { Relation *relation = factory.newRelation(); relation->setType(getUriAttr(node, "type", NS_REL_1)); relation->setTargetType(targetType); if (targetType == Relation::TO_URL) relation->setTargetId(getTextAttr(node, "target")); else relation->setTargetId(getIdAttr(node, "target", getResourceType(targetType))); Relation::Direction direction = Relation::DIR_BOTH; string dirStr = getTextAttr(node, "direction"); if (dirStr == "forward") direction = Relation::DIR_FORWARD; if (dirStr == "backward") direction = Relation::DIR_BACKWARD; relation->setDirection(direction); relation->setBeginDate(getTextAttr(node, "begin")); relation->setEndDate(getTextAttr(node, "end")); vector attributes = getUriListAttr(node, "attributes", NS_REL_1); for (vector::iterator i = attributes.begin(); i != attributes.end(); i++) relation->addAttribute(*i); Entity *target = NULL; if (node.nChildNode() > 0) { XMLNode childNode = node.getChildNode(0); if (string(childNode.getName()) == string("artist")) target = createArtist(childNode); else if (string(childNode.getName()) == string("release")) target = createRelease(childNode); else if (string(childNode.getName()) == string("track")) target = createTrack(childNode); } relation->setTarget(target); return relation; } void MbXmlParser::MbXmlParserPrivate::addRelationsToEntity(XMLNode node, Entity *entity) { string targetType = getUriAttr(node, "target-type"); if (targetType.empty()) return; for (int i = 0; i < node.nChildNode(); i++) { XMLNode childNode = node.getChildNode(i); if (string(childNode.getName()) == string("relation")) { Relation *relation = createRelation(childNode, targetType); if (relation) entity->addRelation(relation); } } } Release * MbXmlParser::MbXmlParserPrivate::createRelease(XMLNode releaseNode) { Release *release = factory.newRelease(); release->setId(getIdAttr(releaseNode, "id", "release")); release->setTypes(getUriListAttr(releaseNode, "type")); for (int i = 0; i < releaseNode.nChildNode(); i++) { XMLNode node = releaseNode.getChildNode(i); string name = node.getName(); if (name == "title") { release->setTitle(getText(node)); } else if (name == "text-representation") { release->setTextLanguage(getTextAttr(node, "language")); release->setTextScript(getTextAttr(node, "script")); } else if (name == "asin") { release->setAsin(getText(node)); } else if (name == "artist") { release->setArtist(createArtist(node)); } else if (name == "release-event-list") { addReleaseEventsToList(node, release->getReleaseEvents()); } else if (name == "disc-list") { addDiscsToList(node, release->getDiscs()); } else if (name == "track-list") { release->setTracksOffset(getIntAttr(node, "offset")); release->setTracksCount(getIntAttr(node, "count")); addTracksToList(node, release->getTracks()); } else if (name == "relation-list") { addRelationsToEntity(node, release); } else if (name == "tag-list") { addTagsToList(node, release->getTags()); } } return release; } Track * MbXmlParser::MbXmlParserPrivate::createTrack(XMLNode trackNode) { Track *track = factory.newTrack(); track->setId(getIdAttr(trackNode, "id", "track")); for (int i = 0; i < trackNode.nChildNode(); i++) { XMLNode node = trackNode.getChildNode(i); string name = node.getName(); if (name == "title") { track->setTitle(getText(node)); } else if (name == "artist") { track->setArtist(createArtist(node)); } else if (name == "duration") { track->setDuration(getInt(node)); } else if (name == "release-list") { track->setReleasesOffset(getIntAttr(node, "offset")); track->setReleasesCount(getIntAttr(node, "count")); addReleasesToList(node, track->getReleases()); } else if (name == "relation-list") { addRelationsToEntity(node, track); } else if (name == "tag-list") { addTagsToList(node, track->getTags()); } } return track; } User * MbXmlParser::MbXmlParserPrivate::createUser(XMLNode userNode) { User *user = factory.newUser(); vector typeList = getUriListAttr(userNode, "type", NS_EXT_1); for (vector::iterator i = typeList.begin(); i != typeList.end(); i++) user->addType(*i); for (int i = 0; i < userNode.nChildNode(); i++) { XMLNode node = userNode.getChildNode(i); string name = node.getName(); if (name == "name") { user->setName(getText(node)); } else if (name == "ext:nag") { user->setShowNag(getBoolAttr(node, "show")); } } return user; } Disc * MbXmlParser::MbXmlParserPrivate::createDisc(XMLNode discNode) { Disc *disc = factory.newDisc(); disc->setId(getTextAttr(discNode, "id")); return disc; } ReleaseEvent * MbXmlParser::MbXmlParserPrivate::createReleaseEvent(XMLNode releaseEventNode) { ReleaseEvent *releaseEvent = factory.newReleaseEvent(); releaseEvent->setCountry(getTextAttr(releaseEventNode, "country")); releaseEvent->setDate(getTextAttr(releaseEventNode, "date")); releaseEvent->setCatalogNumber(getTextAttr(releaseEventNode, "catalog-number")); releaseEvent->setBarcode(getTextAttr(releaseEventNode, "barcode")); for (int i = 0; i < releaseEventNode.nChildNode(); i++) { XMLNode node = releaseEventNode.getChildNode(i); string name = node.getName(); if (name == "label") { releaseEvent->setLabel(createLabel(node)); } } return releaseEvent; } template void MbXmlParser::MbXmlParserPrivate::addResults(XMLNode listNode, TL &resultList, T *(MbXmlParserPrivate::*creator)(XMLNode)) { for (int i = 0; i < listNode.nChildNode(); i++) { XMLNode node = listNode.getChildNode(i); T *entity = (this->*creator)(node); int score = getIntAttr(node, "ext:score"); resultList.push_back(new TR(entity, score)); } } void MbXmlParser::MbXmlParserPrivate::addArtistResults(XMLNode listNode, ArtistResultList &resultList) { addResults(listNode, resultList, &MbXmlParserPrivate::createArtist); } void MbXmlParser::MbXmlParserPrivate::addReleaseResults(XMLNode listNode, ReleaseResultList &resultList) { addResults(listNode, resultList, &MbXmlParserPrivate::createRelease); } void MbXmlParser::MbXmlParserPrivate::addTrackResults(XMLNode listNode, TrackResultList &resultList) { addResults(listNode, resultList, &MbXmlParserPrivate::createTrack); } template void MbXmlParser::MbXmlParserPrivate::addToList(XMLNode listNode, TL &resultList, T *(MbXmlParserPrivate::*creator)(XMLNode)) { for (int i = 0; i < listNode.nChildNode(); i++) { XMLNode node = listNode.getChildNode(i); resultList.push_back((this->*creator)(node)); } } void MbXmlParser::MbXmlParserPrivate::addArtistsToList(XMLNode listNode, ArtistList &resultList) { addToList(listNode, resultList, &MbXmlParserPrivate::createArtist); } void MbXmlParser::MbXmlParserPrivate::addArtistAliasesToList(XMLNode listNode, ArtistAliasList &resultList) { addToList(listNode, resultList, &MbXmlParserPrivate::createArtistAlias); } void MbXmlParser::MbXmlParserPrivate::addDiscsToList(XMLNode listNode, DiscList &resultList) { addToList(listNode, resultList, &MbXmlParserPrivate::createDisc); } void MbXmlParser::MbXmlParserPrivate::addReleasesToList(XMLNode listNode, ReleaseList &resultList) { addToList(listNode, resultList, &MbXmlParserPrivate::createRelease); } void MbXmlParser::MbXmlParserPrivate::addReleaseEventsToList(XMLNode listNode, ReleaseEventList &resultList) { addToList(listNode, resultList, &MbXmlParserPrivate::createReleaseEvent); } void MbXmlParser::MbXmlParserPrivate::addTracksToList(XMLNode listNode, TrackList &resultList) { addToList(listNode, resultList, &MbXmlParserPrivate::createTrack); } void MbXmlParser::MbXmlParserPrivate::addUsersToList(XMLNode listNode, UserList &resultList) { addToList(listNode, resultList, &MbXmlParserPrivate::createUser); } void MbXmlParser::MbXmlParserPrivate::addTagsToList(XMLNode listNode, TagList &resultList) { addToList(listNode, resultList, &MbXmlParserPrivate::createTag); } void MbXmlParser::MbXmlParserPrivate::addLabelAliasesToList(XMLNode listNode, LabelAliasList &resultList) { addToList(listNode, resultList, &MbXmlParserPrivate::createLabelAlias); } MbXmlParser::MbXmlParser(/*IFactory &factory*/) { d = new MbXmlParserPrivate(); } MbXmlParser::~MbXmlParser() { delete d; } Metadata * MbXmlParser::parse(const std::string &data) { XMLNode root = XMLNode::parseString(data.c_str(), "metadata"); if (root.isEmpty() || root.getName() != string("metadata")) { throw ParseError(); } Metadata *md = new Metadata(); try { for (int i = 0; i < root.nChildNode(); i++) { XMLNode node = root.getChildNode(i); string name = node.getName(); if (name == string("artist")) { md->setArtist(d->createArtist(node)); } else if (name == string("track")) { md->setTrack(d->createTrack(node)); } else if (name == string("release")) { md->setRelease(d->createRelease(node)); } else if (name == string("label")) { md->setLabel(d->createLabel(node)); } else if (name == string("artist-list")) { d->addArtistResults(node, md->getArtistResults()); } else if (name == string("track-list")) { d->addTrackResults(node, md->getTrackResults()); } else if (name == string("release-list")) { d->addReleaseResults(node, md->getReleaseResults()); } else if (name == string("ext:user-list")) { d->addUsersToList(node, md->getUserList()); } } } catch (...) { delete md; throw ParseError(); } return md; } libmusicbrainz-3.0.2/src/results.cpp0000644000175000017500000000377010477236200016555 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: results.cpp 8466 2006-09-05 08:59:44Z luks $ */ #include using namespace MusicBrainz; Result::Result(int score) : score(score) { } int Result::getScore() { return score; } void Result::setScore(int value) { score = value; } ArtistResult::ArtistResult(Artist *artist, int score) : Result(score), artist(artist) { } ArtistResult::~ArtistResult() { if (artist) delete artist; } Artist * ArtistResult::getArtist() { return artist; } void ArtistResult::setArtist(Artist *value) { if (artist) delete artist; artist = value; } ReleaseResult::ReleaseResult(Release *release, int score) : Result(score), release(release) { } ReleaseResult::~ReleaseResult() { if (release) delete release; } Release * ReleaseResult::getRelease() { return release; } void ReleaseResult::setRelease(Release *value) { if (release) delete release; release = value; } TrackResult::TrackResult(Track *track, int score) : Result(score), track(track) { } TrackResult::~TrackResult() { if (track) delete track; } Track * TrackResult::getTrack() { return track; } void TrackResult::setTrack(Track *value) { if (track) delete track; track = value; } libmusicbrainz-3.0.2/src/utils_scriptnames.h0000644000175000017500000000254210437363020020262 0ustar lukaslukas/* $Id: utils_scriptnames.h 7772 2006-05-31 18:53:04Z luks $ */ static const char *scriptNames[][2] = { {"Yiii", "Yi"}, {"Telu", "Telugu"}, {"Taml", "Tamil"}, {"Guru", "Gurmukhi"}, {"Hebr", "Hebrew"}, {"Geor", "Georgian (Mkhedruli)"}, {"Ugar", "Ugaritic"}, {"Cyrl", "Cyrillic"}, {"Hrkt", "Kanji & Kana"}, {"Armn", "Armenian"}, {"Runr", "Runic"}, {"Khmr", "Khmer"}, {"Latn", "Latin"}, {"Hani", "Han (Hanzi, Kanji, Hanja)"}, {"Ital", "Old Italic (Etruscan, Oscan, etc.)"}, {"Hano", "Hanunoo (Hanunóo)"}, {"Ethi", "Ethiopic (Ge'ez)"}, {"Gujr", "Gujarati"}, {"Hang", "Hangul"}, {"Arab", "Arabic"}, {"Thaa", "Thaana"}, {"Buhd", "Buhid"}, {"Sinh", "Sinhala"}, {"Orya", "Oriya"}, {"Hans", "Han (Simplified variant)"}, {"Thai", "Thai"}, {"Cprt", "Cypriot"}, {"Linb", "Linear B"}, {"Hant", "Han (Traditional variant)"}, {"Osma", "Osmanya"}, {"Mong", "Mongolian"}, {"Deva", "Devanagari (Nagari)"}, {"Laoo", "Lao"}, {"Tagb", "Tagbanwa"}, {"Hira", "Hiragana"}, {"Bopo", "Bopomofo"}, {"Goth", "Gothic"}, {"Tale", "Tai Le"}, {"Mymr", "Myanmar (Burmese)"}, {"Tglg", "Tagalog"}, {"Grek", "Greek"}, {"Mlym", "Malayalam"}, {"Cher", "Cherokee"}, {"Tibt", "Tibetan"}, {"Kana", "Katakana"}, {"Syrc", "Syriac"}, {"Cans", "Unified Canadian Aboriginal Syllabics"}, {"Beng", "Bengali"}, {"Limb", "Limbu"}, {"Ogam", "Ogham"}, {"Knda", "Kannada"}, }; libmusicbrainz-3.0.2/src/includes.cpp0000644000175000017500000000541210636275723016667 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: includes.cpp 9187 2007-06-20 19:11:15Z luks $ */ #include #include #include using namespace std; using namespace MusicBrainz; #define INCLUDES_METHOD(class, name, name2) \ class##Includes & \ class##Includes::name() \ { \ includes.push_back(#name2); \ return *this; \ } \ INCLUDES_METHOD(Track, artist, artist) INCLUDES_METHOD(Track, releases, releases) INCLUDES_METHOD(Track, puids, puids) INCLUDES_METHOD(Track, artistRelations, artist-rels) INCLUDES_METHOD(Track, releaseRelations, release-rels) INCLUDES_METHOD(Track, trackRelations, track-rels) INCLUDES_METHOD(Track, urlRelations, url-rels) TrackIncludes::IncludeList TrackIncludes::createIncludeTags() const { return includes; } INCLUDES_METHOD(Release, artist, artist) INCLUDES_METHOD(Release, counts, counts) INCLUDES_METHOD(Release, releaseEvents, release-events) INCLUDES_METHOD(Release, discs, discs) INCLUDES_METHOD(Release, tracks, tracks) INCLUDES_METHOD(Release, artistRelations, artist-rels) INCLUDES_METHOD(Release, releaseRelations, release-rels) INCLUDES_METHOD(Release, trackRelations, track-rels) INCLUDES_METHOD(Release, urlRelations, url-rels) ReleaseIncludes::IncludeList ReleaseIncludes::createIncludeTags() const { return includes; } INCLUDES_METHOD(Artist, aliases, aliases) INCLUDES_METHOD(Artist, artistRelations, artist-rels) INCLUDES_METHOD(Artist, releaseRelations, release-rels) INCLUDES_METHOD(Artist, trackRelations, track-rels) INCLUDES_METHOD(Artist, urlRelations, url-rels) INCLUDES_METHOD(Artist, releaseEvents, release-events) ArtistIncludes::IncludeList ArtistIncludes::createIncludeTags() const { return includes; } ArtistIncludes & ArtistIncludes::releases(const string &type) { includes.push_back(string("sa-") + extractFragment(type)); return *this; } ArtistIncludes & ArtistIncludes::vaReleases(const string &type) { includes.push_back(string("va-") + extractFragment(type)); return *this; } libmusicbrainz-3.0.2/src/disc.cpp0000644000175000017500000000634710636301322015774 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: disc.cpp 9189 2007-06-20 19:41:06Z luks $ */ #include #ifdef DISCID_FOUND #include #endif #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; class Disc::DiscPrivate { public: DiscPrivate() : sectors(0), firstTrackNum(0), lastTrackNum(0) {} std::string id; int sectors; int firstTrackNum; int lastTrackNum; Disc::TrackList tracks; }; Disc::Disc(const string &id) { d = new DiscPrivate(); d->id = id; } Disc::~Disc() { d->tracks.clear(); delete d; } SIMPLE_STRING_SETTER_GETTER(Disc, Id, id); SIMPLE_INT_SETTER_GETTER(Disc, Sectors, sectors); SIMPLE_INT_SETTER_GETTER(Disc, FirstTrackNum, firstTrackNum); SIMPLE_INT_SETTER_GETTER(Disc, LastTrackNum, lastTrackNum); Disc::TrackList & Disc::getTracks() { return d->tracks; } void Disc::addTrack(Disc::Track track) { d->tracks.push_back(track); } Disc * MusicBrainz::readDisc(const std::string &deviceName) { #ifdef DISCID_FOUND DiscId *discid = discid_new(); if (!discid) { throw DiscError("Couldn't create a new DiscId instance."); } if (!discid_read(discid, deviceName.empty() ? NULL : deviceName.c_str())) { string msg(discid_get_error_msg(discid)); discid_free(discid); throw DiscError(msg); } Disc *disc = new Disc; disc->setId(discid_get_id(discid)); disc->setSectors(discid_get_sectors(discid)); disc->setFirstTrackNum(discid_get_first_track_num(discid)); disc->setLastTrackNum(discid_get_last_track_num(discid)); for (int i = disc->getFirstTrackNum(); i <= disc->getLastTrackNum(); i++) { disc->addTrack(Disc::Track(discid_get_track_offset(discid, i), discid_get_track_length(discid, i))); } discid_free(discid); return disc; #else throw DiscError("libdiscid is not available."); #endif } std::string MusicBrainz::getSubmissionUrl(Disc *disc, const std::string &host, int port) { string netloc; if (port == 80) netloc = host; else netloc = host + ":" + intToString(port); string toc = intToString(disc->getFirstTrackNum()) + "+" + intToString(disc->getLastTrackNum()) + "+" + intToString(disc->getSectors()); for (Disc::TrackList::const_iterator i = disc->getTracks().begin(); i < disc->getTracks().end(); i++) { toc += "+" + intToString(i->first); } return "http://" + netloc + "/bare/cdlookup.html?id=" + disc->getId() + "&toc=" + toc + "&tracks=" + intToString(disc->getLastTrackNum()); } libmusicbrainz-3.0.2/src/utils_languagenames.h0000644000175000017500000002151510527563264020556 0ustar lukaslukas/* $Id: utils_languagenames.h 8651 2006-11-18 10:55:48Z luks $ */ static const char *languageNames[][2] = { {"ART", "Artificial (Other)"}, {"ROH", "Raeto-Romance"}, {"SCO", "Scots"}, {"SCN", "Sicilian"}, {"ROM", "Romany"}, {"RON", "Romanian"}, {"OSS", "Ossetian; Ossetic"}, {"ALE", "Aleut"}, {"MNI", "Manipuri"}, {"NWC", "Classical Newari; Old Newari; Classical Nepal Bhasa"}, {"OSA", "Osage"}, {"MNC", "Manchu"}, {"MWR", "Marwari"}, {"VEN", "Venda"}, {"MWL", "Mirandese"}, {"FAS", "Persian"}, {"FAT", "Fanti"}, {"FAN", "Fang"}, {"FAO", "Faroese"}, {"DIN", "Dinka"}, {"HYE", "Armenian"}, {"DSB", "Lower Sorbian"}, {"CAR", "Carib"}, {"DIV", "Divehi"}, {"TEL", "Telugu"}, {"TEM", "Timne"}, {"NBL", "Ndebele, South; South Ndebele"}, {"TER", "Tereno"}, {"TET", "Tetum"}, {"SUN", "Sundanese"}, {"KUT", "Kutenai"}, {"SUK", "Sukuma"}, {"KUR", "Kurdish"}, {"KUM", "Kumyk"}, {"SUS", "Susu"}, {"NEW", "Newari; Nepal Bhasa"}, {"KUA", "Kuanyama; Kwanyama"}, {"MEN", "Mende"}, {"LEZ", "Lezghian"}, {"GLA", "Gaelic; Scottish Gaelic"}, {"BOS", "Bosnian"}, {"GLE", "Irish"}, {"EKA", "Ekajuk"}, {"GLG", "Gallegan"}, {"AKA", "Akan"}, {"BOD", "Tibetan"}, {"GLV", "Manx"}, {"JRB", "Judeo-Arabic"}, {"VIE", "Vietnamese"}, {"IPK", "Inupiaq"}, {"UZB", "Uzbek"}, {"BRE", "Breton"}, {"BRA", "Braj"}, {"AYM", "Aymara"}, {"CHA", "Chamorro"}, {"CHB", "Chibcha"}, {"CHE", "Chechen"}, {"CHG", "Chagatai"}, {"CHK", "Chuukese"}, {"CHM", "Mari"}, {"CHN", "Chinook jargon"}, {"CHO", "Choctaw"}, {"CHP", "Chipewyan"}, {"CHR", "Cherokee"}, {"CHU", "Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic"}, {"CHV", "Chuvash"}, {"CHY", "Cheyenne"}, {"MSA", "Malay"}, {"III", "Sichuan Yi"}, {"ACE", "Achinese"}, {"IBO", "Igbo"}, {"IBA", "Iban"}, {"XHO", "Xhosa"}, {"DEU", "German"}, {"CAT", "Catalan; Valencian"}, {"DEL", "Delaware"}, {"DEN", "Slave (Athapascan)"}, {"CAD", "Caddo"}, {"TAT", "Tatar"}, {"RAJ", "Rajasthani"}, {"SPA", "Spanish; Castilian"}, {"TAM", "Tamil"}, {"TAH", "Tahitian"}, {"AFH", "Afrihili"}, {"ENG", "English"}, {"CSB", "Kashubian"}, {"NYN", "Nyankole"}, {"NYO", "Nyoro"}, {"SID", "Sidamo"}, {"NYA", "Chichewa; Chewa; Nyanja"}, {"SIN", "Sinhala; Sinhalese"}, {"AFR", "Afrikaans"}, {"LAM", "Lamba"}, {"SND", "Sindhi"}, {"MAR", "Marathi"}, {"LAH", "Lahnda"}, {"NYM", "Nyamwezi"}, {"SNA", "Shona"}, {"LAD", "Ladino"}, {"SNK", "Soninke"}, {"MAD", "Madurese"}, {"MAG", "Magahi"}, {"MAI", "Maithili"}, {"MAH", "Marshallese"}, {"LAV", "Latvian"}, {"MAL", "Malayalam"}, {"MAN", "Mandingo"}, {"ZND", "Zande"}, {"ZEN", "Zenaga"}, {"KBD", "Kabardian"}, {"ITA", "Italian"}, {"VAI", "Vai"}, {"TSN", "Tswana"}, {"TSO", "Tsonga"}, {"TSI", "Tsimshian"}, {"BYN", "Blin; Bilin"}, {"FIJ", "Fijian"}, {"FIN", "Finnish"}, {"EUS", "Basque"}, {"CEB", "Cebuano"}, {"DAN", "Danish"}, {"NOG", "Nogai"}, {"NOB", "Norwegian Bokmål; Bokmål, Norwegian"}, {"DAK", "Dakota"}, {"CES", "Czech"}, {"DAR", "Dargwa"}, {"DAY", "Dayak"}, {"NOR", "Norwegian"}, {"KPE", "Kpelle"}, {"GUJ", "Gujarati"}, {"MDF", "Moksha"}, {"MAS", "Masai"}, {"LAO", "Lao"}, {"MDR", "Mandar"}, {"GON", "Gondi"}, {"SMS", "Skolt Sami"}, {"SMO", "Samoan"}, {"SMN", "Inari Sami"}, {"SMJ", "Lule Sami"}, {"GOT", "Gothic"}, {"SME", "Northern Sami"}, {"BLA", "Siksika"}, {"SMA", "Southern Sami"}, {"GOR", "Gorontalo"}, {"AST", "Asturian; Bable"}, {"ORM", "Oromo"}, {"QUE", "Quechua"}, {"ORI", "Oriya"}, {"CRH", "Crimean Tatar; Crimean Turkish"}, {"ASM", "Assamese"}, {"PUS", "Pushto"}, {"DGR", "Dogrib"}, {"LTZ", "Luxembourgish; Letzeburgesch"}, {"NDO", "Ndonga"}, {"GEZ", "Geez"}, {"ISL", "Icelandic"}, {"LAT", "Latin"}, {"MAK", "Makasar"}, {"ZAP", "Zapotec"}, {"YID", "Yiddish"}, {"KOK", "Konkani"}, {"KOM", "Komi"}, {"KON", "Kongo"}, {"UKR", "Ukrainian"}, {"TON", "Tonga (Tonga Islands)"}, {"KOS", "Kosraean"}, {"KOR", "Korean"}, {"TOG", "Tonga (Nyasa)"}, {"HUN", "Hungarian"}, {"HUP", "Hupa"}, {"CYM", "Welsh"}, {"UDM", "Udmurt"}, {"BEJ", "Beja"}, {"BEN", "Bengali"}, {"BEL", "Belarusian"}, {"BEM", "Bemba"}, {"AAR", "Afar"}, {"NZI", "Nzima"}, {"SAH", "Yakut"}, {"SAN", "Sanskrit"}, {"SAM", "Samaritan Aramaic"}, {"SAG", "Sango"}, {"SAD", "Sandawe"}, {"RAR", "Rarotongan"}, {"RAP", "Rapanui"}, {"SAS", "Sasak"}, {"SAT", "Santali"}, {"MIN", "Minangkabau"}, {"LIM", "Limburgan; Limburger; Limburgish"}, {"LIN", "Lingala"}, {"LIT", "Lithuanian"}, {"EFI", "Efik"}, {"BTK", "Batak (Indonesia)"}, {"KAC", "Kachin"}, {"KAB", "Kabyle"}, {"KAA", "Kara-Kalpak"}, {"KAN", "Kannada"}, {"KAM", "Kamba"}, {"KAL", "Kalaallisut; Greenlandic"}, {"KAS", "Kashmiri"}, {"KAR", "Karen"}, {"KAU", "Kanuri"}, {"KAT", "Georgian"}, {"KAZ", "Kazakh"}, {"TYV", "Tuvinian"}, {"AWA", "Awadhi"}, {"URD", "Urdu"}, {"DOI", "Dogri"}, {"TPI", "Tok Pisin"}, {"MRI", "Maori"}, {"ABK", "Abkhazian"}, {"TKL", "Tokelau"}, {"NLD", "Dutch; Flemish"}, {"OJI", "Ojibwa"}, {"OCI", "Occitan (post 1500); Provençal"}, {"WOL", "Wolof"}, {"JAV", "Javanese"}, {"HRV", "Croatian"}, {"DYU", "Dyula"}, {"SSW", "Swati"}, {"MUL", "Multiple languages"}, {"HIL", "Hiligaynon"}, {"HIM", "Himachali"}, {"HIN", "Hindi"}, {"BAS", "Basa"}, {"GBA", "Gbaya"}, {"WLN", "Walloon"}, {"BAD", "Banda"}, {"NEP", "Nepali"}, {"CRE", "Cree"}, {"BAN", "Balinese"}, {"BAL", "Baluchi"}, {"BAM", "Bambara"}, {"BAK", "Bashkir"}, {"SHN", "Shan"}, {"ARP", "Arapaho"}, {"ARW", "Arawak"}, {"ARA", "Arabic"}, {"ARC", "Aramaic"}, {"ARG", "Aragonese"}, {"SEL", "Selkup"}, {"ARN", "Araucanian"}, {"LUS", "Lushai"}, {"MUS", "Creek"}, {"LUA", "Luba-Lulua"}, {"LUB", "Luba-Katanga"}, {"LUG", "Ganda"}, {"LUI", "Luiseno"}, {"LUN", "Lunda"}, {"LUO", "Luo (Kenya and Tanzania)"}, {"IKU", "Inuktitut"}, {"TUR", "Turkish"}, {"TUK", "Turkmen"}, {"TUM", "Tumbuka"}, {"COP", "Coptic"}, {"COS", "Corsican"}, {"COR", "Cornish"}, {"ILO", "Iloko"}, {"GWI", "Gwich´in"}, {"TLI", "Tlingit"}, {"TLH", "Klingon; tlhIngan-Hol"}, {"POR", "Portuguese"}, {"PON", "Pohnpeian"}, {"POL", "Polish"}, {"TGK", "Tajik"}, {"TGL", "Tagalog"}, {"FRA", "French"}, {"BHO", "Bhojpuri"}, {"SWA", "Swahili"}, {"DUA", "Duala"}, {"SWE", "Swedish"}, {"YAP", "Yapese"}, {"TIV", "Tiv"}, {"YAO", "Yao"}, {"XAL", "Kalmyk"}, {"FRY", "Frisian"}, {"GAY", "Gayo"}, {"OTA", "Turkish, Ottoman (1500-1928)"}, {"HMN", "Hmong"}, {"HMO", "Hiri Motu"}, {"GAA", "Ga"}, {"FUR", "Friulian"}, {"MLG", "Malagasy"}, {"SLV", "Slovenian"}, {"FIL", "Filipino; Pilipino"}, {"MLT", "Maltese"}, {"SLK", "Slovak"}, {"FUL", "Fulah"}, {"JPN", "Japanese"}, {"VOL", "Volapük"}, {"VOT", "Votic"}, {"IND", "Indonesian"}, {"AVE", "Avestan"}, {"JPR", "Judeo-Persian"}, {"AVA", "Avaric"}, {"PAP", "Papiamento"}, {"EWO", "Ewondo"}, {"PAU", "Palauan"}, {"EWE", "Ewe"}, {"PAG", "Pangasinan"}, {"PAM", "Pampanga"}, {"PAN", "Panjabi; Punjabi"}, {"KIR", "Kirghiz"}, {"NIA", "Nias"}, {"KIK", "Kikuyu; Gikuyu"}, {"SYR", "Syriac"}, {"KIN", "Kinyarwanda"}, {"NIU", "Niuean"}, {"EPO", "Esperanto"}, {"JBO", "Lojban"}, {"MIC", "Mi'kmaq; Micmac"}, {"THA", "Thai"}, {"HAI", "Haida"}, {"ELL", "Greek, Modern (1453-)"}, {"ADY", "Adyghe; Adygei"}, {"ELX", "Elamite"}, {"ADA", "Adangme"}, {"GRB", "Grebo"}, {"HAT", "Haitian; Haitian Creole"}, {"HAU", "Hausa"}, {"HAW", "Hawaiian"}, {"BIN", "Bini"}, {"AMH", "Amharic"}, {"BIK", "Bikol"}, {"BIH", "Bihari"}, {"MOS", "Mossi"}, {"MOH", "Mohawk"}, {"MON", "Mongolian"}, {"MOL", "Moldavian"}, {"BIS", "Bislama"}, {"TVL", "Tuvalu"}, {"IJO", "Ijo"}, {"EST", "Estonian"}, {"KMB", "Kimbundu"}, {"UMB", "Umbundu"}, {"TMH", "Tamashek"}, {"FON", "Fon"}, {"HSB", "Upper Sorbian"}, {"RUN", "Rundi"}, {"RUS", "Russian"}, {"PLI", "Pali"}, {"SRD", "Sardinian"}, {"ACH", "Acoli"}, {"NDE", "Ndebele, North; North Ndebele"}, {"DZO", "Dzongkha"}, {"KRU", "Kurukh"}, {"SRR", "Serer"}, {"IDO", "Ido"}, {"SRP", "Serbian"}, {"KRO", "Kru"}, {"KRC", "Karachay-Balkar"}, {"NDS", "Low German; Low Saxon; German, Low; Saxon, Low"}, {"ZUN", "Zuni"}, {"ZUL", "Zulu"}, {"TWI", "Twi"}, {"NSO", "Northern Sotho, Pedi; Sepedi"}, {"SOM", "Somali"}, {"SON", "Songhai"}, {"SOT", "Sotho, Southern"}, {"MKD", "Macedonian"}, {"HER", "Herero"}, {"LOL", "Mongo"}, {"HEB", "Hebrew"}, {"LOZ", "Lozi"}, {"GIL", "Gilbertese"}, {"WAS", "Washo"}, {"WAR", "Waray"}, {"BUL", "Bulgarian"}, {"WAL", "Walamo"}, {"BUA", "Buriat"}, {"BUG", "Buginese"}, {"AZE", "Azerbaijani"}, {"ZHA", "Zhuang; Chuang"}, {"ZHO", "Chinese"}, {"NNO", "Norwegian Nynorsk; Nynorsk, Norwegian"}, {"UIG", "Uighur; Uyghur"}, {"MYV", "Erzya"}, {"INH", "Ingush"}, {"KHM", "Khmer"}, {"MYA", "Burmese"}, {"KHA", "Khasi"}, {"INA", "Interlingua (International Auxiliary Language Association)"}, {"NAH", "Nahuatl"}, {"TIR", "Tigrinya"}, {"NAP", "Neapolitan"}, {"NAV", "Navajo; Navaho"}, {"NAU", "Nauru"}, {"GRN", "Guarani"}, {"TIG", "Tigre"}, {"YOR", "Yoruba"}, {"ILE", "Interlingue"}, {"SQI", "Albanian"}, }; libmusicbrainz-3.0.2/src/query.cpp0000644000175000017500000001103610552262344016215 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: query.cpp 8789 2007-01-13 23:01:56Z luks $ */ #include #include #include #include #include #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; class Query::QueryPrivate { public: QueryPrivate() : ws(NULL), ownWs(false) {} IWebService *ws; bool ownWs; std::string clientId; }; Query::Query(IWebService *ws, const string &clientId) { d = new QueryPrivate(); d->ws = ws; d->clientId = clientId; if (!d->ws) { d->ws = new WebService(); d->ownWs = true; } } Query::~Query() { if (d->ownWs && d->ws) delete d->ws; delete d; } Artist * Query::getArtistById(const string &id, const ArtistIncludes *include) { string uuid; try { uuid = extractUuid(id); } catch (ValueError &e) { throw RequestError(e.what()); } Metadata *metadata = getFromWebService("artist", uuid, include); Artist *artist = metadata->getArtist(true); delete metadata; return artist; } Release * Query::getReleaseById(const string &id, const ReleaseIncludes *include) { string uuid; try { uuid = extractUuid(id); } catch (ValueError &e) { throw RequestError(e.what()); } Metadata *metadata = getFromWebService("release", uuid, include); Release *release = metadata->getRelease(true); delete metadata; return release; } Track * Query::getTrackById(const string &id, const TrackIncludes *include) { string uuid; try { uuid = extractUuid(id); } catch (ValueError &e) { throw RequestError(e.what()); } Metadata *metadata = getFromWebService("track", uuid, include); Track *track = metadata->getTrack(true); delete metadata; return track; } User * Query::getUserByName(const string &name) { Metadata *metadata = getFromWebService("user", "", NULL, &UserFilter().name(name)); UserList list = metadata->getUserList(true); delete metadata; if (list.size() > 0) return list[0]; else throw ResponseError("response didn't contain user data"); } ArtistResultList Query::getArtists(const ArtistFilter *filter) { Metadata *metadata = getFromWebService("artist", "", NULL, filter); ArtistResultList list = metadata->getArtistResults(true); delete metadata; return list; } ReleaseResultList Query::getReleases(const ReleaseFilter *filter) { Metadata *metadata = getFromWebService("release", "", NULL, filter); ReleaseResultList list = metadata->getReleaseResults(true); delete metadata; return list; } TrackResultList Query::getTracks(const TrackFilter *filter) { Metadata *metadata = getFromWebService("track", "", NULL, filter); TrackResultList list = metadata->getTrackResults(true); delete metadata; return list; } Metadata * Query::getFromWebService(const string &entity, const string &id, const IIncludes *include, const IFilter *filter) { const IIncludes::IncludeList includeParams(include ? include->createIncludeTags() : IIncludes::IncludeList()); const IFilter::ParameterList filterParams(filter ? filter->createParameters() : IFilter::ParameterList()); string content = d->ws->get(entity, id, includeParams, filterParams); try { MbXmlParser parser; return parser.parse(content); } catch (ParseError &e) { throw ResponseError(e.what()); } } void Query::submitPuids(const map &tracks2puids) { if (d->clientId.empty()) throw WebServiceError("Please supply a client ID"); vector > params; params.push_back(pair("client", d->clientId)); for (map::const_iterator i = tracks2puids.begin(); i != tracks2puids.end(); i++) params.push_back(pair("puid", extractUuid(i->first) + " " + i->second)); d->ws->post("track", "", urlEncode(params)); } libmusicbrainz-3.0.2/src/CMakeLists.txt0000644000175000017500000000142310645765712017115 0ustar lukaslukasSET(CMAKE_INCLUDE_CURRENT_DIR ON) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../include ${NEON_INCLUDE_DIR}) FILE(GLOB _sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/xmlParser/*.cpp) ADD_LIBRARY(musicbrainz3 SHARED ${_sources}) SET_TARGET_PROPERTIES(musicbrainz3 PROPERTIES VERSION ${musicbrainz3_VERSION} SOVERSION ${musicbrainz3_SOVERSION} DEFINE_SYMBOL MB_API_EXPORTS ) TARGET_LINK_LIBRARIES(musicbrainz3 ${NEON_LIBRARIES}) IF(DISCID_FOUND) INCLUDE_DIRECTORIES(${DISCID_INCLUDE_DIR}) TARGET_LINK_LIBRARIES(musicbrainz3 ${DISCID_LIBRARIES}) ENDIF(DISCID_FOUND) IF(WIN32) TARGET_LINK_LIBRARIES(musicbrainz3 wsock32 winmm) ENDIF(WIN32) INSTALL(TARGETS musicbrainz3 DESTINATION ${LIB_INSTALL_DIR}) libmusicbrainz-3.0.2/src/label.cpp0000644000175000017500000000634510640020535016126 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: label.cpp 9218 2007-06-25 20:11:09Z luks $ */ #include #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; const string Label::TYPE_PERSON = NS_MMD_1 + "Person"; const string Label::TYPE_GROUP = NS_MMD_1 + "Group"; class Label::LabelPrivate { public: LabelPrivate() : releasesCount(0), releasesOffset(0) {} std::string type; std::string name; std::string sortName; std::string disambiguation; std::string beginDate; std::string endDate; ReleaseList releases; int releasesCount; int releasesOffset; LabelAliasList aliases; }; Label::Label(const string &id, const string &type, const string &name, const string &sortName) : Entity(id) { d = new LabelPrivate(); d->type = type; d->name = name; d->sortName = sortName; } Label::~Label() { for (ReleaseList::iterator i = d->releases.begin(); i != d->releases.end(); i++) delete *i; d->releases.clear(); for (LabelAliasList::iterator i = d->aliases.begin(); i != d->aliases.end(); i++) delete *i; d->aliases.clear(); delete d; } SIMPLE_STRING_SETTER_GETTER(Label, Type, type); SIMPLE_STRING_SETTER_GETTER(Label, Name, name); SIMPLE_STRING_SETTER_GETTER(Label, SortName, sortName); SIMPLE_STRING_SETTER_GETTER(Label, Disambiguation, disambiguation); SIMPLE_STRING_SETTER_GETTER(Label, BeginDate, beginDate); SIMPLE_STRING_SETTER_GETTER(Label, EndDate, endDate); string Label::getUniqueName() const { return d->disambiguation.empty() ? d->name : d->name + " (" + d->disambiguation +")"; } ReleaseList & Label::getReleases() { return d->releases; } void Label::addRelease(Release *release) { d->releases.push_back(release); } LabelAliasList & Label::getAliases() { return d->aliases; } void Label::addAlias(LabelAlias *alias) { d->aliases.push_back(alias); } int Label::getNumReleases() const { return d->releases.size(); } Release * Label::getRelease(int i) { return d->releases[i]; } int Label::getReleasesOffset() const { return d->releasesOffset; } void Label::setReleasesOffset(const int releasesOffset) { d->releasesOffset = releasesOffset; } int Label::getReleasesCount() const { return d->releasesCount; } void Label::setReleasesCount(const int releasesCount) { d->releasesCount = releasesCount; } int Label::getNumAliases() const { return d->aliases.size(); } LabelAlias * Label::getAlias(int i) { return d->aliases[i]; } libmusicbrainz-3.0.2/src/utils_private.cpp0000644000175000017500000000406411032623306017736 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: utils_private.cpp 9934 2008-07-02 06:57:10Z luks $ */ #include #include #include #include #include #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; string MusicBrainz::intToString(const int i) { char temp[32]; sprintf(temp, "%d", i); return string(temp); } int MusicBrainz::stringToInt(const std::string &s) { return atoi(s.c_str()); } string MusicBrainz::uriEscape(const string &uri) { char *esc_uri_str = ne_path_escape(uri.c_str()); string esc_uri = string((const char *)esc_uri_str); free(esc_uri_str); return esc_uri; } string MusicBrainz::urlEncode(const vector > ¶ms) { string encodedStr; bool first = true; for (vector >::const_iterator i = params.begin(); i != params.end(); i++) { string name = i->first; string value = i->second; if (first) first = false; else encodedStr += "&"; encodedStr += name + "=" + uriEscape(value); } return encodedStr; } #ifndef NDEBUG void MusicBrainz::debug(const char *fmt, ...) { va_list ap; va_start(ap, fmt); fprintf(stderr, "MusicBrainz: "); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); va_end(ap); } #endif libmusicbrainz-3.0.2/src/utils_countrynames.h0000644000175000017500000001364710437363020020471 0ustar lukaslukas/* $Id: utils_countrynames.h 7772 2006-05-31 18:53:04Z luks $ */ static const char *countryNames[][2] = { {"BD", "Bangladesh"}, {"BE", "Belgium"}, {"BF", "Burkina Faso"}, {"BG", "Bulgaria"}, {"BB", "Barbados"}, {"WF", "Wallis and Futuna Islands"}, {"BM", "Bermuda"}, {"BN", "Brunei Darussalam"}, {"BO", "Bolivia"}, {"BH", "Bahrain"}, {"BI", "Burundi"}, {"BJ", "Benin"}, {"BT", "Bhutan"}, {"JM", "Jamaica"}, {"BV", "Bouvet Island"}, {"BW", "Botswana"}, {"WS", "Samoa"}, {"BR", "Brazil"}, {"BS", "Bahamas"}, {"BY", "Belarus"}, {"BZ", "Belize"}, {"RU", "Russian Federation"}, {"RW", "Rwanda"}, {"RE", "Reunion"}, {"TM", "Turkmenistan"}, {"TJ", "Tajikistan"}, {"RO", "Romania"}, {"TK", "Tokelau"}, {"GW", "Guinea-Bissau"}, {"GU", "Guam"}, {"GT", "Guatemala"}, {"GR", "Greece"}, {"GQ", "Equatorial Guinea"}, {"GP", "Guadeloupe"}, {"JP", "Japan"}, {"GY", "Guyana"}, {"GF", "French Guiana"}, {"GE", "Georgia"}, {"GD", "Grenada"}, {"GB", "United Kingdom"}, {"GA", "Gabon"}, {"SV", "El Salvador"}, {"GN", "Guinea"}, {"GM", "Gambia"}, {"GL", "Greenland"}, {"GI", "Gibraltar"}, {"GH", "Ghana"}, {"OM", "Oman"}, {"TN", "Tunisia"}, {"JO", "Jordan"}, {"HT", "Haiti"}, {"HU", "Hungary"}, {"HK", "Hong Kong"}, {"HN", "Honduras"}, {"HM", "Heard and Mc Donald Islands"}, {"VE", "Venezuela"}, {"PR", "Puerto Rico"}, {"PW", "Palau"}, {"PT", "Portugal"}, {"SJ", "Svalbard and Jan Mayen Islands"}, {"PY", "Paraguay"}, {"IQ", "Iraq"}, {"PA", "Panama"}, {"PF", "French Polynesia"}, {"PG", "Papua New Guinea"}, {"PE", "Peru"}, {"PK", "Pakistan"}, {"PH", "Philippines"}, {"PN", "Pitcairn"}, {"PL", "Poland"}, {"PM", "St. Pierre and Miquelon"}, {"ZM", "Zambia"}, {"EH", "Western Sahara"}, {"EE", "Estonia"}, {"EG", "Egypt"}, {"ZA", "South Africa"}, {"EC", "Ecuador"}, {"IT", "Italy"}, {"VN", "Viet Nam"}, {"SB", "Solomon Islands"}, {"ET", "Ethiopia"}, {"SO", "Somalia"}, {"ZW", "Zimbabwe"}, {"SA", "Saudi Arabia"}, {"ES", "Spain"}, {"ER", "Eritrea"}, {"MD", "Moldova, Republic of"}, {"MG", "Madagascar"}, {"MA", "Morocco"}, {"MC", "Monaco"}, {"UZ", "Uzbekistan"}, {"MM", "Myanmar"}, {"ML", "Mali"}, {"MO", "Macau"}, {"MN", "Mongolia"}, {"MH", "Marshall Islands"}, {"MK", "Macedonia, The Former Yugoslav Republic of"}, {"MU", "Mauritius"}, {"MT", "Malta"}, {"MW", "Malawi"}, {"MV", "Maldives"}, {"MQ", "Martinique"}, {"MP", "Northern Mariana Islands"}, {"MS", "Montserrat"}, {"MR", "Mauritania"}, {"UG", "Uganda"}, {"MY", "Malaysia"}, {"MX", "Mexico"}, {"IL", "Israel"}, {"FR", "France"}, {"IO", "British Indian Ocean Territory"}, {"SH", "St. Helena"}, {"FI", "Finland"}, {"FJ", "Fiji"}, {"FK", "Falkland Islands (Malvinas)"}, {"FM", "Micronesia, Federated States of"}, {"FO", "Faroe Islands"}, {"NI", "Nicaragua"}, {"NL", "Netherlands"}, {"NO", "Norway"}, {"NA", "Namibia"}, {"VU", "Vanuatu"}, {"NC", "New Caledonia"}, {"NE", "Niger"}, {"NF", "Norfolk Island"}, {"NG", "Nigeria"}, {"NZ", "New Zealand"}, {"ZR", "Zaire"}, {"NP", "Nepal"}, {"NR", "Nauru"}, {"NU", "Niue"}, {"CK", "Cook Islands"}, {"CI", "Cote d'Ivoire"}, {"CH", "Switzerland"}, {"CO", "Colombia"}, {"CN", "China"}, {"CM", "Cameroon"}, {"CL", "Chile"}, {"CC", "Cocos (Keeling) Islands"}, {"CA", "Canada"}, {"CG", "Congo"}, {"CF", "Central African Republic"}, {"CZ", "Czech Republic"}, {"CY", "Cyprus"}, {"CX", "Christmas Island"}, {"CR", "Costa Rica"}, {"CV", "Cape Verde"}, {"CU", "Cuba"}, {"SZ", "Swaziland"}, {"SY", "Syrian Arab Republic"}, {"KG", "Kyrgyzstan"}, {"KE", "Kenya"}, {"SR", "Suriname"}, {"KI", "Kiribati"}, {"KH", "Cambodia"}, {"KN", "Saint Kitts and Nevis"}, {"KM", "Comoros"}, {"ST", "Sao Tome and Principe"}, {"SI", "Slovenia"}, {"KW", "Kuwait"}, {"SN", "Senegal"}, {"SM", "San Marino"}, {"SL", "Sierra Leone"}, {"SC", "Seychelles"}, {"KZ", "Kazakhstan"}, {"KY", "Cayman Islands"}, {"SG", "Singapore"}, {"SE", "Sweden"}, {"SD", "Sudan"}, {"DO", "Dominican Republic"}, {"DM", "Dominica"}, {"DJ", "Djibouti"}, {"DK", "Denmark"}, {"VG", "Virgin Islands (British)"}, {"DE", "Germany"}, {"YE", "Yemen"}, {"DZ", "Algeria"}, {"US", "United States"}, {"UY", "Uruguay"}, {"YT", "Mayotte"}, {"UM", "United States Minor Outlying Islands"}, {"LB", "Lebanon"}, {"LC", "Saint Lucia"}, {"LA", "Lao People's Democratic Republic"}, {"TV", "Tuvalu"}, {"TW", "Taiwan"}, {"TT", "Trinidad and Tobago"}, {"TR", "Turkey"}, {"LK", "Sri Lanka"}, {"LI", "Liechtenstein"}, {"LV", "Latvia"}, {"TO", "Tonga"}, {"LT", "Lithuania"}, {"LU", "Luxembourg"}, {"LR", "Liberia"}, {"LS", "Lesotho"}, {"TH", "Thailand"}, {"TF", "French Southern Territories"}, {"TG", "Togo"}, {"TD", "Chad"}, {"TC", "Turks and Caicos Islands"}, {"LY", "Libyan Arab Jamahiriya"}, {"VA", "Vatican City State (Holy See)"}, {"VC", "Saint Vincent and The Grenadines"}, {"AE", "United Arab Emirates"}, {"AD", "Andorra"}, {"AG", "Antigua and Barbuda"}, {"AF", "Afghanistan"}, {"AI", "Anguilla"}, {"VI", "Virgin Islands (U.S.)"}, {"IS", "Iceland"}, {"IR", "Iran (Islamic Republic of)"}, {"AM", "Armenia"}, {"AL", "Albania"}, {"AO", "Angola"}, {"AN", "Netherlands Antilles"}, {"AQ", "Antarctica"}, {"AS", "American Samoa"}, {"AR", "Argentina"}, {"AU", "Australia"}, {"AT", "Austria"}, {"AW", "Aruba"}, {"IN", "India"}, {"TZ", "Tanzania, United Republic of"}, {"AZ", "Azerbaijan"}, {"IE", "Ireland"}, {"ID", "Indonesia"}, {"UA", "Ukraine"}, {"QA", "Qatar"}, {"MZ", "Mozambique"}, {"BA", "Bosnia and Herzegovina"}, {"CD", "Congo, The Democratic Republic of the"}, {"CS", "Serbia and Montenegro"}, {"HR", "Croatia"}, {"KP", "Korea (North), Democratic People's Republic of"}, {"KR", "Korea (South), Republic of"}, {"SK", "Slovakia"}, {"SU", "Soviet Union (historical, 1922-1991)"}, {"TL", "East Timor"}, {"XC", "Czechoslovakia (historical, 1918-1992)"}, {"XE", "Europe"}, {"XG", "East Germany (historical, 1949-1990)"}, {"XU", "[Unknown Country]"}, {"XW", "[Worldwide]"}, {"YU", "Yugoslavia (historical, 1918-1992)"}, }; libmusicbrainz-3.0.2/src/utils_private.h0000644000175000017500000000344110636301322017401 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: utils_private.h 9189 2007-06-20 19:41:06Z luks $ */ #ifndef __MUSICBRAINZ3_UTILSPRIV_H__ #define __MUSICBRAINZ3_UTILSPRIV_H__ #include #include #include namespace MusicBrainz { #ifndef NDEBUG void debug(const char *fmt, ...); #else inline void debug(const char *fmt, ...) {} #endif std::string intToString(const int i); int stringToInt(const std::string &s); std::string uriEscape(const std::string &uri); std::string urlEncode(const std::vector > ¶ms); } #define SIMPLE_STRING_SETTER_GETTER(class, name, name2) \ string \ class::get##name() const \ { \ return d->name2; \ } \ void \ class::set##name(const string &value) \ { \ d->name2 = value; \ } #define SIMPLE_INT_SETTER_GETTER(class, name, name2) \ int \ class::get##name() const \ { \ return d->name2; \ } \ void \ class::set##name(const int value) \ { \ d->name2 = value; \ } #endif libmusicbrainz-3.0.2/src/tag.cpp0000644000175000017500000000246710640015234015623 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2007 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: tag.cpp 9216 2007-06-25 19:42:20Z luks $ */ #include #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; class Tag::TagPrivate { public: TagPrivate() {} string name; int count; }; Tag::Tag(const string &name, int count) { d = new TagPrivate(); d->name = name; d->count = count; } Tag::~Tag() { delete d; } SIMPLE_STRING_SETTER_GETTER(Tag, Name, name); SIMPLE_INT_SETTER_GETTER(Tag, Count, count); libmusicbrainz-3.0.2/src/user.cpp0000644000175000017500000000320410636301322016015 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: user.cpp 9189 2007-06-20 19:41:06Z luks $ */ #include #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; class User::UserPrivate { public: UserPrivate() : showNag(false) {} std::string name; bool showNag; std::vector types; }; User::User() { d = new UserPrivate(); } User::~User() { delete d; } SIMPLE_STRING_SETTER_GETTER(User, Name, name); bool User::getShowNag() const { return d->showNag; } void User::setShowNag(bool value) { d->showNag = value; } std::vector & User::getTypes() { return d->types; } void User::addType(const string &type) { d->types.push_back(type); } int User::getNumTypes() const { return d->types.size(); } string User::getType(int i) const { return d->types[i]; } libmusicbrainz-3.0.2/src/utils.cpp0000644000175000017500000000734510551442167016222 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: utils.cpp 8784 2007-01-11 14:06:47Z luks $ */ #include #include #include using namespace std; using namespace MusicBrainz; std::string MusicBrainz::extractFragment(const string &uri) { // FIXME: proper URI parsing string::size_type pos = uri.find_last_of('#'); if (pos == string::npos) return uri; else return uri.substr(pos + 1); } std::string MusicBrainz::extractUuid(const string &uri) { if (uri.empty()) return uri; string types[] = {"artist/", "release/", "track/"}; for (int i = 0; i < 3; i++) { string::size_type pos = uri.find(types[i]); if (pos != string::npos) { pos += types[i].size(); if (pos + 36 == uri.size()) { return uri.substr(pos, 36); } } } // FIXME: ugh... if (uri.size() == 36) return uri; throw ValueError(uri + "is not a valid MusicBrainz ID."); } #include "utils_countrynames.h" string MusicBrainz::getCountryName(const string &id) { static bool countryNamesMapBuilt = false; static map countryNamesMap; if (!countryNamesMapBuilt) { for (int i = 0; i < (int)(sizeof(countryNames) / sizeof(countryNames[0])); i++) countryNamesMap[countryNames[i][0]] = countryNames[i][1]; countryNamesMapBuilt = true; } map::iterator i = countryNamesMap.find(id); return i == countryNamesMap.end() ? string() : i->second; } #include "utils_languagenames.h" string MusicBrainz::getLanguageName(const string &id) { static bool languageNamesMapBuilt = false; static map languageNamesMap; if (!languageNamesMapBuilt) { for (int i = 0; i < (int)(sizeof(languageNames) / sizeof(languageNames[0])); i++) languageNamesMap[languageNames[i][0]] = languageNames[i][1]; languageNamesMapBuilt = true; } map::iterator i = languageNamesMap.find(id); return i == languageNamesMap.end() ? string() : i->second; } #include "utils_scriptnames.h" string MusicBrainz::getScriptName(const string &id) { static bool scriptNamesMapBuilt = false; static map scriptNamesMap; if (!scriptNamesMapBuilt) { for (int i = 0; i < (int)(sizeof(scriptNames) / sizeof(scriptNames[0])); i++) scriptNamesMap[scriptNames[i][0]] = scriptNames[i][1]; scriptNamesMapBuilt = true; } map::iterator i = scriptNamesMap.find(id); return i == scriptNamesMap.end() ? string() : i->second; } #include "utils_releasetypenames.h" string MusicBrainz::getReleaseTypeName(const string &id) { static bool releaseTypeNamesMapBuilt = false; static map releaseTypeNamesMap; if (!releaseTypeNamesMapBuilt) { for (int i = 0; i < (int)(sizeof(releaseTypeNames) / sizeof(releaseTypeNames[0])); i++) releaseTypeNamesMap[releaseTypeNames[i][0]] = releaseTypeNames[i][1]; releaseTypeNamesMapBuilt = true; } map::iterator i = releaseTypeNamesMap.find(id); return i == releaseTypeNamesMap.end() ? string() : i->second; } libmusicbrainz-3.0.2/src/releaseevent.cpp0000644000175000017500000000357310640020535017531 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: releaseevent.cpp 9218 2007-06-25 20:11:09Z luks $ */ #include #include #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; class ReleaseEvent::ReleaseEventPrivate { public: ReleaseEventPrivate() : label(NULL) {} string country; string dateStr; string catalogNumber; string barcode; Label *label; }; ReleaseEvent::ReleaseEvent(const string &country, const string &dateStr) { d = new ReleaseEventPrivate(); d->country = country; d->dateStr = dateStr; } ReleaseEvent::~ReleaseEvent() { if (d->label) delete d->label; delete d; } SIMPLE_STRING_SETTER_GETTER(ReleaseEvent, Country, country); SIMPLE_STRING_SETTER_GETTER(ReleaseEvent, CatalogNumber, catalogNumber); SIMPLE_STRING_SETTER_GETTER(ReleaseEvent, Barcode, barcode); SIMPLE_STRING_SETTER_GETTER(ReleaseEvent, Date, dateStr); void ReleaseEvent::setLabel(Label *label) { if (d->label) delete d->label; d->label = label; } Label * ReleaseEvent::getLabel() { return d->label; } libmusicbrainz-3.0.2/src/entity.cpp0000644000175000017500000000520510640015234016355 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: entity.cpp 9216 2007-06-25 19:42:20Z luks $ */ #include #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; class Entity::EntityPrivate { public: EntityPrivate() {} std::string id; RelationList relations; TagList tags; }; Entity::Entity(const string &id) { d = new EntityPrivate(); d->id = id; } Entity::~Entity() { for (RelationList::iterator i = d->relations.begin(); i != d->relations.end(); i++) delete *i; d->relations.clear(); delete d; } SIMPLE_STRING_SETTER_GETTER(Entity, Id, id); RelationList Entity::getRelations(const std::string &targetType, const std::string &relationType) const { if (targetType.empty() && relationType.empty()) return d->relations; RelationList result; if (targetType.empty()) { for (RelationList::const_iterator i = d->relations.begin(); i != d->relations.end(); i++) { if ((*i)->getType() == relationType) { result.push_back(*i); } } } else if (relationType.empty()) { for (RelationList::const_iterator i = d->relations.begin(); i != d->relations.end(); i++) { if ((*i)->getTargetType() == targetType) { result.push_back(*i); } } } else { for (RelationList::const_iterator i = d->relations.begin(); i != d->relations.end(); i++) { if ((*i)->getType() == relationType && (*i)->getTargetType() == targetType) { result.push_back(*i); } } } return result; } void Entity::addRelation(Relation *relation) { d->relations.push_back(relation); } int Entity::getNumRelations() const { return d->relations.size(); } Relation * Entity::getRelation(int i) { return d->relations[i]; } int Entity::getNumTags() const { return d->tags.size(); } Tag * Entity::getTag(int i) { return d->tags[i]; } TagList & Entity::getTags() { return d->tags; } libmusicbrainz-3.0.2/src/release.cpp0000644000175000017500000001055310636303064016471 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: release.cpp 9191 2007-06-20 19:55:32Z luks $ */ #include #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; const string Release::TYPE_NONE = NS_MMD_1 + "None"; const string Release::TYPE_ALBUM = NS_MMD_1 + "Album"; const string Release::TYPE_SINGLE = NS_MMD_1 + "Single"; const string Release::TYPE_EP = NS_MMD_1 + "EP"; const string Release::TYPE_COMPILATION = NS_MMD_1 + "Compilation"; const string Release::TYPE_SOUNDTRACK = NS_MMD_1 + "Soundtrack"; const string Release::TYPE_SPOKENWORD = NS_MMD_1 + "Spokenword"; const string Release::TYPE_INTERVIEW = NS_MMD_1 + "Interview"; const string Release::TYPE_AUDIOBOOK = NS_MMD_1 + "Audiobook"; const string Release::TYPE_LIVE = NS_MMD_1 + "Live"; const string Release::TYPE_REMIX = NS_MMD_1 + "Remix"; const string Release::TYPE_OTHER = NS_MMD_1 + "Other"; const string Release::TYPE_OFFICIAL = NS_MMD_1 + "Official"; const string Release::TYPE_PROMOTION = NS_MMD_1 + "Promotion"; const string Release::TYPE_BOOTLEG = NS_MMD_1 + "Bootleg"; const string Release::TYPE_PSEUDO_RELEASE = NS_MMD_1 + "Pseudo-Release"; class Release::ReleasePrivate { public: ReleasePrivate() : artist(NULL), tracksOffset(0), tracksCount(0) {} std::string title; std::string textLanguage; std::string textScript; std::string asin; vector types; Artist *artist; TrackList tracks; int tracksOffset; int tracksCount; DiscList discs; ReleaseEventList releaseEvents; }; Release::Release(const string &id, const string &title) : Entity(id) { d = new ReleasePrivate(); d->title = title; } Release::~Release() { if (d->artist) delete d->artist; for (TrackList::iterator i = d->tracks.begin(); i != d->tracks.end(); i++) delete *i; d->tracks.clear(); for (DiscList::iterator i = d->discs.begin(); i != d->discs.end(); i++) delete *i; d->discs.clear(); for (ReleaseEventList::iterator i = d->releaseEvents.begin(); i != d->releaseEvents.end(); i++) delete *i; d->releaseEvents.clear(); delete d; } SIMPLE_STRING_SETTER_GETTER(Release, Title, title); SIMPLE_STRING_SETTER_GETTER(Release, TextLanguage, textLanguage); SIMPLE_STRING_SETTER_GETTER(Release, TextScript, textScript); SIMPLE_STRING_SETTER_GETTER(Release, Asin, asin); Artist * Release::getArtist() { return d->artist; } void Release::setArtist(Artist *value) { if (d->artist) delete d->artist; d->artist = value; } TrackList & Release::getTracks() { return d->tracks; } int Release::getTracksOffset() const { return d->tracksOffset; } void Release::setTracksOffset(const int value) { d->tracksOffset = value; } int Release::getTracksCount() const { return d->tracksCount; } void Release::setTracksCount(const int tracksCount) { d->tracksCount = tracksCount; } DiscList & Release::getDiscs() { return d->discs; } ReleaseEventList & Release::getReleaseEvents() { return d->releaseEvents; } int Release::getNumReleaseEvents() const { return d->releaseEvents.size(); } ReleaseEvent * Release::getReleaseEvent(int i) { return d->releaseEvents[i]; } int Release::getNumDiscs() const { return d->discs.size(); } Disc * Release::getDisc(int i) { return d->discs[i]; } int Release::getNumTracks() const { return d->tracks.size(); } Track * Release::getTrack(int i) { return d->tracks[i]; } void Release::setTypes(const vector &types) { d->types = types; } vector & Release::getTypes() { return d->types; } int Release::getNumTypes() const { return d->types.size(); } string Release::getType(int i) const { return d->types[i]; } libmusicbrainz-3.0.2/src/xmlParser/0000755000175000017500000000000011062700246016313 5ustar lukaslukaslibmusicbrainz-3.0.2/src/xmlParser/xmlParser.h0000644000175000017500000002740510477236200020454 0ustar lukaslukas/** **************************************************************************** *

XML.c - implementation file for basic XML parser written in ANSI C++ * for portability. It works by using recursion and a node tree for breaking * down the elements of an XML document.

* * @version V1.16 * * @author Frank Vanden Berghen * based on original implementation by Martyn C Brown * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1 as published by the Free Software Foundation * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * (see lgpl.txt) along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * **************************************************************************** */ #ifndef __INCLUDE_XML_NODE__ #define __INCLUDE_XML_NODE__ #include #ifdef WIN32 #include #endif // Some common types for char set portable code #ifdef _UNICODE #ifdef __linux__ #include #define _T(c) L ## c #endif #ifndef LPCTSTR #define LPCTSTR const wchar_t * #endif /* LPCTSTR */ #ifndef LPTSTR #define LPTSTR wchar_t * #endif /* LPTSTR */ #ifndef TCHAR #define TCHAR wchar_t #endif /* TCHAR */ #else #ifndef WIN32 #define _T(c) c #endif #ifndef LPCTSTR #define LPCTSTR const char * #endif /* LPCTSTR */ #ifndef LPTSTR #define LPTSTR char * #endif /* LPTSTR */ #ifndef TCHAR #define TCHAR char #endif /* TCHAR */ #endif #ifndef FALSE #define FALSE 0 #endif /* FALSE */ #ifndef TRUE #define TRUE 1 #endif /* TRUE */ // Enumeration for XML parse errors. typedef enum XMLError { eXMLErrorNone = 0, eXMLErrorMissingEndTag, eXMLErrorEmpty, eXMLErrorFirstNotStartTag, eXMLErrorMissingTagName, eXMLErrorMissingEndTagName, eXMLErrorNoMatchingQuote, eXMLErrorUnmatchedEndTag, eXMLErrorUnexpectedToken, eXMLErrorInvalidTag, eXMLErrorNoElements, eXMLErrorFileNotFound, eXMLErrorTagNotFound } XMLError; // Enumeration used to manage type of data. Use in conjonction with structure XMLNodeContents typedef enum XMLElementType { eNodeChild=0, eNodeAttribute=1, eNodeText=2, eNodeClear=3, eNodeNULL=4 } XMLElementType; // Structure used to obtain error details if the parse fails. typedef struct XMLResults { enum XMLError error; int nLine,nColumn; } XMLResults; // Structure for XML clear (unformatted) node (usually comments) typedef struct { LPCTSTR lpszOpenTag; LPCTSTR lpszValue; LPCTSTR lpszCloseTag; } XMLClear; // Structure for XML attribute. typedef struct { LPCTSTR lpszName; LPCTSTR lpszValue; } XMLAttribute; struct XMLNodeContents; typedef struct XMLNode { // friend class XMLNode; protected: typedef struct XMLNodeDataTag // to allow shallow copy and "intelligent/smart" pointers (automatic delete): { LPCTSTR lpszName; // Element name (=NULL if root) int nChild, // Num of child nodes nText, // Num of text fields nClear, // Num of Clear fields (comments) nAttribute, // Num of attributes isDeclaration; // Whether node is an XML declaration - '' struct XMLNodeDataTag *pParent; // Pointer to parent element (=NULL if root) XMLNode *pChild; // Array of child nodes LPCTSTR *pText; // Array of text fields XMLClear *pClear; // Array of clear fields XMLAttribute *pAttribute; // Array of attributes int *pOrder; // order in which the child_nodes,text_fields,clear_fields and int ref_count; // for garbage collection (smart pointers) } XMLNodeData; XMLNodeData *d; // protected constructor: use one of these four methods to get your first instance of XMLNode: // - parseString // - parseFile // - openFileHelper // - createXMLTopNode XMLNode(XMLNodeData *pParent, LPCTSTR lpszName, int isDeclaration); public: // You can create your first instance of XMLNode with these 3 parse functions: // (see complete explanation of parameters below) static XMLNode parseString (LPCTSTR lpszXML, LPCTSTR tag=NULL, XMLResults *pResults=NULL); static XMLNode parseFile (const char *lpszXML, LPCTSTR tag=NULL, XMLResults *pResults=NULL); static XMLNode openFileHelper(const char *lpszXML, LPCTSTR tag); // The tag parameter should be the name of the first tag inside the XML file. // If the tag parameter is omitted, the 3 functions return a node that represents // the head of the xml document including the declaration term (). // If the XML document is corrupted: // - The "openFileHelper" method will stop execution and display an error message. // - The 2 other methods will initialize the "pResults" variable with some information that // can be used to trace the error. // you can have a detailed explanation of the parsing error with this function: static LPCTSTR getError(XMLError error); LPCTSTR getName(); // name of the node LPCTSTR getText(int i=0); // return ith text field int nText(); // nbr of text field XMLNode getChildNode(int i=0); // return ith child node XMLNode getChildNode(LPCTSTR name, int i); // return ith child node with specific name // (return an empty node if failing) XMLNode getChildNode(LPCTSTR name, int *i=NULL); // return next child node with specific name // (return an empty node if failing) int nChildNode(LPCTSTR name); // return the number of child node with specific name int nChildNode(); // nbr of child node XMLAttribute getAttribute(int i=0); // return ith attribute char isAttributeSet(LPCTSTR name); // test if an attribute with a specific name is given LPCTSTR getAttribute(LPCTSTR name, int i); // return ith attribute content with specific name // (return a NULL if failing) LPCTSTR getAttribute(LPCTSTR name, int *i=NULL); // return next attribute content with specific name // (return a NULL if failing) int nAttribute(); // nbr of attribute XMLClear getClear(int i=0); // return ith clear field (comment) int nClear(); // nbr of clear field LPTSTR createXMLString(int nFormat, int *pnSize=NULL); // create XML string starting from current XMLNode XMLNodeContents enumContents(int i); // enumerate all the different contents (child,text, // clear,attribute) of the current XMLNode. The order // is reflecting the order of the original file/string int nElement(); // nbr of different contents for current node char isEmpty(); // is this node Empty? char isDeclaration(); // to allow shallow copy: ~XMLNode(); XMLNode(const XMLNode &A); XMLNode& operator=( const XMLNode& A ); static void destroyCurrentBuffer(XMLNodeData *d); XMLNode(): d(NULL){}; static XMLNode emptyXMLNode; static XMLClear emptyXMLClear; static XMLAttribute emptyXMLAttribute; // The following functions allows you to create from scratch a XMLNode structure // The strings given as parameters for these methods will be free'd by the XMLNode class: static XMLNode createXMLTopNode(); XMLNode addChild(LPCTSTR lpszName, int isDeclaration=FALSE); void setName(LPCTSTR lpszName); // WARNING: cannot use lpszName=NULL XMLAttribute *addAttribute(LPCTSTR lpszName, LPCTSTR lpszValuev); LPCTSTR addText(LPCTSTR lpszValue); XMLClear *addClear(LPCTSTR lpszValue, LPCTSTR lpszOpen, LPCTSTR lpszClose); XMLNode addChild(XMLNode nodeToAdd); // If the "nodeToAdd" has some parents, it will be detached // from it's parents before being attached to the current XMLNode // some deletion functions: void deleteNodeContent(); // delete the content of this XMLNode and the subtree void deleteAttribute(int i=0); void deleteAttribute(XMLAttribute *anAttribute); void deleteAttribute(LPCTSTR lpszName); // string parameter must "point" exactly to the memory // location of the attribute's name to remove. void deleteAttributeRelaxed(LPCTSTR lpszName); // string parameter can point to anywhere. // the first attribute's name to match is deleted. void deleteText(int i=0); void deleteText(LPCTSTR lpszValue); void deleteClear(int i=0); void deleteClear(XMLClear *p); void deleteClear(LPCTSTR lpszValue); private: // these are functions used internally (don't bother about them): int ParseClearTag(void *pXML, void *pClear); int ParseXMLElement(void *pXML); void addToOrder(int index, int type); static int CreateXMLStringR(XMLNodeData *pEntry, LPTSTR lpszMarker, int nFormat); static void *enumContent(XMLNodeData *pEntry,int i, XMLElementType *nodeType); static int nElement(XMLNodeData *pEntry); static void removeOrderElement(XMLNodeData *d, XMLElementType t, int index); static void exactMemory(XMLNodeData *d); static void detachFromParent(XMLNodeData *d); } XMLNode; // This structure is given by the function "enumContents". typedef struct XMLNodeContents { // This dictates what's the content of the XMLNodeContent enum XMLElementType type; // should be an union to access the appropriate data. // compiler does not allow union of object with constructor... too bad. XMLNode child; XMLAttribute attrib; LPCTSTR text; XMLClear clear; } XMLNodeContents; // The 2 following functions are processing strings so that all the characters // &,",',<,> are replaced by their XML equivalent: &, ", ', <, >. // The second function ("toXMLStringFast") allows you to re-use the same output // buffer for all the conversions so that only a few memory allocations are performed. // If the output buffer is too small to contain the resulting string, it will // be enlarged. These 2 functions are useful when creating from scratch an // XML file using printf (or cout). LPTSTR toXMLString(LPCTSTR source); LPTSTR toXMLStringFast(LPTSTR *destBuffer,int *destSz, LPCTSTR source); // you should not use this one: LPTSTR toXMLString(LPTSTR dest,LPCTSTR source); // duplicate (copy in a new allocated buffer) the source string LPTSTR stringDup(LPCTSTR source, int cbData=0); #endif libmusicbrainz-3.0.2/src/xmlParser/xmlParser.cpp0000644000175000017500000017342110477236200021007 0ustar lukaslukas/** **************************************************************************** *

XML.c - implementation file for basic XML parser written in ANSI C++ * for portability. It works by using recursion and a node tree for breaking * down the elements of an XML document.

* * @version V1.16 * * @author Frank Vanden Berghen * based on original implementation by Martyn C Brown * * NOTE: * * If you add "#define STRICT_PARSING", on the first line of this file * the parser will see the following XML-stream: *
some textother text * as an error. Otherwise, this tring will be equivalent to: * some textother text * * NOTE: * * If you add "#define APPROXIMATE_PARSING", on the first line of this file * the parser will see the following XML-stream: * * * * as equivalent to the following XML-stream: * * * * This can be useful for badly-formed XML-streams but prevent the use * of the following XML-stream (problem is: tags at contiguous levels * have the same names): * * * * * * * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1 as published by the Free Software Foundation * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * (see lgpl.txt) along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * **************************************************************************** */ #ifdef WIN32 #define WIN32_LEAN_AND_MEAN #ifndef _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE #endif #include // to have IsTextUnicode, MultiByteToWideChar, WideCharToMultiByte // to handle unicode files #endif #include #include #include #include #include #include "xmlParser.h" //#ifdef WIN32 //#ifdef _DEBUG //#define _CRTDBG_MAP_ALLOC //#include //#endif //#endif XMLNode XMLNode::emptyXMLNode; XMLClear XMLNode::emptyXMLClear={ NULL, NULL, NULL}; XMLAttribute XMLNode::emptyXMLAttribute={ NULL, NULL}; #ifndef WIN32 #ifdef _UNICODE int _tcslen(LPCTSTR c) { return wcslen(c); } int _tcsnicmp(LPCTSTR c1, LPCTSTR c2, int l) { return wcsncasecmp(c1,c2,l);} int _tcsicmp(LPCTSTR c1, LPCTSTR c2) { return wcscasecmp(c1,c2); } LPTSTR _tcsstr(LPCTSTR c1, LPCTSTR c2) { return (LPTSTR)wcsstr(c1,c2); } LPTSTR _tcschr(LPCTSTR c1, int c2) { return (LPTSTR)wcschr(c1,c2); } LPTSTR _tcscpy(LPTSTR c1, LPCTSTR c2) { return (LPTSTR)wcscpy(c1,c2); } #else int _tcslen(LPCTSTR c) { return strlen(c); } int _tcsnicmp(LPCTSTR c1, LPCTSTR c2, int l) { return strncasecmp(c1,c2,l);} int _tcsicmp(LPCTSTR c1, LPCTSTR c2) { return strcasecmp(c1,c2); } LPTSTR _tcsstr(LPCTSTR c1, LPCTSTR c2) { return (LPTSTR)strstr(c1,c2); } LPTSTR _tcschr(LPCTSTR c1, int c2) { return (LPTSTR)strchr(c1,c2); } LPTSTR _tcscpy(LPTSTR c1, LPCTSTR c2) { return (LPTSTR)strcpy(c1,c2); } #endif #endif inline int mmin( const int t1, const int t2 ) { return t1 < t2 ? t1 : t2; } // Enumeration used to decipher what type a token is typedef enum TokenTypeTag { eTokenText = 0, eTokenQuotedText, eTokenTagStart, /* "<" */ eTokenTagEnd, /* "" */ eTokenEquals, /* "=" */ eTokenDeclaration, /* "" */ eTokenClear, eTokenError }; #define INDENTCHAR _T('\t') typedef struct ClearTag { LPCTSTR lpszOpen; LPCTSTR lpszClose; } ClearTag; // Main structure used for parsing XML typedef struct XML { LPCTSTR lpXML; int nIndex; enum XMLError error; LPCTSTR lpEndTag; int cbEndTag; LPCTSTR lpNewElement; int cbNewElement; int nFirst; ClearTag *pClrTags; } XML; typedef struct { ClearTag *pClr; LPCTSTR pStr; } NextToken; // Enumeration used when parsing attributes typedef enum Attrib { eAttribName = 0, eAttribEquals, eAttribValue } Attrib; // Enumeration used when parsing elements to dictate whether we are currently // inside a tag typedef enum Status { eInsideTag = 0, eOutsideTag } Status; // private: LPTSTR toXMLString(LPTSTR dest,LPCTSTR source) { LPTSTR dd=dest; while (*source) { switch (*source) { case '<' : _tcscpy(dest,_T("<" )); dest+=4; break; case '>' : _tcscpy(dest,_T(">" )); dest+=4; break; case '&' : _tcscpy(dest,_T("&" )); dest+=5; break; case '\'': _tcscpy(dest,_T("'")); dest+=6; break; case '"' : _tcscpy(dest,_T(""")); dest+=6; break; default: *dest=*source; dest++; break; } source++; } *dest=0; return dd; } // private: int lengthXMLString(LPCTSTR source) { int r=0; while (*source) { switch (*source) { case '<': r+=3; break; case '>' : r+=3; break; case '&' : r+=4; break; case '\'': r+=5; break; case '"' : r+=5; break; } source++; r++; } return r; } LPTSTR toXMLString(LPCTSTR source) { LPTSTR dest=(LPTSTR)malloc((lengthXMLString(source)+1)*sizeof(TCHAR)); return toXMLString(dest,source); } LPTSTR toXMLStringFast(LPTSTR *dest,int *destSz, LPCTSTR source) { int l=lengthXMLString(source)+1; if (l>*destSz) { *destSz=l; *dest=(LPTSTR)realloc(*dest,l*sizeof(TCHAR)); } return toXMLString(*dest,source); } // private: LPTSTR fromXMLString(LPCTSTR s, int lo) { // This function is the opposite of the function "toXMLString". It decodes the escape // sequences &, ", ', <, > and replace them by the characters // &,",',<,>. This function is used internally by the XML Parser. All the calls to // the XML library will always gives you back "decoded" strings. // // in: string (s) and length (lo) of string // out: new allocated string converted from xml if (!s) return NULL; int ll=0; LPTSTR d; LPCTSTR ss=s; while (((lo--)>0)&&(*s)) { if (*s==_T('&')) { s++; if (_tcsnicmp(s,_T("lt;" ),3)==0) { s+=2; lo-=3; } else if (_tcsnicmp(s,_T("gt;" ),3)==0) { s+=2; lo-=3; } else if (_tcsnicmp(s,_T("amp;" ),4)==0) { s+=3; lo-=4; } else if (_tcsnicmp(s,_T("apos;"),5)==0) { s+=4; lo-=5; } else if (_tcsnicmp(s,_T("quot;"),5)==0) { s+=4; lo-=5; } else { ll=0; while (s[ll]&&(s[ll]!=_T(';'))&&(ll<10)) ll++; ll++; d=(LPTSTR)malloc((ll+1)*sizeof(TCHAR)); d[ll]=0; while(ll--) d[ll]=s[ll]; #ifdef _UNICODE printf("unknown escape character: '&%S'",d); #else printf("unknown escape character: '&%s'",d); #endif free(d); exit(255); } }; ll++; s++; } d=(LPTSTR)malloc((ll+1)*sizeof(TCHAR)); s=d; while (ll--) { if (*ss==_T('&')) { ss++; if (_tcsnicmp(ss,_T("lt;" ),3)==0) { *(d++)=_T('<' ); ss+=3; } else if (_tcsnicmp(ss,_T("gt;" ),3)==0) { *(d++)=_T('>' ); ss+=3; } else if (_tcsnicmp(ss,_T("amp;" ),4)==0) { *(d++)=_T('&' ); ss+=4; } else if (_tcsnicmp(ss,_T("apos;"),5)==0) { *(d++)=_T('\''); ss+=5; } else { *(d++)=_T('"' ); ss+=5; } } else { *(d++)=*ss; ss++; } } *d=0; return (LPTSTR)s; } // private: char myTagCompare(LPCTSTR cclose, LPCTSTR copen) // !!!! WARNING strange convention&: // return 0 if equals // return 1 if different { if (!cclose) return 1; int l=(int)_tcslen(cclose); if (_tcsnicmp(cclose, copen, l)!=0) return 1; const TCHAR c=copen[l]; if ((c==_T('\n'))|| (c==_T(' ' ))|| (c==_T('\t'))|| (c==_T('\r'))|| (c==_T('/' ))|| (c==_T('<' ))|| (c==_T('>' ))|| (c==_T('=' ))) return 0; return 1; } // private: // update "order" information when deleting a content of a XMLNode void XMLNode::removeOrderElement(XMLNodeData *d, XMLElementType t, int index) { int j=(int)((index<<2)+t),i=0,n=nElement(d)+1, *o=d->pOrder; while ((o[i]!=j)&&(ipOrder=(int)realloc(d->pOrder,n*sizeof(int)); // but we skip reallocation because it's too time consuming. // Anyway, at the end, it will be free'd completely at once. } // Obtain the next character from the string. static inline TCHAR getNextChar(XML *pXML) { TCHAR ch = pXML->lpXML[pXML->nIndex]; if (ch!=0) pXML->nIndex++; return ch; } // Find next non-white space character. static TCHAR FindNonWhiteSpace(XML *pXML) { TCHAR ch=0; int nExit=FALSE; assert(pXML); // Iterate through characters in the string until we find a NULL or a // non-white space character while((nExit == FALSE) && (ch = getNextChar(pXML))) { switch(ch) { // Ignore white space case _T('\n'): case _T(' '): case _T('\t'): case _T('\r'): continue; default: nExit = TRUE; } } return ch; } // Find the next token in a string. // pcbToken contains the number of characters that have been read. static NextToken GetNextToken(XML *pXML, int *pcbToken, enum TokenTypeTag *pType) { NextToken result; LPCTSTR lpXML; TCHAR ch; TCHAR chTemp; int nSize; int nFoundMatch; int nExit; int n; LPCTSTR lpszOpen; int cbOpen; int nIsText = FALSE; // Find next non-white space character ch = FindNonWhiteSpace(pXML); if (ch) { // Cache the current string pointer lpXML = pXML->lpXML; result.pStr = &lpXML[pXML->nIndex-1]; // First check whether the token is in the clear tag list (meaning it // does not need formatting). n = 0; while(TRUE) { // Obtain the name of the open part of the clear tag lpszOpen = pXML->pClrTags[n].lpszOpen; if (lpszOpen) { // Compare the open tag with the current token cbOpen = (int)_tcslen(lpszOpen); // if (myTagCompare(lpszOpen, result.pStr) == 0) if (_tcsnicmp(lpszOpen, result.pStr, cbOpen)==0) { result.pClr = &pXML->pClrTags[n]; pXML->nIndex += (int)(_tcslen(lpszOpen)-1); *pType = eTokenClear; return result; } n++; } else break; } // If we didn't find a clear tag then check for standard tokens chTemp = 0; lpXML = pXML->lpXML; switch(ch) { // Check for quotes case _T('\''): case _T('\"'): // Type of token *pType = eTokenQuotedText; chTemp = ch; n=pXML->nIndex; // Set the size nSize = 1; nFoundMatch = FALSE; // Search through the string to find a matching quote while((ch = getNextChar(pXML))) { nSize++; if (ch==chTemp) { nFoundMatch = TRUE; break; } if (ch==_T('<')) break; } // If we failed to find a matching quote if (nFoundMatch == FALSE) { pXML->nIndex=n-1; ch=getNextChar(pXML); nIsText=TRUE; break; } // 4.02.2002 if (FindNonWhiteSpace(pXML)) { pXML->nIndex--; } break; // Equals (used with attribute values) case _T('='): nSize = 1; *pType = eTokenEquals; break; // Close tag case _T('>'): nSize = 1; *pType = eTokenCloseTag; break; // Check for tag start and tag end case _T('<'): // Peek at the next character to see if we have an end tag 'lpXML[pXML->nIndex]; // If we have a tag end... if (chTemp == _T('/')) { // Set the type and ensure we point at the next character getNextChar(pXML); *pType = eTokenTagEnd; nSize = 2; } // If we have an XML declaration tag else if (chTemp == _T('?')) { // Set the type and ensure we point at the next character getNextChar(pXML); *pType = eTokenDeclaration; nSize = 2; } // Otherwise we must have a start tag else { *pType = eTokenTagStart; nSize = 1; } break; // Check to see if we have a short hand type end tag ('/>'). case _T('/'): // Peek at the next character to see if we have a short end tag '/>' chTemp = pXML->lpXML[pXML->nIndex]; // If we have a short hand end tag... if (chTemp == _T('>')) { // Set the type and ensure we point at the next character getNextChar(pXML); *pType = eTokenShortHandClose; nSize = 2; break; } // If we haven't found a short hand closing tag then drop into the // text process // Other characters default: nIsText = TRUE; } // If this is a TEXT node if (nIsText) { // Indicate we are dealing with text *pType = eTokenText; nSize = 1; nExit = FALSE; while((nExit == FALSE) && (ch = getNextChar(pXML))) { switch(ch) { // Break when we find white space case _T('\n'): case _T(' '): case _T('\t'): case _T('\r'): nExit = TRUE; break; // If we find a slash then this maybe text or a short hand end tag. case _T('/'): // Peek at the next character to see it we have short hand end tag chTemp = pXML->lpXML[pXML->nIndex]; // If we found a short hand end tag then we need to exit the loop if (chTemp == _T('>')) { pXML->nIndex--; // 03.02.2002 nExit = TRUE; } else { nSize++; } break; // Break when we find a terminator and decrement the index and // column count so that we are pointing at the right character // the next time we are called. case _T('<'): case _T('>'): case _T('='): pXML->nIndex--; nExit = TRUE; break; case 0: nExit = TRUE; break; default: nSize++; } } } *pcbToken = nSize; } else { // If we failed to obtain a valid character *pcbToken = 0; *pType = eTokenError; result.pStr=NULL; } return result; } // Parse XML errors into a user friendly string. LPCTSTR XMLNode::getError(XMLError error) { switch (error) { case eXMLErrorNone: return _T("No error"); case eXMLErrorMissingEndTag: return _T("Warning: Unmatched end tag"); case eXMLErrorEmpty: return _T("Error: No XML data"); case eXMLErrorFirstNotStartTag: return _T("Error: First token not start tag"); case eXMLErrorMissingTagName: return _T("Error: Missing start tag name"); case eXMLErrorMissingEndTagName: return _T("Error: Missing end tag name"); case eXMLErrorNoMatchingQuote: return _T("Error: Unmatched quote"); case eXMLErrorUnmatchedEndTag: return _T("Error: Unmatched end tag"); case eXMLErrorUnexpectedToken: return _T("Error: Unexpected token found"); case eXMLErrorInvalidTag: return _T("Error: Invalid tag found"); case eXMLErrorNoElements: return _T("Error: No elements found"); case eXMLErrorFileNotFound: return _T("Error: File not found"); case eXMLErrorTagNotFound: return _T("Error: First Tag not found"); }; return _T("Unknown"); } void XMLNode::setName(LPCTSTR lpszName) { if (d->lpszName) free((void*)d->lpszName); d->lpszName=lpszName; } // private: XMLNode::XMLNode(XMLNodeData *pParent, LPCTSTR lpszName, int isDeclaration) { d=(XMLNodeData*)malloc(sizeof(XMLNodeData)); d->ref_count=1; d->lpszName=NULL; d->nChild= 0; d->nText = 0; d->nClear = 0; d->nAttribute = 0; d->isDeclaration = isDeclaration; d->pParent = pParent; d->pChild= NULL; d->pText= NULL; d->pClear= NULL; d->pAttribute= NULL; d->pOrder= NULL; setName(lpszName); } #define MEMORYINCREASE 50 int memoryIncrease=0; static void *myRealloc(void *p, int newsize, int memInc, int sizeofElem) { if (p==NULL) { if (memInc) return malloc(memInc*sizeofElem); return malloc(sizeofElem); } if ((memInc==0)||((newsize%memInc)==0)) p=realloc(p,(newsize+memInc)*sizeofElem); // if (!p) // { // printf("XMLParser Error: Not enough memory! Aborting...\n"); exit(220); // } return p; } void XMLNode::addToOrder(int index, int type) { int n=nElement(); d->pOrder=(int*)myRealloc(d->pOrder,n+1,memoryIncrease*3,sizeof(int)); d->pOrder[n]=(index<<2)+type; } // Add a child node to the given element. XMLNode XMLNode::addChild(LPCTSTR lpszName, int isDeclaration) { if (!lpszName) return emptyXMLNode; int nc=d->nChild; d->pChild=(XMLNode*)myRealloc(d->pChild,(nc+1),memoryIncrease,sizeof(XMLNode)); d->pChild[nc].d=NULL; d->pChild[nc]=XMLNode(d,lpszName,isDeclaration); addToOrder(nc,eNodeChild); d->nChild++; return d->pChild[nc]; } XMLNode XMLNode::createXMLTopNode() { return XMLNode(NULL,NULL,FALSE); } // Add an attribute to an element. XMLAttribute *XMLNode::addAttribute(LPCTSTR lpszName, LPCTSTR lpszValuev) { if (!lpszName) return &emptyXMLAttribute; int na=d->nAttribute; d->pAttribute=(XMLAttribute*)myRealloc(d->pAttribute,(na+1),memoryIncrease,sizeof(XMLAttribute)); XMLAttribute *pAttr=d->pAttribute+na; pAttr->lpszName = lpszName; pAttr->lpszValue = lpszValuev; addToOrder(na,eNodeAttribute); d->nAttribute++; return pAttr; } // Add text to the element. LPCTSTR XMLNode::addText(LPCTSTR lpszValue) { if (!lpszValue) return NULL; int nt=d->nText; d->pText=(LPCTSTR*)myRealloc(d->pText,(nt+1),memoryIncrease,sizeof(LPTSTR)); d->pText[nt]=lpszValue; addToOrder(nt,eNodeText); d->nText++; return d->pText[nt]; } // Add clear (unformatted) text to the element. XMLClear *XMLNode::addClear(LPCTSTR lpszValue, LPCTSTR lpszOpen, LPCTSTR lpszClose) { if (!lpszValue) return &emptyXMLClear; int nc=d->nClear; d->pClear=(XMLClear *)myRealloc(d->pClear,(nc+1),memoryIncrease,sizeof(XMLClear)); XMLClear *pNewClear=d->pClear+nc; pNewClear->lpszValue = lpszValue; pNewClear->lpszOpenTag = lpszOpen; pNewClear->lpszCloseTag = lpszClose; addToOrder(nc,eNodeClear); d->nClear++; return pNewClear; } // Trim the end of the text to remove white space characters. static void FindEndOfText(LPCTSTR lpszToken, int *pcbText) { TCHAR ch; int cbText; assert(lpszToken); assert(pcbText); cbText = (*pcbText)-1; while(TRUE) { assert(cbText >= 0); ch = lpszToken[cbText]; switch(ch) { case _T('\r'): case _T('\n'): case _T('\t'): case _T(' '): cbText--; break; default: *pcbText = cbText+1; return; } } } // Duplicate a given string. LPTSTR stringDup(LPCTSTR lpszData, int cbData) { if (lpszData==NULL) return NULL; LPTSTR lpszNew; if (cbData==0) cbData=(int)_tcslen(lpszData); lpszNew = (LPTSTR)malloc((cbData+1) * sizeof(TCHAR)); if (lpszNew) { memcpy(lpszNew, lpszData, (cbData) * sizeof(TCHAR)); lpszNew[cbData] = (TCHAR)NULL; } return lpszNew; } // private: // Parse a clear (unformatted) type node. int XMLNode::ParseClearTag(void *px, void *pa) { XML *pXML=(XML *)px; ClearTag *pClear=(ClearTag *)pa; int cbTemp = 0; LPCTSTR lpszTemp; LPCTSTR lpXML=&pXML->lpXML[pXML->nIndex]; // Find the closing tag lpszTemp = _tcsstr(lpXML, pClear->lpszClose); // Iterate through the tokens until we find the closing tag. if (lpszTemp) { // Cache the size and increment the index cbTemp = (int)(lpszTemp - lpXML); pXML->nIndex += cbTemp; pXML->nIndex += (int)_tcslen(pClear->lpszClose); // Add the clear node to the current element addClear(stringDup(lpXML,cbTemp), pClear->lpszOpen, pClear->lpszClose); return TRUE; } // If we failed to find the end tag pXML->error = eXMLErrorUnmatchedEndTag; return FALSE; } void XMLNode::exactMemory(XMLNodeData *d) { if (memoryIncrease<=1) return; if (d->pOrder) d->pOrder=(int*)realloc(d->pOrder,(d->nChild+d->nAttribute+d->nText+d->nClear)*sizeof(int)); if (d->pChild) d->pChild=(XMLNode*)realloc(d->pChild,d->nChild*sizeof(XMLNode)); if (d->pAttribute) d->pAttribute=(XMLAttribute*)realloc(d->pAttribute,d->nAttribute*sizeof(XMLAttribute)); if (d->pText) d->pText=(LPCTSTR*)realloc(d->pText,d->nText*sizeof(LPTSTR)); if (d->pClear) d->pClear=(XMLClear *)realloc(d->pClear,d->nClear*sizeof(XMLClear)); } // private: // Recursively parse an XML element. int XMLNode::ParseXMLElement(void *pa) { XML *pXML=(XML *)pa; int cbToken; enum TokenTypeTag type; NextToken token; LPCTSTR lpszTemp=NULL; int cbTemp; int nDeclaration; LPCTSTR lpszText=NULL; XMLNode pNew; enum Status status; // inside or outside a tag enum Attrib attrib = eAttribName; assert(pXML); // If this is the first call to the function if (pXML->nFirst) { // Assume we are outside of a tag definition pXML->nFirst = FALSE; status = eOutsideTag; } else { // If this is not the first call then we should only be called when inside a tag. status = eInsideTag; } // Iterate through the tokens in the document while(TRUE) { // Obtain the next token token = GetNextToken(pXML, &cbToken, &type); if (type != eTokenError) { // Check the current status switch(status) { // If we are outside of a tag definition case eOutsideTag: // Check what type of token we obtained switch(type) { // If we have found text or quoted text case eTokenText: case eTokenQuotedText: case eTokenEquals: if (!lpszText) { lpszText = token.pStr; } break; // If we found a start tag '<' and declarations 'error = eXMLErrorMissingTagName; return FALSE; } // If we found a new element which is the same as this // element then we need to pass this back to the caller.. #ifdef APPROXIMATE_PARSING if (d->lpszName && myTagCompare(d->lpszName, token.pStr) == 0) { // Indicate to the caller that it needs to create a // new element. pXML->lpNewElement = token.pStr; pXML->cbNewElement = cbToken; return TRUE; } else #endif { // If the name of the new element differs from the name of // the current element we need to add the new element to // the current one and recurse pNew = addChild(stringDup(token.pStr,cbToken), nDeclaration); while (!pNew.isEmpty()) { // Callself to process the new node. If we return // FALSE this means we dont have any more // processing to do... if (!pNew.ParseXMLElement(pXML)) return FALSE; else { // If the call to recurse this function // evented in a end tag specified in XML then // we need to unwind the calls to this // function until we find the appropriate node // (the element name and end tag name must // match) if (pXML->cbEndTag) { // If we are back at the root node then we // have an unmatched end tag if (!d->lpszName) { pXML->error=eXMLErrorUnmatchedEndTag; return FALSE; } // If the end tag matches the name of this // element then we only need to unwind // once more... if (myTagCompare(d->lpszName, pXML->lpEndTag)==0) { pXML->cbEndTag = 0; } return TRUE; } else if (pXML->cbNewElement) { // If the call indicated a new element is to // be created on THIS element. // If the name of this element matches the // name of the element we need to create // then we need to return to the caller // and let it process the element. if (myTagCompare(d->lpszName, pXML->lpNewElement)==0) { return TRUE; } // Add the new element and recurse pNew = addChild(stringDup(pXML->lpNewElement,pXML->cbNewElement)); pXML->cbNewElement = 0; } else { // If we didn't have a new element to create pNew = emptyXMLNode; } } } } break; // If we found an end tag case eTokenTagEnd: // If we have node text then add this to the element if (lpszText) { cbTemp = (int)(token.pStr - lpszText); FindEndOfText(lpszText, &cbTemp); addText(fromXMLString(lpszText,cbTemp)); lpszText = NULL; } // Find the name of the end tag token = GetNextToken(pXML, &cbTemp, &type); // The end tag should be text if (type != eTokenText) { pXML->error = eXMLErrorMissingEndTagName; return FALSE; } lpszTemp = token.pStr; // After the end tag we should find a closing tag token = GetNextToken(pXML, &cbToken, &type); if (type != eTokenCloseTag) { pXML->error = eXMLErrorMissingEndTagName; return FALSE; } // We need to return to the previous caller. If the name // of the tag cannot be found we need to keep returning to // caller until we find a match if (myTagCompare(d->lpszName, lpszTemp) != 0) #ifdef STRICT_PARSING { pXML->error=eXMLErrorUnmatchedEndTag; return FALSE; } #else { pXML->error=eXMLErrorMissingEndTag; pXML->lpEndTag = lpszTemp; pXML->cbEndTag = cbTemp; } #endif // Return to the caller exactMemory(d); return TRUE; // If we found a clear (unformatted) token case eTokenClear: // If we have node text then add this to the element if (lpszText) { cbTemp = (int)(token.pStr - lpszText); FindEndOfText(lpszText, &cbTemp); addText(stringDup(lpszText,cbTemp)); lpszText = NULL; } if (!ParseClearTag(pXML, token.pClr)) { return FALSE; } break; // Errors... case eTokenCloseTag: /* '>' */ case eTokenShortHandClose: /* '/>' */ pXML->error = eXMLErrorUnexpectedToken; return FALSE; default: break; } break; // If we are inside a tag definition we need to search for attributes case eInsideTag: // Check what part of the attribute (name, equals, value) we // are looking for. switch(attrib) { // If we are looking for a new attribute case eAttribName: // Check what the current token type is switch(type) { // If the current type is text... // Eg. 'attribute' case eTokenText: // Cache the token then indicate that we are next to // look for the equals lpszTemp = token.pStr; cbTemp = cbToken; attrib = eAttribEquals; break; // If we found a closing tag... // Eg. '>' case eTokenCloseTag: // We are now outside the tag status = eOutsideTag; break; // If we found a short hand '/>' closing tag then we can // return to the caller case eTokenShortHandClose: exactMemory(d); return TRUE; // Errors... case eTokenQuotedText: /* '"SomeText"' */ case eTokenTagStart: /* '<' */ case eTokenTagEnd: /* 'error = eXMLErrorUnexpectedToken; return FALSE; default: break; } break; // If we are looking for an equals case eAttribEquals: // Check what the current token type is switch(type) { // If the current type is text... // Eg. 'Attribute AnotherAttribute' case eTokenText: // Add the unvalued attribute to the list addAttribute(stringDup(lpszTemp,cbTemp), NULL); // Cache the token then indicate. We are next to // look for the equals attribute lpszTemp = token.pStr; cbTemp = cbToken; break; // If we found a closing tag 'Attribute >' or a short hand // closing tag 'Attribute />' case eTokenShortHandClose: case eTokenCloseTag: // If we are a declaration element 'isDeclaration && (lpszTemp[cbTemp-1]) == _T('?')) { cbTemp--; } if (cbTemp) { // Add the unvalued attribute to the list addAttribute(stringDup(lpszTemp,cbTemp), NULL); } // If this is the end of the tag then return to the caller if (type == eTokenShortHandClose) { exactMemory(d); return TRUE; } // We are now outside the tag status = eOutsideTag; break; // If we found the equals token... // Eg. 'Attribute =' case eTokenEquals: // Indicate that we next need to search for the value // for the attribute attrib = eAttribValue; break; // Errors... case eTokenQuotedText: /* 'Attribute "InvalidAttr"'*/ case eTokenTagStart: /* 'Attribute <' */ case eTokenTagEnd: /* 'Attribute error = eXMLErrorUnexpectedToken; return FALSE; default: break; } break; // If we are looking for an attribute value case eAttribValue: // Check what the current token type is switch(type) { // If the current type is text or quoted text... // Eg. 'Attribute = "Value"' or 'Attribute = Value' or // 'Attribute = 'Value''. case eTokenText: case eTokenQuotedText: // If we are a declaration element 'isDeclaration && (token.pStr[cbToken-1]) == _T('?')) { cbToken--; } if (cbTemp) { // Add the valued attribute to the list if (type==eTokenQuotedText) { token.pStr++; cbToken-=2; } addAttribute(stringDup(lpszTemp,cbTemp),fromXMLString(token.pStr,cbToken)); } // Indicate we are searching for a new attribute attrib = eAttribName; break; // Errors... case eTokenTagStart: /* 'Attr = <' */ case eTokenTagEnd: /* 'Attr = ' */ case eTokenShortHandClose: /* "Attr = />" */ case eTokenEquals: /* 'Attr = =' */ case eTokenDeclaration: /* 'Attr = error = eXMLErrorUnexpectedToken; return FALSE; break; default: break; } } } } // If we failed to obtain the next token else { return FALSE; } } } // Count the number of lines and columns in an XML string. static void CountLinesAndColumns(LPCTSTR lpXML, int nUpto, XMLResults *pResults) { TCHAR ch; int n; assert(lpXML); assert(pResults); pResults->nLine = 1; pResults->nColumn = 1; for(n=0; nnLine++; pResults->nColumn = 1; } else pResults->nColumn++; } } // Parse XML and return the root element. XMLNode XMLNode::parseString(LPCTSTR lpszXML, LPCTSTR tag, XMLResults *pResults) { if (!lpszXML) { if (pResults) { pResults->error=eXMLErrorNoElements; pResults->nLine=0; pResults->nColumn=0; } return emptyXMLNode; } static struct ClearTag tags[] = { { _T("") }, { _T("
"),        _T("
") }, { _T("") }, { _T("") }, { _T("") }, { NULL, NULL } }; enum XMLError error; XMLNode xnode(NULL,NULL,FALSE); struct XML xml={ NULL, 0, eXMLErrorNone, NULL, 0, NULL, 0, TRUE , NULL}; xml.lpXML = lpszXML; xml.pClrTags = tags; // Create header element memoryIncrease=MEMORYINCREASE; xnode.ParseXMLElement(&xml); memoryIncrease=0; error = xml.error; // If an error occurred if ((error==eXMLErrorNone)||(error==eXMLErrorMissingEndTag)) { if (tag&&_tcslen(tag)) { XMLNode nodeTmp; int i=0; while (ierror=eXMLErrorTagNotFound; pResults->nLine=0; pResults->nColumn=0; } return emptyXMLNode; } xnode=nodeTmp; } } else { // Cleanup: this will destroy all the nodes xnode = emptyXMLNode; } // If we have been given somewhere to place results if (pResults) { pResults->error = error; // If we have an error if ((error!=eXMLErrorNone)&&(error!=eXMLErrorMissingEndTag)) { // Find which line and column it starts on. CountLinesAndColumns(xml.lpXML, xml.nIndex, pResults); } } return xnode; } XMLNode XMLNode::parseFile(const char *filename, LPCTSTR tag, XMLResults *pResults) { FILE *f=fopen(filename,"rb"); if (f==NULL) { if (pResults) { pResults->error=eXMLErrorFileNotFound; pResults->nLine=0; pResults->nColumn=0; } return emptyXMLNode; } fseek(f,0,SEEK_END); int l=ftell(f); fseek(f,0,SEEK_SET); char *buf=(char*)malloc(l+1); fread(buf,l,1,f); fclose(f); buf[l]=0; #ifdef __linux__ #ifdef _UNICODE // The 5 next lines convert multibyte character strings to wide characters. // These lines are only useful if the file is not already in UNICODE. const char *p=buf; LPTSTR b2=(LPTSTR)malloc(l*sizeof(TCHAR)+sizeof(TCHAR)); mbsrtowcs(b2,&p,l,0); // this is the GCC equivalent of MultiByteToWideChar(). REVISIT: Check for return value free(buf); buf=(char*)b2; #endif #elif defined(WIN32) #ifdef _UNICODE if (!IsTextUnicode(buf,mmin(l,10000),NULL)) { LPTSTR b2=(LPTSTR)malloc(l*2+2); MultiByteToWideChar(CP_ACP, // code page MB_PRECOMPOSED, // character-type options buf, // string to map l, // number of bytes in string b2, // wide-character buffer l*2+2); // size of buffer free(buf); buf=(char*)b2; } #else if (IsTextUnicode(buf,mmin(l,10000),NULL)) { l>>=1; LPTSTR b2=(LPTSTR)malloc(l+2); WideCharToMultiByte(CP_ACP, // code page 0, // performance and mapping flags (const WCHAR*)buf, // wide-character string l, // number of chars in string b2, // buffer for new string l+2, // size of buffer NULL, // default for unmappable chars NULL // set when default char used ); free(buf); buf=(char*)b2; } #endif #endif XMLNode x=parseString((LPTSTR)buf,tag,pResults); free(buf); return x; } XMLNode XMLNode::openFileHelper(const char *lpszXML, LPCTSTR tag) { XMLResults pResults; XMLNode xnode=XMLNode::parseFile(lpszXML, tag, &pResults); if (pResults.error != eXMLErrorNone) { printf( "XML Parsing error inside file '%s'.\n" #ifdef _UNICODE "Error: %S\n" #else "Error: %s\n" #endif "At line %i, column %i.\n",lpszXML, XMLNode::getError(pResults.error),pResults.nLine,pResults.nColumn); if (pResults.error==eXMLErrorTagNotFound) { #ifdef _UNICODE printf("Tag is '%S'.\n",tag); #else printf("Tag is '%s'.\n",tag); #endif } exit(255); } return xnode; } XMLNodeContents XMLNode::enumContents(int i) { XMLNodeContents c; if (!d) { c.type=eNodeNULL; return c; } c.type=(XMLElementType)(d->pOrder[i]&3); i=(d->pOrder[i])>>2; switch (c.type) { case eNodeChild: c.child = d->pChild[i]; break; case eNodeAttribute: c.attrib= d->pAttribute[i]; break; case eNodeText: c.text = d->pText[i]; break; case eNodeClear: c.clear = d->pClear[i]; break; default: break; } return c; } // private: void *XMLNode::enumContent(XMLNodeData *pEntry, int i, XMLElementType *nodeType) { XMLElementType j=(XMLElementType)(pEntry->pOrder[i]&3); *nodeType=j; i=(pEntry->pOrder[i])>>2; switch (j) { case eNodeChild: return pEntry->pChild[i].d; case eNodeAttribute: return pEntry->pAttribute+i; case eNodeText: return (void*)(pEntry->pText[i]); case eNodeClear: return pEntry->pClear+i; default: break; } return NULL; } // private: int XMLNode::nElement(XMLNodeData *pEntry) { return pEntry->nChild+pEntry->nText+pEntry->nClear+pEntry->nAttribute; } static inline void charmemset(LPTSTR dest,TCHAR c,int l) { while (l--) *(dest++)=c; } // private: // Creates an user friendly XML string from a given element with // appropriate white space and carriage returns. // // This recurses through all subnodes then adds contents of the nodes to the // string. int XMLNode::CreateXMLStringR(XMLNodeData *pEntry, LPTSTR lpszMarker, int nFormat) { int nResult = 0; int cb; int cbElement; int nIndex; int nChildFormat=-1; int bHasChildren=FALSE; int i; XMLAttribute * pAttr; assert(pEntry); #define LENSTR(lpsz) (lpsz ? _tcslen(lpsz) : 0) // If the element has no name then assume this is the head node. cbElement = (int)LENSTR(pEntry->lpszName); if (cbElement) { // "isDeclaration) lpszMarker[nResult++]=_T('?'); _tcscpy(&lpszMarker[nResult], pEntry->lpszName); nResult+=cbElement; lpszMarker[nResult++]=_T(' '); } else { nResult+=cbElement+2+cb; if (pEntry->isDeclaration) nResult++; } // Enumerate attributes and add them to the string nIndex = pEntry->nAttribute; pAttr=pEntry->pAttribute; for (i=0; ilpszName); if (cb) { if (lpszMarker) _tcscpy(&lpszMarker[nResult], pAttr->lpszName); nResult += cb; // "Attrib=Value " cb = (int)lengthXMLString(pAttr->lpszValue); if (lpszMarker) { lpszMarker[nResult]=_T('='); lpszMarker[nResult+1]=_T('"'); if (cb) toXMLString(&lpszMarker[nResult+2],pAttr->lpszValue); lpszMarker[nResult+cb+2]=_T('"'); } nResult+=cb+3; if (lpszMarker) lpszMarker[nResult] = _T(' '); nResult++; } pAttr++; } bHasChildren=(pEntry->nAttribute!=nElement(pEntry)); if (pEntry->isDeclaration) { if (lpszMarker) { lpszMarker[nResult-1]=_T('?'); lpszMarker[nResult]=_T('>'); } nResult++; if (nFormat!=-1) { if (lpszMarker) lpszMarker[nResult]=_T('\n'); nResult++; } } else // If there are child nodes we need to terminate the start tag if (bHasChildren) { if (lpszMarker) lpszMarker[nResult-1]=_T('>'); if (nFormat!=-1) { if (lpszMarker) lpszMarker[nResult]=_T('\n'); nResult++; } } else nResult--; } // Calculate the child format for when we recurse. This is used to // determine the number of spaces used for prefixes. if (nFormat!=-1) { if (cbElement&&(!pEntry->isDeclaration)) nChildFormat=nFormat+1; else nChildFormat=nFormat; } // Enumerate through remaining children nIndex = nElement(pEntry); XMLElementType nodeType; void *pChild; for (i=0; ilpszOpenTag); if (cb) { if (nFormat!=-1) { if (lpszMarker) { charmemset(&lpszMarker[nResult], INDENTCHAR, sizeof(TCHAR)*(nFormat + 1)); _tcscpy(&lpszMarker[nResult+nFormat+1], ((XMLClear*)pChild)->lpszOpenTag); } nResult+=cb+nFormat+1; } else { if (lpszMarker)_tcscpy(&lpszMarker[nResult], ((XMLClear*)pChild)->lpszOpenTag); nResult += cb; } } // "OpenTag Value" cb = (int)LENSTR(((XMLClear*)pChild)->lpszValue); if (cb) { if (lpszMarker) _tcscpy(&lpszMarker[nResult], ((XMLClear*)pChild)->lpszValue); nResult += cb; } // "OpenTag Value CloseTag" cb = (int)LENSTR(((XMLClear*)pChild)->lpszCloseTag); if (cb) { if (lpszMarker) _tcscpy(&lpszMarker[nResult], ((XMLClear*)pChild)->lpszCloseTag); nResult += cb; } if (nFormat!=-1) { if (lpszMarker) lpszMarker[nResult] = _T('\n'); nResult++; } break; // Element nodes case eNodeChild: // Recursively add child nodes nResult += CreateXMLStringR((XMLNodeData*)pChild, lpszMarker ? lpszMarker + nResult : 0, nChildFormat); break; default: break; } } if ((cbElement)&&(!pEntry->isDeclaration)) { // If we have child entries we need to use long XML notation for // closing the element - "blah blah blah" if (bHasChildren) { // "\0" if (lpszMarker) { if (nFormat != -1) { if (nFormat) { charmemset(&lpszMarker[nResult], INDENTCHAR,sizeof(TCHAR)*nFormat); nResult+=nFormat; } } _tcscpy(&lpszMarker[nResult], _T("lpszName); nResult += cbElement; if (nFormat == -1) { _tcscpy(&lpszMarker[nResult], _T(">")); nResult++; } else { _tcscpy(&lpszMarker[nResult], _T(">\n")); nResult+=2; } } else { if (nFormat != -1) nResult+=cbElement+4+nFormat; else nResult+=cbElement+3; } } else { // If there are no children we can use shorthand XML notation - // "" // "/>\0" if (lpszMarker) { if (nFormat == -1) { _tcscpy(&lpszMarker[nResult], _T("/>")); nResult += 2; } else { _tcscpy(&lpszMarker[nResult], _T("/>\n")); nResult += 3; } } else { nResult += nFormat == -1 ? 2 : 3; } } } return nResult; } #undef LENSTR // Create an XML string // @param int nFormat - 0 if no formatting is required // otherwise nonzero for formatted text // with carriage returns and indentation. // @param int *pnSize - [out] pointer to the size of the // returned string not including the // NULL terminator. // @return LPTSTR - Allocated XML string, you must free // this with free(). LPTSTR XMLNode::createXMLString(int nFormat, int *pnSize) { if (!d) { if (pnSize) *pnSize=0; return NULL; } LPTSTR lpszResult = NULL; int cbStr; // Recursively Calculate the size of the XML string nFormat = nFormat ? 0 : -1; cbStr = CreateXMLStringR(d, 0, nFormat); assert(cbStr); // Alllocate memory for the XML string + the NULL terminator and // create the recursively XML string. lpszResult=(LPTSTR)malloc((cbStr+1)*sizeof(TCHAR)); CreateXMLStringR(d, lpszResult, nFormat); if (pnSize) *pnSize = cbStr; return lpszResult; } XMLNode::~XMLNode() { destroyCurrentBuffer(d); } void XMLNode::deleteNodeContent() { destroyCurrentBuffer(d); } void XMLNode::detachFromParent(XMLNodeData *d) { XMLNode *pa=d->pParent->pChild; int i=0; while (((void*)(pa[i].d))!=((void*)d)) i++; d->pParent->nChild--; memmove(pa+i,pa+i+1,(d->pParent->nChild-i)*sizeof(XMLNode)); removeOrderElement(d->pParent,eNodeChild,i); } void XMLNode::destroyCurrentBuffer(XMLNodeData *d) { if (!d) return; (d->ref_count) --; if (d->ref_count==0) { int i; if (d->pParent) detachFromParent(d); for(i=0; inChild; i++) { d->pChild[i].d->pParent=NULL; destroyCurrentBuffer(d->pChild[i].d); } free(d->pChild); for(i=0; inText; i++) free((void*)d->pText[i]); free(d->pText); for(i=0; inClear; i++) free((void*)d->pClear[i].lpszValue); free(d->pClear); for(i=0; inAttribute; i++) { free((void*)d->pAttribute[i].lpszName); if (d->pAttribute[i].lpszValue) free((void*)d->pAttribute[i].lpszValue); } free(d->pAttribute); free(d->pOrder); free((void*)d->lpszName); free(d); d=NULL; } } XMLNode XMLNode::addChild(XMLNode childNode) { XMLNodeData *dc=childNode.d; if ((!dc)||(!d)) return childNode; if (dc->pParent) detachFromParent(dc); else dc->ref_count++; dc->pParent=d; dc->isDeclaration=0; int nc=d->nChild; d->pChild=(XMLNode*)myRealloc(d->pChild,(nc+1),memoryIncrease,sizeof(XMLNode)); d->pChild[nc].d=dc; addToOrder(nc,eNodeChild); d->nChild++; return childNode; } void XMLNode::deleteAttribute(int i) { if ((!d)||(i>=d->nAttribute)) return; d->nAttribute--; XMLAttribute *p=d->pAttribute+i; free((void*)p->lpszName); if (p->lpszValue) free((void*)p->lpszValue); memmove(p,p+1,(d->nAttribute-i)*sizeof(XMLAttribute)); removeOrderElement(d,eNodeAttribute,i); } void XMLNode::deleteAttribute(LPCTSTR lpszName) { if (!d) return; int i,l=d->nAttribute; XMLAttribute *pa=d->pAttribute; for (i=0; ilpszName); } void XMLNode::deleteAttributeRelaxed(LPCTSTR lpszName) { int j=0; getAttribute(lpszName,&j); if (j) deleteAttribute(j-1); } void XMLNode::deleteText(int i) { if ((!d)||(i>=d->nText)) return; d->nText--; LPCTSTR *p=d->pText+i; free((void*)*p); memmove(p,p+1,(d->nText-i)*sizeof(LPCTSTR)); removeOrderElement(d,eNodeText,i); } void XMLNode::deleteText(LPCTSTR lpszValue) { if (!d) return; int i,l=d->nText; LPCTSTR *p=d->pText; for (i=0; i=d->nClear)) return; d->nClear--; XMLClear *p=d->pClear+i; free((void*)p->lpszValue); memmove(p,p+1,(d->nText-i)*sizeof(XMLClear)); removeOrderElement(d,eNodeClear,i); } void XMLNode::deleteClear(LPCTSTR lpszValue) { if (!d) return; int i,l=d->nClear; XMLClear *p=d->pClear; for (i=0; ilpszValue); } XMLNode& XMLNode::operator=( const XMLNode& A ) { // shallow copy if (this != &A) { destroyCurrentBuffer(d); d=A.d; if (d) (d->ref_count) ++ ; } return *this; } XMLNode::XMLNode(const XMLNode &A) { // shallow copy d=A.d; if (d) (d->ref_count)++ ; } int XMLNode::nChildNode(LPCTSTR name) { if (!d) return 0; int i,j=0,n=d->nChild; XMLNode *pc=d->pChild; for (i=0; id->lpszName, name)==0) j++; pc++; } return j; } XMLNode XMLNode::getChildNode(LPCTSTR name, int *j) { if (!d) return emptyXMLNode; int i=0,n=d->nChild; if (j) i=*j; XMLNode *pc=d->pChild+i; for (; id->lpszName, name)==0) { if (j) *j=i+1; return *pc; } pc++; } return emptyXMLNode; } XMLNode XMLNode::getChildNode(LPCTSTR name, int j) { if (!d) return emptyXMLNode; int i=0; while (j-->0) getChildNode(name,&i); return getChildNode(name,&i); } // Find an attribute on an node. LPCTSTR XMLNode::getAttribute(LPCTSTR lpszAttrib, int *j) { if (!d) return NULL; int i=0,n=d->nAttribute; if (j) i=*j; XMLAttribute *pAttr=d->pAttribute+i; for (; ilpszName, lpszAttrib)==0) { if (j) *j=i+1; return pAttr->lpszValue; } pAttr++; } return NULL; } char XMLNode::isAttributeSet(LPCTSTR lpszAttrib) { if (!d) return FALSE; int i,n=d->nAttribute; XMLAttribute *pAttr=d->pAttribute; for (i=0; ilpszName, lpszAttrib)==0) { return TRUE; } pAttr++; } return FALSE; } LPCTSTR XMLNode::getAttribute(LPCTSTR name, int j) { if (!d) return NULL; int i=0; while (j-->0) getAttribute(name,&i); return getAttribute(name,&i); } LPCTSTR XMLNode::getName(){ if (!d) return NULL; return d->lpszName; } int XMLNode::nText() { if (!d) return 0; return d->nText; } int XMLNode::nChildNode() { if (!d) return 0; return d->nChild; } int XMLNode::nAttribute() { if (!d) return 0; return d->nAttribute; } int XMLNode::nClear() { if (!d) return 0; return d->nClear; } XMLClear XMLNode::getClear (int i) { if (!d) return emptyXMLClear; if (i>=d->nClear ) return emptyXMLClear; return d->pClear[i]; } XMLAttribute XMLNode::getAttribute (int i) { if (!d) return emptyXMLAttribute; if (i>=d->nAttribute) return emptyXMLAttribute; return d->pAttribute[i]; } LPCTSTR XMLNode::getText (int i) { if (!d) return NULL; if (i>=d->nText ) return NULL; return d->pText[i]; } XMLNode XMLNode::getChildNode (int i) { if (!d) return emptyXMLNode; if (i>=d->nChild ) return emptyXMLNode; return d->pChild[i]; } char XMLNode::isDeclaration( ) { if (!d) return 0; return d->isDeclaration; } char XMLNode::isEmpty ( ) { return (d==NULL); } int XMLNode::nElement ( ) { if (!d) return 0; return d->nChild+d->nText+d->nClear+d->nAttribute; } libmusicbrainz-3.0.2/src/filters.cpp0000644000175000017500000001020010477236200016506 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: filters.cpp 8466 2006-09-05 08:59:44Z luks $ */ #include #include #include #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; ArtistFilter::ParameterList ArtistFilter::createParameters() const { return parameters; } ArtistFilter & ArtistFilter::name(const string &value) { parameters.push_back(pair(string("name"), value)); return *this; } ArtistFilter & ArtistFilter::limit(const int value) { parameters.push_back(pair(string("limit"), intToString(value))); return *this; } ReleaseFilter::ParameterList ReleaseFilter::createParameters() const { return parameters; } ReleaseFilter & ReleaseFilter::title(const string &value) { parameters.push_back(pair(string("title"), value)); return *this; } ReleaseFilter & ReleaseFilter::discId(const string &value) { parameters.push_back(pair(string("discid"), value)); return *this; } ReleaseFilter & ReleaseFilter::releaseType(const string &value) { string type = extractFragment(value); for (ParameterList::iterator i = parameters.begin(); i != parameters.end(); i++) { if (i->first == string("releasetypes")) { i->second += string(" ") + type; return *this; } } parameters.push_back(pair(string("releasetypes"), type)); return *this; } ReleaseFilter & ReleaseFilter::artistName(const string &value) { parameters.push_back(pair(string("artist"), value)); return *this; } ReleaseFilter & ReleaseFilter::artistId(const string &value) { parameters.push_back(pair(string("artistid"), value)); return *this; } ReleaseFilter & ReleaseFilter::limit(const int value) { parameters.push_back(pair(string("limit"), intToString(value))); return *this; } TrackFilter::ParameterList TrackFilter::createParameters() const { return parameters; } TrackFilter & TrackFilter::title(const string &value) { parameters.push_back(pair(string("title"), value)); return *this; } TrackFilter & TrackFilter::artistName(const string &value) { parameters.push_back(pair(string("artist"), value)); return *this; } TrackFilter & TrackFilter::artistId(const string &value) { parameters.push_back(pair(string("artistid"), value)); return *this; } TrackFilter & TrackFilter::releaseTitle(const string &value) { parameters.push_back(pair(string("release"), value)); return *this; } TrackFilter & TrackFilter::releaseId(const string &value) { parameters.push_back(pair(string("releaseid"), value)); return *this; } TrackFilter & TrackFilter::duration(const int value) { parameters.push_back(pair(string("duration"), intToString(value))); return *this; } TrackFilter & TrackFilter::puid(const string &value) { parameters.push_back(pair(string("puid"), value)); return *this; } TrackFilter & TrackFilter::limit(const int value) { parameters.push_back(pair(string("limit"), intToString(value))); return *this; } UserFilter::ParameterList UserFilter::createParameters() const { return parameters; } UserFilter & UserFilter::name(const string &value) { parameters.push_back(pair(string("name"), value)); return *this; } libmusicbrainz-3.0.2/src/utils_releasetypenames.h0000644000175000017500000000175210437363020021302 0ustar lukaslukas/* $Id: utils_releasetypenames.h 7772 2006-05-31 18:53:04Z luks $ */ static const char *releaseTypeNames[][2] = { {"http://musicbrainz.org/ns/mmd-1.0#None", "None"}, {"http://musicbrainz.org/ns/mmd-1.0#Album", "Album"}, {"http://musicbrainz.org/ns/mmd-1.0#Single", "Single"}, {"http://musicbrainz.org/ns/mmd-1.0#EP", "EP"}, {"http://musicbrainz.org/ns/mmd-1.0#Compilation", "Compilation"}, {"http://musicbrainz.org/ns/mmd-1.0#Soundtrack", "Soundtrack"}, {"http://musicbrainz.org/ns/mmd-1.0#Spokenword", "Spokenword"}, {"http://musicbrainz.org/ns/mmd-1.0#Interview", "Interview"}, {"http://musicbrainz.org/ns/mmd-1.0#Audiobook", "Audiobook"}, {"http://musicbrainz.org/ns/mmd-1.0#Live", "Live"}, {"http://musicbrainz.org/ns/mmd-1.0#Remix", "Remix"}, {"http://musicbrainz.org/ns/mmd-1.0#Other", "Other"}, {"http://musicbrainz.org/ns/mmd-1.0#Official", "Official"}, {"http://musicbrainz.org/ns/mmd-1.0#Promotion", "Promotion"}, {"http://musicbrainz.org/ns/mmd-1.0#Bootleg", "Bootleg"}, }; libmusicbrainz-3.0.2/src/mb_c.cpp0000644000175000017500000003616311032622261015750 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: mb_c.cpp 9932 2008-07-02 06:48:17Z luks $ */ #include #include #include extern "C" { using namespace std; using namespace MusicBrainz; /* A little bit of cpp goodness :) */ #define MB_C_NEW_NOARGS(TYPE1, TYPE2) \ Mb##TYPE1 \ mb_##TYPE2##_new() \ { \ TYPE1 *o = new TYPE1(); \ return (Mb##TYPE1)o; \ } #define MB_C_FREE(TYPE1, TYPE2) \ void \ mb_##TYPE2##_free(Mb##TYPE1 o) \ { \ delete (TYPE1 *)o; \ } #define MB_C_STR_SETTER(TYPE1, TYPE2, PROP1, PROP2) \ void \ mb_##TYPE2##_set_##PROP2(Mb##TYPE1 o, const char *str) \ { \ try { \ ((TYPE1 *)o)->set##PROP1(str); \ } \ catch (...) { \ } \ } #define MB_C_INT_SETTER(TYPE1, TYPE2, PROP1, PROP2) \ void \ mb_##TYPE2##_set_##PROP2(Mb##TYPE1 o, int i) \ { \ try { \ ((TYPE1 *)o)->set##PROP1(i); \ } \ catch (...) { \ } \ } #define MB_C_STR_GETTER(TYPE1, TYPE2, PROP1, PROP2) \ void \ mb_##TYPE2##_get_##PROP2(Mb##TYPE1 o, char *str, int len) \ { \ try { \ strncpy(str, ((TYPE1 *)o)->get##PROP1().c_str(), len); \ } \ catch (...) { \ str[0] = '\0'; \ } \ } #define MB_C_INT_GETTER(TYPE1, TYPE2, PROP1, PROP2) \ int \ mb_##TYPE2##_get_##PROP2(Mb##TYPE1 o) \ { \ try { \ return ((TYPE1 *)o)->get##PROP1(); \ } \ catch (...) { \ return 0; \ } \ } #define MB_C_BOOL_GETTER(TYPE1, TYPE2, PROP1, PROP2) \ int \ mb_##TYPE2##_get_##PROP2(Mb##TYPE1 o) \ { \ try { \ return ((TYPE1 *)o)->get##PROP1() ? 1 : 0; \ } \ catch (...) { \ return 0; \ } \ } #define MB_C_OBJ_GETTER(TYPE1, TYPE2, PROP1, PROP2, OBJTYPE) \ OBJTYPE \ mb_##TYPE2##_get_##PROP2(Mb##TYPE1 o) \ { \ try { \ return (OBJTYPE)((TYPE1 *)o)->get##PROP1(); \ } \ catch (...) { \ return (OBJTYPE)0; \ } \ } #define MB_C_OBJ_LIST_GETTER(TYPE1, TYPE2, PLR1, PLR2, SNG1, SNG2, RTYPE) \ int \ mb_##TYPE2##_get_num_##PLR2(Mb##TYPE1 o) \ { \ try { \ return ((TYPE1 *)o)->getNum##PLR1(); \ } \ catch (...) { \ return 0; \ } \ } \ Mb##RTYPE \ mb_##TYPE2##_get_##SNG2(Mb##TYPE1 o, int index) \ { \ try { \ return (Mb##RTYPE)((TYPE1 *)o)->get##SNG1(index); \ } \ catch (...) { \ return (Mb##RTYPE)0; \ } \ } #define MB_C_STR_LIST_GETTER(TYPE1, TYPE2, PLR1, PLR2, SNG1, SNG2) \ int \ mb_##TYPE2##_get_num_##PLR2(Mb##TYPE1 o) \ { \ try { \ return ((TYPE1 *)o)->getNum##PLR1(); \ } \ catch (...) { \ return 0; \ } \ } \ void \ mb_##TYPE2##_get_##SNG2(Mb##TYPE1 o, int index, char *str, int len) \ { \ try { \ strncpy(str, ((TYPE1 *)o)->get##SNG1(index).c_str(), len); \ } \ catch (...) { \ str[0] = '\0'; \ } \ } #define MB_C_INCLUDES(TYPE1, TYPE2, INC1, INC2) \ Mb##TYPE1 \ mb_##TYPE2##_##INC2(Mb##TYPE1 o) \ { \ ((TYPE1 *)o)->INC1(); \ return o; \ } #define MB_C_INT_FILTER(TYPE1, TYPE2, INC1, INC2) \ Mb##TYPE1 \ mb_##TYPE2##_##INC2(Mb##TYPE1 o, int i) \ { \ ((TYPE1 *)o)->INC1(i); \ return o; \ } #define MB_C_STR_FILTER(TYPE1, TYPE2, INC1, INC2) \ Mb##TYPE1 \ mb_##TYPE2##_##INC2(Mb##TYPE1 o, const char *s) \ { \ ((TYPE1 *)o)->INC1(s); \ return o; \ } /* === MusicBrainz::WebService === */ MB_C_NEW_NOARGS(WebService, webservice) MB_C_FREE(WebService, webservice) MB_C_STR_SETTER(WebService, webservice, Host, host) MB_C_INT_SETTER(WebService, webservice, Port, port) MB_C_STR_SETTER(WebService, webservice, PathPrefix, path_prefix) MB_C_STR_SETTER(WebService, webservice, UserName, username) MB_C_STR_SETTER(WebService, webservice, Password, password) MB_C_STR_SETTER(WebService, webservice, Realm, realm) MB_C_STR_SETTER(WebService, webservice, ProxyHost, proxy_host) MB_C_INT_SETTER(WebService, webservice, ProxyPort, proxy_port) MB_C_STR_SETTER(WebService, webservice, ProxyUserName, proxy_username) MB_C_STR_SETTER(WebService, webservice, ProxyPassword, proxy_password) /* === MusicBrainz::Query === */ MbQuery mb_query_new(MbWebService ws, const char *client_id) { Query *query = new Query((WebService *)ws, client_id ? client_id : ""); return (MbQuery)query; } MB_C_FREE(Query, query) MbArtist mb_query_get_artist_by_id(MbQuery q, const char *id, MbArtistIncludes inc) { Query *query = (Query *)q; try { return (MbArtist)query->getArtistById(id, (ArtistIncludes *)inc); } catch (...) { return NULL; } } MbRelease mb_query_get_release_by_id(MbQuery q, const char *id, MbReleaseIncludes inc) { Query *query = (Query *)q; try { return (MbRelease)query->getReleaseById(id, (ReleaseIncludes *)inc); } catch (...) { return NULL; } } MbTrack mb_query_get_track_by_id(MbQuery q, const char *id, MbTrackIncludes inc) { Query *query = (Query *)q; try { return (MbTrack)query->getTrackById(id, (TrackIncludes *)inc); } catch (...) { return NULL; } } MbUser mb_query_get_user_by_name(MbQuery q, const char *name) { Query *query = (Query *)q; try { return (MbUser)query->getUserByName(name); } catch (...) { return NULL; } } void mb_result_list_free(MbResultList list) { delete (ResultList *)list; } int mb_result_list_get_size(MbResultList list) { try { return ((ResultList *)list)->size(); } catch (...) { return 0; } } int mb_result_list_get_score(MbResultList list, int index) { try { return (*((ResultList *)list))[index]->getScore(); } catch (...) { return 0; } } MbArtist mb_result_list_get_artist(MbResultList list, int index) { try { return (MbArtist)(*((ArtistResultList *)list))[index]->getArtist(); } catch (...) { return NULL; } } MbRelease mb_result_list_get_release(MbResultList list, int index) { try { return (*((ReleaseResultList *)list))[index]->getRelease(); } catch (...) { return NULL; } } MbTrack mb_result_list_get_track(MbResultList list, int index) { try { return (*((TrackResultList *)list))[index]->getTrack(); } catch (...) { return NULL; } } MB_API MbResultList mb_query_get_artists(MbQuery q, MbArtistFilter flt) { Query *query = (Query *)q; try { ArtistResultList *results = new ArtistResultList(query->getArtists((ArtistFilter *)flt)); return (MbResultList)results; } catch (...) { return NULL; } } MB_API MbResultList mb_query_get_releases(MbQuery q, MbReleaseFilter flt) { Query *query = (Query *)q; try { ReleaseResultList *results = new ReleaseResultList(query->getReleases((ReleaseFilter *)flt)); return (MbResultList)results; } catch (...) { return NULL; } } MB_API MbResultList mb_query_get_tracks(MbQuery q, MbTrackFilter flt) { Query *query = (Query *)q; try { TrackResultList *results = new TrackResultList(query->getTracks((TrackFilter *)flt)); return (MbResultList)results; } catch (...) { return NULL; } } /* === MusicBrainz::Artist === */ MB_C_FREE(Artist, artist) MB_C_STR_GETTER(Artist, artist, Id, id) MB_C_STR_GETTER(Artist, artist, Type, type) MB_C_STR_GETTER(Artist, artist, Name, name) MB_C_STR_GETTER(Artist, artist, SortName, sortname) MB_C_STR_GETTER(Artist, artist, Disambiguation, disambiguation) MB_C_STR_GETTER(Artist, artist, UniqueName, unique_name) MB_C_STR_GETTER(Artist, artist, BeginDate, begin_date) MB_C_STR_GETTER(Artist, artist, EndDate, end_date) MB_C_INT_GETTER(Artist, artist, ReleasesOffset, releases_offset) MB_C_INT_GETTER(Artist, artist, ReleasesCount, releases_count) MB_C_OBJ_LIST_GETTER(Artist, artist, Aliases, aliases, Alias, alias, ArtistAlias) MB_C_OBJ_LIST_GETTER(Artist, artist, Releases, releases, Release, release, Release) MB_C_OBJ_LIST_GETTER(Artist, artist, Relations, relations, Relation, relation, Relation) /* === MusicBrainz::Release === */ MB_C_FREE(Release, release) MB_C_STR_GETTER(Release, release, Id, id) MB_C_STR_GETTER(Release, release, Title, title) MB_C_STR_GETTER(Release, release, TextLanguage, text_language) MB_C_STR_GETTER(Release, release, TextScript, text_script) MB_C_STR_GETTER(Release, release, Asin, asin) MB_C_INT_GETTER(Release, release, TracksOffset, tracks_offset) MB_C_INT_GETTER(Release, release, TracksCount, tracks_count) MB_C_OBJ_LIST_GETTER(Release, release, Tracks, tracks, Track, track, Track) MB_C_OBJ_LIST_GETTER(Release, release, Discs, discs, Disc, disc, Disc) MB_C_OBJ_LIST_GETTER(Release, release, ReleaseEvents, release_events, ReleaseEvent, release_event, ReleaseEvent) MB_C_OBJ_LIST_GETTER(Release, release, Relations, relations, Relation, relation, Relation) MB_C_STR_LIST_GETTER(Release, release, Types, types, Type, type) MB_C_OBJ_GETTER(Release, release, Artist, artist, MbArtist) /* === MusicBrainz::Track === */ MB_C_FREE(Track, track) MB_C_STR_GETTER(Track, track, Id, id) MB_C_STR_GETTER(Track, track, Title, title) MB_C_INT_GETTER(Track, track, Duration, duration) MB_C_OBJ_LIST_GETTER(Track, track, Relations, relations, Relation, relation, Relation) MB_C_OBJ_GETTER(Track, track, Artist, artist, MbArtist) /* === MusicBrainz::ArtistAlias === */ MB_C_STR_GETTER(ArtistAlias, artist_alias, Value, value) MB_C_STR_GETTER(ArtistAlias, artist_alias, Type, type) MB_C_STR_GETTER(ArtistAlias, artist_alias, Script, script) /* === MusicBrainz::User === */ MB_C_FREE(User, user) MB_C_STR_GETTER(User, user, Name, name) MB_C_BOOL_GETTER(User, user, ShowNag, show_nag) MB_C_STR_LIST_GETTER(User, user, Types, types, Type, type) /* === MusicBrainz::ArtistIncludes === */ MB_C_NEW_NOARGS(ArtistIncludes, artist_includes) MB_C_FREE(ArtistIncludes, artist_includes) MB_C_INCLUDES(ArtistIncludes, artist_includes, aliases, aliases) MB_C_INCLUDES(ArtistIncludes, artist_includes, artistRelations, artist_relations) MB_C_INCLUDES(ArtistIncludes, artist_includes, releaseRelations, release_relations) MB_C_INCLUDES(ArtistIncludes, artist_includes, trackRelations, track_relations) MB_C_INCLUDES(ArtistIncludes, artist_includes, urlRelations, url_relations) MB_C_INCLUDES(ArtistIncludes, artist_includes, releaseEvents, release_events) MbArtistIncludes mb_artist_includes_releases(MbArtistIncludes o, const char *str) { ((ArtistIncludes *)o)->releases(str ? string(str) : string()); return o; } MbArtistIncludes mb_artist_includes_va_releases(MbArtistIncludes o, const char *str) { ((ArtistIncludes *)o)->vaReleases(str ? string(str) : string()); return o; } /* === MusicBrainz::ReleaseIncludes === */ MB_C_NEW_NOARGS(ReleaseIncludes, release_includes) MB_C_FREE(ReleaseIncludes, release_includes) MB_C_INCLUDES(ReleaseIncludes, release_includes, artist, artist) MB_C_INCLUDES(ReleaseIncludes, release_includes, counts, counts) MB_C_INCLUDES(ReleaseIncludes, release_includes, releaseEvents, release_events) MB_C_INCLUDES(ReleaseIncludes, release_includes, discs, discs) MB_C_INCLUDES(ReleaseIncludes, release_includes, tracks, tracks) MB_C_INCLUDES(ReleaseIncludes, release_includes, artistRelations, artist_relations) MB_C_INCLUDES(ReleaseIncludes, release_includes, releaseRelations, release_relations) MB_C_INCLUDES(ReleaseIncludes, release_includes, trackRelations, track_relations) MB_C_INCLUDES(ReleaseIncludes, release_includes, urlRelations, url_relations) /* === MusicBrainz::TrackIncludes === */ MB_C_NEW_NOARGS(TrackIncludes, track_includes) MB_C_FREE(TrackIncludes, track_includes) MB_C_INCLUDES(TrackIncludes, track_includes, artist, artist) MB_C_INCLUDES(TrackIncludes, track_includes, releases, releases) MB_C_INCLUDES(TrackIncludes, track_includes, puids, puids) MB_C_INCLUDES(TrackIncludes, track_includes, artistRelations, artist_relations) MB_C_INCLUDES(TrackIncludes, track_includes, releaseRelations, release_relations) MB_C_INCLUDES(TrackIncludes, track_includes, trackRelations, track_relations) MB_C_INCLUDES(TrackIncludes, track_includes, urlRelations, url_relations) /* === MusicBrainz::ReleaseEvent === */ MB_C_STR_GETTER(ReleaseEvent, release_event, Country, country) MB_C_STR_GETTER(ReleaseEvent, release_event, Date, date) /* === MusicBrainz::Relation === */ MB_C_STR_GETTER(Relation, relation, Type, type) MB_C_STR_GETTER(Relation, relation, TargetId, target_id) MB_C_STR_GETTER(Relation, relation, TargetType, target_type) MB_C_STR_GETTER(Relation, relation, BeginDate, begin_date) MB_C_STR_GETTER(Relation, relation, EndDate, end_date) MB_C_INT_GETTER(Relation, relation, Direction, direction) MB_C_OBJ_GETTER(Relation, relation, Target, target, MbEntity) MB_C_STR_LIST_GETTER(Relation, relation, Attributes, attributes, Attribute, attribute) /* === MusicBrainz::Disc === */ MB_C_STR_GETTER(Disc, disc, Id, id) MB_C_INT_GETTER(Disc, disc, Sectors, sectors) MB_C_INT_GETTER(Disc, disc, FirstTrackNum, first_track_num) MB_C_INT_GETTER(Disc, disc, LastTrackNum, last_track_num) MbDisc mb_read_disc(const char *device_name) { try { return (MbDisc)readDisc(device_name); } catch (...) { return NULL; } } void mb_get_submission_url(MbDisc disc, const char *host, int port, char *str, int len) { try { if (host && port) { strncpy(str, getSubmissionUrl((Disc *)disc, host, port).c_str(), len); } else if (host) { strncpy(str, getSubmissionUrl((Disc *)disc, host).c_str(), len); } else { strncpy(str, getSubmissionUrl((Disc *)disc).c_str(), len); } } catch (...) { str[0] = '\0'; } } /* === MusicBrainz::ArtistFilter === */ MB_C_NEW_NOARGS(ArtistFilter, artist_filter) MB_C_FREE(ArtistFilter, artist_filter) MB_C_STR_FILTER(ArtistFilter, artist_filter, name, name) MB_C_INT_FILTER(ArtistFilter, artist_filter, limit, limit) /* === MusicBrainz::ReleaseFilter === */ MB_C_NEW_NOARGS(ReleaseFilter, release_filter) MB_C_FREE(ReleaseFilter, release_filter) MB_C_STR_FILTER(ReleaseFilter, release_filter, title, title) MB_C_STR_FILTER(ReleaseFilter, release_filter, discId, disc_id) MB_C_STR_FILTER(ReleaseFilter, release_filter, releaseType, release_type) MB_C_STR_FILTER(ReleaseFilter, release_filter, artistName, artist_name) MB_C_STR_FILTER(ReleaseFilter, release_filter, artistId, artist_id) MB_C_INT_FILTER(ReleaseFilter, release_filter, limit, limit) /* === MusicBrainz::TrackFilter === */ MB_C_NEW_NOARGS(TrackFilter, track_filter) MB_C_FREE(TrackFilter, track_filter) MB_C_STR_FILTER(TrackFilter, track_filter, title, title) MB_C_STR_FILTER(TrackFilter, track_filter, releaseTitle, release_title) MB_C_STR_FILTER(TrackFilter, track_filter, releaseId, release_id) MB_C_STR_FILTER(TrackFilter, track_filter, artistName, artist_name) MB_C_STR_FILTER(TrackFilter, track_filter, artistId, artist_id) MB_C_INT_FILTER(TrackFilter, track_filter, duration, duration) MB_C_STR_FILTER(TrackFilter, track_filter, puid, puid) MB_C_INT_FILTER(TrackFilter, track_filter, limit, limit) /* === MusicBrainz::UserFilter === */ MB_C_NEW_NOARGS(UserFilter, user_filter) MB_C_FREE(UserFilter, user_filter) MB_C_STR_FILTER(UserFilter, user_filter, name, name) } libmusicbrainz-3.0.2/src/relation.cpp0000644000175000017500000000572010636301322016661 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: relation.cpp 9189 2007-06-20 19:41:06Z luks $ */ #include #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; const string Relation::TO_ARTIST = NS_MMD_1 + "Artist"; const string Relation::TO_RELEASE = NS_MMD_1 + "Release"; const string Relation::TO_TRACK = NS_MMD_1 + "Track"; const string Relation::TO_URL = NS_MMD_1 + "Url"; class Relation::RelationPrivate { public: RelationPrivate() {} std::string type; std::string targetType; std::string targetId; Direction direction; Attributes attributes; std::string beginDate; std::string endDate; Entity *target; }; Relation::Relation(const std::string &relationType, const std::string &targetType, const std::string &targetId, const Direction direction, const std::vector &attributes, const std::string &beginDate, const std::string &endDate, Entity *target) { d = new RelationPrivate(); d->type = relationType; d->targetType = targetType; d->targetId = targetId; d->direction = direction; d->attributes = attributes; d->beginDate = beginDate; d->endDate = endDate; d->target = target; } Relation::~Relation() { if (d->target) delete d->target; delete d; } SIMPLE_STRING_SETTER_GETTER(Relation, Type, type); SIMPLE_STRING_SETTER_GETTER(Relation, TargetId, targetId); SIMPLE_STRING_SETTER_GETTER(Relation, TargetType, targetType); SIMPLE_STRING_SETTER_GETTER(Relation, BeginDate, beginDate); SIMPLE_STRING_SETTER_GETTER(Relation, EndDate, endDate); Relation::Direction Relation::getDirection() const { return d->direction; } void Relation::setDirection(const Relation::Direction value) { d->direction = value; } Entity * Relation::getTarget() const { return d->target; } void Relation::setTarget(Entity *value) { d->target = value; } Relation::Attributes & Relation::getAttributes() { return d->attributes; } void Relation::addAttribute(const string &value) { d->attributes.push_back(value); } int Relation::getNumAttributes() const { return d->attributes.size(); } string Relation::getAttribute(int i) const { return d->attributes[i]; } libmusicbrainz-3.0.2/src/artist.cpp0000644000175000017500000000641010636301322016347 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: artist.cpp 9189 2007-06-20 19:41:06Z luks $ */ #include #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; const string Artist::TYPE_PERSON = NS_MMD_1 + "Person"; const string Artist::TYPE_GROUP = NS_MMD_1 + "Group"; class Artist::ArtistPrivate { public: ArtistPrivate() : releasesCount(0), releasesOffset(0) {} std::string type; std::string name; std::string sortName; std::string disambiguation; std::string beginDate; std::string endDate; ReleaseList releases; int releasesCount; int releasesOffset; ArtistAliasList aliases; }; Artist::Artist(const string &id, const string &type, const string &name, const string &sortName) : Entity(id) { d = new ArtistPrivate(); d->type = type; d->name = name; d->sortName = sortName; } Artist::~Artist() { for (ReleaseList::iterator i = d->releases.begin(); i != d->releases.end(); i++) delete *i; d->releases.clear(); for (ArtistAliasList::iterator i = d->aliases.begin(); i != d->aliases.end(); i++) delete *i; d->aliases.clear(); delete d; } SIMPLE_STRING_SETTER_GETTER(Artist, Type, type); SIMPLE_STRING_SETTER_GETTER(Artist, Name, name); SIMPLE_STRING_SETTER_GETTER(Artist, SortName, sortName); SIMPLE_STRING_SETTER_GETTER(Artist, Disambiguation, disambiguation); SIMPLE_STRING_SETTER_GETTER(Artist, BeginDate, beginDate); SIMPLE_STRING_SETTER_GETTER(Artist, EndDate, endDate); string Artist::getUniqueName() const { return d->disambiguation.empty() ? d->name : d->name + " (" + d->disambiguation +")"; } ReleaseList & Artist::getReleases() { return d->releases; } void Artist::addRelease(Release *release) { d->releases.push_back(release); } ArtistAliasList & Artist::getAliases() { return d->aliases; } void Artist::addAlias(ArtistAlias *alias) { d->aliases.push_back(alias); } int Artist::getNumReleases() const { return d->releases.size(); } Release * Artist::getRelease(int i) { return d->releases[i]; } int Artist::getReleasesOffset() const { return d->releasesOffset; } void Artist::setReleasesOffset(const int releasesOffset) { d->releasesOffset = releasesOffset; } int Artist::getReleasesCount() const { return d->releasesCount; } void Artist::setReleasesCount(const int releasesCount) { d->releasesCount = releasesCount; } int Artist::getNumAliases() const { return d->aliases.size(); } ArtistAlias * Artist::getAlias(int i) { return d->aliases[i]; } libmusicbrainz-3.0.2/src/track.cpp0000644000175000017500000000435110636301322016147 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: track.cpp 9189 2007-06-20 19:41:06Z luks $ */ #include #include #include "utils_private.h" using namespace std; using namespace MusicBrainz; class Track::TrackPrivate { public: TrackPrivate() : artist(0), duration(0) {} std::string title; Artist *artist; int duration; ReleaseList releases; int releasesCount; int releasesOffset; }; Track::Track(const string &id, const string &title) : Entity(id) { d = new TrackPrivate(); d->title = title; } Track::~Track() { if (d->artist) delete d->artist; delete d; } SIMPLE_STRING_SETTER_GETTER(Track, Title, title); SIMPLE_INT_SETTER_GETTER(Track, Duration, duration); Artist * Track::getArtist() { return d->artist; } void Track::setArtist(Artist *value) { if (d->artist) delete d->artist; d->artist = value; } ReleaseList & Track::getReleases() { return d->releases; } void Track::addRelease(Release *release) { d->releases.push_back(release); } int Track::getNumReleases() const { return d->releases.size(); } Release * Track::getRelease(int i) { return d->releases[i]; } int Track::getReleasesOffset() const { return d->releasesOffset; } void Track::setReleasesOffset(const int releasesOffset) { d->releasesOffset = releasesOffset; } int Track::getReleasesCount() const { return d->releasesCount; } void Track::setReleasesCount(const int releasesCount) { d->releasesCount = releasesCount; } libmusicbrainz-3.0.2/src/metadata.cpp0000644000175000017500000000736210640020535016627 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: metadata.cpp 9218 2007-06-25 20:11:09Z luks $ */ #include using namespace MusicBrainz; class Metadata::MetadataPrivate { public: MetadataPrivate() : artist(NULL), track(NULL), release(NULL), label(NULL) {} Artist *artist; Track *track; Release *release; Label *label; UserList userList; ArtistResultList artistResults; TrackResultList trackResults; ReleaseResultList releaseResults; }; Metadata::Metadata() { d = new MetadataPrivate(); } Metadata::~Metadata() { if (d->artist) delete d->artist; if (d->track) delete d->track; if (d->release) delete d->release; if (d->label) delete d->label; for (UserList::iterator i = d->userList.begin(); i != d->userList.end(); i++) delete *i; d->userList.clear(); for (ArtistResultList::iterator i = d->artistResults.begin(); i != d->artistResults.end(); i++) delete *i; d->artistResults.clear(); for (ReleaseResultList::iterator i = d->releaseResults.begin(); i != d->releaseResults.end(); i++) delete *i; d->releaseResults.clear(); for (TrackResultList::iterator i = d->trackResults.begin(); i != d->trackResults.end(); i++) delete *i; d->trackResults.clear(); delete d; } void Metadata::setArtist(Artist *value) { if (d->artist) delete d->artist; d->artist = value; } void Metadata::setTrack(Track *value) { if (d->track) delete d->track; d->track = value; } void Metadata::setRelease(Release *value) { if (d->release) delete d->release; d->release = value; } Artist * Metadata::getArtist(bool remove) { Artist *ret = d->artist; if (remove) d->artist = NULL; return ret; } Track * Metadata::getTrack(bool remove) { Track *ret = d->track; if (remove) d->track = NULL; return ret; } Release * Metadata::getRelease(bool remove) { Release *ret = d->release; if (remove) d->release = NULL; return ret; } Label * Metadata::getLabel(bool remove) { Label *ret = d->label; if (remove) d->label = NULL; return ret; } void Metadata::setLabel(Label *value) { if (d->label) delete d->label; d->label = value; } UserList & Metadata::getUserList() { return d->userList; } ArtistResultList & Metadata::getArtistResults() { return d->artistResults; } TrackResultList & Metadata::getTrackResults() { return d->trackResults; } ReleaseResultList & Metadata::getReleaseResults() { return d->releaseResults; } UserList Metadata::getUserList(bool remove) { UserList list = d->userList; d->userList.clear(); return list; } ArtistResultList Metadata::getArtistResults(bool remove) { ArtistResultList list = d->artistResults; d->artistResults.clear(); return list; } TrackResultList Metadata::getTrackResults(bool remove) { TrackResultList list = d->trackResults; d->trackResults.clear(); return list; } ReleaseResultList Metadata::getReleaseResults(bool remove) { ReleaseResultList list = d->releaseResults; d->releaseResults.clear(); return list; } libmusicbrainz-3.0.2/src/artistalias.cpp0000644000175000017500000000334010477236200017365 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: artistalias.cpp 8466 2006-09-05 08:59:44Z luks $ */ #include using namespace std; using namespace MusicBrainz; class ArtistAlias::ArtistAliasPrivate { public: ArtistAliasPrivate() {} std::string value; std::string type; std::string script; }; ArtistAlias::ArtistAlias(const string &value, const string &type, const string &script) { d = new ArtistAliasPrivate(); d->value = value; d->type = type; d->script = script; } ArtistAlias::~ArtistAlias() { delete d; } string ArtistAlias::getType() const { return d->type; } void ArtistAlias::setType(const string &type) { d->type = type; } string ArtistAlias::getValue() const { return d->value; } void ArtistAlias::setValue(const string &value) { d->value = value; } string ArtistAlias::getScript() const { return d->script; } void ArtistAlias::setScript(const string &script) { d->script = script; } libmusicbrainz-3.0.2/Doxyfile.cmake0000644000175000017500000000077710621324347016353 0ustar lukaslukasPROJECT_NAME = "${PROJECT_NAME}" PROJECT_NUMBER = ${PROJECT_VERSION} HTML_OUTPUT = docs GENERATE_LATEX = NO GENERATE_MAN = NO GENERATE_RTF = NO CASE_SENSE_NAMES = NO INPUT = include/musicbrainz3 JAVADOC_AUTOBRIEF = YES EXTRACT_ALL = YES EXTRACT_STATIC = YES SHOW_USED_FILES = NO GENERATE_TREEVIEW = YES SHOW_INCLUDE_FILES = NO FULL_PATH_NAMES = NO MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = YES PREDEFINED = MB_API libmusicbrainz-3.0.2/COPYING.txt0000644000175000017500000006350410621320144015423 0ustar lukaslukas GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! libmusicbrainz-3.0.2/test-data/0000755000175000017500000000000011062700263015434 5ustar lukaslukaslibmusicbrainz-3.0.2/test-data/invalid/0000755000175000017500000000000011062700262017061 5ustar lukaslukaslibmusicbrainz-3.0.2/test-data/invalid/track/0000755000175000017500000000000011062700262020165 5ustar lukaslukaslibmusicbrainz-3.0.2/test-data/invalid/artist/0000755000175000017500000000000011062700263020370 5ustar lukaslukaslibmusicbrainz-3.0.2/test-data/invalid/artist/basic_2.xml0000644000175000017500000000037010367360533022425 0ustar lukaslukas libmusicbrainz-3.0.2/test-data/invalid/artist/search_result_1.xml0000644000175000017500000000065310410272540024177 0ustar lukaslukas Tori Amos Amos, Tori libmusicbrainz-3.0.2/test-data/invalid/artist/empty_1.xml0000644000175000017500000000000010367360533022467 0ustar lukaslukaslibmusicbrainz-3.0.2/test-data/invalid/artist/basic_1.xml0000644000175000017500000000033010367360533022420 0ustar lukaslukas libmusicbrainz-3.0.2/test-data/invalid/artist/empty_2.xml0000644000175000017500000000013710367360533022503 0ustar lukaslukas libmusicbrainz-3.0.2/test-data/invalid/artist/empty_3.xml0000644000175000017500000000015010367360533022477 0ustar lukaslukas libmusicbrainz-3.0.2/test-data/invalid/artist/tags_1.xml0000644000175000017500000000026410637777526022321 0ustar lukaslukas foo libmusicbrainz-3.0.2/test-data/invalid/release/0000755000175000017500000000000011062700262020501 5ustar lukaslukaslibmusicbrainz-3.0.2/test-data/valid/0000755000175000017500000000000011062700262016532 5ustar lukaslukaslibmusicbrainz-3.0.2/test-data/valid/track/0000755000175000017500000000000011062700261017635 5ustar lukaslukaslibmusicbrainz-3.0.2/test-data/valid/track/Silent_All_These_Years_4.xml0000644000175000017500000000225410405051643025131 0ustar lukaslukas Silent All These Years 253466 Tori Amos Amos, Tori Little Earthquakes libmusicbrainz-3.0.2/test-data/valid/track/Silent_All_These_Years_3.xml0000644000175000017500000000121410405051643025123 0ustar lukaslukas Silent All These Years 253466 libmusicbrainz-3.0.2/test-data/valid/track/search_result_1.xml0000644000175000017500000000354510550166442023461 0ustar lukaslukas Little Earthquakes 457760 Tori Amos To Venus and Back (disc 2: Live, Still Orbiting) Little Earthquakes 413693 Tori Amos Little Earthquakes Little Amsterdam 270106 Tori Amos Boys for Pele libmusicbrainz-3.0.2/test-data/valid/track/Silent_All_These_Years_6.xml0000644000175000017500000000040710637777526025157 0ustar lukaslukas Silent All These Years 253466 libmusicbrainz-3.0.2/test-data/valid/track/Silent_All_These_Years_1.xml0000644000175000017500000000036010367360533025132 0ustar lukaslukas Silent All These Years 253466 libmusicbrainz-3.0.2/test-data/valid/track/Silent_All_These_Years_5.xml0000644000175000017500000000142710405051643025133 0ustar lukaslukas Silent All These Years 253466 This is a very nice song. libmusicbrainz-3.0.2/test-data/valid/track/Silent_All_These_Years_2.xml0000644000175000017500000000136310406316150025125 0ustar lukaslukas Silent All These Years 253466 Tori Amos Amos, Tori Silent All These Years libmusicbrainz-3.0.2/test-data/valid/artist/0000755000175000017500000000000011062700262020040 5ustar lukaslukaslibmusicbrainz-3.0.2/test-data/valid/artist/Tori_Amos_2.xml0000644000175000017500000000511410371365467022720 0ustar lukaslukas Tori Amos Amos, Tori Strange Little Girls B00005NKYQ To Venus and Back (disc 1: Orbiting) B00001IVJS Under the Pink B000002IXU libmusicbrainz-3.0.2/test-data/valid/artist/Tori_Amos_1.xml0000644000175000017500000000045510367360533022714 0ustar lukaslukas Tori Amos Amos, Tori libmusicbrainz-3.0.2/test-data/valid/artist/Tori_Amos_5.xml0000644000175000017500000000102210477304634022711 0ustar lukaslukas Tori Amos Amos, Tori Strange Little Girls libmusicbrainz-3.0.2/test-data/valid/artist/Tchaikovsky-2.xml0000644000175000017500000000073310637777526023253 0ustar lukaslukas Пётр Ильич Чайковский classical russian romantic era composer libmusicbrainz-3.0.2/test-data/valid/artist/search_result_1.xml0000644000175000017500000000147410430176546023665 0ustar lukaslukas Tori Amos Amos, Tori Tori Spelling Spelling, Tori Lisa And Tori Lisa And Tori libmusicbrainz-3.0.2/test-data/valid/artist/empty_1.xml0000644000175000017500000000021710367360533022152 0ustar lukaslukas libmusicbrainz-3.0.2/test-data/valid/artist/Tori_Amos_3.xml0000644000175000017500000000162310437077165022720 0ustar lukaslukas Tori Amos Amos, Tori Mark Hawley Hawley, Mark libmusicbrainz-3.0.2/test-data/valid/artist/Tchaikovsky-1.xml0000644000175000017500000001075710372357332023242 0ustar lukaslukas Пётр Ильич Чайковский Tchaikovsky, Pyotr Ilyich Tchaikovsky Peter Ilyich Tchaikovsky Peter Tchaikovsky Tschaikowsky Peter Tschaikowsky Piotr Ilyich Tchaikovsky Piotr Tchaikovsky Peter Iljitsch Tschaikowsky Tchaikovsky, Peter Ilyich Peter Ilyitch Tchaikovsky Pjotr Ilyich Tchaikovsky Peter I. Tschaikowsky Pyotr Tchaikovsky P. I. Tchaikovsky Peter Ilich Tchaikovsky Tchaikovsky, P.I. Tsjaikovski Tchaikovsky, Pyotr Ilyich Tjajkovskij Piotr Ilyitch Tchaikovsky Tsjajkovskij Peter Ilyich Tchaikovski Peter I. Tchaikovsky Tchaikovsky, Peter I. Tchaikowsky Peter Ilyich Tschaikowsky Peter Iljitsch Tschaikowski Pyotr Il'Yich Tchaikovsky Tchiakovsky, Pyotr Ilich (1840-1893) Tchaikovsky, Peter Ilyich (1840-93) Tchaikovsky, Peter Ilyitch Pyotr Ilyitch Tchaikovsky Tsaikovski Pytor Ilyich Tchaikovsky Piotr Ilyich Tchaikowsky Tchaikovsky - Philharmonic Orchestra Peter Iljitsch Tschaikowsky (1840 - 1893) Peter Tschaikovsky Peter Ilych Tschaikowsky Pyotr II'yich Tchaikovsky Pytor Tchaikovsky Pyotr Ilyich Tchaikovsky Чайковский, Петр Ильич Чайковский, Пётр Ильич Петр Ильич Чайковский Пётр Ильич Чайковский Tchaikovsky, Peter Il'yich Tchaikovsky, Pjotr Ilyich (1840 - 1893) Piotr Illitch Tchaïkovsky Piotr Ilic Ciaikovsky Pyotr Illyich Tchaikovsky Tchaikovsky, Piotr Ilich (1840-1893) Peter Ilyich Tchaikovshy Pyotr Ilyich Tchaikovsly Peter Ilych Tchaikovsky 차이코프스키 Piotr Ilitch Tchaïkovski Chaikovsky, P. I. Pjotr Iljitsch Tschaikowsky Ciaikosvsky Tchaikovsky 1841-1893 Tchaïkovki Piotr Ilych Chaikovsky Pjotr Iljitsj Tsjaikovski Pyotor Ilyich Tschaikovsky Peter Iljitsj Tsjaikovski P. I. Tchaikovskij Piotr Ilich Tchaikovsky Peter Iljitsch Tchaikovsky Tchaikovisky Tchaikovsy Tchailovisky Tchaikovskyes Tchaikovskys Tchaikoskvy Piotr Il'yich Tchaikovsky Tchaikowski Piotr Iljič Čajkovskij Tchaikivsky Pyotor Tchaikovsky libmusicbrainz-3.0.2/test-data/valid/artist/Tori_Amos_4.xml0000644000175000017500000000105510406300610022674 0ustar lukaslukas Tori Amos Amos, Tori yes, that one Myra Ellen Amos Myra Amos Torie Amos libmusicbrainz-3.0.2/test-data/valid/artist/empty_2.xml0000644000175000017500000000026210367360533022153 0ustar lukaslukas libmusicbrainz-3.0.2/test-data/valid/release/0000755000175000017500000000000011062700257020156 5ustar lukaslukaslibmusicbrainz-3.0.2/test-data/valid/release/Under_the_Pink_3.xml0000644000175000017500000000123210675465612024032 0ustar lukaslukas Under the Pink Tori Amos libmusicbrainz-3.0.2/test-data/valid/release/Highway_61_Revisited_2.xml0000644000175000017500000000064510637777526025076 0ustar lukaslukas Highway 61 Revisited rock blues rock folk rock dylan libmusicbrainz-3.0.2/test-data/valid/release/Little_Earthquakes_2.xml0000644000175000017500000000574210371675144024733 0ustar lukaslukas Little Earthquakes B000002IT2 Tori Amos Amos, Tori Crucify 301186 Girl 249493 Silent All These Years 253466 Precious Things 269293 Winter 344573 Happy Phantom 199000 China 301946 Leather 193960 Mother 421173 Tear in Your Hand 280866 Me and a Gun 226920 Little Earthquakes 413693 libmusicbrainz-3.0.2/test-data/valid/release/Under_the_Pink_2.xml0000644000175000017500000000102310477304634024023 0ustar lukaslukas Under the Pink Tori Amos God libmusicbrainz-3.0.2/test-data/valid/release/Little_Earthquakes_1.xml0000644000175000017500000000174010371365467024730 0ustar lukaslukas Little Earthquakes B000002IT2 Tori Amos Amos, Tori libmusicbrainz-3.0.2/test-data/valid/release/search_result_1.xml0000644000175000017500000000223610550166442023771 0ustar lukaslukas Under the Pink B000002IXU Tori Amos Under the Pink Tour 1994 Tori Amos libmusicbrainz-3.0.2/test-data/valid/release/Under_the_Pink_1.xml0000644000175000017500000000113210410300474024004 0ustar lukaslukas Under the Pink B000002IXU Tori Amos libmusicbrainz-3.0.2/test-data/valid/release/Highway_61_Revisited_1.xml0000644000175000017500000000575010405051643025051 0ustar lukaslukas Highway 61 Revisited B0000C8AVR Bob Dylan Dylan, Bob Like a Rolling Stone 373333 Tombstone Blues 360533 It Takes a Lot to Laugh, It Takes a Train to Cry 249066 From a Buick 6 199026 Ballad of a Thin Man 358640 Queen Jane Approximately 331760 Highway 61 Revisited 210333 Just Like Tom Thumb's Blues 332133 Desolation Row 682506 libmusicbrainz-3.0.2/test-data/valid/release/Mission_Impossible_2.xml0000644000175000017500000001601110405741741024732 0ustar lukaslukas Mission: Impossible 2 Various Artists Various Artists Take a Look Around 320160 Limp Bizkit Limp Bizkit I Disappear 266306 Metallica Metallica Scum of the Earth 175533 Rob Zombie Zombie, Rob They Came In 282560 Butthole Surfers Butthole Surfers Rocket Science 210466 The Pimps Pimps, The Have a Cigar (feat. Brian May) 242933 Foo Fighters Foo Fighters Mission 2000 222440 Chris Cornell Cornell, Chris Going Down 203160 Godsmack Godsmack What U Lookin' At? 312000 Uncle Kracker Uncle Kracker Backwards 189506 Apartment 26 Apartment 26 Karma 196160 Diffuser Diffuser Alone 203973 Buckcherry Buckcherry Immune 229026 Tinfed Tinfed My Kinda Scene 266666 Powderfinger Powderfinger Australian rock band Carnival 258066 Tori Amos Amos, Tori Nyah (feat. Heitor Pereira) 213306 Hans Zimmer Zimmer, Hans libmusicbrainz-3.0.2/test-data/valid/user/0000755000175000017500000000000011062700262017510 5ustar lukaslukaslibmusicbrainz-3.0.2/test-data/valid/user/User_1.xml0000644000175000017500000000061510374153130021373 0ustar lukaslukas matt libmusicbrainz-3.0.2/test-data/valid/label/0000755000175000017500000000000011062700256017614 5ustar lukaslukaslibmusicbrainz-3.0.2/test-data/valid/label/Atlantic_Records_2.xml0000644000175000017500000000070310637777526024024 0ustar lukaslukas libmusicbrainz-3.0.2/test-data/valid/label/search_result_1.xml0000644000175000017500000000107510607354732023434 0ustar lukaslukas libmusicbrainz-3.0.2/test-data/valid/label/Atlantic_Records_3.xml0000644000175000017500000000051110637777526024022 0ustar lukaslukas libmusicbrainz-3.0.2/test-data/valid/label/Atlantic_Records_1.xml0000644000175000017500000000052110607354732024004 0ustar lukaslukas libmusicbrainz-3.0.2/test-data/README0000644000175000017500000000066610367360533016335 0ustar lukaslukasMusicBrainz Web Service XML Examples ------------------------------------ This directory contains example XML code for testing an implementation. Implementations MUST be able to parse the XML in the 'valid' directory. It is perfect, schema-compliant XML. The 'invalid' directory contains all kinds of invalid XML. Implementations are not expected to parse those files. They MAY, however. -- $Id: README 33 2006-01-30 09:50:19Z matt $ libmusicbrainz-3.0.2/include/0000755000175000017500000000000011062700232015165 5ustar lukaslukaslibmusicbrainz-3.0.2/include/musicbrainz3/0000755000175000017500000000000011062700237017603 5ustar lukaslukaslibmusicbrainz-3.0.2/include/musicbrainz3/iwebservice.h0000644000175000017500000000605410477236200022273 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: iwebservice.h 8466 2006-09-05 08:59:44Z luks $ */ #ifndef __MUSICBRAINZ3_IWEBSERVICE_H__ #define __MUSICBRAINZ3_IWEBSERVICE_H__ #include #include #include #include namespace MusicBrainz { /** * An interface all concrete web service classes have to implement. * * All web service classes have to implement this and follow the * method specifications. */ class MB_API IWebService { public: virtual ~IWebService() {}; /** * Query the web service. * * Using this method, you can either get a resource by id (using * the \a id parameter, or perform a query on all resources of * a type. * * The \a filter and the \a id parameter exclude each other. If * you are using a filter, you may not set \a id and vice versa. * * Returns a file-like object containing the result or raises a * WebServiceError or one of its subclasses in case of an * error. Which one is used depends on the implementing class. * * @param entity a string containing the entity's name * @param id a string containing a UUID, or the empty string * @param include a tuple containing values for the 'inc' parameter * @param filter parameters, depending on the entity * @param version a string containing the web service version to use * * @return a string contaning the returned data * * @throw WebServiceError: in case of errors */ virtual std::string get(const std::string &entity, const std::string &id, const IIncludes::IncludeList &include, const IFilter::ParameterList &filter, const std::string &version = "1") = 0; /** * Submit data to the web service. * * @param entity a string containing the entity's name * @param id a string containing a UUID, or the empty string * @param data a string containing the data to post * @param version a string containing the web service version to use * * @throw WebServiceError in case of errors */ virtual void post(const std::string &entity, const std::string &id, const std::string &data, const std::string &version = "1") = 0; }; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/includes.h0000644000175000017500000001026410636275723021602 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: includes.h 9187 2007-06-20 19:11:15Z luks $ */ #ifndef __MUSICBRAINZ3_INCLUDES_H__ #define __MUSICBRAINZ3_INCLUDES_H__ #include #include #include namespace MusicBrainz { /** * An interface implemented by include tag generators. */ class MB_API IIncludes { public: typedef std::vector IncludeList; virtual ~IIncludes() {}; /** * Returns a list of strings containing include parameters for * the WebService. * * @return a list of strings */ virtual IncludeList createIncludeTags() const = 0; }; /** * A specification on how much data to return with a track. * * This implementation uses \e method \e chaining to define list of includes. * * Example usage: * \code * ArtistIncludes inc = ArtistIncludes().aliases().urlRelations(); * \endcode */ class MB_API ArtistIncludes : public IIncludes { public: //! Include aliases. ArtistIncludes &aliases(); //! Include releases of speficied type. ArtistIncludes &releases(const std::string &type); //! Include VA releases of speficied type. ArtistIncludes &vaReleases(const std::string &type); //! Include release events for included releases. ArtistIncludes &releaseEvents(); //! Include artist relations. ArtistIncludes &artistRelations(); //! Include release relations. ArtistIncludes &releaseRelations(); //! Include track relations. ArtistIncludes &trackRelations(); //! Include URL relations. ArtistIncludes &urlRelations(); IncludeList createIncludeTags() const; private: IncludeList includes; }; /** * A specification on how much data to return with a release. * * This implementation uses \e method \e chaining to define list of includes. * * Example usage: * \code * ReleaseIncludes inc = ReleaseIncludes().releaseEvents().disc(); * \endcode */ class MB_API ReleaseIncludes : public IIncludes { public: //! Include artist. ReleaseIncludes &artist(); //! Include counts. ReleaseIncludes &counts(); //! Include release events. ReleaseIncludes &releaseEvents(); //! Include discs. ReleaseIncludes &discs(); //! Include tracks. ReleaseIncludes &tracks(); //! Include artist relations. ReleaseIncludes &artistRelations(); //! Include release relations. ReleaseIncludes &releaseRelations(); //! Include track relations. ReleaseIncludes &trackRelations(); //! Include URL relations. ReleaseIncludes &urlRelations(); IncludeList createIncludeTags() const; private: IncludeList includes; }; /** * A specification on how much data to return with a track. * * This implementation uses \e method \e chaining to define list of includes. * * Example usage: * \code * TrackIncludes inc = TrackIncludes().artist().puids().trackRelations(); * \endcode */ class MB_API TrackIncludes : public IIncludes { public: //! Include artist. TrackIncludes &artist(); //! Include releases. TrackIncludes &releases(); //! Include PUIDs. TrackIncludes &puids(); //! Include artist relations. TrackIncludes &artistRelations(); //! Include release relations. TrackIncludes &releaseRelations(); //! Include track relations. TrackIncludes &trackRelations(); //! Include URL relations. TrackIncludes &urlRelations(); IncludeList createIncludeTags() const; private: IncludeList includes; }; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/track.h0000644000175000017500000001207510554002300021054 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: track.h 8794 2007-01-18 23:37:36Z luks $ */ #ifndef __MUSICBRAINZ3_TRACK_H__ #define __MUSICBRAINZ3_TRACK_H__ #include #include #include namespace MusicBrainz { class Artist; /** * Represents a track. * * This class represents a track which may appear on one or more releases. * A track may be associated with exactly one artist (the I{main} artist). * * Using getReleases, you can find out on which releases this track * appears. To get the track number, too, use the * Release::getTracksOffset method. * * @note Currently, the MusicBrainz server doesn't support tracks to * be on more than one release. * * @see Release, Artist */ class MB_API Track : public Entity { public: /** * Constructor. * * @param id a string containing an absolute URI * @param title a string containing the title */ Track(const std::string &id = std::string(), const std::string &title = std::string()); /** * Destructor. */ virtual ~Track(); /** * Returns the track's title. * * The style and format of this attribute is specified by the * style guide. * * @return a string containing an absolute URI * * @see The MusicBrainz * Style Guidelines */ std::string getTitle() const; /** * Sets the track's title. * * @param title: a string containing the title * * @see: getTitle */ void setTitle(const std::string &title); /** * Returns the main artist of this track. * * @return: a pointer to Artist object, or NULL */ Artist *getArtist(); /** * Sets this track's main artist. * * @param artist a pointer to Artist object, or NULL */ void setArtist(Artist *artist); /** * Returns the duration of this track in milliseconds. * * @return an int containing the duration in milliseconds */ int getDuration() const; /** * Sets the duration of this track in milliseconds. * * @param duration an int containing the duration in milliseconds */ void setDuration(const int duration); /** * Returns a list of releases from this artist. * * This may also include releases where this artist isn't the * \e main artist but has just contributed one or more tracks * (aka VA-Releases). * * @return: a list of pointers to Release objects */ ReleaseList &getReleases(); /** * Returns number of releases. * * This is equivalent to \c getReleases().size() * * @return an int containing number of releases * * @see getReleases */ int getNumReleases() const; /** * Returns an release specified by index. * * This is equivalent to \c getReleases()[index] * * @return a pointer to Release instance * * @see getReleases */ Release *getRelease(int index); /** * Adds a release to this artist's list of releases. * * @param release a pointer to Release object */ void addRelease(Release *release); /** * Returns the offset of the release list. * * This is used if the track list is incomplete (ie. the web * service only returned part of the tracks on this release). * Note that the offset value is zero-based, which means track * \a 0 is the first track. * * @return an integer containing the offset * * @see getReleases */ int getReleasesOffset() const; /** * Sets the offset of the release list. * * @param offset an integer containing the offset * * @see getReleasesOffset */ void setReleasesOffset(const int offset); /** * Returns the number of existing releases. * * This may or may not match with the number of elements that * getReleases and getNumReleases returns. If the count is higher than * the list, it indicates that the list is incomplete. * * @return an integer containing the count * * @see getReleases */ int getReleasesCount() const; /** * Sets the count of the release list. * * @param count an integer containing the count * * @see getReleasesCount */ void setReleasesCount(const int count); private: class TrackPrivate; TrackPrivate *d; }; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/labelalias.h0000644000175000017500000000242010640020535022040 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: labelalias.h 9218 2007-06-25 20:11:09Z luks $ */ #ifndef __MUSICBRAINZ3_LABELALIAS_H__ #define __MUSICBRAINZ3_LABELALIAS_H__ #include #include #include namespace MusicBrainz { /** * Represents a label alias. * * BIC: make a generic class Alias with subclasses ArtistAlias, LabelAlias. */ class MB_API LabelAlias : public ArtistAlias { public: }; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/musicbrainz.h0000644000175000017500000000405710477236200022313 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: musicbrainz.h 8466 2006-09-05 08:59:44Z luks $ */ #ifndef __MUSICBRAINZ3_MUSICBRAINZ_H__ #define __MUSICBRAINZ3_MUSICBRAINZ_H__ #include #include #include namespace MusicBrainz { class MB_API Exception : public std::exception { public: Exception(const std::string &msg = std::string()) : msg(msg) {} virtual ~Exception() throw() {} const char *what() const throw() { return msg.c_str(); } private: std::string msg; }; class MB_API ValueError : public Exception { public: ValueError(const std::string &msg = std::string()) : Exception(msg) {} }; /** * The ID of the special 'Various Artists' artist. */ static const std::string VARIOUS_ARTISTS_ID = "http://musicbrainz.org/artist/89ad4ac3-39f7-470e-963a-56509c546377"; /** * Default namespace prefix for all MusicBrainz metadata. */ static const std::string NS_MMD_1 = "http://musicbrainz.org/ns/mmd-1.0#"; /** * Namespace prefix for relations. */ static const std::string NS_REL_1 = "http://musicbrainz.org/ns/rel-1.0#"; /** * Namespace prefix for MusicBrainz extensions. */ static const std::string NS_EXT_1 = "http://musicbrainz.org/ns/ext-1.0#"; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/user.h0000644000175000017500000000561710477236200020746 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: user.h 8466 2006-09-05 08:59:44Z luks $ */ #ifndef __MUSICBRAINZ3_USER_H__ #define __MUSICBRAINZ3_USER_H__ #include #include #include namespace MusicBrainz { /** * Represents a MusicBrainz user. */ class MB_API User { public: /** * Constructor. */ User(); /** * Destructor. */ virtual ~User(); /** * Returns the user name. * * @return a string containing the user name */ std::string getName() const; /** * Sets the user name. * * @param name a string containing the user name */ void setName(const std::string &name); /** * Returns the types of this user. * * Most users' type list is empty. Currently, the following types * are defined: * * - \a "http://musicbrainz.org/ns/ext-1.0#AutoEditor" * - \a "http://musicbrainz.org/ns/ext-1.0#RelationshipEditor" * - \a "http://musicbrainz.org/ns/ext-1.0#Bot" * - \a "http://musicbrainz.org/ns/ext-1.0#NotNaggable" * * @return a vector of strings containing absolute URIs */ std::vector &getTypes(); /** * Returns number of types. * * This is equivalent to \c getTypes().size() * * @return an int containing number of types * * @see getTypes */ int getNumTypes() const; /** * Returns an type specified by index. * * This is equivalent to \c getTypes()[index] * * @return a string containing the type * * @see getTypes */ std::string getType(int index) const; /** * Add a type to the list of types. * * @param type a string containing absolute URIs * * @see getTypes */ void addType(const std::string &type); /** * Returns true if a nag screen should be displayed to the user. * * @return \a true or \a false */ bool getShowNag() const; /** * Sets the value of the nag screen flag. * * @param value \a true or \a false * * @see getShowNag */ void setShowNag(bool value); private: class UserPrivate; UserPrivate *d; }; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/artist.h0000644000175000017500000002032310477305211021264 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: artist.h 8472 2006-09-05 14:32:41Z luks $ */ #ifndef __MUSICBRAINZ3_ARTIST_H__ #define __MUSICBRAINZ3_ARTIST_H__ #include #include #include #include #include namespace MusicBrainz { /** * Represents an artist. * * Artists in MusicBrainz can have a type. Currently, this type can * be either Person or Group for which the following URIs are assigned: * * - \a "http://musicbrainz.org/ns/mmd-1.0#Person" * - \a "http://musicbrainz.org/ns/mmd-1.0#Group" * * Use the \a Artist::TYPE_PERSON and \a Artist::TYPE_GROUP constants for comparison. */ class MB_API Artist : public Entity { public: static const std::string TYPE_PERSON; static const std::string TYPE_GROUP; /** * Constructor. * * @param id a string containing an absolute URI * @param type a string containing an absolute URI * @param name a string containing the artist's name * @param sortName a string containing the artist's sort name */ Artist(const std::string &id = "", const std::string &type = "", const std::string &name = "", const std::string &sortName = ""); /** * Destructor. */ virtual ~Artist(); /** * Returns the artist's type. * * @return a string containing an absolute URI */ std::string getType() const; /** * Sets the artist's type. * * @param type a string containing an absolute URI */ void setType(const std::string &type); /** * Returns the artist's name. * * @return a string containing the artist's name, or empty string */ std::string getName() const; /** * Sets the artist's name. * * @param name a string containing the artist's name */ void setName(const std::string &name); /** * Returns the artist's sort name. * *

The sort name is the artist's name in a special format which * is better suited for lexicographic sorting. The MusicBrainz * style guide specifies this format.

* * @see The MusicBrainz Style Guidelines */ std::string getSortName() const; /** * Sets the artist's sort name. * * @param sortName: a string containing the artist's sort name * * @see #getSortName */ void setSortName(const std::string &sortName); /** * Returns the disambiguation attribute. * * This attribute may be used if there is more than one artist * with the same name. In this case, disambiguation attributes * are added to the artists' names to keep them apart. * * For example, there are at least three bands named 'Vixen'. * Each band has a different disambiguation in the MusicBrainz * database, like 'Hip-hop' or 'all-female rock/glam band'. * * @return a disambiguation string * * @see getUniqueName */ std::string getDisambiguation() const; /** * Sets the disambiguation attribute. * * @param disambiguation a disambiguation string * * @see getDisambiguation, getUniqueName */ void setDisambiguation(const std::string &disambiguation); /** * Returns a unique artist name (using disambiguation). * * This method returns the artist name together with the * disambiguation attribute in parenthesis if it exists. * Example: 'Vixen (Hip-hop)'. * * @return a string containing the unique name * * @see getDisambiguation */ std::string getUniqueName() const; /** * Returns the birth/foundation date. * * The definition of the \e begin \e date depends on the artist's * type. For persons, this is the day of birth, for groups it * is the day the group was founded. * * The returned date has the format "YYYY", "YYYY-MM", or * "YYYY-MM-DD", depending on how much detail is known. * * @return a string containing the date * * @see getType */ std::string getBeginDate() const; /** * Sets the begin/foundation date. * * @param dateStr a date string * * @see getBeginDate */ void setBeginDate(const std::string &dateStr); /** * Get the death/dissolving date. * * The definition of the \e end \e date depends on the artist's * type. For persons, this is the day of death, for groups it * is the day the group was dissolved. * * @return a string containing a date * * @see getBeginDate */ std::string getEndDate() const; /** * Sets the death/dissolving date. * * @param dateStr a string containing a date * * @see: setEndDate, getBeginDate */ void setEndDate(const std::string &dateStr); /** * Returns a list of releases from this artist. * * This may also include releases where this artist isn't the * \e main artist but has just contributed one or more tracks * (aka VA-Releases). * * @return: a list of pointers to Release objects */ ReleaseList &getReleases(); /** * Returns number of releases. * * This is equivalent to \c getReleases().size() * * @return an int containing number of releases * * @see getReleases */ int getNumReleases() const; /** * Returns an release specified by index. * * This is equivalent to \c getReleases()[index] * * @return a pointer to Release instance * * @see getReleases */ Release *getRelease(int index); /** * Adds a release to this artist's list of releases. * * @param release a pointer to Release object */ void addRelease(Release *release); /** * Returns the offset of the release list. * * This is used if the track list is incomplete (ie. the web * service only returned part of the tracks on this release). * Note that the offset value is zero-based, which means track * \a 0 is the first track. * * @return an integer containing the offset * * @see getReleases */ int getReleasesOffset() const; /** * Sets the offset of the release list. * * @param offset an integer containing the offset * * @see getReleasesOffset */ void setReleasesOffset(const int offset); /** * Returns the number of existing releases. * * This may or may not match with the number of elements that * getReleases and getNumReleases returns. If the count is higher than * the list, it indicates that the list is incomplete. * * @return an integer containing the count * * @see getReleases */ int getReleasesCount() const; /** * Sets the count of the release list. * * @param count an integer containing the count * * @see getReleasesCount */ void setReleasesCount(const int count); /** * Returns the list of aliases for this artist. * * @return a list of pointers to ArtistAlias objects */ ArtistAliasList &getAliases(); /** * Returns number of aliases. * * This is equivalent to \c getAliases().size() * * @return an int containing number of aliases * * @see getAliases */ int getNumAliases() const; /** * Returns alias specified by index. * * This is equivalent to \c getAliases()[index] * * @return a pointer to ArtistAlias instance * * @see getAliases */ ArtistAlias *getAlias(int index); /** * Adds an alias for this artist. * * @param alias a pointer to ArtistAlias object */ void addAlias(ArtistAlias *alias); private: class ArtistPrivate; ArtistPrivate *d; }; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/model.h0000644000175000017500000000262110640020535021052 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: model.h 9218 2007-06-25 20:11:09Z luks $ */ #ifndef __MUSICBRAINZ3_MODEL_H__ #define __MUSICBRAINZ3_MODEL_H__ #include #include #include #include #include #include #include #include #include #include #include #include #include #endif libmusicbrainz-3.0.2/include/musicbrainz3/artistalias.h0000644000175000017500000000550010477236200022277 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: artistalias.h 8466 2006-09-05 08:59:44Z luks $ */ #ifndef __MUSICBRAINZ3_ARTISTALIAS_H__ #define __MUSICBRAINZ3_ARTISTALIAS_H__ #include #include namespace MusicBrainz { /** * Represents an artist alias. * * An alias (the \a alias \a value) is a different representation of an * artist's name. This may be a common misspelling or a transliteration * (the \a alias \a type). * * The \a alias \a script is interesting mostly for transliterations and * indicates which script is used for the alias value. To represent the * script, ISO-15924 script codes like 'Latn', 'Cyrl', or 'Hebr' are used. */ class MB_API ArtistAlias { public: /** * Constructor. * * @param value a string containing the alias * @param type a string containing an absolute URI * @param script a string containing an ISO-15924 script code */ ArtistAlias(const std::string &value = std::string(), const std::string &type = std::string(), const std::string &script = std::string()); /** * Destructor. */ virtual ~ArtistAlias(); /** * Returns the alias. * * @return a string containing the alias */ std::string getValue() const; /** * Sets the alias. * * @param value a string containing the alias */ void setValue(const std::string &value); /** * Returns the alias type. * * @return a string containing an absolute URI */ std::string getType() const; /** * Sets the alias type. * * @param type a string containing an absolute URI */ void setType(const std::string &type); /** * Returns the alias script. * * @return a string containing an ISO-15924 script code */ std::string getScript() const; /** * Sets the alias script. * * @param type a string containing an ISO-15924 script code */ void setScript(const std::string &type); private: class ArtistAliasPrivate; ArtistAliasPrivate *d; }; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/defines.h0000644000175000017500000000242510477236200021377 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: defines.h 8466 2006-09-05 08:59:44Z luks $ */ #ifndef __MUSICBRAINZ3_DEFINES_H__ #define __MUSICBRAINZ3_DEFINES_H__ #ifdef _MSC_VER # pragma warning (disable : 4251) #endif #ifdef WIN32 # ifdef MB_API_EXPORTS # define MB_API __declspec(dllexport) # else # define MB_API __declspec(dllimport) # endif #else # ifdef GCC_HASCLASSVISIBILITY # define MB_API __attribute__ ((visibility("default"))) # else # define MB_API # endif #endif #endif libmusicbrainz-3.0.2/include/musicbrainz3/label.h0000644000175000017500000001753010640020535021036 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: label.h 9218 2007-06-25 20:11:09Z luks $ */ #ifndef __MUSICBRAINZ3_LABEL_H__ #define __MUSICBRAINZ3_LABEL_H__ #include #include #include #include #include namespace MusicBrainz { /** * Represents a record label. */ class MB_API Label : public Entity { public: static const std::string TYPE_PERSON; static const std::string TYPE_GROUP; /** * Constructor. * * @param id a string containing an absolute URI * @param type a string containing an absolute URI * @param name a string containing the label's name * @param sortName a string containing the label's sort name */ Label(const std::string &id = "", const std::string &type = "", const std::string &name = "", const std::string &sortName = ""); /** * Destructor. */ virtual ~Label(); /** * Returns the label's type. * * @return a string containing an absolute URI */ std::string getType() const; /** * Sets the label's type. * * @param type a string containing an absolute URI */ void setType(const std::string &type); /** * Returns the label's name. * * @return a string containing the label's name, or empty string */ std::string getName() const; /** * Sets the label's name. * * @param name a string containing the label's name */ void setName(const std::string &name); /** * Returns the label's sort name. * *

The sort name is the label's name in a special format which * is better suited for lexicographic sorting. The MusicBrainz * style guide specifies this format.

* * @see The MusicBrainz Style Guidelines */ std::string getSortName() const; /** * Sets the label's sort name. * * @param sortName: a string containing the label's sort name * * @see #getSortName */ void setSortName(const std::string &sortName); /** * Returns the disambiguation attribute. * * This attribute may be used if there is more than one label * with the same name. In this case, disambiguation attributes * are added to the labels' names to keep them apart. * * For example, there are at least three bands named 'Vixen'. * Each band has a different disambiguation in the MusicBrainz * database, like 'Hip-hop' or 'all-female rock/glam band'. * * @return a disambiguation string * * @see getUniqueName */ std::string getDisambiguation() const; /** * Sets the disambiguation attribute. * * @param disambiguation a disambiguation string * * @see getDisambiguation, getUniqueName */ void setDisambiguation(const std::string &disambiguation); /** * Returns a unique label name (using disambiguation). * * This method returns the label name together with the * disambiguation attribute in parenthesis if it exists. * Example: 'Vixen (Hip-hop)'. * * @return a string containing the unique name * * @see getDisambiguation */ std::string getUniqueName() const; /** * Returns the birth/foundation date. * * The definition of the \e begin \e date depends on the label's * type. For persons, this is the day of birth, for groups it * is the day the group was founded. * * The returned date has the format "YYYY", "YYYY-MM", or * "YYYY-MM-DD", depending on how much detail is known. * * @return a string containing the date * * @see getType */ std::string getBeginDate() const; /** * Sets the begin/foundation date. * * @param dateStr a date string * * @see getBeginDate */ void setBeginDate(const std::string &dateStr); /** * Get the death/dissolving date. * * The definition of the \e end \e date depends on the label's * type. For persons, this is the day of death, for groups it * is the day the group was dissolved. * * @return a string containing a date * * @see getBeginDate */ std::string getEndDate() const; /** * Sets the death/dissolving date. * * @param dateStr a string containing a date * * @see: setEndDate, getBeginDate */ void setEndDate(const std::string &dateStr); /** * Returns a list of releases from this label. * * This may also include releases where this label isn't the * \e main label but has just contributed one or more tracks * (aka VA-Releases). * * @return: a list of pointers to Release objects */ ReleaseList &getReleases(); /** * Returns number of releases. * * This is equivalent to \c getReleases().size() * * @return an int containing number of releases * * @see getReleases */ int getNumReleases() const; /** * Returns an release specified by index. * * This is equivalent to \c getReleases()[index] * * @return a pointer to Release instance * * @see getReleases */ Release *getRelease(int index); /** * Adds a release to this label's list of releases. * * @param release a pointer to Release object */ void addRelease(Release *release); /** * Returns the offset of the release list. * * This is used if the track list is incomplete (ie. the web * service only returned part of the tracks on this release). * Note that the offset value is zero-based, which means track * \a 0 is the first track. * * @return an integer containing the offset * * @see getReleases */ int getReleasesOffset() const; /** * Sets the offset of the release list. * * @param offset an integer containing the offset * * @see getReleasesOffset */ void setReleasesOffset(const int offset); /** * Returns the number of existing releases. * * This may or may not match with the number of elements that * getReleases and getNumReleases returns. If the count is higher than * the list, it indicates that the list is incomplete. * * @return an integer containing the count * * @see getReleases */ int getReleasesCount() const; /** * Sets the count of the release list. * * @param count an integer containing the count * * @see getReleasesCount */ void setReleasesCount(const int count); /** * Returns the list of aliases for this label. * * @return a list of pointers to LabelAlias objects */ LabelAliasList &getAliases(); /** * Returns number of aliases. * * This is equivalent to \c getAliases().size() * * @return an int containing number of aliases * * @see getAliases */ int getNumAliases() const; /** * Returns alias specified by index. * * This is equivalent to \c getAliases()[index] * * @return a pointer to LabelAlias instance * * @see getAliases */ LabelAlias *getAlias(int index); /** * Adds an alias for this label. * * @param alias a pointer to LabelAlias object */ void addAlias(LabelAlias *alias); private: class LabelPrivate; LabelPrivate *d; }; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/release.h0000644000175000017500000002241710636303064021405 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: release.h 9191 2007-06-20 19:55:32Z luks $ */ #ifndef __MUSICBRAINZ3_RELEASE_H__ #define __MUSICBRAINZ3_RELEASE_H__ #include #include #include #include namespace MusicBrainz { class Artist; /** * Represents a Release. * * A release within MusicBrainz is an Entity which contains Track * objects. Releases may be of more than one type: There can be albums, * singles, compilations, live recordings, official releases, bootlegs * etc. * * @note: The current MusicBrainz server implementation supports only a * limited set of types. */ class MB_API Release : public Entity { public: static const std::string TYPE_NONE; static const std::string TYPE_ALBUM; static const std::string TYPE_SINGLE; static const std::string TYPE_EP; static const std::string TYPE_COMPILATION; static const std::string TYPE_SOUNDTRACK; static const std::string TYPE_SPOKENWORD; static const std::string TYPE_INTERVIEW; static const std::string TYPE_AUDIOBOOK; static const std::string TYPE_LIVE; static const std::string TYPE_REMIX; static const std::string TYPE_OTHER; static const std::string TYPE_OFFICIAL; static const std::string TYPE_PROMOTION; static const std::string TYPE_BOOTLEG; static const std::string TYPE_PSEUDO_RELEASE; /** * Constructor. * * @param id a string containing an absolute URI * @param title a string containing the title */ Release(const std::string &id = std::string(), const std::string &title = std::string()); /** * Destructor. */ ~Release(); /** * Returns the track's title. * * The style and format of this attribute is specified by the * style guide. * * @return a string containing an absolute URI * * @see The MusicBrainz * Style Guidelines */ std::string getTitle() const; /** * Sets the release's title. * * @param title: a string containing the release's title * * @see getTitle */ void setTitle(const std::string &title); /** * Returns the language used in release and track titles. * * To represent the language, the ISO-639-2/T standard is used, * which provides three-letter terminological language codes like * "ENG", "DEU", "JPN", "KOR", "ZHO" or "YID". * * Note that this refers to release and track \e titles, not * lyrics. * * @return a string containing the language code * * @see getLanguageName */ std::string getTextLanguage() const; /** * Sets the language used in releaes and track titles. * * @param language a string containing a language code * * @see getTextLanguage */ void setTextLanguage(const std::string &language); /** * Returns the script used in release and track titles. * * To represent the script, ISO-15924 script codes are used. * Valid codes are, among others: "Latn", "Cyrl", "Hans", "Hebr" * * Note that this refers to release and track \e titles, not * lyrics. * * @return: a string containing the script code * * @see: getScriptName */ std::string getTextScript() const; /** * Sets the script used in releaes and track titles. * * @param script a string containing a script code * * @see getTextScript */ void setTextScript(const std::string &script); /** * Returns the main artist of this release. * * @return a pointer to Artist object, or NULL */ Artist *getArtist(); /** * Sets this release's main artist. * * @param artist a pointer to Artist object */ void setArtist(Artist *artist); /** * Returns the Amazon shop identifier (ASIN). * * The ASIN is a 10-letter code (except for books) assigned * by Amazon, which looks like 'B000002IT2' or 'B00006I4YD'. * * @return a string containing the ASIN */ std::string getAsin() const; /** * Sets the Amazon shop identifier (ASIN). * * @param asin a string containing the ASIN * * @see getAsin */ void setAsin(const std::string &asin); /** * Returns the tracks this release contains. * * @return a list containing pointers to Track objects * * @see getTracksOffset */ TrackList &getTracks(); /** * Returns number of tracks. * * This is equivalent to \c getTracks().size() * * @return an int containing number of tracks * * @see getTracks */ int getNumTracks() const; /** * Returns an track specified by index. * * This is equivalent to \c getTracks()[index] * * @warning \c index must be always lower than the result of \c getNumTracks() * * @return a pointer to Track instance * * @see getTracks */ Track *getTrack(int index); /** * Returns the offset of the track list. * * This is used if the track list is incomplete (ie. the web * service only returned part of the tracks on this release). * Note that the offset value is zero-based, which means track * \a 0 is the first track. * * @return an integer containing the offset * * @see getTracks */ int getTracksOffset() const; /** * Sets the offset of the track list. * * @param offset an integer containing the offset * * @see getTracksOffset */ void setTracksOffset(const int offset); /** * Returns the number of tracks on this release. * * This may or may not match with the number of elements that * getTracks and getNumTracks returns. If the count is higher than * the list, it indicates that the list is incomplete. * * @return an integer containing the count * * @see getTracks */ int getTracksCount() const; /** * Sets the count of the track list. * * @param count an integer containing the count * * @see getTracksCount */ void setTracksCount(const int count); /** * Returns the discs associated with this release. * * Discs are currently containers for MusicBrainz DiscIDs. * Note that under rare circumstances (identical TOCs), a * DiscID could be associated with more than one release. * * @return a list of pointers to Disc objects * * @todo make the returned vector \c const */ DiscList &getDiscs(); /** * Returns number of discs. * * This is equivalent to \c getDiscs().size() * * @return an int containing number of discs * * @see getDiscs */ int getNumDiscs() const; /** * Returns an disc specified by index. * * This is equivalent to \c getDiscs()[index] * * @warning \c index must be always lower than the result of \c getNumDiscs() * * @return a pointer to Disc instance * * @see getDiscs */ Disc *getDisc(int index); /** * Returns the list of release events. * * A Release may contain a list of so-called release events, * each represented using a ReleaseEvent object. Release * evens specify where and when this release was, well, released. * * @return a list of pointers to ReleaseEvent objects */ ReleaseEventList &getReleaseEvents(); /** * Returns number of release events. * * This is equivalent to \c getReleaseEvents().size() * * @return an int containing number of release events * * @see getReleaseEvents */ int getNumReleaseEvents() const; /** * Returns an release event specified by index. * * This is equivalent to \c getReleaseevents()[index] * * @warning \c index must be always lower than the result of \c getNumReleaseEvents() * * @return a pointer to ReleaseEvent instance * * @see getReleaseEvents */ ReleaseEvent *getReleaseEvent(int index); /** * Sets the list of release types. * * @param types a vector of strings string */ void setTypes(const std::vector &types); /** * Returns the list of release types. * * @return a vector of strings string * * @see getType */ std::vector &getTypes(); /** * Returns the number of release types. * * @return an int */ int getNumTypes() const; /** * Returns the type specified by index. * * This is an equivalent to \c getTypes()[index] * * @warning \c index must be always lower than the result of \c getNumTypes() * * @param index index * @return a string * * @see getTypes */ std::string getType(int index) const; private: class ReleasePrivate; ReleasePrivate *d; }; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/disc.h0000644000175000017500000001501410477236200020702 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: disc.h 8466 2006-09-05 08:59:44Z luks $ */ #ifndef __MUSICBRAINZ3_DISC_H__ #define __MUSICBRAINZ3_DISC_H__ #include #include #include #include namespace MusicBrainz { /** * Represents an Audio CD. * * This class represents an Audio CD. A disc can have an ID (the * MusicBrainz DiscID), which is calculated from the CD's table of * contents (TOC). There may also be data from the TOC like the length * of the disc in sectors, as well as position and length of the tracks. * * Note that different TOCs, maybe due to different pressings, lead to * different DiscIDs. Conversely, if two different discs have the same * TOC, they also have the same DiscID (which is unlikely but not * impossible). DiscIDs are always 28 characters long and look like this: * \a 'J68I_CDcUFdCRCIbHSEbTBCbooA-'. Sometimes they are also referred * to as CDIndex IDs. * * The MusicBrainz web service (WebService) only returns * the DiscID and the number of sectors. The DiscID calculation function * readDisc, however, can retrieve the other * attributes of Disc from an Audio CD in the disc drive. */ class MB_API Disc { public: typedef std::pair Track; typedef std::vector TrackList; /** * Constructor. * * @param id a string containing a 28-character DiscID */ Disc(const std::string &id = std::string()); /** * Destructor. */ virtual ~Disc(); /** * Returns the MusicBrainz DiscID. * * @return a string containing a 28-character DiscID */ std::string getId() const; /** * Sets the MusicBrainz DiscId. * * @param value a string containing a 28-character DiscID */ void setId(const std::string &value); /** * Returns the length of the disc in sectors. * * @return the length in sectors as an integer */ int getSectors() const; /** * Sets the length of the disc in sectors. * * @param sectors the length in sectors as an integer */ void setSectors(const int sectors); /** * Returns the number of the first track on this disc. * * @return an int containing the track number */ int getFirstTrackNum() const; /** * Sets the number of the first track on this disc. * * @param trackNum an int containing the track number */ void setFirstTrackNum(const int trackNum); /** * Returns the number of the last track on this disc. * * @return an int containing the track number */ int getLastTrackNum() const; /** * Sets the number of the last track on this disc. * * @param trackNum an int containing the track number */ void setLastTrackNum(const int trackNum); /** * Returns the sector offset and length of this disc. * * This method returns a list of tuples containing the track * offset and length in sectors for all tracks on this disc. * The track offset is measured from the beginning of the disc, * the length is relative to the track's offset. Note that the * leadout track is \e not included. * * @return a vector of (offset, length) pairs (values are ints) */ Disc::TrackList &getTracks(); /** * Adds a track to the list. * * This method adds an (offset, length) pair to the list of * tracks. The leadout track must \e not be added. The total * length of the disc can be set using setSectors. * * @param track an (offset, length) pair (values are ints) * * @see getTracks */ void addTrack(Disc::Track track); private: class DiscPrivate; DiscPrivate *d; }; /** * The Audio CD could not be read. * * This may be simply because no disc was in the drive, the device name * was wrong or the disc can't be read. Reading errors can occur in case * of a damaged disc or a copy protection mechanism, for example. */ class MB_API DiscError : public Exception { public: DiscError(const std::string &msg = std::string()) : Exception(msg) {} }; /** * Reads an Audio CD in the disc drive. * * This reads a CD's table of contents (TOC) and calculates the MusicBrainz * DiscID, which is a 28 character ASCII string. This DiscID can be used * to retrieve a list of matching releases from the web service (see * MusicBrainz::Query). * * Note that an Audio CD has to be in drive for this to work. The * \a deviceName argument may be used to set the device. The default * depends on the operating system (on linux, it's \c "/dev/cdrom"). * No network connection is needed for this function. * * If the device doesn't exist or there's no valid Audio CD in the drive, * a DiscError exception is raised. * * @param deviceName a string containing the CD drive's device name * * @return a pointer to Disc object * * @throw DiscError if there was a problem reading the disc */ MB_API Disc *readDisc(const std::string &deviceName = std::string()); /** * Returns a URL for adding a disc to the MusicBrainz database. * * A fully initialized Disc object is needed, as * returned by readDisc. A disc object returned by the web service * doesn't provide the necessary information. * * Note that the created URL is intended for interactive use and points * to the MusicBrainz disc submission wizard by default. This method * just returns a URL, no network connection is needed. The disc drive * isn't used. * * @param disc a fully initialized Disc object * @param host a string containing a host name * @param port an integer containing a port number * * @return a string containing the submission URL * * @see readDisc */ MB_API std::string getSubmissionUrl(Disc *disc, const std::string &host = "mm.musicbrainz.org", int port = 80); } #endif libmusicbrainz-3.0.2/include/musicbrainz3/entity.h0000644000175000017500000001036110640015234021266 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: entity.h 9216 2007-06-25 19:42:20Z luks $ */ #ifndef __MUSICBRAINZ3_ENTITY_H__ #define __MUSICBRAINZ3_ENTITY_H__ #include #include #include #include #include namespace MusicBrainz { /** * A first-level MusicBrainz class. * * All entities in MusicBrainz have unique IDs (which are absolute URIs) * and may have any number of relations (Relation) to other entities. * This class is abstract and should not be instantiated. * * Relations are differentiated by their \e target \e type, that means, * where they link to. MusicBrainz currently supports four target types * (artists, releases, tracks, and URLs) each identified using a URI. * To get all relations with a specific target type, you can use * getRelations and pass one of the following constants as the * parameter: * * - Relation::TO_ARTIST * - Relation::TO_RELEASE * - Relation::TO_TRACK * - Relation::TO_URL * * @see Relation */ class MB_API Entity { protected: /** * Constructor. * * This should only used by derived classes. * * @param id a string containing an absolute URI */ Entity(const std::string &id); public: /** * Destructor. */ virtual ~Entity(); /** * Returns a MusicBrainz ID. * * @return a string containing a URI */ virtual std::string getId() const; /** * Sets a MusicBrainz ID. * * @param value a string containing an absolute URI */ virtual void setId(const std::string &value); /** * Returns a list of relations. * * If \a targetType is given, only relations of that target * type are returned. For MusicBrainz, the following target * types are defined: * * - Relation::TO_ARTIST * - Relation::TO_RELEASE * - Relation::TO_TRACK * - Relation::TO_URL * * If \a targetType is Relation::TO_ARTIST, for example, * this method returns all relations between this Entity and * artists. * * You may use the \a relationType parameter to further restrict * the selection. If it is set, only relations with the given * relation type are returned. * * @param targetType a string containing an absolute URI * @param relationType a string containing an absolute URI * * @return a list of pointers to Relation objects * * @see Entity */ RelationList getRelations(const std::string &targetType = std::string(), const std::string &relationType = std::string()) const; /** * Adds a relation. * * This method adds \a relation to the list of relations. The * given relation has to be initialized, at least the target * type has to be set. * * @param relation a pointer to Relation object to add */ void addRelation(Relation *relation); /** * Returns number of relations. * * This is equivalent to \c getRelations().size() * * @return an int containing number of relations * * @see getRelations */ int getNumRelations() const; /** * Returns an relation specified by index. * * This is equivalent to \c getRelations()[index] * * @return a pointer to Relation instance * * @see getRelations */ Relation *getRelation(int index); TagList &getTags(); int getNumTags() const; Tag *getTag(int index); private: class EntityPrivate; EntityPrivate *d; }; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/mb_c.h0000644000175000017500000004755411032622261020670 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: mb_c.h 9932 2008-07-02 06:48:17Z luks $ */ #ifndef __MUSICBRAINZ3_MB_C_H__ #define __MUSICBRAINZ3_MB_C_H__ #ifdef __cplusplus extern "C" { #endif #include /* {{{ Typedefs */ typedef void *MbArtist; typedef void *MbArtistAlias; typedef void *MbArtistFilter; typedef void *MbArtistIncludes; typedef void *MbDisc; typedef void *MbEntity; typedef void *MbQuery; typedef void *MbRelation; typedef void *MbRelease; typedef void *MbReleaseEvent; typedef void *MbReleaseFilter; typedef void *MbReleaseIncludes; typedef void *MbResultList; typedef void *MbTrack; typedef void *MbTrackFilter; typedef void *MbTrackIncludes; typedef void *MbUser; typedef void *MbUserFilter; typedef void *MbWebService; /* }}} */ /* {{{ MusicBrainz::WebService */ /** * Creates a new instance of MbWebService. * * @see MusicBrainz::WebService::WebService */ MB_API MbWebService mb_webservice_new(); /** * Deletes the MbWebService instance. * * @see MusicBrainz::WebService::~WebService */ MB_API void mb_webservice_free(MbWebService webservice); /** * @see MusicBrainz::WebService::setHost */ MB_API void mb_webservice_set_host(MbWebService webservice, const char *str); /** * @see MusicBrainz::WebService::setPort */ MB_API void mb_webservice_set_port(MbWebService webservice, int port); /** * @see MusicBrainz::WebService::setPathPrefix */ MB_API void mb_webservice_set_path_prefix(MbWebService webservice, const char *str); /** * @see MusicBrainz::WebService::setUserName */ MB_API void mb_webservice_set_username(MbWebService webservice, const char *str); /** * @see MusicBrainz::WebService::setPassword */ MB_API void mb_webservice_set_password(MbWebService webservice, const char *str); /** * @see MusicBrainz::WebService::setRealm */ MB_API void mb_webservice_set_realm(MbWebService webservice, const char *str); /** * @see MusicBrainz::WebService::setProxyHost */ MB_API void mb_webservice_set_proxy_host(MbWebService webservice, const char *str); /** * @see MusicBrainz::WebService::setProxyPort */ MB_API void mb_webservice_set_proxy_port(MbWebService webservice, int port); /** * @see MusicBrainz::WebService::setProxyUserName */ MB_API void mb_webservice_set_proxy_username(MbWebService webservice, const char *str); /** * @see MusicBrainz::WebService::setProxyPassword */ MB_API void mb_webservice_set_proxy_password(MbWebService webservice, const char *str); /* }}} */ /* {{{ MusicBrainz::Query */ /** * Creates a new instance of MbQuery. * * @see MusicBrainz::Query::Query */ MB_API MbQuery mb_query_new(MbWebService ws, const char *client_id); /** * Deletes the MbQuery instance. * * @see MusicBrainz::Query::~Query */ MB_API void mb_query_free(MbQuery query); /** * Returns an artist. * * @see MusicBrainz::Query::getArtistById */ MB_API MbArtist mb_query_get_artist_by_id(MbQuery query, const char *id, MbArtistIncludes inc); /** * Returns an release. * * @see MusicBrainz::Query::getReleaseById */ MB_API MbRelease mb_query_get_release_by_id(MbQuery query, const char *id, MbReleaseIncludes inc); /** * Returns an track. * * @see MusicBrainz::Query::getTrackById */ MB_API MbTrack mb_query_get_track_by_id(MbQuery query, const char *id, MbTrackIncludes inc); /** * Returns information about a MusicBrainz user. * * @see MusicBrainz::Query::getUserByName */ MB_API MbUser mb_query_get_user_by_name(MbQuery query, const char *name); /* }}} */ MB_API void mb_result_list_free(MbResultList list); MB_API int mb_result_list_get_size(MbResultList list); MB_API int mb_result_list_get_score(MbResultList list, int index); MB_API MbArtist mb_result_list_get_artist(MbResultList list, int index); MB_API MbRelease mb_result_list_get_release(MbResultList list, int index); MB_API MbTrack mb_result_list_get_track(MbResultList list, int index); MB_API MbResultList mb_query_get_artists(MbQuery query, MbArtistFilter flt); MB_API MbResultList mb_query_get_releases(MbQuery query, MbReleaseFilter flt); MB_API MbResultList mb_query_get_tracks(MbQuery query, MbTrackFilter flt); /* {{{ MusicBrainz::Artist */ /** * Deletes the MbArtist instance. */ MB_API void mb_artist_free(MbArtist artist); /** * Returns the artist's ID. * * @see MusicBrainz::Artist::getId */ MB_API void mb_artist_get_id(MbArtist artist, char *str, int len); /** * Returns the artist's type. * * @see MusicBrainz::Artist::getType */ MB_API void mb_artist_get_type(MbArtist artist, char *str, int len); /** * Returns the artist's name. * * @see MusicBrainz::Artist::getName */ MB_API void mb_artist_get_name(MbArtist artist, char *str, int len); /** * Returns the artist's sort name. * * @see MusicBrainz::Artist::getSortName */ MB_API void mb_artist_get_sortname(MbArtist artist, char *str, int len); /** * Returns the disambiguation attribute. * * @see MusicBrainz::Artist::getDisambiguation */ MB_API void mb_artist_get_disambiguation(MbArtist artist, char *str, int len); /** * Returns a unique artist name (using disambiguation). * * @see MusicBrainz::Artist::getUniqueName */ MB_API void mb_artist_get_unique_name(MbArtist artist, char *str, int len); /** * Returns the birth/foundation date. * * @see MusicBrainz::Artist::getBeginDate */ MB_API void mb_artist_get_begin_date(MbArtist artist, char *str, int len); /** * Returns the death/dissolving date. * * @see MusicBrainz::Artist::getEndDate */ MB_API void mb_artist_get_end_date(MbArtist artist, char *str, int len); /** * Returns number of aliases. * * @see MusicBrainz::Artist::getNumAliases */ MB_API int mb_artist_get_num_aliases(MbArtist artist); /** * Returns an alias specified by index. * * @see MusicBrainz::Artist::getGetAlias */ MB_API MbArtistAlias mb_artist_get_alias(MbArtist artist, int index); /** * Returns number of releases. * * @see MusicBrainz::Artist::getNumReleases */ MB_API int mb_artist_get_num_releases(MbArtist artist); /** * Returns an release specified by index. * * @see MusicBrainz::Artist::getGetRelease */ MB_API MbRelease mb_artist_get_release(MbArtist artist, int index); /** * Returns the offset of the release list. * * @see MusicBrainz::Artist::getReleasesOffset */ MB_API int mb_artist_get_releases_offset(MbArtist artist); /** * Returns the number of releases on this artist. * * @see MusicBrainz::Artist::getReleasesCount */ MB_API int mb_artist_get_releases_count(MbArtist artist); /** * Returns number of relations. * * @see MusicBrainz::Artist::getNumRelations */ MB_API int mb_artist_get_num_relations(MbArtist artist); /** * Returns a relation specified by index. * * @see MusicBrainz::Artist::getRelation */ MB_API MbRelation mb_artist_get_relation(MbArtist artist, int index); /* }}} */ /* {{{ MusicBrainz::Release */ /** * Deletes the MbRelease instance. */ MB_API void mb_release_free(MbRelease release); /** * Returns the release's ID. * * @see MusicBrainz::Release::getId */ MB_API void mb_release_get_id(MbRelease release, char *str, int len); /** * Returns the release's title. * * @see MusicBrainz::Release::getTitle */ MB_API void mb_release_get_title(MbRelease release, char *str, int len); /** * Returns the language used in release and track titles. * * @see MusicBrainz::Release::getTextLanguage */ MB_API void mb_release_get_text_language(MbRelease release, char *str, int len); /** * Returns the script used in release and track titles. * * @see MusicBrainz::Release::getTextScript */ MB_API void mb_release_get_text_script(MbRelease release, char *str, int len); /** * Returns the Amazon shop identifier (ASIN). * * @see MusicBrainz::Release::getAsin */ MB_API void mb_release_get_asin(MbRelease release, char *str, int len); /** * Returns the artist. * * @see MusicBrainz::Release::getArtist */ MB_API MbArtist mb_release_get_artist(MbRelease release); /** * Returns the offset of the track list. * * @see MusicBrainz::Release::getTracksOffset */ MB_API int mb_release_get_tracks_offset(MbRelease release); /** * Returns the number of tracks on this release. * * @see MusicBrainz::Release::getTracksCount */ MB_API int mb_release_get_tracks_count(MbRelease release); /** * Returns number of relations. * * @see MusicBrainz::Release::getNumRelations */ MB_API int mb_release_get_num_relations(MbRelease release); /** * Returns a relation specified by index. * * @see MusicBrainz::Release::getRelation */ MB_API MbRelation mb_release_get_relation(MbRelease release, int index); /** * Returns number of tracks. * * @see MusicBrainz::Release::getNumTracks */ MB_API int mb_release_get_num_tracks(MbRelease release); /** * Returns a track specified by index. * * @see MusicBrainz::Release::getTrack */ MB_API MbTrack mb_release_get_track(MbRelease release, int index); /** * Returns number of discs. * * @see MusicBrainz::Release::getNumDiscs */ MB_API int mb_release_get_num_discs(MbRelease release); /** * Returns a disc specified by index. * * @see MusicBrainz::Release::getDisc */ MB_API MbDisc mb_release_get_disc(MbRelease release, int index); /** * Returns number of release events. * * @see MusicBrainz::Release::getNumReleaseEvents */ MB_API int mb_release_get_num_release_events(MbRelease release); /** * Returns a release event specified by index. * * @see MusicBrainz::Release::getReleaseEvent */ MB_API MbReleaseEvent mb_release_get_release_event(MbRelease release, int index); /** * Returns number of types. * * @see MusicBrainz::Release::getNumTypes */ MB_API int mb_release_get_num_types(MbRelease release); /** * Returns a type specified by index. * * @see MusicBrainz::Release::getType */ MB_API void mb_release_get_type(MbRelease release, int index, char *str, int len); /* }}} */ /* {{{ MusicBrainz::Track */ /** * Deletes the MbTrack instance. */ MB_API void mb_track_free(MbTrack track); /** * Returns the track's ID. * * @see MusicBrainz::Track::getId */ MB_API void mb_track_get_id(MbTrack track, char *str, int len); /** * Returns the track's title. * * @see MusicBrainz::Track::getTitle */ MB_API void mb_track_get_title(MbTrack track, char *str, int len); /** * Returns the track's duration. * * @see MusicBrainz::Track::getDuration */ MB_API int mb_track_get_duration(MbTrack track); /** * Returns number of relations. * * @see MusicBrainz::Track::getNumRelations */ MB_API int mb_track_get_num_relations(MbTrack track); /** * Returns a relation specified by index. * * @see MusicBrainz::Track::getRelation */ MB_API MbRelation mb_track_get_relation(MbTrack track, int index); /** * Returns the artist. * * @see MusicBrainz::Track::getArtist */ MB_API MbArtist mb_track_get_artist(MbTrack track); /* }}} */ /* {{{ MusicBrainz::ArtistAlias */ /** * Returns the alias. * * @see MusicBrainz::ArtistAlias::getValue */ MB_API void mb_artist_alias_get_value(MbArtistAlias alias, char *str, int len); /** * Returns the alias type. * * @see MusicBrainz::ArtistAlias::getType */ MB_API void mb_artist_alias_get_type(MbArtistAlias alias, char *str, int len); /** * Returns the alias script. * * @see MusicBrainz::ArtistAlias::getScript */ MB_API void mb_artist_alias_get_script(MbArtistAlias alias, char *str, int len); /* }}} */ /* {{{ MusicBrainz::User */ /** * Deletes the MbUsers instance. */ MB_API void mb_user_free(MbUser user); /** * Returns the user name. * * @see MusicBrainz::User::getName */ MB_API void mb_user_get_name(MbUser user, char *str, int len); /** * Returns true if a nag screen should be displayed to the user. * * @see MusicBrainz::User::getShowNag */ MB_API int mb_user_get_show_nag(MbUser user); /** * Returns number of types. * * @see MusicBrainz::User::getNumTypes */ MB_API int mb_user_get_num_types(MbUser user); /** * Returns a type specified by index. * * @see MusicBrainz::User::getType */ MB_API void mb_user_get_type(MbUser user, int index, char *str, int len); /* }}} */ /* {{{ MusicBrainz::ArtistIncludes */ MB_API MbArtistIncludes mb_artist_includes_new(); MB_API void mb_artist_includes_free(MbArtistIncludes inc); MB_API MbArtistIncludes mb_artist_includes_aliases(MbArtistIncludes inc); MB_API MbArtistIncludes mb_artist_includes_releases(MbArtistIncludes inc, const char *type); MB_API MbArtistIncludes mb_artist_includes_va_releases(MbArtistIncludes inc, const char *type); MB_API MbArtistIncludes mb_artist_includes_artist_relations(MbArtistIncludes inc); MB_API MbArtistIncludes mb_artist_includes_release_relations(MbArtistIncludes inc); MB_API MbArtistIncludes mb_artist_includes_track_relations(MbArtistIncludes inc); MB_API MbArtistIncludes mb_artist_includes_url_relations(MbArtistIncludes inc); MB_API MbArtistIncludes mb_artist_includes_release_events(MbArtistIncludes inc); /* }}} */ /* {{{ MusicBrainz::ReleaseIncludes */ MB_API MbReleaseIncludes mb_release_includes_new(); MB_API void mb_release_includes_free(MbReleaseIncludes inc); MB_API MbReleaseIncludes mb_release_includes_artist(MbReleaseIncludes inc); MB_API MbReleaseIncludes mb_release_includes_counts(MbReleaseIncludes inc); MB_API MbReleaseIncludes mb_release_includes_release_events(MbReleaseIncludes inc); MB_API MbReleaseIncludes mb_release_includes_discs(MbReleaseIncludes inc); MB_API MbReleaseIncludes mb_release_includes_tracks(MbReleaseIncludes inc); MB_API MbReleaseIncludes mb_release_includes_artist_relations(MbReleaseIncludes inc); MB_API MbReleaseIncludes mb_release_includes_release_relations(MbReleaseIncludes inc); MB_API MbReleaseIncludes mb_release_includes_track_relations(MbReleaseIncludes inc); MB_API MbReleaseIncludes mb_release_includes_url_relations(MbReleaseIncludes inc); /* }}} */ /* {{{ MusicBrainz::TrackIncludes */ MB_API MbTrackIncludes mb_track_includes_new(); MB_API void mb_track_includes_free(MbArtistIncludes inc); MB_API MbTrackIncludes mb_track_includes_artist(MbArtistIncludes inc); MB_API MbTrackIncludes mb_track_includes_releases(MbArtistIncludes inc); MB_API MbTrackIncludes mb_track_includes_puids(MbArtistIncludes inc); MB_API MbTrackIncludes mb_track_includes_artist_relations(MbArtistIncludes inc); MB_API MbTrackIncludes mb_track_includes_release_relations(MbTrackIncludes inc); MB_API MbTrackIncludes mb_track_includes_track_relations(MbTrackIncludes inc); MB_API MbTrackIncludes mb_track_includes_url_relations(MbTrackIncludes inc); /* }}} */ /* {{{ MusicBrainz::MbArtistFilter */ MB_API MbArtistFilter mb_artist_filter_new(); MB_API void mb_artist_filter_free(MbArtistFilter flt); MB_API MbArtistFilter mb_artist_filter_name(MbArtistFilter flt, const char *value); MB_API MbArtistFilter mb_artist_filter_limit(MbArtistFilter flt, int value); /* }}} */ /* {{{ MusicBrainz::MbReleaseFilter */ MB_API MbReleaseFilter mb_release_filter_new(); MB_API void mb_release_filter_free(MbReleaseFilter flt); MB_API MbReleaseFilter mb_release_filter_title(MbReleaseFilter flt, const char *value); MB_API MbReleaseFilter mb_release_filter_disc_id(MbReleaseFilter flt, const char *value); MB_API MbReleaseFilter mb_release_filter_release_type(MbReleaseFilter flt, const char *value); MB_API MbReleaseFilter mb_release_filter_artist_name(MbReleaseFilter flt, const char *value); MB_API MbReleaseFilter mb_release_filter_artist_id(MbReleaseFilter flt, const char *value); MB_API MbReleaseFilter mb_release_filter_limit(MbReleaseFilter flt, int value); /* }}} */ /* {{{ MusicBrainz::MbTrackFilter */ MB_API MbTrackFilter mb_track_filter_new(); MB_API void mb_track_filter_free(MbTrackFilter flt); MB_API MbTrackFilter mb_track_filter_title(MbTrackFilter flt, const char *value); MB_API MbTrackFilter mb_track_filter_artist_name(MbTrackFilter flt, const char *value); MB_API MbTrackFilter mb_track_filter_artist_id(MbTrackFilter flt, const char *value); MB_API MbTrackFilter mb_track_filter_release_title(MbTrackFilter flt, const char *value); MB_API MbTrackFilter mb_track_filter_release_id(MbTrackFilter flt, const char *value); MB_API MbTrackFilter mb_track_filter_duration(MbTrackFilter flt, int value); MB_API MbTrackFilter mb_track_filter_puid(MbTrackFilter flt, const char *value); MB_API MbTrackFilter mb_track_filter_limit(MbTrackFilter flt, int value); /* }}} */ /* {{{ MusicBrainz::MbUserFilter */ MB_API MbUserFilter mb_user_filter_new(); MB_API void mb_user_filter_free(MbUserFilter flt); MB_API MbUserFilter mb_user_filter_name(MbUserFilter flt, const char *value); /* }}} */ /* {{{ MusicBrainz::ArtistAlias */ /** * Returns the country a release took place. * * @see MusicBrainz::ReleaseEvent::getCountry */ MB_API void mb_release_event_get_country(MbReleaseEvent releaseEvent, char *str, int len); /** * Returns the date a release took place. * * @see MusicBrainz::ReleaseEvent::getDate */ MB_API void mb_release_event_get_date(MbReleaseEvent releaseEvent, char *str, int len); /* }}} */ /* {{{ MusicBrainz::Relation */ /** * Returns this relation's type. * * @see MusicBrainz::Relation::getType */ MB_API void mb_relation_get_type(MbRelation relation, char *str, int len); /** * Returns the target's ID. * * @see MusicBrainz::Relation::getTargetId */ MB_API void mb_relation_get_target_id(MbRelation relation, char *str, int len); /** * Returns the target's type. * * @see MusicBrainz::Relation::getTargetType */ MB_API void mb_relation_get_target_type(MbRelation relation, char *str, int len); /** * Returns the begin date. * * @see MusicBrainz::Relation::getBeginDate */ MB_API void mb_relation_get_begin_date(MbRelation relation, char *str, int len); /** * Returns the end date. * * @see MusicBrainz::Relation::getEndDate */ MB_API void mb_relation_get_end_date(MbRelation relation, char *str, int len); /** * Returns the reading direction. * * @see MusicBrainz::Relation::getDirection */ MB_API int mb_relation_get_direction(MbRelation relation); /** * Returns this relation's target object. * * @see MusicBrainz::Relation::getTarget */ MB_API MbEntity mb_relation_get_target(MbRelation relation); /** * Returns number of attributes. * * @see MusicBrainz::Relation::getNumAttributes */ MB_API int mb_relation_get_num_attributes(MbRelation relation); /** * Returns a attribute specified by index. * * @see MusicBrainz::Relation::getAttribute */ MB_API void mb_relation_get_attribute(MbRelation relation, int index, char *str, int len); /* }}} */ /* {{{ MusicBrainz::Disc */ /** * Returns the MusicBrainz DiscID. * * @see MusicBrainz::Disc::getId */ MB_API void mb_disc_get_id(MbDisc disc, char *str, int len); /** * Returns the length of the disc in sectors. * * @see MusicBrainz::Disc::getSectors */ MB_API int mb_disc_get_sectors(MbDisc disc); /** * Returns the number of the first track on this disc. * * @see MusicBrainz::Disc::getFirstTrackNum */ MB_API int mb_disc_get_first_track_num(MbDisc disc); /** * Returns the number of the last track on this disc. * * @see MusicBrainz::Disc::getLastTrackNum */ MB_API int mb_disc_get_last_track_num(MbDisc disc); /** * Reads an Audio CD in the disc drive. * * @see MusicBrainz::readDisc */ MB_API MbDisc mb_read_disc(const char *device_name); /** * Returns a URL for adding a disc to the MusicBrainz database. * * @see MusicBrainz::getSubmissionUrl */ MB_API void mb_get_submission_url(MbDisc disc, const char *host, int port, char *str, int len); /* }}} */ #ifdef __cplusplus } #endif #endif libmusicbrainz-3.0.2/include/musicbrainz3/filters.h0000644000175000017500000001107310477236200021431 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: filters.h 8466 2006-09-05 08:59:44Z luks $ */ #ifndef __MUSICBRAINZ3_FILTERS_H__ #define __MUSICBRAINZ3_FILTERS_H__ #include #include #include #include namespace MusicBrainz { /** * A filter for collections. * * This is the interface all filters have to implement. */ class MB_API IFilter { public: typedef std::vector > ParameterList; virtual ~IFilter() {}; /** * Create a map of query parameters. * * @return: a string->string map of parameters */ virtual ParameterList createParameters() const = 0; }; /** * A filter for the artist collection. */ class MB_API ArtistFilter : public IFilter { public: ArtistFilter &name(const std::string &name); ArtistFilter &limit(const int limit); ParameterList createParameters() const; private: ParameterList parameters; }; /** * A filter for the release collection. * * If \a discId or \a artistId are set, only releases matching * those IDs are returned. The \a releaseType parameter allows * to limit the types of the releases returned. You can set it to * Release::TYPE_ALBUM and Release::TYPE_OFFICIAL, for example, * to only get officially released albums. Note that those values * are connected using the \e AND operator. MusicBrainz' support * is currently very limited, so Release::TYPE_LIVE and * Release::TYPE_COMPILATION exclude each other (see the * documentation on release attributes ) for more * information and all valid values). * * If both the \a artistName and the \a artistId parameter are * given, the server will ignore \a artistName. * * @note The original Python library has \a releaseTypes parameter * that accepts a list of release types. Due to C++ limitations, the * library has \a releaseType parameter instead, that accepts only one * release type, but you can use it multiple times. For example, to * convert Python code: * \code * ReleaseFilter(releaseTypes=(Release.TYPE_ALBUM, Release.TYPE_OFFICIAL)) * \endcode * you can use following C++ code: * \code * ReleaseFilter().releaseType(Release::TYPE_ALBUM).releaseType(Release::TYPE_OFFICIAL) * \endcode */ class MB_API ReleaseFilter : public IFilter { public: ReleaseFilter &title(const std::string &value); ReleaseFilter &discId(const std::string &value); ReleaseFilter &releaseType(const std::string &value); ReleaseFilter &artistName(const std::string &value); ReleaseFilter &artistId(const std::string &value); ReleaseFilter &limit(const int value); ParameterList createParameters() const; private: ParameterList parameters; }; /** * A filter for the track collection. * * If \a artistId, \a releaseId or \a puid are set, only tracks * matching those IDs are returned. * * The server will ignore \a artistName and \a releaseTitle if * \a artistId or \a releaseId are set respectively. */ class MB_API TrackFilter : public IFilter { public: TrackFilter &title(const std::string &value); TrackFilter &artistName(const std::string &value); TrackFilter &artistId(const std::string &value); TrackFilter &releaseTitle(const std::string &value); TrackFilter &releaseId(const std::string &value); TrackFilter &duration(const int value); TrackFilter &puid(const std::string &value); TrackFilter &limit(const int value); ParameterList createParameters() const; private: ParameterList parameters; }; /** * A filter for the user collection. */ class MB_API UserFilter : public IFilter { public: UserFilter &name(const std::string &name); ParameterList createParameters() const; private: ParameterList parameters; }; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/relation.h0000644000175000017500000001673010477236200021603 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: relation.h 8466 2006-09-05 08:59:44Z luks $ */ #ifndef __MUSICBRAINZ3_RELATION_H__ #define __MUSICBRAINZ3_RELATION_H__ #include #include #include namespace MusicBrainz { class Entity; /** * Represents a relation between two Entities. * * There may be an arbitrary number of relations between all first * class objects in MusicBrainz. The Relation itself has multiple * attributes, which may or may not be used for a given relation * type. * * Note that a Relation object only contains the target but not * the source end of the relation. */ class MB_API Relation { public: //! Identifies relations linking to an artist. static const std::string TO_ARTIST; //! Identifies relations linking to a release. static const std::string TO_RELEASE; //! Identifies relations linking to a track. static const std::string TO_TRACK; //! Identifies relations linking to an URL. static const std::string TO_URL; enum Direction { //! Relation reading direction doesn't matter. DIR_BOTH, //! Relation reading direction is from source to target. DIR_FORWARD, //! Relation reading direction is from target to source. DIR_BACKWARD }; //! A vector of strings (attributes). typedef std::vector Attributes; /** * Constructor. * * @param relationType a string containing an absolute URI * @param targetType a string containing an absolute URI * @param targetId a string containing an absolute URI * @param direction one of Relation::DIR_FORWARD, * Relation::DIR_BACKWARD, or Relation::DIR_BOTH * @param attributes a list of strings containing absolute URIs * @param beginDate a string containing a date * @param endDate a string containing a date * @param target an instance of a subclass of Entity, or NULL */ Relation(const std::string &relationType = std::string(), const std::string &targetType = std::string(), const std::string &targetId = std::string(), const Direction direction = DIR_BOTH, const Attributes &attributes = Attributes(), const std::string &beginDate = std::string(), const std::string &endDate = std::string(), Entity *target = NULL); /** * Destructor. */ virtual ~Relation(); /** * Returns this relation's type. * * @return a string containing an absolute URI */ std::string getType() const; /** * Sets this relation's type. * * @param type a string containing an absolute URI */ void setType(const std::string &type); /** * Returns the target's ID. * * This is the ID the relation points to. It is an absolute * URI, and in case of an URL relation, it is a URL. * * @return a string containing an absolute URI */ std::string getTargetId() const; /** * Sets the target's ID. * * @param targetId a string containing an absolute URI * * @see getTargetId */ void setTargetId(const std::string &targetId); /** * Returns the target's type. * * For MusicBrainz data, the following target types are defined: * - artists: Relation::TO_ARTIST * - releases: Relation::TO_RELEASE * - tracks: Relation::TO_TRACK * - urls: Relation::TO_URL * * @return a string containing an absolute URI */ std::string getTargetType() const; /** * Sets the target's type. * * @param targetType a string containing an absolute URI * * @see getTargetType */ void setTargetType(const std::string &targetType); /** * Returns the begin date. * * The definition depends on the relation's type. It may for * example be the day of a marriage or the year an artist * joined a band. For other relation types this may be * undefined. * * @return a string containing a date */ std::string getBeginDate() const; /** * Sets the begin date. * * @param dateStr a string containing a date * * @see getBeginDate */ void setBeginDate(const std::string &dateStr); /** * Returns the end date. * * As with the begin date, the definition depends on the * relation's type. Depending on the relation type, this may * or may not be defined. * * @return a string containing a date * * @see getBeginDate */ std::string getEndDate() const; /** * Sets the end date. * * @param dateStr: a string containing a date * * @see getBeginDate */ void setEndDate(const std::string &dateStr); /** * Returns the reading direction. * * The direction may be one of Relation::DIR_FORWARD, * Relation::DIR_BACKWARD, or Relation::DIR_BOTH, * depending on how the relation should be read. For example, * if direction is Relation::DIR_FORWARD for a cover relation, * it is read as "X is a cover of Y". Some relations are * bidirectional, like marriages. In these cases, the direction * is Relation::DIR_BOTH. * * @return Relation::DIR_FORWARD, Relation::DIR_BACKWARD, * or Relation::DIR_BOTH */ Direction getDirection() const; /** * Sets the reading direction. * * @param direction Relation::DIR_FORWARD, * Relation::DIR_BACKWARD, or Relation::DIR_BOTH * * @see getDirection */ void setDirection(const Direction direction); /** * Returns a list of attributes describing this relation. * * The attributes permitted depend on the relation type. * * @return a list of strings containing absolute URIs */ Attributes &getAttributes(); /** * Returns number of attributes. * * This is equivalent to \c getAttributes().size() * * @return an int containing number of attributes * * @see getAttributes */ int getNumAttributes() const; /** * Returns an attribute specified by index. * * This is equivalent to \c getAttributes()[index] * * @return a string containing the attribute * * @see getAttributes */ std::string getAttribute(int index) const; /** * Adds an attribute to the list. * * @param attribute a string containing an absolute URI */ void addAttribute(const std::string &attribute); /** * Returns this relation's target object. * * Note that URL relations never have a target object. Use the * getTargetId method to get the URL. * * @return a subclass of Entity, or NULL */ Entity *getTarget() const; /** * Sets this relation's target object. * * Note that URL relations never have a target object, they * are set using setTargetId. * * @param target a subclass of Entity, or NULL */ void setTarget(Entity *target); private: class RelationPrivate; RelationPrivate *d; }; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/results.h0000644000175000017500000000721210477236200021462 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: results.h 8466 2006-09-05 08:59:44Z luks $ */ #ifndef __MUSICBRAINZ3_RESULTS_H__ #define __MUSICBRAINZ3_RESULTS_H__ #include namespace MusicBrainz { /** * Represents generic search result. */ class MB_API Result { public: /** * Constructor. * * @param score an int between 0 and 100 (both inclusive) */ Result(int score); /** * Destructor. */ virtual ~Result() {}; /** * Returns the result score. * * The score indicates how good this result matches the search * parameters. The higher the value, the better the match. * * @return an int between 0 and 100 (both inclusive) */ int getScore(); /** * Sets the result score. * * @param score an int between 0 and 100 (both inclusive) */ void setScore(int score); private: int score; }; /** * Represents an artist result. * * An \a ArtistResult consists of a \a score and an \a artist. The score * is a number between 0 and 100, where a higher number indicates a better * match. */ class MB_API ArtistResult : public Result { public: /** * Constructor. */ ArtistResult(Artist *artist, int score); /** * Destructor. */ ~ArtistResult(); /** * Returns the artist. * * @return a pointer to an Artist object */ Artist *getArtist(); /** * Sets the artist. * * @param artist a pointer to an Artist object */ void setArtist(Artist *artist); private: Artist *artist; }; /** * Represents an release result. * * An \a ReleaseResult consists of a \a score and an \a release. The score * is a number between 0 and 100, where a higher number indicates a better * match. */ class MB_API ReleaseResult : public Result { public: /** * Constructor. */ ReleaseResult(Release *release, int score); /** * Destructor. */ ~ReleaseResult(); /** * Returns the release. * * @return a pointer to a Release object */ Release *getRelease(); /** * Sets the release. * * @param release a pointer to a Release object */ void setRelease(Release *release); private: Release *release; }; /** * Represents an track result. * * An \a TrackResult consists of a \a score and an \a track. The score * is a number between 0 and 100, where a higher number indicates a better * match. */ class MB_API TrackResult : public Result { public: /** * Constructor. */ TrackResult(Track *track, int score); /** * Destructor. */ ~TrackResult(); /** * Returns the track. * * @return a pointer to a Track object */ Track *getTrack(); /** * Sets the track. * * @param track a pointer to a Track object */ void setTrack(Track *track); private: Track *track; }; } #endif libmusicbrainz-3.0.2/include/musicbrainz3/lists.h0000644000175000017500000000515310640020535021113 0ustar lukaslukas/* * MusicBrainz -- The Internet music metadatabase * * Copyright (C) 2006 Lukas Lalinsky * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * $Id: lists.h 9218 2007-06-25 20:11:09Z luks $ */ #ifndef __MUSICBRAINZ3_LISTS_H__ #define __MUSICBRAINZ3_LISTS_H__ #include namespace MusicBrainz { class Artist; class ArtistAlias; class ArtistResult; class Disc; class Relation; class Release; class ReleaseEvent; class ReleaseResult; class Result; class Track; class TrackResult; class User; class Tag; class Label; class LabelAlias; //! A vector of pointers to Artist objects typedef std::vector ArtistList; //! A vector of pointers to ArtistAlias objects typedef std::vector ArtistAliasList; //! A vector of pointers to ArtistResult objects typedef std::vector ArtistResultList; //! A vector of pointers to Disc objects typedef std::vector DiscList; //! A vector of pointers to Relation objects typedef std::vector RelationList; //! A vector of pointers to Release objects typedef std::vector ReleaseList; //! A vector of pointers to ReleaseEvent objects typedef std::vector ReleaseEventList; //! A vector of pointers to ReleaseResult objects typedef std::vector ReleaseResultList; //! A vector of pointers to Result objects typedef std::vector ResultList; //! A vector of pointers to Track objects typedef std::vector TrackList; //! A vector of pointers to TrackResult objects typedef std::vector TrackResultList; //! A vector of pointers to User objects typedef std::vector UserList; //! A vector of pointers to Tag objects typedef std::vector TagList; //! A vector of pointers to Label objects typedef std::vector