pax_global_header00006660000000000000000000000064117550022220014506gustar00rootroot0000000000000052 comment=8f164c2a4aecf7a81ab94b63c121f7da77f4cd26 libmusicbrainz-5.0.1/000077500000000000000000000000001175500222200145265ustar00rootroot00000000000000libmusicbrainz-5.0.1/.gitignore000066400000000000000000000001701175500222200165140ustar00rootroot00000000000000CMakeCache.txt CMakeFiles/ Doxyfile Makefile cmake_install.cmake config.h libmusicbrainz5.pc docs/ install_manifest.txt libmusicbrainz-5.0.1/AUTHORS.txt000066400000000000000000000074521175500222200164240ustar00rootroot00000000000000Credits ======= The following people have contributed to libmusicbrainz5 Andy Hawkins - Update from libmusicbrainz4 The following people have contributed to libmusicbrainz4 Andy Hawkins - Created the C++ implementation (based on libmusicbrainz3) and the C bindings. - Updated examples Lukáš Lalinský - Advised on documentation and examples required. 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. -- libmusicbrainz-5.0.1/CMakeLists.txt000066400000000000000000000051261175500222200172720ustar00rootroot00000000000000cmake_minimum_required(VERSION 2.6) PROJECT(libmusicbrainz5) SET(PROJECT_VERSION 5.0.1) # 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(musicbrainz5_SOVERSION_CURRENT 0) SET(musicbrainz5_SOVERSION_REVISION 1) SET(musicbrainz5_SOVERSION_AGE 0) MATH(EXPR musicbrainz5_SOVERSION_MAJOR "${musicbrainz5_SOVERSION_CURRENT} - ${musicbrainz5_SOVERSION_AGE}") MATH(EXPR musicbrainz5_SOVERSION_MINOR "${musicbrainz5_SOVERSION_AGE}") MATH(EXPR musicbrainz5_SOVERSION_PATCH "${musicbrainz5_SOVERSION_REVISION}") SET(musicbrainz5_VERSION ${musicbrainz5_SOVERSION_MAJOR}.${musicbrainz5_SOVERSION_MINOR}.${musicbrainz5_SOVERSION_PATCH}) SET(musicbrainz5_SOVERSION ${musicbrainz5_SOVERSION_MAJOR}) SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) FIND_PACKAGE(Neon REQUIRED) 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}/libmusicbrainz5.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libmusicbrainz5.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/musicbrainz5/*.h) INSTALL(FILES ${headers} include/musicbrainz5/mb5_c.h DESTINATION ${INCLUDE_INSTALL_DIR}/musicbrainz5) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libmusicbrainz5.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(examples) ADD_CUSTOM_TARGET(docs doxygen ) ADD_DEPENDENCIES(docs src_gen) ADD_CUSTOM_TARGET(dist rm -rf "libmusicbrainz-${PROJECT_VERSION}" COMMAND git archive --prefix="libmusicbrainz-${PROJECT_VERSION}/" release-${PROJECT_VERSION} | gzip -9 > libmusicbrainz-${PROJECT_VERSION}.tar.gz ) libmusicbrainz-5.0.1/COPYING.txt000066400000000000000000000635041175500222200164070ustar00rootroot00000000000000 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-5.0.1/Doxyfile.cmake000066400000000000000000000011361175500222200173140ustar00rootroot00000000000000PROJECT_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/musicbrainz5 EXCLUDE = include/musicbrainz5/xmlParser.h 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 = LIBMB5_DEPRECATED(f)= REPEAT_BRIEF = NO libmusicbrainz-5.0.1/INSTALL.txt000066400000000000000000000020231175500222200163720ustar00rootroot00000000000000================================================ 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/ Building ======== Once you have installed all dependencies, you can compile the library: cmake . make 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 . To disable debug messages, change the build type: cmake -DCMAKE_BUILD_TYPE=Release . 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-5.0.1/NEWS.txt000066400000000000000000000226621175500222200160530ustar00rootroot00000000000000Changes for libmusicbrainz 5.0.1 -------------------------------- - Fix LMB-32 - Correctly ignore unrecognised nodes - Don't compile using -Werror when building from tarball Changes for libmusicbrainz 5.0.0 -------------------------------- - Deprecated functions removed Changes for libmusicbrainz 4.0.3 -------------------------------- - Fix LMB-32 - Correctly ignore unrecognised nodes - Don't compile using -Werror when building from tarball Changes for libmusicbrainz 4.0.2 -------------------------------- - Add extra attributes to Alias - Add IPI lists to Artist and Label - Add 'Ended' to Lifespan - Add PrimaryType and SecondaryTypeList to ReleaseGroup - Add text based track number to Track - Add ISWC list to Work - Debug builds show queries and responses on stderr - Documentation updates Changes for libmusicbrainz 4.0.1 -------------------------------- - Fixed bug LMB-30 - Unable to access all relation lists on objects with multiple relation lists - Fixed bug LMB-31 - mb_relationlist_get_targettype always returns "target-type" Changes for libmusicbrainz 4.0.0 -------------------------------- - Added support for collection list being returned as part of a release Changes for libmusicbrainz 4.0.0 beta 2 --------------------------------------- - Restructured for easier maintenance - List class interface rewritten - Added handling of extension elements and attributes - Add handling of all list attributes and elements - C interface is now automatically generated from an XML file template N.B. The API has changed with regard to lists since beta 1. Any applications are likely to need rewriting to take account of this and will certainly need to be recompiled due to the ABI change. Changes for libmusicbrainz 4.0.0 beta 1 --------------------------------------- - Rewritten from scratch for NGS Changes for libmusicbrainz 3.0.4 -------------------------------- - Fixed parsing of release-group lists. (#5891) - Fixed compilation on the Sun Studio compiler (#5801) - Added mb_disc_free() to the C bindings. (#5885) Changes for libmusicbrainz 3.0.3 -------------------------------- - Use Requires.private instead of Requires for dependencies in libmusicbrainz3.pc - Support for reading and submitting ISRCs - Support for reading ratings for all entity type - Full release group and label support - C wrappers for extractFragment and extractUuid - Support for filtering by any Lucene query Changes for libmusicbrainz 3.0.2 -------------------------------- - Added mb_track_get_artist to the C API. (#3817) - Fix incorrect string comparision in the XML parser code. (#3614) - Fix compilation on GCC 4.3 (#3490 and #3613, patch by Ross Burton and "dirtyepic") Changes for libmusicbrainz 3.0.1 -------------------------------- - Fixed mb_query_get_tracks function name in mb_c.h. - Detect correctly installed libdiscid in src/disc.cpp. - Support for releaseEvents in ArtistIncludes. (#2974) - Support for catalog numbers and barcodes. - Added Release::TYPE_PSEUDO_RELEASE. - Added mb_release_get_artist to the C API, patch by Ross Burton. Changes for libmusicbrainz 3.0.0 (2007-05-12) --------------------------------------------- - Use CMake as the only build system. Changes for libmusicbrainz 3.0.0beta3 ------------------------------------- - C bindings for artist/release/track collections. - New cdlookup_c.c example. Changes for libmusicbrainz 3.0.0beta2 ------------------------------------- - Fixed MusicBrainz::extractUuid for non-artist IDs. - Implementation of release types. - Implementation of release lists on track level. - New cdlookup.cpp example. Changes for libmusicbrainz 3.0.0beta1 ------------------------------------- - Rewritten from scratch, libmusicbrainz now uses the new XML web service. - New object oriented API in C++ based on python-musicbrainz2, with GLib-style C bindings. ****************************************************************************** ****************************************************************************** ****************************************************************************** Changes for libmusicbrainz 2.1.2 ------------------------------------- - Since expat is now installed on most systems we removed our internal copy and now rely on the system installed version. - Juergen Kreileder Supplied minimal patch for making sure that mb_client still works when CDO_CHECK_TYPE is defined - Fixed a C++ style variable declaration inside the album.c C module - On linux the cdrom drive is now opened in non-blocking mode - Fixed bug #834541: Tagger setting track no. is 0 - possibly due to trm mixup? - Added support for parsing AdvancedRelationship date. Also added new getrels.c example program. - Re-added the python bindings and changed the binding's version number to match the version of this lib. - Fixed bug # 1224562: libmusicbrainz fails to post large RDF. This fixes problems looking up CDs with large numbers of tracks. (This was also bug # 725701 ignores blank tracks) The included perl bindings had the following changes: - Updated bindings to match up to 2.1.1 - Fixed int size cast warning - Fixed #6431: unmatched bootstrap parameter - Updated req for MusicBrainz::Queries to 0.07 The included python bindings had the following changes: - Fixed #957393: Python Bindings type bug - Fixed #1206514: Python bindings to select release not up-to-date Changes for libmusicbrainz 2.1.1 ------------------------------------- - Return special TRMs for special conditions for TRM generation: c457a4a8-b342-4ec9-8f13-b6bd26c0e400 -- Sigserver busy and overloaded f9809ab1-2b0f-4d78-8862-fb425ade8ab9 -- Source file is too short to calculate TRM 7d154f52-b536-4fae-b58b-0666826c2bac -- File is slience - If the TRM signature server becomes overloaded, it will now start returning HTTP 503 error codes and the TRM generator will catch that and return the Sigserver busy TRM shown above. Changes for libmusicbrainz 2.1.0 ------------------------------------- - moved the python bindings into a new seperate project - rewrote the mp3 duration detection code to be more robust by making it vastly easier. In the process the bitzi related code has been tossed. This should make the libary smaller and the mp3 duration checking faster. - Due to the bitzi code being removed, the SHA1 and Bitprint related functions have been removed. - Added query items for Release Dates/Countries, Amazon Asins and Amazon cover art URLs - Move include files into include/musicbrainz so that the example files will compile outside of the libmusicbrainz client source tree. Changes for libmusicbrainz 2.0.2 ------------------------------------- - Added support for Mac OS X - Improved build system - Added build files for Visual Studio .NET (VC7) Changes for libmusicbrainz 2.0.1 ------------------------------------- - Added patch for pkgconfig - Threading handled correctly in python wrapper - New perl bindings - Had client use HTTP 1.0 rather than HTTP 1.1 Changes for libmusicbrainz 2.0.0 ------------------------------------- - Removed some spurious C++ comments from mb_c.h - Fixes and improvements to the python language bindings and tools - Updated NetBSD cdrom reading code Changes for libmusicbrainz 2.0.0-pre4 ------------------------------------- - Two new functions have been added: mb_GetFragmentFromURL - Retrieve a fragment from a URI mb_GetOrdinalFromList - Retrieve a list ordinal from a given list -- this is sometimes needed to determine the location of an item in a list. (e.g. a track in an album in order to find the track number) - The TRM code has been updated for TRM B#er. - New queries have been added to queries.h in order to support the improved FileLookupInterface. - The client library now uses the mm-2.1 and mq-1.1 namespaces. - The client library will now be referred to as libmusicbrainz Changes from version 1.1.0 to version 2.0.0-pre1 ------------------------------------------------ - Added authentication support - Added new queries - Added support for submitting client version to the server during TRM submits - Updated client code for TRM B#er Changes from version 1.0.1 to version 1.1.0 ------------------------------------------- - Fixed an OpenBSD 3.0 compile problem - Updated libtool version to 1.4.2 in hopes to get it to build on OSX. - Added MBQ_Quick queries to support the MB Tagger - Fixed a bug in the TRM generation that caused different TRMs to be generated for subsequent runs on the same file. Changes from version 1.0.0 to version 1.0.1 ------------------------------------------- - Fixed the multi drive support under windows. - Added support for setting the depth of a query via GET methods. - Added SetDebug() function that allows the caller to set the debug mode. In debug mode the library will print the server URL, query and responses to stdout. - Fixed a few crash bugs in the bitzi id3/mp3 metadata code - Changed the bitzi plugin manager to not load plugins, in order to avoid the unecessary dependency on dlopen/dlsym/dlclose. - Removed a bunch of generates files from the CVS archive. libmusicbrainz-5.0.1/README.md000066400000000000000000000024361175500222200160120ustar00rootroot00000000000000============================ MusicBrainz Client Library ============================ Documentation ------------- To get started quickly have a look at the examples directory which contains various sample programs. API documentation can be generated using [Doxygen] (http://www.stack.nl/~dimitri/doxygen/). The online version of the API documentation can be found at: http://metabrainz.github.com/libmusicbrainz/ Compiling and Linking --------------------- This package provides a pkg-config script that returns the necessary compiler and linker flags, as well as the version number. To build a small sample program one would use: g++ -o test_app test_app.cpp `pkg-config libmusicbrainz5 --cflags --libs` If you don't want/can't use pkg-config and you are using the C API, make sure you link in the C++ standard library: gcc -o test_app test_app.c -lmusicbrainz5 -lm -lstdc++ Contact ------- If you have any questions about this library, feel free to ask on the MusicBrainz development mailing list: http://lists.musicbrainz.org/mailman/listinfo/musicbrainz-devel Please submit bug reports to the MusicBrainz bug tracking system: http://tickets.musicbrainz.org/browse/LMB You can find out more about the MusicBrainz project by visiting its site: http://musicbrainz.org/ libmusicbrainz-5.0.1/cmake/000077500000000000000000000000001175500222200156065ustar00rootroot00000000000000libmusicbrainz-5.0.1/cmake/modules/000077500000000000000000000000001175500222200172565ustar00rootroot00000000000000libmusicbrainz-5.0.1/cmake/modules/FindNeon.cmake000066400000000000000000000006471175500222200217670ustar00rootroot00000000000000INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE(PkgConfig) PKG_CHECK_MODULES(PKG_NEON neon) FIND_PATH(NEON_INCLUDE_DIR ne_request.h PATHS ${PKG_NEON_INCLUDE_DIRS} /usr/include /usr/local/include PATH_SUFFIXES neon ) FIND_LIBRARY(NEON_LIBRARIES neon ${PKG_NEON_LIBRARY_DIRS} /usr/lib /usr/local/lib ) FIND_PACKAGE_HANDLE_STANDARD_ARGS(Neon DEFAULT_MSG NEON_LIBRARIES NEON_INCLUDE_DIR) libmusicbrainz-5.0.1/config.h.cmake000066400000000000000000000001721175500222200172230ustar00rootroot00000000000000#ifndef __CONFIG_H__ #define __CONFIG_H__ #define PACKAGE "${PROJECT_NAME}" #define VERSION "${PROJECT_VERSION}" #endif libmusicbrainz-5.0.1/examples/000077500000000000000000000000001175500222200163445ustar00rootroot00000000000000libmusicbrainz-5.0.1/examples/.gitignore000066400000000000000000000001311175500222200203270ustar00rootroot00000000000000CMakeFiles/ Makefile cdlookup cdlookup_c cmake_install.cmake collections search search_c libmusicbrainz-5.0.1/examples/CMakeLists.txt000066400000000000000000000015461175500222200211120ustar00rootroot00000000000000INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../include) LINK_LIBRARIES(musicbrainz5 ${NEON_LIBRARIES}) ADD_EXECUTABLE(cdlookup cdlookup.cc) ADD_EXECUTABLE(cdlookup_c cdlookup_c.c) ADD_EXECUTABLE(search search.cc) ADD_EXECUTABLE(search_c search_c.c) ADD_EXECUTABLE(collections collections.cc) IF(CMAKE_COMPILER_IS_GNUCXX) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic-errors") IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) ENDIF(CMAKE_COMPILER_IS_GNUCXX) IF(CMAKE_COMPILER_IS_GNUCC) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic-errors") IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) ENDIF(CMAKE_COMPILER_IS_GNUCC) libmusicbrainz-5.0.1/examples/cdlookup.cc000066400000000000000000000137251175500222200205030ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include #include "musicbrainz5/Query.h" #include "musicbrainz5/Medium.h" #include "musicbrainz5/MediumList.h" #include "musicbrainz5/ReleaseGroup.h" #include "musicbrainz5/Track.h" #include "musicbrainz5/TrackList.h" #include "musicbrainz5/Recording.h" #include "musicbrainz5/Disc.h" #include "musicbrainz5/HTTPFetch.h" #include "musicbrainz5/Release.h" int main(int argc, const char *argv[]) { if (argc==2) { std::string DiscID=argv[1]; MusicBrainz5::CQuery Query("cdlookupexample-1.0"); std::cout << "Library version: '" << Query.Version() << "'" << std::endl; try { MusicBrainz5::CMetadata Metadata=Query.Query("discid",DiscID); if (Metadata.Disc() && Metadata.Disc()->ReleaseList()) { MusicBrainz5::CReleaseList *ReleaseList=Metadata.Disc()->ReleaseList(); std::cout << "Found " << ReleaseList->NumItems() << " release(s)" << std::endl; for (int count=0;countNumItems();count++) { MusicBrainz5::CRelease *Release=ReleaseList->Item(count); std::cout << "Basic release: " << std::endl << (*Release) << std::endl; //The releases returned from LookupDiscID don't contain full information MusicBrainz5::CQuery::tParamMap Params; Params["inc"]="artists labels recordings release-groups url-rels discids artist-credits"; std::string ReleaseID=Release->ID(); MusicBrainz5::CMetadata Metadata2=Query.Query("release",ReleaseID,"",Params); if (Metadata2.Release()) { MusicBrainz5::CRelease *FullRelease=Metadata2.Release(); //However, these releases will include information for all media in the release //So we need to filter out the only the media we want. MusicBrainz5::CMediumList MediaList=FullRelease->MediaMatchingDiscID(DiscID); if (0!=MediaList.NumItems()) { if (FullRelease->ReleaseGroup()) std::cout << "Release group title: '" << FullRelease->ReleaseGroup()->Title() << "'" << std::endl; else std::cout << "No release group for this release" << std::endl; std::cout << "Found " << MediaList.NumItems() << " media item(s)" << std::endl; for (int count=0;countTitle() << "', position " << Medium->Position() << std::endl; MusicBrainz5::CTrackList *TrackList=Medium->TrackList(); if (TrackList) { for (int count=0;countNumItems();count++) { MusicBrainz5::CTrack *Track=TrackList->Item(count); MusicBrainz5::CRecording *Recording=Track->Recording(); if (Recording) std::cout << "Track: " << Track->Position() << " - '" << Recording->Title() << "'" << std::endl; else std::cout << "Track: " << Track->Position() << " - '" << Track->Title() << "'" << std::endl; } } } } } } } } catch (MusicBrainz5::CConnectionError& Error) { std::cout << "Connection Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CTimeoutError& Error) { std::cout << "Timeout Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CAuthenticationError& Error) { std::cout << "Authentication Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CFetchError& Error) { std::cout << "Fetch Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CRequestError& Error) { std::cout << "Request Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CResourceNotFoundError& Error) { std::cout << "ResourceNotFound Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } } else { std::cerr << "Usage: " << argv[0] << " discid" << std::endl; } return 0; } libmusicbrainz-5.0.1/examples/cdlookup_c.c000066400000000000000000000162421175500222200206370ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id: Lifespan.cc 13211 2012-07-20 16:15:03Z adhawkins $ ----------------------------------------------------------------------------*/ #include #include #include #include "musicbrainz5/mb5_c.h" int main(int argc, const char *argv[]) { if (argc==2) { const char *DiscID=argv[1]; Mb5Query Query=mb5_query_new("cdlookupcexample-1.0",NULL,0); if (Query) { Mb5Metadata Metadata1=mb5_query_query(Query,"discid",DiscID,"",0,NULL,NULL); char ErrorMessage[256]; tQueryResult Result=mb5_query_get_lastresult(Query); int HTTPCode=mb5_query_get_lasthttpcode(Query); mb5_query_get_lasterrormessage(Query,ErrorMessage,sizeof(ErrorMessage)); printf("Result: %d\nHTTPCode: %d\nErrorMessage: '%s'\n",Result,HTTPCode,ErrorMessage); if (Metadata1) { Mb5Disc Disc=mb5_metadata_get_disc(Metadata1); if (Disc) { Mb5ReleaseList ReleaseList=mb5_disc_get_releaselist(Disc); if (ReleaseList) { /* *if we want to keep an object around for a while, we can *clone it. We are now responsible for deleting the object */ Mb5ReleaseList CloneReleaseList=mb5_release_list_clone(ReleaseList); int ThisRelease=0; printf("Found %d release(s)\n",mb5_release_list_size(ReleaseList)); for (ThisRelease=0;ThisReleaseAllocSize) { MediumTitle=realloc(MediumTitle,RequiredSize+1); mb5_medium_get_title(Medium,MediumTitle,RequiredSize+1); } printf("Found media: '%s', position %d\n",MediumTitle,mb5_medium_get_position(Medium)); if (TrackList) { int ThisTrack=0; for (ThisTrack=0;ThisTrack. $Id$ ----------------------------------------------------------------------------*/ #include #include "musicbrainz5/Query.h" #include "musicbrainz5/Collection.h" #include "musicbrainz5/CollectionList.h" #include "musicbrainz5/HTTPFetch.h" void ListCollection(MusicBrainz5::CQuery& Query, const std::string& CollectionID) { MusicBrainz5::CMetadata Metadata=Query.Query("collection",CollectionID,"releases"); std::cout << Metadata << std::endl; } int main(int argc, const char *argv[]) { MusicBrainz5::CQuery Query("collectionexample-1.0","test.musicbrainz.org"); if (argc>1) { if (argc>1) Query.SetUserName(argv[1]); if (argc>2) Query.SetPassword(argv[2]); try { MusicBrainz5::CMetadata Metadata=Query.Query("collection"); MusicBrainz5::CCollectionList *CollectionList=Metadata.CollectionList(); if (CollectionList) { if (0!=CollectionList->NumItems()) { MusicBrainz5::CCollection *Collection=CollectionList->Item(0); std::cout << "Collection ID is " << Collection->ID() << std::endl; ListCollection(Query,Collection->ID()); std::vector Releases; Releases.push_back("b5748ac9-f38e-48f7-a8a4-8b43cab025bc"); Releases.push_back("f6335672-c521-4129-86c3-490d20533e08"); bool Ret=Query.AddCollectionEntries(Collection->ID(),Releases); std::cout << "AddCollectionEntries returns " << std::boolalpha << Ret << std::endl; ListCollection(Query,Collection->ID()); Releases.clear(); Releases.push_back("b5748ac9-f38e-48f7-a8a4-8b43cab025bc"); Ret=Query.DeleteCollectionEntries(Collection->ID(),Releases); std::cout << "DeleteCollectionEntries returns " << std::boolalpha << Ret << std::endl; ListCollection(Query,Collection->ID()); } else std::cout << "No collections found" << std::endl; } } catch (MusicBrainz5::CConnectionError& Error) { std::cout << "Connection Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CTimeoutError& Error) { std::cout << "Timeout Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CAuthenticationError& Error) { std::cout << "Authentication Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CFetchError& Error) { std::cout << "Fetch Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CRequestError& Error) { std::cout << "Request Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CResourceNotFoundError& Error) { std::cout << "ResourceNotFound Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } } else { std::cout << "Usage: " << argv[0] << " username [password]" << std::endl << std::endl << "Note that this example uses test.musicbrainz.org by default." << std::endl << "You may need to create an account there." << std::endl; } return 0; } libmusicbrainz-5.0.1/examples/search.cc000066400000000000000000000075271175500222200201330ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include #include "musicbrainz5/Query.h" #include "musicbrainz5/HTTPFetch.h" /* For further information, see the web service search documentation: * * http://wiki.musicbrainz.org/Text_Search_Syntax */ void DoSearch(const std::string& Entity, const std::string Search) { MusicBrainz5::CQuery Query("queryexample-1.0"); MusicBrainz5::CQuery::tParamMap Params; Params["query"]=Search; Params["limit"]="10"; try { MusicBrainz5::CMetadata Metadata=Query.Query(Entity,"","",Params); std::cout << "First 10 " << Entity << "s matching: " << Search << std::endl << Metadata << std::endl; } catch (MusicBrainz5::CConnectionError& Error) { std::cout << "Connection Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CTimeoutError& Error) { std::cout << "Timeout Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CAuthenticationError& Error) { std::cout << "Authentication Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CFetchError& Error) { std::cout << "Fetch Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CRequestError& Error) { std::cout << "Request Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CResourceNotFoundError& Error) { std::cout << "ResourceNotFound Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } } int main(int argc, const char *argv[]) { argc=argc; argv=argv; //Search for all releases by Kate Bush DoSearch("release","artist:\"Kate Bush\""); //Search for all releases with 'sensual' in the title DoSearch("release","release:sensual"); //Search for all artists with 'john' in the name DoSearch("artist","artist:john"); } libmusicbrainz-5.0.1/examples/search_c.c000066400000000000000000000070031175500222200202570ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id: Lifespan.cc 13211 2012-07-20 16:15:03Z adhawkins $ ----------------------------------------------------------------------------*/ #include #include #include #include "musicbrainz5/mb5_c.h" int main(int argc, const char *argv[]) { Mb5Query Query; argc=argc; argv=argv; Query=mb5_query_new("searchcexample-1.0",NULL,0); if (Query) { char **ParamNames; char **ParamValues; Mb5Metadata Metadata; char ErrorMessage[256]; tQueryResult Result; int HTTPCode; ParamNames=malloc(2*sizeof(char *)); ParamNames[0]=malloc(256); ParamNames[1]=malloc(256); ParamValues=malloc(2*sizeof(char *)); ParamValues[0]=malloc(256); ParamValues[1]=malloc(256); strcpy(ParamNames[0],"query"); strcpy(ParamValues[0],"artist:john"); strcpy(ParamNames[1],"limit"); strcpy(ParamValues[1],"10"); Metadata=mb5_query_query(Query,"artist","","",2,ParamNames,ParamValues); Result=mb5_query_get_lastresult(Query); HTTPCode=mb5_query_get_lasthttpcode(Query); mb5_query_get_lasterrormessage(Query,ErrorMessage,sizeof(ErrorMessage)); printf("Result: %d\nHTTPCode: %d\nErrorMessage: '%s'\n",Result,HTTPCode,ErrorMessage); if (Metadata) { int ThisArtist; Mb5ArtistList ArtistList=mb5_metadata_get_artistlist(Metadata); printf("Found %d artist(s)\n",mb5_artist_list_size(ArtistList)); for (ThisArtist=0;ThisArtist. $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ALIAS_H #define _MUSICBRAINZ5_ALIAS_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CAliasPrivate; class CAlias: public CEntity { public: CAlias(const XMLNode& Node); CAlias(const CAlias& Other); CAlias& operator =(const CAlias& Other); virtual ~CAlias(); virtual CAlias *Clone(); std::string Locale() const; std::string Text() const; std::string SortName() const; std::string Type() const; std::string Primary() const; std::string BeginDate() const; std::string EndDate() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CAliasPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/AliasList.h000066400000000000000000000021111175500222200226150ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ALIAS_LIST_H #define _MUSICBRAINZ5_ALIAS_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CAlias; typedef CListImpl CAliasList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Annotation.h000066400000000000000000000033741175500222200230560ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ANNOTATION_H #define _MUSICBRAINZ5_ANNOTATION_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CAnnotationPrivate; class CAnnotation: public CEntity { public: CAnnotation(const XMLNode& Node); CAnnotation(const CAnnotation& Other); CAnnotation& operator =(const CAnnotation& Other); virtual ~CAnnotation(); virtual CAnnotation *Clone(); std::string Type() const; std::string Entity() const; std::string Name() const; std::string Text() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CAnnotationPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/AnnotationList.h000066400000000000000000000021421175500222200237020ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ANNOTATION_LIST_H #define _MUSICBRAINZ5_ANNOTATION_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CAnnotation; typedef CListImpl CAnnotationList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Artist.h000066400000000000000000000053131175500222200222050ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ARTIST_H #define _MUSICBRAINZ5_ARTIST_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/IPIList.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/AliasList.h" #include "musicbrainz5/RecordingList.h" #include "musicbrainz5/ReleaseGroupList.h" #include "musicbrainz5/LabelList.h" #include "musicbrainz5/WorkList.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/TagList.h" #include "musicbrainz5/UserTagList.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CArtistPrivate; class CLifespan; class CRating; class CUserRating; class CArtist: public CEntity { public: CArtist(const XMLNode& Node=XMLNode::emptyNode()); CArtist(const CArtist& Other); CArtist& operator =(const CArtist& Other); virtual ~CArtist(); virtual CArtist *Clone(); std::string ID() const; std::string Type() const; std::string Name() const; std::string SortName() const; std::string Gender() const; std::string Country() const; std::string Disambiguation() const; CIPIList *IPIList() const; CLifespan *Lifespan() const; CAliasList *AliasList() const; CRecordingList *RecordingList() const; CReleaseList *ReleaseList() const; CReleaseGroupList *ReleaseGroupList() const; CLabelList *LabelList() const; CWorkList *WorkList() const; CRelationListList *RelationListList() const; CTagList *TagList() const; CUserTagList *UserTagList() const; CRating *Rating() const; CUserRating *UserRating() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CArtistPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/ArtistCredit.h000066400000000000000000000034161175500222200233420ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ARTIST_CREDIT_H #define _MUSICBRAINZ5_ARTIST_CREDIT_H #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/NameCreditList.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CArtistCreditPrivate; class CArtistCredit: public CEntity { public: CArtistCredit(const XMLNode& Node=XMLNode::emptyNode()); CArtistCredit(const CArtistCredit& Other); CArtistCredit& operator =(const CArtistCredit& Other); virtual ~CArtistCredit(); virtual CArtistCredit *Clone(); CNameCreditList *NameCreditList() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CArtistCreditPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/ArtistList.h000066400000000000000000000021161175500222200230370ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ARTIST_LIST_H #define _MUSICBRAINZ5_ARTIST_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CArtist; typedef CListImpl CArtistList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Attribute.h000066400000000000000000000032571175500222200227070ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ATTRIBUTE_H #define _MUSICBRAINZ5_ATTRIBUTE_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CAttributePrivate; class CAttribute: public CEntity { public: CAttribute(const XMLNode& Node=XMLNode::emptyNode()); CAttribute(const CAttribute& Other); CAttribute& operator =(const CAttribute& Other); virtual ~CAttribute(); virtual CAttribute *Clone(); std::string Text() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CAttributePrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/AttributeList.h000066400000000000000000000021351175500222200235350ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ATTRIBUTE_LIST_H #define _MUSICBRAINZ5_ATTRIBUTE_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CAttribute; typedef CListImpl CAttributeList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/CDStub.h000066400000000000000000000035241175500222200220650ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_CDSTUB_H #define _MUSICBRAINZ5_CDSTUB_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/NonMBTrackList.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CCDStubPrivate; class CCDStub: public CEntity { public: CCDStub(const XMLNode& Node); CCDStub(const CCDStub& Other); CCDStub& operator =(const CCDStub& Other); virtual ~CCDStub(); virtual CCDStub *Clone(); std::string ID() const; std::string Title() const; std::string Artist() const; std::string Barcode() const; std::string Comment() const; CNonMBTrackList *NonMBTrackList() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CCDStubPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/CDStubList.h000066400000000000000000000021161175500222200227150ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_CDSTUB_LIST_H #define _MUSICBRAINZ5_CDSTUB_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CCDStub; typedef CListImpl CCDStubList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Collection.h000066400000000000000000000034251175500222200230340ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_COLLECTION_H #define _MUSICBRAINZ5_COLLECTION_H #include "musicbrainz5/Entity.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CCollectionPrivate; class CCollection: public CEntity { public: CCollection(const XMLNode& Node); CCollection(const CCollection& Other); CCollection& operator =(const CCollection& Other); virtual ~CCollection(); virtual CCollection *Clone(); std::string ID() const; std::string Name() const; std::string Editor() const; CReleaseList *ReleaseList() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CCollectionPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/CollectionList.h000066400000000000000000000021421175500222200236630ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_COLLECTION_LIST_H #define _MUSICBRAINZ5_COLLECTION_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CCollection; typedef CListImpl CCollectionList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Disc.h000066400000000000000000000034121175500222200216170ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_DISC_H #define _MUSICBRAINZ5_DISC_H #include "musicbrainz5/Entity.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/Lifespan.h" #include #include #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CDiscPrivate; class CDisc: public CEntity { public: CDisc(const XMLNode& Node=XMLNode::emptyNode()); CDisc(const CDisc& Other); CDisc& operator =(const CDisc& Other); virtual ~CDisc(); virtual CDisc *Clone(); std::string ID() const; int Sectors() const; CReleaseList *ReleaseList() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CDiscPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/DiscList.h000066400000000000000000000021041175500222200224500ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_DISC_LIST_H #define _MUSICBRAINZ5_DISC_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CDisc; typedef CListImpl CDiscList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Entity.h000066400000000000000000000053231175500222200222140ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ENTITY_H #define _MUSICBRAINZ5_ENTITY_H #include #include #include #include #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CEntityPrivate; class CRelationListList; class CEntity { public: CEntity(); CEntity(const CEntity& Other); CEntity& operator =(const CEntity& Other); virtual ~CEntity(); virtual CEntity *Clone()=0; void Parse(const XMLNode& Node); std::map ExtAttributes() const; std::map ExtElements() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: void ProcessRelationList(const XMLNode& Node, CRelationListList* & RetVal); template void ProcessItem(const XMLNode& Node, T* & RetVal) { RetVal=new T(Node); } template void ProcessItem(const XMLNode& Node, T& RetVal) { std::stringstream os; if (Node.getText()) os << (const char *)Node.getText(); os >> RetVal; if (os.fail()) { std::cerr << "Error parsing value '"; if (Node.getText()) std::cerr << Node.getText(); std::cerr << "'" << std::endl; } } template void ProcessItem(const std::string& Text, T& RetVal) { std::stringstream os; os << Text; os >> RetVal; if (os.fail()) { std::cerr << "Error parsing value '" << Text << "'" << std::endl; } } void ProcessItem(const XMLNode& Node, std::string& RetVal) { if (Node.getText()) RetVal=Node.getText(); } virtual void ParseAttribute(const std::string& Name, const std::string& Value)=0; virtual void ParseElement(const XMLNode& Node)=0; private: CEntityPrivate *m_d; void Cleanup(); }; } std::ostream& operator << (std::ostream& os, const MusicBrainz5::CEntity& Entity); #endif libmusicbrainz-5.0.1/include/musicbrainz5/FreeDBDisc.h000066400000000000000000000036041175500222200226320ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_FREEDB_DISC_H #define _MUSICBRAINZ5_FREEDB_DISC_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/NonMBTrackList.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CFreeDBDiscPrivate; class CFreeDBDisc: public CEntity { public: CFreeDBDisc(const XMLNode& Node); CFreeDBDisc(const CFreeDBDisc& Other); CFreeDBDisc& operator =(const CFreeDBDisc& Other); virtual ~CFreeDBDisc(); virtual CFreeDBDisc *Clone(); std::string ID() const; std::string Title() const; std::string Artist() const; std::string Category() const; std::string Year() const; CNonMBTrackList *NonMBTrackList() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CFreeDBDiscPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/FreeDBDiscList.h000066400000000000000000000021421175500222200234620ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_FREEDBDISC_LIST_H #define _MUSICBRAINZ5_FREEDBDISC_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CFreeDBDisc; typedef CListImpl CFreeDBDiscList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/HTTPFetch.h000066400000000000000000000147661175500222200225040ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_HTTP_FETCH_ #define _MUSICBRAINZ5_HTTP_FETCH_ #include #include namespace MusicBrainz5 { class CHTTPFetchPrivate; class CExceptionBase: public std::exception { public: CExceptionBase(const std::string& ErrorMessage, const std::string& Exception) : m_ErrorMessage(ErrorMessage), m_Exception(Exception) { m_FullMessage=m_Exception + ": " + m_ErrorMessage; } virtual ~CExceptionBase() throw() {}; virtual const char* what() const throw() { return m_FullMessage.c_str(); } private: std::string m_ErrorMessage; std::string m_Exception; std::string m_FullMessage; }; /** * Exception thrown when an error occurs connecting to web service */ class CConnectionError: public CExceptionBase { public: CConnectionError(const std::string& ErrorMessage) : CExceptionBase(ErrorMessage,"Connection error") { } }; /** * Exception thrown when a connection to the web service times out */ class CTimeoutError: public CExceptionBase { public: CTimeoutError(const std::string& ErrorMessage) : CExceptionBase(ErrorMessage,"Timeout error") { } }; /** * Exception thrown when an authentication error occurs */ class CAuthenticationError: public CExceptionBase { public: CAuthenticationError(const std::string& ErrorMessage) : CExceptionBase(ErrorMessage,"Authentication error") { } }; /** * Exception thrown when an error occurs fetching data */ class CFetchError: public CExceptionBase { public: CFetchError(const std::string& ErrorMessage) : CExceptionBase(ErrorMessage,"Fetch error") { } }; /** * Exception thrown when an invalid request is made */ class CRequestError: public CExceptionBase { public: CRequestError(const std::string& ErrorMessage) : CExceptionBase(ErrorMessage,"Request error") { } }; /** * Exception thrown when the requested resource is not found */ class CResourceNotFoundError: public CExceptionBase { public: CResourceNotFoundError(const std::string& ErrorMessage) : CExceptionBase(ErrorMessage,"Resource not found error") { } }; /** * @brief Object for make HTTP requests * * Object to be used to make HTTP requests * */ class CHTTPFetch { public: /** * @brief Constructor * * Constructor * * @param UserAgent User agent string to send * @param Host Host name to connect to * @param Port Port to connect to (80 by default) */ CHTTPFetch(const std::string& UserAgent, const std::string& Host, int Port=80); ~CHTTPFetch(); /** * @brief Set the user name to use * * Set the user name to use when authenticating with the web server * * @param UserName User name to use */ void SetUserName(const std::string& UserName); /** * @brief Set the password to use * * Set the password to use when authenticating with the web server * * @param Password Password to use */ void SetPassword(const std::string& Password); /** * @brief Set the proxy server to use * * Set the proxy server to use when connecting with the web server * * @param ProxyHost Proxy server to use */ void SetProxyHost(const std::string& ProxyHost); /** * @brief Set the proxy port to use * * Set the proxy server port to use when connecting to the web server * * @param ProxyPort Proxy server port to use */ void SetProxyPort(int ProxyPort); /** * @brief Set the proxy user name to use * * Set the user name to use when authenticating with the proxy server * * @param ProxyUserName Proxy user name to use */ void SetProxyUserName(const std::string& ProxyUserName); /** * @brief Set the proxy password to use * * Set the password to use when authenticating with the proxy server * * @param ProxyPassword Proxy server password to use */ void SetProxyPassword(const std::string& ProxyPassword); /** * @brief Make a request to the server * * Make a request to the server * * @param URL URL to request * @param Request Request type (GET by default) * * @return Number of bytes received * * @throw CConnectionError An error occurred connecting to the web server * @throw CTimeoutError A timeout occurred when connecting to the web server * @throw CAuthenticationError An authentication error occurred * @throw CFetchError An error occurred fetching data * @throw CRequestError The request was invalid * @throw CResourceNotFoundError The requested resource was not found */ int Fetch(const std::string& URL, const std::string& Request="GET"); /** * @brief Get the data receieved * * Get the data received from the request * * @return Data received */ std::vector Data() const; /** * @brief libneon result code from the request * * Return the result code from the request * * @return libneon result code from the request */ int Result() const; /** * @brief Status * * Return the HTTP status code from the request * * @return HTTP status code from the request */ int Status() const; /** * @brief Return the error message from the request * * Return the error message from the request * * @return Error message from the request */ std::string ErrorMessage() const; private: CHTTPFetchPrivate * const m_d; static int httpAuth(void *userdata, const char *realm, int attempts, char *username, char *password); static int proxyAuth(void *userdata, const char *realm, int attempts, char *username, char *password); static int httpResponseReader(void *userdata, const char *buf, size_t len); }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/IPI.h000066400000000000000000000031461175500222200213620ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_IPI_H #define _MUSICBRAINZ5_IPI_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CIPIPrivate; class CIPI: public CEntity { public: CIPI(const XMLNode& Node=XMLNode::emptyNode()); CIPI(const CIPI& Other); CIPI& operator =(const CIPI& Other); virtual ~CIPI(); virtual CIPI *Clone(); std::string IPI() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CIPIPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/IPIList.h000066400000000000000000000020771175500222200222200ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_IPI_LIST_H #define _MUSICBRAINZ5_IPI_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CIPI; typedef CListImpl CIPIList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/ISRC.h000066400000000000000000000032561175500222200215030ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ISRC_H #define _MUSICBRAINZ5_ISRC_H #include "musicbrainz5/Entity.h" #include "musicbrainz5/RecordingList.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CISRCPrivate; class CISRC: public CEntity { public: CISRC(const XMLNode& Node=XMLNode::emptyNode()); CISRC(const CISRC& Other); CISRC& operator =(const CISRC& Other); virtual ~CISRC(); virtual CISRC *Clone(); std::string ID() const; CRecordingList *RecordingList() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CISRCPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/ISRCList.h000066400000000000000000000021041175500222200223260ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ISRC_LIST_H #define _MUSICBRAINZ5_ISRC_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CISRC; typedef CListImpl CISRCList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/ISWC.h000066400000000000000000000032061175500222200215030ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ISWC_H #define _MUSICBRAINZ5_ISWC_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CISWCPrivate; class CISWC: public CEntity { public: CISWC(const XMLNode& Node=XMLNode::emptyNode()); CISWC(const CISWC& Other); CISWC& operator =(const CISWC& Other); virtual ~CISWC(); virtual CISWC *Clone(); std::string ISWC() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CISWCPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/ISWCList.h000066400000000000000000000032411175500222200223360ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_ISWC_LIST_H #define _MUSICBRAINZ5_ISWC_LIST_H #include #include #include "musicbrainz5/ListImpl.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CISWC; class CISWCListPrivate; class CISWCList: public CListImpl { public: CISWCList(const XMLNode& Node=XMLNode::emptyNode()); CISWCList(const CISWCList& Other); CISWCList& operator =(const CISWCList& Other); virtual ~CISWCList(); virtual CISWCList *Clone(); virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CISWCListPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Label.h000066400000000000000000000046111175500222200217560ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_LABEL_H #define _MUSICBRAINZ5_LABEL_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/IPIList.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/AliasList.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/TagList.h" #include "musicbrainz5/UserTagList.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CLabelPrivate; class CLifespan; class CRating; class CUserRating; class CLabel: public CEntity { public: CLabel(const XMLNode& Node=XMLNode::emptyNode()); CLabel(const CLabel& Other); CLabel& operator =(const CLabel& Other); virtual ~CLabel(); virtual CLabel *Clone(); std::string ID() const; std::string Type() const; std::string Name() const; std::string SortName() const; int LabelCode() const; CIPIList *IPIList() const; std::string Disambiguation() const; std::string Country() const; CLifespan *Lifespan() const; CAliasList *AliasList() const; CReleaseList *ReleaseList() const; CRelationListList *RelationListList() const; CTagList *TagList() const; CUserTagList *UserTagList() const; CRating *Rating() const; CUserRating *UserRating() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CLabelPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/LabelInfo.h000066400000000000000000000033671175500222200226010ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_LABEL_INFO_H #define _MUSICBRAINZ5_LABEL_INFO_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CLabelInfoPrivate; class CLabel; class CLabelInfo: public CEntity { public: CLabelInfo(const XMLNode& Node=XMLNode::emptyNode()); CLabelInfo(const CLabelInfo& Other); CLabelInfo& operator =(const CLabelInfo& Other); virtual ~CLabelInfo(); virtual CLabelInfo *Clone(); std::string CatalogNumber() const; CLabel *Label() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CLabelInfoPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/LabelInfoList.h000066400000000000000000000021351175500222200234250ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_LABELINFO_LIST_H #define _MUSICBRAINZ5_LABELINFO_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CLabelInfo; typedef CListImpl CLabelInfoList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/LabelList.h000066400000000000000000000021111175500222200226030ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_LABEL_LIST_H #define _MUSICBRAINZ5_LABEL_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CLabel; typedef CListImpl CLabelList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Lifespan.h000066400000000000000000000033341175500222200225010ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_LIFESPAN_H #define _MUSICBRAINZ5_LIFESPAN_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CLifespanPrivate; class CLifespan: public CEntity { public: CLifespan(const XMLNode& Node=XMLNode::emptyNode()); CLifespan(const CLifespan& Other); CLifespan& operator =(const CLifespan& Other); virtual ~CLifespan(); virtual CLifespan *Clone(); std::string Begin() const; std::string End() const; std::string Ended() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CLifespanPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/List.h000066400000000000000000000032311175500222200216470ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_LIST_H #define _MUSICBRAINZ5_LIST_H #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CListPrivate; class CList: public CEntity { public: CList(); CList(const CList& Other); CList& operator =(const CList& Other); virtual ~CList(); virtual CList *Clone(); int NumItems() const; int Offset() const; int Count() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); void AddItem(CEntity *Item); CEntity *Item(int Item) const; private: CListPrivate *m_d; void Cleanup(); }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/ListImpl.h000066400000000000000000000045651175500222200225040ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_LIST_IMPL_H #define _MUSICBRAINZ5_LIST_IMPL_H #include "musicbrainz5/List.h" namespace MusicBrainz5 { template class CListImpl: public CList { public: CListImpl(const XMLNode& Node=XMLNode::emptyNode()) : CList() { if (!Node.isEmpty()) { //std::cout << T::GetElementName() << " List node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } CListImpl(const CListImpl& Other) : CList() { *this=Other; } MusicBrainz5::CListImpl& operator =(const CListImpl& Other) { if (this!=&Other) { CList::operator =(Other); } return *this; } virtual ~CListImpl() { } CListImpl *Clone() { return new CListImpl(*this); } virtual std::ostream& Serialise(std::ostream& os) const { os << T::GetElementName() << " List (impl):" << std::endl; CList::Serialise(os); for (int count=0;count(CList::Item(Item)); } void AddItem(T *Item) { CList::AddItem(Item); } protected: void ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if (T::GetElementName()==NodeName) { T *Item=0; ProcessItem(Node,Item); AddItem(Item); } else CList::ParseElement(Node); } }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Medium.h000066400000000000000000000036251175500222200221630ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_MEDIUM_H #define _MUSICBRAINZ5_MEDIUM_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/DiscList.h" #include "musicbrainz5/TrackList.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CMediumPrivate; class CMedium: public CEntity { public: CMedium(const XMLNode& Node=XMLNode::emptyNode()); CMedium(const CMedium& Other); CMedium& operator =(const CMedium& Other); virtual ~CMedium(); virtual CMedium *Clone(); std::string Title() const; int Position() const; std::string Format() const; CDiscList *DiscList() const; CTrackList *TrackList() const; bool ContainsDiscID(const std::string& DiscID) const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CMediumPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/MediumList.h000066400000000000000000000033301175500222200230100ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_MEDIUM_LIST_H #define _MUSICBRAINZ5_MEDIUM_LIST_H #include #include #include "musicbrainz5/ListImpl.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CMedium; class CMediumListPrivate; class CMediumList: public CListImpl { public: CMediumList(const XMLNode& Node=XMLNode::emptyNode()); CMediumList(const CMediumList& Other); CMediumList& operator =(const CMediumList& Other); virtual ~CMediumList(); virtual CMediumList *Clone(); int TrackCount() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CMediumListPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Message.h000066400000000000000000000032021175500222200223160ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_MESSAGE_H #define _MUSICBRAINZ5_MESSAGE_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CMessagePrivate; class CMessage: public CEntity { public: CMessage(const XMLNode& Node); CMessage(const CMessage& Other); CMessage& operator =(const CMessage& Other); virtual ~CMessage(); virtual CMessage *Clone(); std::string Text() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CMessagePrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Metadata.h000066400000000000000000000066621175500222200224670ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_METADATA_H #define _MUSICBRAINZ5_METADATA_H #include "musicbrainz5/Entity.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/ArtistList.h" #include "musicbrainz5/WorkList.h" #include "musicbrainz5/ISRCList.h" #include "musicbrainz5/LabelInfoList.h" #include "musicbrainz5/ReleaseGroupList.h" #include "musicbrainz5/RecordingList.h" #include "musicbrainz5/LabelList.h" #include "musicbrainz5/AnnotationList.h" #include "musicbrainz5/CDStubList.h" #include "musicbrainz5/FreeDBDiscList.h" #include "musicbrainz5/TagList.h" #include "musicbrainz5/UserTagList.h" #include "musicbrainz5/CollectionList.h" #include "musicbrainz5/xmlParser.h" #include namespace MusicBrainz5 { class CMetadataPrivate; class CArtist; class CRelease; class CReleaseGroup; class CRecording; class CLabel; class CPUID; class CISRC; class CDisc; class CRating; class CUserRating; class CCollection; class CArtist; class CWork; class CCDStub; class CMessage; class CMetadata: public CEntity { public: CMetadata(const XMLNode& Node=XMLNode::emptyNode()); CMetadata(const CMetadata& Other); CMetadata& operator =(const CMetadata& Other); virtual ~CMetadata(); virtual CMetadata *Clone(); std::string XMLNS() const; std::string XMLNSExt() const; std::string Generator() const; std::string Created() const; CArtist *Artist() const; CRelease *Release() const; CReleaseGroup *ReleaseGroup() const; CRecording *Recording() const; CLabel *Label() const; CWork *Work() const; CPUID *PUID() const; CISRC *ISRC() const; CDisc *Disc() const; CLabelInfoList *LabelInfoList() const; CRating *Rating() const; CUserRating *UserRating() const; CCollection *Collection() const; CArtistList *ArtistList() const; CReleaseList *ReleaseList() const; CReleaseGroupList *ReleaseGroupList() const; CRecordingList *RecordingList() const; CLabelList *LabelList() const; CWorkList *WorkList() const; CISRCList *ISRCList() const; CAnnotationList *AnnotationList() const; CCDStubList *CDStubList() const; CFreeDBDiscList *FreeDBDiscList() const; CTagList *TagList() const; CUserTagList *UserTagList() const; CCollectionList *CollectionList() const; CCDStub *CDStub() const; CMessage *Message() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CMetadataPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/NameCredit.h000066400000000000000000000034361175500222200227560ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_NAME_CREDIT_H #define _MUSICBRAINZ5_NAME_CREDIT_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CNameCreditPrivate; class CArtist; class CNameCredit: public CEntity { public: CNameCredit(const XMLNode& Node=XMLNode::emptyNode()); CNameCredit(const CNameCredit& Other); CNameCredit& operator =(const CNameCredit& Other); virtual ~CNameCredit(); virtual CNameCredit *Clone(); std::string JoinPhrase() const; std::string Name() const; CArtist *Artist() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CNameCreditPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/NameCreditList.h000066400000000000000000000021421175500222200236030ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_NAMECREDIT_LIST_H #define _MUSICBRAINZ5_NAMECREDIT_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CNameCredit; typedef CListImpl CNameCreditList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/NonMBTrack.h000066400000000000000000000033371175500222200227010ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_NON_MB_TRACK_H #define _MUSICBRAINZ5_NON_MB_TRACK_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CNonMBTrackPrivate; class CNonMBTrack: public CEntity { public: CNonMBTrack(const XMLNode& Node); CNonMBTrack(const CNonMBTrack& Other); CNonMBTrack& operator =(const CNonMBTrack& Other); virtual ~CNonMBTrack(); virtual CNonMBTrack *Clone(); std::string Title() const; std::string Artist() const; int Length() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CNonMBTrackPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/NonMBTrackList.h000066400000000000000000000021421175500222200235260ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_NONMBTRACK_LIST_H #define _MUSICBRAINZ5_NONMBTRACK_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CNonMBTrack; typedef CListImpl CNonMBTrackList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/PUID.h000066400000000000000000000033011175500222200214730ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_PUID_H #define _MUSICBRAINZ5_PUID_H #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/RecordingList.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CPUIDPrivate; class CPUID: public CEntity { public: CPUID(const XMLNode& Node=XMLNode::emptyNode()); CPUID(const CPUID& Other); CPUID& operator =(const CPUID& Other); virtual ~CPUID(); virtual CPUID *Clone(); std::string ID() const; CRecordingList *RecordingList() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CPUIDPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/PUIDList.h000066400000000000000000000021041175500222200223270ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_PUID_LIST_H #define _MUSICBRAINZ5_PUID_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CPUID; typedef CListImpl CPUIDList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Query.h000066400000000000000000000352371175500222200220540ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_QUERY_H #define _MUSICBRAINZ5_QUERY_H #include "defines.h" #include "Entity.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/Metadata.h" #include "musicbrainz5/xmlParser.h" #include #include #include /** * @mainpage libmusicbrainz5 * * This is the documentation for libmusicbrainz5, a library for retrieving data from * the MusicBrainz service. * * The main entry point to the library is the MusicBrainz5::CQuery object. * * For details of the C interface, see the documentation for the file mb5_c.h. * * Please report any issues with this library at * http://tickets.musicbrainz.org/. * * @par Compiling and Linking * * This package provides a pkg-config script that returns the necessary compiler * and linker flags, as well as the version number. To build a small sample * program one would use: * * @par * g++ -o test_app test_app.cpp `pkg-config libmusicbrainz5 --cflags --libs` * * If you don't want/can't use pkg-config and you are using the C API, make sure * you link in the C++ standard library: * * @par * gcc -o test_app test_app.c -lmusicbrainz5 -lm -lstdc++ * * @par Example: * * A brief example showing how to lookup a list of releases matching a disc id * @code MusicBrainz5::CQuery Query("cdlookupexample-1.0"); try { MusicBrainz5::CMetadata Metadata=Query.Query("discid",DiscID); if (Metadata.Disc() && Metadata.Disc()->ReleaseList()) { MusicBrainz5::CReleaseList *ReleaseList=Metadata.Disc()->ReleaseList(); std::cout << "Found " << ReleaseList->NumItems() << " release(s)" << std::endl; for (int count=0;countNumItems();count++) { MusicBrainz5::CRelease *Release=ReleaseList->Item(count); std::cout << "Basic release: " << std::endl << *Release << std::endl; //The releases returned from LookupDiscID don't contain full information MusicBrainz5::CQuery::tParamMap Params; Params["inc"]="artists labels recordings release-groups url-rels discids artist-credits"; Metadata=Query.Query("release",Release.ID(),"",Params); if (Metadata.Release()) { MusicBrainz5::CRelease *FullRelease=Metadata.Release(); std::cout << *FullRelease << std::endl; } } } } catch (MusicBrainz5::CConnectionError& Error) { std::cout << "Connection Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CTimeoutError& Error) { std::cout << "Timeout Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CAuthenticationError& Error) { std::cout << "Authentication Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CFetchError& Error) { std::cout << "Fetch Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CRequestError& Error) { std::cout << "Request Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } catch (MusicBrainz5::CResourceNotFoundError& Error) { std::cout << "ResourceNotFound Exception: '" << Error.what() << "'" << std::endl; std::cout << "LastResult: " << Query.LastResult() << std::endl; std::cout << "LastHTTPCode: " << Query.LastHTTPCode() << std::endl; std::cout << "LastErrorMessage: " << Query.LastErrorMessage() << std::endl; } @endcode */ namespace MusicBrainz5 { class CQueryPrivate; /** * @brief Main object for generating queries to MusicBrainz * * This object is the main entry point for the library, generating a query to the * MusicBrainz service, and parsing the results. The resultant objects can be used * to retrieve information appropriate to the query. * * For information on generating queries and the expected responses, see the * documentation for the * web service. * * For information on search syntax, see the documentation for * search syntax. * * @b Note It is the responsibility of the caller to validate any pointers returned * from the library. It is valid for a pointer to be NULL if the information was not * present in the response from the MusicBrainz service. * * @b Note The ownership of any pointers returned from the C++ interfaces remains * with the library. The caller should not delete any pointer returned from the * library. Users of the C library should take note of the documentation for each * individual function in mb5_c.h */ class CQuery { public: typedef std::map tParamMap; /** * @brief Enumerated type for query status * * Enumerated type for query status */ enum tQueryResult { eQuery_Success=0, eQuery_ConnectionError, eQuery_Timeout, eQuery_AuthenticationError, eQuery_FetchError, eQuery_RequestError, eQuery_ResourceNotFound }; /** * @brief Constructor for MusicBrainz::CQuery object * * This is the constructor for the MusicBrainz::CQuery object. * * @param UserAgent User agent to use in any queries and submissions. The format * is @c "application-version", where application is your application's name * and version is a version number which may not contain a '-' character. * @param Server Server to be used (defaults to musicbrainz.org if not specified) * @param Port Port to use (defaults to 80 if not specified) * */ CQuery(const std::string& UserAgent, const std::string& Server="musicbrainz.org", int Port=80); ~CQuery(); /** * @brief Set the user name * * Set the user name to use when authenticating to the MusicBrainz service * * @param UserName Username to use */ void SetUserName(const std::string& UserName); /** * @brief Set the password * * Set the password to use when authenticating to the MusicBrainz service * * @param Password Password to use */ void SetPassword(const std::string& Password); /** * @brief Set proxy server * * Set the proxy server to use for queries. @b Note The http_proxy environment variable * will be used to set a 'default' proxy server. Calls to this method will override any * proxy settings set by the http_proxy environment variable. * * @param ProxyHost Proxy server to use */ void SetProxyHost(const std::string& ProxyHost); /** * @brief Set proxy server port * * Set the proxy server port to use for queries. @b Note The http_proxy environment variable * will be used to set a 'default' proxy server. Calls to this method will override any * proxy settings set by the http_proxy environment variable. * * @param ProxyPort Proxy port to use */ void SetProxyPort(int ProxyPort); /** * @brief Set proxy server user name * * Set the user name to use when authenticating to the proxy server. @b Note The http_proxy * environment variable will be used to set a 'default' proxy server. Calls to this method * will override any proxy settings set by the http_proxy environment variable. * * @param ProxyUserName Proxy user name to use */ void SetProxyUserName(const std::string& ProxyUserName); /** * @brief Set proxy server password * * Set the password to use when authenticating to the proxy server. @b Note The http_proxy * environment variable will be used to set a 'default' proxy server. Calls to this method * will override any proxy settings set by the http_proxy environment variable. * * @param ProxyPassword Proxy password to use */ void SetProxyPassword(const std::string& ProxyPassword); /** * @brief Return a list of releases that match a disc ID * * Request a list of releases matching the specified disc ID. * * @param DiscID Disc id to match * * @return MusicBrainz5::CReleaseList */ CReleaseList LookupDiscID(const std::string& DiscID); /** * @brief Return full information about a release * * Query for detailed information about a specific release * * @param ReleaseID MusicBrainz release ID to lookup * * @return MusicBrainz::CRelease object * * @throw CConnectionError An error occurred connecting to the web server * @throw CTimeoutError A timeout occurred when connecting to the web server * @throw CAuthenticationError An authentication error occurred * @throw CFetchError An error occurred fetching data * @throw CRequestError The request was invalid * @throw CResourceNotFoundError The requested resource was not found */ CRelease LookupRelease(const std::string& ReleaseID); /** * @brief Perform a generic query * * Performs a generic query. * * Assuming the following parameters are set: * * "param1" = "p1v1 p1v2 p1v3"
* "param2" = "p2v1"
* "param3" = ""
* * The following query will be generated: * * /ws/2/Entity/ID/Resource?param1=p1v1+p1v2+p1v3¶m2=p2v1¶m3 * * If any of ID or Resource are empty, those components will be omitted from the query. * * For full details about generating queries, see the * web service * documentation. * * @param Entity Entity to lookup (e.g. artist, release, discid) * @param ID The MusicBrainz ID of the entity * @param Resource The resource (currently only used for collections) * @param Params Map of parameters to add to the query (e.g. inc) * * @return MusicBrainz5::CMetadata object * * @throw CConnectionError An error occurred connecting to the web server * @throw CTimeoutError A timeout occurred when connecting to the web server * @throw CAuthenticationError An authentication error occurred * @throw CFetchError An error occurred fetching data * @throw CRequestError The request was invalid * @throw CResourceNotFoundError The requested resource was not found */ CMetadata Query(const std::string& Entity,const std::string& ID="",const std::string& Resource="",const tParamMap& Params=tParamMap()); /** * @brief Add entries to the specified collection * * Add a list of releases to the specified collection. * * @param CollectionID The MusicBrainz ID of the collection to add entries to * @param Entries List of MusicBrainz Release IDs to add to the collection * * @return true if successful, false otherwise * * @throw CConnectionError An error occurred connecting to the web server * @throw CTimeoutError A timeout occurred when connecting to the web server * @throw CAuthenticationError An authentication error occurred * @throw CFetchError An error occurred fetching data * @throw CRequestError The request was invalid * @throw CResourceNotFoundError The requested resource was not found */ bool AddCollectionEntries(const std::string& CollectionID, const std::vector& Entries); /** * @brief Delete entries from the specified collection * * Delete a list of releases from the specified collection. * * @param CollectionID The MusicBrainz ID of the collection to delete entries from * @param Entries List of MusicBrainz Release IDs to delete from the collection * * @return true if successful, false otherwise * * @throw CConnectionError An error occurred connecting to the web server * @throw CTimeoutError A timeout occurred when connecting to the web server * @throw CAuthenticationError An authentication error occurred * @throw CFetchError An error occurred fetching data * @throw CRequestError The request was invalid * @throw CResourceNotFoundError The requested resource was not found */ bool DeleteCollectionEntries(const std::string& CollectionID, const std::vector& Entries); /** * @brief Return result of the last query * * Return the result of the last query * * @return Result of last query */ CQuery::tQueryResult LastResult() const; /** * @brief Return HTTP code of the last query * * Return the HTTP code of the last query * * @return HTTP code of last query */ int LastHTTPCode() const; /** * @brief Return error message from the last query * * Return the error message from the last query * * @return Error message from last query */ std::string LastErrorMessage() const; /** * @brief Return the library version * * Return the library version * * @return Library version */ std::string Version() const; private: CQueryPrivate * const m_d; CMetadata PerformQuery(const std::string& Query); void WaitRequest() const; std::string UserAgent() const; bool EditCollection(const std::string& CollectionID, const std::vector& Entries, const std::string& Action); std::string URIEscape(const std::string& URI); std::string URLEncode(const std::map& Params); }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Rating.h000066400000000000000000000032201175500222200221560ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_RATING_H #define _MUSICBRAINZ5_RATING_H #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CRatingPrivate; class CRating: public CEntity { public: CRating(const XMLNode& Node=XMLNode::emptyNode()); CRating(const CRating& Other); CRating& operator =(const CRating& Other); virtual ~CRating(); virtual CRating *Clone(); int VotesCount() const; double Rating() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CRatingPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Recording.h000066400000000000000000000046271175500222200226620ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_RECORDING_H #define _MUSICBRAINZ5_RECORDING_H #include #include namespace MusicBrainz5 { class CRecording; } #include "musicbrainz5/Entity.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/PUIDList.h" #include "musicbrainz5/ISRCList.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/TagList.h" #include "musicbrainz5/UserTagList.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CRecordingPrivate; class CArtistCredit; class CRating; class CUserRating; class CRecording: public CEntity { public: CRecording(const XMLNode& Node=XMLNode::emptyNode()); CRecording(const CRecording& Other); CRecording& operator =(const CRecording& Other); virtual ~CRecording(); virtual CRecording *Clone(); std::string ID() const; std::string Title() const; int Length() const; std::string Disambiguation() const; CArtistCredit *ArtistCredit() const; CReleaseList *ReleaseList() const; CPUIDList *PUIDList() const; CISRCList *ISRCList() const; CRelationListList *RelationListList() const; CTagList *TagList() const; CUserTagList *UserTagList() const; CRating *Rating() const; CUserRating *UserRating() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CRecordingPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/RecordingList.h000066400000000000000000000021351175500222200235060ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_RECORDING_LIST_H #define _MUSICBRAINZ5_RECORDING_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CRecording; typedef CListImpl CRecordingList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Relation.h000066400000000000000000000042261175500222200225160ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_RELATION_H #define _MUSICBRAINZ5_RELATION_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/AttributeList.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CRelationPrivate; class CArtist; class CRelease; class CReleaseGroup; class CRecording; class CLabel; class CWork; class CRelation: public CEntity { public: CRelation(const XMLNode& Node=XMLNode::emptyNode()); CRelation(const CRelation& Other); CRelation& operator =(const CRelation& Other); virtual ~CRelation(); virtual CRelation *Clone(); std::string Type() const; std::string Target() const; std::string Direction() const; CAttributeList *AttributeList() const; std::string Begin() const; std::string End() const; CArtist *Artist() const; CRelease *Release() const; CReleaseGroup *ReleaseGroup() const; CRecording *Recording() const; CLabel *Label() const; CWork *Work() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CRelationPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/RelationList.h000066400000000000000000000033471175500222200233550ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_RELATION_LIST_H #define _MUSICBRAINZ5_RELATION_LIST_H #include #include #include "musicbrainz5/ListImpl.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CRelation; class CRelationListPrivate; class CRelationList: public CListImpl { public: CRelationList(const XMLNode& Node); CRelationList(const CRelationList& Other); CRelationList& operator =(const CRelationList& Other); virtual ~CRelationList(); virtual CRelationList *Clone(); std::string TargetType() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CRelationListPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/RelationListList.h000066400000000000000000000033401175500222200242020ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_RELATIONLIST_GROUP_H #define _MUSICBRAINZ5_RELATIONLIST_GROUP_H #include #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CRelationListListPrivate; class CRelationList; class CRelationListList { public: CRelationListList(); CRelationListList(const CRelationListList& Other); CRelationListList& operator =(const CRelationListList& Other); virtual ~CRelationListList(); void Add(CRelationList *RelationList); int NumItems() const; CRelationList *Item(int Item) const; int Offset() const { return 0; } int Count() const { return NumItems(); } std::ostream& Serialise(std::ostream& os) const; private: void Cleanup(); CRelationListListPrivate * const m_d; }; } std::ostream& operator << (std::ostream& os, const MusicBrainz5::CRelationListList& RelationListList); #endif libmusicbrainz-5.0.1/include/musicbrainz5/Release.h000066400000000000000000000050411175500222200223150ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_RELEASE_H #define _MUSICBRAINZ5_RELEASE_H #include "musicbrainz5/Entity.h" #include "musicbrainz5/LabelInfoList.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/MediumList.h" #include "musicbrainz5/CollectionList.h" #include "musicbrainz5/xmlParser.h" #include #include namespace MusicBrainz5 { class CReleasePrivate; class CTextRepresentation; class CArtistCredit; class CReleaseGroup; class CMedium; class CRelease: public CEntity { public: CRelease(const XMLNode& Node=XMLNode::emptyNode()); CRelease(const CRelease& Other); CRelease& operator =(const CRelease& Other); virtual ~CRelease(); virtual CRelease *Clone(); std::string ID() const; std::string Title() const; std::string Status() const; std::string Quality() const; std::string Disambiguation() const; std::string Packaging() const; CTextRepresentation *TextRepresentation() const; CArtistCredit *ArtistCredit() const; CReleaseGroup *ReleaseGroup() const; std::string Date() const; std::string Country() const; std::string Barcode() const; std::string ASIN() const; CLabelInfoList *LabelInfoList() const; CMediumList *MediumList() const; CRelationListList *RelationListList() const; CCollectionList *CollectionList() const; CMediumList MediaMatchingDiscID(const std::string& DiscID) const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CReleasePrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/ReleaseGroup.h000066400000000000000000000046631175500222200233430ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_RELEASE_GROUP_H #define _MUSICBRAINZ5_RELEASE_GROUP_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/TagList.h" #include "musicbrainz5/UserTagList.h" #include "musicbrainz5/SecondaryTypeList.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CReleaseGroupPrivate; class CArtistCredit; class CRating; class CUserRating; class CSecondaryType; class CReleaseGroup: public CEntity { public: CReleaseGroup(const XMLNode& Node=XMLNode::emptyNode()); CReleaseGroup(const CReleaseGroup& Other); CReleaseGroup& operator =(const CReleaseGroup& Other); virtual ~CReleaseGroup(); virtual CReleaseGroup *Clone(); std::string ID() const; std::string PrimaryType() const; std::string Title() const; std::string Disambiguation() const; std::string FirstReleaseDate() const; CArtistCredit *ArtistCredit() const; CReleaseList *ReleaseList() const; CRelationListList *RelationListList() const; CTagList *TagList() const; CUserTagList *UserTagList() const; CRating *Rating() const; CUserRating *UserRating() const; CSecondaryTypeList *SecondaryTypeList() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CReleaseGroupPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/ReleaseGroupList.h000066400000000000000000000021541175500222200241700ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_RELEASEGROUP_LIST_H #define _MUSICBRAINZ5_RELEASEGROUP_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CReleaseGroup; typedef CListImpl CReleaseGroupList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/ReleaseList.h000066400000000000000000000021231175500222200231470ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_RELEASE_LIST_H #define _MUSICBRAINZ5_RELEASE_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CRelease; typedef CListImpl CReleaseList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/SecondaryType.h000066400000000000000000000033751175500222200235360ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_SECONDARY_TYPE_H #define _MUSICBRAINZ5_SECONDARY_TYPE_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CSecondaryTypePrivate; class CSecondaryType: public CEntity { public: CSecondaryType(const XMLNode& Node=XMLNode::emptyNode()); CSecondaryType(const CSecondaryType& Other); CSecondaryType& operator =(const CSecondaryType& Other); virtual ~CSecondaryType(); virtual CSecondaryType *Clone(); std::string SecondaryType() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CSecondaryTypePrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/SecondaryTypeList.h000066400000000000000000000034411175500222200243640ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_SECONDARY_TYPE_LIST_H #define _MUSICBRAINZ5_SECONDARY_TYPE_LIST_H #include #include #include "musicbrainz5/ListImpl.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CSecondaryType; class CSecondaryTypeListPrivate; class CSecondaryTypeList: public CListImpl { public: CSecondaryTypeList(const XMLNode& Node=XMLNode::emptyNode()); CSecondaryTypeList(const CSecondaryTypeList& Other); CSecondaryTypeList& operator =(const CSecondaryTypeList& Other); virtual ~CSecondaryTypeList(); virtual CSecondaryTypeList *Clone(); virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CSecondaryTypeListPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Tag.h000066400000000000000000000031471175500222200214550ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_TAG_H #define _MUSICBRAINZ5_TAG_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CTagPrivate; class CTag: public CEntity { public: CTag(const XMLNode& Node); CTag(const CTag& Other); CTag& operator =(const CTag& Other); virtual ~CTag(); virtual CTag *Clone(); int Count() const; std::string Name() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CTagPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/TagList.h000066400000000000000000000020771175500222200223120ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_TAG_LIST_H #define _MUSICBRAINZ5_TAG_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CTag; typedef CListImpl CTagList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/TextRepresentation.h000066400000000000000000000034771175500222200246170ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_TEXT_REPRESENTATION_H #define _MUSICBRAINZ5_TEXT_REPRESENTATION_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CTextRepresentationPrivate; class CTextRepresentation: public CEntity { public: CTextRepresentation(const XMLNode& Node=XMLNode::emptyNode()); CTextRepresentation(const CTextRepresentation& Other); CTextRepresentation& operator =(const CTextRepresentation& Other); virtual ~CTextRepresentation(); virtual CTextRepresentation *Clone(); std::string Language() const; std::string Script() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CTextRepresentationPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Track.h000066400000000000000000000035211175500222200220020ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_TRACK_H #define _MUSICBRAINZ5_TRACK_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CTrackPrivate; class CRecording; class CArtistCredit; class CTrack: public CEntity { public: CTrack(const XMLNode& Node=XMLNode::emptyNode()); CTrack(const CTrack& Other); CTrack& operator =(const CTrack& Other); virtual ~CTrack(); virtual CTrack *Clone(); int Position() const; std::string Title() const; CRecording *Recording() const; int Length() const; CArtistCredit *ArtistCredit() const; std::string Number() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CTrackPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/TrackList.h000066400000000000000000000021111175500222200226300ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_TRACK_LIST_H #define _MUSICBRAINZ5_TRACK_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CTrack; typedef CListImpl CTrackList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/UserRating.h000066400000000000000000000032241175500222200230210ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_USER_RATING_H #define _MUSICBRAINZ5_USER_RATING_H #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CUserRatingPrivate; class CUserRating: public CEntity { public: CUserRating(const XMLNode& Node); CUserRating(const CUserRating& Other); CUserRating& operator =(const CUserRating& Other); virtual ~CUserRating(); virtual CUserRating *Clone(); int UserRating() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CUserRatingPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/UserTag.h000066400000000000000000000032041175500222200223060ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_USER_TAG_H #define _MUSICBRAINZ5_USER_TAG_H #include #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CUserTagPrivate; class CUserTag: public CEntity { public: CUserTag(const XMLNode& Node); CUserTag(const CUserTag& Other); CUserTag& operator =(const CUserTag& Other); virtual ~CUserTag(); virtual CUserTag *Clone(); std::string Name() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: CUserTagPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/UserTagList.h000066400000000000000000000021231175500222200231410ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_USERTAG_LIST_H #define _MUSICBRAINZ5_USERTAG_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CUserTag; typedef CListImpl CUserTagList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/Work.h000066400000000000000000000044051175500222200216620ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_WORK_H #define _MUSICBRAINZ5_WORK_H #include #include "musicbrainz5/Entity.h" #include "musicbrainz5/AliasList.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/TagList.h" #include "musicbrainz5/UserTagList.h" #include "musicbrainz5/ISWCList.h" #include "musicbrainz5/xmlParser.h" namespace MusicBrainz5 { class CWorkPrivate; class CArtistCredit; class CISWC; class CRating; class CUserRating; class CWork: public CEntity { public: CWork(const XMLNode& Node=XMLNode::emptyNode()); CWork(const CWork& Other); CWork& operator =(const CWork& Other); virtual ~CWork(); virtual CWork *Clone(); std::string ID() const; std::string Type() const; std::string Title() const; CArtistCredit *ArtistCredit() const; CISWCList *ISWCList() const; std::string Disambiguation() const; CAliasList *AliasList() const; CRelationListList *RelationListList() const; CTagList *TagList() const; CUserTagList *UserTagList() const; CRating *Rating() const; CUserRating *UserRating() const; std::string Language() const; virtual std::ostream& Serialise(std::ostream& os) const; static std::string GetElementName(); protected: virtual void ParseAttribute(const std::string& Name, const std::string& Value); virtual void ParseElement(const XMLNode& Node); private: void Cleanup(); CWorkPrivate * const m_d; }; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/WorkList.h000066400000000000000000000021041175500222200225100ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_WORK_LIST_H #define _MUSICBRAINZ5_WORK_LIST_H #include "musicbrainz5/ListImpl.h" namespace MusicBrainz5 { class CWork; typedef CListImpl CWorkList; } #endif libmusicbrainz-5.0.1/include/musicbrainz5/defines.h000066400000000000000000000024521175500222200223550ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #ifndef _MUSICBRAINZ5_DEFINES_H #define _MUSICBRAINZ5_DEFINES_H #if defined(__GNUC__) && __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) #define LIBMB5_DEPRECATED(f) __attribute__((deprecated("Use '" #f "' instead"))) #elif defined(__GNUC__) && __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) #define LIBMB5_DEPRECATED(f) __attribute__ ((deprecated)) #else #define LIBMB5_DEPRECATED(f) #endif #endif libmusicbrainz-5.0.1/include/musicbrainz5/xmlParser.h000066400000000000000000001237171175500222200227250ustar00rootroot00000000000000/****************************************************************************/ /*! \mainpage XMLParser library * \section intro_sec Introduction * * This is a 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 V2.43 * @author Frank Vanden Berghen * * Copyright (c) 2002, Business-Insight * Business-Insight * All rights reserved. * See the file AFPL-license.txt about the licensing terms * * \section tutorial First Tutorial * You can follow a simple Tutorial to know the basics... * * \section usage General usage: How to include the XMLParser library inside your project. * * The library is composed of two files: xmlParser.cpp and * xmlParser.h. These are the ONLY 2 files that you need when * using the library inside your own projects. * * All the functions of the library are documented inside the comments of the file * xmlParser.h. These comments can be transformed in * full-fledged HTML documentation using the DOXYGEN software: simply type: "doxygen doxy.cfg" * * By default, the XMLParser library uses (char*) for string representation.To use the (wchar_t*) * version of the library, you need to define the "_UNICODE" preprocessor definition variable * (this is usually done inside your project definition file) (This is done automatically for you * when using Visual Studio). * * \section example Advanced Tutorial and Many Examples of usage. * * Some very small introductory examples are described inside the Tutorial file * xmlParser.html * * Some additional small examples are also inside the file xmlTest.cpp * (for the "char*" version of the library) and inside the file * xmlTestUnicode.cpp (for the "wchar_t*" * version of the library). If you have a question, please review these additionnal examples * before sending an e-mail to the author. * * To build the examples: * - linux/unix: type "make" * - solaris: type "make -f makefile.solaris" * - windows: Visual Studio: double-click on xmlParser.dsw * (under Visual Studio .NET, the .dsp and .dsw files will be automatically converted to .vcproj and .sln files) * * In order to build the examples you need some additional files: * - linux/unix: makefile * - solaris: makefile.solaris * - windows: Visual Studio: *.dsp, xmlParser.dsw and also xmlParser.lib and xmlParser.dll * * \section debugging Debugging with the XMLParser library * * \subsection debugwin Debugging under WINDOWS * * Inside Visual C++, the "debug versions" of the memory allocation functions are * very slow: Do not forget to compile in "release mode" to get maximum speed. * When I had to debug a software that was using the XMLParser Library, it was usually * a nightmare because the library was sooOOOoooo slow in debug mode (because of the * slow memory allocations in Debug mode). To solve this * problem, during all the debugging session, I am now using a very fast DLL version of the * XMLParser Library (the DLL is compiled in release mode). Using the DLL version of * the XMLParser Library allows me to have lightening XML parsing speed even in debug! * Other than that, the DLL version is useless: In the release version of my tool, * I always use the normal, ".cpp"-based, XMLParser Library (I simply include the * xmlParser.cpp and * xmlParser.h files into the project). * * The file XMLNodeAutoexp.txt contains some * "tweaks" that improve substancially the display of the content of the XMLNode objects * inside the Visual Studio Debugger. Believe me, once you have seen inside the debugger * the "smooth" display of the XMLNode objects, you cannot live without it anymore! * * \subsection debuglinux Debugging under LINUX/UNIX * * The speed of the debug version of the XMLParser library is tolerable so no extra * work.has been done. * ****************************************************************************/ #ifndef __INCLUDE_XML_NODE__ #define __INCLUDE_XML_NODE__ #include #ifdef _UNICODE // If you comment the next "define" line then the library will never "switch to" _UNICODE (wchar_t*) mode (16/32 bits per characters). // This is useful when you get error messages like: // 'XMLNode::openFileHelper' : cannot convert parameter 2 from 'const char [5]' to 'const wchar_t *' // The _XMLWIDECHAR preprocessor variable force the XMLParser library into either utf16/32-mode (the proprocessor variable // must be defined) or utf8-mode(the pre-processor variable must be undefined). #define _XMLWIDECHAR #endif #if defined(WIN32) || defined(UNDER_CE) || defined(_WIN32) || defined(WIN64) || defined(__BORLANDC__) // comment the next line if you are under windows and the compiler is not Microsoft Visual Studio (6.0 or .NET) or Borland #define _XMLWINDOWS #endif #ifdef XMLDLLENTRY #undef XMLDLLENTRY #endif #ifdef _USE_XMLPARSER_DLL #ifdef _DLL_EXPORTS_ #define XMLDLLENTRY __declspec(dllexport) #else #define XMLDLLENTRY __declspec(dllimport) #endif #else #define XMLDLLENTRY #endif // uncomment the next line if you want no support for wchar_t* (no need for the or libraries anymore to compile) //#define XML_NO_WIDE_CHAR #ifdef XML_NO_WIDE_CHAR #undef _XMLWINDOWS #undef _XMLWIDECHAR #endif #ifdef _XMLWINDOWS #include #else #define XMLDLLENTRY #ifndef XML_NO_WIDE_CHAR #include // to have 'wcsrtombs' for ANSI version // to have 'mbsrtowcs' for WIDECHAR version #endif #endif // Some common types for char set portable code #ifdef _XMLWIDECHAR #define _CXML(c) L ## c #define XMLCSTR const wchar_t * #define XMLSTR wchar_t * #define XMLCHAR wchar_t #else #define _CXML(c) c #define XMLCSTR const char * #define XMLSTR char * #define XMLCHAR char #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, eXMLErrorNoXMLTagFound, eXMLErrorEmpty, eXMLErrorMissingTagName, eXMLErrorMissingEndTagName, eXMLErrorUnmatchedEndTag, eXMLErrorUnmatchedEndClearTag, eXMLErrorUnexpectedToken, eXMLErrorNoElements, eXMLErrorFileNotFound, eXMLErrorFirstTagNotFound, eXMLErrorUnknownCharacterEntity, eXMLErrorCharacterCodeAbove255, eXMLErrorCharConversionError, eXMLErrorCannotOpenWriteFile, eXMLErrorCannotWriteFile, eXMLErrorBase64DataSizeIsNotMultipleOf4, eXMLErrorBase64DecodeIllegalCharacter, eXMLErrorBase64DecodeTruncatedData, eXMLErrorBase64DecodeBufferTooSmall } XMLError; /// Enumeration used to manage type of data. Use in conjunction 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 XMLClear { XMLCSTR lpszValue; XMLCSTR lpszOpenTag; XMLCSTR lpszCloseTag; } XMLClear; /// Structure for XML attribute. typedef struct XMLAttribute { XMLCSTR lpszName; XMLCSTR lpszValue; } XMLAttribute; /// XMLElementPosition are not interchangeable with simple indexes typedef int XMLElementPosition; struct XMLNodeContents; /** @defgroup XMLParserGeneral The XML parser */ /// Main Class representing a XML node /** * All operations are performed using this class. * \note The constructors of the XMLNode class are protected, so use instead one of these four methods to get your first instance of XMLNode: *
    *
  • XMLNode::parseString
  • *
  • XMLNode::parseFile
  • *
  • XMLNode::openFileHelper
  • *
  • XMLNode::createXMLTopNode (or XMLNode::createXMLTopNode_WOSD)
  • *
*/ typedef struct XMLDLLENTRY XMLNode { private: struct XMLNodeDataTag; /// Constructors are protected, so use instead one of: XMLNode::parseString, XMLNode::parseFile, XMLNode::openFileHelper, XMLNode::createXMLTopNode XMLNode(struct XMLNodeDataTag *pParent, XMLSTR lpszName, char isDeclaration); /// Constructors are protected, so use instead one of: XMLNode::parseString, XMLNode::parseFile, XMLNode::openFileHelper, XMLNode::createXMLTopNode XMLNode(struct XMLNodeDataTag *p); public: static XMLCSTR getVersion();///< Return the XMLParser library version number /** @defgroup conversions Parsing XML files/strings to an XMLNode structure and Rendering XMLNode's to files/string. * @ingroup XMLParserGeneral * @{ */ /// Parse an XML string and return the root of a XMLNode tree representing the string. static XMLNode parseString (XMLCSTR lpXMLString, XMLCSTR tag=NULL, XMLResults *pResults=NULL); /**< The "parseString" function parse an XML string and return the root of a XMLNode tree. The "opposite" of this function is * the function "createXMLString" that re-creates an XML string from an XMLNode tree. If the XML document is corrupted, the * "parseString" method will initialize the "pResults" variable with some information that can be used to trace the error. * If you still want to parse the file, you can use the APPROXIMATE_PARSING option as explained inside the note at the * beginning of the "xmlParser.cpp" file. * * @param lpXMLString the XML string to parse * @param tag the name of the first tag inside the XML file. If the tag parameter is omitted, this function returns a node that represents the head of the xml document including the declaration term (). * @param pResults a pointer to a XMLResults variable that will contain some information that can be used to trace the XML parsing error. You can have a user-friendly explanation of the parsing error with the "getError" function. */ /// Parse an XML file and return the root of a XMLNode tree representing the file. static XMLNode parseFile (XMLCSTR filename, XMLCSTR tag=NULL, XMLResults *pResults=NULL); /**< The "parseFile" function parse an XML file and return the root of a XMLNode tree. The "opposite" of this function is * the function "writeToFile" that re-creates an XML file from an XMLNode tree. If the XML document is corrupted, the * "parseFile" method will initialize the "pResults" variable with some information that can be used to trace the error. * If you still want to parse the file, you can use the APPROXIMATE_PARSING option as explained inside the note at the * beginning of the "xmlParser.cpp" file. * * @param filename the path to the XML file to parse * @param tag the name of the first tag inside the XML file. If the tag parameter is omitted, this function returns a node that represents the head of the xml document including the declaration term (). * @param pResults a pointer to a XMLResults variable that will contain some information that can be used to trace the XML parsing error. You can have a user-friendly explanation of the parsing error with the "getError" function. */ /// Parse an XML file and return the root of a XMLNode tree representing the file. A very crude error checking is made. An attempt to guess the Char Encoding used in the file is made. static XMLNode openFileHelper(XMLCSTR filename, XMLCSTR tag=NULL); /**< The "openFileHelper" function reports to the screen all the warnings and errors that occurred during parsing of the XML file. * This function also tries to guess char Encoding (UTF-8, ASCII or SHIT-JIS) based on the first 200 bytes of the file. Since each * application has its own way to report and deal with errors, you should rather use the "parseFile" function to parse XML files * and program yourself thereafter an "error reporting" tailored for your needs (instead of using the very crude "error reporting" * mechanism included inside the "openFileHelper" function). * * If the XML document is corrupted, the "openFileHelper" method will: * - display an error message on the console (or inside a messageBox for windows). * - stop execution (exit). * * I strongly suggest that you write your own "openFileHelper" method tailored to your needs. If you still want to parse * the file, you can use the APPROXIMATE_PARSING option as explained inside the note at the beginning of the "xmlParser.cpp" file. * * @param filename the path of the XML file to parse. * @param tag the name of the first tag inside the XML file. If the tag parameter is omitted, this function returns a node that represents the head of the xml document including the declaration term (). */ static XMLCSTR getError(XMLError error); ///< this gives you a user-friendly explanation of the parsing error /// Create an XML string starting from the current XMLNode. XMLSTR createXMLString(int nFormat=1, int *pnSize=NULL) const; /**< The returned string should be free'd using the "freeXMLString" function. * * If nFormat==0, no formatting is required otherwise this returns an user friendly XML string from a given element * with appropriate white spaces and carriage returns. if pnSize is given it returns the size in character of the string. */ /// Save the content of an xmlNode inside a file XMLError writeToFile(XMLCSTR filename, const char *encoding=NULL, char nFormat=1) const; /**< If nFormat==0, no formatting is required otherwise this returns an user friendly XML string from a given element with appropriate white spaces and carriage returns. * If the global parameter "characterEncoding==encoding_UTF8", then the "encoding" parameter is ignored and always set to "utf-8". * If the global parameter "characterEncoding==encoding_ShiftJIS", then the "encoding" parameter is ignored and always set to "SHIFT-JIS". * If "_XMLWIDECHAR=1", then the "encoding" parameter is ignored and always set to "utf-16". * If no "encoding" parameter is given the "ISO-8859-1" encoding is used. */ /** @} */ /** @defgroup navigate Navigate the XMLNode structure * @ingroup XMLParserGeneral * @{ */ XMLCSTR getName() const; ///< name of the node XMLCSTR getText(int i=0) const; ///< return ith text field int nText() const; ///< nbr of text field XMLNode getParentNode() const; ///< return the parent node XMLNode getChildNode(int i=0) const; ///< return ith child node XMLNode getChildNode(XMLCSTR name, int i) const; ///< return ith child node with specific name (return an empty node if failing). If i==-1, this returns the last XMLNode with the given name. XMLNode getChildNode(XMLCSTR name, int *i=NULL) const; ///< return next child node with specific name (return an empty node if failing) XMLNode getChildNodeWithAttribute(XMLCSTR tagName, XMLCSTR attributeName, XMLCSTR attributeValue=NULL, int *i=NULL) const; ///< return child node with specific name/attribute (return an empty node if failing) XMLNode getChildNodeByPath(XMLCSTR path, char createNodeIfMissing=0, XMLCHAR sep='/'); ///< return the first child node with specific path XMLNode getChildNodeByPathNonConst(XMLSTR path, char createNodeIfMissing=0, XMLCHAR sep='/'); ///< return the first child node with specific path. int nChildNode(XMLCSTR name) const; ///< return the number of child node with specific name int nChildNode() const; ///< nbr of child node XMLAttribute getAttribute(int i=0) const; ///< return ith attribute XMLCSTR getAttributeName(int i=0) const; ///< return ith attribute name XMLCSTR getAttributeValue(int i=0) const; ///< return ith attribute value char isAttributeSet(XMLCSTR name) const; ///< test if an attribute with a specific name is given XMLCSTR getAttribute(XMLCSTR name, int i) const; ///< return ith attribute content with specific name (return a NULL if failing) XMLCSTR getAttribute(XMLCSTR name, int *i=NULL) const; ///< return next attribute content with specific name (return a NULL if failing) int nAttribute() const; ///< nbr of attribute XMLClear getClear(int i=0) const; ///< return ith clear field (comments) int nClear() const; ///< nbr of clear field XMLNodeContents enumContents(XMLElementPosition i) const; ///< enumerate all the different contents (attribute,child,text, clear) of the current XMLNode. The order is reflecting the order of the original file/string. NOTE: 0 <= i < nElement(); int nElement() const; ///< nbr of different contents for current node char isEmpty() const; ///< is this node Empty? char isDeclaration() const; ///< is this node a declaration XMLNode deepCopy() const; ///< deep copy (duplicate/clone) a XMLNode static XMLNode emptyNode(); ///< return XMLNode::emptyXMLNode; /** @} */ ~XMLNode(); XMLNode(const XMLNode &A); ///< to allow shallow/fast copy: XMLNode& operator=( const XMLNode& A ); ///< to allow shallow/fast copy: XMLNode(): d(NULL){}; static XMLNode emptyXMLNode; static XMLClear emptyXMLClear; static XMLAttribute emptyXMLAttribute; /** @defgroup xmlModify Create or Update the XMLNode structure * @ingroup XMLParserGeneral * The functions in this group allows you to create from scratch (or update) a XMLNode structure. Start by creating your top * node with the "createXMLTopNode" function and then add new nodes with the "addChild" function. The parameter 'pos' gives * the position where the childNode, the text or the XMLClearTag will be inserted. The default value (pos=-1) inserts at the * end. The value (pos=0) insert at the beginning (Insertion at the beginning is slower than at the end).
* * REMARK: 0 <= pos < nChild()+nText()+nClear()
*/ /** @defgroup creation Creating from scratch a XMLNode structure * @ingroup xmlModify * @{ */ static XMLNode createXMLTopNode(XMLCSTR lpszName, char isDeclaration=FALSE); ///< Create the top node of an XMLNode structure XMLNode addChild(XMLCSTR lpszName, char isDeclaration=FALSE, XMLElementPosition pos=-1); ///< Add a new child node XMLNode addChild(XMLNode nodeToAdd, XMLElementPosition pos=-1); ///< If the "nodeToAdd" has some parents, it will be detached from it's parents before being attached to the current XMLNode XMLAttribute *addAttribute(XMLCSTR lpszName, XMLCSTR lpszValuev); ///< Add a new attribute XMLCSTR addText(XMLCSTR lpszValue, XMLElementPosition pos=-1); ///< Add a new text content XMLClear *addClear(XMLCSTR lpszValue, XMLCSTR lpszOpen=NULL, XMLCSTR lpszClose=NULL, XMLElementPosition pos=-1); /**< Add a new clear tag * @param lpszOpen default value "" */ /** @} */ /** @defgroup xmlUpdate Updating Nodes * @ingroup xmlModify * Some update functions: * @{ */ XMLCSTR updateName(XMLCSTR lpszName); ///< change node's name XMLAttribute *updateAttribute(XMLAttribute *newAttribute, XMLAttribute *oldAttribute); ///< if the attribute to update is missing, a new one will be added XMLAttribute *updateAttribute(XMLCSTR lpszNewValue, XMLCSTR lpszNewName=NULL,int i=0); ///< if the attribute to update is missing, a new one will be added XMLAttribute *updateAttribute(XMLCSTR lpszNewValue, XMLCSTR lpszNewName,XMLCSTR lpszOldName);///< set lpszNewName=NULL if you don't want to change the name of the attribute if the attribute to update is missing, a new one will be added XMLCSTR updateText(XMLCSTR lpszNewValue, int i=0); ///< if the text to update is missing, a new one will be added XMLCSTR updateText(XMLCSTR lpszNewValue, XMLCSTR lpszOldValue); ///< if the text to update is missing, a new one will be added XMLClear *updateClear(XMLCSTR lpszNewContent, int i=0); ///< if the clearTag to update is missing, a new one will be added XMLClear *updateClear(XMLClear *newP,XMLClear *oldP); ///< if the clearTag to update is missing, a new one will be added XMLClear *updateClear(XMLCSTR lpszNewValue, XMLCSTR lpszOldValue); ///< if the clearTag to update is missing, a new one will be added /** @} */ /** @defgroup xmlDelete Deleting Nodes or Attributes * @ingroup xmlModify * Some deletion functions: * @{ */ /// The "deleteNodeContent" function forces the deletion of the content of this XMLNode and the subtree. void deleteNodeContent(); /**< \note The XMLNode instances that are referring to the part of the subtree that has been deleted CANNOT be used anymore!!. Unexpected results will occur if you continue using them. */ void deleteAttribute(int i=0); ///< Delete the ith attribute of the current XMLNode void deleteAttribute(XMLCSTR lpszName); ///< Delete the attribute with the given name (the "strcmp" function is used to find the right attribute) void deleteAttribute(XMLAttribute *anAttribute); ///< Delete the attribute with the name "anAttribute->lpszName" (the "strcmp" function is used to find the right attribute) void deleteText(int i=0); ///< Delete the Ith text content of the current XMLNode void deleteText(XMLCSTR lpszValue); ///< Delete the text content "lpszValue" inside the current XMLNode (direct "pointer-to-pointer" comparison is used to find the right text) void deleteClear(int i=0); ///< Delete the Ith clear tag inside the current XMLNode void deleteClear(XMLCSTR lpszValue); ///< Delete the clear tag "lpszValue" inside the current XMLNode (direct "pointer-to-pointer" comparison is used to find the clear tag) void deleteClear(XMLClear *p); ///< Delete the clear tag "p" inside the current XMLNode (direct "pointer-to-pointer" comparison on the lpszName of the clear tag is used to find the clear tag) /** @} */ /** @defgroup xmlWOSD ???_WOSD functions. * @ingroup xmlModify * The strings given as parameters for the "add" and "update" methods that have a name with * the postfix "_WOSD" (that means "WithOut String Duplication")(for example "addText_WOSD") * will be free'd by the XMLNode class. For example, it means that this is incorrect: * \code * xNode.addText_WOSD("foo"); * xNode.updateAttribute_WOSD("#newcolor" ,NULL,"color"); * \endcode * In opposition, this is correct: * \code * xNode.addText("foo"); * xNode.addText_WOSD(stringDup("foo")); * xNode.updateAttribute("#newcolor" ,NULL,"color"); * xNode.updateAttribute_WOSD(stringDup("#newcolor"),NULL,"color"); * \endcode * Typically, you will never do: * \code * char *b=(char*)malloc(...); * xNode.addText(b); * free(b); * \endcode * ... but rather: * \code * char *b=(char*)malloc(...); * xNode.addText_WOSD(b); * \endcode * ('free(b)' is performed by the XMLNode class) * @{ */ static XMLNode createXMLTopNode_WOSD(XMLSTR lpszName, char isDeclaration=FALSE); ///< Create the top node of an XMLNode structure XMLNode addChild_WOSD(XMLSTR lpszName, char isDeclaration=FALSE, XMLElementPosition pos=-1); ///< Add a new child node XMLAttribute *addAttribute_WOSD(XMLSTR lpszName, XMLSTR lpszValue); ///< Add a new attribute XMLCSTR addText_WOSD(XMLSTR lpszValue, XMLElementPosition pos=-1); ///< Add a new text content XMLClear *addClear_WOSD(XMLSTR lpszValue, XMLCSTR lpszOpen=NULL, XMLCSTR lpszClose=NULL, XMLElementPosition pos=-1); ///< Add a new clear Tag XMLCSTR updateName_WOSD(XMLSTR lpszName); ///< change node's name XMLAttribute *updateAttribute_WOSD(XMLAttribute *newAttribute, XMLAttribute *oldAttribute); ///< if the attribute to update is missing, a new one will be added XMLAttribute *updateAttribute_WOSD(XMLSTR lpszNewValue, XMLSTR lpszNewName=NULL,int i=0); ///< if the attribute to update is missing, a new one will be added XMLAttribute *updateAttribute_WOSD(XMLSTR lpszNewValue, XMLSTR lpszNewName,XMLCSTR lpszOldName); ///< set lpszNewName=NULL if you don't want to change the name of the attribute if the attribute to update is missing, a new one will be added XMLCSTR updateText_WOSD(XMLSTR lpszNewValue, int i=0); ///< if the text to update is missing, a new one will be added XMLCSTR updateText_WOSD(XMLSTR lpszNewValue, XMLCSTR lpszOldValue); ///< if the text to update is missing, a new one will be added XMLClear *updateClear_WOSD(XMLSTR lpszNewContent, int i=0); ///< if the clearTag to update is missing, a new one will be added XMLClear *updateClear_WOSD(XMLClear *newP,XMLClear *oldP); ///< if the clearTag to update is missing, a new one will be added XMLClear *updateClear_WOSD(XMLSTR lpszNewValue, XMLCSTR lpszOldValue); ///< if the clearTag to update is missing, a new one will be added /** @} */ /** @defgroup xmlPosition Position helper functions (use in conjunction with the update&add functions * @ingroup xmlModify * These are some useful functions when you want to insert a childNode, a text or a XMLClearTag in the * middle (at a specified position) of a XMLNode tree already constructed. The value returned by these * methods is to be used as last parameter (parameter 'pos') of addChild, addText or addClear. * @{ */ XMLElementPosition positionOfText(int i=0) const; XMLElementPosition positionOfText(XMLCSTR lpszValue) const; XMLElementPosition positionOfClear(int i=0) const; XMLElementPosition positionOfClear(XMLCSTR lpszValue) const; XMLElementPosition positionOfClear(XMLClear *a) const; XMLElementPosition positionOfChildNode(int i=0) const; XMLElementPosition positionOfChildNode(XMLNode x) const; XMLElementPosition positionOfChildNode(XMLCSTR name, int i=0) const; ///< return the position of the ith childNode with the specified name if (name==NULL) return the position of the ith childNode /** @} */ /// Enumeration for XML character encoding. typedef enum XMLCharEncoding { char_encoding_error=0, char_encoding_UTF8=1, char_encoding_legacy=2, char_encoding_ShiftJIS=3, char_encoding_GB2312=4, char_encoding_Big5=5, char_encoding_GBK=6 // this is actually the same as Big5 } XMLCharEncoding; /** \addtogroup conversions * @{ */ /// Sets the global options for the conversions static char setGlobalOptions(XMLCharEncoding characterEncoding=XMLNode::char_encoding_UTF8, char guessWideCharChars=1, char dropWhiteSpace=1, char removeCommentsInMiddleOfText=1); /**< The "setGlobalOptions" function allows you to change four global parameters that affect string & file * parsing. First of all, you most-probably will never have to change these 3 global parameters. * * @param guessWideCharChars If "guessWideCharChars"=1 and if this library is compiled in WideChar mode, then the * XMLNode::parseFile and XMLNode::openFileHelper functions will test if the file contains ASCII * characters. If this is the case, then the file will be loaded and converted in memory to * WideChar before being parsed. If 0, no conversion will be performed. * * @param guessWideCharChars If "guessWideCharChars"=1 and if this library is compiled in ASCII/UTF8/char* mode, then the * XMLNode::parseFile and XMLNode::openFileHelper functions will test if the file contains WideChar * characters. If this is the case, then the file will be loaded and converted in memory to * ASCII/UTF8/char* before being parsed. If 0, no conversion will be performed. * * @param characterEncoding This parameter is only meaningful when compiling in char* mode (multibyte character mode). * In wchar_t* (wide char mode), this parameter is ignored. This parameter should be one of the * three currently recognized encodings: XMLNode::encoding_UTF8, XMLNode::encoding_ascii, * XMLNode::encoding_ShiftJIS. * * @param dropWhiteSpace In most situations, text fields containing only white spaces (and carriage returns) * are useless. Even more, these "empty" text fields are annoying because they increase the * complexity of the user's code for parsing. So, 99% of the time, it's better to drop * the "empty" text fields. However The XML specification indicates that no white spaces * should be lost when parsing the file. So to be perfectly XML-compliant, you should set * dropWhiteSpace=0. A note of caution: if you set "dropWhiteSpace=0", the parser will be * slower and your code will be more complex. * * @param removeCommentsInMiddleOfText To explain this parameter, let's consider this code: * \code * XMLNode x=XMLNode::parseString("foobarchu","a"); * \endcode * If removeCommentsInMiddleOfText=0, then we will have: * \code * x.getText(0) -> "foo" * x.getText(1) -> "bar" * x.getText(2) -> "chu" * x.getClear(0) --> "" * x.getClear(1) --> "" * \endcode * If removeCommentsInMiddleOfText=1, then we will have: * \code * x.getText(0) -> "foobar" * x.getText(1) -> "chu" * x.getClear(0) --> "" * \endcode * * \return "0" when there are no errors. If you try to set an unrecognized encoding then the return value will be "1" to signal an error. * * \note Sometime, it's useful to set "guessWideCharChars=0" to disable any conversion * because the test to detect the file-type (ASCII/UTF8/char* or WideChar) may fail (rarely). */ /// Guess the character encoding of the string (ascii, utf8 or shift-JIS) static XMLCharEncoding guessCharEncoding(void *buffer, int bufLen, char useXMLEncodingAttribute=1); /**< The "guessCharEncoding" function try to guess the character encoding. You most-probably will never * have to use this function. It then returns the appropriate value of the global parameter * "characterEncoding" described in the XMLNode::setGlobalOptions. The guess is based on the content of a buffer of length * "bufLen" bytes that contains the first bytes (minimum 25 bytes; 200 bytes is a good value) of the * file to be parsed. The XMLNode::openFileHelper function is using this function to automatically compute * the value of the "characterEncoding" global parameter. There are several heuristics used to do the * guess. One of the heuristic is based on the "encoding" attribute. The original XML specifications * forbids to use this attribute to do the guess but you can still use it if you set * "useXMLEncodingAttribute" to 1 (this is the default behavior and the behavior of most parsers). * If an inconsistency in the encoding is detected, then the return value is "0". */ /** @} */ private: // these are functions and structures used internally by the XMLNode class (don't bother about them): typedef struct XMLNodeDataTag // to allow shallow copy and "intelligent/smart" pointers (automatic delete): { XMLCSTR lpszName; // Element name (=NULL if root) int nChild, // Number of child nodes nText, // Number of text fields nClear, // Number of Clear fields (comments) nAttribute; // Number of attributes char isDeclaration; // Whether node is an XML declaration - '' struct XMLNodeDataTag *pParent; // Pointer to parent element (=NULL if root) XMLNode *pChild; // Array of child nodes XMLCSTR *pText; // Array of text fields XMLClear *pClear; // Array of clear fields XMLAttribute *pAttribute; // Array of attributes int *pOrder; // order of the child_nodes,text_fields,clear_fields int ref_count; // for garbage collection (smart pointers) } XMLNodeData; XMLNodeData *d; char parseClearTag(void *px, void *pa); char maybeAddTxT(void *pa, XMLCSTR tokenPStr); int ParseXMLElement(void *pXML); void *addToOrder(int memInc, int *_pos, int nc, void *p, int size, XMLElementType xtype); int indexText(XMLCSTR lpszValue) const; int indexClear(XMLCSTR lpszValue) const; XMLNode addChild_priv(int,XMLSTR,char,int); XMLAttribute *addAttribute_priv(int,XMLSTR,XMLSTR); XMLCSTR addText_priv(int,XMLSTR,int); XMLClear *addClear_priv(int,XMLSTR,XMLCSTR,XMLCSTR,int); void emptyTheNode(char force); static inline XMLElementPosition findPosition(XMLNodeData *d, int index, XMLElementType xtype); static int CreateXMLStringR(XMLNodeData *pEntry, XMLSTR lpszMarker, int nFormat); static int removeOrderElement(XMLNodeData *d, XMLElementType t, int index); static void exactMemory(XMLNodeData *d); static int detachFromParent(XMLNodeData *d); } XMLNode; /// This structure is given by the function XMLNode::enumContents. typedef struct XMLNodeContents { /// This dictates what's the content of the XMLNodeContent enum XMLElementType etype; /**< should be an union to access the appropriate data. Compiler does not allow union of object with constructor... too bad. */ XMLNode child; XMLAttribute attrib; XMLCSTR text; XMLClear clear; } XMLNodeContents; /** @defgroup StringAlloc String Allocation/Free functions * @ingroup xmlModify * @{ */ /// Duplicate (copy in a new allocated buffer) the source string. XMLDLLENTRY XMLSTR stringDup(XMLCSTR source, int cbData=-1); /**< This is * a very handy function when used with all the "XMLNode::*_WOSD" functions (\link xmlWOSD \endlink). * @param cbData If !=0 then cbData is the number of chars to duplicate. New strings allocated with * this function should be free'd using the "freeXMLString" function. */ /// to free the string allocated inside the "stringDup" function or the "createXMLString" function. XMLDLLENTRY void freeXMLString(XMLSTR t); // {free(t);} /** @} */ /** @defgroup atoX ato? like functions * @ingroup XMLParserGeneral * The "xmlto?" functions are equivalents to the atoi, atol, atof functions. * The only difference is: If the variable "xmlString" is NULL, than the return value * is "defautValue". These 6 functions are only here as "convenience" functions for the * user (they are not used inside the XMLparser). If you don't need them, you can * delete them without any trouble. * * @{ */ XMLDLLENTRY char xmltob(XMLCSTR xmlString,char defautValue=0); XMLDLLENTRY int xmltoi(XMLCSTR xmlString,int defautValue=0); XMLDLLENTRY long xmltol(XMLCSTR xmlString,long defautValue=0); XMLDLLENTRY double xmltof(XMLCSTR xmlString,double defautValue=.0); XMLDLLENTRY XMLCSTR xmltoa(XMLCSTR xmlString,XMLCSTR defautValue=_CXML("")); XMLDLLENTRY XMLCHAR xmltoc(XMLCSTR xmlString,const XMLCHAR defautValue=_CXML('\0')); /** @} */ /** @defgroup ToXMLStringTool Helper class to create XML files using "printf", "fprintf", "cout",... functions. * @ingroup XMLParserGeneral * @{ */ /// Helper class to create XML files using "printf", "fprintf", "cout",... functions. /** The ToXMLStringTool class helps you creating XML files using "printf", "fprintf", "cout",... functions. * The "ToXMLStringTool" class is processing strings so that all the characters * &,",',<,> are replaced by their XML equivalent: * \verbatim &, ", ', <, > \endverbatim * Using the "ToXMLStringTool class" and the "fprintf function" is THE most efficient * way to produce VERY large XML documents VERY fast. * \note If you are creating from scratch an XML file using the provided XMLNode class * you must not use the "ToXMLStringTool" class (because the "XMLNode" class does the * processing job for you during rendering).*/ typedef struct XMLDLLENTRY ToXMLStringTool { public: ToXMLStringTool(): buf(NULL),buflen(0){} ~ToXMLStringTool(); void freeBuffer();///= 0.25 Libs: -L${LIB_INSTALL_DIR} -lmusicbrainz5 Cflags: -I${INCLUDE_INSTALL_DIR} libmusicbrainz-5.0.1/src/000077500000000000000000000000001175500222200153155ustar00rootroot00000000000000libmusicbrainz-5.0.1/src/.gitignore000066400000000000000000000001371175500222200173060ustar00rootroot00000000000000CMakeFiles/ Makefile cmake_install.cmake libmusicbrainz5.so* make-c-interface mb5_c.cc mb5_c.h libmusicbrainz-5.0.1/src/Alias.cc000066400000000000000000000075211175500222200166620ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Alias.h" class MusicBrainz5::CAliasPrivate { public: std::string m_Locale; std::string m_Text; std::string m_SortName; std::string m_Type; std::string m_Primary; std::string m_BeginDate; std::string m_EndDate; }; MusicBrainz5::CAlias::CAlias(const XMLNode& Node) : CEntity(), m_d(new CAliasPrivate) { if (!Node.isEmpty()) { //std::cout << "Alias node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); if (Node.getText()) ProcessItem(Node,m_d->m_Text); } } MusicBrainz5::CAlias::CAlias(const CAlias& Other) : CEntity(), m_d(new CAliasPrivate) { *this=Other; } MusicBrainz5::CAlias& MusicBrainz5::CAlias::operator =(const CAlias& Other) { if (this!=&Other) { CEntity::operator =(Other); m_d->m_Locale=Other.m_d->m_Locale; m_d->m_Text=Other.m_d->m_Text; m_d->m_SortName=Other.m_d->m_SortName; m_d->m_Type=Other.m_d->m_Type; m_d->m_Primary=Other.m_d->m_Primary; m_d->m_BeginDate=Other.m_d->m_BeginDate; m_d->m_EndDate=Other.m_d->m_EndDate; } return *this; } MusicBrainz5::CAlias::~CAlias() { delete m_d; } MusicBrainz5::CAlias *MusicBrainz5::CAlias::Clone() { return new CAlias(*this); } void MusicBrainz5::CAlias::ParseAttribute(const std::string& Name, const std::string& Value) { if ("locale"==Name) m_d->m_Locale=Value; else if ("sort-name"==Name) m_d->m_SortName=Value; else if ("type"==Name) m_d->m_Type=Value; else if ("primary"==Name) m_d->m_Primary=Value; else if ("begin-date"==Name) m_d->m_BeginDate=Value; else if ("end-date"==Name) m_d->m_EndDate=Value; else { std::cerr << "Unrecognised alias attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CAlias::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); std::cerr << "Unrecognised alias element: '" << NodeName << std::endl; } std::string MusicBrainz5::CAlias::GetElementName() { return "alias"; } std::string MusicBrainz5::CAlias::Locale() const { return m_d->m_Locale; } std::string MusicBrainz5::CAlias::Text() const { return m_d->m_Text; } std::string MusicBrainz5::CAlias::SortName() const { return m_d->m_SortName; } std::string MusicBrainz5::CAlias::Type() const { return m_d->m_Type; } std::string MusicBrainz5::CAlias::Primary() const { return m_d->m_Primary; } std::string MusicBrainz5::CAlias::BeginDate() const { return m_d->m_BeginDate; } std::string MusicBrainz5::CAlias::EndDate() const { return m_d->m_EndDate; } std::ostream& MusicBrainz5::CAlias::Serialise(std::ostream& os) const { os << "Alias:" << std::endl; CEntity::Serialise(os); os << "\tLocale: " << Locale() << std::endl; os << "\tText: " << Text() << std::endl; os << "\tSort Name: " << SortName() << std::endl; os << "\tType: " << Type() << std::endl; os << "\tPrimary: " << Primary() << std::endl; os << "\tBeginDate: " << BeginDate() << std::endl; os << "\tEndDate: " << EndDate() << std::endl; return os; } libmusicbrainz-5.0.1/src/Annotation.cc000066400000000000000000000064221175500222200177420ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Annotation.h" class MusicBrainz5::CAnnotationPrivate { public: std::string m_Type; std::string m_Entity; std::string m_Name; std::string m_Text; }; MusicBrainz5::CAnnotation::CAnnotation(const XMLNode& Node) : CEntity(), m_d(new CAnnotationPrivate) { if (!Node.isEmpty()) { //std::cout << "Annotation node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CAnnotation::CAnnotation(const CAnnotation& Other) : CEntity(), m_d(new CAnnotationPrivate) { *this=Other; } MusicBrainz5::CAnnotation& MusicBrainz5::CAnnotation::operator =(const CAnnotation& Other) { if (this!=&Other) { CEntity::operator =(Other); m_d->m_Type=Other.m_d->m_Type; m_d->m_Entity=Other.m_d->m_Entity; m_d->m_Name=Other.m_d->m_Name; m_d->m_Text=Other.m_d->m_Text; } return *this; } MusicBrainz5::CAnnotation::~CAnnotation() { delete m_d; } MusicBrainz5::CAnnotation *MusicBrainz5::CAnnotation::Clone() { return new CAnnotation(*this); } void MusicBrainz5::CAnnotation::ParseAttribute(const std::string& Name, const std::string& Value) { if ("type"==Name) m_d->m_Type=Value; else { std::cerr << "Unrecognised annotation attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CAnnotation::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("entity"==NodeName) { ProcessItem(Node,m_d->m_Entity); } else if ("name"==NodeName) { ProcessItem(Node,m_d->m_Name); } else if ("text"==NodeName) { ProcessItem(Node,m_d->m_Text); } else { std::cerr << "Unrecognised annotation element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CAnnotation::GetElementName() { return "annotation"; } std::string MusicBrainz5::CAnnotation::Type() const { return m_d->m_Type; } std::string MusicBrainz5::CAnnotation::Entity() const { return m_d->m_Entity; } std::string MusicBrainz5::CAnnotation::Name() const { return m_d->m_Name; } std::string MusicBrainz5::CAnnotation::Text() const { return m_d->m_Text; } std::ostream& MusicBrainz5::CAnnotation::Serialise(std::ostream& os) const { os << "Annotation:" << std::endl; CEntity::Serialise(os); os << "\tType: " << Type() << std::endl; os << "\tEntity: " << Entity() << std::endl; os << "\tName: " << Name() << std::endl; os << "\tText: " << Text() << std::endl; return os; } libmusicbrainz-5.0.1/src/Artist.cc000066400000000000000000000247221175500222200171010ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Artist.h" #include "musicbrainz5/Lifespan.h" #include "musicbrainz5/IPI.h" #include "musicbrainz5/Rating.h" #include "musicbrainz5/UserRating.h" #include "musicbrainz5/AliasList.h" #include "musicbrainz5/Alias.h" #include "musicbrainz5/RecordingList.h" #include "musicbrainz5/Recording.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/Release.h" #include "musicbrainz5/ReleaseGroupList.h" #include "musicbrainz5/ReleaseGroup.h" #include "musicbrainz5/LabelList.h" #include "musicbrainz5/Label.h" #include "musicbrainz5/WorkList.h" #include "musicbrainz5/Work.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/RelationListList.h" #include "musicbrainz5/Relation.h" #include "musicbrainz5/TagList.h" #include "musicbrainz5/Tag.h" #include "musicbrainz5/UserTagList.h" #include "musicbrainz5/UserTag.h" class MusicBrainz5::CArtistPrivate { public: CArtistPrivate() : m_IPIList(0), m_Lifespan(0), m_AliasList(0), m_RecordingList(0), m_ReleaseList(0), m_ReleaseGroupList(0), m_LabelList(0), m_WorkList(0), m_RelationListList(0), m_TagList(0), m_UserTagList(0), m_Rating(0), m_UserRating(0) { } std::string m_ID; std::string m_Type; std::string m_Name; std::string m_SortName; std::string m_Gender; std::string m_Country; std::string m_Disambiguation; CIPIList *m_IPIList; CLifespan *m_Lifespan; CAliasList *m_AliasList; CRecordingList *m_RecordingList; CReleaseList *m_ReleaseList; CReleaseGroupList *m_ReleaseGroupList; CLabelList *m_LabelList; CWorkList *m_WorkList; CRelationListList *m_RelationListList; CTagList *m_TagList; CUserTagList *m_UserTagList; CRating *m_Rating; CUserRating *m_UserRating; }; MusicBrainz5::CArtist::CArtist(const XMLNode& Node) : CEntity(), m_d(new CArtistPrivate) { if (!Node.isEmpty()) { //std::cout << "Artist node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CArtist::CArtist(const CArtist& Other) : CEntity(), m_d(new CArtistPrivate) { *this=Other; } MusicBrainz5::CArtist& MusicBrainz5::CArtist::operator =(const CArtist& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_ID=Other.m_d->m_ID; m_d->m_Type=Other.m_d->m_Type; m_d->m_Name=Other.m_d->m_Name; m_d->m_SortName=Other.m_d->m_SortName; m_d->m_Gender=Other.m_d->m_Gender; m_d->m_Country=Other.m_d->m_Country; m_d->m_Disambiguation=Other.m_d->m_Disambiguation; if (Other.m_d->m_IPIList) m_d->m_IPIList=new CIPIList(*Other.m_d->m_IPIList); if (Other.m_d->m_Lifespan) m_d->m_Lifespan=new CLifespan(*Other.m_d->m_Lifespan); if (Other.m_d->m_AliasList) m_d->m_AliasList=new CAliasList(*Other.m_d->m_AliasList); if (Other.m_d->m_RecordingList) m_d->m_RecordingList=new CRecordingList(*Other.m_d->m_RecordingList); if (Other.m_d->m_ReleaseList) m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); if (Other.m_d->m_ReleaseGroupList) m_d->m_ReleaseGroupList=new CReleaseGroupList(*Other.m_d->m_ReleaseGroupList); if (Other.m_d->m_LabelList) m_d->m_LabelList=new CLabelList(*Other.m_d->m_LabelList); if (Other.m_d->m_WorkList) m_d->m_WorkList=new CWorkList(*Other.m_d->m_WorkList); if (Other.m_d->m_RelationListList) m_d->m_RelationListList=new CRelationListList(*Other.m_d->m_RelationListList); if (Other.m_d->m_TagList) m_d->m_TagList=new CTagList(*Other.m_d->m_TagList); if (Other.m_d->m_UserTagList) m_d->m_UserTagList=new CUserTagList(*Other.m_d->m_UserTagList); if (Other.m_d->m_Rating) m_d->m_Rating=new CRating(*Other.m_d->m_Rating); if (Other.m_d->m_UserRating) m_d->m_UserRating=new CUserRating(*Other.m_d->m_UserRating); } return *this; } MusicBrainz5::CArtist::~CArtist() { Cleanup(); delete m_d; } void MusicBrainz5::CArtist::Cleanup() { delete m_d->m_IPIList; m_d->m_IPIList=0; delete m_d->m_Lifespan; m_d->m_Lifespan=0; delete m_d->m_AliasList; m_d->m_AliasList=0; delete m_d->m_RecordingList; m_d->m_RecordingList=0; delete m_d->m_ReleaseList; m_d->m_ReleaseList=0; delete m_d->m_ReleaseGroupList; m_d->m_ReleaseGroupList=0; delete m_d->m_LabelList; m_d->m_LabelList=0; delete m_d->m_WorkList; m_d->m_WorkList=0; delete m_d->m_RelationListList; m_d->m_RelationListList=0; delete m_d->m_TagList; m_d->m_TagList=0; delete m_d->m_UserTagList; m_d->m_UserTagList=0; delete m_d->m_Rating; m_d->m_Rating=0; delete m_d->m_UserRating; m_d->m_UserRating=0; } MusicBrainz5::CArtist *MusicBrainz5::CArtist::Clone() { return new CArtist(*this); } void MusicBrainz5::CArtist::ParseAttribute(const std::string& Name, const std::string& Value) { if ("id"==Name) m_d->m_ID=Value; else if ("type"==Name) m_d->m_Type=Value; else { std::cerr << "Unrecognised artist attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CArtist::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("name"==NodeName) { ProcessItem(Node,m_d->m_Name); } else if ("sort-name"==NodeName) { ProcessItem(Node,m_d->m_SortName); } else if ("gender"==NodeName) { ProcessItem(Node,m_d->m_Gender); } else if ("country"==NodeName) { ProcessItem(Node,m_d->m_Country); } else if ("disambiguation"==NodeName) { ProcessItem(Node,m_d->m_Disambiguation); } else if ("ipi"==NodeName) { //Ignore IPI } else if ("ipi-list"==NodeName) { ProcessItem(Node,m_d->m_IPIList); } else if ("life-span"==NodeName) { ProcessItem(Node,m_d->m_Lifespan); } else if ("alias-list"==NodeName) { ProcessItem(Node,m_d->m_AliasList); } else if ("recording-list"==NodeName) { ProcessItem(Node,m_d->m_RecordingList); } else if ("release-list"==NodeName) { ProcessItem(Node,m_d->m_ReleaseList); } else if ("release-group-list"==NodeName) { ProcessItem(Node,m_d->m_ReleaseGroupList); } else if ("label-list"==NodeName) { ProcessItem(Node,m_d->m_LabelList); } else if ("work-list"==NodeName) { ProcessItem(Node,m_d->m_WorkList); } else if ("relation-list"==NodeName) { ProcessRelationList(Node,m_d->m_RelationListList); } else if ("tag-list"==NodeName) { ProcessItem(Node,m_d->m_TagList); } else if ("user-tag-list"==NodeName) { ProcessItem(Node,m_d->m_UserTagList); } else if ("rating"==NodeName) { ProcessItem(Node,m_d->m_Rating); } else if ("user-rating"==NodeName) { ProcessItem(Node,m_d->m_UserRating); } else { std::cerr << "Unrecognised artist element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CArtist::GetElementName() { return "artist"; } std::string MusicBrainz5::CArtist::ID() const { return m_d->m_ID; } std::string MusicBrainz5::CArtist::Type() const { return m_d->m_Type; } std::string MusicBrainz5::CArtist::Name() const { return m_d->m_Name; } std::string MusicBrainz5::CArtist::SortName() const { return m_d->m_SortName; } std::string MusicBrainz5::CArtist::Gender() const { return m_d->m_Gender; } std::string MusicBrainz5::CArtist::Country() const { return m_d->m_Country; } std::string MusicBrainz5::CArtist::Disambiguation() const { return m_d->m_Disambiguation; } MusicBrainz5::CIPIList *MusicBrainz5::CArtist::IPIList() const { return m_d->m_IPIList; } MusicBrainz5::CLifespan *MusicBrainz5::CArtist::Lifespan() const { return m_d->m_Lifespan; } MusicBrainz5::CAliasList *MusicBrainz5::CArtist::AliasList() const { return m_d->m_AliasList; } MusicBrainz5::CRecordingList *MusicBrainz5::CArtist::RecordingList() const { return m_d->m_RecordingList; } MusicBrainz5::CReleaseList *MusicBrainz5::CArtist::ReleaseList() const { return m_d->m_ReleaseList; } MusicBrainz5::CReleaseGroupList *MusicBrainz5::CArtist::ReleaseGroupList() const { return m_d->m_ReleaseGroupList; } MusicBrainz5::CLabelList *MusicBrainz5::CArtist::LabelList() const { return m_d->m_LabelList; } MusicBrainz5::CWorkList *MusicBrainz5::CArtist::WorkList() const { return m_d->m_WorkList; } MusicBrainz5::CRelationListList *MusicBrainz5::CArtist::RelationListList() const { return m_d->m_RelationListList; } MusicBrainz5::CTagList *MusicBrainz5::CArtist::TagList() const { return m_d->m_TagList; } MusicBrainz5::CUserTagList *MusicBrainz5::CArtist::UserTagList() const { return m_d->m_UserTagList; } MusicBrainz5::CRating *MusicBrainz5::CArtist::Rating() const { return m_d->m_Rating; } MusicBrainz5::CUserRating *MusicBrainz5::CArtist::UserRating() const { return m_d->m_UserRating; } std::ostream& MusicBrainz5::CArtist::Serialise(std::ostream& os) const { os << "Artist:" << std::endl; CEntity::Serialise(os); os << "\tID: " << ID() << std::endl; os << "\tType: " << Type() << std::endl; os << "\tName: " << Name() << std::endl; os << "\tSort name: " << SortName() << std::endl; os << "\tGender: " << Gender() << std::endl; os << "\tCountry: " << Country() << std::endl; os << "\tDisambiguation: " << Disambiguation() << std::endl; if (IPIList()) os << *IPIList() << std::endl; if (Lifespan()) os << *Lifespan() << std::endl; if (AliasList()) os << *AliasList() << std::endl; if (RecordingList()) os << *RecordingList() << std::endl; if (ReleaseList()) os << *ReleaseList() << std::endl; if (ReleaseGroupList()) os << *ReleaseGroupList() << std::endl; if (LabelList()) os << *LabelList() << std::endl; if (WorkList()) os << *WorkList() << std::endl; if (RelationListList()) os << *RelationListList() << std::endl; if (TagList()) os << *TagList() << std::endl; if (UserTagList()) os << *UserTagList() << std::endl; if (Rating()) os << *Rating() << std::endl; if (UserRating()) os << *UserRating() << std::endl; return os; } libmusicbrainz-5.0.1/src/ArtistCredit.cc000066400000000000000000000063131175500222200202300ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/ArtistCredit.h" #include "musicbrainz5/NameCreditList.h" #include "musicbrainz5/NameCredit.h" class MusicBrainz5::CArtistCreditPrivate { public: CArtistCreditPrivate() : m_NameCreditList(0) { } CNameCreditList *m_NameCreditList; }; MusicBrainz5::CArtistCredit::CArtistCredit(const XMLNode& Node) : CEntity(), m_d(new CArtistCreditPrivate) { if (!Node.isEmpty()) { //std::cout << "Artist credit node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); m_d->m_NameCreditList=new CNameCreditList(Node); } } MusicBrainz5::CArtistCredit::CArtistCredit(const CArtistCredit& Other) : CEntity(), m_d(new CArtistCreditPrivate) { *this=Other; } MusicBrainz5::CArtistCredit& MusicBrainz5::CArtistCredit::operator =(const CArtistCredit& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); if (Other.m_d->m_NameCreditList) m_d->m_NameCreditList=new CNameCreditList(*Other.m_d->m_NameCreditList); } return *this; } MusicBrainz5::CArtistCredit::~CArtistCredit() { Cleanup(); delete m_d; } void MusicBrainz5::CArtistCredit::Cleanup() { delete m_d->m_NameCreditList; m_d->m_NameCreditList=0; } MusicBrainz5::CArtistCredit *MusicBrainz5::CArtistCredit::Clone() { return new CArtistCredit(*this); } void MusicBrainz5::CArtistCredit::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised artistcredit attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CArtistCredit::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("name-credit"==NodeName) { //The artist credit element is a special case, in that all it contains is a list of name-credits //Parsing of this list is handled in the constructor } else { std::cerr << "Unrecognised artistcredit element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CArtistCredit::GetElementName() { return "artist-credit"; } MusicBrainz5::CNameCreditList *MusicBrainz5::CArtistCredit::NameCreditList() const { return m_d->m_NameCreditList; } std::ostream& MusicBrainz5::CArtistCredit::Serialise(std::ostream& os) const { os << "Artist credit:" << std::endl; CEntity::Serialise(os); if (NameCreditList()) os << *NameCreditList() << std::endl; return os; } libmusicbrainz-5.0.1/src/Attribute.cc000066400000000000000000000050141175500222200175670ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Attribute.h" class MusicBrainz5::CAttributePrivate { public: std::string m_Text; }; MusicBrainz5::CAttribute::CAttribute(const XMLNode& Node) : CEntity(), m_d(new CAttributePrivate) { if (!Node.isEmpty()) { //std::cout << "Attribute node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); if (Node.getText()) ProcessItem(Node,m_d->m_Text); } } MusicBrainz5::CAttribute::CAttribute(const CAttribute& Other) : CEntity(), m_d(new CAttributePrivate) { *this=Other; } MusicBrainz5::CAttribute& MusicBrainz5::CAttribute::operator =(const CAttribute& Other) { if (this!=&Other) { CEntity::operator =(Other); m_d->m_Text=Other.m_d->m_Text; } return *this; } MusicBrainz5::CAttribute::~CAttribute() { delete m_d; } MusicBrainz5::CAttribute *MusicBrainz5::CAttribute::Clone() { return new CAttribute(*this); } void MusicBrainz5::CAttribute::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised attribute attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CAttribute::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); std::cerr << "Unrecognised attribute element: '" << NodeName << "'" << std::endl; } std::string MusicBrainz5::CAttribute::GetElementName() { return "attribute"; } std::string MusicBrainz5::CAttribute::Text() const { return m_d->m_Text; } std::ostream& MusicBrainz5::CAttribute::Serialise(std::ostream& os) const { os << "Attribute:" << std::endl; CEntity::Serialise(os); os << "\tText: " << Text() << std::endl; return os; } libmusicbrainz-5.0.1/src/CDStub.cc000066400000000000000000000101241175500222200167460ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/CDStub.h" #include "musicbrainz5/NonMBTrackList.h" #include "musicbrainz5/NonMBTrack.h" class MusicBrainz5::CCDStubPrivate { public: CCDStubPrivate() : m_NonMBTrackList(0) { } std::string m_ID; std::string m_Title; std::string m_Artist; std::string m_Barcode; std::string m_Comment; CNonMBTrackList *m_NonMBTrackList; }; MusicBrainz5::CCDStub::CCDStub(const XMLNode& Node) : CEntity(), m_d(new CCDStubPrivate) { if (!Node.isEmpty()) { //std::cout << "CDStub node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CCDStub::CCDStub(const CCDStub& Other) : CEntity(), m_d(new CCDStubPrivate) { *this=Other; } MusicBrainz5::CCDStub& MusicBrainz5::CCDStub::operator =(const CCDStub& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_ID=Other.m_d->m_ID; m_d->m_Title=Other.m_d->m_Title; m_d->m_Artist=Other.m_d->m_Artist; m_d->m_Barcode=Other.m_d->m_Barcode; m_d->m_Comment=Other.m_d->m_Comment; if (Other.m_d->m_NonMBTrackList) m_d->m_NonMBTrackList=new CNonMBTrackList(*Other.m_d->m_NonMBTrackList); } return *this; } MusicBrainz5::CCDStub::~CCDStub() { Cleanup(); delete m_d; } void MusicBrainz5::CCDStub::Cleanup() { delete m_d->m_NonMBTrackList; m_d->m_NonMBTrackList=0; } MusicBrainz5::CCDStub *MusicBrainz5::CCDStub::Clone() { return new CCDStub(*this); } void MusicBrainz5::CCDStub::ParseAttribute(const std::string& Name, const std::string& Value) { if ("id"==Name) m_d->m_ID=Value; else { std::cerr << "Unrecognised cdstub attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CCDStub::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("title"==NodeName) { ProcessItem(Node,m_d->m_Title); } else if ("artist"==NodeName) { ProcessItem(Node,m_d->m_Artist); } else if ("barcode"==NodeName) { ProcessItem(Node,m_d->m_Barcode); } else if ("comment"==NodeName) { ProcessItem(Node,m_d->m_Comment); } else if ("track-list"==NodeName) { ProcessItem(Node,m_d->m_NonMBTrackList); } else { std::cerr << "Unrecognised cd stub element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CCDStub::GetElementName() { return "cdstub"; } std::string MusicBrainz5::CCDStub::ID() const { return m_d->m_ID; } std::string MusicBrainz5::CCDStub::Title() const { return m_d->m_Title; } std::string MusicBrainz5::CCDStub::Artist() const { return m_d->m_Artist; } std::string MusicBrainz5::CCDStub::Barcode() const { return m_d->m_Barcode; } std::string MusicBrainz5::CCDStub::Comment() const { return m_d->m_Comment; } MusicBrainz5::CNonMBTrackList *MusicBrainz5::CCDStub::NonMBTrackList() const { return m_d->m_NonMBTrackList; } std::ostream& MusicBrainz5::CCDStub::Serialise(std::ostream& os) const { os << "CDStub:" << std::endl; CEntity::Serialise(os); os << "\tID: " << ID() << std::endl; os << "\tTitle: " << Title() << std::endl; os << "\tArtist: " << Artist() << std::endl; os << "\tBarcode: " << Barcode() << std::endl; os << "\tComment: " << Comment() << std::endl; if (NonMBTrackList()) os << *NonMBTrackList() << std::endl; return os; } libmusicbrainz-5.0.1/src/CMakeLists.txt000066400000000000000000000044371175500222200200650ustar00rootroot00000000000000SET(CMAKE_INCLUDE_CURRENT_DIR ON) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../include ${NEON_INCLUDE_DIR}) SET(_sources Alias.cc Annotation.cc Artist.cc ArtistCredit.cc Attribute.cc CDStub.cc Collection.cc Disc.cc Entity.cc FreeDBDisc.cc HTTPFetch.cc ISRC.cc Label.cc LabelInfo.cc Lifespan.cc List.cc mb5_c.cc Medium.cc MediumList.cc Message.cc Metadata.cc NameCredit.cc NonMBTrack.cc PUID.cc Query.cc Rating.cc Recording.cc Relation.cc RelationList.cc Release.cc ReleaseGroup.cc Tag.cc TextRepresentation.cc Track.cc UserRating.cc UserTag.cc Work.cc xmlParser.cpp RelationListList.cc ISWCList.cc ISWC.cc SecondaryType.cc SecondaryTypeList.cc IPI.cc) ADD_EXECUTABLE(make-c-interface make-c-interface.cc xmlParser.cpp) ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mb5_c.cc ${CMAKE_CURRENT_BINARY_DIR}/mb5_c.h ${CMAKE_CURRENT_BINARY_DIR}/../include/musicbrainz5/mb5_c.h COMMAND make-c-interface ${CMAKE_CURRENT_SOURCE_DIR} cinterface.xml ${CMAKE_CURRENT_BINARY_DIR} mb5_c.cc mb5_c.h COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/mb5_c.h ${CMAKE_CURRENT_BINARY_DIR}/../include/musicbrainz5 DEPENDS make-c-interface cinterface.xml *.inc ) ADD_CUSTOM_TARGET(src_gen DEPENDS mb5_c.h) ADD_LIBRARY(musicbrainz5 SHARED ${_sources}) SET_TARGET_PROPERTIES(musicbrainz5 PROPERTIES VERSION ${musicbrainz5_VERSION} SOVERSION ${musicbrainz5_SOVERSION} DEFINE_SYMBOL MB_API_EXPORTS ) if(CMAKE_BUILD_TYPE STREQUAL Debug) SET_TARGET_PROPERTIES(musicbrainz5 PROPERTIES DEFINE_SYMBOL _MB5_DEBUG_ ) IF(CMAKE_COMPILER_IS_GNUCXX) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -ggdb -O0") ENDIF(CMAKE_COMPILER_IS_GNUCXX) endif(CMAKE_BUILD_TYPE STREQUAL Debug) TARGET_LINK_LIBRARIES(musicbrainz5 ${NEON_LIBRARIES}) IF(WIN32) TARGET_LINK_LIBRARIES(musicbrainz5 wsock32 winmm ws2_32) ENDIF(WIN32) IF(CMAKE_COMPILER_IS_GNUCXX) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic-errors") IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) set_source_files_properties(mb5_c.cc PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations") ENDIF(CMAKE_COMPILER_IS_GNUCXX) INSTALL(TARGETS musicbrainz5 DESTINATION ${LIB_INSTALL_DIR}) libmusicbrainz-5.0.1/src/Collection.cc000066400000000000000000000072011175500222200177170ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Collection.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/Release.h" class MusicBrainz5::CCollectionPrivate { public: CCollectionPrivate() : m_ReleaseList(0) { } std::string m_ID; std::string m_Name; std::string m_Editor; CReleaseList *m_ReleaseList; }; MusicBrainz5::CCollection::CCollection(const XMLNode& Node) : CEntity(), m_d(new CCollectionPrivate) { if (!Node.isEmpty()) { //std::cout << "Medium node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CCollection::CCollection(const CCollection& Other) : CEntity(), m_d(new CCollectionPrivate) { *this=Other; } MusicBrainz5::CCollection& MusicBrainz5::CCollection::operator =(const CCollection& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_ID=Other.m_d->m_ID; m_d->m_Name=Other.m_d->m_Name; m_d->m_Editor=Other.m_d->m_Editor; if (Other.m_d->m_ReleaseList) m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); } return *this; } MusicBrainz5::CCollection::~CCollection() { Cleanup(); delete m_d; } void MusicBrainz5::CCollection::Cleanup() { delete m_d->m_ReleaseList; m_d->m_ReleaseList=0; } MusicBrainz5::CCollection *MusicBrainz5::CCollection::Clone() { return new CCollection(*this); } void MusicBrainz5::CCollection::ParseAttribute(const std::string& Name, const std::string& Value) { if ("id"==Name) m_d->m_ID=Value; else { std::cerr << "Unrecognised collection attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CCollection::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("name"==NodeName) { ProcessItem(Node,m_d->m_Name); } else if ("editor"==NodeName) { ProcessItem(Node,m_d->m_Editor); } else if ("release-list"==NodeName) { ProcessItem(Node,m_d->m_ReleaseList); } else { std::cerr << "Unrecognised collection element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CCollection::GetElementName() { return "collection"; } std::string MusicBrainz5::CCollection::ID() const { return m_d->m_ID; } std::string MusicBrainz5::CCollection::Name() const { return m_d->m_Name; } std::string MusicBrainz5::CCollection::Editor() const { return m_d->m_Editor; } MusicBrainz5::CReleaseList *MusicBrainz5::CCollection::ReleaseList() const { return m_d->m_ReleaseList; } std::ostream& MusicBrainz5::CCollection::Serialise(std::ostream& os) const { os << "Collection:" << std::endl; CEntity::Serialise(os); os << "\tID: " << ID() << std::endl; os << "\tName: " << Name() << std::endl; os << "\tEditor: " << Editor() << std::endl; if (ReleaseList()) os << *ReleaseList() << std::endl; return os; } libmusicbrainz-5.0.1/src/Disc.cc000066400000000000000000000063601175500222200165130ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Disc.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/Release.h" class MusicBrainz5::CDiscPrivate { public: CDiscPrivate() : m_Sectors(0), m_ReleaseList(0) { } std::string m_ID; int m_Sectors; CReleaseList *m_ReleaseList; }; MusicBrainz5::CDisc::CDisc(const XMLNode& Node) : CEntity(), m_d(new CDiscPrivate) { if (!Node.isEmpty()) { //std::cout << "Disc node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CDisc::CDisc(const CDisc& Other) : CEntity(), m_d(new CDiscPrivate) { *this=Other; } MusicBrainz5::CDisc& MusicBrainz5::CDisc::operator =(const CDisc& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_ID=Other.m_d->m_ID; m_d->m_Sectors=Other.m_d->m_Sectors; if (Other.m_d->m_ReleaseList) m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); } return *this; } MusicBrainz5::CDisc::~CDisc() { Cleanup(); delete m_d; } void MusicBrainz5::CDisc::Cleanup() { delete m_d->m_ReleaseList; m_d->m_ReleaseList=0; } MusicBrainz5::CDisc *MusicBrainz5::CDisc::Clone() { return new CDisc(*this); } void MusicBrainz5::CDisc::ParseAttribute(const std::string& Name, const std::string& Value) { if ("id"==Name) ProcessItem(Value,m_d->m_ID); else { std::cerr << "Unrecognised disc attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CDisc::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("sectors"==NodeName) { ProcessItem(Node,m_d->m_Sectors); } else if ("release-list"==NodeName) { ProcessItem(Node,m_d->m_ReleaseList); } else { std::cerr << "Unrecognised disc element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CDisc::GetElementName() { return "disc"; } std::string MusicBrainz5::CDisc::ID() const { return m_d->m_ID; } int MusicBrainz5::CDisc::Sectors() const { return m_d->m_Sectors; } MusicBrainz5::CReleaseList *MusicBrainz5::CDisc::ReleaseList() const { return m_d->m_ReleaseList; } std::ostream& MusicBrainz5::CDisc::Serialise(std::ostream& os) const { os << "Disc:" << std::endl; CEntity::Serialise(os); os << "\tID: " << ID() << std::endl; os << "\tSectors: " << Sectors() << std::endl; if (ReleaseList()) os << *ReleaseList() << std::endl; return os; } libmusicbrainz-5.0.1/src/Entity.cc000066400000000000000000000076351175500222200171130ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Entity.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/RelationListList.h" class MusicBrainz5::CEntityPrivate { public: CEntityPrivate() { } std::map m_ExtAttributes; std::map m_ExtElements; }; MusicBrainz5::CEntity::CEntity() : m_d(new CEntityPrivate) { } MusicBrainz5::CEntity::CEntity(const CEntity& Other) : m_d(new CEntityPrivate) { *this=Other; } MusicBrainz5::CEntity& MusicBrainz5::CEntity::operator =(const CEntity& Other) { if (this!=&Other) { Cleanup(); m_d->m_ExtAttributes=Other.m_d->m_ExtAttributes; m_d->m_ExtElements=Other.m_d->m_ExtElements; } return *this; } MusicBrainz5::CEntity::~CEntity() { Cleanup(); delete m_d; } void MusicBrainz5::CEntity::Cleanup() { } void MusicBrainz5::CEntity::Parse(const XMLNode& Node) { if (!Node.isEmpty()) { for (int count=0;countm_ExtAttributes[Name.substr(4)]=Value; else ParseAttribute(Name,Value); } //std::cout << "Node: " << std::endl << Node.createXMLString(true) << std::endl; for (int count=0;countm_ExtElements[Name.substr(4)]=Value; else ParseElement(ChildNode); } } } std::map MusicBrainz5::CEntity::ExtAttributes() const { return m_d->m_ExtAttributes; } std::map MusicBrainz5::CEntity::ExtElements() const { return m_d->m_ExtElements; } void MusicBrainz5::CEntity::ProcessRelationList(const XMLNode& Node, CRelationListList* & RetVal) { if (0==RetVal) RetVal=new CRelationListList; CRelationList *RelationList=0; ProcessItem(Node,RelationList); RetVal->Add(RelationList); delete RelationList; } std::ostream& MusicBrainz5::CEntity::Serialise(std::ostream& os) const { if (!ExtAttributes().empty()) { os << "Ext attrs: " << std::endl; std::map ExtAttrs=ExtAttributes(); std::map::const_iterator ThisExtAttr=ExtAttrs.begin(); while (ThisExtAttr!=ExtAttrs.end()) { os << (*ThisExtAttr).first << " = " << (*ThisExtAttr).second << std::endl; ++ThisExtAttr; } } if (!ExtElements().empty()) { os << "Ext elements: " << std::endl; std::map ExtElems=ExtElements(); std::map::const_iterator ThisExtElement=ExtElems.begin(); while (ThisExtElement!=ExtElems.end()) { os << (*ThisExtElement).first << " = " << (*ThisExtElement).second << std::endl; ++ThisExtElement; } } return os; } std::ostream& operator << (std::ostream& os, const MusicBrainz5::CEntity& Entity) { return Entity.Serialise(os); } libmusicbrainz-5.0.1/src/FreeDBDisc.cc000066400000000000000000000103311175500222200175140ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/FreeDBDisc.h" #include "musicbrainz5/NonMBTrackList.h" #include "musicbrainz5/NonMBTrack.h" class MusicBrainz5::CFreeDBDiscPrivate { public: CFreeDBDiscPrivate() : m_NonMBTrackList(0) { } std::string m_ID; std::string m_Title; std::string m_Artist; std::string m_Category; std::string m_Year; CNonMBTrackList *m_NonMBTrackList; }; MusicBrainz5::CFreeDBDisc::CFreeDBDisc(const XMLNode& Node) : CEntity(), m_d(new CFreeDBDiscPrivate) { if (!Node.isEmpty()) { //std::cout << "FreeDBDisc node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CFreeDBDisc::CFreeDBDisc(const CFreeDBDisc& Other) : CEntity(), m_d(new CFreeDBDiscPrivate) { *this=Other; } MusicBrainz5::CFreeDBDisc& MusicBrainz5::CFreeDBDisc::operator =(const CFreeDBDisc& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_ID=Other.m_d->m_ID; m_d->m_Title=Other.m_d->m_Title; m_d->m_Artist=Other.m_d->m_Artist; m_d->m_Category=Other.m_d->m_Category; m_d->m_Year=Other.m_d->m_Year; if (Other.m_d->m_NonMBTrackList) m_d->m_NonMBTrackList=new CNonMBTrackList(*Other.m_d->m_NonMBTrackList); } return *this; } MusicBrainz5::CFreeDBDisc::~CFreeDBDisc() { Cleanup(); delete m_d; } void MusicBrainz5::CFreeDBDisc::Cleanup() { delete m_d->m_NonMBTrackList; m_d->m_NonMBTrackList=0; } MusicBrainz5::CFreeDBDisc *MusicBrainz5::CFreeDBDisc::Clone() { return new CFreeDBDisc(*this); } void MusicBrainz5::CFreeDBDisc::ParseAttribute(const std::string& Name, const std::string& Value) { if ("id"==Name) m_d->m_ID=Value; else { std::cerr << "Unrecognised freedb disc attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CFreeDBDisc::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("title"==NodeName) { ProcessItem(Node,m_d->m_Title); } else if ("artist"==NodeName) { ProcessItem(Node,m_d->m_Artist); } else if ("category"==NodeName) { ProcessItem(Node,m_d->m_Category); } else if ("year"==NodeName) { ProcessItem(Node,m_d->m_Year); } else if ("nonmb-track-list"==NodeName) { ProcessItem(Node,m_d->m_NonMBTrackList); } else { std::cerr << "Unrecognised freedb disc element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CFreeDBDisc::GetElementName() { return "freedb-disc"; } std::string MusicBrainz5::CFreeDBDisc::ID() const { return m_d->m_ID; } std::string MusicBrainz5::CFreeDBDisc::Title() const { return m_d->m_Title; } std::string MusicBrainz5::CFreeDBDisc::Artist() const { return m_d->m_Artist; } std::string MusicBrainz5::CFreeDBDisc::Category() const { return m_d->m_Category; } std::string MusicBrainz5::CFreeDBDisc::Year() const { return m_d->m_Year; } MusicBrainz5::CNonMBTrackList *MusicBrainz5::CFreeDBDisc::NonMBTrackList() const { return m_d->m_NonMBTrackList; } std::ostream& MusicBrainz5::CFreeDBDisc::Serialise(std::ostream& os) const { os << "FreeDBDisc:" << std::endl; CEntity::Serialise(os); os << "\tID: " << ID() << std::endl; os << "\tTitle: " << Title() << std::endl; os << "\tArtist: " << Artist() << std::endl; os << "\tCategory: " << Category() << std::endl; os << "\tYear: " << Year() << std::endl; if (NonMBTrackList()) os << *NonMBTrackList() << std::endl; return os; } libmusicbrainz-5.0.1/src/HTTPFetch.cc000066400000000000000000000143451175500222200173640ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/HTTPFetch.h" #include #include #include "ne_session.h" #include "ne_auth.h" #include "ne_string.h" #include "ne_request.h" class MusicBrainz5::CHTTPFetchPrivate { public: CHTTPFetchPrivate() : m_Port(80), m_Result(0), m_Status(0), m_ProxyPort(0) { } std::string m_UserAgent; std::string m_Host; int m_Port; std::vector m_Data; int m_Result; int m_Status; std::string m_ErrorMessage; std::string m_UserName; std::string m_Password; std::string m_ProxyHost; int m_ProxyPort; std::string m_ProxyUserName; std::string m_ProxyPassword; }; MusicBrainz5::CHTTPFetch::CHTTPFetch(const std::string& UserAgent, const std::string& Host, int Port) : m_d(new CHTTPFetchPrivate) { m_d->m_UserAgent=UserAgent; for (std::string::size_type Pos=0;Posm_UserAgent.length();Pos++) if (m_d->m_UserAgent[Pos]=='-') m_d->m_UserAgent[Pos]='/'; m_d->m_Host=Host; m_d->m_Port=Port; // Parse http_proxy environmnent variable const char *http_proxy = getenv("http_proxy"); if (http_proxy) { ne_uri uri; if (!ne_uri_parse(http_proxy, &uri)) { if (uri.host) m_d->m_ProxyHost = uri.host; if (uri.port) m_d->m_ProxyPort = uri.port; if (uri.userinfo) { char *pos = strchr(uri.userinfo, ':'); if (pos) { *pos = '\0'; m_d->m_ProxyUserName = uri.userinfo; m_d->m_ProxyPassword = pos + 1; } else { m_d->m_ProxyUserName = uri.userinfo; } } } ne_uri_free(&uri); } } MusicBrainz5::CHTTPFetch::~CHTTPFetch() { delete m_d; } void MusicBrainz5::CHTTPFetch::SetUserName(const std::string& UserName) { m_d->m_UserName=UserName; } void MusicBrainz5::CHTTPFetch::SetPassword(const std::string& Password) { m_d->m_Password=Password; } void MusicBrainz5::CHTTPFetch::SetProxyHost(const std::string& ProxyHost) { m_d->m_ProxyHost=ProxyHost; } void MusicBrainz5::CHTTPFetch::SetProxyPort(int ProxyPort) { m_d->m_ProxyPort=ProxyPort; } void MusicBrainz5::CHTTPFetch::SetProxyUserName(const std::string& ProxyUserName) { m_d->m_ProxyUserName=ProxyUserName; } void MusicBrainz5::CHTTPFetch::SetProxyPassword(const std::string& ProxyPassword) { m_d->m_ProxyPassword=ProxyPassword; } int MusicBrainz5::CHTTPFetch::Fetch(const std::string& URL, const std::string& Request) { int Ret=0; m_d->m_Data.clear(); ne_sock_init(); ne_session *sess=ne_session_create("http", m_d->m_Host.c_str(), m_d->m_Port); if (sess) { ne_set_useragent(sess, m_d->m_UserAgent.c_str()); ne_set_server_auth(sess, httpAuth, this); // Use proxy server if (!m_d->m_ProxyHost.empty()) { ne_session_proxy(sess, m_d->m_ProxyHost.c_str(), m_d->m_ProxyPort); ne_set_proxy_auth(sess, proxyAuth, this); } ne_request *req = ne_request_create(sess, Request.c_str(), URL.c_str()); if (Request=="PUT") ne_set_request_body_buffer(req,0,0); if (Request!="GET") ne_set_request_flag(req, NE_REQFLAG_IDEMPOTENT, 0); ne_add_response_body_reader(req, ne_accept_2xx, httpResponseReader, &m_d->m_Data); m_d->m_Result = ne_request_dispatch(req); m_d->m_Status = ne_get_status(req)->code; Ret=m_d->m_Data.size(); ne_request_destroy(req); m_d->m_ErrorMessage = ne_get_error(sess); ne_session_destroy(sess); switch (m_d->m_Result) { case NE_OK: break; case NE_CONNECT: case NE_LOOKUP: throw CConnectionError(m_d->m_ErrorMessage); break; case NE_TIMEOUT: throw CTimeoutError(m_d->m_ErrorMessage); break; case NE_AUTH: case NE_PROXYAUTH: throw CAuthenticationError(m_d->m_ErrorMessage); break; default: throw CFetchError(m_d->m_ErrorMessage); break; } switch (m_d->m_Status) { case 200: break; case 400: throw CRequestError(m_d->m_ErrorMessage); break; case 401: throw CAuthenticationError(m_d->m_ErrorMessage); break; case 404: throw CResourceNotFoundError(m_d->m_ErrorMessage); break; default: throw CFetchError(m_d->m_ErrorMessage); break; } } ne_sock_exit(); return Ret; } int MusicBrainz5::CHTTPFetch::httpAuth(void *userdata, const char *realm, int attempts, char *username, char *password) { realm=realm; MusicBrainz5::CHTTPFetch *Fetch = (MusicBrainz5::CHTTPFetch *)userdata; strncpy(username, Fetch->m_d->m_UserName.c_str(), NE_ABUFSIZ); strncpy(password, Fetch->m_d->m_Password.c_str(), NE_ABUFSIZ); return attempts; } int MusicBrainz5::CHTTPFetch::proxyAuth(void *userdata, const char *realm, int attempts, char *username, char *password) { realm=realm; MusicBrainz5::CHTTPFetch *Fetch = (MusicBrainz5::CHTTPFetch *)userdata; strncpy(username, Fetch->m_d->m_ProxyUserName.c_str(), NE_ABUFSIZ); strncpy(password, Fetch->m_d->m_ProxyPassword.c_str(), NE_ABUFSIZ); return attempts; } int MusicBrainz5::CHTTPFetch::httpResponseReader(void *userdata, const char *buf, size_t len) { std::vector *buffer = reinterpret_cast *>(userdata); buffer->insert(buffer->end(),buf,buf+len); return 0; } std::vector MusicBrainz5::CHTTPFetch::Data() const { return m_d->m_Data; } int MusicBrainz5::CHTTPFetch::Result() const { return m_d->m_Result; } int MusicBrainz5::CHTTPFetch::Status() const { return m_d->m_Status; } std::string MusicBrainz5::CHTTPFetch::ErrorMessage() const { return m_d->m_ErrorMessage; } libmusicbrainz-5.0.1/src/IPI.cc000066400000000000000000000045721175500222200162550ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/IPI.h" class MusicBrainz5::CIPIPrivate { public: CIPIPrivate() { } std::string m_IPI; }; MusicBrainz5::CIPI::CIPI(const XMLNode& Node) : CEntity(), m_d(new CIPIPrivate) { if (!Node.isEmpty()) { //std::cout << "IPI node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); if (Node.getText()) { ProcessItem(Node,m_d->m_IPI); } } } MusicBrainz5::CIPI::CIPI(const CIPI& Other) : CEntity(), m_d(new CIPIPrivate) { *this=Other; } MusicBrainz5::CIPI& MusicBrainz5::CIPI::operator =(const CIPI& Other) { if (this!=&Other) { CEntity::operator =(Other); m_d->m_IPI=Other.m_d->m_IPI; } return *this; } MusicBrainz5::CIPI::~CIPI() { delete m_d; } MusicBrainz5::CIPI *MusicBrainz5::CIPI::Clone() { return new CIPI(*this); } void MusicBrainz5::CIPI::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised IPI attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CIPI::ParseElement(const XMLNode& Node) { std::string Name=Node.getName(); std::cerr << "Unrecognised IPI element: '" << Name << "'" << std::endl; } std::string MusicBrainz5::CIPI::GetElementName() { return "ipi"; } std::string MusicBrainz5::CIPI::IPI() const { return m_d->m_IPI; } std::ostream& MusicBrainz5::CIPI::Serialise(std::ostream& os) const { os << "IPI:" << std::endl; CEntity::Serialise(os); os << "\tIPI: " << IPI() << std::endl; return os; } libmusicbrainz-5.0.1/src/ISRC.cc000066400000000000000000000057721175500222200163770ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/ISRC.h" #include "musicbrainz5/RecordingList.h" #include "musicbrainz5/Recording.h" class MusicBrainz5::CISRCPrivate { public: CISRCPrivate() : m_RecordingList(0) { } std::string m_ID; CRecordingList *m_RecordingList; }; MusicBrainz5::CISRC::CISRC(const XMLNode& Node) : CEntity(), m_d(new CISRCPrivate) { if (!Node.isEmpty()) { //std::cout << "ISRC node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CISRC::CISRC(const CISRC& Other) : CEntity(), m_d(new CISRCPrivate) { *this=Other; } MusicBrainz5::CISRC& MusicBrainz5::CISRC::operator =(const CISRC& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_ID=Other.m_d->m_ID; if (Other.m_d->m_RecordingList) m_d->m_RecordingList=new CRecordingList(*Other.m_d->m_RecordingList); } return *this; } MusicBrainz5::CISRC::~CISRC() { Cleanup(); delete m_d; } void MusicBrainz5::CISRC::Cleanup() { delete m_d->m_RecordingList; m_d->m_RecordingList=0; } MusicBrainz5::CISRC *MusicBrainz5::CISRC::Clone() { return new CISRC(*this); } void MusicBrainz5::CISRC::ParseAttribute(const std::string& Name, const std::string& Value) { if ("id"==Name) m_d->m_ID=Value; else { std::cerr << "Unrecognised isrc attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CISRC::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("recording-list"==NodeName) { ProcessItem(Node,m_d->m_RecordingList); } else { std::cerr << "Unrecognised ISRC element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CISRC::GetElementName() { return "isrc"; } std::string MusicBrainz5::CISRC::ID() const { return m_d->m_ID; } MusicBrainz5::CRecordingList *MusicBrainz5::CISRC::RecordingList() const { return m_d->m_RecordingList; } std::ostream& MusicBrainz5::CISRC::Serialise(std::ostream& os) const { os << "ISRC:" << std::endl; CEntity::Serialise(os); os << "\tID: " << ID() << std::endl; if (RecordingList()) os << *RecordingList() << std::endl; return os; } libmusicbrainz-5.0.1/src/ISWC.cc000066400000000000000000000047001175500222200163720ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/ISWC.h" class MusicBrainz5::CISWCPrivate { public: CISWCPrivate() { } std::string m_ISWC; }; MusicBrainz5::CISWC::CISWC(const XMLNode& Node) : CEntity(), m_d(new CISWCPrivate) { if (!Node.isEmpty()) { //std::cout << "ISWC node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); if (Node.getText()) ProcessItem(Node,m_d->m_ISWC); } } MusicBrainz5::CISWC::CISWC(const CISWC& Other) : CEntity(), m_d(new CISWCPrivate) { *this=Other; } MusicBrainz5::CISWC& MusicBrainz5::CISWC::operator =(const CISWC& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_ISWC=Other.m_d->m_ISWC; } return *this; } MusicBrainz5::CISWC::~CISWC() { Cleanup(); delete m_d; } void MusicBrainz5::CISWC::Cleanup() { } MusicBrainz5::CISWC *MusicBrainz5::CISWC::Clone() { return new CISWC(*this); } void MusicBrainz5::CISWC::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised ISWC attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CISWC::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); std::cerr << "Unrecognised ISWC element: '" << NodeName << "'" << std::endl; } std::string MusicBrainz5::CISWC::GetElementName() { return "iswc"; } std::string MusicBrainz5::CISWC::ISWC() const { return m_d->m_ISWC; } std::ostream& MusicBrainz5::CISWC::Serialise(std::ostream& os) const { os << "ISWC:" << std::endl; CEntity::Serialise(os); os << "\tISWC: " << ISWC() << std::endl; return os; } libmusicbrainz-5.0.1/src/ISWCList.cc000066400000000000000000000043631175500222200172330ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/ISWCList.h" #include "musicbrainz5/ISWC.h" class MusicBrainz5::CISWCListPrivate { public: CISWCListPrivate() { } }; MusicBrainz5::CISWCList::CISWCList(const XMLNode& Node) : CListImpl(), m_d(new CISWCListPrivate) { if (!Node.isEmpty()) { //std::cout << "ISWCList node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CISWCList::CISWCList(const CISWCList& Other) : CListImpl(), m_d(new CISWCListPrivate) { *this=Other; } MusicBrainz5::CISWCList& MusicBrainz5::CISWCList::operator =(const CISWCList& Other) { if (this!=&Other) { CListImpl::operator =(Other); } return *this; } MusicBrainz5::CISWCList::~CISWCList() { delete m_d; } MusicBrainz5::CISWCList *MusicBrainz5::CISWCList::Clone() { return new CISWCList(*this); } void MusicBrainz5::CISWCList::ParseAttribute(const std::string& Name, const std::string& Value) { CListImpl::ParseAttribute(Name,Value); } void MusicBrainz5::CISWCList::ParseElement(const XMLNode& Node) { CListImpl::ParseElement(Node); } std::string MusicBrainz5::CISWCList::GetElementName() { return "iswc-list"; } std::ostream& MusicBrainz5::CISWCList::Serialise(std::ostream& os) const { os << "ISWC list:" << std::endl; CListImpl::Serialise(os); return os; } libmusicbrainz-5.0.1/src/Label.cc000066400000000000000000000206231175500222200166460ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Label.h" #include #include "musicbrainz5/Lifespan.h" #include "musicbrainz5/IPI.h" #include "musicbrainz5/Rating.h" #include "musicbrainz5/UserRating.h" #include "musicbrainz5/Alias.h" #include "musicbrainz5/AliasList.h" #include "musicbrainz5/Release.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/Relation.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/RelationListList.h" #include "musicbrainz5/Tag.h" #include "musicbrainz5/TagList.h" #include "musicbrainz5/UserTag.h" #include "musicbrainz5/UserTagList.h" class MusicBrainz5::CLabelPrivate { public: CLabelPrivate() : m_LabelCode(0), m_IPIList(0), m_Lifespan(0), m_AliasList(0), m_ReleaseList(0), m_RelationListList(0), m_TagList(0), m_UserTagList(0), m_Rating(0), m_UserRating(0) { } std::string m_ID; std::string m_Type; std::string m_Name; std::string m_SortName; int m_LabelCode; CIPIList *m_IPIList; std::string m_Disambiguation; std::string m_Country; CLifespan *m_Lifespan; CAliasList *m_AliasList; CReleaseList *m_ReleaseList; CRelationListList *m_RelationListList; CTagList *m_TagList; CUserTagList *m_UserTagList; CRating *m_Rating; CUserRating *m_UserRating; }; MusicBrainz5::CLabel::CLabel(const XMLNode& Node) : CEntity(), m_d(new CLabelPrivate) { if (!Node.isEmpty()) { //std::cout << "Label node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CLabel::CLabel(const CLabel& Other) : CEntity(), m_d(new CLabelPrivate) { *this=Other; } MusicBrainz5::CLabel& MusicBrainz5::CLabel::operator =(const CLabel& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_ID=Other.m_d->m_ID; m_d->m_Type=Other.m_d->m_Type; m_d->m_Name=Other.m_d->m_Name; m_d->m_SortName=Other.m_d->m_SortName; m_d->m_LabelCode=Other.m_d->m_LabelCode; if (Other.m_d->m_IPIList) m_d->m_IPIList=new CIPIList(*Other.m_d->m_IPIList); m_d->m_Disambiguation=Other.m_d->m_Disambiguation; m_d->m_Country=Other.m_d->m_Country; if (Other.m_d->m_Lifespan) m_d->m_Lifespan=new CLifespan(*Other.m_d->m_Lifespan); if (Other.m_d->m_AliasList) m_d->m_AliasList=new CAliasList(*Other.m_d->m_AliasList); if (Other.m_d->m_ReleaseList) m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); if (Other.m_d->m_RelationListList) m_d->m_RelationListList=new CRelationListList(*Other.m_d->m_RelationListList); if (Other.m_d->m_TagList) m_d->m_TagList=new CTagList(*Other.m_d->m_TagList); if (Other.m_d->m_UserTagList) m_d->m_UserTagList=new CUserTagList(*Other.m_d->m_UserTagList); if (Other.m_d->m_Rating) m_d->m_Rating=new CRating(*Other.m_d->m_Rating); if (Other.m_d->m_UserRating) m_d->m_UserRating=new CUserRating(*Other.m_d->m_UserRating); } return *this; } MusicBrainz5::CLabel::~CLabel() { Cleanup(); delete m_d; } void MusicBrainz5::CLabel::Cleanup() { delete m_d->m_IPIList; m_d->m_IPIList=0; delete m_d->m_Lifespan; m_d->m_Lifespan=0; delete m_d->m_AliasList; m_d->m_AliasList=0; delete m_d->m_ReleaseList; m_d->m_ReleaseList=0; delete m_d->m_RelationListList; m_d->m_RelationListList=0; delete m_d->m_TagList; m_d->m_TagList=0; delete m_d->m_UserTagList; m_d->m_UserTagList=0; delete m_d->m_Rating; m_d->m_Rating=0; delete m_d->m_UserRating; m_d->m_UserRating=0; } MusicBrainz5::CLabel *MusicBrainz5::CLabel::Clone() { return new CLabel(*this); } void MusicBrainz5::CLabel::ParseAttribute(const std::string& Name, const std::string& Value) { if ("id"==Name) m_d->m_ID=Value; else if ("type"==Name) m_d->m_Type=Value; else { std::cerr << "Unrecognised label attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CLabel::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("name"==NodeName) { ProcessItem(Node,m_d->m_Name); } else if ("sort-name"==NodeName) { ProcessItem(Node,m_d->m_SortName); } else if ("label-code"==NodeName) { ProcessItem(Node,m_d->m_LabelCode); } else if ("ipi"==NodeName) { //Ignore IPI } else if ("ipi-list"==NodeName) { ProcessItem(Node,m_d->m_IPIList); } else if ("disambiguation"==NodeName) { ProcessItem(Node,m_d->m_Disambiguation); } else if ("country"==NodeName) { ProcessItem(Node,m_d->m_Country); } else if ("life-span"==NodeName) { ProcessItem(Node,m_d->m_Lifespan); } else if ("alias-list"==NodeName) { ProcessItem(Node,m_d->m_AliasList); } else if ("release-list"==NodeName) { ProcessItem(Node,m_d->m_ReleaseList); } else if ("relation-list"==NodeName) { ProcessRelationList(Node,m_d->m_RelationListList); } else if ("tag-list"==NodeName) { ProcessItem(Node,m_d->m_TagList); } else if ("user-tag-list"==NodeName) { ProcessItem(Node,m_d->m_UserTagList); } else if ("rating"==NodeName) { ProcessItem(Node,m_d->m_Rating); } else if ("user-rating"==NodeName) { ProcessItem(Node,m_d->m_UserRating); } else { std::cerr << "Unrecognised label element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CLabel::GetElementName() { return "label"; } std::string MusicBrainz5::CLabel::ID() const { return m_d->m_ID; } std::string MusicBrainz5::CLabel::Type() const { return m_d->m_Type; } std::string MusicBrainz5::CLabel::Name() const { return m_d->m_Name; } std::string MusicBrainz5::CLabel::SortName() const { return m_d->m_SortName; } int MusicBrainz5::CLabel::LabelCode() const { return m_d->m_LabelCode; } MusicBrainz5::CIPIList *MusicBrainz5::CLabel::IPIList() const { return m_d->m_IPIList; } std::string MusicBrainz5::CLabel::Disambiguation() const { return m_d->m_Disambiguation; } std::string MusicBrainz5::CLabel::Country() const { return m_d->m_Country; } MusicBrainz5::CLifespan *MusicBrainz5::CLabel::Lifespan() const { return m_d->m_Lifespan; } MusicBrainz5::CAliasList *MusicBrainz5::CLabel::AliasList() const { return m_d->m_AliasList; } MusicBrainz5::CReleaseList *MusicBrainz5::CLabel::ReleaseList() const { return m_d->m_ReleaseList; } MusicBrainz5::CRelationListList *MusicBrainz5::CLabel::RelationListList() const { return m_d->m_RelationListList; } MusicBrainz5::CTagList *MusicBrainz5::CLabel::TagList() const { return m_d->m_TagList; } MusicBrainz5::CUserTagList *MusicBrainz5::CLabel::UserTagList() const { return m_d->m_UserTagList; } MusicBrainz5::CRating *MusicBrainz5::CLabel::Rating() const { return m_d->m_Rating; } MusicBrainz5::CUserRating *MusicBrainz5::CLabel::UserRating() const { return m_d->m_UserRating; } std::ostream& MusicBrainz5::CLabel::Serialise(std::ostream& os) const { os << "Label:" << std::endl; CEntity::Serialise(os); os << "\tID: " << ID() << std::endl; os << "\tType: " << Type() << std::endl; os << "\tName: " << Name() << std::endl; os << "\tSort name: " << SortName() << std::endl; os << "\tLabel code: " << LabelCode() << std::endl; if (IPIList()) os << *IPIList() << std::endl; os << "\tDisambiguation: " << Disambiguation() << std::endl; os << "\tCountry: " << Country() << std::endl; if (Lifespan()) os << *Lifespan() << std::endl; if (AliasList()) os << *AliasList() << std::endl; if (ReleaseList()) os << *ReleaseList() << std::endl; if (RelationListList()) os << *RelationListList() << std::endl; if (TagList()) os << *TagList() << std::endl; if (UserTagList()) os << *UserTagList() << std::endl; if (Rating()) os << *Rating() << std::endl; if (UserRating()) os << *UserRating() << std::endl; return os; } libmusicbrainz-5.0.1/src/LabelInfo.cc000066400000000000000000000061361175500222200174650ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/LabelInfo.h" #include "musicbrainz5/Label.h" class MusicBrainz5::CLabelInfoPrivate { public: CLabelInfoPrivate() : m_Label(0) { } std::string m_CatalogNumber; CLabel *m_Label; }; MusicBrainz5::CLabelInfo::CLabelInfo(const XMLNode& Node) : CEntity(), m_d(new CLabelInfoPrivate) { if (!Node.isEmpty()) { //std::cout << "Label info node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CLabelInfo::CLabelInfo(const CLabelInfo& Other) : CEntity(), m_d(new CLabelInfoPrivate) { *this=Other; } MusicBrainz5::CLabelInfo& MusicBrainz5::CLabelInfo::operator =(const CLabelInfo& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_CatalogNumber=Other.m_d->m_CatalogNumber; if (Other.m_d->m_Label) m_d->m_Label=new CLabel(*Other.m_d->m_Label); } return *this; } MusicBrainz5::CLabelInfo::~CLabelInfo() { Cleanup(); delete m_d; } void MusicBrainz5::CLabelInfo::Cleanup() { delete m_d->m_Label; m_d->m_Label=0; } MusicBrainz5::CLabelInfo *MusicBrainz5::CLabelInfo::Clone() { return new CLabelInfo(*this); } void MusicBrainz5::CLabelInfo::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised labelinfo attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CLabelInfo::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("catalog-number"==NodeName) { ProcessItem(Node,m_d->m_CatalogNumber); } else if ("label"==NodeName) { ProcessItem(Node,m_d->m_Label); } else { std::cerr << "Unrecognised label info element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CLabelInfo::GetElementName() { return "label-info"; } std::string MusicBrainz5::CLabelInfo::CatalogNumber() const { return m_d->m_CatalogNumber; } MusicBrainz5::CLabel *MusicBrainz5::CLabelInfo::Label() const { return m_d->m_Label; } std::ostream& MusicBrainz5::CLabelInfo::Serialise(std::ostream& os) const { os << "Label info:" << std::endl; CEntity::Serialise(os); os << "\tCatalog number: " << CatalogNumber() << std::endl; if (Label()) os << *Label() << std::endl; return os; } libmusicbrainz-5.0.1/src/Lifespan.cc000066400000000000000000000057551175500222200174010ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Lifespan.h" class MusicBrainz5::CLifespanPrivate { public: std::string m_Begin; std::string m_End; std::string m_Ended; }; MusicBrainz5::CLifespan::CLifespan(const XMLNode& Node) : CEntity(), m_d(new CLifespanPrivate) { if (!Node.isEmpty()) { //std::cout << "Lifespan node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CLifespan::CLifespan(const CLifespan& Other) : CEntity(), m_d(new CLifespanPrivate) { *this=Other; } MusicBrainz5::CLifespan& MusicBrainz5::CLifespan::operator =(const CLifespan& Other) { if (this!=&Other) { CEntity::operator =(Other); m_d->m_Begin=Other.m_d->m_Begin; m_d->m_End=Other.m_d->m_End; m_d->m_Ended=Other.m_d->m_Ended; } return *this; } MusicBrainz5::CLifespan::~CLifespan() { delete m_d; } MusicBrainz5::CLifespan *MusicBrainz5::CLifespan::Clone() { return new CLifespan(*this); } void MusicBrainz5::CLifespan::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised lifespan attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CLifespan::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("begin"==NodeName) { ProcessItem(Node,m_d->m_Begin); } else if ("end"==NodeName) { ProcessItem(Node,m_d->m_End); } else if ("ended"==NodeName) { ProcessItem(Node,m_d->m_Ended); } else { std::cerr << "Unrecognised lifespan element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CLifespan::GetElementName() { return "life-span"; } std::string MusicBrainz5::CLifespan::Begin() const { return m_d->m_Begin; } std::string MusicBrainz5::CLifespan::End() const { return m_d->m_End; } std::string MusicBrainz5::CLifespan::Ended() const { return m_d->m_Ended; } std::ostream& MusicBrainz5::CLifespan::Serialise(std::ostream& os) const { os << "Lifespan:" << std::endl; CEntity::Serialise(os); os << "\tBegin: " << Begin() << std::endl; os << "\tEnd: " << End() << std::endl; os << "\tEnded: " << Ended() << std::endl; return os; } libmusicbrainz-5.0.1/src/List.cc000066400000000000000000000063101175500222200165370ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/List.h" #include class MusicBrainz5::CListPrivate { public: CListPrivate() : m_Offset(0), m_Count(0) { } int m_Offset; int m_Count; std::vector m_Items; }; MusicBrainz5::CList::CList() : CEntity(), m_d(new CListPrivate) { } MusicBrainz5::CList::CList(const CList& Other) : CEntity(), m_d(new CListPrivate) { *this=Other; } MusicBrainz5::CList& MusicBrainz5::CList::operator =(const CList& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_Offset=Other.m_d->m_Offset; m_d->m_Count=Other.m_d->m_Count; std::vector::const_iterator ThisItem=Other.m_d->m_Items.begin(); while (ThisItem!=Other.m_d->m_Items.end()) { CEntity *Item=(*ThisItem); m_d->m_Items.push_back(Item->Clone()); ++ThisItem; } } return *this; } MusicBrainz5::CList::~CList() { Cleanup(); delete m_d; } void MusicBrainz5::CList::Cleanup() { while (!m_d->m_Items.empty()) { delete m_d->m_Items.back(); m_d->m_Items.pop_back(); } } MusicBrainz5::CList *MusicBrainz5::CList::Clone() { return new CList(*this); } void MusicBrainz5::CList::ParseAttribute(const std::string& Name, const std::string& Value) { if ("offset"==Name) ProcessItem(Value,m_d->m_Offset); else if ("count"==Name) ProcessItem(Value,m_d->m_Count); else { std::cerr << "Unrecognised list attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CList::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); std::cerr << "Unrecognised list element: '" << NodeName << "'" << std::endl; } std::string MusicBrainz5::CList::GetElementName() { return ""; } void MusicBrainz5::CList::AddItem(CEntity *Item) { m_d->m_Items.push_back(Item); } int MusicBrainz5::CList::NumItems() const { return m_d->m_Items.size(); } MusicBrainz5::CEntity *MusicBrainz5::CList::Item(int Item) const { CEntity *Ret=0; if (Itemm_Items[Item]; return Ret; } int MusicBrainz5::CList::Offset() const { return m_d->m_Offset; } int MusicBrainz5::CList::Count() const { return m_d->m_Count; } std::ostream& MusicBrainz5::CList::Serialise(std::ostream& os) const { os << "List: " << std::endl; os << "Offset: " << Offset() << std::endl; os << "Count: " << Count() << std::endl; return os; } libmusicbrainz-5.0.1/src/Medium.cc000066400000000000000000000105031175500222200170430ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Medium.h" #include "musicbrainz5/Disc.h" #include "musicbrainz5/DiscList.h" #include "musicbrainz5/Track.h" #include "musicbrainz5/TrackList.h" class MusicBrainz5::CMediumPrivate { public: CMediumPrivate() : m_Position(0), m_DiscList(0), m_TrackList(0) { } std::string m_Title; int m_Position; std::string m_Format; CDiscList *m_DiscList; CTrackList *m_TrackList; }; MusicBrainz5::CMedium::CMedium(const XMLNode& Node) : CEntity(), m_d(new CMediumPrivate) { if (!Node.isEmpty()) { //std::cout << "Medium node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CMedium::CMedium(const CMedium& Other) : CEntity(), m_d(new CMediumPrivate) { *this=Other; } MusicBrainz5::CMedium& MusicBrainz5::CMedium::operator =(const CMedium& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_Title=Other.m_d->m_Title; m_d->m_Position=Other.m_d->m_Position; m_d->m_Format=Other.m_d->m_Format; if (Other.m_d->m_DiscList) m_d->m_DiscList=new CDiscList(*Other.m_d->m_DiscList); if (Other.m_d->m_TrackList) m_d->m_TrackList=new CTrackList(*Other.m_d->m_TrackList); } return *this; } MusicBrainz5::CMedium::~CMedium() { Cleanup(); delete m_d; } void MusicBrainz5::CMedium::Cleanup() { delete m_d->m_DiscList; m_d->m_DiscList=0; delete m_d->m_TrackList; m_d->m_TrackList=0; } MusicBrainz5::CMedium *MusicBrainz5::CMedium::Clone() { return new CMedium(*this); } void MusicBrainz5::CMedium::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised medium attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CMedium::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("title"==NodeName) { ProcessItem(Node,m_d->m_Title); } else if ("position"==NodeName) { ProcessItem(Node,m_d->m_Position); } else if ("format"==NodeName) { ProcessItem(Node,m_d->m_Format); } else if ("disc-list"==NodeName) { ProcessItem(Node,m_d->m_DiscList); } else if ("track-list"==NodeName) { ProcessItem(Node,m_d->m_TrackList); } else { std::cerr << "Unrecognised medium element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CMedium::GetElementName() { return "medium"; } std::string MusicBrainz5::CMedium::Title() const { return m_d->m_Title; } int MusicBrainz5::CMedium::Position() const { return m_d->m_Position; } std::string MusicBrainz5::CMedium::Format() const { return m_d->m_Format; } MusicBrainz5::CDiscList *MusicBrainz5::CMedium::DiscList() const { return m_d->m_DiscList; } MusicBrainz5::CTrackList *MusicBrainz5::CMedium::TrackList() const { return m_d->m_TrackList; } bool MusicBrainz5::CMedium::ContainsDiscID(const std::string& DiscID) const { bool RetVal=false; if (m_d->m_DiscList) { for (int count=0;!RetVal && countm_DiscList->NumItems();count++) { CDisc *Disc=m_d->m_DiscList->Item(count); if (Disc->ID()==DiscID) RetVal=true; } } return RetVal; } std::ostream& MusicBrainz5::CMedium::Serialise(std::ostream& os) const { os << "Medium:" << std::endl; CEntity::Serialise(os); os << "\tTitle: " << Title() << std::endl; os << "\tPosition: " << Position() << std::endl; os << "\tFormat: " << Format() << std::endl; if (DiscList()) os << *DiscList() << std::endl; if (TrackList()) os << *TrackList() << std::endl; return os; } libmusicbrainz-5.0.1/src/MediumList.cc000066400000000000000000000052231175500222200177020ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/MediumList.h" #include "musicbrainz5/Medium.h" class MusicBrainz5::CMediumListPrivate { public: CMediumListPrivate() : m_TrackCount(0) { } int m_TrackCount; }; MusicBrainz5::CMediumList::CMediumList(const XMLNode& Node) : CListImpl(), m_d(new CMediumListPrivate) { if (!Node.isEmpty()) { //std::cout << "MediumList node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CMediumList::CMediumList(const CMediumList& Other) : CListImpl(), m_d(new CMediumListPrivate) { *this=Other; } MusicBrainz5::CMediumList& MusicBrainz5::CMediumList::operator =(const CMediumList& Other) { if (this!=&Other) { CListImpl::operator =(Other); m_d->m_TrackCount=Other.m_d->m_TrackCount; } return *this; } MusicBrainz5::CMediumList::~CMediumList() { delete m_d; } MusicBrainz5::CMediumList *MusicBrainz5::CMediumList::Clone() { return new CMediumList(*this); } void MusicBrainz5::CMediumList::ParseAttribute(const std::string& Name, const std::string& Value) { CListImpl::ParseAttribute(Name,Value); } void MusicBrainz5::CMediumList::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("track-count"==NodeName) { ProcessItem(Node,m_d->m_TrackCount); } else { CListImpl::ParseElement(Node); } } std::string MusicBrainz5::CMediumList::GetElementName() { return "medium-list"; } int MusicBrainz5::CMediumList::TrackCount() const { return m_d->m_TrackCount; } std::ostream& MusicBrainz5::CMediumList::Serialise(std::ostream& os) const { os << "Medium list:" << std::endl; os << "\tTrack count: " << TrackCount() << std::endl; CListImpl::Serialise(os); return os; } libmusicbrainz-5.0.1/src/Message.cc000066400000000000000000000047371175500222200172230ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Message.h" class MusicBrainz5::CMessagePrivate { public: std::string m_Text; }; MusicBrainz5::CMessage::CMessage(const XMLNode& Node) : CEntity(), m_d(new CMessagePrivate) { if (!Node.isEmpty()) { //std::cout << "Message node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CMessage::CMessage(const CMessage& Other) : CEntity(), m_d(new CMessagePrivate) { *this=Other; } MusicBrainz5::CMessage& MusicBrainz5::CMessage::operator =(const CMessage& Other) { if (this!=&Other) { CEntity::operator =(Other); m_d->m_Text=Other.m_d->m_Text; } return *this; } MusicBrainz5::CMessage::~CMessage() { delete m_d; } MusicBrainz5::CMessage *MusicBrainz5::CMessage::Clone() { return new CMessage(*this); } void MusicBrainz5::CMessage::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised message attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CMessage::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if (NodeName=="text") ProcessItem(Node,m_d->m_Text); else { std::cerr << "Unrecognised message element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CMessage::GetElementName() { return "message"; } std::string MusicBrainz5::CMessage::Text() const { return m_d->m_Text; } std::ostream& MusicBrainz5::CMessage::Serialise(std::ostream& os) const { os << "Message:" << std::endl; CEntity::Serialise(os); os << "\tText: " << Text() << std::endl; return os; } libmusicbrainz-5.0.1/src/Metadata.cc000066400000000000000000000374401175500222200173540ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Metadata.h" #include "musicbrainz5/Artist.h" #include "musicbrainz5/ArtistList.h" #include "musicbrainz5/Release.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/ReleaseGroup.h" #include "musicbrainz5/ReleaseGroupList.h" #include "musicbrainz5/Recording.h" #include "musicbrainz5/RecordingList.h" #include "musicbrainz5/Label.h" #include "musicbrainz5/LabelList.h" #include "musicbrainz5/Work.h" #include "musicbrainz5/WorkList.h" #include "musicbrainz5/PUID.h" #include "musicbrainz5/ISRC.h" #include "musicbrainz5/ISRCList.h" #include "musicbrainz5/Disc.h" #include "musicbrainz5/Rating.h" #include "musicbrainz5/UserRating.h" #include "musicbrainz5/Collection.h" #include "musicbrainz5/CollectionList.h" #include "musicbrainz5/Annotation.h" #include "musicbrainz5/AnnotationList.h" #include "musicbrainz5/CDStub.h" #include "musicbrainz5/CDStubList.h" #include "musicbrainz5/FreeDBDisc.h" #include "musicbrainz5/FreeDBDiscList.h" #include "musicbrainz5/Tag.h" #include "musicbrainz5/TagList.h" #include "musicbrainz5/UserTag.h" #include "musicbrainz5/UserTagList.h" #include "musicbrainz5/LabelInfo.h" #include "musicbrainz5/LabelInfoList.h" #include "musicbrainz5/Message.h" class MusicBrainz5::CMetadataPrivate { public: CMetadataPrivate() : m_Artist(0), m_Release(0), m_ReleaseGroup(0), m_Recording(0), m_Label(0), m_Work(0), m_PUID(0), m_ISRC(0), m_Disc(0), m_LabelInfoList(0), m_Rating(0), m_UserRating(0), m_Collection(0), m_ArtistList(0), m_ReleaseList(0), m_ReleaseGroupList(0), m_RecordingList(0), m_LabelList(0), m_WorkList(0), m_ISRCList(0), m_AnnotationList(0), m_CDStubList(0), m_FreeDBDiscList(0), m_TagList(0), m_UserTagList(0), m_CollectionList(0), m_CDStub(0), m_Message(0) { } std::string m_XMLNS; std::string m_XMLNSExt; std::string m_Generator; std::string m_Created; CArtist *m_Artist; CRelease *m_Release; CReleaseGroup *m_ReleaseGroup; CRecording *m_Recording; CLabel *m_Label; CWork *m_Work; CPUID *m_PUID; CISRC *m_ISRC; CDisc *m_Disc; CLabelInfoList *m_LabelInfoList; CRating *m_Rating; CUserRating *m_UserRating; CCollection *m_Collection; CArtistList *m_ArtistList; CReleaseList *m_ReleaseList; CReleaseGroupList *m_ReleaseGroupList; CRecordingList *m_RecordingList; CLabelList *m_LabelList; CWorkList *m_WorkList; CISRCList *m_ISRCList; CAnnotationList *m_AnnotationList; CCDStubList *m_CDStubList; CFreeDBDiscList *m_FreeDBDiscList; CTagList *m_TagList; CUserTagList *m_UserTagList; CCollectionList *m_CollectionList; CCDStub *m_CDStub; CMessage *m_Message; }; MusicBrainz5::CMetadata::CMetadata(const XMLNode& Node) : CEntity(), m_d(new CMetadataPrivate) { if (!Node.isEmpty()) { //std::cout << "Metadata node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CMetadata::CMetadata(const CMetadata& Other) : CEntity(), m_d(new CMetadataPrivate) { *this=Other; } MusicBrainz5::CMetadata& MusicBrainz5::CMetadata::operator =(const CMetadata& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_XMLNS=Other.m_d->m_XMLNS; m_d->m_XMLNSExt=Other.m_d->m_XMLNSExt; m_d->m_Generator=Other.m_d->m_Generator; m_d->m_Created=Other.m_d->m_Created; if (Other.m_d->m_Artist) m_d->m_Artist=new CArtist(*Other.m_d->m_Artist); if (Other.m_d->m_Release) m_d->m_Release=new CRelease(*Other.m_d->m_Release); if (Other.m_d->m_ReleaseGroup) m_d->m_ReleaseGroup=new CReleaseGroup(*Other.m_d->m_ReleaseGroup); if (Other.m_d->m_Recording) m_d->m_Recording=new CRecording(*Other.m_d->m_Recording); if (Other.m_d->m_Label) m_d->m_Label=new CLabel(*Other.m_d->m_Label); if (Other.m_d->m_Work) m_d->m_Work=new CWork(*Other.m_d->m_Work); if (Other.m_d->m_PUID) m_d->m_PUID=new CPUID(*Other.m_d->m_PUID); if (Other.m_d->m_ISRC) m_d->m_ISRC=new CISRC(*Other.m_d->m_ISRC); if (Other.m_d->m_Disc) m_d->m_Disc=new CDisc(*Other.m_d->m_Disc); if (Other.m_d->m_LabelInfoList) m_d->m_LabelInfoList=new CLabelInfoList(*Other.m_d->m_LabelInfoList); if (Other.m_d->m_Rating) m_d->m_Rating=new CRating(*Other.m_d->m_Rating); if (Other.m_d->m_UserRating) m_d->m_UserRating=new CUserRating(*Other.m_d->m_UserRating); if (Other.m_d->m_Collection) m_d->m_Collection=new CCollection(*Other.m_d->m_Collection); if (Other.m_d->m_ArtistList) m_d->m_ArtistList=new CArtistList(*Other.m_d->m_ArtistList); if (Other.m_d->m_ReleaseList) m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); if (Other.m_d->m_ReleaseGroupList) m_d->m_ReleaseGroupList=new CReleaseGroupList(*Other.m_d->m_ReleaseGroupList); if (Other.m_d->m_RecordingList) m_d->m_RecordingList=new CRecordingList(*Other.m_d->m_RecordingList); if (Other.m_d->m_LabelList) m_d->m_LabelList=new CLabelList(*Other.m_d->m_LabelList); if (Other.m_d->m_WorkList) m_d->m_WorkList=new CWorkList(*Other.m_d->m_WorkList); if (Other.m_d->m_ISRCList) m_d->m_ISRCList=new CISRCList(*Other.m_d->m_ISRCList); if (Other.m_d->m_AnnotationList) m_d->m_AnnotationList=new CAnnotationList(*Other.m_d->m_AnnotationList); if (Other.m_d->m_CDStubList) m_d->m_CDStubList=new CCDStubList(*Other.m_d->m_CDStubList); if (Other.m_d->m_FreeDBDiscList) m_d->m_FreeDBDiscList=new CFreeDBDiscList(*Other.m_d->m_FreeDBDiscList); if (Other.m_d->m_TagList) m_d->m_TagList=new CTagList(*Other.m_d->m_TagList); if (Other.m_d->m_UserTagList) m_d->m_UserTagList=new CUserTagList(*Other.m_d->m_UserTagList); if (Other.m_d->m_CollectionList) m_d->m_CollectionList=new CCollectionList(*Other.m_d->m_CollectionList); if (Other.m_d->m_CDStub) m_d->m_CDStub=new CCDStub(*Other.m_d->m_CDStub); if (Other.m_d->m_Message) m_d->m_Message=new CMessage(*Other.m_d->m_Message); } return *this; } MusicBrainz5::CMetadata::~CMetadata() { Cleanup(); delete m_d; } void MusicBrainz5::CMetadata::Cleanup() { delete m_d->m_Artist; m_d->m_Artist=0; delete m_d->m_Release; m_d->m_Release=0; delete m_d->m_ReleaseGroup; m_d->m_ReleaseGroup=0; delete m_d->m_Recording; m_d->m_Recording=0; delete m_d->m_Label; m_d->m_Label=0; delete m_d->m_Work; m_d->m_Work=0; delete m_d->m_PUID; m_d->m_PUID=0; delete m_d->m_ISRC; m_d->m_ISRC=0; delete m_d->m_Disc; m_d->m_Disc=0; delete m_d->m_LabelInfoList; m_d->m_LabelInfoList=0; delete m_d->m_Rating; m_d->m_Rating=0; delete m_d->m_UserRating; m_d->m_UserRating=0; delete m_d->m_Collection; m_d->m_Collection=0; delete m_d->m_ArtistList; m_d->m_ArtistList=0; delete m_d->m_ReleaseList; m_d->m_ReleaseList=0; delete m_d->m_ReleaseGroupList; m_d->m_ReleaseGroupList=0; delete m_d->m_RecordingList; m_d->m_RecordingList=0; delete m_d->m_LabelList; m_d->m_LabelList=0; delete m_d->m_WorkList; m_d->m_WorkList=0; delete m_d->m_ISRCList; m_d->m_ISRCList=0; delete m_d->m_AnnotationList; m_d->m_AnnotationList=0; delete m_d->m_CDStubList; m_d->m_CDStubList=0; delete m_d->m_FreeDBDiscList; m_d->m_FreeDBDiscList=0; delete m_d->m_TagList; m_d->m_TagList=0; delete m_d->m_UserTagList; m_d->m_UserTagList=0; delete m_d->m_CollectionList; m_d->m_CollectionList=0; delete m_d->m_CDStub; m_d->m_CDStub=0; delete m_d->m_Message; m_d->m_Message=0; } MusicBrainz5::CMetadata *MusicBrainz5::CMetadata::Clone() { return new CMetadata(*this); } void MusicBrainz5::CMetadata::ParseAttribute(const std::string& Name, const std::string& Value) { if ("xmlns"==Name) m_d->m_XMLNS=Value; else if ("xmlns:ext"==Name) m_d->m_XMLNSExt=Value; else if ("generator"==Name) m_d->m_Generator=Value; else if ("created"==Name) m_d->m_Created=Value; else { std::cerr << "Unrecognised metadata attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CMetadata::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("artist"==NodeName) { ProcessItem(Node,m_d->m_Artist); } else if ("release"==NodeName) { ProcessItem(Node,m_d->m_Release); } else if ("release-group"==NodeName) { ProcessItem(Node,m_d->m_ReleaseGroup); } else if ("recording"==NodeName) { ProcessItem(Node,m_d->m_Recording); } else if ("label"==NodeName) { ProcessItem(Node,m_d->m_Label); } else if ("work"==NodeName) { ProcessItem(Node,m_d->m_Work); } else if ("puid"==NodeName) { ProcessItem(Node,m_d->m_PUID); } else if ("isrc"==NodeName) { ProcessItem(Node,m_d->m_ISRC); } else if ("disc"==NodeName) { ProcessItem(Node,m_d->m_Disc); } else if ("rating"==NodeName) { ProcessItem(Node,m_d->m_Rating); } else if ("user-rating"==NodeName) { ProcessItem(Node,m_d->m_UserRating); } else if ("collection"==NodeName) { ProcessItem(Node,m_d->m_Collection); } else if ("artist-list"==NodeName) { ProcessItem(Node,m_d->m_ArtistList); } else if ("release-list"==NodeName) { ProcessItem(Node,m_d->m_ReleaseList); } else if ("release-group-list"==NodeName) { ProcessItem(Node,m_d->m_ReleaseGroupList); } else if ("recording-list"==NodeName) { ProcessItem(Node,m_d->m_RecordingList); } else if ("label-list"==NodeName) { ProcessItem(Node,m_d->m_LabelList); } else if ("work-list"==NodeName) { ProcessItem(Node,m_d->m_WorkList); } else if ("isrc-list"==NodeName) { ProcessItem(Node,m_d->m_ISRCList); } else if ("annotation-list"==NodeName) { ProcessItem(Node,m_d->m_AnnotationList); } else if ("cdstub-list"==NodeName) { ProcessItem(Node,m_d->m_CDStubList); } else if ("freedb-disc-list"==NodeName) { ProcessItem(Node,m_d->m_FreeDBDiscList); } else if ("tag-list"==NodeName) { ProcessItem(Node,m_d->m_TagList); } else if ("user-tag-list"==NodeName) { ProcessItem(Node,m_d->m_UserTagList); } else if ("collection-list"==NodeName) { ProcessItem(Node,m_d->m_CollectionList); } else if ("cdstub"==NodeName) { ProcessItem(Node,m_d->m_CDStub); } else if ("message"==NodeName) { ProcessItem(Node,m_d->m_Message); } else { std::cerr << "Unrecognised metadata element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CMetadata::GetElementName() { return "metadata"; } std::string MusicBrainz5::CMetadata::XMLNS() const { return m_d->m_XMLNS; } std::string MusicBrainz5::CMetadata::XMLNSExt() const { return m_d->m_XMLNSExt; } std::string MusicBrainz5::CMetadata::Generator() const { return m_d->m_Generator; } std::string MusicBrainz5::CMetadata::Created() const { return m_d->m_Created; } MusicBrainz5::CArtist *MusicBrainz5::CMetadata::Artist() const { return m_d->m_Artist; } MusicBrainz5::CRelease *MusicBrainz5::CMetadata::Release() const { return m_d->m_Release; } MusicBrainz5::CReleaseGroup *MusicBrainz5::CMetadata::ReleaseGroup() const { return m_d->m_ReleaseGroup; } MusicBrainz5::CRecording *MusicBrainz5::CMetadata::Recording() const { return m_d->m_Recording; } MusicBrainz5::CLabel *MusicBrainz5::CMetadata::Label() const { return m_d->m_Label; } MusicBrainz5::CWork *MusicBrainz5::CMetadata::Work() const { return m_d->m_Work; } MusicBrainz5::CPUID *MusicBrainz5::CMetadata::PUID() const { return m_d->m_PUID; } MusicBrainz5::CISRC *MusicBrainz5::CMetadata::ISRC() const { return m_d->m_ISRC; } MusicBrainz5::CDisc *MusicBrainz5::CMetadata::Disc() const { return m_d->m_Disc; } MusicBrainz5::CLabelInfoList *MusicBrainz5::CMetadata::LabelInfoList() const { return m_d->m_LabelInfoList; } MusicBrainz5::CRating *MusicBrainz5::CMetadata::Rating() const { return m_d->m_Rating; } MusicBrainz5::CUserRating *MusicBrainz5::CMetadata::UserRating() const { return m_d->m_UserRating; } MusicBrainz5::CCollection *MusicBrainz5::CMetadata::Collection() const { return m_d->m_Collection; } MusicBrainz5::CArtistList *MusicBrainz5::CMetadata::ArtistList() const { return m_d->m_ArtistList; } MusicBrainz5::CReleaseList *MusicBrainz5::CMetadata::ReleaseList() const { return m_d->m_ReleaseList; } MusicBrainz5::CReleaseGroupList *MusicBrainz5::CMetadata::ReleaseGroupList() const { return m_d->m_ReleaseGroupList; } MusicBrainz5::CRecordingList *MusicBrainz5::CMetadata::RecordingList() const { return m_d->m_RecordingList; } MusicBrainz5::CLabelList *MusicBrainz5::CMetadata::LabelList() const { return m_d->m_LabelList; } MusicBrainz5::CWorkList *MusicBrainz5::CMetadata::WorkList() const { return m_d->m_WorkList; } MusicBrainz5::CISRCList *MusicBrainz5::CMetadata::ISRCList() const { return m_d->m_ISRCList; } MusicBrainz5::CAnnotationList *MusicBrainz5::CMetadata::AnnotationList() const { return m_d->m_AnnotationList; } MusicBrainz5::CCDStubList *MusicBrainz5::CMetadata::CDStubList() const { return m_d->m_CDStubList; } MusicBrainz5::CFreeDBDiscList *MusicBrainz5::CMetadata::FreeDBDiscList() const { return m_d->m_FreeDBDiscList; } MusicBrainz5::CTagList *MusicBrainz5::CMetadata::TagList() const { return m_d->m_TagList; } MusicBrainz5::CUserTagList *MusicBrainz5::CMetadata::UserTagList() const { return m_d->m_UserTagList; } MusicBrainz5::CCollectionList *MusicBrainz5::CMetadata::CollectionList() const { return m_d->m_CollectionList; } MusicBrainz5::CCDStub *MusicBrainz5::CMetadata::CDStub() const { return m_d->m_CDStub; } MusicBrainz5::CMessage *MusicBrainz5::CMetadata::Message() const { return m_d->m_Message; } std::ostream& MusicBrainz5::CMetadata::Serialise(std::ostream& os) const { os << "Metadata:" << std::endl; CEntity::Serialise(os); os << "XMLNS: " << XMLNS() << std::endl; os << "XMLNS-Ext: " << XMLNSExt() << std::endl; os << "Generator: " << Generator() << std::endl; os << "Created: " << Created() << std::endl; if (Artist()) os << *Artist() << std::endl; if (Release()) os << *Release() << std::endl; if (ReleaseGroup()) os << *ReleaseGroup() << std::endl; if (Recording()) os << *Recording() << std::endl; if (Label()) os << *Label() << std::endl; if (Work()) os << *Work() << std::endl; if (PUID()) os << *PUID() << std::endl; if (ISRC()) os << *ISRC() << std::endl; if (Disc()) os << *Disc() << std::endl; if (LabelInfoList()) os << *LabelInfoList() << std::endl; if (UserRating()) os << *UserRating() << std::endl; if (Collection()) os << *Collection() << std::endl; if (ArtistList()) os << *ArtistList() << std::endl; if (ReleaseList()) os << *ReleaseList() << std::endl; if (ReleaseGroupList()) os << *ReleaseGroupList() << std::endl; if (RecordingList()) os << *RecordingList() << std::endl; if (LabelList()) os << *LabelList() << std::endl; if (WorkList()) os << *WorkList() << std::endl; if (ISRCList()) os << *ISRCList() << std::endl; if (AnnotationList()) os << *AnnotationList() << std::endl; if (CDStubList()) os << *CDStubList() << std::endl; if (FreeDBDiscList()) os << *FreeDBDiscList() << std::endl; if (TagList()) os << *TagList() << std::endl; if (UserTagList()) os << *UserTagList() << std::endl; if (CollectionList()) os << *CollectionList() << std::endl; if (CDStub()) os << *CDStub() << std::endl; if (Message()) os << *Message() << std::endl; return os; } libmusicbrainz-5.0.1/src/NameCredit.cc000066400000000000000000000065311175500222200176440ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/NameCredit.h" #include "musicbrainz5/Artist.h" class MusicBrainz5::CNameCreditPrivate { public: CNameCreditPrivate() : m_Artist(0) { } std::string m_JoinPhrase; std::string m_Name; CArtist *m_Artist; }; MusicBrainz5::CNameCredit::CNameCredit(const XMLNode& Node) : CEntity(), m_d(new CNameCreditPrivate) { if (!Node.isEmpty()) { //std::cout << "Name credit node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CNameCredit::CNameCredit(const CNameCredit& Other) : CEntity(), m_d(new CNameCreditPrivate) { *this=Other; } MusicBrainz5::CNameCredit& MusicBrainz5::CNameCredit::operator =(const CNameCredit& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_JoinPhrase=Other.m_d->m_JoinPhrase; m_d->m_Name=Other.m_d->m_Name; if (Other.m_d->m_Artist) m_d->m_Artist=new CArtist(*Other.m_d->m_Artist); } return *this; } MusicBrainz5::CNameCredit::~CNameCredit() { Cleanup(); delete m_d; } void MusicBrainz5::CNameCredit::Cleanup() { delete m_d->m_Artist; m_d->m_Artist=0; } MusicBrainz5::CNameCredit *MusicBrainz5::CNameCredit::Clone() { return new CNameCredit(*this); } void MusicBrainz5::CNameCredit::ParseAttribute(const std::string& Name, const std::string& Value) { if ("joinphrase"==Name) m_d->m_JoinPhrase=Value; else { std::cerr << "Unrecognised namecredit attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CNameCredit::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("name"==NodeName) { ProcessItem(Node,m_d->m_Name); } else if ("artist"==NodeName) { ProcessItem(Node,m_d->m_Artist); } else { std::cerr << "Unrecognised name credit element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CNameCredit::GetElementName() { return "name-credit"; } std::string MusicBrainz5::CNameCredit::JoinPhrase() const { return m_d->m_JoinPhrase; } std::string MusicBrainz5::CNameCredit::Name() const { return m_d->m_Name; } MusicBrainz5::CArtist *MusicBrainz5::CNameCredit::Artist() const { return m_d->m_Artist; } std::ostream& MusicBrainz5::CNameCredit::Serialise(std::ostream& os) const { os << "Name credit:" << std::endl; CEntity::Serialise(os); os << "\tJoin phrase: " << JoinPhrase() << std::endl; os << "\tName: " << Name() << std::endl; if (Artist()) os << *Artist() << std::endl; return os; } libmusicbrainz-5.0.1/src/NonMBTrack.cc000066400000000000000000000061501175500222200175640ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/NonMBTrack.h" class MusicBrainz5::CNonMBTrackPrivate { public: CNonMBTrackPrivate() : m_Length(0) { } std::string m_Title; std::string m_Artist; int m_Length; }; MusicBrainz5::CNonMBTrack::CNonMBTrack(const XMLNode& Node) : CEntity(), m_d(new CNonMBTrackPrivate) { if (!Node.isEmpty()) { //std::cout << "NonMBTrack node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CNonMBTrack::CNonMBTrack(const CNonMBTrack& Other) : CEntity(), m_d(new CNonMBTrackPrivate) { *this=Other; } MusicBrainz5::CNonMBTrack& MusicBrainz5::CNonMBTrack::operator =(const CNonMBTrack& Other) { if (this!=&Other) { CEntity::operator =(Other); m_d->m_Title=Other.m_d->m_Title; m_d->m_Artist=Other.m_d->m_Artist; m_d->m_Length=Other.m_d->m_Length; } return *this; } MusicBrainz5::CNonMBTrack::~CNonMBTrack() { delete m_d; } MusicBrainz5::CNonMBTrack *MusicBrainz5::CNonMBTrack::Clone() { return new CNonMBTrack(*this); } void MusicBrainz5::CNonMBTrack::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised non MB track attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CNonMBTrack::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("title"==NodeName) { ProcessItem(Node,m_d->m_Title); } else if ("artist"==NodeName) { ProcessItem(Node,m_d->m_Artist); } else if ("length"==NodeName) { ProcessItem(Node,m_d->m_Length); } else { std::cerr << "Unrecognised non MB track element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CNonMBTrack::GetElementName() { return "track"; } std::string MusicBrainz5::CNonMBTrack::Title() const { return m_d->m_Title; } std::string MusicBrainz5::CNonMBTrack::Artist() const { return m_d->m_Artist; } int MusicBrainz5::CNonMBTrack::Length() const { return m_d->m_Length; } std::ostream& MusicBrainz5::CNonMBTrack::Serialise(std::ostream& os) const { os << "NonMBTrack:" << std::endl; CEntity::Serialise(os); os << "\tTitle: " << Title() << std::endl; os << "\tArtist: " << Artist() << std::endl; os << "\tLength: " << Length() << std::endl; return os; } libmusicbrainz-5.0.1/src/PUID.cc000066400000000000000000000057721175500222200164000ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/PUID.h" #include "musicbrainz5/RecordingList.h" #include "musicbrainz5/Recording.h" class MusicBrainz5::CPUIDPrivate { public: CPUIDPrivate() : m_RecordingList(0) { } std::string m_ID; CRecordingList *m_RecordingList; }; MusicBrainz5::CPUID::CPUID(const XMLNode& Node) : CEntity(), m_d(new CPUIDPrivate) { if (!Node.isEmpty()) { //std::cout << "PUID node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CPUID::CPUID(const CPUID& Other) : CEntity(), m_d(new CPUIDPrivate) { *this=Other; } MusicBrainz5::CPUID& MusicBrainz5::CPUID::operator =(const CPUID& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_ID=Other.m_d->m_ID; if (Other.m_d->m_RecordingList) m_d->m_RecordingList=new CRecordingList(*Other.m_d->m_RecordingList); } return *this; } MusicBrainz5::CPUID::~CPUID() { Cleanup(); delete m_d; } void MusicBrainz5::CPUID::Cleanup() { delete m_d->m_RecordingList; m_d->m_RecordingList=0; } MusicBrainz5::CPUID *MusicBrainz5::CPUID::Clone() { return new CPUID(*this); } void MusicBrainz5::CPUID::ParseAttribute(const std::string& Name, const std::string& Value) { if ("id"==Name) m_d->m_ID=Value; else { std::cerr << "Unrecognised puid attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CPUID::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("recording-list"==NodeName) { ProcessItem(Node,m_d->m_RecordingList); } else { std::cerr << "Unrecognised PUID element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CPUID::GetElementName() { return "puid"; } std::string MusicBrainz5::CPUID::ID() const { return m_d->m_ID; } MusicBrainz5::CRecordingList *MusicBrainz5::CPUID::RecordingList() const { return m_d->m_RecordingList; } std::ostream& MusicBrainz5::CPUID::Serialise(std::ostream& os) const { os << "PUID:" << std::endl; CEntity::Serialise(os); os << "\tID: " << ID() << std::endl; if (RecordingList()) os << *RecordingList() << std::endl; return os; } libmusicbrainz-5.0.1/src/Query.cc000066400000000000000000000273711175500222200167430ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ //http://musicbrainz.org/doc/XML_Web_Service/Version_2 //http://bugs.musicbrainz.org/browser/mmd-schema/trunk/schema/musicbrainz_mmd-2.0.rng //http://wiki.musicbrainz.org/Picard_Tag_Mapping #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Query.h" #include #include #include #include #include #include #include "musicbrainz5/HTTPFetch.h" #include "musicbrainz5/Disc.h" #include "musicbrainz5/Message.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/Release.h" class MusicBrainz5::CQueryPrivate { public: CQueryPrivate() : m_Port(80), m_ProxyPort(0), m_LastResult(CQuery::eQuery_Success), m_LastHTTPCode(200) { } std::string m_UserAgent; std::string m_Server; int m_Port; std::string m_UserName; std::string m_Password; std::string m_ProxyHost; int m_ProxyPort; std::string m_ProxyUserName; std::string m_ProxyPassword; CQuery::tQueryResult m_LastResult; int m_LastHTTPCode; std::string m_LastErrorMessage; }; MusicBrainz5::CQuery::CQuery(const std::string& UserAgent, const std::string& Server, int Port) : m_d(new CQueryPrivate) { m_d->m_UserAgent=UserAgent; m_d->m_Server=Server; m_d->m_Port=Port; } MusicBrainz5::CQuery::~CQuery() { delete m_d; } void MusicBrainz5::CQuery::SetUserName(const std::string& UserName) { m_d->m_UserName=UserName; } void MusicBrainz5::CQuery::SetPassword(const std::string& Password) { m_d->m_Password=Password; } void MusicBrainz5::CQuery::SetProxyHost(const std::string& ProxyHost) { m_d->m_ProxyHost=ProxyHost; } void MusicBrainz5::CQuery::SetProxyPort(int ProxyPort) { m_d->m_ProxyPort=ProxyPort; } void MusicBrainz5::CQuery::SetProxyUserName(const std::string& ProxyUserName) { m_d->m_ProxyUserName=ProxyUserName; } void MusicBrainz5::CQuery::SetProxyPassword(const std::string& ProxyPassword) { m_d->m_ProxyPassword=ProxyPassword; } MusicBrainz5::CMetadata MusicBrainz5::CQuery::PerformQuery(const std::string& Query) { WaitRequest(); CMetadata Metadata; CHTTPFetch Fetch(UserAgent(),m_d->m_Server,m_d->m_Port); if (!m_d->m_UserName.empty()) Fetch.SetUserName(m_d->m_UserName); if (!m_d->m_Password.empty()) Fetch.SetPassword(m_d->m_Password); if (!m_d->m_ProxyHost.empty()) Fetch.SetProxyHost(m_d->m_ProxyHost); if (0!=m_d->m_ProxyPort) Fetch.SetProxyPort(m_d->m_ProxyPort); if (!m_d->m_ProxyUserName.empty()) Fetch.SetProxyUserName(m_d->m_ProxyUserName); if (!m_d->m_ProxyPassword.empty()) Fetch.SetProxyPassword(m_d->m_ProxyPassword); try { int Ret=Fetch.Fetch(Query); #ifdef _MB5_DEBUG_ std::cerr << "Ret: " << Ret << std::endl; #endif if (Ret>0) { std::vector Data=Fetch.Data(); std::string strData(Data.begin(),Data.end()); #ifdef _MB5_DEBUG_ std::cerr << "Ret is '" << strData << "'" << std::endl; #endif XMLResults Results; XMLNode TopNode=XMLNode::parseString(strData.c_str(), 0, &Results); if (Results.error==eXMLErrorNone) { XMLNode MetadataNode=TopNode.getChildNode("metadata"); if (!MetadataNode.isEmpty()) { Metadata=CMetadata(MetadataNode); } } } } catch (CConnectionError& Error) { m_d->m_LastResult=CQuery::eQuery_ConnectionError; m_d->m_LastHTTPCode=Fetch.Status(); m_d->m_LastErrorMessage=Fetch.ErrorMessage(); throw; } catch (CTimeoutError& Error) { m_d->m_LastResult=CQuery::eQuery_Timeout; m_d->m_LastHTTPCode=Fetch.Status(); m_d->m_LastErrorMessage=Fetch.ErrorMessage(); throw; } catch (CAuthenticationError& Error) { m_d->m_LastResult=CQuery::eQuery_AuthenticationError; m_d->m_LastHTTPCode=Fetch.Status(); m_d->m_LastErrorMessage=Fetch.ErrorMessage(); throw; } catch (CFetchError& Error) { m_d->m_LastResult=CQuery::eQuery_FetchError; m_d->m_LastHTTPCode=Fetch.Status(); m_d->m_LastErrorMessage=Fetch.ErrorMessage(); throw; } catch (CRequestError& Error) { m_d->m_LastResult=CQuery::eQuery_RequestError; m_d->m_LastHTTPCode=Fetch.Status(); m_d->m_LastErrorMessage=Fetch.ErrorMessage(); throw; } catch (CResourceNotFoundError& Error) { m_d->m_LastResult=CQuery::eQuery_ResourceNotFound; m_d->m_LastHTTPCode=Fetch.Status(); m_d->m_LastErrorMessage=Fetch.ErrorMessage(); throw; } return Metadata; } MusicBrainz5::CMetadata MusicBrainz5::CQuery::Query(const std::string& Entity, const std::string& ID, const std::string& Resource, const tParamMap& Params) { std::stringstream os; os << "/ws/2/" << Entity; if (!ID.empty()) { os << "/" << ID; if (!Resource.empty()) os << "/" << Resource; } if (!Params.empty()) os << "?" << URLEncode(Params); #ifdef _MB5_DEBUG_ std::cerr << "Query is '" << os.str() << "'" << std::endl; #endif return PerformQuery(os.str()); } MusicBrainz5::CReleaseList MusicBrainz5::CQuery::LookupDiscID(const std::string& DiscID) { //Will this work soon (and return disc IDs as well)? //http://musicbrainz.org/ws/2/discid/arIS30RPWowvwNEqsqdDnZzDGhk-?inc=artists+labels+recordings+release-groups+artist-credits MusicBrainz5::CReleaseList ReleaseList; CMetadata Metadata=Query("discid",DiscID); CDisc *Disc=Metadata.Disc(); if (Disc && Disc->ReleaseList()) ReleaseList=*Disc->ReleaseList(); return ReleaseList; } MusicBrainz5::CRelease MusicBrainz5::CQuery::LookupRelease(const std::string& ReleaseID) { MusicBrainz5::CRelease Release; tParamMap Params; Params["inc"]="artists labels recordings release-groups url-rels discids artist-credits"; CMetadata Metadata=Query("release",ReleaseID,"",Params); if (Metadata.Release()) Release=*Metadata.Release(); return Release; } void MusicBrainz5::CQuery::WaitRequest() const { if (m_d->m_Server.find("musicbrainz.org")!=std::string::npos) { static struct timeval LastRequest; const int TimeBetweenRequests=2; struct timeval TimeNow; gettimeofday(&TimeNow,0); if (LastRequest.tv_sec!=0 || LastRequest.tv_usec!=0) { struct timeval Diff; do { gettimeofday(&TimeNow,0); timersub(&TimeNow,&LastRequest,&Diff); if (Diff.tv_sec& Entries) { return EditCollection(CollectionID,Entries,"PUT"); } bool MusicBrainz5::CQuery::DeleteCollectionEntries(const std::string& CollectionID, const std::vector& Entries) { return EditCollection(CollectionID,Entries,"DELETE"); } bool MusicBrainz5::CQuery::EditCollection(const std::string& CollectionID, const std::vector& Entries, const std::string& Action) { bool RetVal=false; std::vector ToProcess=Entries; while (!ToProcess.empty()) { std::string Query; Query="/ws/2/collection/"+CollectionID+"/releases/"; std::vector ThisBatch; while (!ToProcess.empty() && ThisBatch.size()<25) { ThisBatch.push_back(ToProcess.back()); ToProcess.pop_back(); } std::vector::const_iterator ThisRelease=ThisBatch.begin(); while(ThisRelease!=ThisBatch.end()) { if (ThisRelease!=ThisBatch.begin()) Query+=";"; Query+=*ThisRelease; ++ThisRelease; } Query+="?client="+m_d->m_UserAgent; CHTTPFetch Fetch(UserAgent(),m_d->m_Server,m_d->m_Port); if (!m_d->m_UserName.empty()) Fetch.SetUserName(m_d->m_UserName); if (!m_d->m_Password.empty()) Fetch.SetPassword(m_d->m_Password); if (!m_d->m_ProxyHost.empty()) Fetch.SetProxyHost(m_d->m_ProxyHost); if (0!=m_d->m_ProxyPort) Fetch.SetProxyPort(m_d->m_ProxyPort); if (!m_d->m_ProxyUserName.empty()) Fetch.SetProxyUserName(m_d->m_ProxyUserName); if (!m_d->m_ProxyPassword.empty()) Fetch.SetProxyPassword(m_d->m_ProxyPassword); try { #ifdef _MB5_DEBUG_ std::cerr << "Collection " << Action << " Query is '" << Query << "'" << std::endl; #endif int Ret=Fetch.Fetch(Query,Action); #ifdef _MB5_DEBUG_ std::cerr << "Collection Ret: " << Ret << std::endl; #endif if (Ret>0) { std::vector Data=Fetch.Data(); std::string strData(Data.begin(),Data.end()); #ifdef _MB5_DEBUG_ std::cerr << "Collection " << Action << " ret is '" << strData << "'" << std::endl; #endif XMLResults Results; XMLNode TopNode=XMLNode::parseString(strData.c_str(), 0, &Results); if (Results.error==eXMLErrorNone) { XMLNode MetadataNode=TopNode.getChildNode("metadata"); if (!MetadataNode.isEmpty()) { CMetadata Metadata(MetadataNode); if (Metadata.Message() && Metadata.Message()->Text()=="OK") RetVal=RetVal && true; } } } } catch (CConnectionError& Error) { m_d->m_LastResult=CQuery::eQuery_ConnectionError; m_d->m_LastHTTPCode=Fetch.Status(); m_d->m_LastErrorMessage=Fetch.ErrorMessage(); throw; } catch (CTimeoutError& Error) { m_d->m_LastResult=CQuery::eQuery_Timeout; m_d->m_LastHTTPCode=Fetch.Status(); m_d->m_LastErrorMessage=Fetch.ErrorMessage(); throw; } catch (CAuthenticationError& Error) { m_d->m_LastResult=CQuery::eQuery_AuthenticationError; m_d->m_LastHTTPCode=Fetch.Status(); m_d->m_LastErrorMessage=Fetch.ErrorMessage(); throw; } catch (CFetchError& Error) { m_d->m_LastResult=CQuery::eQuery_FetchError; m_d->m_LastHTTPCode=Fetch.Status(); m_d->m_LastErrorMessage=Fetch.ErrorMessage(); throw; } catch (CRequestError& Error) { m_d->m_LastResult=CQuery::eQuery_RequestError; m_d->m_LastHTTPCode=Fetch.Status(); m_d->m_LastErrorMessage=Fetch.ErrorMessage(); throw; } catch (CResourceNotFoundError& Error) { m_d->m_LastResult=CQuery::eQuery_ResourceNotFound; m_d->m_LastHTTPCode=Fetch.Status(); m_d->m_LastErrorMessage=Fetch.ErrorMessage(); throw; } } return RetVal; } std::string MusicBrainz5::CQuery::UserAgent() const { std::string UserAgent=m_d->m_UserAgent; if (!UserAgent.empty()) UserAgent+=" "; UserAgent+=PACKAGE "/v" VERSION; return UserAgent; } std::string MusicBrainz5::CQuery::URIEscape(const std::string &URI) { char *EscURIStr = ne_path_escape(URI.c_str()); std::string EscURI((const char *)EscURIStr); free(EscURIStr); return EscURI; } std::string MusicBrainz5::CQuery::URLEncode(const std::map& Params) { std::string EncodedStr; for (std::map::const_iterator i = Params.begin(); i != Params.end(); i++) { std::string Name = (*i).first; std::string Value = (*i).second; if (i!=Params.begin()) EncodedStr += "&"; EncodedStr += Name + "=" + URIEscape(Value); } return EncodedStr; } MusicBrainz5::CQuery::tQueryResult MusicBrainz5::CQuery::LastResult() const { return m_d->m_LastResult; } int MusicBrainz5::CQuery::LastHTTPCode() const { return m_d->m_LastHTTPCode; } std::string MusicBrainz5::CQuery::LastErrorMessage() const { return m_d->m_LastErrorMessage; } std::string MusicBrainz5::CQuery::Version() const { return PACKAGE "-v" VERSION; } libmusicbrainz-5.0.1/src/Rating.cc000066400000000000000000000054471175500222200170620ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Rating.h" class MusicBrainz5::CRatingPrivate { public: CRatingPrivate() : m_VotesCount(0), m_Rating(0.0) { } int m_VotesCount; double m_Rating; }; MusicBrainz5::CRating::CRating(const XMLNode& Node) : CEntity(), m_d(new CRatingPrivate) { if (!Node.isEmpty()) { //std::cout << "Rating node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); if (Node.getText()) { ProcessItem(Node,m_d->m_Rating); } } } MusicBrainz5::CRating::CRating(const CRating& Other) : CEntity(), m_d(new CRatingPrivate) { *this=Other; } MusicBrainz5::CRating& MusicBrainz5::CRating::operator =(const CRating& Other) { if (this!=&Other) { CEntity::operator =(Other); m_d->m_VotesCount=Other.m_d->m_VotesCount; m_d->m_Rating=Other.m_d->m_Rating; } return *this; } MusicBrainz5::CRating::~CRating() { delete m_d; } MusicBrainz5::CRating *MusicBrainz5::CRating::Clone() { return new CRating(*this); } void MusicBrainz5::CRating::ParseAttribute(const std::string& Name, const std::string& Value) { if ("votes-count"==Name) { ProcessItem(Value,m_d->m_VotesCount); } else { std::cerr << "Unrecognised rating attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CRating::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); std::cerr << "Unrecognised rating attribute: '" << NodeName << "'" << std::endl; } std::string MusicBrainz5::CRating::GetElementName() { return "rating"; } int MusicBrainz5::CRating::VotesCount() const { return m_d->m_VotesCount; } double MusicBrainz5::CRating::Rating() const { return m_d->m_Rating; } std::ostream& MusicBrainz5::CRating::Serialise(std::ostream& os) const { os << "Rating:" << std::endl; CEntity::Serialise(os); os << "\tVotes count: " << VotesCount() << std::endl; os << "\tRating: " << Rating() << std::endl; return os; } libmusicbrainz-5.0.1/src/Recording.cc000066400000000000000000000174231175500222200175470ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Recording.h" #include "musicbrainz5/ArtistCredit.h" #include "musicbrainz5/Rating.h" #include "musicbrainz5/UserRating.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/Release.h" #include "musicbrainz5/PUIDList.h" #include "musicbrainz5/PUID.h" #include "musicbrainz5/ISRCList.h" #include "musicbrainz5/ISRC.h" #include "musicbrainz5/RelationListList.h" #include "musicbrainz5/Relation.h" #include "musicbrainz5/TagList.h" #include "musicbrainz5/Tag.h" #include "musicbrainz5/UserTagList.h" #include "musicbrainz5/UserTag.h" class MusicBrainz5::CRecordingPrivate { public: CRecordingPrivate() : m_Length(0), m_ArtistCredit(0), m_ReleaseList(0), m_PUIDList(0), m_ISRCList(0), m_RelationListList(0), m_TagList(0), m_UserTagList(0), m_Rating(0), m_UserRating(0) { } std::string m_ID; std::string m_Title; int m_Length; std::string m_Disambiguation; CArtistCredit *m_ArtistCredit; CReleaseList *m_ReleaseList; CPUIDList *m_PUIDList; CISRCList *m_ISRCList; CRelationListList *m_RelationListList; CTagList *m_TagList; CUserTagList *m_UserTagList; CRating *m_Rating; CUserRating *m_UserRating; }; MusicBrainz5::CRecording::CRecording(const XMLNode& Node) : CEntity(), m_d(new CRecordingPrivate) { if (!Node.isEmpty()) { //std::cout << "Recording node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CRecording::CRecording(const CRecording& Other) : CEntity(), m_d(new CRecordingPrivate) { *this=Other; } MusicBrainz5::CRecording& MusicBrainz5::CRecording::operator =(const CRecording& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_ID=Other.m_d->m_ID; m_d->m_Title=Other.m_d->m_Title; m_d->m_Length=Other.m_d->m_Length; m_d->m_Disambiguation=Other.m_d->m_Disambiguation; if (Other.m_d->m_ArtistCredit) m_d->m_ArtistCredit=new CArtistCredit(*Other.m_d->m_ArtistCredit); if (Other.m_d->m_ReleaseList) m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); if (Other.m_d->m_PUIDList) m_d->m_PUIDList=new CPUIDList(*Other.m_d->m_PUIDList); if (Other.m_d->m_ISRCList) m_d->m_ISRCList=new CISRCList(*Other.m_d->m_ISRCList); if (Other.m_d->m_RelationListList) m_d->m_RelationListList=new CRelationListList(*Other.m_d->m_RelationListList); if (Other.m_d->m_TagList) m_d->m_TagList=new CTagList(*Other.m_d->m_TagList); if (Other.m_d->m_UserTagList) m_d->m_UserTagList=new CUserTagList(*Other.m_d->m_UserTagList); if (Other.m_d->m_Rating) m_d->m_Rating=new CRating(*Other.m_d->m_Rating); if (Other.m_d->m_UserRating) m_d->m_UserRating=new CUserRating(*Other.m_d->m_UserRating); } return *this; } MusicBrainz5::CRecording::~CRecording() { Cleanup(); delete m_d; } MusicBrainz5::CRecording *MusicBrainz5::CRecording::Clone() { return new CRecording(*this); } void MusicBrainz5::CRecording::ParseAttribute(const std::string& Name, const std::string& Value) { if ("id"==Name) m_d->m_ID=Value; else { std::cerr << "Unrecognised recording attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CRecording::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("title"==NodeName) { ProcessItem(Node,m_d->m_Title); } else if ("length"==NodeName) { ProcessItem(Node,m_d->m_Length); } else if ("disambiguation"==NodeName) { ProcessItem(Node,m_d->m_Disambiguation); } else if ("artist-credit"==NodeName) { ProcessItem(Node,m_d->m_ArtistCredit); } else if ("release-list"==NodeName) { ProcessItem(Node,m_d->m_ReleaseList); } else if ("puid-list"==NodeName) { ProcessItem(Node,m_d->m_PUIDList); } else if ("isrc-list"==NodeName) { ProcessItem(Node,m_d->m_ISRCList); } else if ("relation-list"==NodeName) { ProcessRelationList(Node,m_d->m_RelationListList); } else if ("tag-list"==NodeName) { ProcessItem(Node,m_d->m_TagList); } else if ("user-tag-list"==NodeName) { ProcessItem(Node,m_d->m_UserTagList); } else if ("rating"==NodeName) { ProcessItem(Node,m_d->m_Rating); } else if ("user-rating"==NodeName) { ProcessItem(Node,m_d->m_UserRating); } else { std::cerr << "Unrecognised recording element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CRecording::GetElementName() { return "recording"; } void MusicBrainz5::CRecording::Cleanup() { delete m_d->m_ArtistCredit; m_d->m_ArtistCredit=0; delete m_d->m_ReleaseList; m_d->m_ReleaseList=0; delete m_d->m_PUIDList; m_d->m_PUIDList=0; delete m_d->m_ISRCList; m_d->m_ISRCList=0; delete m_d->m_RelationListList; m_d->m_RelationListList=0; delete m_d->m_TagList; m_d->m_TagList=0; delete m_d->m_UserTagList; m_d->m_UserTagList=0; delete m_d->m_Rating; m_d->m_Rating=0; delete m_d->m_UserRating; m_d->m_UserRating=0; } std::string MusicBrainz5::CRecording::ID() const { return m_d->m_ID; } std::string MusicBrainz5::CRecording::Title() const { return m_d->m_Title; } int MusicBrainz5::CRecording::Length() const { return m_d->m_Length; } std::string MusicBrainz5::CRecording::Disambiguation() const { return m_d->m_Disambiguation; } MusicBrainz5::CArtistCredit *MusicBrainz5::CRecording::ArtistCredit() const { return m_d->m_ArtistCredit; } MusicBrainz5::CReleaseList *MusicBrainz5::CRecording::ReleaseList() const { return m_d->m_ReleaseList; } MusicBrainz5::CPUIDList *MusicBrainz5::CRecording::PUIDList() const { return m_d->m_PUIDList; } MusicBrainz5::CISRCList *MusicBrainz5::CRecording::ISRCList() const { return m_d->m_ISRCList; } MusicBrainz5::CRelationListList *MusicBrainz5::CRecording::RelationListList() const { return m_d->m_RelationListList; } MusicBrainz5::CTagList *MusicBrainz5::CRecording::TagList() const { return m_d->m_TagList; } MusicBrainz5::CUserTagList *MusicBrainz5::CRecording::UserTagList() const { return m_d->m_UserTagList; } MusicBrainz5::CRating *MusicBrainz5::CRecording::Rating() const { return m_d->m_Rating; } MusicBrainz5::CUserRating *MusicBrainz5::CRecording::UserRating() const { return m_d->m_UserRating; } std::ostream& MusicBrainz5::CRecording::Serialise(std::ostream& os) const { os << "Recording:" << std::endl; CEntity::Serialise(os); os << "\tID: " << ID() << std::endl; os << "\tTitle: " << Title() << std::endl; os << "\tLength: " << Length() << std::endl; os << "\tDisambiguation: " << Disambiguation() << std::endl; if (ArtistCredit()) os << *ArtistCredit() << std::endl; if (ReleaseList()) os << *ReleaseList() << std::endl; if (PUIDList()) os << *PUIDList() << std::endl; if (ISRCList()) os << *ISRCList() << std::endl; if (RelationListList()) os << *RelationListList() << std::endl; if (TagList()) os << *TagList() << std::endl; if (UserTagList()) os << *UserTagList() << std::endl; if (Rating()) os << *Rating() << std::endl; if (UserRating()) os << *UserRating() << std::endl; return os; } libmusicbrainz-5.0.1/src/Relation.cc000066400000000000000000000151711175500222200174060ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Relation.h" #include "musicbrainz5/Artist.h" #include "musicbrainz5/Release.h" #include "musicbrainz5/ReleaseGroup.h" #include "musicbrainz5/Recording.h" #include "musicbrainz5/Label.h" #include "musicbrainz5/Work.h" #include "musicbrainz5/AttributeList.h" #include "musicbrainz5/Attribute.h" class MusicBrainz5::CRelationPrivate { public: CRelationPrivate() : m_AttributeList(0), m_Artist(0), m_Release(0), m_ReleaseGroup(0), m_Recording(0), m_Label(0), m_Work(0) { } std::string m_Type; std::string m_Target; std::string m_Direction; CAttributeList *m_AttributeList; std::string m_Begin; std::string m_End; CArtist *m_Artist; CRelease *m_Release; CReleaseGroup *m_ReleaseGroup; CRecording *m_Recording; CLabel *m_Label; CWork *m_Work; }; MusicBrainz5::CRelation::CRelation(const XMLNode& Node) : CEntity(), m_d(new CRelationPrivate) { if (!Node.isEmpty()) { //std::cout << "Relation node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CRelation::CRelation(const CRelation& Other) : CEntity(), m_d(new CRelationPrivate) { *this=Other; } MusicBrainz5::CRelation& MusicBrainz5::CRelation::operator =(const CRelation& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_Type=Other.m_d->m_Type; m_d->m_Target=Other.m_d->m_Target; m_d->m_Direction=Other.m_d->m_Direction; if (Other.m_d->m_AttributeList) m_d->m_AttributeList=new CAttributeList(*Other.m_d->m_AttributeList); m_d->m_Begin=Other.m_d->m_Begin; m_d->m_End=Other.m_d->m_End; if (Other.m_d->m_Artist) m_d->m_Artist=new CArtist(*Other.m_d->m_Artist); if (Other.m_d->m_Release) m_d->m_Release=new CRelease(*Other.m_d->m_Release); if (Other.m_d->m_ReleaseGroup) m_d->m_ReleaseGroup=new CReleaseGroup(*Other.m_d->m_ReleaseGroup); if (Other.m_d->m_Recording) m_d->m_Recording=new CRecording(*Other.m_d->m_Recording); if (Other.m_d->m_Label) m_d->m_Label=new CLabel(*Other.m_d->m_Label); if (Other.m_d->m_Work) m_d->m_Work=new CWork(*Other.m_d->m_Work); } return *this; } MusicBrainz5::CRelation::~CRelation() { Cleanup(); delete m_d; } void MusicBrainz5::CRelation::Cleanup() { delete m_d->m_AttributeList; m_d->m_AttributeList=0; delete m_d->m_Artist; m_d->m_Artist=0; delete m_d->m_Release; m_d->m_Release=0; delete m_d->m_ReleaseGroup; m_d->m_ReleaseGroup=0; delete m_d->m_Recording; m_d->m_Recording=0; delete m_d->m_Label; m_d->m_Label=0; delete m_d->m_Work; m_d->m_Work=0; } MusicBrainz5::CRelation *MusicBrainz5::CRelation::Clone() { return new CRelation(*this); } void MusicBrainz5::CRelation::ParseAttribute(const std::string& Name, const std::string& Value) { if ("type"==Name) m_d->m_Type=Value; else { std::cerr << "Unrecognised relation attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CRelation::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("target"==NodeName) { ProcessItem(Node,m_d->m_Target); } else if ("direction"==NodeName) { ProcessItem(Node,m_d->m_Direction); } else if ("attribute-list"==NodeName) { ProcessItem(Node,m_d->m_AttributeList); } else if ("begin"==NodeName) { ProcessItem(Node,m_d->m_Begin); } else if ("end"==NodeName) { ProcessItem(Node,m_d->m_End); } else if ("artist"==NodeName) { ProcessItem(Node,m_d->m_Artist); } else if ("release"==NodeName) { ProcessItem(Node,m_d->m_Release); } else if ("release-group"==NodeName) { ProcessItem(Node,m_d->m_ReleaseGroup); } else if ("recording"==NodeName) { ProcessItem(Node,m_d->m_Recording); } else if ("label"==NodeName) { ProcessItem(Node,m_d->m_Label); } else if ("work"==NodeName) { ProcessItem(Node,m_d->m_Work); } else { std::cerr << "Unrecognised relation element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CRelation::GetElementName() { return "relation"; } std::string MusicBrainz5::CRelation::Type() const { return m_d->m_Type; } std::string MusicBrainz5::CRelation::Target() const { return m_d->m_Target; } std::string MusicBrainz5::CRelation::Direction() const { return m_d->m_Direction; } MusicBrainz5::CAttributeList *MusicBrainz5::CRelation::AttributeList() const { return m_d->m_AttributeList; } std::string MusicBrainz5::CRelation::Begin() const { return m_d->m_Begin; } std::string MusicBrainz5::CRelation::End() const { return m_d->m_End; } MusicBrainz5::CArtist *MusicBrainz5::CRelation::Artist() const { return m_d->m_Artist; } MusicBrainz5::CRelease *MusicBrainz5::CRelation::Release() const { return m_d->m_Release; } MusicBrainz5::CReleaseGroup *MusicBrainz5::CRelation::ReleaseGroup() const { return m_d->m_ReleaseGroup; } MusicBrainz5::CRecording *MusicBrainz5::CRelation::Recording() const { return m_d->m_Recording; } MusicBrainz5::CLabel *MusicBrainz5::CRelation::Label() const { return m_d->m_Label; } MusicBrainz5::CWork *MusicBrainz5::CRelation::Work() const { return m_d->m_Work; } std::ostream& MusicBrainz5::CRelation::Serialise(std::ostream& os) const { os << "Relation:" << std::endl; CEntity::Serialise(os); os << "\tType: " << Type() << std::endl; os << "\tTarget: " << Target() << std::endl; os << "\tDirection: " << Direction() << std::endl; if (AttributeList()) os << AttributeList() << std::endl; os << "\tBegin: " << Begin() << std::endl; os << "\tEnd: " << End() << std::endl; if (Artist()) os << *Artist() << std::endl; if (Release()) os << *Release() << std::endl; if (ReleaseGroup()) os << *ReleaseGroup() << std::endl; if (Recording()) os << *Recording() << std::endl; if (Label()) os << *Label() << std::endl; if (Work()) os << *Work() << std::endl; return os; } libmusicbrainz-5.0.1/src/RelationList.cc000066400000000000000000000051711175500222200202410ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/Relation.h" class MusicBrainz5::CRelationListPrivate { public: std::string m_TargetType; }; MusicBrainz5::CRelationList::CRelationList(const XMLNode& Node) : CListImpl(), m_d(new CRelationListPrivate) { if (!Node.isEmpty()) { //std::cout << "RelationList node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CRelationList::CRelationList(const CRelationList& Other) : CListImpl(), m_d(new CRelationListPrivate) { *this=Other; } MusicBrainz5::CRelationList& MusicBrainz5::CRelationList::operator =(const CRelationList& Other) { if (this!=&Other) { CListImpl::operator =(Other); m_d->m_TargetType=Other.m_d->m_TargetType; } return *this; } MusicBrainz5::CRelationList::~CRelationList() { delete m_d; } MusicBrainz5::CRelationList *MusicBrainz5::CRelationList::Clone() { return new CRelationList(*this); } void MusicBrainz5::CRelationList::ParseAttribute(const std::string& Name, const std::string& Value) { if ("target-type"==Name) ProcessItem(Value,m_d->m_TargetType); else CListImpl::ParseAttribute(Name,Value); } void MusicBrainz5::CRelationList::ParseElement(const XMLNode& Node) { CListImpl::ParseElement(Node); } std::string MusicBrainz5::CRelationList::GetElementName() { return "relation-list"; } std::string MusicBrainz5::CRelationList::TargetType() const { return m_d->m_TargetType; } std::ostream& MusicBrainz5::CRelationList::Serialise(std::ostream& os) const { os << "Relation list:" << std::endl; os << "\tTarget type: " << TargetType() << std::endl; CListImpl::Serialise(os); return os; } libmusicbrainz-5.0.1/src/RelationListList.cc000066400000000000000000000067271175500222200211050ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/RelationListList.h" #include #include "musicbrainz5/RelationList.h" #include "musicbrainz5/Relation.h" class MusicBrainz5::CRelationListListPrivate { public: CRelationListListPrivate() : m_ListGroup(0) { } std::vector *m_ListGroup; }; MusicBrainz5::CRelationListList::CRelationListList() : m_d(new CRelationListListPrivate) { } MusicBrainz5::CRelationListList::CRelationListList(const CRelationListList& Other) : m_d(new CRelationListListPrivate) { *this=Other; } MusicBrainz5::CRelationListList& MusicBrainz5::CRelationListList::operator =(const CRelationListList& Other) { if (this!=&Other) { Cleanup(); if (Other.m_d->m_ListGroup) { m_d->m_ListGroup=new std::vector; for (std::vector::const_iterator ThisRelationList=Other.m_d->m_ListGroup->begin();ThisRelationList!=Other.m_d->m_ListGroup->end();++ThisRelationList) { CRelationList *RelationList=*ThisRelationList; m_d->m_ListGroup->push_back(new CRelationList(*RelationList)); } } } return *this; } MusicBrainz5::CRelationListList::~CRelationListList() { Cleanup(); delete m_d; } void MusicBrainz5::CRelationListList::Cleanup() { if (m_d->m_ListGroup) { for (std::vector::const_iterator ThisRelationList=m_d->m_ListGroup->begin();ThisRelationList!=m_d->m_ListGroup->end();++ThisRelationList) { CRelationList *RelationList=*ThisRelationList; delete RelationList; } } delete m_d->m_ListGroup; m_d->m_ListGroup=0; } void MusicBrainz5::CRelationListList::Add(CRelationList *RelationList) { if (!m_d->m_ListGroup) m_d->m_ListGroup=new std::vector; m_d->m_ListGroup->push_back(new CRelationList(*RelationList)); } int MusicBrainz5::CRelationListList::NumItems() const { int Ret=0; if (m_d->m_ListGroup) Ret=m_d->m_ListGroup->size(); return Ret; } MusicBrainz5::CRelationList *MusicBrainz5::CRelationListList::Item(int Item) const { CRelationList *RelationList=0; if (m_d->m_ListGroup && Item<(int)m_d->m_ListGroup->size()) RelationList=(*m_d->m_ListGroup)[Item]; return RelationList; } std::ostream& MusicBrainz5::CRelationListList::Serialise(std::ostream& os) const { if (m_d->m_ListGroup && m_d->m_ListGroup->size()!=0) { os << "RelationLists:" << std::endl; for (int count=0;count. $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Release.h" #include #include "musicbrainz5/TextRepresentation.h" #include "musicbrainz5/ArtistCredit.h" #include "musicbrainz5/ReleaseGroup.h" #include "musicbrainz5/Medium.h" #include "musicbrainz5/LabelInfoList.h" #include "musicbrainz5/LabelInfo.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/RelationListList.h" #include "musicbrainz5/Relation.h" #include "musicbrainz5/MediumList.h" #include "musicbrainz5/Medium.h" #include "musicbrainz5/Collection.h" #include "musicbrainz5/CollectionList.h" class MusicBrainz5::CReleasePrivate { public: CReleasePrivate() : m_TextRepresentation(0), m_ArtistCredit(0), m_ReleaseGroup(0), m_LabelInfoList(0), m_MediumList(0), m_RelationListList(0), m_CollectionList(0) { } std::string m_ID; std::string m_Title; std::string m_Status; std::string m_Quality; std::string m_Disambiguation; std::string m_Packaging; CTextRepresentation *m_TextRepresentation; CArtistCredit *m_ArtistCredit; CReleaseGroup *m_ReleaseGroup; std::string m_Date; std::string m_Country; std::string m_Barcode; std::string m_ASIN; CLabelInfoList *m_LabelInfoList; CMediumList *m_MediumList; CRelationListList *m_RelationListList; CCollectionList *m_CollectionList; }; MusicBrainz5::CRelease::CRelease(const XMLNode& Node) : CEntity(), m_d(new CReleasePrivate) { if (!Node.isEmpty()) { //std::cout << "Release node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CRelease::CRelease(const CRelease& Other) : CEntity(), m_d(new CReleasePrivate) { *this=Other; } MusicBrainz5::CRelease& MusicBrainz5::CRelease::operator =(const CRelease& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_ID=Other.m_d->m_ID; m_d->m_Title=Other.m_d->m_Title; m_d->m_Status=Other.m_d->m_Status; m_d->m_Quality=Other.m_d->m_Quality; m_d->m_Disambiguation=Other.m_d->m_Disambiguation; m_d->m_Packaging=Other.m_d->m_Packaging; if (Other.m_d->m_TextRepresentation) m_d->m_TextRepresentation=new CTextRepresentation(*Other.m_d->m_TextRepresentation); if (Other.m_d->m_ArtistCredit) m_d->m_ArtistCredit=new CArtistCredit(*Other.m_d->m_ArtistCredit); if (Other.m_d->m_ReleaseGroup) m_d->m_ReleaseGroup=new CReleaseGroup(*Other.m_d->m_ReleaseGroup); m_d->m_Date=Other.m_d->m_Date; m_d->m_Country=Other.m_d->m_Country; m_d->m_Barcode=Other.m_d->m_Barcode; m_d->m_ASIN=Other.m_d->m_ASIN; if (Other.m_d->m_LabelInfoList) m_d->m_LabelInfoList=new CLabelInfoList(*Other.m_d->m_LabelInfoList); if (Other.m_d->m_MediumList) m_d->m_MediumList=new CMediumList(*Other.m_d->m_MediumList); if (Other.m_d->m_RelationListList) m_d->m_RelationListList=new CRelationListList(*Other.m_d->m_RelationListList); if (Other.m_d->m_CollectionList) m_d->m_CollectionList=new CCollectionList(*Other.m_d->m_CollectionList); } return *this; } MusicBrainz5::CRelease::~CRelease() { Cleanup(); delete m_d; } void MusicBrainz5::CRelease::Cleanup() { delete m_d->m_TextRepresentation; m_d->m_TextRepresentation=0; delete m_d->m_ArtistCredit; m_d->m_ArtistCredit=0; delete m_d->m_ReleaseGroup; m_d->m_ReleaseGroup=0; delete m_d->m_LabelInfoList; m_d->m_LabelInfoList=0; delete m_d->m_MediumList; m_d->m_MediumList=0; delete m_d->m_RelationListList; m_d->m_RelationListList=0; } MusicBrainz5::CRelease *MusicBrainz5::CRelease::Clone() { return new CRelease(*this); } void MusicBrainz5::CRelease::ParseAttribute(const std::string& Name, const std::string& Value) { if ("id"==Name) m_d->m_ID=Value; else { std::cerr << "Unrecognised release attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CRelease::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("title"==NodeName) { ProcessItem(Node,m_d->m_Title); } else if ("status"==NodeName) { ProcessItem(Node,m_d->m_Status); } else if ("quality"==NodeName) { ProcessItem(Node,m_d->m_Quality); } else if ("disambiguation"==NodeName) { ProcessItem(Node,m_d->m_Disambiguation); } else if ("packaging"==NodeName) { ProcessItem(Node,m_d->m_Packaging); } else if ("text-representation"==NodeName) { ProcessItem(Node,m_d->m_TextRepresentation); } else if ("artist-credit"==NodeName) { ProcessItem(Node,m_d->m_ArtistCredit); } else if ("release-group"==NodeName) { ProcessItem(Node,m_d->m_ReleaseGroup); } else if ("date"==NodeName) { ProcessItem(Node,m_d->m_Date); } else if ("country"==NodeName) { ProcessItem(Node,m_d->m_Country); } else if ("barcode"==NodeName) { ProcessItem(Node,m_d->m_Barcode); } else if ("asin"==NodeName) { ProcessItem(Node,m_d->m_ASIN); } else if ("label-info-list"==NodeName) { ProcessItem(Node,m_d->m_LabelInfoList); } else if ("medium-list"==NodeName) { ProcessItem(Node,m_d->m_MediumList); } else if ("relation-list"==NodeName) { ProcessRelationList(Node,m_d->m_RelationListList); } else if ("collection-list"==NodeName) { ProcessItem(Node,m_d->m_CollectionList); } else { std::cerr << "Unrecognised release element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CRelease::GetElementName() { return "release"; } std::string MusicBrainz5::CRelease::ID() const { return m_d->m_ID; } std::string MusicBrainz5::CRelease::Title() const { return m_d->m_Title; } std::string MusicBrainz5::CRelease::Status() const { return m_d->m_Status; } std::string MusicBrainz5::CRelease::Quality() const { return m_d->m_Quality; } std::string MusicBrainz5::CRelease::Disambiguation() const { return m_d->m_Disambiguation; } std::string MusicBrainz5::CRelease::Packaging() const { return m_d->m_Packaging; } MusicBrainz5::CTextRepresentation *MusicBrainz5::CRelease::TextRepresentation() const { return m_d->m_TextRepresentation; } MusicBrainz5::CArtistCredit *MusicBrainz5::CRelease::ArtistCredit() const { return m_d->m_ArtistCredit; } MusicBrainz5::CReleaseGroup *MusicBrainz5::CRelease::ReleaseGroup() const { return m_d->m_ReleaseGroup; } std::string MusicBrainz5::CRelease::Date() const { return m_d->m_Date; } std::string MusicBrainz5::CRelease::Country() const { return m_d->m_Country; } std::string MusicBrainz5::CRelease::Barcode() const { return m_d->m_Barcode; } std::string MusicBrainz5::CRelease::ASIN() const { return m_d->m_ASIN; } MusicBrainz5::CLabelInfoList *MusicBrainz5::CRelease::LabelInfoList() const { return m_d->m_LabelInfoList; } MusicBrainz5::CMediumList *MusicBrainz5::CRelease::MediumList() const { return m_d->m_MediumList; } MusicBrainz5::CRelationListList *MusicBrainz5::CRelease::RelationListList() const { return m_d->m_RelationListList; } MusicBrainz5::CCollectionList *MusicBrainz5::CRelease::CollectionList() const { return m_d->m_CollectionList; } MusicBrainz5::CMediumList MusicBrainz5::CRelease::MediaMatchingDiscID(const std::string& DiscID) const { MusicBrainz5::CMediumList Ret; if (m_d->m_MediumList) { for (int count=0;countm_MediumList->NumItems();count++) { MusicBrainz5::CMedium *Medium=m_d->m_MediumList->Item(count); if (Medium->ContainsDiscID(DiscID)) Ret.AddItem(new MusicBrainz5::CMedium(*Medium)); } } return Ret; } std::ostream& MusicBrainz5::CRelease::Serialise(std::ostream& os) const { os << "Release:" << std::endl; CEntity::Serialise(os); os << "\tID: " << ID() << std::endl; os << "\tTitle: " << Title() << std::endl; os << "\tStatus: " << Status() << std::endl; os << "\tQuality: " << Quality() << std::endl; os << "\tDisambiguation: " << Disambiguation() << std::endl; os << "\tPackaging: " << Packaging() << std::endl; if (TextRepresentation()) os << *TextRepresentation(); if (ArtistCredit()) os << *ArtistCredit() << std::endl; if (ReleaseGroup()) os << *ReleaseGroup() << std::endl; os << "\tDate: " << Date() << std::endl; os << "\tCountry: " << Country() << std::endl; os << "\tBarcode: " << Barcode() << std::endl; os << "\tASIN: " << ASIN() << std::endl; if (LabelInfoList()) os << *LabelInfoList() << std::endl; if (MediumList()) os << *MediumList() << std::endl; if (RelationListList()) os << *RelationListList() << std::endl; if (CollectionList()) os << *CollectionList() << std::endl; return os; } libmusicbrainz-5.0.1/src/ReleaseGroup.cc000066400000000000000000000201161175500222200202210ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/ReleaseGroup.h" #include "musicbrainz5/ArtistCredit.h" #include "musicbrainz5/Rating.h" #include "musicbrainz5/UserRating.h" #include "musicbrainz5/ReleaseList.h" #include "musicbrainz5/Release.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/RelationListList.h" #include "musicbrainz5/Relation.h" #include "musicbrainz5/TagList.h" #include "musicbrainz5/Tag.h" #include "musicbrainz5/UserTagList.h" #include "musicbrainz5/UserTag.h" #include "musicbrainz5/SecondaryTypeList.h" #include "musicbrainz5/SecondaryType.h" class MusicBrainz5::CReleaseGroupPrivate { public: CReleaseGroupPrivate() : m_ArtistCredit(0), m_ReleaseList(0), m_RelationListList(0), m_TagList(0), m_UserTagList(0), m_Rating(0), m_UserRating(0), m_SecondaryTypeList(0) { } std::string m_ID; std::string m_PrimaryType; std::string m_Title; std::string m_Disambiguation; std::string m_FirstReleaseDate; CArtistCredit *m_ArtistCredit; CReleaseList *m_ReleaseList; CRelationListList *m_RelationListList; CTagList *m_TagList; CUserTagList *m_UserTagList; CRating *m_Rating; CUserRating *m_UserRating; CSecondaryTypeList *m_SecondaryTypeList; }; MusicBrainz5::CReleaseGroup::CReleaseGroup(const XMLNode& Node) : CEntity(), m_d(new CReleaseGroupPrivate) { if (!Node.isEmpty()) { //std::cout << "Name credit node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CReleaseGroup::CReleaseGroup(const CReleaseGroup& Other) : CEntity(), m_d(new CReleaseGroupPrivate) { *this=Other; } MusicBrainz5::CReleaseGroup& MusicBrainz5::CReleaseGroup::operator =(const CReleaseGroup& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_ID=Other.m_d->m_ID; m_d->m_PrimaryType=Other.m_d->m_PrimaryType; m_d->m_Title=Other.m_d->m_Title; m_d->m_Disambiguation=Other.m_d->m_Disambiguation; m_d->m_FirstReleaseDate=Other.m_d->m_FirstReleaseDate; if (Other.m_d->m_ArtistCredit) m_d->m_ArtistCredit=new CArtistCredit(*Other.m_d->m_ArtistCredit); if (Other.m_d->m_ReleaseList) m_d->m_ReleaseList=new CReleaseList(*Other.m_d->m_ReleaseList); if (Other.m_d->m_RelationListList) m_d->m_RelationListList=new CRelationListList(*Other.m_d->m_RelationListList); if (Other.m_d->m_TagList) m_d->m_TagList=new CTagList(*Other.m_d->m_TagList); if (Other.m_d->m_UserTagList) m_d->m_UserTagList=new CUserTagList(*Other.m_d->m_UserTagList); if (Other.m_d->m_Rating) m_d->m_Rating=new CRating(*Other.m_d->m_Rating); if (Other.m_d->m_UserRating) m_d->m_UserRating=new CUserRating(*Other.m_d->m_UserRating); if (Other.m_d->m_SecondaryTypeList) m_d->m_SecondaryTypeList=new CSecondaryTypeList(*Other.m_d->m_SecondaryTypeList); } return *this; } MusicBrainz5::CReleaseGroup::~CReleaseGroup() { Cleanup(); delete m_d; } void MusicBrainz5::CReleaseGroup::Cleanup() { delete m_d->m_ArtistCredit; m_d->m_ArtistCredit=0; delete m_d->m_ReleaseList; m_d->m_ReleaseList=0; delete m_d->m_RelationListList; m_d->m_RelationListList=0; delete m_d->m_TagList; m_d->m_TagList=0; delete m_d->m_UserTagList; m_d->m_UserTagList=0; delete m_d->m_Rating; m_d->m_Rating=0; delete m_d->m_UserRating; m_d->m_UserRating=0; delete m_d->m_SecondaryTypeList; m_d->m_SecondaryTypeList=0; } MusicBrainz5::CReleaseGroup *MusicBrainz5::CReleaseGroup::Clone() { return new CReleaseGroup(*this); } void MusicBrainz5::CReleaseGroup::ParseAttribute(const std::string& Name, const std::string& Value) { if ("id"==Name) m_d->m_ID=Value; else if ("type"==Name) { //Ignore type } else { std::cerr << "Unrecognised releasegroup attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CReleaseGroup::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("primary-type"==NodeName) { ProcessItem(Node,m_d->m_PrimaryType); } else if ("title"==NodeName) { ProcessItem(Node,m_d->m_Title); } else if ("disambiguation"==NodeName) { ProcessItem(Node,m_d->m_Disambiguation); } else if ("first-release-date"==NodeName) { ProcessItem(Node,m_d->m_FirstReleaseDate); } else if ("artist-credit"==NodeName) { ProcessItem(Node,m_d->m_ArtistCredit); } else if ("release-list"==NodeName) { ProcessItem(Node,m_d->m_ReleaseList); } else if ("relation-list"==NodeName) { ProcessRelationList(Node,m_d->m_RelationListList); } else if ("tag-list"==NodeName) { ProcessItem(Node,m_d->m_TagList); } else if ("user-tag-list"==NodeName) { ProcessItem(Node,m_d->m_UserTagList); } else if ("rating"==NodeName) { ProcessItem(Node,m_d->m_Rating); } else if ("user-rating"==NodeName) { ProcessItem(Node,m_d->m_UserRating); } else if ("secondary-type-list"==NodeName) { ProcessItem(Node,m_d->m_SecondaryTypeList); } else { std::cerr << "Unrecognised release group element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CReleaseGroup::GetElementName() { return "release-group"; } std::string MusicBrainz5::CReleaseGroup::ID() const { return m_d->m_ID; } std::string MusicBrainz5::CReleaseGroup::PrimaryType() const { return m_d->m_PrimaryType; } std::string MusicBrainz5::CReleaseGroup::Title() const { return m_d->m_Title; } std::string MusicBrainz5::CReleaseGroup::Disambiguation() const { return m_d->m_Disambiguation; } std::string MusicBrainz5::CReleaseGroup::FirstReleaseDate() const { return m_d->m_FirstReleaseDate; } MusicBrainz5::CArtistCredit *MusicBrainz5::CReleaseGroup::ArtistCredit() const { return m_d->m_ArtistCredit; } MusicBrainz5::CReleaseList *MusicBrainz5::CReleaseGroup::ReleaseList() const { return m_d->m_ReleaseList; } MusicBrainz5::CRelationListList *MusicBrainz5::CReleaseGroup::RelationListList() const { return m_d->m_RelationListList; } MusicBrainz5::CTagList *MusicBrainz5::CReleaseGroup::TagList() const { return m_d->m_TagList; } MusicBrainz5::CUserTagList *MusicBrainz5::CReleaseGroup::UserTagList() const { return m_d->m_UserTagList; } MusicBrainz5::CRating *MusicBrainz5::CReleaseGroup::Rating() const { return m_d->m_Rating; } MusicBrainz5::CUserRating *MusicBrainz5::CReleaseGroup::UserRating() const { return m_d->m_UserRating; } MusicBrainz5::CSecondaryTypeList *MusicBrainz5::CReleaseGroup::SecondaryTypeList() const { return m_d->m_SecondaryTypeList; } std::ostream& MusicBrainz5::CReleaseGroup::Serialise(std::ostream& os) const { os << "Release group:" << std::endl; CEntity::Serialise(os); os << "\tID: " << ID() << std::endl; os << "\tPrimaryType: " << PrimaryType() << std::endl; os << "\tTitle: " << Title() << std::endl; os << "\tDisambiguation: " << Disambiguation() << std::endl; os << "\tFirst release date: " << FirstReleaseDate() << std::endl; if (ArtistCredit()) os << *ArtistCredit() << std::endl; if (ReleaseList()) os << *ReleaseList() << std::endl; if (RelationListList()) os << *RelationListList() << std::endl; if (TagList()) os << *TagList() << std::endl; if (UserTagList()) os << *UserTagList() << std::endl; if (Rating()) os << *Rating() << std::endl; if (UserRating()) os << *UserRating() << std::endl; if (SecondaryTypeList()) os << *SecondaryTypeList() << std::endl; return os; } libmusicbrainz-5.0.1/src/SecondaryType.cc000066400000000000000000000054631175500222200204250ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/SecondaryType.h" class MusicBrainz5::CSecondaryTypePrivate { public: CSecondaryTypePrivate() { } std::string m_SecondaryType; }; MusicBrainz5::CSecondaryType::CSecondaryType(const XMLNode& Node) : CEntity(), m_d(new CSecondaryTypePrivate) { if (!Node.isEmpty()) { //std::cout << "SecondaryType node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); if (Node.getText()) ProcessItem(Node,m_d->m_SecondaryType); } } MusicBrainz5::CSecondaryType::CSecondaryType(const CSecondaryType& Other) : CEntity(), m_d(new CSecondaryTypePrivate) { *this=Other; } MusicBrainz5::CSecondaryType& MusicBrainz5::CSecondaryType::operator =(const CSecondaryType& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_SecondaryType=Other.m_d->m_SecondaryType; } return *this; } MusicBrainz5::CSecondaryType::~CSecondaryType() { Cleanup(); delete m_d; } void MusicBrainz5::CSecondaryType::Cleanup() { } MusicBrainz5::CSecondaryType *MusicBrainz5::CSecondaryType::Clone() { return new CSecondaryType(*this); } void MusicBrainz5::CSecondaryType::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised secondary type attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CSecondaryType::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); std::cerr << "Unrecognised secondary type element: '" << NodeName << "'" << std::endl; } std::string MusicBrainz5::CSecondaryType::GetElementName() { return "secondary-type"; } std::string MusicBrainz5::CSecondaryType::SecondaryType() const { return m_d->m_SecondaryType; } std::ostream& MusicBrainz5::CSecondaryType::Serialise(std::ostream& os) const { os << "Secondary Type:" << std::endl; CEntity::Serialise(os); os << "\tSecondaryType: " << SecondaryType() << std::endl; return os; } libmusicbrainz-5.0.1/src/SecondaryTypeList.cc000066400000000000000000000050251175500222200212530ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/SecondaryTypeList.h" #include "musicbrainz5/SecondaryType.h" class MusicBrainz5::CSecondaryTypeListPrivate { public: CSecondaryTypeListPrivate() { } }; MusicBrainz5::CSecondaryTypeList::CSecondaryTypeList(const XMLNode& Node) : CListImpl(), m_d(new CSecondaryTypeListPrivate) { if (!Node.isEmpty()) { //std::cout << "SecondaryTypeList node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CSecondaryTypeList::CSecondaryTypeList(const CSecondaryTypeList& Other) : CListImpl(), m_d(new CSecondaryTypeListPrivate) { *this=Other; } MusicBrainz5::CSecondaryTypeList& MusicBrainz5::CSecondaryTypeList::operator =(const CSecondaryTypeList& Other) { if (this!=&Other) { CListImpl::operator =(Other); } return *this; } MusicBrainz5::CSecondaryTypeList::~CSecondaryTypeList() { delete m_d; } MusicBrainz5::CSecondaryTypeList *MusicBrainz5::CSecondaryTypeList::Clone() { return new CSecondaryTypeList(*this); } void MusicBrainz5::CSecondaryTypeList::ParseAttribute(const std::string& Name, const std::string& Value) { CListImpl::ParseAttribute(Name,Value); } void MusicBrainz5::CSecondaryTypeList::ParseElement(const XMLNode& Node) { CListImpl::ParseElement(Node); } std::string MusicBrainz5::CSecondaryTypeList::GetElementName() { return "secondary-type-list"; } std::ostream& MusicBrainz5::CSecondaryTypeList::Serialise(std::ostream& os) const { os << "Secondary type list:" << std::endl; CListImpl::Serialise(os); return os; } libmusicbrainz-5.0.1/src/Tag.cc000066400000000000000000000052101175500222200163350ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Tag.h" class MusicBrainz5::CTagPrivate { public: CTagPrivate() : m_Count(0) { } int m_Count; std::string m_Name; }; MusicBrainz5::CTag::CTag(const XMLNode& Node) : CEntity(), m_d(new CTagPrivate) { if (!Node.isEmpty()) { //std::cout << "Tag node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CTag::CTag(const CTag& Other) : CEntity(), m_d(new CTagPrivate) { *this=Other; } MusicBrainz5::CTag& MusicBrainz5::CTag::operator =(const CTag& Other) { if (this!=&Other) { CEntity::operator =(Other); m_d->m_Count=Other.m_d->m_Count; m_d->m_Name=Other.m_d->m_Name; } return *this; } MusicBrainz5::CTag::~CTag() { delete m_d; } MusicBrainz5::CTag *MusicBrainz5::CTag::Clone() { return new CTag(*this); } void MusicBrainz5::CTag::ParseAttribute(const std::string& Name, const std::string& Value) { if ("count"==Name) { ProcessItem(Value,m_d->m_Count); } else { std::cerr << "Unrecognised tag attribute: '" << Name << "'" << std::endl; } } void MusicBrainz5::CTag::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("name"==NodeName) { ProcessItem(Node,m_d->m_Name); } else { std::cerr << "Unrecognised tag element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CTag::GetElementName() { return "tag"; } int MusicBrainz5::CTag::Count() const { return m_d->m_Count; } std::string MusicBrainz5::CTag::Name() const { return m_d->m_Name; } std::ostream& MusicBrainz5::CTag::Serialise(std::ostream& os) const { os << "Tag:" << std::endl; CEntity::Serialise(os); os << "\tCount: " << Count() << std::endl; os << "\tName: " << Name() << std::endl; return os; } libmusicbrainz-5.0.1/src/TextRepresentation.cc000066400000000000000000000061131175500222200214740ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/TextRepresentation.h" class MusicBrainz5::CTextRepresentationPrivate { public: std::string m_Language; std::string m_Script; }; MusicBrainz5::CTextRepresentation::CTextRepresentation(const XMLNode& Node) : CEntity(), m_d(new CTextRepresentationPrivate) { if (!Node.isEmpty()) { //std::cout << "Text representation node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CTextRepresentation::CTextRepresentation(const CTextRepresentation& Other) : CEntity(), m_d(new CTextRepresentationPrivate) { *this=Other; } MusicBrainz5::CTextRepresentation& MusicBrainz5::CTextRepresentation::operator =(const CTextRepresentation& Other) { if (this!=&Other) { CEntity::operator =(Other); m_d->m_Language=Other.m_d->m_Language; m_d->m_Script=Other.m_d->m_Script; } return *this; } MusicBrainz5::CTextRepresentation::~CTextRepresentation() { delete m_d; } MusicBrainz5::CTextRepresentation *MusicBrainz5::CTextRepresentation::Clone() { return new CTextRepresentation(*this); } void MusicBrainz5::CTextRepresentation::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised textrepresentation attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CTextRepresentation::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("language"==NodeName) { ProcessItem(Node,m_d->m_Language); } else if ("script"==NodeName) { ProcessItem(Node,m_d->m_Script); } else { std::cerr << "Unrecognised textrepresentation element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CTextRepresentation::GetElementName() { return "text-representation"; } std::string MusicBrainz5::CTextRepresentation::Language() const { return m_d->m_Language; } std::string MusicBrainz5::CTextRepresentation::Script() const { return m_d->m_Script; } std::ostream& MusicBrainz5::CTextRepresentation::Serialise(std::ostream& os) const { os << "\tText Representation:" << std::endl; CEntity::Serialise(os); os << "\t\tLanguage: " << Language() << std::endl; os << "\t\tScript: " << Script() << std::endl; return os; } libmusicbrainz-5.0.1/src/Track.cc000066400000000000000000000103551175500222200166740ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Track.h" #include "musicbrainz5/Recording.h" #include "musicbrainz5/ArtistCredit.h" class MusicBrainz5::CTrackPrivate { public: CTrackPrivate() : m_Position(0), m_Recording(0), m_Length(0), m_ArtistCredit(0) { } int m_Position; std::string m_Title; CRecording *m_Recording; int m_Length; CArtistCredit *m_ArtistCredit; std::string m_Number; }; MusicBrainz5::CTrack::CTrack(const XMLNode& Node) : CEntity(), m_d(new CTrackPrivate) { if (!Node.isEmpty()) { //std::cout << "Track node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CTrack::CTrack(const CTrack& Other) : CEntity(), m_d(new CTrackPrivate) { *this=Other; } MusicBrainz5::CTrack& MusicBrainz5::CTrack::operator =(const CTrack& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_Position=Other.m_d->m_Position; m_d->m_Title=Other.m_d->m_Title; if (Other.m_d->m_Recording) m_d->m_Recording=new CRecording(*Other.m_d->m_Recording); m_d->m_Length=Other.m_d->m_Length; if (Other.m_d->m_ArtistCredit) m_d->m_ArtistCredit=new CArtistCredit(*Other.m_d->m_ArtistCredit); m_d->m_Number=Other.m_d->m_Number; } return *this; } MusicBrainz5::CTrack::~CTrack() { Cleanup(); delete m_d; } void MusicBrainz5::CTrack::Cleanup() { delete m_d->m_Recording; m_d->m_Recording=0; delete m_d->m_ArtistCredit; m_d->m_ArtistCredit=0; } MusicBrainz5::CTrack *MusicBrainz5::CTrack::Clone() { return new CTrack(*this); } void MusicBrainz5::CTrack::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised track attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CTrack::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("position"==NodeName) { ProcessItem(Node,m_d->m_Position); } else if ("title"==NodeName) { ProcessItem(Node,m_d->m_Title); } else if ("recording"==NodeName) { ProcessItem(Node,m_d->m_Recording); } else if ("length"==NodeName) { ProcessItem(Node,m_d->m_Length); } else if ("artist-credit"==NodeName) { ProcessItem(Node,m_d->m_ArtistCredit); } else if ("number"==NodeName) { ProcessItem(Node,m_d->m_Number); } else { std::cerr << "Unrecognised track element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CTrack::GetElementName() { return "track"; } int MusicBrainz5::CTrack::Position() const { return m_d->m_Position; } std::string MusicBrainz5::CTrack::Title() const { return m_d->m_Title; } MusicBrainz5::CRecording *MusicBrainz5::CTrack::Recording() const { return m_d->m_Recording; } int MusicBrainz5::CTrack::Length() const { return m_d->m_Length; } MusicBrainz5::CArtistCredit *MusicBrainz5::CTrack::ArtistCredit() const { return m_d->m_ArtistCredit; } std::string MusicBrainz5::CTrack::Number() const { return m_d->m_Number; } std::ostream& MusicBrainz5::CTrack::Serialise(std::ostream& os) const { os << "Track:" << std::endl; CEntity::Serialise(os); os << "\tPosition: " << Position() << std::endl; os << "\tTitle: " << Title() << std::endl; if (Recording()) os << *Recording() << std::endl; os << "\tLength: " << Length() << std::endl; if (ArtistCredit()) os << *ArtistCredit() << std::endl; os << "\tNumber: " << Number() << std::endl; return os; } libmusicbrainz-5.0.1/src/UserRating.cc000066400000000000000000000051701175500222200177120ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/UserRating.h" class MusicBrainz5::CUserRatingPrivate { public: CUserRatingPrivate() : m_UserRating(0) { } int m_UserRating; }; MusicBrainz5::CUserRating::CUserRating(const XMLNode& Node) : CEntity(), m_d(new CUserRatingPrivate) { if (!Node.isEmpty()) { //std::cout << "User rating node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); if (Node.getText()) { ProcessItem(Node,m_d->m_UserRating); } } } MusicBrainz5::CUserRating::CUserRating(const CUserRating& Other) : CEntity(), m_d(new CUserRatingPrivate) { *this=Other; } MusicBrainz5::CUserRating& MusicBrainz5::CUserRating::operator =(const CUserRating& Other) { if (this!=&Other) { CEntity::operator =(Other); m_d->m_UserRating=Other.m_d->m_UserRating; } return *this; } MusicBrainz5::CUserRating::~CUserRating() { delete m_d; } MusicBrainz5::CUserRating *MusicBrainz5::CUserRating::Clone() { return new CUserRating(*this); } void MusicBrainz5::CUserRating::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised userrating attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CUserRating::ParseElement(const XMLNode& Node) { std::string Name=Node.getName(); std::cerr << "Unrecognised userrating element: '" << Name << "'" << std::endl; } std::string MusicBrainz5::CUserRating::GetElementName() { return "user-rating"; } int MusicBrainz5::CUserRating::UserRating() const { return m_d->m_UserRating; } std::ostream& MusicBrainz5::CUserRating::Serialise(std::ostream& os) const { os << "User rating:" << std::endl; CEntity::Serialise(os); os << "\tRating: " << UserRating() << std::endl; return os; } libmusicbrainz-5.0.1/src/UserTag.cc000066400000000000000000000047501175500222200172040ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/UserTag.h" class MusicBrainz5::CUserTagPrivate { public: std::string m_Name; }; MusicBrainz5::CUserTag::CUserTag(const XMLNode& Node) : CEntity(), m_d(new CUserTagPrivate) { if (!Node.isEmpty()) { //std::cout << "UserTag node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CUserTag::CUserTag(const CUserTag& Other) : CEntity(), m_d(new CUserTagPrivate) { *this=Other; } MusicBrainz5::CUserTag& MusicBrainz5::CUserTag::operator =(const CUserTag& Other) { if (this!=&Other) { CEntity::operator =(Other); m_d->m_Name=Other.m_d->m_Name; } return *this; } MusicBrainz5::CUserTag::~CUserTag() { delete m_d; } MusicBrainz5::CUserTag *MusicBrainz5::CUserTag::Clone() { return new CUserTag(*this); } void MusicBrainz5::CUserTag::ParseAttribute(const std::string& Name, const std::string& /*Value*/) { std::cerr << "Unrecognised usertag attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CUserTag::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("name"==NodeName) { ProcessItem(Node,m_d->m_Name); } else { std::cerr << "Unrecognised UserTag element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CUserTag::GetElementName() { return "user-tag"; } std::string MusicBrainz5::CUserTag::Name() const { return m_d->m_Name; } std::ostream& MusicBrainz5::CUserTag::Serialise(std::ostream& os) const { os << "UserTag:" << std::endl; CEntity::Serialise(os); os << "\tName: " << Name() << std::endl; return os; } libmusicbrainz-5.0.1/src/Work.cc000066400000000000000000000164751175500222200165630ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include "musicbrainz5/Work.h" #include "musicbrainz5/ArtistCredit.h" #include "musicbrainz5/AliasList.h" #include "musicbrainz5/Alias.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/RelationListList.h" #include "musicbrainz5/TagList.h" #include "musicbrainz5/Tag.h" #include "musicbrainz5/UserTagList.h" #include "musicbrainz5/UserTag.h" #include "musicbrainz5/Rating.h" #include "musicbrainz5/UserRating.h" #include "musicbrainz5/ISWC.h" #include "musicbrainz5/ISWCList.h" class MusicBrainz5::CWorkPrivate { public: CWorkPrivate() : m_ArtistCredit(0), m_ISWCList(0), m_AliasList(0), m_RelationListList(0), m_TagList(0), m_UserTagList(0), m_Rating(0), m_UserRating(0) { } std::string m_ID; std::string m_Type; std::string m_Title; CArtistCredit *m_ArtistCredit; CISWCList *m_ISWCList; std::string m_Disambiguation; CAliasList *m_AliasList; CRelationListList *m_RelationListList; CTagList *m_TagList; CUserTagList *m_UserTagList; CRating *m_Rating; CUserRating *m_UserRating; std::string m_Language; }; MusicBrainz5::CWork::CWork(const XMLNode& Node) : CEntity(), m_d(new CWorkPrivate) { if (!Node.isEmpty()) { //std::cout << "Work node: " << std::endl << Node.createXMLString(true) << std::endl; Parse(Node); } } MusicBrainz5::CWork::CWork(const CWork& Other) : CEntity(), m_d(new CWorkPrivate) { *this=Other; } MusicBrainz5::CWork& MusicBrainz5::CWork::operator =(const CWork& Other) { if (this!=&Other) { Cleanup(); CEntity::operator =(Other); m_d->m_ID=Other.m_d->m_ID; m_d->m_Type=Other.m_d->m_Type; m_d->m_Title=Other.m_d->m_Title; if (Other.m_d->m_ArtistCredit) m_d->m_ArtistCredit=new CArtistCredit(*Other.m_d->m_ArtistCredit); if (Other.m_d->m_ISWCList) m_d->m_ISWCList=new CISWCList(*Other.m_d->m_ISWCList); m_d->m_Disambiguation=Other.m_d->m_Disambiguation; if (Other.m_d->m_AliasList) m_d->m_AliasList=new CAliasList(*Other.m_d->m_AliasList); if (Other.m_d->m_RelationListList) m_d->m_RelationListList=new CRelationListList(*Other.m_d->m_RelationListList); if (Other.m_d->m_TagList) m_d->m_TagList=new CTagList(*Other.m_d->m_TagList); if (Other.m_d->m_UserTagList) m_d->m_UserTagList=new CUserTagList(*Other.m_d->m_UserTagList); if (Other.m_d->m_Rating) m_d->m_Rating=new CRating(*Other.m_d->m_Rating); if (Other.m_d->m_UserRating) m_d->m_UserRating=new CUserRating(*Other.m_d->m_UserRating); m_d->m_Language=Other.m_d->m_Language; } return *this; } MusicBrainz5::CWork::~CWork() { Cleanup(); delete m_d; } void MusicBrainz5::CWork::Cleanup() { delete m_d->m_ArtistCredit; m_d->m_ArtistCredit=0; delete m_d->m_ISWCList; m_d->m_ISWCList=0; delete m_d->m_AliasList; m_d->m_AliasList=0; delete m_d->m_RelationListList; m_d->m_RelationListList=0; delete m_d->m_TagList; m_d->m_TagList=0; delete m_d->m_UserTagList; m_d->m_UserTagList=0; delete m_d->m_Rating; m_d->m_Rating=0; delete m_d->m_UserRating; m_d->m_UserRating=0; } MusicBrainz5::CWork *MusicBrainz5::CWork::Clone() { return new CWork(*this); } void MusicBrainz5::CWork::ParseAttribute(const std::string& Name, const std::string& Value) { if ("id"==Name) m_d->m_ID=Value; else if ("type"==Name) m_d->m_Type=Value; else std::cerr << "Unrecognised work attribute: '" << Name << "'" << std::endl; } void MusicBrainz5::CWork::ParseElement(const XMLNode& Node) { std::string NodeName=Node.getName(); if ("title"==NodeName) { ProcessItem(Node,m_d->m_Title); } else if ("artist-credit"==NodeName) { ProcessItem(Node,m_d->m_ArtistCredit); } else if ("iswc-list"==NodeName) { ProcessItem(Node,m_d->m_ISWCList); } else if ("disambiguation"==NodeName) { ProcessItem(Node,m_d->m_Disambiguation); } else if ("alias-list"==NodeName) { ProcessItem(Node,m_d->m_AliasList); } else if ("relation-list"==NodeName) { ProcessRelationList(Node,m_d->m_RelationListList); } else if ("tag-list"==NodeName) { ProcessItem(Node,m_d->m_TagList); } else if ("user-tag-list"==NodeName) { ProcessItem(Node,m_d->m_UserTagList); } else if ("rating"==NodeName) { ProcessItem(Node,m_d->m_Rating); } else if ("user-rating"==NodeName) { ProcessItem(Node,m_d->m_UserRating); } else if ("language"==NodeName) { ProcessItem(Node,m_d->m_Language); } else { std::cerr << "Unrecognised work element: '" << NodeName << "'" << std::endl; } } std::string MusicBrainz5::CWork::GetElementName() { return "work"; } std::string MusicBrainz5::CWork::ID() const { return m_d->m_ID; } std::string MusicBrainz5::CWork::Type() const { return m_d->m_Type; } std::string MusicBrainz5::CWork::Title() const { return m_d->m_Title; } MusicBrainz5::CArtistCredit *MusicBrainz5::CWork::ArtistCredit() const { return m_d->m_ArtistCredit; } MusicBrainz5::CISWCList *MusicBrainz5::CWork::ISWCList() const { return m_d->m_ISWCList; } std::string MusicBrainz5::CWork::Disambiguation() const { return m_d->m_Disambiguation; } MusicBrainz5::CAliasList *MusicBrainz5::CWork::AliasList() const { return m_d->m_AliasList; } MusicBrainz5::CRelationListList *MusicBrainz5::CWork::RelationListList() const { return m_d->m_RelationListList; } MusicBrainz5::CTagList *MusicBrainz5::CWork::TagList() const { return m_d->m_TagList; } MusicBrainz5::CUserTagList *MusicBrainz5::CWork::UserTagList() const { return m_d->m_UserTagList; } MusicBrainz5::CRating *MusicBrainz5::CWork::Rating() const { return m_d->m_Rating; } MusicBrainz5::CUserRating *MusicBrainz5::CWork::UserRating() const { return m_d->m_UserRating; } std::string MusicBrainz5::CWork::Language() const { return m_d->m_Language; } std::ostream& MusicBrainz5::CWork::Serialise(std::ostream& os) const { os << "Work:" << std::endl; CEntity::Serialise(os); os << "\tID: " << ID() << std::endl; os << "\tWork: " << Type() << std::endl; os << "\tTitle: " << Title() << std::endl; if (ArtistCredit()) os << ArtistCredit() << std::endl; if (ISWCList()) os << ISWCList() << std::endl; os << "\tDisambiguation: " << Disambiguation() << std::endl; if (AliasList()) os << AliasList() << std::endl; if (RelationListList()) os << RelationListList() << std::endl; if (TagList()) os << TagList() << std::endl; if (UserTagList()) os << UserTagList() << std::endl; if (Rating()) os << Rating() << std::endl; if (UserRating()) os << UserRating() << std::endl; os << "\tLanguage: " << Language() << std::endl; return os; } libmusicbrainz-5.0.1/src/c-int-medium-defines.inc000066400000000000000000000021771175500222200217220ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ /** * @see MusicBrainz5::CMedium::ContainsDiscID * * @param Medium #Mb5Medium object * @param DiscID DiscID to check * * @return 1 if DiscID found, 0 otherwise */ unsigned char mb5_medium_contains_discid(Mb5Medium Medium, const char *DiscID); libmusicbrainz-5.0.1/src/c-int-medium-source.inc000066400000000000000000000022401175500222200215740ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ unsigned char mb5_medium_contains_discid(Mb5Medium Medium, const char *DiscID) { unsigned char Ret=0; if (Medium) { MusicBrainz5::CMedium *TheMedium=reinterpret_cast(Medium); if (TheMedium) Ret=TheMedium->ContainsDiscID(DiscID); } return Ret; } libmusicbrainz-5.0.1/src/c-int-query-defines.inc000066400000000000000000000130721175500222200216030ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ /** * Create a new instance of #Mb5Query. * * @see MusicBrainz5::CQuery::CQuery * * @param UserAgent User agent to be passed to submissions * @param Server Server to use, pass null to use the default server * @param Port Port to use, pass 0 to use the default port * * @return The newly created #Mb5Query object. This object must be deleted once * finished with. */ Mb5Query mb5_query_new(const char *UserAgent, const char *Server, int Port); /** * Set the username for authenticating to MusicBrainz * * @see MusicBrainz5::CQuery::SetUserName * * @param Query #Mb5Query object * @param UserName Username to use */ void mb5_query_set_username(Mb5Query Query, const char *UserName); /** * Set the password for authenticating to MusicBrainz * * @see MusicBrainz5::CQuery::SetPassword * * @param Query #Mb5Query object * @param Password Password to use */ void mb5_query_set_password(Mb5Query Query, const char *Password); /** * Set the proxy server * * @see MusicBrainz5::CQuery::SetProxyHost * * @param Query #Mb5Query object * @param ProxyHost Proxy server to use */ void mb5_query_set_proxyhost(Mb5Query Query, const char *ProxyHost); /** * Set the port to use on the proxy server * * @see MusicBrainz5::CQuery::SetProxyPort * * @param Query #Mb5Query object * @param ProxyPort Port to use on proxy server */ void mb5_query_set_proxyport(Mb5Query Query, int ProxyPort); /** * Set the username to use to authenticate to the proxy server * * @see MusicBrainz5::CQuery::SetProxyUserName * * @param Query #Mb5Query object * @param ProxyUserName User name to use */ void mb5_query_set_proxyusername(Mb5Query Query, const char *ProxyUserName); /** * Set the password to use to authenticate to the proxy server * * @see MusicBrainz5::CQuery::SetProxyPassword * * @param Query #Mb5Query object * @param ProxyPassword Password to use */ void mb5_query_set_proxypassword(Mb5Query Query, const char *ProxyPassword); /** * Return a list of releases that match the specified Disc ID * * @see MusicBrainz5::CQuery::LookupDiscID * * @param Query #Mb5Query object * @param DiscID DiscID to lookup * * @return A #Mb5ReleaseList object. This object must be deleted once * finished with. */ Mb5ReleaseList mb5_query_lookup_discid(Mb5Query Query, const char *DiscID); /** * Return full information about a specific release * * @see MusicBrainz5::CQuery::LookupRelease * * @param Query #Mb5Query object * @param Release Release to return information for * * @return A #Mb5Release object. This object must be deleted once * finished with. */ Mb5Release mb5_query_lookup_release(Mb5Query Query, const char *Release); /** * Perform a generic query * * @see MusicBrainz5::CQuery::Query * * @param Query #Mb5Query object * @param Entity The entity to query * @param ID The ID to query * @param Resource The resource to query * @param NumParams The number of parameters in the following arrays * @param ParamNames Array of strings containing parameter names * @param ParamValues Array of space seperated parameter values * * @return A #Mb5Metadata object. This object must be deleted once * finished with. */ Mb5Metadata mb5_query_query(Mb5Query Query, const char *Entity, const char *ID, const char *Resource, int NumParams, char **ParamNames, char **ParamValues); /** * Add a list of releases to a collection * * @see MusicBrainz5::CQuery::AddCollectionEntries * * @param Query #Mb5Query object * @param Collection ID of collection to add releases to * @param NumEntries The number of entries to add * @param Entries Array of strings of release IDs to add * * @return 0 on failure, 1 on success */ unsigned char mb5_query_add_collection_entries(Mb5Query Query, const char *Collection, int NumEntries, const char **Entries); /** * Delete a list of releases from a collection * * @see MusicBrainz5::CQuery::AddCollectionEntries * * @param Query #Mb5Query object * @param Collection ID of collection to delete releases from * @param NumEntries The number of entries to delete * @param Entries Array of strings of release IDs to delete * * @return 0 on failure, 1 on success */ unsigned char mb5_query_delete_collection_entries(Mb5Query Query, const char *Collection, int NumEntries, const char **Entries); /** * @see MusicBrainz5::CQuery::tQueryResult */ typedef enum { eQuery_Success=0, eQuery_ConnectionError, eQuery_Timeout, eQuery_AuthenticationError, eQuery_FetchError, eQuery_RequestError, eQuery_ResourceNotFound } tQueryResult; /** * @see MusicBrainz5::CQuery::LastResult * * @param Query #Mb5Query object * * @return Last query result code */ tQueryResult mb5_query_get_lastresult(Mb5Query Query); libmusicbrainz-5.0.1/src/c-int-query-source.inc000066400000000000000000000100021175500222200214540ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ Mb5Query mb5_query_new(const char *UserAgent, const char *Server, int Port) { return new MusicBrainz5::CQuery(UserAgent, Server ? Server : "musicbrainz.org", Port!=0 ? Port : 80); } MB5_C_STR_SETTER(Query,query,UserName,username) MB5_C_STR_SETTER(Query,query,Password,password) MB5_C_STR_SETTER(Query,query,ProxyHost,proxyhost) MB5_C_INT_SETTER(Query,query,ProxyPort,proxyport) MB5_C_STR_SETTER(Query,query,ProxyUserName,proxyusername) MB5_C_STR_SETTER(Query,query,ProxyPassword,proxypassword) Mb5ReleaseList mb5_query_lookup_discid(Mb5Query Query, const char *DiscID) { if (Query) { try { MusicBrainz5::CQuery *TheQuery=reinterpret_cast(Query); if (TheQuery) return new MusicBrainz5::CReleaseList(TheQuery->LookupDiscID(DiscID)); } catch(...) { } } return 0; } Mb5Release mb5_query_lookup_release(Mb5Query Query, const char *Release) { if (Query) { try { MusicBrainz5::CQuery *TheQuery=reinterpret_cast(Query); if (TheQuery) return new MusicBrainz5::CRelease(TheQuery->LookupRelease(Release)); } catch(...) { } } return 0; } Mb5Metadata mb5_query_query(Mb5Query Query, const char *Entity, const char *ID, const char *Resource, int NumParams, char **ParamName, char **ParamValue) { if (Query) { try { MusicBrainz5::CQuery::tParamMap Params; for (int count=0;count(Query); if (TheQuery) return new MusicBrainz5::CMetadata(TheQuery->Query(Entity?Entity:"", ID?ID:"", Resource?Resource:"", Params)); } catch(...) { } } return 0; } unsigned char mb5_query_add_collection_entries(Mb5Query Query, const char *Collection, int NumEntries, const char **Entries) { if (Query) { try { std::vector VecEntries; MusicBrainz5::CQuery *TheQuery=reinterpret_cast(Query); if (TheQuery) { for (int count=0;countAddCollectionEntries(Collection,VecEntries)?1:0; } } catch(...) { } } return 0; } unsigned char mb5_query_delete_collection_entries(Mb5Query Query, const char *Collection, int NumEntries, const char **Entries) { if (Query) { try { std::vector VecEntries; MusicBrainz5::CQuery *TheQuery=reinterpret_cast(Query); if (TheQuery) { for (int count=0;countAddCollectionEntries(Collection,VecEntries)?1:0; } } catch(...) { } } return 0; } tQueryResult mb5_query_get_lastresult(Mb5Query o) { if (o) { try { return (tQueryResult)((MusicBrainz5::CQuery *)o)->LastResult(); } catch (...) { } } return eQuery_FetchError; } libmusicbrainz-5.0.1/src/c-int-release-defines.inc000066400000000000000000000023001175500222200220460ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ /** * @see MusicBrainz5::CRelease::MediaMatchingDiscID * * @param Release #Mb5Release object * @param DiscID DiscID to match * * @return #Mb5MediumList. This object must be deleted once * finished with. */ Mb5MediumList mb5_release_media_matching_discid(Mb5Release Release, const char *DiscID); libmusicbrainz-5.0.1/src/c-int-release-source.inc000066400000000000000000000022771175500222200217460ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ Mb5MediumList mb5_release_media_matching_discid(Mb5Release Release, const char *DiscID) { if (Release) { MusicBrainz5::CRelease *TheRelease=reinterpret_cast(Release); if (TheRelease) return new MusicBrainz5::CMediumList(TheRelease->MediaMatchingDiscID(DiscID)); } return 0; } libmusicbrainz-5.0.1/src/c-int-source-funcs.inc000066400000000000000000000201571175500222200214410ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "musicbrainz5/defines.h" #include "musicbrainz5/Query.h" #include "musicbrainz5/mb5_c.h" #include #include "musicbrainz5/Alias.h" #include "musicbrainz5/AliasList.h" #include "musicbrainz5/Annotation.h" #include "musicbrainz5/AnnotationList.h" #include "musicbrainz5/Artist.h" #include "musicbrainz5/ArtistList.h" #include "musicbrainz5/ArtistCredit.h" #include "musicbrainz5/Attribute.h" #include "musicbrainz5/AttributeList.h" #include "musicbrainz5/CDStub.h" #include "musicbrainz5/CDStubList.h" #include "musicbrainz5/Collection.h" #include "musicbrainz5/CollectionList.h" #include "musicbrainz5/Disc.h" #include "musicbrainz5/DiscList.h" #include "musicbrainz5/FreeDBDisc.h" #include "musicbrainz5/FreeDBDiscList.h" #include "musicbrainz5/IPI.h" #include "musicbrainz5/ISRC.h" #include "musicbrainz5/ISRCList.h" #include "musicbrainz5/ISWC.h" #include "musicbrainz5/ISWCList.h" #include "musicbrainz5/Label.h" #include "musicbrainz5/LabelList.h" #include "musicbrainz5/LabelInfo.h" #include "musicbrainz5/LabelInfoList.h" #include "musicbrainz5/Lifespan.h" #include "musicbrainz5/Medium.h" #include "musicbrainz5/MediumList.h" #include "musicbrainz5/Message.h" #include "musicbrainz5/Metadata.h" #include "musicbrainz5/NameCredit.h" #include "musicbrainz5/NameCreditList.h" #include "musicbrainz5/NonMBTrack.h" #include "musicbrainz5/NonMBTrackList.h" #include "musicbrainz5/PUID.h" #include "musicbrainz5/PUIDList.h" #include "musicbrainz5/Rating.h" #include "musicbrainz5/Recording.h" #include "musicbrainz5/RecordingList.h" #include "musicbrainz5/Relation.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/RelationListList.h" #include "musicbrainz5/Release.h" #include "musicbrainz5/ReleaseGroup.h" #include "musicbrainz5/ReleaseGroupList.h" #include "musicbrainz5/SecondaryType.h" #include "musicbrainz5/SecondaryTypeList.h" #include "musicbrainz5/Tag.h" #include "musicbrainz5/TagList.h" #include "musicbrainz5/TextRepresentation.h" #include "musicbrainz5/Track.h" #include "musicbrainz5/TrackList.h" #include "musicbrainz5/UserRating.h" #include "musicbrainz5/UserTag.h" #include "musicbrainz5/UserTagList.h" #include "musicbrainz5/Work.h" #include "musicbrainz5/WorkList.h" std::string GetMapName(std::map Map, int Item) { std::string Ret; if (Item<(int)Map.size()) { std::map::const_iterator ThisItem=Map.begin(); int count=0; while (count Map, int Item) { std::string Ret; if (Item<(int)Map.size()) { std::map::const_iterator ThisItem=Map.begin(); int count=0; while (countSet##PROP1(str); \ } \ catch (...) { \ } \ } \ } #define MB5_C_INT_SETTER(TYPE1, TYPE2, PROP1, PROP2) \ void \ mb5_##TYPE2##_set_##PROP2(Mb5##TYPE1 o, int i) \ { \ if (o) \ { \ try { \ ((MusicBrainz5::C##TYPE1 *)o)->Set##PROP1(i); \ } \ catch (...) { \ } \ } \ } #define MB5_C_STR_GETTER(TYPE1, TYPE2, PROP1, PROP2) \ int \ mb5_##TYPE2##_get_##PROP2(Mb5##TYPE1 o, char *str, int len) \ { \ int ret=0; \ if (str) \ *str=0; \ if (o) \ { \ try { \ ret=((MusicBrainz5::C##TYPE1 *)o)->PROP1().length(); \ if (str && len) \ { \ strncpy(str, ((MusicBrainz5::C##TYPE1 *)o)->PROP1().c_str(), len); \ str[len-1]='\0'; \ } \ } \ catch (...) { \ str[0] = '\0'; \ } \ } \ return ret; \ } #define MB5_C_INT_GETTER(TYPE1, TYPE2, PROP1, PROP2) \ int \ mb5_##TYPE2##_get_##PROP2(Mb5##TYPE1 o) \ { \ if (o) \ { \ try { \ return ((MusicBrainz5::C##TYPE1 *)o)->PROP1(); \ } \ catch (...) { \ } \ } \ return 0; \ } #define MB5_C_DOUBLE_GETTER(TYPE1, TYPE2, PROP1, PROP2) \ double \ mb5_##TYPE2##_get_##PROP2(Mb5##TYPE1 o) \ { \ if (o) \ { \ try { \ return ((MusicBrainz5::C##TYPE1 *)o)->PROP1(); \ } \ catch (...) { \ } \ } \ return 0; \ } #define MB5_C_BOOL_GETTER(TYPE1, TYPE2, PROP1, PROP2) \ unsigned char \ mb5_##TYPE2##_get_##PROP2(Mb##TYPE1 o) \ { \ if (o) \ { \ try { \ return ((TYPE1 *)o)->PROP1() ? 1 : 0; \ } \ catch (...) { \ return 0; \ } \ } \ } #define MB5_C_OBJ_GETTER(TYPE1, TYPE2, PROP1, PROP2) \ Mb5##PROP1 \ mb5_##TYPE2##_get_##PROP2(Mb5##TYPE1 o) \ { \ if (o) \ { \ try { \ return (Mb5##PROP1)((MusicBrainz5::C##TYPE1 *)o)->PROP1(); \ } \ catch (...) { \ } \ } \ return (Mb5##PROP1)0; \ } #define MB5_C_LIST_GETTER(TYPE1, TYPE2) \ void \ mb5_##TYPE2##_list_delete(Mb5##TYPE1 o) \ { \ delete (MusicBrainz5::C##TYPE1##List *)o; \ } \ int \ mb5_##TYPE2##_list_size(Mb5##TYPE1##List List) \ { \ if (List) \ { \ try { \ return ((MusicBrainz5::C##TYPE1##List *)List)->NumItems(); \ } \ catch (...) { \ return 0; \ } \ } \ return 0; \ } \ \ Mb5##TYPE1 \ mb5_##TYPE2##_list_item(Mb5##TYPE1##List List, int Item) \ { \ if (List) \ { \ try { \ return ((MusicBrainz5::C##TYPE1##List *)List)->Item(Item); \ } \ catch (...) { \ return (Mb5##TYPE1)0; \ } \ } \ return (Mb5##TYPE1)0; \ } \ int \ mb5_##TYPE2##_list_get_count(Mb5##TYPE1##List List) \ { \ if (List) \ { \ try { \ return ((MusicBrainz5::C##TYPE1##List *)List)->Count(); \ } \ catch (...) { \ return 0; \ } \ } \ return 0; \ } \ \ int \ mb5_##TYPE2##_list_get_offset(Mb5##TYPE1##List List) \ { \ if (List) \ { \ try { \ return ((MusicBrainz5::C##TYPE1##List *)List)->Offset(); \ } \ catch (...) { \ return 0; \ } \ } \ return 0; \ } \ \ #define MB5_C_EXT_GETTER(PROP1, PROP2) \ int \ mb5_entity_ext_##PROP2##s_size(Mb5Entity o) \ { \ if (o) \ { \ return ((MusicBrainz5::CEntity *)o)->Ext##PROP1##s().size(); \ } \ return 0; \ } \ int \ mb5_entity_ext_##PROP2##_name(Mb5Entity o, int Item, char *str, int len) \ { \ int ret=0; \ if (str) \ *str=0; \ if (o) \ { \ std::map Items=((MusicBrainz5::CEntity *)o)->Ext##PROP1##s(); \ std::string Name=GetMapName(Items,Item); \ ret=Name.length(); \ if (str && len) \ { \ strncpy(str, Name.c_str(), len); \ str[len-1]='\0'; \ } \ } \ return ret; \ } \ int \ mb5_entity_ext_##PROP2##_value(Mb5Entity o, int Item, char *str, int len) \ { \ int ret=0; \ if (str) \ *str=0; \ if (o) \ { \ std::map Items=((MusicBrainz5::CEntity *)o)->Ext##PROP1##s(); \ std::string Name=GetMapValue(Items,Item); \ ret=Name.length(); \ if (str && len) \ { \ strncpy(str, Name.c_str(), len); \ str[len-1]='\0'; \ } \ } \ return ret; \ } \ libmusicbrainz-5.0.1/src/cinterface.xml000066400000000000000000000401201175500222200201370ustar00rootroot00000000000000
/* Things you should delete using the appropriate mb5_xxx_delete() function: * The query object you create to do the actual work * Any object or list returned from one of the mb5_query_xxx() functions * The return from mb5_release_media_matching_discid() function * The return from any mb5_xxx_clone() function Everything else remains managed by the library, and should not be deleted If in doubt, valgrind is a useful way to spot leaks or things being deleted when they shouldn't be. */ #ifndef _MUSICBRAINZ5_MB_C_H #define _MUSICBRAINZ5_MB_C_H #include "musicbrainz5/defines.h" #ifdef __cplusplus extern "C" { #endif #ifdef __cplusplus } #endif #endif libmusicbrainz-5.0.1/src/make-c-interface.cc000066400000000000000000000657541175500222200207400ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include "config.h" #include "musicbrainz5/defines.h" #include #include #include #include #include #include "musicbrainz5/xmlParser.h" void ProcessBoilerplate(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include); void ProcessHeader(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include); void ProcessEntity(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include); void ProcessClass(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include); void ProcessList(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include); void ProcessDeclare(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include); int main(int argc, const char *argv[]) { for (int count=0;count." << std::endl; os << std::endl; os << " THIS FILE IS AUTOMATICALLY GENERATED - DO NOT EDIT IT!" << std::endl; os << std::endl; os << "----------------------------------------------------------------------------*/" << std::endl; os << std::endl; Source << os.str() << std::endl; Include << os.str() << std::endl; } void ProcessBoilerplate(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include) { std::ofstream *File=GetFile(Node,Source,Include); if (Node.isAttributeSet("file")) { std::string FileName=Node.getAttribute("file"); std::ifstream InFile(FileName.c_str()); if (InFile.is_open()) *File << InFile.rdbuf() << std::endl; else { std::cerr << "Error opening include file '" << FileName << "'" << std::endl; exit(1); } } else if (Node.getText()) { *File << Node.getText() << std::endl; } *File << std::endl; } void ProcessEntity(const XMLNode& /*Node*/, std::ofstream& Source, std::ofstream& Include) { Include << "/**" << std::endl; Include << " * Returns the number of extension attributes for the entity" << std::endl; Include << " *" << std::endl; Include << " * @param Entity #Mb5Entity object" << std::endl; Include << " *" << std::endl; Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; Include << " */" << std::endl; Include << " int mb5_entity_ext_attributes_size(Mb5Entity Entity);" << std::endl; Include << std::endl; Include << "/**" << std::endl; Include << " * Returns the name of the requested extension attribute" << std::endl; Include << " *" << std::endl; Include << " * @param Entity #Mb5Entity object" << std::endl; Include << " * @param Item Item to return" << std::endl; Include << " * @param str Returned string" << std::endl; Include << " * @param len Number of characters available in return string" << std::endl; Include << " *" << std::endl; Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; Include << " */" << std::endl; Include << " int mb5_entity_ext_attribute_name(Mb5Entity Entity, int Item, char *str, int len);" << std::endl; Include << std::endl; Include << "/**" << std::endl; Include << " * Returns the value of the requested extension attribute" << std::endl; Include << " *" << std::endl; Include << " * @param Entity #Mb5Entity object" << std::endl; Include << " * @param Item Item to return" << std::endl; Include << " * @param str Returned string" << std::endl; Include << " * @param len Number of characters available in return string" << std::endl; Include << " *" << std::endl; Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; Include << " */" << std::endl; Include << " int mb5_entity_ext_attribute_value(Mb5Entity Entity, int Item, char *str, int len);" << std::endl; Include << std::endl; Include << "/**" << std::endl; Include << " * Returns the number of extension elements for the entity" << std::endl; Include << " *" << std::endl; Include << " * @param Entity #Mb5Entity object" << std::endl; Include << " *" << std::endl; Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; Include << " */" << std::endl; Include << " int mb5_entity_ext_elements_size(Mb5Entity Entity);" << std::endl; Include << std::endl; Include << "/**" << std::endl; Include << " * Returns the name of the requested extension element" << std::endl; Include << " *" << std::endl; Include << " * @param Entity #Mb5Entity object" << std::endl; Include << " * @param Item Item to return" << std::endl; Include << " * @param str Returned string" << std::endl; Include << " * @param len Number of characters available in return string" << std::endl; Include << " *" << std::endl; Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; Include << " */" << std::endl; Include << " int mb5_entity_ext_element_name(Mb5Entity Entity, int Item, char *str, int len);" << std::endl; Include << std::endl; Include << "/**" << std::endl; Include << " * Returns the value of the requested extension element" << std::endl; Include << " *" << std::endl; Include << " * @param Entity #Mb5Entity object" << std::endl; Include << " * @param Item Item to return" << std::endl; Include << " * @param str Returned string" << std::endl; Include << " * @param len Number of characters available in return string" << std::endl; Include << " *" << std::endl; Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; Include << " */" << std::endl; Include << " int mb5_entity_ext_element_value(Mb5Entity Entity, int Item, char *str, int len);" << std::endl; Include << std::endl; Source << " MB5_C_EXT_GETTER(Attribute,attribute)" << std::endl; Source << " MB5_C_EXT_GETTER(Element,element)" << std::endl; Source << std::endl; } void ProcessClass(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include) { if (Node.isAttributeSet("name")) { std::string LowerName=Node.getAttribute("name"); std::string UpperName=LowerName; if (Node.isAttributeSet("uppername")) UpperName=Node.getAttribute("uppername"); else UpperName[0]=toupper(UpperName[0]); Include << "/**" << std::endl; Include << "* Delete an #Mb5" << UpperName << " object" << std::endl; Include << "*" << std::endl; Include << "* @param " << UpperName << " Object to delete" << std::endl; Include << "*/" << std::endl; Include << " void mb5_" << LowerName << "_delete(Mb5" << UpperName << " " << UpperName << ");" << std::endl; Include << std::endl; Source << " MB5_C_DELETE(" << UpperName << "," << LowerName << ")" << std::endl; Include << "/**" << std::endl; Include << "* Clone an #Mb5" << UpperName << " object" << std::endl; Include << "*" << std::endl; Include << "* @param " << UpperName << " Object to clone" << std::endl; Include << "*" << std::endl; Include << "* @return Cloned object. This object must be deleted once" << std::endl; Include << "* finished with." << std::endl; Include << "*/" << std::endl; Include << " Mb5" << UpperName << " mb5_" << LowerName << "_clone(Mb5" << UpperName << " " << UpperName << ");" << std::endl; Include << std::endl; Source << " MB5_C_CLONE(" << UpperName << "," << LowerName << ")" << std::endl; for (int count=0;countThis method is deprecated, please use #" << Replacement << "" << std::endl; Include << " *" << std::endl; } Include << " * @param " << UpperName << " #Mb5" << UpperName << " object" << std::endl; Include << " * @param str Returned string" << std::endl; Include << " * @param len Number of characters available in return string" << std::endl; Include << " *" << std::endl; Include << " * @return The number of characters in the string to copy (not including terminating NULL)" << std::endl; Include << " */" << std::endl; Include << " "; if (Deprecated) Include << "LIBMB5_DEPRECATED(" << Replacement << ") "; Include << "int mb5_" << LowerName << "_get_" << PropertyLowerName << "(Mb5" << UpperName << " " << UpperName << ", char *str, int len);" << std::endl; Include << std::endl; Source << " MB5_C_STR_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "," << PropertyLowerName << ")" << std::endl; } else if ("integer"==PropertyType) { Include << "/**" << std::endl; Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << std::endl; Include << " *" << std::endl; Include << " * @param " << UpperName << " #Mb5" << UpperName << " object" << std::endl; Include << " *" << std::endl; Include << " * @return Returned value" << std::endl; Include << " */" << std::endl; Include << " int mb5_" << LowerName << "_get_" << PropertyLowerName << "(Mb5" << UpperName << " " << UpperName << ");" << std::endl; Include << std::endl; Source << " MB5_C_INT_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "," << PropertyLowerName << ")" << std::endl; } else if ("double"==PropertyType) { Include << "/**" << std::endl; Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << std::endl; Include << " *" << std::endl; Include << " * @param " << UpperName << " #Mb5" << UpperName << " object" << std::endl; Include << " *" << std::endl; Include << " * @return Returned value" << std::endl; Include << " */" << std::endl; Include << " double mb5_" << LowerName << "_get_" << PropertyLowerName << "(Mb5" << UpperName << " " << UpperName << ");" << std::endl; Include << std::endl; Source << " MB5_C_DOUBLE_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "," << PropertyLowerName << ")" << std::endl; } else if ("object"==PropertyType) { Include << "/**" << std::endl; Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << std::endl; Include << " *" << std::endl; Include << " * @param " << UpperName << " #Mb5" << UpperName << " object" << std::endl; Include << " *" << std::endl; Include << " * @return #Mb5" << PropertyUpperName << " object" << std::endl; Include << " */" << std::endl; Include << " Mb5" << PropertyUpperName << " mb5_" << LowerName << "_get_" << PropertyLowerName << "(Mb5" << UpperName << " " << UpperName << ");" << std::endl; Include << std::endl; Source << " MB5_C_OBJ_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "," << PropertyLowerName << ")" << std::endl; } else if ("relationlist"==PropertyType) { Include << "/**" << std::endl; Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << "List" << std::endl; Include << " *" << std::endl; Include << " * @param " << UpperName << " #Mb5" << UpperName << "List object" << std::endl; Include << " *" << std::endl; Include << " * @return #Mb5" << PropertyUpperName << "List object" << std::endl; Include << " */" << std::endl; Include << " Mb5" << PropertyUpperName << "List mb5_" << LowerName << "_get_" << PropertyLowerName << "list(Mb5" << UpperName << " " << UpperName << ");" << std::endl; Include << std::endl; Source << " MB5_C_OBJ_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "List," << PropertyLowerName << "list)" << std::endl; } else if ("iswc"==PropertyType) { Include << "/**" << std::endl; Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << "List" << std::endl; Include << " *" << std::endl; Include << " * @param " << UpperName << " #Mb5" << UpperName << "List object" << std::endl; Include << " *" << std::endl; Include << " * @return #Mb5" << PropertyUpperName << "List object" << std::endl; Include << " */" << std::endl; Include << " Mb5" << PropertyUpperName << "List mb5_" << LowerName << "_get_" << PropertyLowerName << "list(Mb5" << UpperName << " " << UpperName << ");" << std::endl; Include << std::endl; Source << " MB5_C_OBJ_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "List," << PropertyLowerName << "list)" << std::endl; } else if ("ipi"==PropertyType) { Include << "/**" << std::endl; Include << " * @see MusicBrainz5::C" << UpperName << "::" << PropertyUpperName << "List" << std::endl; Include << " *" << std::endl; Include << " * @param " << UpperName << " #Mb5" << UpperName << "List object" << std::endl; Include << " *" << std::endl; Include << " * @return #Mb5" << PropertyUpperName << "List object" << std::endl; Include << " */" << std::endl; Include << " Mb5" << PropertyUpperName << "List mb5_" << LowerName << "_get_" << PropertyLowerName << "list(Mb5" << UpperName << " " << UpperName << ");" << std::endl; Include << std::endl; Source << " MB5_C_OBJ_GETTER(" << UpperName << "," << LowerName << "," << PropertyUpperName << "List," << PropertyLowerName << "list)" << std::endl; } else { std::cerr << "Unexpected property type: '" << PropertyType << "'" << std::endl; exit(1); } } else { std::cerr << "Class " << LowerName << " property specified with no name or type" << std::endl; exit(1); } } } Source << std::endl; } else { std::cerr << "Class specified with no name" << std::endl; exit(1); } } void ProcessList(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include) { if (Node.isAttributeSet("name")) { std::string LowerName=Node.getAttribute("name"); std::string UpperName=LowerName; if (Node.isAttributeSet("uppername")) UpperName=Node.getAttribute("uppername"); else UpperName[0]=toupper(UpperName[0]); Include << "/**" << std::endl; Include << " * Delete a #Mb5" << UpperName << "List" << std::endl; Include << " *" << std::endl; Include << " * @param List List to delete" << std::endl; Include << " */" << std::endl; Include << " void mb5_" << LowerName << "_list_delete(Mb5" << UpperName << "List List);" << std::endl; Include << std::endl; Include << "/**" << std::endl; Include << " * Return the number of entries in a #Mb5" << UpperName << "List" << std::endl; Include << " *" << std::endl; Include << " * @param List List to use" << std::endl; Include << " */" << std::endl; Include << " int mb5_" << LowerName << "_list_size(Mb5" << UpperName << "List List);" << std::endl; Include << std::endl; Include << "/**" << std::endl; Include << " * Returns an entry from a #Mb5" << UpperName << "List" << std::endl; Include << " *" << std::endl; Include << " * @param List List to use" << std::endl; Include << " * @param Item Item number to return" << std::endl; Include << " *" << std::endl; Include << " * @return A #Mb5" << UpperName << " object." << std::endl; Include << " */" << std::endl; Include << " Mb5" << UpperName << " mb5_" << LowerName << "_list_item(Mb5" << UpperName << "List List, int Item);" << std::endl; Include << std::endl; Include << "/**" << std::endl; Include << " * Return the count of entries in an #Mb5" << UpperName << "List" << std::endl; Include << " *" << std::endl; Include << " * @param List List to use" << std::endl; Include << " */" << std::endl; Include << " int mb5_" << LowerName << "_list_get_count(Mb5" << UpperName << "List List);" << std::endl; Include << std::endl; Include << "/**" << std::endl; Include << " * Return the offset of entries in an #Mb5" << UpperName << "List" << std::endl; Include << " *" << std::endl; Include << " * @param List List to use" << std::endl; Include << " */" << std::endl; Include << " int mb5_" << LowerName << "_list_get_offset(Mb5" << UpperName << "List List);" << std::endl; Include << std::endl; Source << " MB5_C_LIST_GETTER(" << UpperName << "," << LowerName << ")" << std::endl; Include << "/**" << std::endl; Include << "* Clone an #Mb5" << UpperName << "List object" << std::endl; Include << "*" << std::endl; Include << "* @param " << UpperName << "List Object to clone" << std::endl; Include << "*" << std::endl; Include << "* @return Cloned list. This list must be deleted once" << std::endl; Include << "* finished with." << std::endl; Include << "*/" << std::endl; Include << " Mb5" << UpperName << "List mb5_" << LowerName << "_list_clone(Mb5" << UpperName << "List " << UpperName << "List" << ");" << std::endl; Include << std::endl; Source << " MB5_C_CLONE(" << UpperName << "List," << LowerName << "_list)" << std::endl; for (int count=0;count Classes; Classes.push_back("Entity"); for (int count=0;count::const_iterator Class=Classes.begin();Class!=Classes.end();Class++) { Include << " typedef void *Mb5" << *Class << ";" << std::endl; } Include << std::endl; } libmusicbrainz-5.0.1/src/xmlParser.cpp000066400000000000000000003255111175500222200200050ustar00rootroot00000000000000/** **************************************************************************** *

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 V2.43 * @author Frank Vanden Berghen * * 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): * * * * * * * NOTE: * * If you add "#define _XMLPARSER_NO_MESSAGEBOX_" on the first line of this file * the "openFileHelper" function will always display error messages inside the * console instead of inside a message-box-window. Message-box-windows are * available on windows 9x/NT/2000/XP/Vista only. * * Copyright (c) 2002, Business-Insight * Business-Insight * All rights reserved. * See the file "AFPL-license.txt" about the licensing terms * **************************************************************************** */ #ifndef _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE #endif #include "musicbrainz5/xmlParser.h" #ifdef _XMLWINDOWS //#ifdef _DEBUG //#define _CRTDBG_MAP_ALLOC //#include //#endif #define WIN32_LEAN_AND_MEAN #include // to have IsTextUnicode, MultiByteToWideChar, WideCharToMultiByte to handle unicode files // to have "MessageBoxA" to display error messages for openFilHelper #endif #include #include #include #include #include XMLCSTR XMLNode::getVersion() { return _CXML("v2.43"); } void freeXMLString(XMLSTR t){if(t)free(t);} static XMLNode::XMLCharEncoding characterEncoding=XMLNode::char_encoding_UTF8; static char guessWideCharChars=1, dropWhiteSpace=1, removeCommentsInMiddleOfText=1; inline int mmin( const int t1, const int t2 ) { return t1 < t2 ? t1 : t2; } // You can modify the initialization of the variable "XMLClearTags" below // to change the clearTags that are currently recognized by the library. // The number on the second columns is the length of the string inside the // first column. // The "") }, { _CXML("") }, { _CXML("") }, { _CXML("
")    ,5,  _CXML("
") }, // { _CXML("")}, { NULL ,0, NULL } }; // You can modify the initialization of the variable "XMLEntities" below // to change the character entities that are currently recognized by the library. // The number on the second columns is the length of the string inside the // first column. Additionally, the syntaxes " " and " " are recognized. typedef struct { XMLCSTR s; int l; XMLCHAR c;} XMLCharacterEntity; static XMLCharacterEntity XMLEntities[] = { { _CXML("&" ), 5, _CXML('&' )}, { _CXML("<" ), 4, _CXML('<' )}, { _CXML(">" ), 4, _CXML('>' )}, { _CXML("""), 6, _CXML('\"')}, { _CXML("'"), 6, _CXML('\'')}, { NULL , 0, '\0' } }; // When rendering the XMLNode to a string (using the "createXMLString" function), // you can ask for a beautiful formatting. This formatting is using the // following indentation character: #define INDENTCHAR _CXML('\t') // The following function parses the XML errors into a user friendly string. // You can edit this to change the output language of the library to something else. XMLCSTR XMLNode::getError(XMLError xerror) { switch (xerror) { case eXMLErrorNone: return _CXML("No error"); case eXMLErrorMissingEndTag: return _CXML("Warning: Unmatched end tag"); case eXMLErrorNoXMLTagFound: return _CXML("Warning: No XML tag found"); case eXMLErrorEmpty: return _CXML("Error: No XML data"); case eXMLErrorMissingTagName: return _CXML("Error: Missing start tag name"); case eXMLErrorMissingEndTagName: return _CXML("Error: Missing end tag name"); case eXMLErrorUnmatchedEndTag: return _CXML("Error: Unmatched end tag"); case eXMLErrorUnmatchedEndClearTag: return _CXML("Error: Unmatched clear tag end"); case eXMLErrorUnexpectedToken: return _CXML("Error: Unexpected token found"); case eXMLErrorNoElements: return _CXML("Error: No elements found"); case eXMLErrorFileNotFound: return _CXML("Error: File not found"); case eXMLErrorFirstTagNotFound: return _CXML("Error: First Tag not found"); case eXMLErrorUnknownCharacterEntity:return _CXML("Error: Unknown character entity"); case eXMLErrorCharacterCodeAbove255: return _CXML("Error: Character code above 255 is forbidden in MultiByte char mode."); case eXMLErrorCharConversionError: return _CXML("Error: unable to convert between WideChar and MultiByte chars"); case eXMLErrorCannotOpenWriteFile: return _CXML("Error: unable to open file for writing"); case eXMLErrorCannotWriteFile: return _CXML("Error: cannot write into file"); case eXMLErrorBase64DataSizeIsNotMultipleOf4: return _CXML("Warning: Base64-string length is not a multiple of 4"); case eXMLErrorBase64DecodeTruncatedData: return _CXML("Warning: Base64-string is truncated"); case eXMLErrorBase64DecodeIllegalCharacter: return _CXML("Error: Base64-string contains an illegal character"); case eXMLErrorBase64DecodeBufferTooSmall: return _CXML("Error: Base64 decode output buffer is too small"); }; return _CXML("Unknown"); } ///////////////////////////////////////////////////////////////////////// // Here start the abstraction layer to be OS-independent // ///////////////////////////////////////////////////////////////////////// // Here is an abstraction layer to access some common string manipulation functions. // The abstraction layer is currently working for gcc, Microsoft Visual Studio 6.0, // Microsoft Visual Studio .NET, CC (sun compiler) and Borland C++. // If you plan to "port" the library to a new system/compiler, all you have to do is // to edit the following lines. #ifdef XML_NO_WIDE_CHAR char myIsTextWideChar(const void *b, int len) { return FALSE; } #else #if defined (UNDER_CE) || !defined(_XMLWINDOWS) char myIsTextWideChar(const void *b, int len) // inspired by the Wine API: RtlIsTextUnicode { #ifdef sun // for SPARC processors: wchar_t* buffers must always be alligned, otherwise it's a char* buffer. if ((((unsigned long)b)%sizeof(wchar_t))!=0) return FALSE; #endif const wchar_t *s=(const wchar_t*)b; // buffer too small: if (len<(int)sizeof(wchar_t)) return FALSE; // odd length test if (len&1) return FALSE; /* only checks the first 256 characters */ len=mmin(256,len/sizeof(wchar_t)); // Check for the special byte order: if (*((unsigned short*)s) == 0xFFFE) return TRUE; // IS_TEXT_UNICODE_REVERSE_SIGNATURE; if (*((unsigned short*)s) == 0xFEFF) return TRUE; // IS_TEXT_UNICODE_SIGNATURE // checks for ASCII characters in the UNICODE stream int i,stats=0; for (i=0; ilen/2) return TRUE; // Check for UNICODE NULL chars for (i=0; i static inline int xstrnicmp(XMLCSTR c1, XMLCSTR c2, int l) { return wsncasecmp(c1,c2,l);} static inline int xstrncmp(XMLCSTR c1, XMLCSTR c2, int l) { return wsncmp(c1,c2,l);} static inline int xstricmp(XMLCSTR c1, XMLCSTR c2) { return wscasecmp(c1,c2); } #else static inline int xstrncmp(XMLCSTR c1, XMLCSTR c2, int l) { return wcsncmp(c1,c2,l);} #ifdef __linux__ // for gcc/linux static inline int xstrnicmp(XMLCSTR c1, XMLCSTR c2, int l) { return wcsncasecmp(c1,c2,l);} static inline int xstricmp(XMLCSTR c1, XMLCSTR c2) { return wcscasecmp(c1,c2); } #else #include // for gcc/non-linux (MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 4.3.2, HP-UX 11, IRIX 6.5, OSF/1 5.1, Cygwin, mingw) static inline int xstricmp(XMLCSTR c1, XMLCSTR c2) { wchar_t left,right; do { left=towlower(*c1++); right=towlower(*c2++); } while (left&&(left==right)); return (int)left-(int)right; } static inline int xstrnicmp(XMLCSTR c1, XMLCSTR c2, int l) { wchar_t left,right; while(l--) { left=towlower(*c1++); right=towlower(*c2++); if ((!left)||(left!=right)) return (int)left-(int)right; } return 0; } #endif #endif static inline XMLSTR xstrstr(XMLCSTR c1, XMLCSTR c2) { return (XMLSTR)wcsstr(c1,c2); } static inline XMLSTR xstrcpy(XMLSTR c1, XMLCSTR c2) { return (XMLSTR)wcscpy(c1,c2); } static inline FILE *xfopen(XMLCSTR filename,XMLCSTR mode) { char *filenameAscii=myWideCharToMultiByte(filename); FILE *f; if (mode[0]==_CXML('r')) f=fopen(filenameAscii,"rb"); else f=fopen(filenameAscii,"wb"); free(filenameAscii); return f; } #else static inline FILE *xfopen(XMLCSTR filename,XMLCSTR mode) { return fopen(filename,mode); } static inline int xstrlen(XMLCSTR c) { return strlen(c); } static inline int xstrnicmp(XMLCSTR c1, XMLCSTR c2, int l) { return strncasecmp(c1,c2,l);} static inline int xstrncmp(XMLCSTR c1, XMLCSTR c2, int l) { return strncmp(c1,c2,l);} static inline int xstricmp(XMLCSTR c1, XMLCSTR c2) { return strcasecmp(c1,c2); } static inline XMLSTR xstrstr(XMLCSTR c1, XMLCSTR c2) { return (XMLSTR)strstr(c1,c2); } static inline XMLSTR xstrcpy(XMLSTR c1, XMLCSTR c2) { return (XMLSTR)strcpy(c1,c2); } #endif static inline int _strnicmp(const char *c1,const char *c2, int l) { return strncasecmp(c1,c2,l);} #endif /////////////////////////////////////////////////////////////////////////////// // the "xmltoc,xmltob,xmltoi,xmltol,xmltof,xmltoa" functions // /////////////////////////////////////////////////////////////////////////////// // These 6 functions are not used inside the XMLparser. // There are only here as "convenience" functions for the user. // If you don't need them, you can delete them without any trouble. #ifdef _XMLWIDECHAR #ifdef _XMLWINDOWS // for Microsoft Visual Studio 6.0 and Microsoft Visual Studio .NET and Borland C++ Builder 6.0 char xmltob(XMLCSTR t,char v){ if (t&&(*t)) return (char)_wtoi(t); return v; } int xmltoi(XMLCSTR t,int v){ if (t&&(*t)) return _wtoi(t); return v; } long xmltol(XMLCSTR t,long v){ if (t&&(*t)) return _wtol(t); return v; } double xmltof(XMLCSTR t,double v){ if (t&&(*t)) swscanf(t, L"%lf", &v); /*v=_wtof(t);*/ return v; } #else #ifdef sun // for CC #include char xmltob(XMLCSTR t,char v){ if (t) return (char)wstol(t,NULL,10); return v; } int xmltoi(XMLCSTR t,int v){ if (t) return (int)wstol(t,NULL,10); return v; } long xmltol(XMLCSTR t,long v){ if (t) return wstol(t,NULL,10); return v; } #else // for gcc char xmltob(XMLCSTR t,char v){ if (t) return (char)wcstol(t,NULL,10); return v; } int xmltoi(XMLCSTR t,int v){ if (t) return (int)wcstol(t,NULL,10); return v; } long xmltol(XMLCSTR t,long v){ if (t) return wcstol(t,NULL,10); return v; } #endif double xmltof(XMLCSTR t,double v){ if (t&&(*t)) swscanf(t, L"%lf", &v); /*v=_wtof(t);*/ return v; } #endif #else char xmltob(XMLCSTR t,char v){ if (t&&(*t)) return (char)atoi(t); return v; } int xmltoi(XMLCSTR t,int v){ if (t&&(*t)) return atoi(t); return v; } long xmltol(XMLCSTR t,long v){ if (t&&(*t)) return atol(t); return v; } double xmltof(XMLCSTR t,double v){ if (t&&(*t)) return atof(t); return v; } #endif XMLCSTR xmltoa(XMLCSTR t, XMLCSTR v){ if (t) return t; return v; } XMLCHAR xmltoc(XMLCSTR t,const XMLCHAR v){ if (t&&(*t)) return *t; return v; } ///////////////////////////////////////////////////////////////////////// // the "openFileHelper" function // ///////////////////////////////////////////////////////////////////////// // Since each application has its own way to report and deal with errors, you should modify & rewrite // the following "openFileHelper" function to get an "error reporting mechanism" tailored to your needs. XMLNode XMLNode::openFileHelper(XMLCSTR filename, XMLCSTR tag) { // guess the value of the global parameter "characterEncoding" // (the guess is based on the first 200 bytes of the file). FILE *f=xfopen(filename,_CXML("rb")); if (f) { char bb[205]; int l=(int)fread(bb,1,200,f); setGlobalOptions(guessCharEncoding(bb,l),guessWideCharChars,dropWhiteSpace,removeCommentsInMiddleOfText); fclose(f); } // parse the file XMLResults pResults; XMLNode xnode=XMLNode::parseFile(filename,tag,&pResults); // display error message (if any) if (pResults.error != eXMLErrorNone) { // create message char message[2000],*s1=(char*)"",*s3=(char*)""; XMLCSTR s2=_CXML(""); if (pResults.error==eXMLErrorFirstTagNotFound) { s1=(char*)"First Tag should be '"; s2=tag; s3=(char*)"'.\n"; } sprintf(message, #ifdef _XMLWIDECHAR "XML Parsing error inside file '%S'.\n%S\nAt line %i, column %i.\n%s%S%s" #else "XML Parsing error inside file '%s'.\n%s\nAt line %i, column %i.\n%s%s%s" #endif ,filename,XMLNode::getError(pResults.error),pResults.nLine,pResults.nColumn,s1,s2,s3); // display message #if defined(_XMLWINDOWS) && !defined(UNDER_CE) && !defined(_XMLPARSER_NO_MESSAGEBOX_) MessageBoxA(NULL,message,"XML Parsing error",MB_OK|MB_ICONERROR|MB_TOPMOST); #else printf("%s",message); #endif } return xnode; } ///////////////////////////////////////////////////////////////////////// // Here start the core implementation of the XMLParser library // ///////////////////////////////////////////////////////////////////////// // You should normally not change anything below this point. #ifndef _XMLWIDECHAR // If "characterEncoding=ascii" then we assume that all characters have the same length of 1 byte. // If "characterEncoding=UTF8" then the characters have different lengths (from 1 byte to 4 bytes). // If "characterEncoding=ShiftJIS" then the characters have different lengths (from 1 byte to 2 bytes). // This table is used as lookup-table to know the length of a character (in byte) based on the // content of the first byte of the character. // (note: if you modify this, you must always have XML_utf8ByteTable[0]=0 ). static const char XML_utf8ByteTable[256] = { // 0 1 2 3 4 5 6 7 8 9 a b c d e f 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x00 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x10 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x20 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x30 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x40 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x50 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x60 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x70 End of ASCII range 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x80 0x80 to 0xc1 invalid 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x90 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0xa0 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0xb0 1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0xc0 0xc2 to 0xdf 2 byte 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0xd0 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,// 0xe0 0xe0 to 0xef 3 byte 4,4,4,4,4,1,1,1,1,1,1,1,1,1,1,1 // 0xf0 0xf0 to 0xf4 4 byte, 0xf5 and higher invalid }; static const char XML_legacyByteTable[256] = { 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 }; static const char XML_sjisByteTable[256] = { // 0 1 2 3 4 5 6 7 8 9 a b c d e f 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x00 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x10 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x20 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x30 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x40 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x50 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x60 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x70 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0x80 0x81 to 0x9F 2 bytes 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0x90 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0xa0 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0xb0 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0xc0 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0xd0 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0xe0 0xe0 to 0xef 2 bytes 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 // 0xf0 }; static const char XML_gb2312ByteTable[256] = { // 0 1 2 3 4 5 6 7 8 9 a b c d e f 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x00 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x10 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x20 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x30 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x40 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x50 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x60 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x70 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x80 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x90 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0xa0 0xa1 to 0xf7 2 bytes 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0xb0 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0xc0 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0xd0 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0xe0 2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1 // 0xf0 }; static const char XML_gbk_big5_ByteTable[256] = { // 0 1 2 3 4 5 6 7 8 9 a b c d e f 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x00 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x10 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x20 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x30 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x40 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x50 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x60 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,// 0x70 1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0x80 0x81 to 0xfe 2 bytes 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0x90 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0xa0 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0xb0 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0xc0 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0xd0 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,// 0xe0 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1 // 0xf0 }; static const char *XML_ByteTable=(const char *)XML_utf8ByteTable; // the default is "characterEncoding=XMLNode::encoding_UTF8" #endif XMLNode XMLNode::emptyXMLNode; XMLClear XMLNode::emptyXMLClear={ NULL, NULL, NULL}; XMLAttribute XMLNode::emptyXMLAttribute={ NULL, NULL}; // Enumeration used to decipher what type a token is typedef enum XMLTokenTypeTag { eTokenText = 0, eTokenQuotedText, eTokenTagStart, /* "<" */ eTokenTagEnd, /* "" */ eTokenEquals, /* "=" */ eTokenDeclaration, /* "" */ eTokenClear, eTokenError } XMLTokenType; // Main structure used for parsing XML typedef struct XML { XMLCSTR lpXML; XMLCSTR lpszText; int nIndex,nIndexMissigEndTag; enum XMLError error; XMLCSTR lpEndTag; int cbEndTag; XMLCSTR lpNewElement; int cbNewElement; int nFirst; } XML; typedef struct { ALLXMLClearTag *pClr; XMLCSTR 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 XMLStatus { eInsideTag = 0, eOutsideTag } XMLStatus; XMLError XMLNode::writeToFile(XMLCSTR filename, const char *encoding, char nFormat) const { if (!d) return eXMLErrorNone; FILE *f=xfopen(filename,_CXML("wb")); if (!f) return eXMLErrorCannotOpenWriteFile; #ifdef _XMLWIDECHAR unsigned char h[2]={ 0xFF, 0xFE }; if (!fwrite(h,2,1,f)) { fclose(f); return eXMLErrorCannotWriteFile; } if ((!isDeclaration())&&((d->lpszName)||(!getChildNode().isDeclaration()))) { if (!fwrite(L"\n",sizeof(wchar_t)*40,1,f)) { fclose(f); return eXMLErrorCannotWriteFile; } } #else if ((!isDeclaration())&&((d->lpszName)||(!getChildNode().isDeclaration()))) { if (characterEncoding==char_encoding_UTF8) { // header so that windows recognize the file as UTF-8: unsigned char h[3]={0xEF,0xBB,0xBF}; if (!fwrite(h,3,1,f)) { fclose(f); return eXMLErrorCannotWriteFile; } encoding="utf-8"; } else if (characterEncoding==char_encoding_ShiftJIS) encoding="SHIFT-JIS"; if (!encoding) encoding="ISO-8859-1"; if (fprintf(f,"\n",encoding)<0) { fclose(f); return eXMLErrorCannotWriteFile; } } else { if (characterEncoding==char_encoding_UTF8) { unsigned char h[3]={0xEF,0xBB,0xBF}; if (!fwrite(h,3,1,f)) { fclose(f); return eXMLErrorCannotWriteFile; } } } #endif int i; XMLSTR t=createXMLString(nFormat,&i); if (!fwrite(t,sizeof(XMLCHAR)*i,1,f)) { free(t); fclose(f); return eXMLErrorCannotWriteFile; } if (fclose(f)!=0) { free(t); return eXMLErrorCannotWriteFile; } free(t); return eXMLErrorNone; } // Duplicate a given string. XMLSTR stringDup(XMLCSTR lpszData, int cbData) { if (lpszData==NULL) return NULL; XMLSTR lpszNew; if (cbData==-1) cbData=(int)xstrlen(lpszData); lpszNew = (XMLSTR)malloc((cbData+1) * sizeof(XMLCHAR)); if (lpszNew) { memcpy(lpszNew, lpszData, (cbData) * sizeof(XMLCHAR)); lpszNew[cbData] = (XMLCHAR)NULL; } return lpszNew; } XMLSTR ToXMLStringTool::toXMLUnSafe(XMLSTR dest,XMLCSTR source) { XMLSTR dd=dest; XMLCHAR ch; XMLCharacterEntity *entity; while ((ch=*source)) { entity=XMLEntities; do { if (ch==entity->c) {xstrcpy(dest,entity->s); dest+=entity->l; source++; goto out_of_loop1; } entity++; } while(entity->s); #ifdef _XMLWIDECHAR *(dest++)=*(source++); #else switch(XML_ByteTable[(unsigned char)ch]) { case 4: *(dest++)=*(source++); case 3: *(dest++)=*(source++); case 2: *(dest++)=*(source++); case 1: *(dest++)=*(source++); } #endif out_of_loop1: ; } *dest=0; return dd; } // private (used while rendering): int ToXMLStringTool::lengthXMLString(XMLCSTR source) { int r=0; XMLCharacterEntity *entity; XMLCHAR ch; while ((ch=*source)) { entity=XMLEntities; do { if (ch==entity->c) { r+=entity->l; source++; goto out_of_loop1; } entity++; } while(entity->s); #ifdef _XMLWIDECHAR r++; source++; #else ch=XML_ByteTable[(unsigned char)ch]; r+=ch; source+=ch; #endif out_of_loop1: ; } return r; } ToXMLStringTool::~ToXMLStringTool(){ freeBuffer(); } void ToXMLStringTool::freeBuffer(){ if (buf) free(buf); buf=NULL; buflen=0; } XMLSTR ToXMLStringTool::toXML(XMLCSTR source) { if (!source) { if (buflen<1) { buflen=1; buf=(XMLSTR)malloc(sizeof(XMLCHAR)); } *buf=0; return buf; } int l=lengthXMLString(source)+1; if (l>buflen) { freeBuffer(); buflen=l; buf=(XMLSTR)malloc(l*sizeof(XMLCHAR)); } return toXMLUnSafe(buf,source); } // private: XMLSTR fromXMLString(XMLCSTR s, int lo, XML *pXML) { // 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,j; XMLSTR d; XMLCSTR ss=s; XMLCharacterEntity *entity; while ((lo>0)&&(*s)) { if (*s==_CXML('&')) { if ((lo>2)&&(s[1]==_CXML('#'))) { s+=2; lo-=2; if ((*s==_CXML('X'))||(*s==_CXML('x'))) { s++; lo--; } while ((*s)&&(*s!=_CXML(';'))&&((lo--)>0)) s++; if (*s!=_CXML(';')) { pXML->error=eXMLErrorUnknownCharacterEntity; return NULL; } s++; lo--; } else { entity=XMLEntities; do { if ((lo>=entity->l)&&(xstrnicmp(s,entity->s,entity->l)==0)) { s+=entity->l; lo-=entity->l; break; } entity++; } while(entity->s); if (!entity->s) { pXML->error=eXMLErrorUnknownCharacterEntity; return NULL; } } } else { #ifdef _XMLWIDECHAR s++; lo--; #else j=XML_ByteTable[(unsigned char)*s]; s+=j; lo-=j; ll+=j-1; #endif } ll++; } d=(XMLSTR)malloc((ll+1)*sizeof(XMLCHAR)); s=d; while (ll-->0) { if (*ss==_CXML('&')) { if (ss[1]==_CXML('#')) { ss+=2; j=0; if ((*ss==_CXML('X'))||(*ss==_CXML('x'))) { ss++; while (*ss!=_CXML(';')) { if ((*ss>=_CXML('0'))&&(*ss<=_CXML('9'))) j=(j<<4)+*ss-_CXML('0'); else if ((*ss>=_CXML('A'))&&(*ss<=_CXML('F'))) j=(j<<4)+*ss-_CXML('A')+10; else if ((*ss>=_CXML('a'))&&(*ss<=_CXML('f'))) j=(j<<4)+*ss-_CXML('a')+10; else { free((void*)s); pXML->error=eXMLErrorUnknownCharacterEntity;return NULL;} ss++; } } else { while (*ss!=_CXML(';')) { if ((*ss>=_CXML('0'))&&(*ss<=_CXML('9'))) j=(j*10)+*ss-_CXML('0'); else { free((void*)s); pXML->error=eXMLErrorUnknownCharacterEntity;return NULL;} ss++; } } #ifndef _XMLWIDECHAR if (j>255) { free((void*)s); pXML->error=eXMLErrorCharacterCodeAbove255;return NULL;} #endif (*d++)=(XMLCHAR)j; ss++; } else { entity=XMLEntities; do { if (xstrnicmp(ss,entity->s,entity->l)==0) { *(d++)=entity->c; ss+=entity->l; break; } entity++; } while(entity->s); } } else { #ifdef _XMLWIDECHAR *(d++)=*(ss++); #else switch(XML_ByteTable[(unsigned char)*ss]) { case 4: *(d++)=*(ss++); ll--; case 3: *(d++)=*(ss++); ll--; case 2: *(d++)=*(ss++); ll--; case 1: *(d++)=*(ss++); } #endif } } *d=0; return (XMLSTR)s; } #define XML_isSPACECHAR(ch) ((ch==_CXML('\n'))||(ch==_CXML(' '))||(ch== _CXML('\t'))||(ch==_CXML('\r'))) // private: char myTagCompare(XMLCSTR cclose, XMLCSTR copen) // !!!! WARNING strange convention&: // return 0 if equals // return 1 if different { if (!cclose) return 1; int l=(int)xstrlen(cclose); if (xstrnicmp(cclose, copen, l)!=0) return 1; const XMLCHAR c=copen[l]; if (XML_isSPACECHAR(c)|| (c==_CXML('/' ))|| (c==_CXML('<' ))|| (c==_CXML('>' ))|| (c==_CXML('=' ))) return 0; return 1; } // Obtain the next character from the string. static inline XMLCHAR getNextChar(XML *pXML) { XMLCHAR ch = pXML->lpXML[pXML->nIndex]; #ifdef _XMLWIDECHAR if (ch!=0) pXML->nIndex++; #else pXML->nIndex+=XML_ByteTable[(unsigned char)ch]; #endif 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 XMLTokenTypeTag *pType) { NextToken result; XMLCHAR ch; XMLCHAR chTemp; int indexStart,nFoundMatch,nIsText=FALSE; result.pClr=NULL; // prevent warning // Find next non-white space character do { indexStart=pXML->nIndex; ch=getNextChar(pXML); } while XML_isSPACECHAR(ch); if (ch) { // Cache the current string pointer result.pStr = &pXML->lpXML[indexStart]; // check for standard tokens switch(ch) { // Check for quotes case _CXML('\''): case _CXML('\"'): // Type of token *pType = eTokenQuotedText; chTemp = ch; // Set the size nFoundMatch = FALSE; // Search through the string to find a matching quote while((ch = getNextChar(pXML))) { if (ch==chTemp) { nFoundMatch = TRUE; break; } if (ch==_CXML('<')) break; } // If we failed to find a matching quote if (nFoundMatch == FALSE) { pXML->nIndex=indexStart+1; nIsText=TRUE; break; } // 4.02.2002 // if (FindNonWhiteSpace(pXML)) pXML->nIndex--; break; // Equals (used with attribute values) case _CXML('='): *pType = eTokenEquals; break; // Close tag case _CXML('>'): *pType = eTokenCloseTag; break; // Check for tag start and tag end case _CXML('<'): { // First check whether the token is in the clear tag list (meaning it // does not need formatting). ALLXMLClearTag *ctag=XMLClearTags; do { if (!xstrncmp(ctag->lpszOpen, result.pStr, ctag->openTagLen)) { result.pClr=ctag; pXML->nIndex+=ctag->openTagLen-1; *pType=eTokenClear; return result; } ctag++; } while(ctag->lpszOpen); // Peek at the next character to see if we have an end tag 'lpXML[pXML->nIndex]; // If we have a tag end... if (chTemp == _CXML('/')) { // Set the type and ensure we point at the next character getNextChar(pXML); *pType = eTokenTagEnd; } // If we have an XML declaration tag else if (chTemp == _CXML('?')) { // Set the type and ensure we point at the next character getNextChar(pXML); *pType = eTokenDeclaration; } // Otherwise we must have a start tag else { *pType = eTokenTagStart; } break; } // Check to see if we have a short hand type end tag ('/>'). case _CXML('/'): // 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 == _CXML('>')) { // Set the type and ensure we point at the next character getNextChar(pXML); *pType = eTokenShortHandClose; 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; while((ch = getNextChar(pXML))) { if XML_isSPACECHAR(ch) { indexStart++; break; } else if (ch==_CXML('/')) { // If we find a slash then this maybe text or a short hand end tag // Peek at the next character to see it we have short hand end tag ch=pXML->lpXML[pXML->nIndex]; // If we found a short hand end tag then we need to exit the loop if (ch==_CXML('>')) { pXML->nIndex--; break; } } else if ((ch==_CXML('<'))||(ch==_CXML('>'))||(ch==_CXML('='))) { pXML->nIndex--; break; } } } *pcbToken = pXML->nIndex-indexStart; } else { // If we failed to obtain a valid character *pcbToken = 0; *pType = eTokenError; result.pStr=NULL; } return result; } XMLCSTR XMLNode::updateName_WOSD(XMLSTR lpszName) { if (!d) { free(lpszName); return NULL; } if (d->lpszName&&(lpszName!=d->lpszName)) free((void*)d->lpszName); d->lpszName=lpszName; return lpszName; } // private: XMLNode::XMLNode(struct XMLNodeDataTag *p){ d=p; (p->ref_count)++; } XMLNode::XMLNode(XMLNodeData *pParent, XMLSTR lpszName, char 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; updateName_WOSD(lpszName); } XMLNode XMLNode::createXMLTopNode_WOSD(XMLSTR lpszName, char isDeclaration) { return XMLNode(NULL,lpszName,isDeclaration); } XMLNode XMLNode::createXMLTopNode(XMLCSTR lpszName, char isDeclaration) { return XMLNode(NULL,stringDup(lpszName),isDeclaration); } #define MEMORYINCREASE 50 static inline void myFree(void *p) { if (p) free(p); } static inline 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; } // private: XMLElementPosition XMLNode::findPosition(XMLNodeData *d, int index, XMLElementType xxtype) { if (index<0) return -1; int i=0,j=(int)((index<<2)+xxtype),*o=d->pOrder; while (o[i]!=j) i++; return i; } // private: // update "order" information when deleting a content of a XMLNode int XMLNode::removeOrderElement(XMLNodeData *d, XMLElementType t, int index) { int n=d->nChild+d->nText+d->nClear, *o=d->pOrder,i=findPosition(d,index,t); memmove(o+i, o+i+1, (n-i)*sizeof(int)); for (;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. return i; } void *XMLNode::addToOrder(int memoryIncrease,int *_pos, int nc, void *p, int size, XMLElementType xtype) { // in: *_pos is the position inside d->pOrder ("-1" means "EndOf") // out: *_pos is the index inside p p=myRealloc(p,(nc+1),memoryIncrease,size); int n=d->nChild+d->nText+d->nClear; d->pOrder=(int*)myRealloc(d->pOrder,n+1,memoryIncrease*3,sizeof(int)); int pos=*_pos,*o=d->pOrder; if ((pos<0)||(pos>=n)) { *_pos=nc; o[n]=(int)((nc<<2)+xtype); return p; } int i=pos; memmove(o+i+1, o+i, (n-i)*sizeof(int)); while ((pos>2; memmove(((char*)p)+(pos+1)*size,((char*)p)+pos*size,(nc-pos)*size); return p; } // Add a child node to the given element. XMLNode XMLNode::addChild_priv(int memoryIncrease, XMLSTR lpszName, char isDeclaration, int pos) { if (!lpszName) return emptyXMLNode; d->pChild=(XMLNode*)addToOrder(memoryIncrease,&pos,d->nChild,d->pChild,sizeof(XMLNode),eNodeChild); d->pChild[pos].d=NULL; d->pChild[pos]=XMLNode(d,lpszName,isDeclaration); d->nChild++; return d->pChild[pos]; } // Add an attribute to an element. XMLAttribute *XMLNode::addAttribute_priv(int memoryIncrease,XMLSTR lpszName, XMLSTR lpszValuev) { if (!lpszName) return &emptyXMLAttribute; if (!d) { myFree(lpszName); myFree(lpszValuev); return &emptyXMLAttribute; } int nc=d->nAttribute; d->pAttribute=(XMLAttribute*)myRealloc(d->pAttribute,(nc+1),memoryIncrease,sizeof(XMLAttribute)); XMLAttribute *pAttr=d->pAttribute+nc; pAttr->lpszName = lpszName; pAttr->lpszValue = lpszValuev; d->nAttribute++; return pAttr; } // Add text to the element. XMLCSTR XMLNode::addText_priv(int memoryIncrease, XMLSTR lpszValue, int pos) { if (!lpszValue) return NULL; if (!d) { myFree(lpszValue); return NULL; } d->pText=(XMLCSTR*)addToOrder(memoryIncrease,&pos,d->nText,d->pText,sizeof(XMLSTR),eNodeText); d->pText[pos]=lpszValue; d->nText++; return lpszValue; } // Add clear (unformatted) text to the element. XMLClear *XMLNode::addClear_priv(int memoryIncrease, XMLSTR lpszValue, XMLCSTR lpszOpen, XMLCSTR lpszClose, int pos) { if (!lpszValue) return &emptyXMLClear; if (!d) { myFree(lpszValue); return &emptyXMLClear; } d->pClear=(XMLClear *)addToOrder(memoryIncrease,&pos,d->nClear,d->pClear,sizeof(XMLClear),eNodeClear); XMLClear *pNewClear=d->pClear+pos; pNewClear->lpszValue = lpszValue; if (!lpszOpen) lpszOpen=XMLClearTags->lpszOpen; if (!lpszClose) lpszClose=XMLClearTags->lpszClose; pNewClear->lpszOpenTag = lpszOpen; pNewClear->lpszCloseTag = lpszClose; d->nClear++; return pNewClear; } // private: // Parse a clear (unformatted) type node. char XMLNode::parseClearTag(void *px, void *_pClear) { XML *pXML=(XML *)px; ALLXMLClearTag pClear=*((ALLXMLClearTag*)_pClear); int cbTemp=0; XMLCSTR lpszTemp=NULL; XMLCSTR lpXML=&pXML->lpXML[pXML->nIndex]; static XMLCSTR docTypeEnd=_CXML("]>"); // Find the closing tag // Seems the ')) { lpszTemp=pCh; break; } #ifdef _XMLWIDECHAR pCh++; #else pCh+=XML_ByteTable[(unsigned char)(*pCh)]; #endif } } else lpszTemp=xstrstr(lpXML, pClear.lpszClose); if (lpszTemp) { // Cache the size and increment the index cbTemp = (int)(lpszTemp - lpXML); pXML->nIndex += cbTemp+(int)xstrlen(pClear.lpszClose); // Add the clear node to the current element addClear_priv(MEMORYINCREASE,cbTemp?stringDup(lpXML,cbTemp):NULL, pClear.lpszOpen, pClear.lpszClose,-1); return 0; } // If we failed to find the end tag pXML->error = eXMLErrorUnmatchedEndClearTag; return 1; } void XMLNode::exactMemory(XMLNodeData *d) { if (d->pOrder) d->pOrder=(int*)realloc(d->pOrder,(d->nChild+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=(XMLCSTR*)realloc(d->pText,d->nText*sizeof(XMLSTR)); if (d->pClear) d->pClear=(XMLClear *)realloc(d->pClear,d->nClear*sizeof(XMLClear)); } char XMLNode::maybeAddTxT(void *pa, XMLCSTR tokenPStr) { XML *pXML=(XML *)pa; XMLCSTR lpszText=pXML->lpszText; if (!lpszText) return 0; if (dropWhiteSpace) while (XML_isSPACECHAR(*lpszText)&&(lpszText!=tokenPStr)) lpszText++; int cbText = (int)(tokenPStr - lpszText); if (!cbText) { pXML->lpszText=NULL; return 0; } if (dropWhiteSpace) { cbText--; while ((cbText)&&XML_isSPACECHAR(lpszText[cbText])) cbText--; cbText++; } if (!cbText) { pXML->lpszText=NULL; return 0; } XMLSTR lpt=fromXMLString(lpszText,cbText,pXML); if (!lpt) return 1; pXML->lpszText=NULL; if (removeCommentsInMiddleOfText && d->nText && d->nClear) { // if the previous insertion was a comment () AND // if the previous previous insertion was a text then, delete the comment and append the text int n=d->nChild+d->nText+d->nClear-1,*o=d->pOrder; if (((o[n]&3)==eNodeClear)&&((o[n-1]&3)==eNodeText)) { int i=o[n]>>2; if (d->pClear[i].lpszOpenTag==XMLClearTags[2].lpszOpen) { deleteClear(i); i=o[n-1]>>2; n=xstrlen(d->pText[i]); int n2=xstrlen(lpt)+1; d->pText[i]=(XMLSTR)realloc((void*)d->pText[i],(n+n2)*sizeof(XMLCHAR)); if (!d->pText[i]) return 1; memcpy((void*)(d->pText[i]+n),lpt,n2*sizeof(XMLCHAR)); free(lpt); return 0; } } } addText_priv(MEMORYINCREASE,lpt,-1); return 0; } // private: // Recursively parse an XML element. int XMLNode::ParseXMLElement(void *pa) { XML *pXML=(XML *)pa; int cbToken; enum XMLTokenTypeTag xtype; NextToken token; XMLCSTR lpszTemp=NULL; int cbTemp=0; char nDeclaration; XMLNode pNew; enum XMLStatus 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 for(;;) { // Obtain the next token token = GetNextToken(pXML, &cbToken, &xtype); if (xtype != 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(xtype) { // If we have found text or quoted text case eTokenText: case eTokenCloseTag: /* '>' */ case eTokenShortHandClose: /* '/>' */ case eTokenQuotedText: case eTokenEquals: 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_priv(MEMORYINCREASE,stringDup(token.pStr,cbToken), nDeclaration,-1); 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_priv(MEMORYINCREASE,stringDup(pXML->lpNewElement,pXML->cbNewElement),0,-1); 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 (maybeAddTxT(pXML,token.pStr)) return FALSE; // Find the name of the end tag token = GetNextToken(pXML, &cbTemp, &xtype); // The end tag should be text if (xtype != eTokenText) { pXML->error = eXMLErrorMissingEndTagName; return FALSE; } lpszTemp = token.pStr; // After the end tag we should find a closing tag token = GetNextToken(pXML, &cbToken, &xtype); if (xtype != eTokenCloseTag) { pXML->error = eXMLErrorMissingEndTagName; return FALSE; } pXML->lpszText=pXML->lpXML+pXML->nIndex; // 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; pXML->nIndexMissigEndTag=pXML->nIndex; return FALSE; } #else { pXML->error=eXMLErrorMissingEndTag; pXML->nIndexMissigEndTag=pXML->nIndex; 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 (maybeAddTxT(pXML,token.pStr)) return FALSE; if (parseClearTag(pXML, token.pClr)) return FALSE; pXML->lpszText=pXML->lpXML+pXML->nIndex; break; 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(xtype) { // 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; pXML->lpszText=pXML->lpXML+pXML->nIndex; break; // If we found a short hand '/>' closing tag then we can // return to the caller case eTokenShortHandClose: exactMemory(d); pXML->lpszText=pXML->lpXML+pXML->nIndex; 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(xtype) { // If the current type is text... // Eg. 'Attribute AnotherAttribute' case eTokenText: // Add the unvalued attribute to the list addAttribute_priv(MEMORYINCREASE,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 'lpszText=pXML->lpXML+pXML->nIndex; if (d->isDeclaration && (lpszTemp[cbTemp-1]) == _CXML('?')) { cbTemp--; if (d->pParent && d->pParent->pParent) xtype = eTokenShortHandClose; } if (cbTemp) { // Add the unvalued attribute to the list addAttribute_priv(MEMORYINCREASE,stringDup(lpszTemp,cbTemp), NULL); } // If this is the end of the tag then return to the caller if (xtype == 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(xtype) { // 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]) == _CXML('?')) { cbToken--; } if (cbTemp) { // Add the valued attribute to the list if (xtype==eTokenQuotedText) { token.pStr++; cbToken-=2; } XMLSTR attrVal=(XMLSTR)token.pStr; if (attrVal) { attrVal=fromXMLString(attrVal,cbToken,pXML); if (!attrVal) return FALSE; } addAttribute_priv(MEMORYINCREASE,stringDup(lpszTemp,cbTemp),attrVal); } // 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 { if ((!d->isDeclaration)&&(d->pParent)) { #ifdef STRICT_PARSING pXML->error=eXMLErrorUnmatchedEndTag; #else pXML->error=eXMLErrorMissingEndTag; #endif pXML->nIndexMissigEndTag=pXML->nIndex; } maybeAddTxT(pXML,pXML->lpXML+pXML->nIndex); return FALSE; } } } // Count the number of lines and columns in an XML string. static void CountLinesAndColumns(XMLCSTR lpXML, int nUpto, XMLResults *pResults) { XMLCHAR ch; assert(lpXML); assert(pResults); struct XML xml={ lpXML,lpXML, 0, 0, eXMLErrorNone, NULL, 0, NULL, 0, TRUE }; pResults->nLine = 1; pResults->nColumn = 1; while (xml.nIndexnColumn++; else { pResults->nLine++; pResults->nColumn=1; } } } // Parse XML and return the root element. XMLNode XMLNode::parseString(XMLCSTR lpszXML, XMLCSTR tag, XMLResults *pResults) { if (!lpszXML) { if (pResults) { pResults->error=eXMLErrorNoElements; pResults->nLine=0; pResults->nColumn=0; } return emptyXMLNode; } XMLNode xnode(NULL,NULL,FALSE); struct XML xml={ lpszXML, lpszXML, 0, 0, eXMLErrorNone, NULL, 0, NULL, 0, TRUE }; // Create header element xnode.ParseXMLElement(&xml); enum XMLError error = xml.error; if (!xnode.nChildNode()) error=eXMLErrorNoXMLTagFound; if ((xnode.nChildNode()==1)&&(xnode.nElement()==1)) xnode=xnode.getChildNode(); // skip the empty node // If no error occurred if ((error==eXMLErrorNone)||(error==eXMLErrorMissingEndTag)||(error==eXMLErrorNoXMLTagFound)) { XMLCSTR name=xnode.getName(); if (tag&&(*tag)&&((!name)||(xstricmp(name,tag)))) { xnode=xnode.getChildNode(tag); if (xnode.isEmpty()) { if (pResults) { pResults->error=eXMLErrorFirstTagNotFound; pResults->nLine=0; pResults->nColumn=0; } return emptyXMLNode; } } } 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) { if (error==eXMLErrorMissingEndTag) xml.nIndex=xml.nIndexMissigEndTag; // Find which line and column it starts on. CountLinesAndColumns(xml.lpXML, xml.nIndex, pResults); } } return xnode; } XMLNode XMLNode::parseFile(XMLCSTR filename, XMLCSTR tag, XMLResults *pResults) { if (pResults) { pResults->nLine=0; pResults->nColumn=0; } FILE *f=xfopen(filename,_CXML("rb")); if (f==NULL) { if (pResults) pResults->error=eXMLErrorFileNotFound; return emptyXMLNode; } fseek(f,0,SEEK_END); int l=(int)ftell(f),headerSz=0; if (!l) { if (pResults) pResults->error=eXMLErrorEmpty; fclose(f); return emptyXMLNode; } fseek(f,0,SEEK_SET); unsigned char *buf=(unsigned char*)malloc(l+4); l=(int)fread(buf,1,l,f); fclose(f); buf[l]=0;buf[l+1]=0;buf[l+2]=0;buf[l+3]=0; #ifdef _XMLWIDECHAR if (guessWideCharChars) { if (!myIsTextWideChar(buf,l)) { XMLNode::XMLCharEncoding ce=XMLNode::char_encoding_legacy; if ((buf[0]==0xef)&&(buf[1]==0xbb)&&(buf[2]==0xbf)) { headerSz=3; ce=XMLNode::char_encoding_UTF8; } XMLSTR b2=myMultiByteToWideChar((const char*)(buf+headerSz),ce); if (!b2) { // todo: unable to convert } free(buf); buf=(unsigned char*)b2; headerSz=0; } else { if ((buf[0]==0xef)&&(buf[1]==0xff)) headerSz=2; if ((buf[0]==0xff)&&(buf[1]==0xfe)) headerSz=2; } } else { if ((buf[0]==0xef)&&(buf[1]==0xff)) headerSz=2; if ((buf[0]==0xff)&&(buf[1]==0xfe)) headerSz=2; if ((buf[0]==0xef)&&(buf[1]==0xbb)&&(buf[2]==0xbf)) headerSz=3; } #else if (guessWideCharChars) { if (myIsTextWideChar(buf,l)) { if ((buf[0]==0xef)&&(buf[1]==0xff)) headerSz=2; if ((buf[0]==0xff)&&(buf[1]==0xfe)) headerSz=2; char *b2=myWideCharToMultiByte((const wchar_t*)(buf+headerSz)); free(buf); buf=(unsigned char*)b2; headerSz=0; } else { if ((buf[0]==0xef)&&(buf[1]==0xbb)&&(buf[2]==0xbf)) headerSz=3; } } else { if ((buf[0]==0xef)&&(buf[1]==0xff)) headerSz=2; if ((buf[0]==0xff)&&(buf[1]==0xfe)) headerSz=2; if ((buf[0]==0xef)&&(buf[1]==0xbb)&&(buf[2]==0xbf)) headerSz=3; } #endif if (!buf) { if (pResults) pResults->error=eXMLErrorCharConversionError; return emptyXMLNode; } XMLNode x=parseString((XMLSTR)(buf+headerSz),tag,pResults); free(buf); return x; } static inline void charmemset(XMLSTR dest,XMLCHAR 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, XMLSTR lpszMarker, int nFormat) { int nResult = 0; int cb=nFormat<0?0:nFormat; int cbElement; int nChildFormat=-1; int nElementI=pEntry->nChild+pEntry->nText+pEntry->nClear; int i,j; if ((nFormat>=0)&&(nElementI==1)&&(pEntry->nText==1)&&(!pEntry->isDeclaration)) nFormat=-2; assert(pEntry); #define LENSTR(lpsz) (lpsz ? xstrlen(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++]=_CXML('?'); xstrcpy(&lpszMarker[nResult], pEntry->lpszName); nResult+=cbElement; lpszMarker[nResult++]=_CXML(' '); } else { nResult+=cbElement+2+cb; if (pEntry->isDeclaration) nResult++; } // Enumerate attributes and add them to the string XMLAttribute *pAttr=pEntry->pAttribute; for (i=0; inAttribute; i++) { // "Attrib cb = (int)LENSTR(pAttr->lpszName); if (cb) { if (lpszMarker) xstrcpy(&lpszMarker[nResult], pAttr->lpszName); nResult += cb; // "Attrib=Value " if (pAttr->lpszValue) { cb=(int)ToXMLStringTool::lengthXMLString(pAttr->lpszValue); if (lpszMarker) { lpszMarker[nResult]=_CXML('='); lpszMarker[nResult+1]=_CXML('"'); if (cb) ToXMLStringTool::toXMLUnSafe(&lpszMarker[nResult+2],pAttr->lpszValue); lpszMarker[nResult+cb+2]=_CXML('"'); } nResult+=cb+3; } if (lpszMarker) lpszMarker[nResult] = _CXML(' '); nResult++; } pAttr++; } if (pEntry->isDeclaration) { if (lpszMarker) { lpszMarker[nResult-1]=_CXML('?'); lpszMarker[nResult]=_CXML('>'); } nResult++; if (nFormat!=-1) { if (lpszMarker) lpszMarker[nResult]=_CXML('\n'); nResult++; } } else // If there are child nodes we need to terminate the start tag if (nElementI) { if (lpszMarker) lpszMarker[nResult-1]=_CXML('>'); if (nFormat>=0) { if (lpszMarker) lpszMarker[nResult]=_CXML('\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 for (i=0; ipOrder[i]; switch((XMLElementType)(j&3)) { // Text nodes case eNodeText: { // "Text" XMLCSTR pChild=pEntry->pText[j>>2]; cb = (int)ToXMLStringTool::lengthXMLString(pChild); if (cb) { if (nFormat>=0) { if (lpszMarker) { charmemset(&lpszMarker[nResult],INDENTCHAR,nFormat+1); ToXMLStringTool::toXMLUnSafe(&lpszMarker[nResult+nFormat+1],pChild); lpszMarker[nResult+nFormat+1+cb]=_CXML('\n'); } nResult+=cb+nFormat+2; } else { if (lpszMarker) ToXMLStringTool::toXMLUnSafe(&lpszMarker[nResult], pChild); nResult += cb; } } break; } // Clear type nodes case eNodeClear: { XMLClear *pChild=pEntry->pClear+(j>>2); // "OpenTag" cb = (int)LENSTR(pChild->lpszOpenTag); if (cb) { if (nFormat!=-1) { if (lpszMarker) { charmemset(&lpszMarker[nResult], INDENTCHAR, nFormat+1); xstrcpy(&lpszMarker[nResult+nFormat+1], pChild->lpszOpenTag); } nResult+=cb+nFormat+1; } else { if (lpszMarker)xstrcpy(&lpszMarker[nResult], pChild->lpszOpenTag); nResult += cb; } } // "OpenTag Value" cb = (int)LENSTR(pChild->lpszValue); if (cb) { if (lpszMarker) xstrcpy(&lpszMarker[nResult], pChild->lpszValue); nResult += cb; } // "OpenTag Value CloseTag" cb = (int)LENSTR(pChild->lpszCloseTag); if (cb) { if (lpszMarker) xstrcpy(&lpszMarker[nResult], pChild->lpszCloseTag); nResult += cb; } if (nFormat!=-1) { if (lpszMarker) lpszMarker[nResult] = _CXML('\n'); nResult++; } break; } // Element nodes case eNodeChild: { // Recursively add child nodes nResult += CreateXMLStringR(pEntry->pChild[j>>2].d, 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 (nElementI) { // "\0" if (lpszMarker) { if (nFormat >=0) { charmemset(&lpszMarker[nResult], INDENTCHAR,nFormat); nResult+=nFormat; } lpszMarker[nResult]=_CXML('<'); lpszMarker[nResult+1]=_CXML('/'); nResult += 2; xstrcpy(&lpszMarker[nResult], pEntry->lpszName); nResult += cbElement; lpszMarker[nResult]=_CXML('>'); if (nFormat == -1) nResult++; else { lpszMarker[nResult+1]=_CXML('\n'); nResult+=2; } } else { if (nFormat>=0) nResult+=cbElement+4+nFormat; else if (nFormat==-1) nResult+=cbElement+3; else nResult+=cbElement+4; } } else { // If there are no children we can use shorthand XML notation - // "" // "/>\0" if (lpszMarker) { lpszMarker[nResult]=_CXML('/'); lpszMarker[nResult+1]=_CXML('>'); if (nFormat != -1) lpszMarker[nResult+2]=_CXML('\n'); } 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 XMLSTR - Allocated XML string, you must free // this with free(). XMLSTR XMLNode::createXMLString(int nFormat, int *pnSize) const { if (!d) { if (pnSize) *pnSize=0; return NULL; } XMLSTR lpszResult = NULL; int cbStr; // Recursively Calculate the size of the XML string if (!dropWhiteSpace) nFormat=0; nFormat = nFormat ? 0 : -1; cbStr = CreateXMLStringR(d, 0, nFormat); // Alllocate memory for the XML string + the NULL terminator and // create the recursively XML string. lpszResult=(XMLSTR)malloc((cbStr+1)*sizeof(XMLCHAR)); CreateXMLStringR(d, lpszResult, nFormat); lpszResult[cbStr]=_CXML('\0'); if (pnSize) *pnSize = cbStr; return lpszResult; } int XMLNode::detachFromParent(XMLNodeData *d) { XMLNode *pa=d->pParent->pChild; int i=0; while (((void*)(pa[i].d))!=((void*)d)) i++; d->pParent->nChild--; if (d->pParent->nChild) memmove(pa+i,pa+i+1,(d->pParent->nChild-i)*sizeof(XMLNode)); else { free(pa); d->pParent->pChild=NULL; } return removeOrderElement(d->pParent,eNodeChild,i); } XMLNode::~XMLNode() { if (!d) return; d->ref_count--; emptyTheNode(0); } void XMLNode::deleteNodeContent() { if (!d) return; if (d->pParent) { detachFromParent(d); d->pParent=NULL; d->ref_count--; } emptyTheNode(1); } void XMLNode::emptyTheNode(char force) { XMLNodeData *dd=d; // warning: must stay this way! if ((dd->ref_count==0)||force) { if (d->pParent) detachFromParent(d); int i; XMLNode *pc; for(i=0; inChild; i++) { pc=dd->pChild+i; pc->d->pParent=NULL; pc->d->ref_count--; pc->emptyTheNode(force); } myFree(dd->pChild); for(i=0; inText; i++) free((void*)dd->pText[i]); myFree(dd->pText); for(i=0; inClear; i++) free((void*)dd->pClear[i].lpszValue); myFree(dd->pClear); for(i=0; inAttribute; i++) { free((void*)dd->pAttribute[i].lpszName); if (dd->pAttribute[i].lpszValue) free((void*)dd->pAttribute[i].lpszValue); } myFree(dd->pAttribute); myFree(dd->pOrder); myFree((void*)dd->lpszName); dd->nChild=0; dd->nText=0; dd->nClear=0; dd->nAttribute=0; dd->pChild=NULL; dd->pText=NULL; dd->pClear=NULL; dd->pAttribute=NULL; dd->pOrder=NULL; dd->lpszName=NULL; dd->pParent=NULL; } if (dd->ref_count==0) { free(dd); d=NULL; } } XMLNode& XMLNode::operator=( const XMLNode& A ) { // shallow copy if (this != &A) { if (d) { d->ref_count--; emptyTheNode(0); } 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)++ ; } XMLNode XMLNode::deepCopy() const { if (!d) return XMLNode::emptyXMLNode; XMLNode x(NULL,stringDup(d->lpszName),d->isDeclaration); XMLNodeData *p=x.d; int n=d->nAttribute; if (n) { p->nAttribute=n; p->pAttribute=(XMLAttribute*)malloc(n*sizeof(XMLAttribute)); while (n--) { p->pAttribute[n].lpszName=stringDup(d->pAttribute[n].lpszName); p->pAttribute[n].lpszValue=stringDup(d->pAttribute[n].lpszValue); } } if (d->pOrder) { n=(d->nChild+d->nText+d->nClear)*sizeof(int); p->pOrder=(int*)malloc(n); memcpy(p->pOrder,d->pOrder,n); } n=d->nText; if (n) { p->nText=n; p->pText=(XMLCSTR*)malloc(n*sizeof(XMLCSTR)); while(n--) p->pText[n]=stringDup(d->pText[n]); } n=d->nClear; if (n) { p->nClear=n; p->pClear=(XMLClear*)malloc(n*sizeof(XMLClear)); while (n--) { p->pClear[n].lpszCloseTag=d->pClear[n].lpszCloseTag; p->pClear[n].lpszOpenTag=d->pClear[n].lpszOpenTag; p->pClear[n].lpszValue=stringDup(d->pClear[n].lpszValue); } } n=d->nChild; if (n) { p->nChild=n; p->pChild=(XMLNode*)malloc(n*sizeof(XMLNode)); while (n--) { p->pChild[n].d=NULL; p->pChild[n]=d->pChild[n].deepCopy(); p->pChild[n].d->pParent=p; } } return x; } XMLNode XMLNode::addChild(XMLNode childNode, int pos) { XMLNodeData *dc=childNode.d; if ((!dc)||(!d)) return childNode; if (!dc->lpszName) { // this is a root node: todo: correct fix int j=pos; while (dc->nChild) { addChild(dc->pChild[0],j); if (pos>=0) j++; } return childNode; } if (dc->pParent) { if ((detachFromParent(dc)<=pos)&&(dc->pParent==d)) pos--; } else dc->ref_count++; dc->pParent=d; // int nc=d->nChild; // d->pChild=(XMLNode*)myRealloc(d->pChild,(nc+1),memoryIncrease,sizeof(XMLNode)); d->pChild=(XMLNode*)addToOrder(0,&pos,d->nChild,d->pChild,sizeof(XMLNode),eNodeChild); d->pChild[pos].d=dc; d->nChild++; return childNode; } void XMLNode::deleteAttribute(int i) { if ((!d)||(i<0)||(i>=d->nAttribute)) return; d->nAttribute--; XMLAttribute *p=d->pAttribute+i; free((void*)p->lpszName); if (p->lpszValue) free((void*)p->lpszValue); if (d->nAttribute) memmove(p,p+1,(d->nAttribute-i)*sizeof(XMLAttribute)); else { free(p); d->pAttribute=NULL; } } void XMLNode::deleteAttribute(XMLAttribute *a){ if (a) deleteAttribute(a->lpszName); } void XMLNode::deleteAttribute(XMLCSTR lpszName) { int j=0; getAttribute(lpszName,&j); if (j) deleteAttribute(j-1); } XMLAttribute *XMLNode::updateAttribute_WOSD(XMLSTR lpszNewValue, XMLSTR lpszNewName,int i) { if (!d) { if (lpszNewValue) free(lpszNewValue); if (lpszNewName) free(lpszNewName); return NULL; } if (i>=d->nAttribute) { if (lpszNewName) return addAttribute_WOSD(lpszNewName,lpszNewValue); return NULL; } XMLAttribute *p=d->pAttribute+i; if (p->lpszValue&&p->lpszValue!=lpszNewValue) free((void*)p->lpszValue); p->lpszValue=lpszNewValue; if (lpszNewName&&p->lpszName!=lpszNewName) { free((void*)p->lpszName); p->lpszName=lpszNewName; }; return p; } XMLAttribute *XMLNode::updateAttribute_WOSD(XMLAttribute *newAttribute, XMLAttribute *oldAttribute) { if (oldAttribute) return updateAttribute_WOSD((XMLSTR)newAttribute->lpszValue,(XMLSTR)newAttribute->lpszName,oldAttribute->lpszName); return addAttribute_WOSD((XMLSTR)newAttribute->lpszName,(XMLSTR)newAttribute->lpszValue); } XMLAttribute *XMLNode::updateAttribute_WOSD(XMLSTR lpszNewValue, XMLSTR lpszNewName,XMLCSTR lpszOldName) { int j=0; getAttribute(lpszOldName,&j); if (j) return updateAttribute_WOSD(lpszNewValue,lpszNewName,j-1); else { if (lpszNewName) return addAttribute_WOSD(lpszNewName,lpszNewValue); else return addAttribute_WOSD(stringDup(lpszOldName),lpszNewValue); } } int XMLNode::indexText(XMLCSTR lpszValue) const { if (!d) return -1; int i,l=d->nText; if (!lpszValue) { if (l) return 0; return -1; } XMLCSTR *p=d->pText; for (i=0; i=d->nText)) return; d->nText--; XMLCSTR *p=d->pText+i; free((void*)*p); if (d->nText) memmove(p,p+1,(d->nText-i)*sizeof(XMLCSTR)); else { free(p); d->pText=NULL; } removeOrderElement(d,eNodeText,i); } void XMLNode::deleteText(XMLCSTR lpszValue) { deleteText(indexText(lpszValue)); } XMLCSTR XMLNode::updateText_WOSD(XMLSTR lpszNewValue, int i) { if (!d) { if (lpszNewValue) free(lpszNewValue); return NULL; } if (i>=d->nText) return addText_WOSD(lpszNewValue); XMLCSTR *p=d->pText+i; if (*p!=lpszNewValue) { free((void*)*p); *p=lpszNewValue; } return lpszNewValue; } XMLCSTR XMLNode::updateText_WOSD(XMLSTR lpszNewValue, XMLCSTR lpszOldValue) { if (!d) { if (lpszNewValue) free(lpszNewValue); return NULL; } int i=indexText(lpszOldValue); if (i>=0) return updateText_WOSD(lpszNewValue,i); return addText_WOSD(lpszNewValue); } void XMLNode::deleteClear(int i) { if ((!d)||(i<0)||(i>=d->nClear)) return; d->nClear--; XMLClear *p=d->pClear+i; free((void*)p->lpszValue); if (d->nClear) memmove(p,p+1,(d->nClear-i)*sizeof(XMLClear)); else { free(p); d->pClear=NULL; } removeOrderElement(d,eNodeClear,i); } int XMLNode::indexClear(XMLCSTR lpszValue) const { if (!d) return -1; int i,l=d->nClear; if (!lpszValue) { if (l) return 0; return -1; } XMLClear *p=d->pClear; for (i=0; ilpszValue); } XMLClear *XMLNode::updateClear_WOSD(XMLSTR lpszNewContent, int i) { if (!d) { if (lpszNewContent) free(lpszNewContent); return NULL; } if (i>=d->nClear) return addClear_WOSD(lpszNewContent); XMLClear *p=d->pClear+i; if (lpszNewContent!=p->lpszValue) { free((void*)p->lpszValue); p->lpszValue=lpszNewContent; } return p; } XMLClear *XMLNode::updateClear_WOSD(XMLSTR lpszNewContent, XMLCSTR lpszOldValue) { if (!d) { if (lpszNewContent) free(lpszNewContent); return NULL; } int i=indexClear(lpszOldValue); if (i>=0) return updateClear_WOSD(lpszNewContent,i); return addClear_WOSD(lpszNewContent); } XMLClear *XMLNode::updateClear_WOSD(XMLClear *newP,XMLClear *oldP) { if (oldP) return updateClear_WOSD((XMLSTR)newP->lpszValue,(XMLSTR)oldP->lpszValue); return NULL; } int XMLNode::nChildNode(XMLCSTR name) const { 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(XMLCSTR name, int *j) const { if (!d) return emptyXMLNode; int i=0,n=d->nChild; if (j) i=*j; XMLNode *pc=d->pChild+i; for (; id->lpszName, name)) { if (j) *j=i+1; return *pc; } pc++; } return emptyXMLNode; } XMLNode XMLNode::getChildNode(XMLCSTR name, int j) const { if (!d) return emptyXMLNode; if (j>=0) { int i=0; while (j-->0) getChildNode(name,&i); return getChildNode(name,&i); } int i=d->nChild; while (i--) if (!xstricmp(name,d->pChild[i].d->lpszName)) break; if (i<0) return emptyXMLNode; return getChildNode(i); } XMLNode XMLNode::getChildNodeByPath(XMLCSTR _path, char createMissing, XMLCHAR sep) { XMLSTR path=stringDup(_path); XMLNode x=getChildNodeByPathNonConst(path,createMissing,sep); if (path) free(path); return x; } XMLNode XMLNode::getChildNodeByPathNonConst(XMLSTR path, char createIfMissing, XMLCHAR sep) { if ((!path)||(!(*path))) return *this; XMLNode xn,xbase=*this; XMLCHAR *tend1,sepString[2]; sepString[0]=sep; sepString[1]=0; tend1=xstrstr(path,sepString); while(tend1) { *tend1=0; xn=xbase.getChildNode(path); if (xn.isEmpty()) { if (createIfMissing) xn=xbase.addChild(path); else { *tend1=sep; return XMLNode::emptyXMLNode; } } *tend1=sep; xbase=xn; path=tend1+1; tend1=xstrstr(path,sepString); } xn=xbase.getChildNode(path); if (xn.isEmpty()&&createIfMissing) xn=xbase.addChild(path); return xn; } XMLElementPosition XMLNode::positionOfText (int i) const { if (i>=d->nText ) i=d->nText-1; return findPosition(d,i,eNodeText ); } XMLElementPosition XMLNode::positionOfClear (int i) const { if (i>=d->nClear) i=d->nClear-1; return findPosition(d,i,eNodeClear); } XMLElementPosition XMLNode::positionOfChildNode(int i) const { if (i>=d->nChild) i=d->nChild-1; return findPosition(d,i,eNodeChild); } XMLElementPosition XMLNode::positionOfText (XMLCSTR lpszValue) const { return positionOfText (indexText (lpszValue)); } XMLElementPosition XMLNode::positionOfClear(XMLCSTR lpszValue) const { return positionOfClear(indexClear(lpszValue)); } XMLElementPosition XMLNode::positionOfClear(XMLClear *a) const { if (a) return positionOfClear(a->lpszValue); return positionOfClear(); } XMLElementPosition XMLNode::positionOfChildNode(XMLNode x) const { if ((!d)||(!x.d)) return -1; XMLNodeData *dd=x.d; XMLNode *pc=d->pChild; int i=d->nChild; while (i--) if (pc[i].d==dd) return findPosition(d,i,eNodeChild); return -1; } XMLElementPosition XMLNode::positionOfChildNode(XMLCSTR name, int count) const { if (!name) return positionOfChildNode(count); int j=0; do { getChildNode(name,&j); if (j<0) return -1; } while (count--); return findPosition(d,j-1,eNodeChild); } XMLNode XMLNode::getChildNodeWithAttribute(XMLCSTR name,XMLCSTR attributeName,XMLCSTR attributeValue, int *k) const { int i=0,j; if (k) i=*k; XMLNode x; XMLCSTR t; do { x=getChildNode(name,&i); if (!x.isEmpty()) { if (attributeValue) { j=0; do { t=x.getAttribute(attributeName,&j); if (t&&(xstricmp(attributeValue,t)==0)) { if (k) *k=i; return x; } } while (t); } else { if (x.isAttributeSet(attributeName)) { if (k) *k=i; return x; } } } } while (!x.isEmpty()); return emptyXMLNode; } // Find an attribute on an node. XMLCSTR XMLNode::getAttribute(XMLCSTR lpszAttrib, int *j) const { 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(XMLCSTR lpszAttrib) const { if (!d) return FALSE; int i,n=d->nAttribute; XMLAttribute *pAttr=d->pAttribute; for (i=0; ilpszName, lpszAttrib)==0) { return TRUE; } pAttr++; } return FALSE; } XMLCSTR XMLNode::getAttribute(XMLCSTR name, int j) const { if (!d) return NULL; int i=0; while (j-->0) getAttribute(name,&i); return getAttribute(name,&i); } XMLNodeContents XMLNode::enumContents(int i) const { XMLNodeContents c; if (!d) { c.etype=eNodeNULL; return c; } if (inAttribute) { c.etype=eNodeAttribute; c.attrib=d->pAttribute[i]; return c; } i-=d->nAttribute; c.etype=(XMLElementType)(d->pOrder[i]&3); i=(d->pOrder[i])>>2; switch (c.etype) { case eNodeChild: c.child = d->pChild[i]; break; case eNodeText: c.text = d->pText[i]; break; case eNodeClear: c.clear = d->pClear[i]; break; default: break; } return c; } XMLCSTR XMLNode::getName() const { if (!d) return NULL; return d->lpszName; } int XMLNode::nText() const { if (!d) return 0; return d->nText; } int XMLNode::nChildNode() const { if (!d) return 0; return d->nChild; } int XMLNode::nAttribute() const { if (!d) return 0; return d->nAttribute; } int XMLNode::nClear() const { if (!d) return 0; return d->nClear; } int XMLNode::nElement() const { if (!d) return 0; return d->nAttribute+d->nChild+d->nText+d->nClear; } XMLClear XMLNode::getClear (int i) const { if ((!d)||(i>=d->nClear )) return emptyXMLClear; return d->pClear[i]; } XMLAttribute XMLNode::getAttribute (int i) const { if ((!d)||(i>=d->nAttribute)) return emptyXMLAttribute; return d->pAttribute[i]; } XMLCSTR XMLNode::getAttributeName (int i) const { if ((!d)||(i>=d->nAttribute)) return NULL; return d->pAttribute[i].lpszName; } XMLCSTR XMLNode::getAttributeValue(int i) const { if ((!d)||(i>=d->nAttribute)) return NULL; return d->pAttribute[i].lpszValue; } XMLCSTR XMLNode::getText (int i) const { if ((!d)||(i>=d->nText )) return NULL; return d->pText[i]; } XMLNode XMLNode::getChildNode (int i) const { if ((!d)||(i>=d->nChild )) return emptyXMLNode; return d->pChild[i]; } XMLNode XMLNode::getParentNode ( ) const { if ((!d)||(!d->pParent )) return emptyXMLNode; return XMLNode(d->pParent); } char XMLNode::isDeclaration ( ) const { if (!d) return 0; return d->isDeclaration; } char XMLNode::isEmpty ( ) const { return (d==NULL); } XMLNode XMLNode::emptyNode ( ) { return XMLNode::emptyXMLNode; } XMLNode XMLNode::addChild(XMLCSTR lpszName, char isDeclaration, XMLElementPosition pos) { return addChild_priv(0,stringDup(lpszName),isDeclaration,pos); } XMLNode XMLNode::addChild_WOSD(XMLSTR lpszName, char isDeclaration, XMLElementPosition pos) { return addChild_priv(0,lpszName,isDeclaration,pos); } XMLAttribute *XMLNode::addAttribute(XMLCSTR lpszName, XMLCSTR lpszValue) { return addAttribute_priv(0,stringDup(lpszName),stringDup(lpszValue)); } XMLAttribute *XMLNode::addAttribute_WOSD(XMLSTR lpszName, XMLSTR lpszValuev) { return addAttribute_priv(0,lpszName,lpszValuev); } XMLCSTR XMLNode::addText(XMLCSTR lpszValue, XMLElementPosition pos) { return addText_priv(0,stringDup(lpszValue),pos); } XMLCSTR XMLNode::addText_WOSD(XMLSTR lpszValue, XMLElementPosition pos) { return addText_priv(0,lpszValue,pos); } XMLClear *XMLNode::addClear(XMLCSTR lpszValue, XMLCSTR lpszOpen, XMLCSTR lpszClose, XMLElementPosition pos) { return addClear_priv(0,stringDup(lpszValue),lpszOpen,lpszClose,pos); } XMLClear *XMLNode::addClear_WOSD(XMLSTR lpszValue, XMLCSTR lpszOpen, XMLCSTR lpszClose, XMLElementPosition pos) { return addClear_priv(0,lpszValue,lpszOpen,lpszClose,pos); } XMLCSTR XMLNode::updateName(XMLCSTR lpszName) { return updateName_WOSD(stringDup(lpszName)); } XMLAttribute *XMLNode::updateAttribute(XMLAttribute *newAttribute, XMLAttribute *oldAttribute) { return updateAttribute_WOSD(stringDup(newAttribute->lpszValue),stringDup(newAttribute->lpszName),oldAttribute->lpszName); } XMLAttribute *XMLNode::updateAttribute(XMLCSTR lpszNewValue, XMLCSTR lpszNewName,int i) { return updateAttribute_WOSD(stringDup(lpszNewValue),stringDup(lpszNewName),i); } XMLAttribute *XMLNode::updateAttribute(XMLCSTR lpszNewValue, XMLCSTR lpszNewName,XMLCSTR lpszOldName) { return updateAttribute_WOSD(stringDup(lpszNewValue),stringDup(lpszNewName),lpszOldName); } XMLCSTR XMLNode::updateText(XMLCSTR lpszNewValue, int i) { return updateText_WOSD(stringDup(lpszNewValue),i); } XMLCSTR XMLNode::updateText(XMLCSTR lpszNewValue, XMLCSTR lpszOldValue) { return updateText_WOSD(stringDup(lpszNewValue),lpszOldValue); } XMLClear *XMLNode::updateClear(XMLCSTR lpszNewContent, int i) { return updateClear_WOSD(stringDup(lpszNewContent),i); } XMLClear *XMLNode::updateClear(XMLCSTR lpszNewValue, XMLCSTR lpszOldValue) { return updateClear_WOSD(stringDup(lpszNewValue),lpszOldValue); } XMLClear *XMLNode::updateClear(XMLClear *newP,XMLClear *oldP) { return updateClear_WOSD(stringDup(newP->lpszValue),oldP->lpszValue); } char XMLNode::setGlobalOptions(XMLCharEncoding _characterEncoding, char _guessWideCharChars, char _dropWhiteSpace, char _removeCommentsInMiddleOfText) { guessWideCharChars=_guessWideCharChars; dropWhiteSpace=_dropWhiteSpace; removeCommentsInMiddleOfText=_removeCommentsInMiddleOfText; #ifdef _XMLWIDECHAR if (_characterEncoding) characterEncoding=_characterEncoding; #else switch(_characterEncoding) { case char_encoding_UTF8: characterEncoding=_characterEncoding; XML_ByteTable=XML_utf8ByteTable; break; case char_encoding_legacy: characterEncoding=_characterEncoding; XML_ByteTable=XML_legacyByteTable; break; case char_encoding_ShiftJIS: characterEncoding=_characterEncoding; XML_ByteTable=XML_sjisByteTable; break; case char_encoding_GB2312: characterEncoding=_characterEncoding; XML_ByteTable=XML_gb2312ByteTable; break; case char_encoding_Big5: case char_encoding_GBK: characterEncoding=_characterEncoding; XML_ByteTable=XML_gbk_big5_ByteTable; break; default: return 1; } #endif return 0; } XMLNode::XMLCharEncoding XMLNode::guessCharEncoding(void *buf,int l, char useXMLEncodingAttribute) { #ifdef _XMLWIDECHAR return (XMLCharEncoding)0; #else if (l<25) return (XMLCharEncoding)0; if (guessWideCharChars&&(myIsTextWideChar(buf,l))) return (XMLCharEncoding)0; unsigned char *b=(unsigned char*)buf; if ((b[0]==0xef)&&(b[1]==0xbb)&&(b[2]==0xbf)) return char_encoding_UTF8; // Match utf-8 model ? XMLCharEncoding bestGuess=char_encoding_UTF8; int i=0; while (i>2 ]; *(curr++)=base64EncodeTable[(inbuf[0]<<4)&0x3F]; *(curr++)=base64Fillchar; *(curr++)=base64Fillchar; } else if (eLen==2) { j=(inbuf[0]<<8)|inbuf[1]; *(curr++)=base64EncodeTable[ j>>10 ]; *(curr++)=base64EncodeTable[(j>> 4)&0x3f]; *(curr++)=base64EncodeTable[(j<< 2)&0x3f]; *(curr++)=base64Fillchar; } *(curr++)=0; return (XMLSTR)buf; } unsigned int XMLParserBase64Tool::decodeSize(XMLCSTR data,XMLError *xe) { if (!data) return 0; if (xe) *xe=eXMLErrorNone; int size=0; unsigned char c; //skip any extra characters (e.g. newlines or spaces) while (*data) { #ifdef _XMLWIDECHAR if (*data>255) { if (xe) *xe=eXMLErrorBase64DecodeIllegalCharacter; return 0; } #endif c=base64DecodeTable[(unsigned char)(*data)]; if (c<97) size++; else if (c==98) { if (xe) *xe=eXMLErrorBase64DecodeIllegalCharacter; return 0; } data++; } if (xe&&(size%4!=0)) *xe=eXMLErrorBase64DataSizeIsNotMultipleOf4; if (size==0) return 0; do { data--; size--; } while(*data==base64Fillchar); size++; return (unsigned int)((size*3)/4); } unsigned char XMLParserBase64Tool::decode(XMLCSTR data, unsigned char *buf, int len, XMLError *xe) { if (!data) return 0; if (xe) *xe=eXMLErrorNone; int i=0,p=0; unsigned char d,c; for(;;) { #ifdef _XMLWIDECHAR #define BASE64DECODE_READ_NEXT_CHAR(c) \ do { \ if (data[i]>255){ c=98; break; } \ c=base64DecodeTable[(unsigned char)data[i++]]; \ }while (c==97); \ if(c==98){ if(xe)*xe=eXMLErrorBase64DecodeIllegalCharacter; return 0; } #else #define BASE64DECODE_READ_NEXT_CHAR(c) \ do { c=base64DecodeTable[(unsigned char)data[i++]]; }while (c==97); \ if(c==98){ if(xe)*xe=eXMLErrorBase64DecodeIllegalCharacter; return 0; } #endif BASE64DECODE_READ_NEXT_CHAR(c) if (c==99) { return 2; } if (c==96) { if (p==(int)len) return 2; if (xe) *xe=eXMLErrorBase64DecodeTruncatedData; return 1; } BASE64DECODE_READ_NEXT_CHAR(d) if ((d==99)||(d==96)) { if (xe) *xe=eXMLErrorBase64DecodeTruncatedData; return 1; } if (p==(int)len) { if (xe) *xe=eXMLErrorBase64DecodeBufferTooSmall; return 0; } buf[p++]=(unsigned char)((c<<2)|((d>>4)&0x3)); BASE64DECODE_READ_NEXT_CHAR(c) if (c==99) { if (xe) *xe=eXMLErrorBase64DecodeTruncatedData; return 1; } if (p==(int)len) { if (c==96) return 2; if (xe) *xe=eXMLErrorBase64DecodeBufferTooSmall; return 0; } if (c==96) { if (xe) *xe=eXMLErrorBase64DecodeTruncatedData; return 1; } buf[p++]=(unsigned char)(((d<<4)&0xf0)|((c>>2)&0xf)); BASE64DECODE_READ_NEXT_CHAR(d) if (d==99 ) { if (xe) *xe=eXMLErrorBase64DecodeTruncatedData; return 1; } if (p==(int)len) { if (d==96) return 2; if (xe) *xe=eXMLErrorBase64DecodeBufferTooSmall; return 0; } if (d==96) { if (xe) *xe=eXMLErrorBase64DecodeTruncatedData; return 1; } buf[p++]=(unsigned char)(((c<<6)&0xc0)|d); } } #undef BASE64DECODE_READ_NEXT_CHAR void XMLParserBase64Tool::alloc(int newsize) { if ((!buf)&&(newsize)) { buf=malloc(newsize); buflen=newsize; return; } if (newsize>buflen) { buf=realloc(buf,newsize); buflen=newsize; } } unsigned char *XMLParserBase64Tool::decode(XMLCSTR data, int *outlen, XMLError *xe) { if (xe) *xe=eXMLErrorNone; if (!data) { *outlen=0; return (unsigned char*)""; } unsigned int len=decodeSize(data,xe); if (outlen) *outlen=len; if (!len) return NULL; alloc(len+1); if(!decode(data,(unsigned char*)buf,len,xe)){ return NULL; } return (unsigned char*)buf; } libmusicbrainz-5.0.1/tests/000077500000000000000000000000001175500222200156705ustar00rootroot00000000000000libmusicbrainz-5.0.1/tests/.gitignore000066400000000000000000000000661175500222200176620ustar00rootroot00000000000000CMakeFiles/ Makefile cmake_install.cmake ctest mbtest libmusicbrainz-5.0.1/tests/CMakeLists.txt000066400000000000000000000016471175500222200204400ustar00rootroot00000000000000INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../include) LINK_LIBRARIES(musicbrainz5 ${NEON_LIBRARIES}) ADD_EXECUTABLE(mbtest mbtest.cc) ADD_EXECUTABLE(ctest ctest.c) IF(CMAKE_COMPILER_IS_GNUCXX) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic-errors") IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) ENDIF(CMAKE_COMPILER_IS_GNUCXX) IF(CMAKE_COMPILER_IS_GNUCC) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic-errors") IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../.git) set_source_files_properties(ctest.c PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations") set_source_files_properties(mbtest.cc PROPERTIES COMPILE_FLAGS "-Wno-deprecated-declarations") ENDIF(CMAKE_COMPILER_IS_GNUCC) libmusicbrainz-5.0.1/tests/ctest.c000066400000000000000000000671041175500222200171660ustar00rootroot00000000000000/* -------------------------------------------------------------------------- libmusicbrainz5 - Client library to access MusicBrainz Copyright (C) 2012 Andrew Hawkins This file is part of libmusicbrainz5. This library is free software; you can redistribute it and/or modify it under the terms of v2 of the GNU Lesser General Public License as published by the Free Software Foundation. libmusicbrainz5 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 General Public License along with this library. If not, see . $Id$ ----------------------------------------------------------------------------*/ #include #include #include #include "musicbrainz5/mb5_c.h" void PrintRelationList(Mb5RelationList RelationList) { char Type[256]; int count; mb5_relation_list_get_targettype(RelationList,Type,sizeof(Type)); printf("Target type is '%s'\n",Type); for (count=0;count. $Id$ ----------------------------------------------------------------------------*/ #include #include #include "musicbrainz5/Query.h" #include "musicbrainz5/Release.h" #include "musicbrainz5/ReleaseGroup.h" #include "musicbrainz5/Medium.h" #include "musicbrainz5/MediumList.h" #include "musicbrainz5/NameCredit.h" #include "musicbrainz5/ArtistCredit.h" #include "musicbrainz5/Artist.h" #include "musicbrainz5/Alias.h" #include "musicbrainz5/HTTPFetch.h" #include "musicbrainz5/Track.h" #include "musicbrainz5/Recording.h" #include "musicbrainz5/Collection.h" #include "musicbrainz5/CollectionList.h" #include "musicbrainz5/RelationListList.h" #include "musicbrainz5/RelationList.h" #include "musicbrainz5/Relation.h" #include "musicbrainz5/Work.h" #include "musicbrainz5/ISWC.h" #include "musicbrainz5/ISWCList.h" #include "musicbrainz5/SecondaryType.h" #include "musicbrainz5/SecondaryTypeList.h" #include "musicbrainz5/IPI.h" #include "musicbrainz5/IPIList.h" #include "musicbrainz5/Lifespan.h" void PrintRelationList(MusicBrainz5::CRelationList *RelationList) { std::cout << "Target type: '" << RelationList->TargetType() << "'" << std::endl; for (int count=0;countNumItems();count++) { MusicBrainz5::CRelation *Relation=RelationList->Item(count); std::cout << "Relation: " << count << " - Type '" << Relation->Type() << "', Target '" << Relation->Target() << "'" << std::endl; } } int main(int argc, const char *argv[]) { MusicBrainz5::CQuery MB2("MBTest/v1.0","test.musicbrainz.org"); MusicBrainz5::CQuery::tParamMap Params5; Params5["inc"]="aliases"; MusicBrainz5::CMetadata Metadata5=MB2.Query("artist","4b585938-f271-45e2-b19a-91c634b5e396","",Params5); MusicBrainz5::CArtist *Artist=Metadata5.Artist(); if (Artist) { MusicBrainz5::CLifespan *Lifespan=Artist->Lifespan(); if (Lifespan) { std::cout << "Begin: " << Lifespan->Begin() << std::endl; std::cout << "End: " << Lifespan->End() << std::endl; std::cout << "Ended: " << Lifespan->Ended() << std::endl; } } return 0; MusicBrainz5::CMetadata Metadata8=MB2.Query("release-group","2eefe885-f050-426d-93f0-29c5eb8b4f9a"); std::cout << Metadata8 << std::endl; return 0; MusicBrainz5::CMetadata Metadata7=MB2.Query("artist","4b585938-f271-45e2-b19a-91c634b5e396"); Artist=Metadata7.Artist(); if (Artist) { MusicBrainz5::CIPIList *IPIList=Artist->IPIList(); if (IPIList) { for (int count=0;countNumItems();count++) { MusicBrainz5::CIPI *IPI=IPIList->Item(count); if (IPI) { std::cout << "IPI " << count << ": " << IPI->IPI() << std::endl; } } } } return 0; MusicBrainz5::CMetadata Metadata6=MB2.Query("release-group","2eefe885-f050-426d-93f0-29c5eb8b4f9a"); MusicBrainz5::CReleaseGroup *ReleaseGroup=Metadata6.ReleaseGroup(); if (ReleaseGroup) { std::cout << "ID: " << ReleaseGroup->ID() << std::endl; std::cout << "PrimaryType: " << ReleaseGroup->PrimaryType() << std::endl; std::cout << "Title: " << ReleaseGroup->Title() << std::endl; std::cout << "Disambiguation: " << ReleaseGroup->Disambiguation() << std::endl; std::cout << "FirstReleaseDate: " << ReleaseGroup->FirstReleaseDate() << std::endl; MusicBrainz5::CSecondaryTypeList *SecondaryTypeList=ReleaseGroup->SecondaryTypeList(); if (SecondaryTypeList) { for (int count=0;countNumItems();count++) { MusicBrainz5::CSecondaryType *SecondaryType=SecondaryTypeList->Item(count); if (SecondaryType) { std::cout << "Secondary type " << count << " = " << SecondaryType->SecondaryType() << std::endl; } } } } return 0; MusicBrainz5::CMetadata Metadata4=MB2.Query("work","b0d17375-5593-390e-a936-1a65ce74c630"); MusicBrainz5::CWork *ThisWork=Metadata4.Work(); if (ThisWork) { std::cout << "ID: '" << ThisWork->ID() << "'" << std::endl; std::cout << "Title: '" << ThisWork->Title() << "'" << std::endl; MusicBrainz5::CISWCList *ISWCList=ThisWork->ISWCList(); if (ISWCList) { for (int count=0;countNumItems();count++) { MusicBrainz5::CISWC *ISWC=ISWCList->Item(count); std::cout << "ISWC " << count << " - '" << ISWC->ISWC() << "'" << std::endl; } } std::cout << "Disambiguation: '" << ThisWork->Disambiguation() << "'" << std::endl; std::cout << "Language: '" << ThisWork->Language() << "'" << std::endl; } MusicBrainz5::CQuery::tParamMap Params3; Params3["inc"]="media recordings"; Metadata4=MB2.Query("release","ae050d13-7f86-495e-9918-10d8c0ac58e8","",Params3); MusicBrainz5::CRelease *Release2=Metadata4.Release(); if (Release2) { MusicBrainz5::CMediumList *MediumList=Release2->MediumList(); if (MediumList) { for (int count=0;countNumItems();count++) { MusicBrainz5::CMedium *Medium=MediumList->Item(count); if (Medium) { MusicBrainz5::CTrackList *TrackList=Medium->TrackList(); if (TrackList) { for (int track=0;trackNumItems();track++) { MusicBrainz5::CTrack *Track=TrackList->Item(track); if (Track) { std::cout << "Position: " << Track->Position() << std::endl; std::cout << "Title: " << Track->Title() << std::endl; std::cout << "Length: " << Track->Length() << std::endl; std::cout << "Number: " << Track->Number() << std::endl; } } } } } } } return 0; MusicBrainz5::CQuery MB("MBTest/v1.0"); if (argc>1) { std::cout << "Setting username: '" << argv[1] << "'" << std::endl; MB.SetUserName(argv[1]); } if (argc>2) { std::cout << "Setting password: '" << argv[2] << "'" << std::endl; MB.SetPassword(argv[2]); } MusicBrainz5::CQuery::tParamMap Params2; Params2["inc"]="artists release-groups url-rels work-level-rels work-rels artist-rels"; MusicBrainz5::CMetadata Metadata3=MB.Query("recording","3631f569-520d-40ff-a1ee-076604723275","",Params2); MusicBrainz5::CRecording *Recording=Metadata3.Recording(); if (Recording) { MusicBrainz5::CRelationListList *RelationListList=Recording->RelationListList(); for (int count=0;countNumItems();count++) { MusicBrainz5::CRelationList *RelationList=RelationListList->Item(count); PrintRelationList(RelationList); } } return 0; MusicBrainz5::CQuery::tParamMap Params; Params["inc"]="artists labels recordings release-groups url-rels discids recording-level-rels work-level-rels work-rels artist-rels"; MusicBrainz5::CMetadata Metadata2=MB.Query("release","ef4596f0-5554-443a-aea9-247d2e250f61","",Params); MusicBrainz5::CRelease *Release=Metadata2.Release(); if (Release) { MusicBrainz5::CMediumList *MediumList=Release->MediumList(); if (MediumList) { for (int MediumNum=0;MediumNumNumItems();MediumNum++) { MusicBrainz5::CMedium *Medium=MediumList->Item(MediumNum); if (Medium) { MusicBrainz5::CTrackList *TrackList=Medium->TrackList(); if (TrackList) { for (int TrackNum=0;TrackNumNumItems();TrackNum++) { MusicBrainz5::CTrack *Track=TrackList->Item(TrackNum); if (Track) { MusicBrainz5::CRecording *Recording=Track->Recording(); if (Recording) { MusicBrainz5::CRelationListList *RelationListList=Recording->RelationListList(); if (RelationListList) { std::cout << RelationListList->NumItems() << " items" << std::endl; for (int RelationListNum=0;RelationListNumNumItems();RelationListNum++) { MusicBrainz5::CRelationList *RelationList=RelationListList->Item(RelationListNum); PrintRelationList(RelationList); } } } } } } } } } } return 0; MusicBrainz5::CMetadata Metadata=MB.Query("collection"); MusicBrainz5::CCollectionList *CollectionList=Metadata.CollectionList(); if (CollectionList && 0!=CollectionList->NumItems()) { MusicBrainz5::CCollection *Collection=CollectionList->Item(0); std::cout << "ID is " << Collection->ID() << std::endl; MB.Query("collection",Collection->ID(),"releases"); std::vector Releases; Releases.push_back("b5748ac9-f38e-48f7-a8a4-8b43cab025bc"); Releases.push_back("f6335672-c521-4129-86c3-490d20533e08"); bool Ret=MB.AddCollectionEntries(Collection->ID(),Releases); std::cout << "AddCollectionEntries returns " << std::boolalpha << Ret << std::endl; MB.Query("collection",Collection->ID(),"releases"); Releases.clear(); Releases.push_back("b5748ac9-f38e-48f7-a8a4-8b43cab025bc"); Ret=MB.DeleteCollectionEntries(Collection->ID(),Releases); std::cout << "DeleteCollectionEntries returns " << std::boolalpha << Ret << std::endl; MB.Query("collection",Collection->ID(),"releases"); } return 0; std::string DiscID="arIS30RPWowvwNEqsqdDnZzDGhk-"; if (argc==2) DiscID=argv[1]; MusicBrainz5::CReleaseList ReleaseList=MB.LookupDiscID(DiscID); for (int count=0;countID()); std::cout << "Full release: " << std::endl; std::cout << FullRelease << std::endl; std::cout << "Release group title: '" << FullRelease.ReleaseGroup()->Title() << "'" << std::endl; std::cout << std::endl << std::endl << "Media matching " << DiscID << ":" << std::endl; MusicBrainz5::CMediumList MediaList=FullRelease.MediaMatchingDiscID(DiscID); for (int count=0;count