rpld-0.1.9/0000755000175000017500000000000012266603012010602 5ustar phiphirpld-0.1.9/codec-helper/0000755000175000017500000000000012266602740013143 5ustar phiphirpld-0.1.9/codec-helper/rpld-codec-helper-gstreamer0000755000175000017500000000176511501404247020353 0ustar phiphi#!/bin/sh # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. { gst-launch fdsrc fd=0 ! decodebin ! audioconvert ! capsfilter caps="audio/x-raw-int,width=16,channels=2,rate=44100" ! fdsink fd=3 > /dev/null 2> /dev/null } 3>&1 #ll rpld-0.1.9/codec-helper/rpld-codec-helper.10000644000175000017500000000204711504134235016512 0ustar phiphi.\" rpld-codec-helper.1: .TH "rpld-codec-helper" "1" "July 2010" "RoarAudio PlayList Daemon" "System User's Manual: rpld" .SH NAME rpld-codec-helper \- Codec helper script for RoarAudio PlayList Daemon .SH SYNOPSIS rpld-codec-helper .SH DESCRIPTION The RoarAudio PlayList Daemon is a daemon which manages playlists and can play files or streams from those lists using a RoarAudio Sound Server. This program is used internally by rpld to support codecs which are not supported by the sound server. Those formats are normally non-free ones. If you use recommended formats like Ogg Vorbis this seldom will be used. This program should never be called directly (by user). Functionality of this is not part of rpld to keep sources clean and to avoid depends on code with doubtful legal status. .SH "OPTIONS" This program does not have any options. .SH "SEE ALSO" \fBrpld\fR(1), \fBRoarAudio\fR(7). .SH "HISTORY" Support for codec helper script was added with release 0.1beta0 and 0.1rc4 will be the first release shipping a codec helper script. .\" ll rpld-0.1.9/COPYING.gplv30000644000175000017500000010451311274114601012672 0ustar phiphi GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, 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 them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If 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 convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU 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 Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state 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 program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . rpld-0.1.9/ChangeLog0000644000175000017500000001716112266601524012370 0ustar phiphiv. 0.1.9 - Sat Jan 18 2014 23:41 CET * Print warning when --load-playlist is used (Closes: #361) * Did some hardening, also fixed a bit in AUTOQUEUE support. * Avoid segfault on wrong SEARCHPLE syntax (Closes: #364) * Corrected rpld_ple_copy() to also copy filenames (Closes: #365) * Updated copyright statements. v. 0.1.8 - Sat Nov 23 2013 11:45 CET * Added AUTOQUEUE command. * Updated copyright statements. * Added support to handle multiple filenames per plent (Closes: #319) * Added FALLBACK pointer. * Cleanup. * Fixed playlist leak. * Improved LISTCLIENTS command. * Corrected parser errors for simple protocol (Closes: #357) v. 0.1.7 - Mon Dec 10 2012 16:00 CET * Updated win32 port. v. 0.1.6 - Wed Oct 18 2012 25:51 CEST * Init plugins before we start playback. This fixes a bug with the playback-logging plugin. * Allow to use NEXT command with autoqueue. * Fixed double free caused by deleting to copies of a PLE with extra meta data. * Moved to new build system (See: #325) * Done win32 port updates. * Cleanup of HAVE_LIBROAR_UUID. * Changed default socket location to ~/.rpld. * Improved RePlayGain support. v. 0.1.5 - Mon Sep 17 2012 21:23 CEST * Reenabled --bl-codec. * Updated plugin host interface (version changed). * Also try to read from codec-helper if input from the data source is available. Should avoid stalled codec-helpers. * Applied "01-hyphen-used-as-minus-sign.diff" patch to manpage from Debian. * Added a plugin to write a log file for queues (Closes: #298) * Added support to export a playlist via command line parameters. * Replaced --load-playlist with --playlist-import. * Disabled starting of rpld in debian-like init script by default. This is to better allow per-user sessions as well as rpld instances running only with servers of type +fork. * Added support for server meta data like provided by the RoarAudio Protocol. Also added command SERVERINFO. (Closes: #312) * Fixed PAUSE command on streams using codec-helper (Closes: #316) * Allow backend objects not connected to the server. This is used to avoid queues disappearing on restore in case the server is unreachable (Closes: #317) * Correctly handle EOF while in IMPORT (Closes: #320) * Work around win32's %lli-bug (See: #271) * Ignore all lines in simple protocol starting with hash ('#'). * Added support to report version, buildstamp as well as distribution-version-string. * Added SEARCHPLE command. v. 0.1.4 - Tue Aug 21 2012 13:09 CEST * Add support to hold more meta data (Closes: #202) * Fixed an memory leak in IMPORT and EXPORT commands when using STDIN/STDOUT. * Added support to read and write URAS playlists (Closes: #299) * Added script to manipulate stores offline (Closes: #59) * Updated plugin host interface (version changed) (Closes: #304) * Changed --load-playlist with --restore back to expected behavior. v. 0.1.3 - Thu Aug 09 2012 17:00 CEST * Use UUID API of libroar and remove dependency on libuuid (Closes: #266) * Delay adding queue to "Main Queue" until command lion switches are read and server address is set. This allows --server to as expected again (Closes: #259) * Added support to not connect to a server at startup (Closes: #260) * Free Main Queue and Main History early in case of loading "new" (>= 0.1rc7) stores. This saves a few bytes of runtime memory. * Prepared porting to the common protocol interface (See: #261) * Do not try to install deprecated tools (Closes: #289) * Enabled optimizer (-O2). * Implemented Common Protocol Interface support (Closes: #261) * Added watchdog (Closes: #292) v. 0.1.2 - Tue Jul 10 2012 17:43 CEST * Fixed a segfault in autoqueue. * Added new command LISTCLIENTS (Closes: #227) * Added new command IDENTIFY (Closes: #242) * Removed the deprecated tools rpld-{play,stop,prev,store,addplaylist,delplaylist} (Closes: #239) v. 0.1.1 - Fri May 25 2012 20:43 CEST * Corrected symlink generation for manpages. * Updated debian init script. v. 0.1.0 - Thu May 24 2012 21:33 CEST * Improved error handling * Added common options to tools (Closes: #237, See: #239) * Added status command to debian init script (Closes: #204) * Check argument list to be present (Closes: #241) * Added SHOWQUEUE command. * Added support to import xspf playlists (Closes: #65) v. 0.1rc7 - Sun May 13 2012 21:28 CEST * Fixed warnings on AMD64 (Closes: #203) * Added support to set audio info of codec helper (Closes: #200) * Added support for multiple queues (Closes: #210, #211, #198) * Added const keywords to client_str2acclev() and client_str2proto() (Closes: #216) * Support reading old stores (Closes: #221) * CURRENT, DEFAULT and STARTUP pointers are now per queue (Closes: #223) * Make global variables more local. * Reduced memory usage (by ~24% on test setup). * Updated plugin system (export public header with plugin API). v. 0.1rc6 - Sat Mar 17 2012 13:12 CET * Ported to RoarAudio 1.0* (Closes: #182) * Fixed some compiler warnings. * Added support to load plugins. * Added some more const keywords. * Made some global variables more local. * Re-ported to win32. * Increased maximum number of playlists to 64. v. 0.1rc5 - Fri Sep 30 2011 14:07 CEST * Some fixes to smooth usage on win32. * Corrected license headers. * Support to load playlist via command lion. * Support playback while import. v. 0.1rc4 - Tue Dec 21 2010 15:57 CET * Corrected test for libuuid and libslp * Added codec-helper directory with common Codec Helpers * Moved rpld-* tools from RoaringBox package to this one. * Added support for random EIs and random pointers. * Store and restore volume via normal store directory (Closes: #67) * Added support (currently write only) for XSPF playlists (See: #65) v. 0.1rc3 - Thu Nov 18 2010 15:42 CET * Set ownership and rights on UNIX sockets on our own, no need to be set by init script anymore (Closes: #69) * Do not kill process if pidfile does not exist or is empty (Closes: #70) * Handle server side volume changes correctly (Closes: #68) * Added support for --close-fh and --client-fh (Closes: #71) * Added support for --no-listen * Done some manpage updates. * Avoid non-deletable pid-file * Fixed a lot compiler warnings (-Wextra stuff only) * Fixed spaces in IMPORT and EXPORT commands bug (Closes: #79) * Set debug message prefix correctly v. 0.1rc2 - Tue Nov 09 2010 17:05 CET * Fixed OpenSLP support (cased when libroar not supporing SLP) * Added non-fatal version of --restore (Closes: #58) * Corrected text in Debian init script (Closes: #57) * Reject to run as root. Fixes root exploit trigged by very stupid users (Closes: #63) v. 0.1rc1 - Fri Oct 01 2010 21:08 CEST * Added history playlist * Updated mpd protocol support a lot v. 0.1rc0 - Sat Jul 24 2010 23:04 CEST * Added manpage * Added UNAUTH command in simple protocol * Changed all internals from sysio to VIO v. 0.1beta1 - Mon May 03 2010 22:12 CEST * support for auto locating files if no filename is given based on Tantalos * Added support for reading meta data from roard * started MPD protocol emulation * wrote control files for Debian v. 0.1beta0 - Sun Jan 10 2010 23:42 CET * Start of project * Support for multiple playlists * Import/Export for RPLD, VCLT, M3U, PLS, Plain * Support for UNIX/IPv4/DECnet sockets * Support for Store and Restore * Support for codec helper * Support files for Debian like systems * configure and install make target * Support restore of UUID from VCLT playlists * Support for two pointers: current playlist pointer, default playlist pointer * Support to store pointers * PIDFile support * support to pause streams * support for Artist/Performer to be diffrent * support annoucement via OpenSLP rpld-0.1.9/Makefile0000644000175000017500000000633012031301747012244 0ustar phiphiTARGET=rpld FF_OBJS=fformat.o ff_vclt.o ff_plain.o ff_m3u.o ff_rpld.o ff_pls.o ff_xspf.o ff_uras.o PROTO_OBJS=proto_simple.o proto_simple_vio.o proto_mpd.o OBJS=rpld.o playlist.o client.o network.o backend.o playback.o store.o autoqueue.o yield.o rpldslp.o pointer.o plugin.o serverinfo.o ${FF_OBJS} ${PROTO_OBJS} MANPAGES_1 = rpld.1 HEADERS = rpldplugin.h rpldnotify.h TOOLS_DIR = tools TOOLS_MAN1_BASENAME_0 = rpld-tools TOOLS_MAN1_BASENAME_1 = rpld-deprecated TOOLS_MAN1_BASENAME_2 = rpld-storemgr TOOLS_MAN1_0 = $(TOOLS_DIR)/$(TOOLS_MAN1_BASENAME_0).1 TOOLS_MAN1_1 = $(TOOLS_DIR)/$(TOOLS_MAN1_BASENAME_1).1 TOOLS_MAN1_2 = $(TOOLS_DIR)/$(TOOLS_MAN1_BASENAME_2).1 TOOLS = $(TOOLS_DIR)/rpld-import $(TOOLS_DIR)/rpld-next $(TOOLS_DIR)/rpld-queueple $(TOOLS_DIR)/rpld-setpointer $(TOOLS_DIR)/rpld-listq $(TOOLS_DIR)/rpld-ctl $(TOOLS_DIR)/rpld-listplaylists $(TOOLS_DIR)/rpld-showplaying $(TOOLS_DIR)/rpld-storemgr include Makefile.conf #DEFINES = -DDEBUG DEFINES += -DROAR_DBG_PREFIX=\"roarplaylistd\" CFLAGS += -Wall $(Wextra) -g $(OPTI_O) $(DEFINES) $(INCLUDE) $(INCPATH) LDFLAGS += -Wall $(Wextra) -g $(OPTI_O) $(LDPATH) NETLIBS += $(lib_wsock32) $(lib_ws2_32) LIBS += $(lib_roar) $(lib_slp) $(lib_xml2) $(NETLIBS) all: $(TARGET) clean: rm -f $(TARGET) *.o new: clean all distclean: clean rm -f Makefile.conf config.h config.log $(TARGET): $(OBJS) $(CC) $(LDFLAGS) -o $(TARGET) $(OBJS) $(LIBS) prep-install-dirs: mkdir -p '$(DESTDIR)$(PREFIX_BIN)' mkdir -p '$(DESTDIR)$(PREFIX_LIB)' mkdir -p '$(DESTDIR)$(PREFIX_INC)' mkdir -p '$(DESTDIR)$(PREFIX_MAN)' mkdir -p '$(DESTDIR)$(PREFIX_MAN)'/man1/ prep-install: all prep-install-dirs install: prep-install install-rpld install-tools install-rpld: cp $(cp_v) $(TARGET) '$(DESTDIR)$(PREFIX_BIN)' cp $(cp_v) $(MANPAGES_1) '$(DESTDIR)$(PREFIX_MAN)'/man1/ cp $(cp_v) $(HEADERS) '$(DESTDIR)$(PREFIX_INC)' install-tools: cp $(cp_v) $(TOOLS) '$(DESTDIR)$(PREFIX_BIN)' cp $(cp_v) $(TOOLS_MAN1_0) '$(DESTDIR)$(PREFIX_MAN)'/man1/ cp $(cp_v) $(TOOLS_MAN1_1) '$(DESTDIR)$(PREFIX_MAN)'/man1/ cp $(cp_v) $(TOOLS_MAN1_2) '$(DESTDIR)$(PREFIX_MAN)'/man1/ while read fn fc tn tc; do ln -s ../man$$tc/$$tn.$$tc '$(DESTDIR)$(PREFIX_MAN)'/man$$fc/$$fn.$$fc 2> /dev/null; done < man-symlinks.src; true semi-install: prep-install semi-install-rpld semi-install-tools semi-install-rpld: ln -fs `pwd`/$(TARGET) '$(DESTDIR)$(PREFIX_BIN)' set -e; for i in $(MANPAGES_1); do ln -fs `pwd`/$$i '$(DESTDIR)$(PREFIX_MAN)'/man1/$$i; done set -e; for i in $(HEADERS); do ln -fs `pwd`/$$i '$(DESTDIR)$(PREFIX_INC)'/$$i; done semi-install-tools: set -e; for i in $(TOOLS); do ln -fs `pwd`/$$i '$(DESTDIR)$(PREFIX_BIN)'; done ln -fs `pwd`/$(TOOLS_MAN1_0) '$(DESTDIR)$(PREFIX_MAN)'/man1/$(TOOLS_MAN1_BASENAME_0).1 ln -fs `pwd`/$(TOOLS_MAN1_1) '$(DESTDIR)$(PREFIX_MAN)'/man1/$(TOOLS_MAN1_BASENAME_1).1 ln -fs `pwd`/$(TOOLS_MAN1_2) '$(DESTDIR)$(PREFIX_MAN)'/man1/$(TOOLS_MAN1_BASENAME_2).1 while read fn fc tn tc; do ln -s `pwd`/tools/$$tn.$$tc '$(DESTDIR)$(PREFIX_MAN)'/man$$fc/$$fn.$$fc 2> /dev/null; done < man-symlinks.src; true uninstall: rm -f '$(DESTDIR)$(PREFIX_BIN)/$(TARGET)' .PHONY: all clean new distclean prep-install-dirs prep-install install semi-install uninstall rpld-0.1.9/README0000644000175000017500000000356012266601511011470 0ustar phiphi RoarAudio PlayList Daemon ----------------------------- --- Build: -- Build requirements: In order to build the rpld you need to install RoarAudio and it's devel packets. In addition you should install libuuid from e2progs and it's devel packet. -- How to build: $ ./configure $ make Install with: $ make install -- Codec Helper: The Codec Helper is a small script which is used to decode stuff if codec is unknown or unsupported by server. This is mostly used for non-free codecs which can not be implemented by us. It is very strongly recommended to use a server implementing the codecs you use and only use free codecs. To use a Codec Helper copy one of the files in codec-helper/ to your normal bin directory (/usr/bin, /usr/local/bin, ...) with the name 'rpld-codec-helper'. Diffrent Codec Helper may require diffrent dependencies on installed tools. --- Tested platforms: OPERATING SYSTEM ARCH COMPILER TESTED M/STATUS COMMENT AND VERSION VERSION --------------------------------------------------------------------------------------------------- Debian Etch ix86 gcc 4.1.2 current s/OK Debian Etch x86_64 gcc 4.1.2 0.1.6 s/OK Debian Lenny ix86 gcc 4.3.2 0.1rc4 s/OK Debian Wheezy x86_64 gcc 4.7.2 0.1.8 M/OK Debian Sid ix86 gcc 4.6.1 0.1.1 M/OK Debian Sid ix86 clang 2.7 0.1rc4 s/OK Debian Sid x86_64 gcc 4.7.1 0.1.5 M/OK FreeBSD 7.3 i386 gcc 4.2.1 0.1.7 s/OK Wine 0.9.25 ix86 mingw 3.4.5 0.1.0 s/OK OpenBSD 4.4 i386 gcc 3.3.5 0.1.2 s/OK WinXP/MSys ix86 mingw 4.7.0 0.1.9 m/OK Automatic Build Bot. Tested Version: Current: Current as listed on Homepage last: Last released version (This system is on release checklist) *b*: Beta Status: Maintenance/testing Status: Maintenance: s = your are on your own, sources. m = package in work, beta package M = maintained S = maintained source package B = maintained binary package rpld-0.1.9/TODO0000644000175000017500000000046412023720156011276 0ustar phiphiMore Tickets on BTS at: https://bts.keep-cool.org/ Things we need to do: * (0.1) implement search Things we should do: * (0.1) support for MPD protocol (WIP) * (0.1) something to detect playlist changes * (0.1 #201) 'queue counter' for PLEs Things it would be nice to have: * (0.2 #302 #303) x-fader rpld-0.1.9/autoqueue.c0000644000175000017500000001300312266574300012767 0ustar phiphi//autoqueue.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" static inline int __autoqueue(pli_t queue, struct rpld_playlist * pl) { struct rpld_playlist_entry * plent; struct rpld_playlist_entry * copy; struct rpld_playlist_search pls; struct rpld_playlist_pointer * plp = NULL, * plp_copy = NULL; int update_current = 0; if ( rpld_pointer_is_set(POINTER_CURRENT, queue, -1) == 0 ) { ROAR_DBG("autoqueue(void): no current pointer"); plp = rpld_pointer_get(POINTER_DEFAULT, queue, -1); if ( plp != NULL ) { ROAR_DBG("autoqueue(void): we have a default pointer at %p", plp); if ( rpld_plp_copy(&plp_copy, plp) == -1 ) { ROAR_DBG("autoqueue(void): copy of default pointer to current pointer failed"); return -1; } rpld_pointer_set(POINTER_CURRENT, queue, -1, plp_copy); rpld_plp_unref(plp); rpld_plp_unref(plp_copy); #ifdef DEBUG if ( rpld_pointer_is_set(POINTER_CURRENT, queue, -1) == 0 ) { ROAR_DBG("autoqueue(void): still no current pointer"); } } else { ROAR_DBG("autoqueue(void): no default pointer"); #endif } } plp = rpld_pointer_get(POINTER_CURRENT, queue, -1); if ( plp != NULL ) { ROAR_DBG("autoqueue(void): we have a current pointer at %p", plp); update_current = 1; } if ( plp == NULL ) { plp = rpld_pointer_get(POINTER_FALLBACK, queue, -1); #ifdef DEBUG if ( plp != NULL ) { ROAR_DBG("autoqueue(void): we have a fallback pointer at %p", plp); } #endif } if ( plp == NULL ) { ROAR_DBG("autoqueue(void): No pointers left to try. giving up."); ROAR_DBG("autoqueue(void) = -1"); return -1; } if ( (plent = rpld_plp_search(plp)) == NULL ) { rpld_plp_unref(plp); return -1; } if ( (copy = rpld_ple_copy(plent)) == NULL ) { rpld_plp_unref(plp); return -1; } rpld_pl_push(pl, copy); if ( update_current && !( plp->pls.type == RPLD_PL_ST_RANDOM || plp->pls.type == RPLD_PL_ST_RANDOM_LIKENESS ) ) { if ( rpld_pointer_set(POINTER_CURRENT, queue, -1, NULL) == 0 ) { if ( plent->list.next != NULL ) { plent = plent->list.next; memset(&pls, 0, sizeof(pls)); pls.type = RPLD_PL_ST_UUID; memcpy(pls.subject.uuid, plent->uuid, sizeof(pls.subject.uuid)); plp_copy = rpld_plp_init(NULL, &pls); rpld_pointer_set(POINTER_CURRENT, queue, -1, plp_copy); rpld_plp_unref(plp_copy); } } } rpld_plp_unref(plp); return 0; } static inline struct rpld_playlist_entry * __get_fallback(pli_t queue) { struct rpld_playlist_entry * plent; struct rpld_playlist_pointer * plp = NULL; int err; plp = rpld_pointer_get(POINTER_FALLBACK, queue, -1); if ( plp == NULL ) return NULL; plent = rpld_plp_search(plp); err = roar_error; rpld_plp_unref(plp); roar_err_set(err); return plent; } static inline void __go_back_in_time(pli_t queue, struct rpld_playlist * pl, struct rpld_playlist_entry ** plep, time_t now) { struct rpld_playlist_entry * ple = *plep; (void)pl; // keep everything that is up to 5 secs too early. if ( (ple->wallclock_start - 5) <= now ) return; // TODO: Implement a way to upmove the CURRENT Pointer. // This is a bit harder as we need to detect the inital point. // That is doable in case it was inited using the DEFAULT pointer. // But what about manually set pointer or other kind of pointer operations? // for now we ignore that case and skip to the next try. // if there is nothing else left we can still try the FALLBACK pointer before we keep the current title. ple = __get_fallback(queue); if ( ple != NULL ) { rpld_ple_free(*plep); *plep = ple; return; } // ok, nothing left. We just return and keep the current one. } int autoqueue(pli_t queue) { struct rpld_playlist * pl = rpld_pl_get_by_id(queue); struct rpld_playlist_entry * ple = NULL; time_t now = RPLD_PLE_WALLCLOCK_INVALID; int ret = 0; int err; ROAR_DBG("autoqueue(void) = ?"); if ( pl == NULL ) { ROAR_DBG("autoqueue(void) = -1"); return -1; } while (ret == 0 && ple == NULL) { ret = __autoqueue(queue, pl); err = roar_error; if ( pl != NULL ) ple = rpld_pl_pop(pl); if ( ple == NULL ) { err = roar_error; ret = -1; } else if ( ple->wallclock_start == RPLD_PLE_WALLCLOCK_INVALID ) { break; } else { if ( now == RPLD_PLE_WALLCLOCK_INVALID ) now = time(NULL); if ( ((ple->wallclock_start + ple->length) < now) && !(ple->flags & RPLD_PLE_FLAG_UNSKIPABLE) ) { rpld_ple_free(ple); ple = NULL; continue; } else if ( ple->wallclock_start > now ) { __go_back_in_time(queue, pl, &ple, now); } else { break; } } } if ( ple != NULL ) rpld_pl_push(pl, ple); rpld_pl_unref(pl); roar_err_set(err); return ret; } //ll rpld-0.1.9/autoqueue.h0000644000175000017500000000175312266574301013006 0ustar phiphi//autoqueue.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_AUTOQUEUE_H_ #define _RPLD_AUTOQUEUE_H_ int autoqueue(pli_t queue); #endif //ll rpld-0.1.9/backend.c0000644000175000017500000001130512266574301012345 0ustar phiphi//backend.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2012-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" static struct roar_kstore * backend_store = NULL; static int global_codecbl[PLAYBACK_MAX_CODECBL]; int backend_init(void) { size_t i; if ( backend_store != NULL ) return 0; for (i = 0; i < PLAYBACK_MAX_CODECBL; i++) { global_codecbl[i] = -1; } backend_store = roar_kstore_new(-1, (int(*)(void*))backend_ref, (int(*)(void*))backend_unref, NULL); if ( backend_store == NULL ) return -1; return 0; } int backend_free(void) { if ( roar_kstore_unref(backend_store) == -1 ) return -1; backend_store = NULL; return 0; } struct rpld_backend * backend_get_connection(const char * name) { return backend_get_connection2(name, 0); } struct rpld_backend * backend_get_connection2(const char * name, int allow_stub) { struct rpld_backend * ret = NULL; const char * server; size_t i; int err; if ( name == NULL ) name = BACKEND_DEFAULT_NAME; if ( backend_store != NULL ) { ret = roar_kstore_get(backend_store, name); if ( ret != NULL ) return ret; } ret = roar_mm_malloc(sizeof(struct rpld_backend)); if ( ret == NULL ) return NULL; memset(ret, 0, sizeof(struct rpld_backend)); ret->refc = 1; ret->flags = 0; for (i = 0; i < PLAYBACK_MAX_CODECBL; i++) { ret->codecbl[i] = -1; } if ( !strcmp(name, BACKEND_DEFAULT_NAME) ) { server = NULL; } else { server = name; } if ( roar_simple_connect(&(ret->con), server, APPLICATION_NAME) == -1 ) { if ( allow_stub ) { roar_connect_none(&(ret->con)); } else { err = roar_error; roar_mm_free(ret); roar_error = err; return NULL; } } else { ret->flags |= BACKEND_FLAG_CONNECTED; } if ( backend_store != NULL ) { ROAR_DBG("backend_get_connection2(name=?, allow_stub=%i): name='%s'", allow_stub, name); if ( roar_kstore_add(backend_store, ret, name) == -1 ) { err = roar_error; if ( ret->flags & BACKEND_FLAG_CONNECTED ) roar_disconnect(&(ret->con)); roar_mm_free(ret); roar_error = err; return NULL; } } return ret; } int backend_ref(struct rpld_backend * backend) { if ( backend == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } backend->refc++; return 0; } int backend_unref(struct rpld_backend * backend) { if ( backend == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } backend->refc--; if ( backend->refc ) return 0; if ( backend->flags & BACKEND_FLAG_CONNECTED ) roar_disconnect(&(backend->con)); roar_mm_free(backend); return 0; } const char * backend_get_name(struct rpld_backend * backend) { const char * ret; if ( backend == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return NULL; } if ( !(backend->flags & BACKEND_FLAG_CONNECTED) ) return roar_kstore_name(backend_store, backend); ret = roar_get_connection_server(&(backend->con)); if ( ret == NULL ) return BACKEND_DEFAULT_NAME; return ret; } int backend_blacklist_codec(struct rpld_backend * backend, int codec) { int i; if ( backend == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } for (i = 0; i < PLAYBACK_MAX_CODECBL; i++) { if ( backend->codecbl[i] == -1 ) { backend->codecbl[i] = codec; return 0; } } roar_err_set(ROAR_ERROR_NOSPC); return -1; } int backend_blacklist_codec_global(int codec) { int i; for (i = 0; i < PLAYBACK_MAX_CODECBL; i++) { if ( global_codecbl[i] == -1 ) { global_codecbl[i] = codec; return 0; } } roar_err_set(ROAR_ERROR_NOSPC); return -1; } int backend_blacklist_check_codec(struct rpld_backend * backend, int codec) { int i; if ( backend == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } if ( codec == -1 ) { roar_err_set(ROAR_ERROR_INVAL); return 1; } for (i = 0; i < PLAYBACK_MAX_CODECBL; i++) { if ( global_codecbl[i] == codec ) { return 1; } } for (i = 0; i < PLAYBACK_MAX_CODECBL; i++) { if ( backend->codecbl[i] == codec ) { return 1; } } return 0; } //ll rpld-0.1.9/backend.h0000644000175000017500000000347112266574301012357 0ustar phiphi//backend.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2012-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_BACKEND_H_ #define _RPLD_BACKEND_H_ #define PLAYBACK_MAX_CODECBL 16 #define BACKEND_DEFAULT_NAME "+default" #define BACKEND_FLAG_NONE 0x0000 #define BACKEND_FLAG_CONNECTED 0x0001 struct rpld_backend { size_t refc; int flags; struct roar_connection con; int codecbl[PLAYBACK_MAX_CODECBL]; }; int backend_init(void); int backend_free(void); struct rpld_backend * backend_get_connection(const char * name); struct rpld_backend * backend_get_connection2(const char * name, int allow_stub); int backend_ref(struct rpld_backend * backend); int backend_unref(struct rpld_backend * backend); const char * backend_get_name(struct rpld_backend * backend); int backend_blacklist_codec(struct rpld_backend * backend, int codec); int backend_blacklist_codec_global(int codec); int backend_blacklist_check_codec(struct rpld_backend * backend, int codec); #endif //ll rpld-0.1.9/client.c0000644000175000017500000003340112266574302012236 0ustar phiphi//client.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" static const struct roar_dl_proto __proto_rpld = { .proto = ROAR_PROTO_RPLD, .description = "RPLD Simple", .flags = ROAR_DL_PROTO_FLAGS_NONE, .set_proto = NULL, .unset_proto = NULL, .handle = proto_simple_client_handle, .flush = NULL, .flushed = NULL, .status = NULL }; static const struct roar_dl_proto __proto_mpd = { .proto = ROAR_PROTO_MPD, .description = "MPD", .flags = ROAR_DL_PROTO_FLAGS_NONE, .set_proto = proto_mpd_client_set_proto, .unset_proto = NULL, .handle = proto_mpd_client_handle, .flush = NULL, .flushed = NULL, .status = NULL }; static struct rpld_proto g_proto[RPLD_PROTOS_MAX]; static struct rpld_client { enum rpld_client_state state; pli_t playlist; pli_t queue; // which playlist is the main queue for this client? struct rpld_playlist_pointer * tmpptr; struct roar_vio_calls con; enum rpld_client_acclev acclev; char * name; // for proto functions. const struct rpld_proto * proto; struct roar_buffer * obuffer; void * userdata; } g_clients[RPLD_CLIENTS_MAX]; static int plugin_callback(enum roar_dl_fnreg_action action, int fn, int subtype, const void * object, size_t objectlen, int version, int options, void * userdata, struct roar_dl_lhandle * lhandle) { const struct roar_dl_proto * impl = object; size_t i, j; (void)fn, (void)subtype, (void)version, (void)options, (void)userdata; ROAR_DBG("plugin_callback(action=%i, fn=%i, subtype=%i, object=%p, objectlen=%lu, version=%i, options=%i, userdata=%p, lhandle=%p) = ?", (int)action, fn, subtype, object, (long unsigned int)objectlen, version, options, userdata, lhandle); if ( objectlen != ROAR_DL_PROTO_SIZE ) { ROAR_WARN("plugin_callback(*): Library %p tries to register protocol with bad object length.", lhandle); roar_err_set(ROAR_ERROR_BADLIB); return -1; } switch (action) { case ROAR_DL_FNREG: for (i = 0; i < RPLD_PROTOS_MAX; i++) { if ( g_proto[i].impl == NULL ) { ROAR_DBG("plugin_callback(*): Registering as protocol number %u", (unsigned int)i); memset(&(g_proto[i]), 0, sizeof(g_proto[i])); g_proto[i].para = NULL; g_proto[i].paralen = -1; g_proto[i].pluginpara = NULL; g_proto[i].lhandle = lhandle; g_proto[i].impl = impl; ROAR_DBG("plugin_callback(action=%i, fn=%i, subtype=%i, object=%p, objectlen=%lu, version=%i, options=%i, userdata=%p, lhandle=%p) = 0", (int)action, fn, subtype, object, (long unsigned int)objectlen, version, options, userdata, lhandle); return 0; } } break; case ROAR_DL_FNUNREG: for (i = 0; i < RPLD_PROTOS_MAX; i++) { if ( g_proto[i].impl != NULL && g_proto[i].lhandle == lhandle ) { for (j = 0; j < RPLD_CLIENTS_MAX; j++) { if ( g_clients[j].state != CSTATE_UNUSED && g_clients[j].proto == &(g_proto[i]) ) { client_delete(j); } } g_proto[i].impl = NULL; } } return 0; break; } roar_err_set(ROAR_ERROR_NOSPC); return -1; } static const struct roar_dl_fnreg __fnreg_proto = { .fn = ROAR_DL_FN_PROTO, .subtype = ROAR_DL_PROTO_SUBTYPE, .version = ROAR_DL_PROTO_VERSION, .callback = plugin_callback, .userdata = NULL }; static inline int __proto_run(int id, int (*func)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara)) { const struct rpld_proto * proto = g_clients[id].proto; int ret; if ( func == NULL ) { roar_err_set(ROAR_ERROR_NOSYS); return -1; } if ( proto->lhandle != NULL ) roar_dl_context_restore(proto->lhandle); ret = func(id, &(g_clients[id].con), &(g_clients[id].obuffer), &(g_clients[id].userdata), g_clients[id].proto->para, g_clients[id].proto->paralen, g_clients[id].proto->pluginpara); if ( proto->lhandle != NULL ) roar_dl_context_store(proto->lhandle); return ret; } #define PROTO_RUN(id,func) __proto_run((id), (g_clients[(id)].proto == NULL || \ g_clients[(id)].proto->impl->func == NULL) ? \ NULL : g_clients[(id)].proto->impl->func) void client_init(void) { size_t i; memset(g_clients, 0, sizeof(g_clients)); for (i = 0; i < RPLD_PROTOS_MAX; i++) g_proto[i].impl = NULL; for (i = 0; i < RPLD_CLIENTS_MAX; i++) g_clients[i].state = CSTATE_UNUSED; ROAR_DL_RFNREG(ROAR_DL_HANDLE_APPLICATION, __fnreg_proto); roar_dl_register_fn(ROAR_DL_HANDLE_APPLICATION, ROAR_DL_FN_PROTO, ROAR_DL_PROTO_SUBTYPE, &__proto_rpld, sizeof(__proto_rpld), ROAR_DL_PROTO_VERSION, ROAR_DL_FNREG_OPT_NONE); roar_dl_register_fn(ROAR_DL_HANDLE_APPLICATION, ROAR_DL_FN_PROTO, ROAR_DL_PROTO_SUBTYPE, &__proto_mpd, sizeof(__proto_mpd), ROAR_DL_PROTO_VERSION, ROAR_DL_FNREG_OPT_NONE); } int client_new(struct roar_vio_calls ** vio) { int i; if ( vio == NULL ) return -1; for (i = 0; i < RPLD_CLIENTS_MAX; i++) { if ( g_clients[i].state == CSTATE_UNUSED ) { g_clients[i].state = CSTATE_USED; g_clients[i].playlist = 0; /* 0=main queue */ g_clients[i].queue = 0; /* 0=main queue */ g_clients[i].tmpptr = NULL; g_clients[i].acclev = ACCLEV_ALL; // currently all clients have fill access rights g_clients[i].name = NULL; g_clients[i].proto = NULL; g_clients[i].userdata = NULL; g_clients[i].obuffer = NULL; roar_vio_clear_calls(&(g_clients[i].con)); *vio = &(g_clients[i].con); client_set_proto(i, ROAR_PROTO_RPLD); return i; } } return -1; } int client_delete(int id) { if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return -1; if ( g_clients[id].state == CSTATE_UNUSED ) return 0; g_clients[id].state = CSTATE_UNUSED; PROTO_RUN(id, unset_proto); if ( g_clients[id].userdata != NULL ) { roar_mm_free(g_clients[id].userdata); g_clients[id].userdata = NULL; } if ( g_clients[id].name != NULL ) roar_mm_free(g_clients[id].name); g_clients[id].proto = NULL; if ( g_clients[id].tmpptr != NULL ) { rpld_plp_unref(g_clients[id].tmpptr); g_clients[id].tmpptr = NULL; } roar_vio_close(&(g_clients[id].con)); return 0; } int client_get_proto(int id) { if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return RPLD_PROTO_UNUSED; if ( g_clients[id].state == CSTATE_UNUSED ) return RPLD_PROTO_UNUSED; if ( g_clients[id].proto == NULL ) return RPLD_PROTO_UNUSED; return g_clients[id].proto->impl->proto; } int client_set_proto(int id, int proto) { const struct rpld_proto * newproto = NULL; size_t i; int ret = 0; if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return -1; if ( g_clients[id].state != CSTATE_USED ) return -1; for (i = 0; i < (sizeof(g_proto)/sizeof(*g_proto)); i++) { if ( g_proto[i].impl != NULL && g_proto[i].impl->proto == proto ) { newproto = &(g_proto[i]); break; } } if ( newproto == NULL ) return -1; PROTO_RUN(id, unset_proto); if ( g_clients[id].userdata != NULL ) { roar_mm_free(g_clients[id].userdata); g_clients[id].userdata = NULL; } g_clients[id].proto = newproto; if ( newproto->impl->set_proto != NULL ) ret = PROTO_RUN(id, set_proto); return ret; } struct roar_vio_calls * client_get_vio(int id) { if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return NULL; if ( g_clients[id].state == CSTATE_UNUSED ) return NULL; return &(g_clients[id].con); } enum rpld_client_acclev client_get_acclev(int id) { if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return ACCLEV_ERR; return g_clients[id].acclev; } int client_set_acclev(int id, enum rpld_client_acclev acclev, int setter) { if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return -1; if ( setter != -1 ) { if ( setter != id ) if ( setter < 0 || setter >= RPLD_CLIENTS_MAX ) return -1; if ( acclev > g_clients[setter].acclev ) return -1; } g_clients[id].acclev = acclev; return 0; } int client_inc_acclev(int id, int inc, int setter) { int newlev; enum rpld_client_acclev acclev; if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return -1; if ( setter != id ) if ( setter < 0 || setter >= RPLD_CLIENTS_MAX ) return -1; newlev = (int)g_clients[id].acclev + inc; if ( newlev < 0 ) { acclev = ACCLEV_NONE; } else { acclev = newlev; } if ( acclev > g_clients[setter].acclev ) return -1; g_clients[id].acclev = acclev; return 0; } int client_set_name(int id, const char * name) { if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return -1; if ( name != NULL && name[0] == 0 ) name = NULL; if ( g_clients[id].name != NULL ) roar_mm_free(g_clients[id].name); if ( name == NULL ) { g_clients[id].name = NULL; } else { g_clients[id].name = roar_mm_strdup(name); } return 0; } const char * client_get_name(int id) { if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return NULL; return g_clients[id].name; } int client_set_playlist(int id, pli_t pl) { if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return -1; g_clients[id].playlist = pl; return 0; } pli_t client_get_playlist(int id) { if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return -1; return g_clients[id].playlist; } int client_set_queue(int id, pli_t pl) { if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return -1; // TODO: check if the playlist is a queue. g_clients[id].queue = pl; return 0; } pli_t client_get_queue(int id) { if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return -1; return g_clients[id].queue; } int client_set_pointer(int id, int pointer, struct rpld_playlist_pointer * plp) { if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return -1; if ( pointer != POINTER_TEMP ) { roar_err_set(ROAR_ERROR_INVAL); return -1; } if ( g_clients[id].tmpptr != NULL ) rpld_plp_unref(g_clients[id].tmpptr); g_clients[id].tmpptr = plp; if ( g_clients[id].tmpptr != NULL ) rpld_plp_ref(g_clients[id].tmpptr); return 0; } struct rpld_playlist_pointer * client_get_pointer(int id, int pointer) { struct rpld_playlist_pointer * ret; if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return NULL; if ( pointer != POINTER_TEMP ) { roar_err_set(ROAR_ERROR_INVAL); return NULL; } ret = g_clients[id].tmpptr; if ( ret == NULL ) { roar_err_set(ROAR_ERROR_NOENT); } else { rpld_plp_ref(ret); } return ret; } static void __flush_client(int id, struct roar_vio_calls * vio, struct roar_buffer ** buffer) { size_t len; ssize_t ret; void * buf; if ( roar_buffer_get_datalen(*buffer, &buf, &len) == -1 ) return; ret = roar_vio_write(vio, buf, len); if ( ret < 1 ) { client_delete(id); return; } if ( ret == (ssize_t)len ) { if ( roar_buffer_next(buffer) == -1 ) { client_delete(id); return; } } else { if ( roar_buffer_set_offset(*buffer, ret) == -1 ) { client_delete(id); return; } } roar_err_set(ROAR_ERROR_NONE); } int client_handle(int id, int eventsa) { int ret = 0; ROAR_DBG("client_handle(id=%i, eventsa=%i) = ?", id, eventsa); if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return -1; if ( g_clients[id].state == CSTATE_UNUSED ) return -1; roar_err_set(ROAR_ERROR_NONE); if ( eventsa & ROAR_VIO_SELECT_READ ) { ret = PROTO_RUN(id, handle); } if ( eventsa & ROAR_VIO_SELECT_WRITE ) { if ( g_clients[id].proto->impl->flush != NULL ) { PROTO_RUN(id, flush); } else { __flush_client(id, &(g_clients[id].con), &(g_clients[id].obuffer)); } if ( g_clients[id].obuffer == NULL && g_clients[id].proto->impl->flushed != NULL ) { PROTO_RUN(id, flushed); } } ROAR_DBG("client_handle(id=%i, eventsa=%i) = %i", id, eventsa, ret); return ret; } int client_get_eventsq(int id) { int ret = ROAR_VIO_SELECT_READ; if ( id < 0 || id >= RPLD_CLIENTS_MAX ) return ROAR_VIO_SELECT_NO_RETEST; if ( g_clients[id].state == CSTATE_UNUSED ) return ROAR_VIO_SELECT_NO_RETEST; if ( g_clients[id].obuffer != NULL ) ret |= ROAR_VIO_SELECT_WRITE; return ret; } int client_str2proto(const char * str) { if ( str == NULL || *str == 0 ) return -1; if ( !strcasecmp(str, "simple") ) return ROAR_PROTO_RPLD; if ( !strcasecmp(str, "rpld") ) return ROAR_PROTO_RPLD; if ( !strcasecmp(str, "mpd") ) return ROAR_PROTO_MPD; return roar_str2proto(str); } const char * client_proto2str(const int proto) { switch (proto) { case RPLD_PROTO_UNUSED: return "(unused client)"; break; case ROAR_PROTO_RPLD: return "rpld"; break; case ROAR_PROTO_MPD: return "mpd"; break; default: return roar_proto2str(proto); break; } } int client_str2acclev(const char * str) { if ( !strcasecmp(str, "none") ) return ACCLEV_NONE; if ( !strcasecmp(str, "conctl") ) return ACCLEV_CONCTL; if ( !strcasecmp(str, "guest") ) return ACCLEV_GUEST; if ( !strcasecmp(str, "user") ) return ACCLEV_USER; if ( !strcasecmp(str, "all") ) return ACCLEV_ALL; return -1; } const char * client_acclev2str(enum rpld_client_acclev acclev) { switch (acclev) { case ACCLEV_ERR: return "(error)"; break; case ACCLEV_NONE: return "none"; break; case ACCLEV_CONCTL: return "conctl"; break; case ACCLEV_GUEST: return "guest"; break; case ACCLEV_USER: return "user"; break; case ACCLEV_ALL: return "all"; break; default: return "(unknown acclev)"; break; } } //ll rpld-0.1.9/client.h0000644000175000017500000000537012266574302012247 0ustar phiphi//client.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_CLIENT_H_ #define _RPLD_CLIENT_H_ #define RPLD_PROTO_UNUSED ROAR_PROTO_NONE #define RPLD_PROTOS_MAX 8 #define RPLD_CLIENTS_MAX 8 // access level: enum rpld_client_acclev { ACCLEV_ERR = -1, ACCLEV_NONE = 0, // no right to do anything ACCLEV_CONCTL, // only allowed to do basic connection things: noop, quit, auth... ACCLEV_GUEST, // guest connection (read only) ACCLEV_USER, // normal user connect (read write) ACCLEV_ALL // full (admin) access (read write ctl) }; enum rpld_client_state { CSTATE_ERROR = -1, CSTATE_UNUSED = 0, CSTATE_USED = 1 }; struct rpld_proto { const struct roar_keyval * para; ssize_t paralen; struct roar_dl_librarypara * pluginpara; struct roar_dl_lhandle * lhandle; const struct roar_dl_proto * impl; }; void client_init(void); int client_new(struct roar_vio_calls ** vio); int client_delete(int id); int client_set_proto(int id, int proto); int client_get_proto(int id); struct roar_vio_calls * client_get_vio(int id); enum rpld_client_acclev client_get_acclev(int id); int client_set_acclev(int id, enum rpld_client_acclev acclev, int setter); int client_inc_acclev(int id, int inc, int setter); int client_set_name(int id, const char * name); const char * client_get_name(int id); int client_set_playlist(int id, pli_t pl); pli_t client_get_playlist(int id); int client_set_queue(int id, pli_t pl); pli_t client_get_queue(int id); int client_set_pointer(int id, int pointer, struct rpld_playlist_pointer * plp); struct rpld_playlist_pointer * client_get_pointer(int id, int pointer); int client_handle(int id, int eventsa); int client_get_eventsq(int id); int client_str2proto(const char * str); const char * client_proto2str(const int proto); int client_str2acclev(const char * str); const char * client_acclev2str(enum rpld_client_acclev acclev); #endif //ll rpld-0.1.9/configure0000755000175000017500000000675712245102653012532 0ustar phiphi#!/bin/sh # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012 # # This file is part of roard a part of RoarAudio, # a cross-platform sound system for both, home and professional use. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. # This code sets up $ROAR_BUILDSYSTEM_DIR if [ "$1" = '--buildsystem' ] then ROAR_BUILDSYSTEM_DIR="$2" shift 2 fi if [ "$ROAR_BUILDSYSTEM_DIR" = '' ] then for dir in `roar-config --path prefix-buildsystem 2> /dev/null` \ /usr/lib/roaraudio/build-system/ \ /usr/local/lib/roaraudio/build-system/ do if [ -d "$dir" ] then ROAR_BUILDSYSTEM_DIR="$dir" break fi done fi if [ "$ROAR_BUILDSYSTEM_DIR" = '' ] then echo 'Can not find build system. Try --buildsystem /path/to/build-system/' >&2 exit 1 fi # now we include the build system. . "$ROAR_BUILDSYSTEM_DIR/configure.all" # the real configure starts here: # Bad libxml-2.0 hack: CFLAGS="$CFLAGS -I/usr/include/libxml2" test_libroar '1.0.11' || exit 1 test_pkgversion test_buildstamp test_cc test_ranlib test_pkgconfig test_sysname while [ "$1" != '' ] do parse_option "$@" shift $SHIFT_COUNT $HANDLED && continue; case "$1" in '--help') write_help echo 'OPTIONS:' exit 0; ;; *) echo "Error: unknown option: $1" >&2; echo "Try: $0 --help" >&2; exit 1; ;; esac; shift; done open_configure_files update_target test_crosscompile update_prefixes update_ccft update_cc test_wextra write_header _CONFIG_H_ test_bin_format test_linkdeps test_cp_v echo -n 'checking for user id of root/superuser... ' if [ "$ROOT_UID" = '(none)' ] then echo "none (disabled by user)" elif [ "$ROOT_UID" = '' ] then ROOT_USER='root' ROOT_UID=`id -u $ROOT_USER` if [ "$ROOT_UID" = '' ] then echo "none (please report this)" else echo "$ROOT_UID($ROOT_USER)" echo "ROOT_UID=$ROOT_UID" >&4 fi else echo "$ROOT_UID" echo "ROOT_UID=$ROOT_UID" >&4 fi test_func_defmake HAVE_FUNC_UALARM ualarm 'ualarm(0, 0)' -- unistd.h test_func_defmake HAVE_FUNC_SIGINTERRUPT siginterrupt 'siginterrupt(0, 0)' -- signal.h test_lib_defmake HAVE_H_STDINT % stdint.h c -- stdint.h test_lib_defmake HAVE_LIB_WSOCK32 % WinSockP0 wsock32 -- winsock2.h test_lib_defmake HAVE_LIB_WS2_32 % WinSockP1 ws2_32 -- winsock2.h test_lib_defmake HAVE_LIB_SLP % OpenSLP slp -- slp.h test_lib_defmake HAVE_LIB_XML2 % libxml-2 xml2 -- libxml/tree.h libxml/parser.h libxml/xmlreader.h libxml/xpath.h libxml/xpathInternals.h libxml/uri.h test_lib_defmake HAVE_LIB_ROAR % RoarAudio roar -- roaraudio.h if [ "$?" != '0' ] then echo "Error: can not find libroar" >&2 exit 1 fi write_vars_configh_literal ROOT_UID write_vars_configh_string VERSION BUILD_STAMP DISTRIBUTION_VERSION_STRING cleanup_ccft write_footer #ll rpld-0.1.9/ff_m3u.c0000644000175000017500000000533012266574302012137 0ustar phiphi//ff_m3u.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" int ff_m3u_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { const char * artist; struct rpld_playlist_entry * cur = rpld_pl_get_first(pl); (void)handle; roar_vio_printf(vio, "#EXTM3U\n"); while ( cur != NULL ) { artist = cur->meta.artist; if ( *artist == 0 ) artist = cur->meta.performer; roar_vio_printf(vio, "#EXTINF:%lu,%s - %s\n", (unsigned long)cur->length, artist, cur->meta.title); roar_vio_printf(vio, "%s\n", rpld_ple_get_filename(cur, -1, NULL)); cur = cur->list.next; } return 0; } int ff_m3u_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { struct rpld_playlist_entry * plent = NULL; char buf[1024]; char * s, * delm; size_t len; (void)handle; while ((s = roar_vio_fgets(vio, buf, 1024)) != NULL ) { len = strlen(s); for (s += len - 1; *s == '\r' || *s == '\n'; s--) *s = 0; if ( !*buf ) continue; if ( plent == NULL ) if ( (plent = rpld_ple_new()) == NULL ) return -1; if ( buf[0] == '#' ) { if ( !strcmp(buf, "#EXTM3U") ) continue; if ( !strncmp(buf, "#EXTINF:", 8) ) { s = strstr(buf+8, ","); if ( s != NULL ) { *s = 0; s++; } if ( !strcmp(buf+8, "-1") ) { plent->length = 0; } else { plent->length = atol(buf+8); } if ( (delm = strstr(s, " - ")) == NULL ) { strncpy(plent->meta.title, s, sizeof(plent->meta.title)); } else { *delm = 0; delm += 3; strncpy(plent->meta.artist, s, sizeof(plent->meta.artist)); strncpy(plent->meta.title, delm, sizeof(plent->meta.title)); } } continue; } rpld_ple_push_filename(plent, buf, RPLD_TYPE_UNKNOWN, 1); rpld_pl_push(pl, plent); plent = NULL; } if ( plent != NULL ) rpld_ple_free(plent); return 0; } //ll rpld-0.1.9/ff_plain.c0000644000175000017500000000401412266574302012534 0ustar phiphi//ff_plain.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" int ff_plain_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { struct rpld_playlist_entry * cur = rpld_pl_get_first(pl); const char * file; (void)handle; while ( cur != NULL ) { file = rpld_ple_get_filename(cur, -1, NULL); if ( file ) roar_vio_printf(vio, "%s\n", file); cur = cur->list.next; } return 0; } int ff_plain_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { struct rpld_playlist_entry * plent; char buf[1024]; char * s; size_t len; (void)handle; ROAR_DBG("ff_plain_pl_import(handle=%p, vio=%p, pl=%p) = ?", handle, vio, pl); while ((s = roar_vio_fgets(vio, buf, 1024)) != NULL ) { len = strlen(s); for (s += len - 1; *s == '\r' || *s == '\n'; s--) *s = 0; if ( !*buf ) continue; ROAR_DBG("ff_plain_pl_import(*): s='%s'", buf); if ( (plent = rpld_ple_new()) == NULL ) return -1; rpld_ple_push_filename(plent, buf, RPLD_TYPE_UNKNOWN, 1); rpld_pl_push(pl, plent); } ROAR_DBG("ff_plain_pl_import(handle=%p, vio=%p, pl=%p) = 0", handle, vio, pl); return 0; } //ll rpld-0.1.9/ff_pls.c0000644000175000017500000000355512266574303012241 0ustar phiphi//ff_pls.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" int ff_pls_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { struct rpld_playlist_entry * cur = rpld_pl_get_first(pl); size_t num = rpld_pl_num(pl); unsigned long counter = 1; (void)handle; roar_vio_printf(vio, "[playlist]\n"); roar_vio_printf(vio, "NumberOfEntries=%lu\n", (unsigned long)num); while ( cur != NULL ) { // roar_vio_printf(vio, "#EXTINF:%i,%s - %s\n", cur->length, cur->meta.artist, cur->meta.title); roar_vio_printf(vio, "File%lu=%s\n", counter, rpld_ple_get_filename(cur, -1, NULL)); if ( cur->meta.title[0] ) roar_vio_printf(vio, "Title%lu=%s\n", counter, cur->meta.title); if ( cur->length ) roar_vio_printf(vio, "Length%lu=%lu\n", counter, (unsigned long)cur->length); counter++; cur = cur->list.next; } roar_vio_printf(vio, "Version=2\n"); return 0; } int ff_pls_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); //ll rpld-0.1.9/ff_rpld.c0000644000175000017500000001223712266574303012401 0ustar phiphi//ff_rpld.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" static char *_strtok(char *str, const char *delim) { static char * next = NULL; if ( str == NULL ) str = next; if ( str == NULL ) return NULL; next = strstr(str, delim); if ( next != NULL ) { *next = 0; next++; } return str; } int ff_rpld_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { struct rpld_playlist_entry * plent = rpld_pl_get_first(pl); char uuid[37]; (void)handle; roar_uuid2str(uuid, plent->uuid, sizeof(uuid)); while ( plent != NULL ) { roar_vio_printf(vio, "%s=%s=%s=%s=%s=%s=%s=%s=long:0x%.16" __ll "X/short:0x%.8lX/uuid:%s=0x%.8lx/%i=%s(0x%x)=%f\n", roar_codec2str(plent->codec), rpld_ple_time_hr(plent), plent->meta.album, plent->meta.title, plent->meta.artist, plent->meta.performer, plent->meta.version, rpld_ple_get_filename(plent, -1, NULL), (__longlong unsigned int)plent->global_tracknum, (long unsigned int)plent->global_short_tracknum, uuid, (long unsigned int)plent->meta.discid, plent->meta.tracknum, roar_meta_strgenre(plent->meta.genre), plent->meta.genre, (double)plent->likeness ); plent = plent->list.next; } return 0; } int ff_rpld_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { struct rpld_playlist_entry * plent_new; char buf[1024]; char * s, * curtok; size_t len; (void)handle; while ((s = roar_vio_fgets(vio, buf, 1024)) != NULL ) { len = strlen(s); ROAR_DBG("ff_rpld_pl_import(*) = ?"); for (s += len - 1; *s == '\r' || *s == '\n'; s--) *s = 0; if ( !*buf ) continue; if ( (plent_new = rpld_ple_new()) == NULL ) return -1; ROAR_DBG("ff_rpld_pl_import(*) = ?"); // TYPE aka CODEC: if ( (curtok = _strtok(buf, "=")) == NULL ) { rpld_ple_free(plent_new); return -1; } plent_new->codec = roar_str2codec(curtok); ROAR_DBG("ff_rpld_pl_import(*) = ?"); // LENGTH, we ignore this if ( (curtok = _strtok(NULL, "=")) == NULL ) { rpld_ple_free(plent_new); return -1; } if ( strstr(curtok, ":") == NULL ) { // parse SS plent_new->length = atol(curtok); } else { // parse HH:MM:SS rpld_ple_set_time_hr(plent_new, curtok); } ROAR_DBG("ff_rpld_pl_import(*) = ?"); // ALBUM if ( (curtok = _strtok(NULL, "=")) == NULL ) { rpld_ple_free(plent_new); return -1; } strncpy(plent_new->meta.album, curtok, sizeof(plent_new->meta.album)); plent_new->meta.album[sizeof(plent_new->meta.album)-1] = 0; ROAR_DBG("ff_rpld_pl_import(*) = ?"); // TITLE if ( (curtok = _strtok(NULL, "=")) == NULL ) { rpld_ple_free(plent_new); return -1; } strncpy(plent_new->meta.title, curtok, sizeof(plent_new->meta.title)); plent_new->meta.title[sizeof(plent_new->meta.title)-1] = 0; ROAR_DBG("ff_rpld_pl_import(*) = ?"); // ARTIST if ( (curtok = _strtok(NULL, "=")) == NULL ) { rpld_ple_free(plent_new); return -1; } strncpy(plent_new->meta.artist, curtok, sizeof(plent_new->meta.artist)); plent_new->meta.artist[sizeof(plent_new->meta.artist)-1] = 0; ROAR_DBG("ff_rpld_pl_import(*) = ?"); // PERFORMER if ( (curtok = _strtok(NULL, "=")) == NULL ) { rpld_ple_free(plent_new); return -1; } strncpy(plent_new->meta.performer, curtok, sizeof(plent_new->meta.performer)); plent_new->meta.performer[sizeof(plent_new->meta.performer)-1] = 0; ROAR_DBG("ff_rpld_pl_import(*) = ?"); // VERSION if ( (curtok = _strtok(NULL, "=")) == NULL ) { rpld_ple_free(plent_new); return -1; } strncpy(plent_new->meta.version, curtok, sizeof(plent_new->meta.version)); plent_new->meta.version[sizeof(plent_new->meta.version)-1] = 0; ROAR_DBG("ff_rpld_pl_import(*) = ?"); // FILE if ( (curtok = _strtok(NULL, "=")) == NULL ) { rpld_ple_free(plent_new); return -1; } rpld_ple_push_filename(plent_new, curtok, RPLD_TYPE_UNKNOWN, 1); ROAR_DBG("ff_rpld_pl_import(*) = ?"); rpld_pl_push(pl, plent_new); } return 0; } //ll rpld-0.1.9/ff_uras.c0000644000175000017500000002630612266574304012415 0ustar phiphi//ff_xspf.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" #ifdef HAVE_LIB_XML2 #include #include #include #include #include #include #include static int ff_uras_write(void * context, const char * buffer, int len) { return roar_vio_write(context, (void*)buffer, len); } static int ff_uras_read (void * context, char * buffer, int len) { ssize_t ret = roar_vio_read(context, buffer, len); ROAR_DBG("ff_uras_read(context=%p, buffer=%p, len=%i) = %i(?)", context, buffer, len, (int)ret); return ret; } static xmlNodePtr new_text_node(xmlNodePtr parent, const char * name, const char * value) { xmlNodePtr ret = xmlNewNode(NULL, (const xmlChar *)name); if ( ret == NULL ) return NULL; xmlAddChild(ret, xmlNewText((const xmlChar *)value)); xmlAddChild(parent, ret); return ret; } static inline xmlNodePtr new_pos_node(xmlNodePtr parent, const char * name, rpld_mus_t pos) { xmlNodePtr ret = xmlNewNode(NULL, (const xmlChar *)name); char buf[80]; if ( ret == NULL ) return NULL; if ( pos == -1 ) pos = 0; snprintf(buf, sizeof(buf), "%ld", (long int)pos/1000); xmlSetProp(ret, (xmlChar *)"pos", (const xmlChar *)buf); xmlAddChild(parent, ret); return ret; } int ff_uras_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { const struct roar_server_info * info = rpld_serverinfo_get(); struct rpld_playlist_entry * cur = rpld_pl_get_first(pl); char buf[RPLD_MAX_PLF_LEN+64]; xmlDocPtr doc; xmlNodePtr rootnode, track; xmlOutputBufferPtr output; ssize_t i; struct roar_keyval * extra; const char * file; (void)handle; output = xmlAllocOutputBuffer(NULL); if ( output == NULL ) return -1; output->context = vio; output->writecallback = ff_uras_write; output->closecallback = NULL; doc = xmlNewDoc((xmlChar *)"1.0"); if ( doc == NULL ) return -1; doc->charset = XML_CHAR_ENCODING_UTF8; doc->encoding = xmlStrdup((xmlChar *)"UTF-8"); rootnode = xmlNewNode(NULL, (xmlChar *)"playlist"); xmlSetProp(rootnode, (xmlChar *)"uribase", (xmlChar *)"/"); xmlDocSetRootElement(doc, rootnode); if ( rpld_pl_get_name(pl) != NULL ) { new_text_node(rootnode, "name", rpld_pl_get_name(pl)); } else { new_text_node(rootnode, "name", "default"); } new_text_node(rootnode, "location", info->location == NULL ? "default" : info->location); new_text_node(rootnode, "date", "default"); new_text_node(rootnode, "rgain", "ON"); new_text_node(rootnode, "resync", "ON"); while ( cur != NULL ) { track = xmlNewNode(NULL, (xmlChar *)"track"); file = rpld_ple_get_filename(cur, -1, NULL); if (file != NULL) { xmlSetProp(track, (xmlChar *)"uri", (const xmlChar *)file); } if (cur->meta.title[0] != 0) new_text_node(track, "name", cur->meta.title); if (cur->meta.tracknum) { snprintf(buf, sizeof(buf), "%d", (int)cur->meta.tracknum); new_text_node(track, "tracknum", buf); } switch (cur->meta.genre) { #ifdef ROAR_META_GENRE_META_OTHER case ROAR_META_GENRE_META_OTHER: new_text_node(track, "Type", "Nonsong"); break; #endif #ifdef ROAR_META_GENRE_META_COMMERCIAL case ROAR_META_GENRE_META_COMMERCIAL: new_text_node(track, "Type", "Comm"); break; #endif default: new_text_node(track, "Type", "Song"); break; } if (cur->length) { snprintf(buf, sizeof(buf), "%d", (int)cur->length); new_text_node(track, "duration", buf); } new_pos_node(track, "start", cur->start); new_pos_node(track, "end", cur->end); for (i = 0; i < cur->meta.extra.kvlen; i++) { extra = &(cur->meta.extra.kv[i]); if ( extra->key == NULL || extra->value == NULL ) continue; if ( !strcasecmp(extra->key, "X-URAS-START") ) { new_text_node(track, "start", extra->value); } else if ( !strcasecmp(extra->key, "X-URAS-MAPNUM") ) { new_text_node(track, "mapnum", extra->value); } } xmlAddChild(rootnode, track); cur = cur->list.next; } xmlSaveFormatFileTo(output, doc, "UTF-8", 1); xmlFreeDoc(doc); return 0; } static void ff_uras_pl_import_track(struct rpld_playlist * pl, xmlNode * track, const char * uribase, int rgain) { struct rpld_playlist_entry * plent = rpld_ple_new(); xmlNode * element; const char * name; const char * value; char * dst; size_t dst_len; int tmp; const char * start = NULL; const char * mapnum = NULL; char filenamebuffer[RPLD_MAX_PLF_LEN]; ROAR_DBG("ff_uras_pl_import_track(pl=%p, track=%p, uribase='%s') = ?", pl, track, uribase); if ( plent == NULL ) return; plent->rpg.mode = rgain ? ROAR_RPGMODE_TRACKALBUM : ROAR_RPGMODE_NONE; value = (const char * /* libxml2 cast-hell */) xmlGetProp(track, (xmlChar *)"uri"); snprintf(filenamebuffer, sizeof(filenamebuffer)-1, "%s/%s", uribase, value); rpld_ple_push_filename(plent, filenamebuffer, RPLD_TYPE_UNKNOWN, 1); // guess codec: // as per sepcs only ogg_vorbis and native flac is allowed. value = strrchr(value, '.'); if ( value != NULL ) { value++; if ( !strcasecmp(value, "ogg") ) { plent->codec = ROAR_CODEC_OGG_VORBIS; } else if ( !strcasecmp(value, "flac") ) { plent->codec = ROAR_CODEC_FLAC; } } for (element = track->children; element != NULL; element = element->next) { if ( element->type != XML_ELEMENT_NODE ) continue; dst = NULL; dst_len = 0; name = (const char * /* libxml2 cast-hell */) element->name; value = (const char * /* libxml2 cast-hell */) xmlNodeGetContent(element); ROAR_DBG("ff_uras_pl_import_track(pl=%p, track=%p, uribase='%s'): name='%s', value='%s'", pl, track, uribase, name, value); if (!strcmp(name, "tracknum")) { plent->meta.tracknum = atoi(value); } else if (!strcmp(name, "name")) { dst = plent->meta.title; dst_len = sizeof(plent->meta.title); } else if (!strcmp(name, "trackNum")) { if ( sscanf(value, "%d", &tmp) == 1 ) { plent->meta.tracknum = tmp; } } else if (!strcmp(name, "mapnum")) { mapnum = value; } else if (!strcmp(name, "duration")) { if ( sscanf(value, "%d", &tmp) == 1 ) { plent->length = tmp; } } else if (!strcmp(name, "start") && xmlGetProp(element, (const xmlChar *)"pos") == NULL ) { // this is the start time of the track in wallclock time. start = value; } else if (!strcmp(name, "start") && xmlGetProp(element, (const xmlChar *)"pos") != NULL ) { // this is the start time of the content within the track. value = (const char * /* libxml2 cast-hell */)xmlGetProp(element, (const xmlChar *)"pos"); if ( value == NULL ) { ROAR_WARN("ff_uras_pl_import_track(pl=%p, track=%p, uribase='%s'): No Prop \"pos\" in \"start\" tag: Bad. Playlist file is corruped.", pl, track, uribase); continue; } plent->start = 1000*atoi(value); if ( plent->start == 0 ) plent->start = -1; } else if (!strcmp(name, "end")) { value = (const char * /* libxml2 cast-hell */)xmlGetProp(element, (const xmlChar *)"pos"); if ( value == NULL ) { ROAR_WARN("ff_uras_pl_import_track(pl=%p, track=%p, uribase='%s'): No Prop \"pos\" in \"end\" tag: Bad. Playlist file is corruped.", pl, track, uribase); continue; } plent->end = 1000*atoi(value); if ( plent->end == 0 ) plent->end = -1; } else if (!strcmp(name, "Type")) { if ( 0 ) { /* noop to ensure correct syntax */ #ifdef ROAR_META_GENRE_META_MUSIC } else if ( !strcasecmp(value, "Song") ) { plent->meta.genre = ROAR_META_GENRE_META_MUSIC; #endif #ifdef ROAR_META_GENRE_META_OTHER } else if ( !strcasecmp(value, "Nonong") ) { plent->meta.genre = ROAR_META_GENRE_META_OTHER; #endif #ifdef ROAR_META_GENRE_META_COMMERCIAL } else if ( !strcasecmp(value, "Comm") ) { plent->meta.genre = ROAR_META_GENRE_META_COMMERCIAL; #endif } } if ( dst != NULL ) { ROAR_DBG("ff_uras_pl_import_track(pl=%p, track=%p): Copy '%s' to %p (element type: %s).", pl, track, value, dst, name); strncpy(dst, value, dst_len); dst[dst_len-1] = 0; } else { ROAR_DBG("ff_uras_pl_import_track(pl=%p, track=%p): no data to copy (element type: %s).", pl, track, name); } } // push in, do this now so we can do more easy error handling in the next block: rpld_pl_push(pl, plent); plent->meta.extra.kv = roar_mm_malloc(sizeof(struct roar_keyval)*2); if ( plent->meta.extra.kv == NULL ) return; plent->meta.extra.kvlen = 2; plent->meta.extra.kv[0].key = "X-URAS-START"; plent->meta.extra.kv[1].key = "X-URAS-MAPNUM"; if ( start == NULL ) start = ""; if ( mapnum == NULL ) mapnum = ""; plent->meta.extra.kv_storelen = roar_mm_strlen(start) + roar_mm_strlen(mapnum) + 2; plent->meta.extra.kv_store = roar_mm_malloc(plent->meta.extra.kv_storelen); if ( plent->meta.extra.kv_store == NULL ) { roar_mm_free(plent->meta.extra.kv); plent->meta.extra.kv = NULL; plent->meta.extra.kvlen = -1; return; } plent->meta.extra.kv[0].value = plent->meta.extra.kv_store; plent->meta.extra.kv[1].value = plent->meta.extra.kv_store + roar_mm_strlen(start) + 1; strcpy(plent->meta.extra.kv[0].value, start); strcpy(plent->meta.extra.kv[1].value, mapnum); } int ff_uras_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { xmlDoc * doc; xmlNode * main_element; xmlNode * playlist_element; const char * uribase = "/DUMMY/"; int rgain = 0; const xmlChar * value; (void)handle; doc = xmlReadIO(ff_uras_read, NULL, vio, "__dummy.xml", NULL, XML_PARSE_RECOVER); if ( doc == NULL ) return -1; for (main_element = doc->children; main_element != NULL; main_element = main_element->next) { if ( main_element->type != XML_ELEMENT_NODE ) continue; if ( !!xmlStrcmp(main_element->name, (xmlChar *)"playlist") ) continue; uribase = (const char * /* libxml2 cast-hell */) xmlGetProp(main_element, (xmlChar *)"uribase"); if ( uribase == NULL ) uribase = "/DUMMY/"; for (playlist_element = main_element->children; playlist_element != NULL; playlist_element = playlist_element->next) { if ( playlist_element->type != XML_ELEMENT_NODE ) continue; if ( !xmlStrcmp(playlist_element->name, (xmlChar *)"track") ) { ff_uras_pl_import_track(pl, playlist_element, uribase, rgain); } else if ( !xmlStrcmp(playlist_element->name, (xmlChar *)"rgain") ) { value = xmlNodeGetContent(playlist_element); if ( value == NULL ) continue; rgain = !xmlStrcmp(value, (xmlChar *)"ON") ? 1 : 0; // } else if ( !xmlStrcmp(playlist_element->name, (xmlChar *)"resync") ) { } } } xmlFreeDoc(doc); return 0; } #endif //ll rpld-0.1.9/ff_vclt.c0000644000175000017500000001643312266574304012413 0ustar phiphi//ff_vclt.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" int ff_vclt_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { struct rpld_playlist_entry * cur = rpld_pl_get_first(pl); ssize_t i; char uuid[37]; const char * filename; const char * key; enum rpld_filename_type filenametype; ssize_t num; (void)handle; while ( cur != NULL ) { roar_uuid2str(uuid, cur->uuid, sizeof(uuid)); roar_vio_printf(vio, "HASH={UUID}%s\n", uuid); num = rpld_ple_num_filename(cur); for (i = 0; i < num; i++) { filename = rpld_ple_get_filename(cur, i, &filenametype); if ( filename != NULL ) { switch (filenametype) { case RPLD_TYPE_STREAMURL: key = "STREAMURL"; break; case RPLD_TYPE_FILENAME: key = "FILENAME"; break; case RPLD_TYPE_FILEURL: key = "FILEURL"; break; default: key = "FILENAME"; break; } roar_vio_printf(vio, "%s=%s\n", key, filename); } } if ( cur->meta.album[0] ) roar_vio_printf(vio, "ALBUM=%s\n", cur->meta.album); if ( cur->meta.title[0] ) roar_vio_printf(vio, "TITLE=%s\n", cur->meta.title); if ( cur->meta.artist[0] ) roar_vio_printf(vio, "ARTIST=%s\n", cur->meta.artist); if ( cur->meta.performer[0] ) roar_vio_printf(vio, "PERFORMER=%s\n", cur->meta.performer); if ( cur->meta.version[0] ) roar_vio_printf(vio, "VERSION=%s\n", cur->meta.version); if ( cur->meta.genre != -1 ) roar_vio_printf(vio, "GENRE=%s\n", roar_meta_strgenre(cur->meta.genre)); if ( cur->meta.tracknum ) roar_vio_printf(vio, "TRACKNUMBER=%i\n", cur->meta.tracknum); if ( cur->meta.discid ) roar_vio_printf(vio, "DISCID=%.8x\n", cur->meta.discid); if ( cur->length ) roar_vio_printf(vio, "LENGTH=%s\n", rpld_ple_time_hr(cur)); if ( cur->codec != -1 ) roar_vio_printf(vio, "SIGNALINFO=codec:%s\n", roar_codec2str(cur->codec)); if ( cur->wallclock_start != RPLD_PLE_WALLCLOCK_INVALID ) roar_vio_printf(vio, "X-RPLD-WALLCLOCK-START=%" __ll "i\n", (__longlong)cur->wallclock_start); roar_vio_printf(vio, "LIKENESS=%f\n", (double)cur->likeness); for (i = 0; i < cur->meta.extra.kvlen && cur->meta.extra.kv[i].key != NULL && cur->meta.extra.kv[i].value != NULL; i++) { roar_vio_printf(vio, "%s=%s\n", cur->meta.extra.kv[i].key, cur->meta.extra.kv[i].value); } roar_vio_printf(vio, "==\n"); cur = cur->list.next; } return 0; } int ff_vclt_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { struct rpld_playlist_entry * plent = NULL; struct roar_audio_info info; char buf[1024]; char * s, * delm; char * dst; size_t dst_len; size_t len; int meta; ssize_t extra_index = 0; void * extra_buf; ssize_t extra_len; roar_uuid_t uuid; enum rpld_filename_type filenametype; (void)handle; while ((s = roar_vio_fgets(vio, buf, sizeof(buf))) != NULL ) { len = strlen(s); for (s += len - 1; s > buf && (*s == '\r' || *s == '\n'); s--) *s = 0; if ( !*buf ) continue; if ( !strcmp(buf, "==") ) { if ( plent != NULL ) rpld_pl_push(pl, plent); plent = NULL; continue; } if ( (delm = strstr(buf, "=")) == NULL ) continue; *delm = 0; delm++; if ( plent == NULL ) if ( (plent = rpld_ple_new()) == NULL ) return -1; if ( !strcasecmp(buf, "X-RPLD-WALLCLOCK-START") ) { plent->wallclock_start = atoi(delm); continue; } meta = roar_meta_inttype(buf); dst = NULL; dst_len = 0; switch (meta) { case ROAR_META_TYPE_FILENAME: case ROAR_META_TYPE_FILEURL: case ROAR_META_TYPE_STREAMURL: filenametype = rpld_ple_get_filenametype(buf); rpld_ple_push_filename(plent, delm, filenametype, 0); continue; break; case ROAR_META_TYPE_ALBUM: dst = plent->meta.album; dst_len = sizeof(plent->meta.album); break; case ROAR_META_TYPE_TITLE: dst = plent->meta.title; dst_len = sizeof(plent->meta.title); break; case ROAR_META_TYPE_ARTIST: dst = plent->meta.artist; dst_len = sizeof(plent->meta.artist); break; case ROAR_META_TYPE_PERFORMER: dst = plent->meta.performer; dst_len = sizeof(plent->meta.performer); break; case ROAR_META_TYPE_VERSION: dst = plent->meta.version; dst_len = sizeof(plent->meta.version); break; case ROAR_META_TYPE_LENGTH: rpld_ple_set_time_hr(plent, delm); continue; break; case ROAR_META_TYPE_AUDIOINFO: if ( roar_meta_parse_audioinfo(&info, delm) != -1 ) { plent->codec = info.codec; } continue; break; case ROAR_META_TYPE_TRACKNUMBER: plent->meta.tracknum = atoi(delm); continue; break; case ROAR_META_TYPE_GENRE: plent->meta.genre = roar_meta_intgenre(delm); continue; break; case ROAR_META_TYPE_DISCID: sscanf(delm, "%8x", &(plent->meta.discid)); continue; break; #ifdef ROAR_META_TYPE_LIKENESS case ROAR_META_TYPE_LIKENESS: plent->likeness = atof(delm); continue; break; #endif case ROAR_META_TYPE_HASH: if ( !strncasecmp(delm, "{UUID}", 6) ) { if ( roar_str2uuid(uuid, delm+6) == 0 ) { memcpy(plent->uuid, uuid, sizeof(plent->uuid)); } } continue; break; default: if ( plent->meta.extra.kvlen == -1 ) plent->meta.extra.kvlen = 0; if ( plent->meta.extra.kv_storelen == -1 ) plent->meta.extra.kv_storelen = 0; if ( extra_index == plent->meta.extra.kvlen ) { extra_buf = roar_mm_realloc(plent->meta.extra.kv, sizeof(struct roar_keyval)*(extra_index + 8)); if ( extra_buf == NULL ) continue; plent->meta.extra.kvlen += 8; plent->meta.extra.kv = extra_buf; memset(extra_buf+sizeof(struct roar_keyval)*extra_index, 0, sizeof(struct roar_keyval)*8); } extra_len = roar_mm_strlen(buf) + roar_mm_strlen(delm) + 2; extra_buf = roar_mm_realloc(plent->meta.extra.kv_store, plent->meta.extra.kv_storelen + extra_len); if ( extra_buf == NULL ) continue; plent->meta.extra.kv[extra_index].key = extra_buf + plent->meta.extra.kv_storelen; strcpy(plent->meta.extra.kv[extra_index].key, buf); plent->meta.extra.kv[extra_index].value = extra_buf + plent->meta.extra.kv_storelen + roar_mm_strlen(buf) + 1; strcpy(plent->meta.extra.kv[extra_index].value, delm); plent->meta.extra.kv_store = extra_buf; plent->meta.extra.kv_storelen += extra_len; continue; break; } strncpy(dst, delm, dst_len); dst[dst_len-1] = 0; } if ( plent != NULL ) rpld_pl_push(pl, plent); return 0; } //ll rpld-0.1.9/ff_xspf.c0000644000175000017500000002600512266574304012417 0ustar phiphi//ff_xspf.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" #ifdef HAVE_LIB_XML2 #include #include #include #include #include #include #include #define META_BASE_URL_PREFIX "http://roaraudio.keep-cool.org/spec/xspf/meta-" #define META_BASE_URL_SUFFIX ".txt" #define META_BASE_URL_STATIC(x) (META_BASE_URL_PREFIX x META_BASE_URL_SUFFIX) #define META_BASE_URL META_BASE_URL_STATIC("%s") static int ff_xspf_write(void * context, const char * buffer, int len) { return roar_vio_write(context, (void*)buffer, len); } static int ff_xspf_read (void * context, char * buffer, int len) { ssize_t ret = roar_vio_read(context, buffer, len); ROAR_DBG("ff_xspf_read(context=%p, buffer=%p, len=%i) = %i(?)", context, buffer, len, (int)ret); return ret; } static xmlNodePtr new_text_node(xmlNodePtr parent, const char * name, const char * value) { xmlNodePtr ret = xmlNewNode(NULL, (const xmlChar *)name); if ( ret == NULL ) return NULL; xmlAddChild(ret, xmlNewText((const xmlChar *)value)); xmlAddChild(parent, ret); return ret; } static xmlNodePtr new_meta_text_node(xmlNodePtr parent, const char * name, const char * value) { xmlNodePtr ret = xmlNewNode(NULL, (const xmlChar *)"meta"); char buf[256]; if ( ret == NULL ) return NULL; snprintf(buf, sizeof(buf), META_BASE_URL, name); xmlSetProp(ret, (xmlChar *)"rel", (const xmlChar *)buf); xmlAddChild(ret, xmlNewText((const xmlChar *)value)); xmlAddChild(parent, ret); return ret; } static void __add_filenames(xmlNodePtr track, struct rpld_playlist_entry * cur) { char buf[RPLD_MAX_PLF_LEN+64]; const char * filename; xmlChar * location; ssize_t i, num; num = rpld_ple_num_filename(cur); for (i = 0; i < num; i++) { filename = rpld_ple_get_filename(cur, i, NULL); if ( filename == NULL ) continue; if ( isalpha(filename[0]) ) { new_text_node(track, "location", filename); } else { location = xmlPathToURI((const xmlChar *)filename); snprintf(buf, sizeof(buf), "file://%s", location); xmlFree(location); new_text_node(track, "location", buf); } } } int ff_xspf_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { struct rpld_playlist * parentpl; struct rpld_playlist_entry * cur = rpld_pl_get_first(pl); int parent = rpld_pl_get_parent(pl); char buf[RPLD_MAX_PLF_LEN+64]; xmlDocPtr doc; xmlNodePtr rootnode, tracklist, track; xmlOutputBufferPtr output; (void)handle; output = xmlAllocOutputBuffer(NULL); if ( output == NULL ) return -1; output->context = vio; output->writecallback = ff_xspf_write; output->closecallback = NULL; doc = xmlNewDoc((xmlChar *)"1.0"); if ( doc == NULL ) return -1; doc->charset = XML_CHAR_ENCODING_UTF8; doc->encoding = xmlStrdup((xmlChar *)"UTF-8"); rootnode = xmlNewNode(NULL, (xmlChar *)"playlist"); xmlSetProp(rootnode, (xmlChar *)"version", (xmlChar *)"1"); xmlSetProp(rootnode, (xmlChar *)"xmlns", (xmlChar *)"http://xspf.org/ns/0/"); xmlDocSetRootElement(doc, rootnode); if ( rpld_pl_get_name(pl) != NULL ) new_text_node(rootnode, "title", rpld_pl_get_name(pl)); if (parent != 0 && parent != -1) { snprintf(buf, sizeof(buf), "%d", parent); new_meta_text_node(rootnode, "parent-playlist-id", buf); parentpl = rpld_pl_get_by_id(parent); new_meta_text_node(rootnode, "parent-playlist-name", rpld_pl_get_name(parentpl)); rpld_pl_unref(parentpl); } tracklist = xmlNewNode(NULL, (xmlChar *)"trackList"); xmlAddChild(rootnode, tracklist); while ( cur != NULL ) { track = xmlNewNode(NULL, (xmlChar *)"track"); __add_filenames(track, cur); strcpy(buf, "tantalos://"); roar_uuid2str(buf+11, cur->uuid, sizeof(buf)-11); new_text_node(track, "identifier", buf); if (cur->meta.album[0] != 0) new_text_node(track, "album", cur->meta.album); if (cur->meta.title[0] != 0) new_text_node(track, "title", cur->meta.title); if (cur->meta.artist[0] != 0) new_text_node(track, "creator", cur->meta.artist); if (cur->meta.performer[0] != 0) new_meta_text_node(track, "performer", cur->meta.performer); if (cur->meta.version[0] != 0) new_meta_text_node(track, "version", cur->meta.version); if (cur->meta.tracknum) { snprintf(buf, sizeof(buf), "%d", (int)cur->meta.tracknum); new_text_node(track, "trackNum", buf); } if (cur->meta.discid != 0 && cur->meta.discid != (discid_t)-1) { snprintf(buf, sizeof(buf), "0x%.8X", (int)cur->meta.discid); new_meta_text_node(track, "discid", buf); } if (cur->meta.genre != -1) new_meta_text_node(track, "genre", roar_meta_strgenre(cur->meta.genre)); if (cur->likeness) { snprintf(buf, sizeof(buf), "%f", (double)cur->likeness); new_meta_text_node(track, "likeness", buf); } if (cur->codec != -1) { new_meta_text_node(track, "codec", roar_codec2str(cur->codec)); } if (cur->length) { snprintf(buf, sizeof(buf), "%d", (int)(cur->length * 1000)); new_text_node(track, "duration", buf); } xmlAddChild(tracklist, track); cur = cur->list.next; } xmlSaveFormatFileTo(output, doc, "UTF-8", 1); xmlFreeDoc(doc); return 0; } static void ff_xspf_pl_import_track_parse_meta(struct rpld_playlist_entry * plent, char ** dst, size_t * dst_len, const char ** value, xmlNode * element) { const char * name = (const char * /* libxml2 cast-hell */) xmlGetProp(element, (xmlChar *)"rel"); int tmp; //Audacious: ??? if ( !strcmp(name, META_BASE_URL_STATIC("performer")) ) { *dst = plent->meta.performer; *dst_len = sizeof(plent->meta.performer); } else if ( !strcmp(name, META_BASE_URL_STATIC("version")) ) { *dst = plent->meta.version; *dst_len = sizeof(plent->meta.version); } else if ( !strcmp(name, META_BASE_URL_STATIC("discid")) ) { if ( sscanf(*value, "0x%8x", &tmp) == 1 ) { plent->meta.discid = tmp; } } else if ( !strcmp(name, META_BASE_URL_STATIC("genre")) ) { plent->meta.genre = roar_meta_intgenre(*value); } else if ( !strcmp(name, META_BASE_URL_STATIC("likeness")) ) { plent->likeness = atof(*value); } else if ( !strcmp(name, META_BASE_URL_STATIC("codec")) ) { plent->codec = roar_str2codec(*value); } } static void ff_xspf_pl_import_track(struct rpld_playlist * pl, xmlNode * track) { struct rpld_playlist_entry * plent = rpld_ple_new(); int uuid_set = 0; char buf[RPLD_MAX_PLF_LEN+64]; xmlNode * element; const char * name; const char * value; char * dst; size_t dst_len; int tmp; if ( plent == NULL ) return; for (element = track->children; element != NULL; element = element->next) { if ( element->type != XML_ELEMENT_NODE ) continue; dst = NULL; dst_len = 0; name = (const char * /* libxml2 cast-hell */) element->name; value = (const char * /* libxml2 cast-hell */) xmlNodeGetContent(element); if (!strcmp(name, "location")) { // TODO. if ( !uuid_set && !strncmp(value, "tantalos://", 11) ) { // For error checking see below. value += 11; roar_str2uuid(plent->uuid, value); uuid_set = 1; } // Very ugly workaround as libxml2 has bad docs. // Prey this will never explode. if ( strlen(value) < (sizeof(buf)-1) ) { (void)xmlURIUnescapeString(value, -1, buf); buf[sizeof(buf)-1] = 0; rpld_ple_push_filename(plent, buf, RPLD_TYPE_UNKNOWN, 0); } } else if (!strcmp(name, "identifier")) { if ( !strncmp(value, "tantalos://", 11) ) { value += 11; // We can ignore errors here as uuid_parse() does not alter the UUID if parsing failed. // This is the documented behavior. Hope nobody will break it somewhen... roar_str2uuid(plent->uuid, value); uuid_set = 1; } } else if (!strcmp(name, "title")) { dst = plent->meta.title; dst_len = sizeof(plent->meta.title); } else if (!strcmp(name, "creator")) { dst = plent->meta.artist; dst_len = sizeof(plent->meta.artist); } else if (!strcmp(name, "album")) { dst = plent->meta.album; dst_len = sizeof(plent->meta.album); } else if (!strcmp(name, "trackNum")) { if ( sscanf(value, "%d", &tmp) == 1 ) { plent->meta.tracknum = tmp; } } else if (!strcmp(name, "duration")) { if ( sscanf(value, "%d", &tmp) == 1 ) { plent->length = tmp / 1000; } } else if (!strcmp(name, "meta")) { ff_xspf_pl_import_track_parse_meta(plent, &dst, &dst_len, &value, element); #if 0 // The following is not relevant for us. } else if (!strcmp(name, "extension")) { } else if (!strcmp(name, "link")) { } else if (!strcmp(name, "annotation")) { } else if (!strcmp(name, "info")) { } else if (!strcmp(name, "image")) { #endif } if ( dst != NULL ) { ROAR_DBG("ff_xspf_pl_import_track(pl=%p, track=%p): Copy '%s' to %p (element type: %s).", pl, track, value, dst, name); strncpy(dst, value, dst_len); dst[dst_len-1] = 0; } else { ROAR_DBG("ff_xspf_pl_import_track(pl=%p, track=%p): no data to copy (element type: %s).", pl, track, name); } } rpld_pl_push(pl, plent); } int ff_xspf_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { xmlDoc * doc; xmlNode * main_element; xmlNode * playlist_element; xmlNode * tracklist_element; (void)handle; doc = xmlReadIO(ff_xspf_read, NULL, vio, "__dummy.xspf", NULL, XML_PARSE_RECOVER); if ( doc == NULL ) return -1; for (main_element = doc->children; main_element != NULL; main_element = main_element->next) { if ( main_element->type != XML_ELEMENT_NODE ) continue; if ( !!xmlStrcmp(main_element->name, (xmlChar *)"playlist") ) continue; for (playlist_element = main_element->children; playlist_element != NULL; playlist_element = playlist_element->next) { if ( playlist_element->type != XML_ELEMENT_NODE ) continue; if ( !!xmlStrcmp(playlist_element->name, (xmlChar *)"trackList") ) continue; for (tracklist_element = playlist_element->children; tracklist_element != NULL; tracklist_element = tracklist_element->next) { if ( tracklist_element->type != XML_ELEMENT_NODE ) continue; if ( !!xmlStrcmp(tracklist_element->name, (xmlChar *)"track") ) continue; ff_xspf_pl_import_track(pl, tracklist_element); } } } xmlFreeDoc(doc); return 0; } #endif //ll rpld-0.1.9/fformat.c0000644000175000017500000001233712266574304012425 0ustar phiphi//fformat.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" static struct { int id; const char * name; const char * ext; } ff_plf[] = { {RPLD_FF_PLF_RPLD, "rpld", "rpldpl"}, {RPLD_FF_PLF_VCLT, "vclt", "vclt" }, {RPLD_FF_PLF_PLS, "pls", "pls" }, {RPLD_FF_PLF_M3U, "m3u", "m3u" }, {RPLD_FF_PLF_XSPF, "xspf", "xspf" }, {RPLD_FF_PLF_PLAIN, "plain", NULL }, {RPLD_FF_PLF_URAS, "uras", "xml" }, {-1, NULL, NULL} }; int fformat_str2plf(const char * str) { int i; if ( str == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } for (i = 0; ff_plf[i].id != -1; i++) if ( !strcasecmp(str, ff_plf[i].name) ) return ff_plf[i].id; roar_err_set(ROAR_ERROR_NOENT); return -1; } const char * fformat_plf2str(int plf) { int i; for (i = 0; ff_plf[i].id != -1; i++) if ( ff_plf[i].id == plf ) return ff_plf[i].name; roar_err_set(ROAR_ERROR_NOENT); return NULL; } static struct { int format; int (*open) (struct fformat_handle * handle); void (*close )(struct fformat_handle * handle); int (*pl_export)(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int (*pl_import)(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int (*pl_update)(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); } ff_handles[] = { {RPLD_FF_PLF_VCLT, NULL, NULL, ff_vclt_pl_export, ff_vclt_pl_import, NULL}, {RPLD_FF_PLF_PLAIN, NULL, NULL, ff_plain_pl_export, ff_plain_pl_import, NULL}, {RPLD_FF_PLF_M3U, NULL, NULL, ff_m3u_pl_export, ff_m3u_pl_import, NULL}, {RPLD_FF_PLF_RPLD, NULL, NULL, ff_rpld_pl_export, ff_rpld_pl_import, NULL}, {RPLD_FF_PLF_PLS, NULL, NULL, ff_pls_pl_export, NULL, NULL}, #ifdef HAVE_LIB_XML2 {RPLD_FF_PLF_XSPF, NULL, NULL, ff_xspf_pl_export, ff_xspf_pl_import, NULL}, {RPLD_FF_PLF_URAS, NULL, NULL, ff_uras_pl_export, ff_uras_pl_import, NULL}, #endif {-1, NULL, NULL, NULL, NULL, NULL} }; struct fformat_handle * fformat_handle_new(int format) { struct fformat_handle * ret; int i; for (i = 0; ff_handles[i].format != -1; i++) { if ( ff_handles[i].format == format ) { if ( (ret = roar_mm_malloc(sizeof(struct fformat_handle))) == NULL ) return NULL; memset(ret, 0, sizeof(struct fformat_handle)); ret->format = format; ret->table_id = i; if ( ff_handles[i].open != NULL ) { if ( ff_handles[i].open(ret) == -1 ) { roar_mm_free(ret); return NULL; } } return ret; } } return NULL; } void fformat_handle_close(struct fformat_handle * handle) { if ( handle == NULL ) return; if ( ff_handles[handle->table_id].close != NULL ) { ff_handles[handle->table_id].close(handle); } roar_mm_free(handle); } int fformat_playlist_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { if ( ff_handles[handle->table_id].pl_export == NULL ) return -1; return ff_handles[handle->table_id].pl_export(handle, vio, pl); } int fformat_playlist_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { struct rpld_playlist * tmp_pl; int ret; if ( ff_handles[handle->table_id].pl_import == NULL ) { roar_err_set(ROAR_ERROR_NOTSUP); return -1; } tmp_pl = rpld_pl_new(); if ( tmp_pl == NULL ) return -1; yield_watchdog_stop(); yield_auto(RPLD_YIELD_START, RPLD_YIELD_TASK_PLAYBACK, RPLD_YIELD_TASK_NETWORK, RPLD_YIELD_NONBLOCK); ret = ff_handles[handle->table_id].pl_import(handle, vio, tmp_pl); yield_auto(RPLD_YIELD_STOP, RPLD_YIELD_TASK_PLAYBACK, RPLD_YIELD_TASK_NETWORK, RPLD_YIELD_NONBLOCK); yield_watchdog_start(); if ( ret == 0 ) { ret = rpld_pl_merge(pl, tmp_pl); } if ( ret == -1 ) { rpld_pl_unref(tmp_pl); } return ret; } int fformat_playlist_update(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl) { if ( ff_handles[handle->table_id].pl_update == NULL ) return -1; return ff_handles[handle->table_id].pl_update(handle, vio, pl); } //ll rpld-0.1.9/fformat.h0000644000175000017500000000742212266574304012431 0ustar phiphi//fformat.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_FFORMAT_H_ #define _RPLD_FFORMAT_H_ #define RPLD_FF_PLF_NONE 0 #define RPLD_FF_PLF_RPLD 1 #define RPLD_FF_PLF_VCLT 2 #define RPLD_FF_PLF_PLS 3 #define RPLD_FF_PLF_M3U 4 #define RPLD_FF_PLF_XSPF 5 #define RPLD_FF_PLF_PLAIN 6 #define RPLD_FF_PLF_URAS 7 #define RPLD_FF_PLF_DEFAULT RPLD_FF_PLF_VCLT struct fformat_handle { int format; int table_id; }; int fformat_str2plf(const char * str); const char * fformat_plf2str(int plf); struct fformat_handle * fformat_handle_new(int format); void fformat_handle_close(struct fformat_handle * handle); int fformat_playlist_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int fformat_playlist_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int fformat_playlist_update(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); // prototypes for ff_*.c: int ff_vclt_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int ff_vclt_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int ff_plain_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int ff_plain_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int ff_m3u_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int ff_m3u_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int ff_rpld_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int ff_rpld_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int ff_pls_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int ff_pls_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int ff_xspf_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int ff_xspf_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int ff_uras_pl_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); int ff_uras_pl_import(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); #endif //ll rpld-0.1.9/man-symlinks.src0000644000175000017500000000066111757750155013757 0ustar phiphirpld-ctl 1 rpld-tools 1 rpld-next 1 rpld-tools 1 rpld-listq 1 rpld-tools 1 rpld-import 1 rpld-tools 1 rpld-listplaylists 1 rpld-tools 1 rpld-queueple 1 rpld-tools 1 rpld-setpointer 1 rpld-tools 1 rpld-showplaying 1 rpld-tools 1 rpld-play 1 rpld-deprecated 1 rpld-prev 1 rpld-deprecated 1 rpld-stop 1 rpld-deprecated 1 rpld-store 1 rpld-deprecated 1 rpld-addplaylist 1 rpld-deprecated 1 rpld-delplaylist 1 rpld-deprecated 1 rpld-0.1.9/network.c0000644000175000017500000001506612266574304012462 0ustar phiphi//network.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) #include #include #endif #define _AS(x) (sizeof((x))/sizeof(*(x))) static struct { struct roar_vio_calls sock; int proto; const char * server; enum rpld_client_acclev acclev; } g_listen[RPLD_MAX_LISTEN]; int network_preinit(void) { size_t i; memset(g_listen, 0, sizeof(g_listen)); for (i = 0; i < _AS(g_listen); i++) g_listen[i].proto = RPLD_PROTO_UNUSED; return 0; } int network_add_server(const char * server, int port, int type, int proto, enum rpld_client_acclev acclev) { char unixpath_buf[128]; size_t id; if ( acclev == ACCLEV_ERR ) return -1; for (id = 0; id < _AS(g_listen); id++) if ( g_listen[id].proto == RPLD_PROTO_UNUSED ) break; if ( id == _AS(g_listen) ) return -1; if ( type == -1 ) { type = ROAR_SOCKET_TYPE_UNKNOWN; } if ( type == ROAR_SOCKET_TYPE_UNKNOWN && server == NULL && port == -1 ) { #ifdef ROAR_HAVE_UNIX type = ROAR_SOCKET_TYPE_UNIX; #elif defined(ROAR_HAVE_IPV4) type = ROAR_SOCKET_TYPE_TCP; #elif defined(ROAR_HAVE_LIBDNET) type = ROAR_SOCKET_TYPE_DECNET; #else ROAR_ERR("network_add_server(*): Can not find any working default address familiy."); return -1; #endif } switch (type) { case ROAR_SOCKET_TYPE_UNIX: if ( server == NULL ) { if ( roar_env_render_path_r(unixpath_buf, sizeof(unixpath_buf), RPLD_SOCKNAME_UNIX) != -1 ) { server = unixpath_buf; } else { server = RPLD_SOCKNAME_UNIX_FALLBACK; } } break; case ROAR_SOCKET_TYPE_TCP: if ( server == NULL ) server = RPLD_SOCKNAME_TCP; if ( port == -1 ) port = RPLD_PORT; case ROAR_SOCKET_TYPE_DECNET: if ( server == NULL ) server = RPLD_SOCKNAME_DECNET; if ( port == -1 ) port = 0; break; } // TODO: FIXME: this code unlinks sockets that are aktive: if ( roar_vio_open_socket_listen(&(g_listen[id].sock), type, server, port) == -1 ) { if ( type == ROAR_SOCKET_TYPE_UNIX ) { unlink(server); if ( roar_vio_open_socket_listen(&(g_listen[id].sock), type, server, port) == -1 ) return -1; } } #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) if ( type == ROAR_SOCKET_TYPE_UNIX ) { if ( g_pwd != NULL || g_grp != NULL ) { if ( chown(server, g_pwd != NULL ? g_pwd->pw_uid : (uid_t)-1, g_grp != NULL ? g_grp->gr_gid : (gid_t)-1) == -1 ) { ROAR_WARN("Can not change ownership of socket: %s: %s", server, strerror(errno)); } } if ( chmod(server, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1 ) { ROAR_WARN("Can not change permissions of socket: %s: %s", server, strerror(errno)); } } #endif g_listen[id].proto = proto; g_listen[id].server = server; g_listen[id].acclev = acclev; return 0; } int network_init(void) { return 0; } void network_uninit(void) { size_t id; for (id = 0; id < _AS(g_listen); id++) { if ( g_listen[id].proto != RPLD_PROTO_UNUSED ) roar_vio_close(&(g_listen[id].sock)); if ( g_listen[id].server != NULL ) unlink(g_listen[id].server); } for (id = 0; id < RPLD_CLIENTS_MAX; id++) { client_delete(id); } } #define NUM_VIOS (RPLD_CLIENTS_MAX + RPLD_MAX_LISTEN) void network_check(int block) { struct roar_vio_selecttv tv; struct roar_vio_select vios[NUM_VIOS]; struct roar_vio_calls * vio; int id; int i; int clientid; size_t num = 0; size_t min_client; ROAR_DBG("network_check(block=%i) = ?", block); tv.sec = 0; switch (block) { case RPLD_YIELD_NONBLOCK: tv.nsec = 32000; break; case RPLD_YIELD_BLOCK: tv.nsec = 1024000; break; case RPLD_YIELD_LONGBLOCK: tv.sec = 3600; tv.nsec = 0; break; default: tv.nsec = 1024000; break; } ROAR_DBG("num=%lu", (unsigned long int)num); for (i = 0; i < (int)_AS(g_listen); i++) { if ( g_listen[i].proto == RPLD_PROTO_UNUSED ) continue; vios[num].ud.si = i; ROAR_VIO_SELECT_SETVIO(&(vios[num]), &(g_listen[i].sock), ROAR_VIO_SELECT_READ); num++; } // ROAR_DBG("(int)(vios[0].vio->inst) = %i", (int)(vios[0].vio->inst)); ROAR_DBG("num=%lu", (unsigned long int)num); min_client = num; for (id = 0; id < RPLD_CLIENTS_MAX; id++) { if ( (vio = client_get_vio(id)) != NULL ) { vios[num].ud.si = id; ROAR_VIO_SELECT_SETVIO(&(vios[num]), vio, client_get_eventsq(id)); num++; } } ROAR_DBG("num=%lu", (unsigned long int)num); if ( num == 0 ) { rpld_exit(); return; } if ( block != RPLD_YIELD_NONBLOCK ) yield_watchdog_stop(); if ( roar_vio_select(vios, num, &tv, NULL) < 1 ) { if ( block != RPLD_YIELD_NONBLOCK ) yield_watchdog_start(); ROAR_DBG("network_check(block=%i) = (void)", block); return; } if ( block != RPLD_YIELD_NONBLOCK ) yield_watchdog_start(); // first handle clients so new clients may not break the list for (i = min_client; i < NUM_VIOS && i < (int)num; i++) { if ( vios[i].eventsa & (ROAR_VIO_SELECT_READ|ROAR_VIO_SELECT_WRITE) ) { ROAR_DBG("network_check(block=%i): vios[i=%i].ud.si = %i", block, i, vios[i].ud.si); // handle client if ( client_handle(vios[i].ud.si, vios[i].eventsa) == -1 ) client_delete(vios[i].ud.si); } } for (i = 0; i < (int)min_client && i < (int)num; i++) { if ( !(vios[i].eventsa & ROAR_VIO_SELECT_READ) ) continue; // handle listen socket if ( (clientid = client_new(&vio)) == -1 ) { continue; } if ( roar_vio_accept(vio, &(g_listen[vios[i].ud.si].sock)) == -1 ) { roar_vio_clear_calls(vio); client_delete(clientid); continue; } if ( client_set_proto(clientid, g_listen[i].proto) == -1 ) { client_delete(clientid); } if ( client_set_acclev(clientid, g_listen[i].acclev, -1) == -1 ) { client_delete(clientid); } } ROAR_DBG("network_check(block=%i) = (void)", block); } //ll rpld-0.1.9/network.h0000644000175000017500000000270212266574304012460 0ustar phiphi//network.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_NETWORK_H_ #define _RPLD_NETWORK_H_ #define RPLD_SOCKNAME_UNIX "~/.rpld" #define RPLD_SOCKNAME_UNIX_FALLBACK "/tmp/.rpld" #define RPLD_SOCKNAME_TCP "localhost" #define RPLD_SOCKNAME_DECNET "::rpld" #define RPLD_SOCKNAME RPLD_SOCKNAME_UNIX #define RPLD_PORT 24148 #define RPLD_MAX_LISTEN 4 int network_preinit(void); int network_add_server(const char * server, int port, int type, int proto, enum rpld_client_acclev acclev); int network_init(void); void network_uninit(void); void network_check(int block); #endif //ll rpld-0.1.9/playback.c0000644000175000017500000006556712266574304012572 0ustar phiphi//playback.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" static struct rpld_queue * _get_queue(pli_t queue, struct rpld_playlist ** playlist) { struct rpld_playlist * pl = rpld_pl_get_by_id(queue); if ( pl == NULL ) { roar_err_set(ROAR_ERROR_NOENT); return NULL; } if ( pl->queue == NULL ) { rpld_pl_unref(pl); roar_err_set(ROAR_ERROR_TYPEMM); return NULL; } *playlist = pl; return pl->queue; } int playback_preinit(void) { return 0; } int playback_init(void) { ROAR_DBG("playback_init() = ?"); if ( playback_preinit() == -1 ) return -1; ROAR_DBG("playback_init() = 0"); return 0; } void playback_uninit(void) { size_t i; for (i = 0; i < MAX_PLAYLISTS; i++) { if ( g_playlists[i] == NULL ) continue; if ( g_playlists[i]->queue == NULL ) continue; playback_stop(g_playlists[i]->id, 0, 1); } } void playback_set_role(pli_t queue, const int role) { struct rpld_playlist * pl; struct rpld_queue * plq = _get_queue(queue, &pl); if ( plq == NULL ) return; roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_ROLE, -1, queue, -1, role, -1, NULL, -1); plq->role = role; if ( !plq->playing ) { rpld_pl_unref(pl); return; } // set role on running stream: if ( roar_stream_set_role(&(plq->backend->con), &(plq->stream), plq->role) == -1 ) { ROAR_WARN("playback_set_role(queue=%i, role=%i): Can not set role for new stream to %s", (int)queue, role, roar_role2str(plq->role)); } rpld_pl_unref(pl); } struct roar_audio_info * playback_get_codechelper_info(void) { static struct roar_audio_info ret = { .rate = ROAR_RATE_DEFAULT, .bits = ROAR_BITS_DEFAULT, .channels = ROAR_CHANNELS_DEFAULT, .codec = ROAR_CODEC_DEFAULT }; return &ret; } static void _handle_queue_io(pli_t queue, struct rpld_queue * plq) { char buf[2*1024]; ssize_t len; int is_playing; if ( (len = roar_vio_read(plq->io.fp, buf, sizeof(buf))) < 1 ) { if ( len == -1 && roar_error == ROAR_ERROR_AGAIN ) return; is_playing = playback_is_playing(queue); playback_stop(queue, 0, 0); playback_next(queue); if ( is_playing ) playback_play(queue); return; } if ( roar_vio_write(&(plq->io.stream), buf, len) != len ) { is_playing = playback_is_playing(queue); playback_stop(queue, 0, 0); playback_next(queue); if ( is_playing ) playback_play(queue); return; } } void playback_check(int block) { struct roar_vio_select vioset[3*(MAX_PLAYLISTS/2)]; // we need 3 handles per queue // and guess we have a max of MAX_PLAYLISTS/2 queues. struct rpld_queue * plq; struct rpld_playlist * pl; struct roar_vio_selecttv tv; size_t i; size_t count = 0; int is_playing = 0; size_t left_handles = 0; #ifdef ROAR_TARGET_WIN32 if ( block == RPLD_YIELD_NONBLOCK ) { // we do not support non-blocking checks as win32 is totally broken. See below. return; } #endif if ( block == RPLD_YIELD_NONBLOCK ) { block = 0; } else { block = 1; } for (i = 0; i < MAX_PLAYLISTS; i++) { pl = g_playlists[i]; if ( pl == NULL ) continue; plq = pl->queue; if ( plq == NULL ) continue; if ( !plq->playing ) continue; ROAR_VIO_SELECT_SETVIO(&(vioset[count]), &(plq->io.stream), ROAR_VIO_SELECT_WRITE); vioset[count].ud.vp = pl; count++; ROAR_VIO_SELECT_SETVIO(&(vioset[count]), plq->io.fp, ROAR_VIO_SELECT_READ); vioset[count].ud.vp = pl; count++; left_handles += 2; if ( plq->io.fp == &(plq->io.file) ) { ROAR_VIO_SELECT_SETVIO(&(vioset[count]), &(plq->io.file), ROAR_VIO_SELECT_NONE|ROAR_VIO_SELECT_NO_RETEST); } else { ROAR_VIO_SELECT_SETVIO(&(vioset[count]), &(plq->io.file), ROAR_VIO_SELECT_READ); left_handles++; } vioset[count].ud.vp = pl; count++; is_playing = 1; } if ( is_playing ) { tv.sec = 0; tv.nsec = 32*1000; yield_watchdog_trigger(); if ( roar_vio_select(vioset, count, &tv, NULL) == -1 ) return; yield_watchdog_trigger(); for (i = 0; i < count; i++) { if ( vioset[i].eventsa & vioset[i].eventsq ) { vioset[i].eventsq |= ROAR_VIO_SELECT_NO_RETEST; left_handles--; } } tv.sec = 0; if ( block ) { tv.nsec = 10*1000*1000; } else { tv.nsec = 32*1000; } ROAR_DBG("playback_check(void) = ?"); ROAR_DBG("playback_check(void) = ?"); yield_watchdog_trigger(); // if we have less than one handle we can not do anything anyway so we just return. ROAR_DBG("playback_check(void) = ?"); if ( left_handles ) if ( roar_vio_select(vioset, count, &tv, NULL) == -1 ) return; ROAR_DBG("playback_check(void) = ?"); yield_watchdog_trigger(); for (i = 0; i < count; i += 3) { if ( !(vioset[i+0].eventsa & ROAR_VIO_SELECT_WRITE) ) continue; if ( !(vioset[i+1].eventsa & ROAR_VIO_SELECT_READ) && !(vioset[i+2].eventsa & ROAR_VIO_SELECT_READ) ) continue; pl = vioset[i].ud.vp; _handle_queue_io(pl->id, pl->queue); } ROAR_DBG("playback_check(void) = ?"); } else { ROAR_DBG("playback_check(void) = ?"); roar_usleep(10000); } ROAR_DBG("playback_check(void) = (void)"); } #if defined(HAVE_FUNC_UALARM) && defined(HAVE_FUNC_SIGINTERRUPT) static void _sighandler_dummy(int sig) { (void)sig; } #endif int playback_add_queue(struct rpld_playlist * pl, const char * backend, int mixer, struct rpld_playlist * history) { struct rpld_queue * queue; int err; if ( pl == NULL || history == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } if ( pl->queue != NULL ) { roar_err_set(ROAR_ERROR_BUSY); return -1; } queue = roar_mm_malloc(sizeof(*queue)); if ( queue == NULL ) return -1; memset(queue, 0, sizeof(*queue)); queue->refc = 1; queue->playing = 0; queue->role = ROAR_ROLE_MUSIC; queue->volume_mono = 65535; queue->ple_mduc = 0; queue->mixer = mixer; queue->history = history; queue->backend = backend_get_connection(backend); if ( queue->backend == NULL ) { err = roar_error; roar_mm_free(queue); roar_error = err; return -1; } rpld_pl_ref(history); pl->queue = queue; return 0; } int playback_del_queue(struct rpld_playlist * pl) { struct rpld_queue * plq; if ( pl == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } if ( (plq = pl->queue) == NULL ) { roar_err_set(ROAR_ERROR_TYPEMM); return -1; } if ( plq->playing ) if ( playback_stop(rpld_pl_get_id(pl), 0, 1) == -1 ) return -1; pl->queue = NULL; rpld_pl_unref(plq->history); backend_unref(plq->backend); roar_mm_free(plq); return 0; } int playback_has_queue(pli_t queue) { struct rpld_playlist * pl = rpld_pl_get_by_id(queue); int ret; if ( pl == NULL ) return -1; ret = pl->queue == NULL ? 0 : 1; rpld_pl_unref(pl); return ret; } int playback_set_pointer(pli_t queue, int pointer, struct rpld_playlist_pointer * plp) { struct rpld_playlist * pl = rpld_pl_get_by_id(queue); struct rpld_playlist_pointer ** cpointer; if ( pl == NULL ) return -1; if ( pl->queue == NULL ) { rpld_pl_unref(pl); roar_err_set(ROAR_ERROR_TYPEMM); return -1; } switch (pointer) { case POINTER_DEFAULT: cpointer = &(pl->queue->pointers.defaultptr); break; case POINTER_CURRENT: cpointer = &(pl->queue->pointers.currentptr); break; case POINTER_STARTUP: cpointer = &(pl->queue->pointers.startupptr); break; case POINTER_FALLBACK: cpointer = &(pl->queue->pointers.fallbackptr); break; default: rpld_pl_unref(pl); roar_err_set(ROAR_ERROR_INVAL); return -1; break; } if ( *cpointer != NULL ) { rpld_plp_unref(*cpointer); *cpointer = NULL; } *cpointer = plp; if ( plp != NULL ) rpld_plp_ref(plp); rpld_pl_unref(pl); return 0; } struct rpld_playlist_pointer * playback_get_pointer(pli_t queue, int pointer) { struct rpld_playlist * pl = rpld_pl_get_by_id(queue); struct rpld_playlist_pointer * ret = NULL; if ( pl == NULL ) return NULL; if ( pl->queue == NULL ) { rpld_pl_unref(pl); roar_err_set(ROAR_ERROR_TYPEMM); return NULL; } switch (pointer) { case POINTER_DEFAULT: ret = pl->queue->pointers.defaultptr; break; case POINTER_CURRENT: ret = pl->queue->pointers.currentptr; break; case POINTER_STARTUP: ret = pl->queue->pointers.startupptr; break; case POINTER_FALLBACK: ret = pl->queue->pointers.fallbackptr; break; default: roar_err_set(ROAR_ERROR_INVAL); break; } rpld_pl_unref(pl); if ( ret == NULL ) { roar_err_set(ROAR_ERROR_NOENT); } else { rpld_plp_ref(ret); } return ret; } void playback_play_all(void) { size_t i; roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_PLAY, -1, -1, -1, -1, -1, NULL, -1); for (i = 0; i < MAX_PLAYLISTS; i++) { if ( g_playlists[i] == NULL ) continue; if ( g_playlists[i]->queue == NULL ) continue; playback_play(rpld_pl_get_id(g_playlists[i])); } } void playback_stop_all(size_t offset, int kick) { size_t i; roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_STOP, -1, -1, -1, offset, kick, NULL, -1); for (i = 0; i < MAX_PLAYLISTS; i++) { if ( g_playlists[i] == NULL ) continue; if ( g_playlists[i]->queue == NULL ) continue; playback_stop(rpld_pl_get_id(g_playlists[i]), offset, kick); } } int playback_is_playing_any(void) { size_t i; for (i = 0; i < MAX_PLAYLISTS; i++) { if ( g_playlists[i] == NULL ) continue; if ( g_playlists[i]->queue == NULL ) continue; if ( playback_is_playing(rpld_pl_get_id(g_playlists[i])) ) return 1; } return 0; } int playback_play(pli_t queue) { struct rpld_playlist * pl = rpld_pl_get_by_id(queue); struct roar_audio_info * codechelper_info = playback_get_codechelper_info(); struct rpld_playlist_entry * plent; int codec; ssize_t magic_len = 0; char magic[64]; const char * content_type; struct rpld_queue * plq; const char * filename = NULL; ssize_t filenamecount; ssize_t i; int err; int ret; ROAR_DBG("playback_play(void) = ?"); if ( pl == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } if ( (plq = pl->queue) == NULL ) { rpld_pl_unref(pl); roar_err_set(ROAR_ERROR_TYPEMM); return -1; } if ( plq->playing ) { rpld_pl_unref(pl); return 0; } if ( !(plq->backend->flags & BACKEND_FLAG_CONNECTED) ) { rpld_pl_unref(pl); roar_err_set(ROAR_ERROR_NOTCONN); return -1; } ROAR_DBG("playback_play(void) = ?"); if ( (plent = rpld_pl_get_first(pl)) == NULL ) { // retry with autoqueue if ( autoqueue(queue) == -1 ) { rpld_pl_unref(pl); return -1; } if ( (plent = rpld_pl_get_first(pl)) == NULL ) { rpld_pl_unref(pl); return -1; } } ROAR_DBG("playback_play(void) = ?"); filenamecount = rpld_ple_num_filename(plent); ret = -1; err = ROAR_ERROR_NOENT; ROAR_DBG("playback_play(void) = ?"); for (i = 0; ret == -1 && i < filenamecount; i++) { filename = rpld_ple_get_filename(plent, i, NULL); if ( filename == NULL ) { err = roar_error; continue; } yield_auto(RPLD_YIELD_PAUSE, 0, 0, 0); #if defined(HAVE_FUNC_UALARM) && defined(HAVE_FUNC_SIGINTERRUPT) //signal(SIGALRM, SIG_IGN); signal(SIGALRM, _sighandler_dummy); siginterrupt(SIGALRM, 0); ualarm(1000*1000, 0); #endif ret = roar_vio_open_dstr_simple(&(plq->io.file), filename, ROAR_VIOF_READ|ROAR_VIOF_NONBLOCK); err = roar_error; yield_auto(RPLD_YIELD_UNPAUSE, 0, 0, 0); } if ( ret == -1 ) { rpld_pl_unref(pl); roar_err_set(err); ROAR_WARN("playback_play(void): Can not open file: %s: %s", filename, roar_error2str(roar_error)); return -1; } ROAR_DBG("playback_play(void) = ?"); plq->io.fp = &(plq->io.file); /* TODO: FIXME: do a better check for streams than checking for :// ! */ // try to guess the type by magic. if ( (codec = plent->codec) == -1 && strstr(filename, "://") == NULL ) { if ( (magic_len = roar_vio_read(&(plq->io.file), magic, 64)) < 1 ) { err = roar_error; roar_vio_close(&(plq->io.file)); rpld_pl_unref(pl); roar_err_set(err); return -1; } codec = roar_file_codecdetect(magic, magic_len); if ( codec == -1 ) { if ( roar_vio_lseek(&(plq->io.file), 0, SEEK_SET) == (off_t)-1 ) { err = roar_error; roar_vio_close(&(plq->io.file)); rpld_pl_unref(pl); roar_err_set(err); return -1; } } } ROAR_DBG("playback_play(void): codec=%i", codec); // try to read the magic from filesystem or stream headers. if ( codec == -1 ) { if ( roar_vio_ctl(&(plq->io.file), ROAR_VIO_CTL_GET_MIMETYPE, &content_type) != -1 ) { codec = roar_mime2codec(content_type); } } ROAR_DBG("playback_play(void): codec=%i", codec); // test if we need the codec helper for this kind of stream. if ( backend_blacklist_check_codec(plq->backend, codec) ) { codec = -1; } // open stream... if ( codec != -1 ) { if ( roar_vio_simple_new_stream_obj(&(plq->io.stream), &(plq->backend->con), &(plq->stream), ROAR_RATE_DEFAULT, ROAR_CHANNELS_DEFAULT, ROAR_BITS_DEFAULT, codec, ROAR_DIR_PLAY, plq->mixer ) == -1 ) { ROAR_DBG("playback_play(void): codec=%i->-1", codec); codec = -1; // we try the helper in case roard does not know about this codec... } } ROAR_DBG("playback_play(void): codec=%i", codec); if ( codec == -1 ) { if ( roar_vio_simple_new_stream_obj(&(plq->io.stream), &(plq->backend->con), &(plq->stream), codechelper_info->rate, codechelper_info->channels, codechelper_info->bits, codechelper_info->codec, ROAR_DIR_PLAY, plq->mixer ) == -1 ) { err = roar_error; roar_vio_close(&(plq->io.file)); rpld_pl_unref(pl); roar_err_set(err); ROAR_DBG("playback_play(void) = -1"); return -1; } } ROAR_DBG("playback_play(void) = ?"); if ( codec == -1 ) { if ( roar_vio_open_cmd(&(plq->io.filter), &(plq->io.file), "rpld-codec-helper", NULL, 0) == -1 ) { err = roar_error; roar_vio_close(&(plq->io.file)); roar_vio_close(&(plq->io.stream)); rpld_pl_unref(pl); roar_err_set(err); ROAR_DBG("playback_play(void) = -1"); return -1; } plq->io.fp = &(plq->io.filter); } else { if ( magic_len > 0 ) { if ( roar_vio_write(&(plq->io.stream), magic, magic_len) != magic_len ) { err = roar_error; roar_vio_close(&(plq->io.file)); roar_vio_close(&(plq->io.stream)); rpld_pl_unref(pl); roar_err_set(err); ROAR_DBG("playback_play(void) = -1"); return -1; } } } ROAR_DBG("playback_play(void) = ?"); memcpy(&(plq->ple), plent, sizeof(plq->ple)); plq->ple_mduc = 1; plq->playing = 1; roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_PLAY, -1, queue, -1, -1, -1, NULL, -1); // set rpg data: // only set in case non-default parameters are requested. if ( plent->rpg.mode != ROAR_RPGMODE_DEFAULT ) { if ( roar_stream_set_rpg(&(plq->backend->con), &(plq->stream), &(plent->rpg)) == -1 ) { ROAR_WARN("playback_play(queue=%u): Can not set RPG settings: %s", (unsigned)queue, roar_errorstring); } } // set role for new stream: playback_set_role(queue, plq->role); // set volume for next track: playback_set_volume(queue); rpld_pl_unref(pl); ROAR_DBG("playback_play(void) = 0"); return 0; } int playback_next(pli_t queue) { struct rpld_playlist * pl = rpld_pl_get_by_id(queue); struct rpld_queue * plq; struct rpld_playlist_entry * old; int was_playing; ssize_t histsize; // we implement this by stoping the current song, // hoping to the next and restart playing if we was playing. if ( pl == NULL ) return -1; if ( (plq = pl->queue) == NULL ) { rpld_pl_unref(pl); roar_err_set(ROAR_ERROR_TYPEMM); return -1; } roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_NEXT, -1, queue, -1, -1, -1, NULL, -1); was_playing = plq->playing; if ( playback_stop(queue, 0, 1) == -1 ) { rpld_pl_unref(pl); return -1; } // get next element, if there is none try autoqueue. if ( (old = rpld_pl_shift(pl)) == NULL ) if ( autoqueue(queue) != -1 ) old = rpld_pl_shift(pl); if ( old != NULL ) { rpld_pl_add(plq->history, old, -1); histsize = rpld_pl_get_histsize(plq->history); if ( histsize != -1 ) { while ( (ssize_t)rpld_pl_num(plq->history) > histsize ) { old = rpld_pl_pop(plq->history); if ( old != NULL ) rpld_ple_free(old); } } } if ( was_playing ) return playback_play(queue); rpld_pl_unref(pl); return 0; } int playback_prev(pli_t queue) { struct rpld_playlist * pl = rpld_pl_get_by_id(queue); struct rpld_queue * plq; struct rpld_playlist_entry * old; int was_playing; if ( pl == NULL ) return -1; if ( (plq = pl->queue) == NULL ) { rpld_pl_unref(pl); roar_err_set(ROAR_ERROR_TYPEMM); return -1; } roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_PREV, -1, queue, -1, -1, -1, NULL, -1); was_playing = plq->playing; old = rpld_pl_shift(plq->history); if ( old == NULL ) { rpld_pl_unref(pl); return -1; } if ( playback_stop(queue, 0, 1) == -1 ) { rpld_pl_add(plq->history, old, -1); rpld_pl_unref(pl); return -1; } rpld_pl_add(pl, old, -1); rpld_pl_unref(pl); if ( was_playing ) return playback_play(queue); return 0; } int playback_stop(pli_t queue, size_t offset, int kick) { struct rpld_playlist * pl; struct rpld_queue * plq = _get_queue(queue, &pl); if ( plq == NULL ) return -1; if ( !plq->playing ) { rpld_pl_unref(pl); return 0; } roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_STOP, -1, queue, -1, offset, kick, NULL, -1); // first we kick, than we close the IO handles to avoid race conditions. roar_kick(&(plq->backend->con), ROAR_OT_STREAM, roar_stream_get_id(&(plq->stream))); roar_vio_close(&(plq->io.stream)); roar_vio_close(plq->io.fp); plq->playing = 0; memset(&(plq->ple), 0, sizeof(plq->ple)); plq->ple_mduc = 0; rpld_pl_unref(pl); ROAR_DBG("playback_stop(offset=%i, kick=%i) = 0", offset, kick); return 0; } int playback_pause(pli_t queue, int how) { struct rpld_playlist * pl; struct rpld_queue * plq = _get_queue(queue, &pl); struct roar_stream_info info; int reset = -1; if ( plq == NULL ) return -1; if ( !plq->playing ) { rpld_pl_unref(pl); return -1; } switch (how) { case PLAYBACK_PAUSE_TRUE: reset = ROAR_SET_FLAG; break; case PLAYBACK_PAUSE_FALSE: reset = ROAR_RESET_FLAG; break; case PLAYBACK_PAUSE_TOGGLE: #ifdef ROAR_FT_FUNC_SET_FLAGS2 #ifdef ROAR_FT_SONAME_LIBROAR2 #define _set_flags roar_stream_set_flags #else #define _set_flags roar_stream_set_flags2 #endif if ( _set_flags(&(plq->backend->con), &(plq->stream), ROAR_FLAG_PAUSE, ROAR_TOGGLE_FLAG) == 0 ) { rpld_pl_unref(pl); return 0; } #endif if ( roar_stream_get_info(&(plq->backend->con), &(plq->stream), &info) == -1 ) { rpld_pl_unref(pl); return -1; } if ( info.flags & ROAR_FLAG_PAUSE ) { reset = ROAR_RESET_FLAG; } else { reset = ROAR_SET_FLAG; } break; } #ifdef ROAR_FT_FUNC_SET_FLAGS2 return _set_flags(&(plq->backend->con), &(plq->stream), ROAR_FLAG_PAUSE, reset); #else return roar_stream_set_flags(&(plq->backend->con), &(plq->stream), ROAR_FLAG_PAUSE, reset); #endif rpld_pl_unref(pl); roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_PAUSE, -1, queue, -1, how, -1, NULL, -1); } int playback_is_playing(pli_t queue) { struct rpld_playlist * pl; struct rpld_queue * plq = _get_queue(queue, &pl); int ret; if ( plq == NULL ) return 0; ret = plq->playing; rpld_pl_unref(pl); return ret; } char * playback_stream_identifier(pli_t queue) { struct rpld_playlist * pl; struct rpld_queue * plq = _get_queue(queue, &pl); static char buf[32]; if ( plq == NULL ) return 0; if ( !plq->playing ) { rpld_pl_unref(pl); return NULL; } snprintf(buf, sizeof(buf), "%i", roar_stream_get_id(&(plq->stream))); buf[sizeof(buf)-1] = 0; rpld_pl_unref(pl); return buf; } int playback_is_pause(pli_t queue) { struct rpld_playlist * pl; struct rpld_queue * plq = _get_queue(queue, &pl); struct roar_stream_info info; if ( plq == NULL ) return PLAYBACK_PAUSE_FALSE; if ( !plq->playing ) { rpld_pl_unref(pl); return PLAYBACK_PAUSE_FALSE; } if ( roar_stream_get_info(&(plq->backend->con), &(plq->stream), &info) == -1 ) { rpld_pl_unref(pl); return PLAYBACK_PAUSE_FALSE; } rpld_pl_unref(pl); if ( info.flags & ROAR_FLAG_PAUSE ) return PLAYBACK_PAUSE_TRUE; return PLAYBACK_PAUSE_FALSE; } int playback_set_volume(pli_t queue) { struct rpld_playlist * pl; struct rpld_queue * plq = _get_queue(queue, &pl); struct roar_mixer_settings mixer; int id; // stream ID int channels; // nummber of channels int i; if ( plq == NULL ) return -1; // it's an error to enforce a volume in case we are not playing if ( !plq->playing ) { rpld_pl_unref(pl); return -1; } id = roar_stream_get_id(&(plq->stream)); if ( roar_get_vol(&(plq->backend->con), id, &mixer, &channels) == -1 ) { rpld_pl_unref(pl); return -1; } mixer.scale = 65535; mixer.rpg_mul = 1; mixer.rpg_div = 1; for (i = 0; i < channels; i++) mixer.mixer[i] = plq->volume_mono; #ifdef ROAR_FT_SONAME_LIBROAR2 if ( roar_set_vol(&(plq->backend->con), id, &mixer, channels, ROAR_SET_VOL_ALL) == -1 ) { channels = 1; if ( roar_set_vol(&(plq->backend->con), id, &mixer, channels, ROAR_SET_VOL_UNMAPPED) == -1 ) { rpld_pl_unref(pl); return -1; } } #else if ( roar_set_vol(&(plq->backend->con), id, &mixer, channels) == -1 ) { rpld_pl_unref(pl); return -1; } #endif rpld_pl_unref(pl); return 0; } int playback_set_volume_mu16(pli_t queue, uint16_t mono) { struct rpld_playlist * pl; struct rpld_queue * plq = _get_queue(queue, &pl); if ( plq == NULL ) return -1; plq->volume_mono = mono; roar_notify_core_emit_simple(RPLD_NOTIFY_PLAYBACK_VOLUME, -1, queue, -1, mono, -1, NULL, -1); // if we are not playing we are done if ( !plq->playing ) { rpld_pl_unref(pl); return 0; } rpld_pl_unref(pl); return playback_set_volume(queue); } int playback_set_volume_mpc(pli_t queue, int pc) { uint16_t u16 = pc * 655; // correct maximum if ( u16 > 65480 ) u16 = 65535; return playback_set_volume_mu16(queue, u16); } uint16_t playback_get_volume_mu16(pli_t queue) { struct rpld_playlist * pl; struct rpld_queue * plq = _get_queue(queue, &pl); struct roar_mixer_settings mixer; uint32_t s = 0; int channels; // nummber of channels int id; // stream ID int i; if ( plq == NULL ) return 65535; if ( !plq->playing ) { rpld_pl_unref(pl); return plq->volume_mono; } id = roar_stream_get_id(&(plq->stream)); if ( roar_get_vol(&(plq->backend->con), id, &mixer, &channels) == -1 ) { rpld_pl_unref(pl); return plq->volume_mono; } for (i = 0; i < channels; i++) { s += mixer.mixer[i]; } if ( mixer.scale != 65535 ) { s = (float)s / (float)(mixer.scale * channels / 65535.); } else { s /= channels; } plq->volume_mono = s; rpld_pl_unref(pl); return s; } int playback_get_volume_mpc(pli_t queue) { return playback_get_volume_mu16(queue) / 655; } const struct roar_stream * playback_get_stream (pli_t queue) { struct rpld_playlist * pl; struct rpld_queue * plq = _get_queue(queue, &pl); static struct roar_stream stream; // TODO: FIXME: Why don't we just returen the stream object from the plq? if ( plq == NULL ) return NULL; if ( !plq->playing ) { rpld_pl_unref(pl); return NULL; } if ( roar_get_stream(&(plq->backend->con), &stream, roar_stream_get_id(&(plq->stream))) == -1 ) { rpld_pl_unref(pl); return NULL; } rpld_pl_unref(pl); return &stream; } struct rpld_playlist_entry * playback_get_ple (pli_t queue) { struct rpld_playlist * pl; struct rpld_queue * plq = _get_queue(queue, &pl); struct rpld_playlist_entry * plent; struct roar_meta meta; int types[ROAR_META_MAX_PER_STREAM]; int i; int len; char * metadata; size_t metalen; if ( plq == NULL ) return NULL; if ( !plq->playing ) { rpld_pl_unref(pl); return NULL; } plent = &(plq->ple); if ( (len = roar_stream_meta_list(&(plq->backend->con), &(plq->stream), types, ROAR_META_MAX_PER_STREAM)) != -1 ) { for (i = 0; i < len; i++) { metalen = 0; metadata = NULL; switch (types[i]) { case ROAR_META_TYPE_ALBUM: metadata = plent->meta.album; metalen = sizeof(plent->meta.album); break; case ROAR_META_TYPE_TITLE: metadata = plent->meta.title; metalen = sizeof(plent->meta.title); break; case ROAR_META_TYPE_ARTIST: metadata = plent->meta.artist; metalen = sizeof(plent->meta.artist); break; case ROAR_META_TYPE_PERFORMER: metadata = plent->meta.performer; metalen = sizeof(plent->meta.performer); break; case ROAR_META_TYPE_VERSION: metadata = plent->meta.version; metalen = sizeof(plent->meta.version); break; /* TODO: FIXME: add support for this case ROAR_META_TYPE_TRACKNUMBER: plent->meta.tracknum = atoi(delm); continue; break; case ROAR_META_TYPE_GENRE: plent->meta.genre = roar_meta_intgenre(delm); continue; break; case ROAR_META_TYPE_DISCID: sscanf(delm, "%8x", &(plent->meta.discid)); continue; break; */ default: metalen = 0; continue; break; } if ( metalen != 0 ) { meta.type = types[i]; if ( roar_stream_meta_get(&(plq->backend->con), &(plq->stream), &meta) != -1 ) { plq->ple_mduc++; strncpy(metadata, meta.value, metalen); metadata[metalen-1] = 0; roar_meta_free(&meta); } } } } rpld_pl_unref(pl); return plent; } size_t playback_get_mduc(pli_t queue) { struct rpld_playlist * pl; struct rpld_queue * plq = _get_queue(queue, &pl); size_t ret; if ( plq == NULL ) return 0; ret = plq->ple_mduc; rpld_pl_unref(pl); return ret; } //ll rpld-0.1.9/playback.h0000644000175000017500000000647212266574305012566 0ustar phiphi//playback.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_PLAYBACK_H_ #define _RPLD_PLAYBACK_H_ #define PLAYBACK_PAUSE_TRUE 1 #define PLAYBACK_PAUSE_FALSE 0 #define PLAYBACK_PAUSE_TOGGLE 2 struct rpld_queue { size_t refc; int playing; size_t stop_offset; int kick_on_stop; int role; // conf. int mixer; // conf. struct rpld_playlist * history; // conf. struct rpld_backend * backend; // conf. struct roar_stream stream; struct { struct roar_vio_calls file; struct roar_vio_calls stream; struct roar_vio_calls filter; struct roar_vio_calls * fp; } io; uint16_t volume_mono; // conf., scale is 2^16-1 struct rpld_playlist_entry ple; size_t ple_mduc; struct { struct rpld_playlist_pointer * currentptr; struct rpld_playlist_pointer * defaultptr; struct rpld_playlist_pointer * startupptr; struct rpld_playlist_pointer * fallbackptr; } pointers; }; int playback_preinit(void); int playback_init(void); void playback_uninit(void); void playback_set_role(pli_t queue, const int role); struct roar_audio_info * playback_get_codechelper_info(void); void playback_check(int block); int playback_add_queue(struct rpld_playlist * pl, const char * backend, int mixer, struct rpld_playlist * history); int playback_del_queue(struct rpld_playlist * pl); int playback_has_queue(pli_t queue); int playback_set_pointer(pli_t queue, int pointer, struct rpld_playlist_pointer * plp); struct rpld_playlist_pointer * playback_get_pointer(pli_t queue, int pointer); // start or stop all queues. void playback_play_all(void); void playback_stop_all(size_t offset, int kick); // test if at least one queue is playing. int playback_is_playing_any(void); int playback_play(pli_t queue); int playback_next(pli_t queue); int playback_prev(pli_t queue); int playback_stop(pli_t queue, size_t offset, int kick); int playback_pause(pli_t queue, int how); int playback_is_playing(pli_t queue); char * playback_stream_identifier(pli_t queue); int playback_is_pause(pli_t queue); int playback_set_volume(pli_t queue); int playback_set_volume_mu16(pli_t queue, uint16_t mono); /* relative to 2^16-1 */ int playback_set_volume_mpc(pli_t queue, int pc); /* in % */ uint16_t playback_get_volume_mu16(pli_t queue); int playback_get_volume_mpc(pli_t queue); const struct roar_stream * playback_get_stream (pli_t queue); struct rpld_playlist_entry * playback_get_ple (pli_t queue); size_t playback_get_mduc(pli_t queue); #endif //ll rpld-0.1.9/playlist.c0000644000175000017500000007353512266574305012640 0ustar phiphi //playlist.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" #include struct rpld_playlist * g_playlists[MAX_PLAYLISTS]; struct rpld_playlist_entry * rpld_ple_new (void) { struct rpld_playlist_entry * plent = roar_mm_malloc(sizeof(struct rpld_playlist_entry)); static uint64_t counter = 0; unsigned char rand_data = roar_random_uint16() & 0xFF; if ( plent == NULL ) return NULL; memset(plent, 0, sizeof(struct rpld_playlist_entry)); plent->global_tracknum = (((ei_t )getpid() & 0xFF) << 56) | (((uint64_t)RPLD_PL_MAGIC) << 48) | (counter << 8) | rand_data; plent->global_short_tracknum = (((ei_short_t)getpid() & 0xFF) << 24) ^ (counter & 0x00FF0000) >> 16; plent->global_short_tracknum |= (counter & 0xFFFF) << 8; plent->global_short_tracknum |= rand_data ^ RPLD_PL_MAGIC; plent->flags = RPLD_PLE_FLAG_UNSKIPABLE; plent->start = -1; plent->end = -1; plent->wallclock_start = RPLD_PLE_WALLCLOCK_INVALID; plent->rpg.mode = ROAR_RPGMODE_DEFAULT; plent->rpg.mul = 1; plent->rpg.div = 1; plent->codec = -1; plent->io.filenames = NULL; plent->io.num = 0; plent->io.slots = 0; plent->meta.genre = -1; plent->meta.extra.kv = NULL; plent->meta.extra.kvlen = -1; plent->meta.extra.kv_store = NULL; plent->meta.extra.kv_storelen = -1; plent->likeness = 1; roar_uuid_gen_random(plent->uuid); counter++; return plent; } void rpld_ple_free (struct rpld_playlist_entry * plent) { ssize_t i; if ( plent == NULL ) return; if ( plent->meta.extra.kv_store != NULL ) roar_mm_free(plent->meta.extra.kv_store); if ( plent->meta.extra.kv != NULL ) roar_mm_free(plent->meta.extra.kv); if ( plent->io.filenames != NULL ) { for (i = 0; i < plent->io.num; i++ ) roar_mm_free(plent->io.filenames[i].filename); roar_mm_free(plent->io.filenames); } memset(plent, 0, sizeof(*plent)); strncpy(plent->meta.title, "<<>>", sizeof(plent->meta.title)); roar_mm_free(plent); } static inline struct rpld_filename * __copy_filenames(const struct rpld_filename * src, ssize_t len) { struct rpld_filename * ret; ssize_t i; int err; if ( len < 1 ) return NULL; ret = roar_mm_malloc(sizeof(struct rpld_filename)*len); if ( ret == NULL ) return NULL; for (i = 0; i < len; i++) { ret[i] = src[i]; ret[i].filename = roar_mm_strdup(src[i].filename); if ( ret[i].filename == NULL ) { err = roar_error; for (i--; i >= 0; i--) roar_mm_free(ret[i].filename); roar_mm_free(ret); roar_err_set(err); return NULL; } } return ret; } struct rpld_playlist_entry * rpld_ple_copy (struct rpld_playlist_entry * plent) { struct rpld_playlist_entry * ret = NULL; ei_t trknl; ei_short_t trkns; int err; if ( plent == NULL ) return NULL; if ( (ret = rpld_ple_new()) == NULL ) return NULL; trknl = ret->global_tracknum; trkns = ret->global_short_tracknum; memcpy(ret, plent, sizeof(struct rpld_playlist_entry)); memset(&(ret->list), 0, sizeof(ret->list)); memset(&(ret->meta.extra), 0, sizeof(ret->meta.extra)); ret->global_tracknum = trknl; ret->global_short_tracknum = trkns; ret->meta.extra.kv_store = roar_keyval_copy(&(ret->meta.extra.kv), plent->meta.extra.kv, plent->meta.extra.kvlen); ret->meta.extra.kv_storelen = -1; if ( ret->meta.extra.kv_store != NULL ) ret->meta.extra.kvlen = plent->meta.extra.kvlen; ret->io.filenames = __copy_filenames(plent->io.filenames, plent->io.num); if ( ret->io.filenames == NULL ) { err = roar_error; rpld_ple_free(ret); roar_err_set(err); } return ret; } struct rpld_playlist_entry * rpld_ple_cut_out_next (struct rpld_playlist_entry * plent) { struct rpld_playlist_entry * next; if ( plent == NULL ) return NULL; // test if there is a next element in chain: if ( (next = plent->list.next) == NULL ) return NULL; plent->list.next = next->list.next; memset(&(next->list), 0, sizeof(next->list)); return next; } const char * rpld_ple_time_hr (const struct rpld_playlist_entry * plent) { static char buf[32]; struct tm tm; time_t length = plent->length; tm.tm_hour = length / 3600; length = length % 3600; tm.tm_min = length / 60; length = length % 60; tm.tm_sec = length; snprintf(buf, 31, "%.2u:%.2u:%.2u", tm.tm_hour, tm.tm_min, tm.tm_sec); buf[31] = 0; return buf; } int rpld_ple_set_time_hr (struct rpld_playlist_entry * plent, char * time) { char * cur; char * next; time_t length = 0; if ( plent == NULL || time == NULL ) return -1; cur = time; while ( cur != NULL ) { next = strstr(cur, ":"); if ( next != NULL ) { *next = 0; next++; } length *= 60; length += atol(cur); cur = next; } plent->length = length; return 0; } enum rpld_filename_type rpld_ple_get_filenametype(const char * type) { const struct { const enum rpld_filename_type type; const char * name; } names[] = { {RPLD_TYPE_ERROR, "error"}, {RPLD_TYPE_UNKNOWN, "unknown"}, {RPLD_TYPE_AUTOLOCATE, "autolocate"}, {RPLD_TYPE_STREAMURL, "streamurl"}, {RPLD_TYPE_FILENAME, "filename"}, {RPLD_TYPE_FILEURL, "fileurl"} }; size_t i; if ( type == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return RPLD_TYPE_ERROR; } for (i = 0; i < (sizeof(names)/sizeof(*names)); i++) { if ( !!strcasecmp(names[i].name, type) ) continue; roar_err_set(ROAR_ERROR_NONE); return names[i].type; } roar_err_set(ROAR_ERROR_NOENT); return RPLD_TYPE_ERROR; } int rpld_ple_push_filename(struct rpld_playlist_entry * plent, const char * filename, enum rpld_filename_type type, int clear) { const char * tantalos; void * tmp; ssize_t i; ROAR_DBG("rpld_ple_push_filename(plent=%p, filename='%s', type=%i, clear=%i) = ?", plent, filename, (int)type, clear); if ( plent == NULL || filename == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } switch (type) { case RPLD_TYPE_ERROR: roar_err_set(ROAR_ERROR_INVAL); return -1; break; case RPLD_TYPE_UNKNOWN: if ( !strncmp(filename, "tantalos://", 11) ) { type = RPLD_TYPE_AUTOLOCATE; } else if ( !strncmp(filename, "file://", 7) ) { type = RPLD_TYPE_FILENAME; } else if ( !strncmp(filename, "icy://", 6) ) { type = RPLD_TYPE_STREAMURL; } break; #ifndef DEBUG default: /* make gcc not warn about missing cases */ break; #endif } tantalos = rpld_ple_get_filename(plent, plent->io.num, NULL); if ( tantalos != NULL ) { if ( !strcmp(tantalos, filename) ) { roar_err_set(ROAR_ERROR_ALREADY); return -1; } } for (i = 0; i < plent->io.num; i++) { if ( !strcmp(plent->io.filenames[i].filename, filename) && plent->io.filenames[i].type == type ) { roar_err_set(ROAR_ERROR_ALREADY); return -1; } } ROAR_DBG("rpld_ple_push_filename(plent=%p, filename='%s', type=%i, clear=%i) = ?", plent, filename, (int)type, clear); if ( plent->io.slots == plent->io.num ) { tmp = roar_mm_realloc(plent->io.filenames, (plent->io.slots + 8)*sizeof(*plent->io.filenames)); if ( tmp == NULL ) return -1; plent->io.slots += 8; plent->io.filenames = tmp; } ROAR_DBG("rpld_ple_push_filename(plent=%p, filename='%s', type=%i, clear=%i) = ?", plent, filename, (int)type, clear); if ( clear ) { for (i = 0; i < plent->io.num; i++) roar_mm_free(plent->io.filenames[plent->io.num].filename); plent->io.num = 0; } plent->io.filenames[plent->io.num].filename = roar_mm_strdup(filename); plent->io.filenames[plent->io.num].type = type; plent->io.num++; ROAR_DBG("rpld_ple_push_filename(plent=%p, filename='%s', type=%i, clear=%i) = 0", plent, filename, (int)type, clear); return 0; } const char * rpld_ple_get_filename(struct rpld_playlist_entry * plent, ssize_t index, enum rpld_filename_type * type) { ssize_t max_index; char uuid[37]; ROAR_DBG("rpld_ple_get_filename(plent=%p, index=%lli, type=%p) = ?", plent, (long long int)index, type); if ( plent == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return NULL; } max_index = rpld_ple_num_filename(plent); if ( max_index == -1 ) return NULL; max_index--; if ( index == -1 ) index = 0; if ( index < 0 ) { roar_err_set(ROAR_ERROR_INVAL); return NULL; } else if ( index == max_index ) { roar_uuid2str(uuid, plent->uuid, sizeof(uuid)); snprintf(plent->io.tantalos, sizeof(plent->io.tantalos), "tantalos://%s", uuid); plent->io.tantalos[sizeof(plent->io.tantalos)-1] = 0; if ( type != NULL ) *type = RPLD_TYPE_AUTOLOCATE; return plent->io.tantalos; } else if ( index >= max_index ) { roar_err_set(ROAR_ERROR_NOENT); return NULL; } if ( type != NULL ) *type = plent->io.filenames[index].type; ROAR_DBG("rpld_ple_get_filename(plent=%p, index=%lli, type=%p) = ?", plent, (long long int)index, type); (void)(volatile typeof(plent->io.filenames[index]))plent->io.filenames[index]; return plent->io.filenames[index].filename; } ssize_t rpld_ple_num_filename(const struct rpld_playlist_entry * plent) { if ( plent == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } return plent->io.num + 1; } static inline int __iscasein(const char * haystack, const char * needle) { size_t i, j; int lower_first = tolower(*needle); // consider the following magic. for (i = 0; haystack[i]; i++) { if ( tolower(haystack[i]) == lower_first ) { for (j = 0; haystack[i+j] && needle[j]; j++) if ( tolower(haystack[i+j]) != tolower(needle[j]) ) break; if ( !needle[j] ) return 1; } } return 0; } int rpld_ple_filter (struct rpld_playlist_entry * plent, const void * needle, const char * key, int options) { const char * barn[8]; const char ** haystacks; ssize_t haystackcount = 0; ssize_t filenamecount = -1; ssize_t i, j; ssize_t needlelen; int ret = 0; union { const ei_t * ei; const ei_short_t * ei_short; const roar_uuid_t * uuid; const discid_t * discid; const int * si; const char * str; const void * vp; } subject; subject.vp = needle; // a key of NULL is valid and means 'search in all keys'. if ( plent == NULL || needle == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } // if no sources are given this doesn't match. if ( !(options & (RPLD_PLE_FILTER_NORMKEY|RPLD_PLE_FILTER_EXTKEY)) ) return 0; if ( options & RPLD_PLE_FILTER_BNEEDLE ) { // we can not do a binary search on non-binary data. if ( options & RPLD_PLE_FILTER_EXTKEY ) { roar_err_set(ROAR_ERROR_INVAL); return -1; } // key needs to be given as we use it as type in binary mode. if ( key == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } if ( !strcasecmp(key, "long") ) { return *subject.ei == plent->global_tracknum ? 1 : 0; } else if ( !strcasecmp(key, "short") ) { return *subject.ei_short == plent->global_short_tracknum ? 1 : 0; } else if ( !strcasecmp(key, "uuid") ) { return roar_uuid_eq(*subject.uuid, plent->uuid); } else if ( !strcasecmp(key, "discid") ) { return *subject.discid == plent->meta.discid ? 1 : 0; } else if ( !strcasecmp(key, "genre") ) { return *subject.si == plent->meta.genre ? 1 : 0; } else if ( !strcasecmp(key, "tracknum") || !strcasecmp(key, "tracknumber") ) { return *subject.si == plent->meta.tracknum ? 1 : 0; } else { roar_err_set(ROAR_ERROR_NOTSUP); return -1; } } // first count how many keys we need to search: if ( options & RPLD_PLE_FILTER_NORMKEY ) { #define _ck(keyname) if ( key == NULL || !strcasecmp(key, (keyname)) ) { haystackcount++; } _ck("album") _ck("title") _ck("artist") _ck("performer") _ck("version") #undef _ck if ( key == NULL || !strcasecmp(key, "filename") ) { filenamecount = rpld_ple_num_filename(plent); if ( filenamecount > 0 ) haystackcount += filenamecount; } } if ( (options & RPLD_PLE_FILTER_EXTKEY) && plent->meta.extra.kv != NULL ) for (i = 0; i < plent->meta.extra.kvlen; i++) if ( plent->meta.extra.kv[i].key != NULL && (key == NULL || !strcasecmp(plent->meta.extra.kv[i].key, key)) ) haystackcount++; // now allocate space for all the hay: if ( haystackcount <= (ssize_t)(sizeof(barn)/sizeof(*barn)) ) { haystacks = barn; } else { haystacks = roar_mm_malloc(haystackcount*sizeof(*haystacks)); if ( haystacks == NULL ) return -1; } // Build the list of haystacks: j = 0; if ( options & RPLD_PLE_FILTER_NORMKEY ) { #define _ck(keyname,member) if ( key == NULL || !strcasecmp(key, (keyname)) ) { haystacks[j++] = plent->member; } _ck("album", meta.album) _ck("title", meta.title) _ck("artist", meta.artist) _ck("performer", meta.performer) _ck("version", meta.version) #undef _ck if ( key == NULL || !strcasecmp(key, "filename") ) { for (i = 0; i < filenamecount; i++) { haystacks[j++] = rpld_ple_get_filename(plent, i, NULL); } } } if ( (options & RPLD_PLE_FILTER_EXTKEY) && plent->meta.extra.kv != NULL ) for (i = 0; i < plent->meta.extra.kvlen; i++) if ( plent->meta.extra.kv[i].key != NULL && (key == NULL || !strcasecmp(plent->meta.extra.kv[i].key, key)) ) haystacks[j++] = plent->meta.extra.kv[i].value; // now do the search: // TODO: this should be optimized. needlelen = roar_mm_strlen(subject.str); for (i = 0; !ret && i < haystackcount; i++) { if ( haystacks[i] == NULL ) continue; if ( (options & RPLD_PLE_FILTER_ANCHORB) & (options & RPLD_PLE_FILTER_ANCHORE) ) { if ( options & RPLD_PLE_FILTER_CASE ) { if ( !strcmp(haystacks[i], subject.str) ) ret = 1; } else { if ( !strcasecmp(haystacks[i], subject.str) ) ret = 1; } } else if ( options & RPLD_PLE_FILTER_ANCHORB ) { if ( options & RPLD_PLE_FILTER_CASE ) { if ( !strncmp(haystacks[i], subject.str, needlelen) ) ret = 1; } else { if ( !strncasecmp(haystacks[i], subject.str, needlelen) ) ret = 1; } } else if ( options & RPLD_PLE_FILTER_ANCHORE ) { j = roar_mm_strlen(haystacks[i]); if ( needlelen > j ) continue; if ( options & RPLD_PLE_FILTER_CASE ) { if ( !strcmp(haystacks[i] + j - needlelen, subject.str) ) ret = 1; } else { if ( !strcasecmp(haystacks[i] + j - needlelen, subject.str) ) ret = 1; } } else { if ( options & RPLD_PLE_FILTER_CASE ) { if ( strstr(haystacks[i], subject.str) != NULL ) ret = 1; } else { ret = __iscasein(haystacks[i], subject.str); } } } // Free space space we alloced because barn was too small. if ( haystacks != barn ) roar_mm_free(haystacks); return ret; } struct rpld_playlist * rpld_pl_new (void) { struct rpld_playlist * pl = roar_mm_malloc(sizeof(struct rpld_playlist)); if ( pl == NULL ) return NULL; memset(pl, 0, sizeof(struct rpld_playlist)); pl->refc = 1; pl->histsize = -1; return pl; } int rpld_pl_ref (struct rpld_playlist * pl) { if ( pl == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } pl->refc++; return 0; } int rpld_pl_unref (struct rpld_playlist * pl) { if ( pl == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } pl->refc--; if ( pl->refc == 1 && pl->name == NULL ) { if ( rpld_pl_unregister(pl) == 0 ) return 0; } if ( pl->refc ) return 0; rpld_pl_flush(pl); if ( pl->queue != NULL ) playback_del_queue(pl); if ( pl->id ) rpld_pl_unregister(pl); if ( pl->name != NULL ) roar_mm_free(pl->name); roar_mm_free(pl); return 0; } void rpld_pl_push (struct rpld_playlist * pl, struct rpld_playlist_entry * plent) { struct rpld_playlist_entry * next = pl->first; struct rpld_playlist_entry * last; if ( next == NULL ) { pl->first = plent; } else { while (next != NULL) { last = next; next = next->list.next; } last->list.next = plent; } pl->likeness_hint += plent->likeness; pl->size_hint++; } void rpld_pl_add (struct rpld_playlist * pl, struct rpld_playlist_entry * plent, ssize_t pos) { struct rpld_playlist_entry * next = pl->first; struct rpld_playlist_entry * last; if ( pos == -1 ) { plent->list.next = pl->first; pl->first = plent; pl->likeness_hint += plent->likeness; pl->size_hint++; return; } if ( pos < 0 ) return; pl->likeness_hint += plent->likeness; pl->size_hint++; if ( next == NULL ) { pl->first = plent; } else { while (next != NULL) { // printf("pos=%lu, next=%p\n", (unsigned long)pos, next); if ( pos == 0 ) { plent->list.next = next->list.next; next->list.next = plent; return; } pos--; last = next; next = next->list.next; } last->list.next = plent; } } struct rpld_playlist_entry * rpld_pl_get_first(struct rpld_playlist * pl) { if ( pl == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return NULL; } if ( pl->flags & RPLD_PL_FLAG_VIRTUAL ) { return pl->first->list.next; } else { return pl->first; } } struct rpld_playlist_entry * rpld_pl_shift (struct rpld_playlist * pl) { struct rpld_playlist_entry * first = pl->first; if ( pl->first == NULL ) { roar_err_set(ROAR_ERROR_NOENT); return NULL; } else { if ( pl->flags & RPLD_PL_FLAG_VIRTUAL ) { first = first->list.next; pl->first->list.next = first->list.next; } else { pl->first = first->list.next; } pl->likeness_hint -= first->likeness; pl->size_hint--; memset(&(first->list), 0, sizeof(first->list)); return first; } } struct rpld_playlist_entry * rpld_pl_pop (struct rpld_playlist * pl) { struct rpld_playlist_entry * cur = pl->first; struct rpld_playlist_entry * old = NULL; struct rpld_playlist_entry * next; if ( pl->flags & RPLD_PL_FLAG_VIRTUAL ) { old = cur; cur = cur->list.next; } if ( cur == NULL ) { roar_err_set(ROAR_ERROR_NOENT); return NULL; } while ((next = cur->list.next) != NULL) { old = cur; cur = next; } if ( old == NULL ) { pl->first = NULL; } else { old->list.next = NULL; } pl->likeness_hint -= cur->likeness; pl->size_hint--; return cur; } void rpld_pl_flush (struct rpld_playlist * pl) { struct rpld_playlist_entry * next = pl->first; struct rpld_playlist_entry * cur; while (next != NULL) { cur = next; next = next->list.next; rpld_ple_free(cur); } pl->first = NULL; if ( pl->flags & RPLD_PL_FLAG_VIRTUAL ) pl->flags -= RPLD_PL_FLAG_VIRTUAL; pl->size_hint = 0; pl->likeness_hint = 0; } static float rand_float(float max); static size_t rand_size_t(size_t max) { /* size_t ret = rand() * max; ROAR_DBG("rand_size_t(max=%zu) = ?", max); return ret / RAND_MAX; */ return rand_float((float)max); } static float rand_float(float max) { const float range = 65535.; float ret = (float)roar_random_uint16(); ret *= max; ROAR_DBG("rand_size_t(max=%f) = ?", (double)max); return ret / range; } struct rpld_playlist_entry * rpld_pl_search (struct rpld_playlist * pl, struct rpld_playlist_search * search, struct rpld_playlist_entry * pmatch) { struct rpld_playlist_entry * cur = NULL; struct rpld_playlist_entry * prev = NULL; size_t counter = 0; float likeness = 0.0; size_t target_num = 0; float target_likeness = 0.0; if ( pl == NULL || search == NULL ) return NULL; ROAR_DBG("rpld_pl_search(*) = ?"); ROAR_DBG("rpld_pl_search(*): pl ID=%i", rpld_pl_get_id(pl)); switch (search->type) { case RPLD_PL_ST_NUM: target_num = search->subject.num; break; case RPLD_PL_ST_LIKENESS: target_likeness = search->subject.likeness; break; case RPLD_PL_ST_RANDOM: target_num = rand_size_t(pl->size_hint); break; case RPLD_PL_ST_RANDOM_LIKENESS: target_likeness = rand_float(pl->likeness_hint); break; } if ( search->options & RPLD_PL_SO_PREVIOUS ) { if ( rpld_pl_virtual(pl, RPLD_PL_VIRT_CREATE) != 0 ) return NULL; } ROAR_DBG("rpld_pl_search(*) = ?"); cur = pl->first; if ( pl->flags & RPLD_PL_FLAG_VIRTUAL ) { prev = cur; cur = cur->list.next; } if ( pmatch != NULL ) { prev = pmatch; cur = prev->list.next; } ROAR_DBG("rpld_pl_search(*) = ?"); #define _match() \ if ( search->options & RPLD_PL_SO_PREVIOUS ) { \ return prev; \ } else { \ return cur; \ } while (cur != NULL) { likeness += cur->likeness; switch (search->type) { case RPLD_PL_ST_TRACKNUM_LONG: if ( cur->global_tracknum == search->subject.long_tracknum ) { _match(); } break; case RPLD_PL_ST_TRACKNUM_SHORT: if ( cur->global_short_tracknum == search->subject.short_tracknum ) { _match(); } break; case RPLD_PL_ST_UUID: if ( roar_uuid_eq(cur->uuid, search->subject.uuid) ) { _match(); } break; case RPLD_PL_ST_NUM: case RPLD_PL_ST_RANDOM: if ( counter == target_num ) { _match(); } break; case RPLD_PL_ST_LIKENESS: case RPLD_PL_ST_RANDOM_LIKENESS: if ( likeness >= target_likeness ) { _match(); } break; default: return NULL; } prev = cur; cur = cur->list.next; counter++; } #undef _match // update _hints: if ( pmatch == NULL ) { pl->size_hint = counter; pl->likeness_hint = likeness; } // if we did not found any entry, but on random search we need to re-search with updated hints: if ( pmatch == NULL && counter > 0 ) { if ( search->type == RPLD_PL_ST_RANDOM || search->type == RPLD_PL_ST_RANDOM_LIKENESS ) { return rpld_pl_search(pl, search, pmatch); } } ROAR_DBG("rpld_pl_search(*) = ?"); return NULL; } int rpld_pl_virtual (struct rpld_playlist * pl, int virt) { struct rpld_playlist_entry * plent; if ( pl == NULL ) return -1; switch (virt) { case RPLD_PL_VIRT_KEEP: return 0; break; case RPLD_PL_VIRT_DELETE: if ( !(pl->flags & RPLD_PL_FLAG_VIRTUAL) ) return 0; plent = pl->first; pl->first = plent->list.next; rpld_ple_free(plent); pl->flags -= RPLD_PL_FLAG_VIRTUAL; return 0; break; case RPLD_PL_VIRT_CREATE: if ( pl->flags & RPLD_PL_FLAG_VIRTUAL ) return 0; plent = rpld_ple_new(); if ( plent == NULL ) return -1; plent->list.next = pl->first; pl->first = plent; pl->flags |= RPLD_PL_FLAG_VIRTUAL; return 0; break; } return -1; } int rpld_pl_merge (struct rpld_playlist * pl, struct rpld_playlist * tm) { struct rpld_playlist_entry * ple; ROAR_DBG("rpld_pl_merge(pl=%p, tm=%p) = ?", pl, tm); if ( pl == NULL || tm == NULL ) return -1; rpld_pl_unregister(tm); if ( rpld_pl_virtual(tm, RPLD_PL_VIRT_DELETE) == -1 ) { return -1; } ple = tm->first; tm->first = NULL; if ( ple != NULL ) { rpld_pl_push(pl, ple); pl->size_hint += tm->size_hint - 1; pl->likeness_hint += tm->likeness_hint - ple->likeness; } rpld_pl_unref(tm); return 0; } int rpld_pl_set_name (struct rpld_playlist * pl, const char * name) { if ( pl == NULL ) return -1; if ( pl->name != NULL ) roar_mm_free(pl->name); if ( name == NULL ) { pl->name = NULL; return 0; } pl->name = roar_mm_strdup(name); if ( pl->name != NULL ) return 0; return -1; } char * rpld_pl_get_name (struct rpld_playlist * pl) { if ( pl == NULL ) return NULL; return pl->name; } int rpld_pl_set_id (struct rpld_playlist * pl, pli_t id) { if ( pl == NULL ) return -1; pl->id = id; return 0; } pli_t rpld_pl_get_id (struct rpld_playlist * pl) { if ( pl == NULL ) return 0; return pl->id; } int rpld_pl_set_parent(struct rpld_playlist * pl, pli_t parent) { if ( pl == NULL ) return -1; pl->parent = parent; return 0; } pli_t rpld_pl_get_parent(struct rpld_playlist * pl) { if ( pl == NULL ) return 0; return pl->parent; } int rpld_pl_set_histsize(struct rpld_playlist * pl, ssize_t size) { if ( pl == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } // this may be reported as warning on some platforms. // if you split such a case please open a ticket at our bug tracker // or contact us via some other way. Thanks. if ( size < -1 ) size = -1; pl->histsize = size; return 0; } ssize_t rpld_pl_get_histsize(struct rpld_playlist * pl) { if ( pl == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } if ( pl->histsize == -1 ) { roar_err_set(ROAR_ERROR_TYPEMM); return -1; } return pl->histsize; } int rpld_pl_register (struct rpld_playlist * pl) { static pli_t counter = 0; int i; if ( pl == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } for (i = 0; i < MAX_PLAYLISTS; i++) { if ( g_playlists[i] == NULL ) { counter++; g_playlists[i] = pl; rpld_pl_ref(pl); // TODO: support tables sizes > 256 entrys return rpld_pl_set_id(pl, (counter << 8) | i); } } return -1; } int rpld_pl_register_id(struct rpld_playlist * pl, pli_t id) { int index = id % MAX_PLAYLISTS; if ( pl == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } if ( g_playlists[index] != NULL ) { roar_err_set(ROAR_ERROR_EXIST); return -1; } g_playlists[index] = pl; rpld_pl_ref(pl); return rpld_pl_set_id(pl, id); } int rpld_pl_unregister(struct rpld_playlist * pl) { int index; if ( pl == NULL ) return -1; index = pl->id % MAX_PLAYLISTS; if ( g_playlists[index] != pl ) return -1; rpld_pl_unref(g_playlists[index]); g_playlists[index] = NULL; return 0; } struct rpld_playlist * rpld_pl_get_by_id (pli_t id) { struct rpld_playlist * ret = g_playlists[id % MAX_PLAYLISTS]; ROAR_DBG("rpld_pl_get_by_id(id=%i) = ?", (int)id); if ( ret == NULL ) { roar_err_set(ROAR_ERROR_NOENT); return NULL; } rpld_pl_ref(ret); return ret; } struct rpld_playlist * rpld_pl_get_by_name(const char * name) { struct rpld_playlist * c; int i; if ( name == NULL ) return NULL; for (i = 0; i < MAX_PLAYLISTS; i++) { c = g_playlists[i]; if ( c != NULL ) { if ( c->name != NULL && !strcmp(c->name, name) ) { rpld_pl_ref(c); return c; } } } return NULL; } size_t rpld_pl_num (struct rpld_playlist * pl) { struct rpld_playlist_entry * cur, * next; size_t count = 0; if ( pl == NULL ) return 0; cur = rpld_pl_get_first(pl); while ( cur != NULL ) { count++; next = cur->list.next; if ( next == cur ) { ROAR_ERR("rpld_pl_num(pl=%p): Application error: PLE %p points to itself as next.", pl, cur); roar_panic(ROAR_FATAL_ERROR_MEMORY_CORRUPTION, NULL); return count; } cur = next; } return count; } struct rpld_playlist_pointer * rpld_plp_init (struct rpld_playlist * pl, struct rpld_playlist_search * pls) { struct rpld_playlist_pointer * plp = roar_mm_malloc(sizeof(struct rpld_playlist_pointer)); if ( plp == NULL ) return NULL; memset(plp, 0, sizeof(struct rpld_playlist_pointer)); plp->refc = 1; if ( pl != NULL ) { plp->hint.pl = pl; rpld_pl_ref(pl); } if ( pls != NULL ) { memcpy(&(plp->pls), pls, sizeof(struct rpld_playlist_search)); } return plp; } int rpld_plp_ref (struct rpld_playlist_pointer * plp) { if ( plp == NULL ) return -1; plp->refc++; return 0; } int rpld_plp_unref (struct rpld_playlist_pointer * plp) { if ( plp == NULL ) return -1; plp->refc--; if ( plp->refc ) return 0; if ( plp->hint.pl != NULL ) rpld_pl_unref(plp->hint.pl); roar_mm_free(plp); return 0; } struct rpld_playlist_entry * rpld_plp_search (struct rpld_playlist_pointer * plp) { struct rpld_playlist_entry * ple; struct rpld_playlist * pl; int i; ROAR_DBG("rpld_plp_search(*) = ?"); if ( plp == NULL ) return NULL; if ( plp->hint.pl != NULL ) { ROAR_DBG("rpld_plp_search(*): We have a playlist hint"); return rpld_pl_search(plp->hint.pl, &(plp->pls), NULL); } if ( plp->pls.type == RPLD_PL_ST_RANDOM || plp->pls.type == RPLD_PL_ST_RANDOM_LIKENESS ) { ROAR_DBG("rpld_plp_search(*): We have a random search."); pl = rpld_pl_get_by_id(plp->pls.subject.pl); ple = rpld_pl_search(pl, &(plp->pls), NULL); rpld_pl_unref(pl); return ple; } ROAR_DBG("rpld_plp_search(*): No Playlist hint, searching..."); // add some way to search multiple playlists for (i = 0; i < MAX_PLAYLISTS; i++) { if ( rpld_pl_get_histsize(g_playlists[i]) != -1 ) continue; if ( g_playlists[i] != NULL ) { if ( (ple = rpld_pl_search(g_playlists[i], &(plp->pls), NULL)) != NULL ) return ple; } } ROAR_DBG("rpld_plp_search(*): No matches found."); ROAR_DBG("rpld_plp_search(*) = NULL"); return NULL; } int rpld_plp_copy (struct rpld_playlist_pointer ** dst, struct rpld_playlist_pointer * src) { if ( dst == NULL || src == NULL ) return -1; if ( *dst != NULL ) if ( rpld_plp_unref(*dst) == -1 ) return -1; if ( (*dst = rpld_plp_init(src->hint.pl, &(src->pls))) == NULL ) return -1; return 0; } //ll rpld-0.1.9/playlist.h0000644000175000017500000002217312266574305012635 0ustar phiphi//playlist.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_PLAYLIST_H_ #define _RPLD_PLAYLIST_H_ #define MAX_PLAYLISTS 64 #define RPLD_MAX_PLF_LEN 1024 #define RPLD_META_SHORT_LEN 384 /* 1024*3/8, well above the 255/256 limit of some applications */ #define RPLD_PL_MAGIC 0xD9 typedef unsigned int pli_t; typedef uint64_t ei_t; typedef uint32_t ei_short_t; typedef uint32_t discid_t; // PLE flags: #define RPLD_PLE_FLAG_NONE 0x0000 #define RPLD_PLE_FLAG_UNSKIPABLE 0x0001 // PLE Wallclock time parameters: #define RPLD_PLE_WALLCLOCK_INVALID ((time_t)770248800L) // PLE filter options: #define RPLD_PLE_FILTER_NONE 0x0000 #define RPLD_PLE_FILTER_NORMKEY 0x0001 /* search in normal keys */ #define RPLD_PLE_FILTER_EXTKEY 0x0002 /* search in extra keys */ #define RPLD_PLE_FILTER_CASE 0x0004 /* search case sensetive */ #define RPLD_PLE_FILTER_ANCHORB 0x0008 /* "begin" anchor: ^ */ #define RPLD_PLE_FILTER_ANCHORE 0x0010 /* "end" anchor: $ */ #define RPLD_PLE_FILTER_BNEEDLE 0x0020 /* needle is binary (uuid, GTN, ...) */ // ???: #define RPLD_PL_FLAG_NONE 0x0000 #define RPLD_PL_FLAG_VIRTUAL 0x0001 #define RPLD_PL_FLAG_UNLINKED 0x0002 #define RPLD_PL_VIRT_DELETE -1 #define RPLD_PL_VIRT_KEEP 0 #define RPLD_PL_VIRT_CREATE +1 // PlayList SearchType #define RPLD_PL_ST_NONE 0 #define RPLD_PL_ST_TRACKNUM_LONG 1 #define RPLD_PL_ST_TRACKNUM_SHORT 2 #define RPLD_PL_ST_UUID 3 #define RPLD_PL_ST_NUM 4 #define RPLD_PL_ST_LIKENESS 5 #define RPLD_PL_ST_RANDOM 6 #define RPLD_PL_ST_RANDOM_LIKENESS 7 // PlayList SearchOptions #define RPLD_PL_SO_NONE 0x0000 #define RPLD_PL_SO_PREVIOUS 0x0001 typedef int_least32_t rpld_mus_t; enum rpld_filename_type { RPLD_TYPE_ERROR = -1, RPLD_TYPE_UNKNOWN = 0, RPLD_TYPE_AUTOLOCATE = 1, RPLD_TYPE_STREAMURL, RPLD_TYPE_FILENAME, RPLD_TYPE_FILEURL }; struct rpld_filename { char * filename; enum rpld_filename_type type; }; struct rpld_playlist_entry { /* trancknum: 11223344 AABBCCDD 11 8 Bit -> PID & 0xFF 22 8 Bit -> Magic 3344 AABBCC 40 Bit -> counter DD 8 Bit -> RAND() short: 11223344 11 8 Bit -> (PID & 0xFF) ^ ((counter & 0x00FF0000) >> 16) 2233 16 Bit -> counter & 0xFFFF 44 8 Bit -> RAND() ^ Magic */ ei_t global_tracknum; ei_short_t global_short_tracknum; roar_uuid_t uuid; unsigned int flags; time_t length; rpld_mus_t start; // start time (within the resource) in ms. rpld_mus_t end; // end time (within the resource) in ms. time_t wallclock_start; struct roar_stream_rpg rpg; int codec; struct { struct rpld_filename * filenames; ssize_t num; ssize_t slots; char tantalos[48]; } io; struct { char album[RPLD_META_SHORT_LEN]; char title[RPLD_META_SHORT_LEN]; char artist[RPLD_MAX_PLF_LEN]; char performer[RPLD_MAX_PLF_LEN]; char version[RPLD_META_SHORT_LEN]; int genre; int tracknum; discid_t discid; struct { struct roar_keyval * kv; ssize_t kvlen; void * kv_store; ssize_t kv_storelen; } extra; } meta; struct { struct rpld_playlist_entry * next; } list; float likeness; }; struct rpld_playlist { size_t refc; struct rpld_playlist_entry * first; char * name; pli_t id; pli_t parent; unsigned int flags; volatile size_t transactions; int policy; size_t size_hint; float likeness_hint; struct rpld_queue * queue; ssize_t histsize; }; struct rpld_playlist_search { int type; union { ei_t long_tracknum; ei_short_t short_tracknum; roar_uuid_t uuid; size_t num; float likeness; pli_t pl; } subject; unsigned int options; }; struct rpld_playlist_pointer { size_t refc; struct rpld_playlist_search pls; struct { struct rpld_playlist * pl; struct rpld_playlist_entry * ple; } hint; }; extern struct rpld_playlist * g_playlists[MAX_PLAYLISTS]; struct rpld_playlist_entry * rpld_ple_new (void); void rpld_ple_free (struct rpld_playlist_entry * plent); struct rpld_playlist_entry * rpld_ple_copy (struct rpld_playlist_entry * plent); struct rpld_playlist_entry * rpld_ple_cut_out_next (struct rpld_playlist_entry * plent); const char * rpld_ple_time_hr (const struct rpld_playlist_entry * plent); int rpld_ple_set_time_hr (struct rpld_playlist_entry * plent, char * time); enum rpld_filename_type rpld_ple_get_filenametype(const char * type); int rpld_ple_push_filename(struct rpld_playlist_entry * plent, const char * filename, enum rpld_filename_type type, int clear); const char * rpld_ple_get_filename(struct rpld_playlist_entry * plent, ssize_t index, enum rpld_filename_type * type); ssize_t rpld_ple_num_filename(const struct rpld_playlist_entry * plent); // SEARCHPLE {"search string"|0xdiscid|uuid} [{AS|IN} {ALL|TITLE|ARTIST|VERSION|FILENAME|DISCID|UUID|TAG:"Tagname"}] [FROM {"Name"|ID|ANY}] int rpld_ple_filter (struct rpld_playlist_entry * plent, const void * needle, const char * key, int options); struct rpld_playlist * rpld_pl_new (void); int rpld_pl_ref (struct rpld_playlist * pl); int rpld_pl_unref (struct rpld_playlist * pl); void rpld_pl_push (struct rpld_playlist * pl, struct rpld_playlist_entry * plent); void rpld_pl_add (struct rpld_playlist * pl, struct rpld_playlist_entry * plent, ssize_t pos); struct rpld_playlist_entry * rpld_pl_get_first(struct rpld_playlist * pl); struct rpld_playlist_entry * rpld_pl_shift (struct rpld_playlist * pl); struct rpld_playlist_entry * rpld_pl_pop (struct rpld_playlist * pl); void rpld_pl_flush (struct rpld_playlist * pl); struct rpld_playlist_entry * rpld_pl_search (struct rpld_playlist * pl, struct rpld_playlist_search * search, struct rpld_playlist_entry * pmatch); int rpld_pl_virtual (struct rpld_playlist * pl, int virt); int rpld_pl_merge (struct rpld_playlist * pl, struct rpld_playlist * tm); int rpld_pl_set_name (struct rpld_playlist * pl, const char * name); char * rpld_pl_get_name (struct rpld_playlist * pl); int rpld_pl_set_id (struct rpld_playlist * pl, pli_t id); pli_t rpld_pl_get_id (struct rpld_playlist * pl); int rpld_pl_set_parent(struct rpld_playlist * pl, pli_t parent); pli_t rpld_pl_get_parent(struct rpld_playlist * pl); int rpld_pl_set_histsize(struct rpld_playlist * pl, ssize_t size); ssize_t rpld_pl_get_histsize(struct rpld_playlist * pl); int rpld_pl_register (struct rpld_playlist * pl); int rpld_pl_register_id(struct rpld_playlist * pl, pli_t id); int rpld_pl_unregister(struct rpld_playlist * pl); struct rpld_playlist * rpld_pl_get_by_id (pli_t id); struct rpld_playlist * rpld_pl_get_by_name(const char * name); size_t rpld_pl_num (struct rpld_playlist * pl); struct rpld_playlist_pointer * rpld_plp_init (struct rpld_playlist * pl, struct rpld_playlist_search * pls); int rpld_plp_ref (struct rpld_playlist_pointer * plp); int rpld_plp_unref (struct rpld_playlist_pointer * plp); int rpld_plp_copy (struct rpld_playlist_pointer ** dst, struct rpld_playlist_pointer * src); struct rpld_playlist_entry * rpld_plp_search (struct rpld_playlist_pointer * plp); #endif //ll rpld-0.1.9/plugin.c0000644000175000017500000005344112266574305012267 0ustar phiphi//plugin.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" #ifdef SUPPORT_PLUGIN #include "rpldplugin.h" static struct roar_plugincontainer * g_plugin_container = NULL; static ssize_t _config_get_limit(rpldph_config_key_t key) { switch (key) { // invalid keys: case RPLDPH_CONFIG_KEY_DEFAULT_BACKEND: case RPLDPH_CONFIG_KEY_APPNAME: roar_err_set(ROAR_ERROR_TYPEMM); return -1; break; // valid keys: case RPLDPH_CONFIG_KEY_MAX_CLIENTS: return RPLD_CLIENTS_MAX; break; case RPLDPH_CONFIG_KEY_MAX_PLAYLISTS: return MAX_PLAYLISTS; break; case RPLDPH_CONFIG_KEY_MAX_LISTENS: return RPLD_MAX_LISTEN; break; case RPLDPH_CONFIG_KEY_MAX_CODECBL: return PLAYBACK_MAX_CODECBL; break; case RPLDPH_CONFIG_KEY_MAX_POINTER: return POINTER_NUM; break; case RPLDPH_CONFIG_KEY_DEFAULT_PLF: return RPLD_FF_PLF_DEFAULT; break; case RPLDPH_CONFIG_KEY_APPVENDOR: return ROAR_VID_ROARAUDIO; break; } roar_err_set(ROAR_ERROR_NOENT); return -1; } static const char * _config_get_value(rpldph_config_key_t key) { switch (key) { // invalid keys: case RPLDPH_CONFIG_KEY_MAX_CLIENTS: case RPLDPH_CONFIG_KEY_MAX_PLAYLISTS: case RPLDPH_CONFIG_KEY_MAX_LISTENS: case RPLDPH_CONFIG_KEY_MAX_CODECBL: case RPLDPH_CONFIG_KEY_MAX_POINTER: roar_err_set(ROAR_ERROR_TYPEMM); return NULL; break; // valid keys: case RPLDPH_CONFIG_KEY_DEFAULT_BACKEND: return BACKEND_DEFAULT_NAME; break; case RPLDPH_CONFIG_KEY_APPNAME: return APPLICATION_NAME; break; case RPLDPH_CONFIG_KEY_APPVENDOR: return ROAR_VSTR_ROARAUDIO; break; case RPLDPH_CONFIG_KEY_DEFAULT_PLF: return "vclt"; break; // TODO: FIXME: use a global const here. } roar_err_set(ROAR_ERROR_NOENT); return NULL; } static void * _mm_calloc(size_t nmemb, size_t size) { return roar_mm_calloc(nmemb, size); } static void * _mm_malloc(size_t size) { return roar_mm_malloc(size); } static void * _mm_realloc(void *ptr, size_t size) { return roar_mm_realloc(ptr, size); } static char * _mm_strdup(const char *s) { return roar_mm_strdup(s); } static int _error_get(void) { return roar_error; } #define __ple_check(ret) if ( plent == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return (ret); } static int _ple_set_res (struct rpld_playlist_entry * plent, const char * file, int codec, time_t length) { __ple_check(-1) if ( file == NULL ) file = ""; rpld_ple_push_filename(plent, file, RPLD_TYPE_UNKNOWN, 1); plent->codec = codec; plent->length = length; return 0; } static int _ple_set_meta (struct rpld_playlist_entry * plent, struct roar_keyval * kv, ssize_t len) { struct roar_keyval * c; ssize_t i; if ( plent == NULL || kv == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } for (i = 0; len == -1 ? (kv[i].key != NULL || kv[i].value != NULL) : i < len; i++) { c = &(kv[i]); if ( 0 ) { #define _handle_meta_type(type) } else if ( !strcasecmp(c->key, #type) ) { \ strncpy(plent->meta.type, c->value == NULL ? "" : c->value, sizeof(plent->meta.type)); #ifdef __RPLD__FIX_VIM_SYNTAX_HIGHLIGHT__ } #endif _handle_meta_type(album) _handle_meta_type(title) _handle_meta_type(artist) _handle_meta_type(performer) _handle_meta_type(version) } } return 0; } static const char * _ple_get_meta (struct rpld_playlist_entry * plent, const char * key) { const struct roar_keyval * kv; __ple_check(NULL) if ( !strcasecmp(key, "album") ) return plent->meta.album; if ( !strcasecmp(key, "title") ) return plent->meta.title; if ( !strcasecmp(key, "artist") ) return plent->meta.artist; if ( !strcasecmp(key, "performer") ) return plent->meta.performer; if ( !strcasecmp(key, "version") ) return plent->meta.version; if ( plent->meta.extra.kv != NULL ) { kv = roar_keyval_lookup(plent->meta.extra.kv, key, plent->meta.extra.kvlen, 0); if ( kv != NULL ) return kv->value; } roar_err_set(ROAR_ERROR_NOENT); return NULL; } static int _ple_set_meta_int(struct rpld_playlist_entry * plent, const char * key, rpld_maxint_t val) { __ple_check(-1) if ( !strcasecmp(key, "length") ) { plent->length = val; } else if ( !strcasecmp(key, "codec") ) { plent->codec = val; } else if ( !strcasecmp(key, "genre") ) { plent->meta.genre = val; } else if ( !strcasecmp(key, "tracknum") || !strcasecmp(key, "tracknumber") ) { plent->meta.tracknum = val; } else if ( !strcasecmp(key, "discid") ) { plent->meta.discid = val; } else { roar_err_set(ROAR_ERROR_NOTSUP); return -1; } return 0; } static rpld_maxint_t _ple_get_meta_int(struct rpld_playlist_entry * plent, const char * key) { __ple_check((rpld_maxint_t)-1) if ( !strcasecmp(key, "length") ) return plent->length; if ( !strcasecmp(key, "codec") ) return plent->codec; if ( !strcasecmp(key, "genre") ) return plent->meta.genre; if ( !strcasecmp(key, "tracknum") || !strcasecmp(key, "tracknumber") ) return plent->meta.tracknum; if ( !strcasecmp(key, "discid") ) return (uint32_t)plent->meta.discid; roar_err_set(ROAR_ERROR_NOENT); return (rpld_maxint_t)-1; } static int _ple_get_codec (struct rpld_playlist_entry * plent) { __ple_check(-1) return plent->codec; } static time_t _ple_get_length (struct rpld_playlist_entry * plent) { __ple_check((time_t)-1) return plent->length; } static int _ple_set_uuid (struct rpld_playlist_entry * plent, const char * uuid) { if ( plent == NULL || uuid == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } if ( roar_str2uuid(plent->uuid, uuid) == 0 ) return 0; roar_err_set(ROAR_ERROR_ILLSEQ); return -1; } static const char * _ple_get_uuid (struct rpld_playlist_entry * plent, char * buf) { static char buffer[37]; __ple_check(NULL) if ( buf == NULL ) buf = buffer; roar_uuid2str(buf, plent->uuid, sizeof(buffer)); return buf; } static int _ple_set_likeness(struct rpld_playlist_entry * plent, float likeness) { __ple_check(-1) plent->likeness = likeness; return 0; } static int _ple_inc_likeness(struct rpld_playlist_entry * plent, float likeness) { __ple_check(-1) plent->likeness += likeness; return 0; } static float _ple_get_likeness(struct rpld_playlist_entry * plent) { __ple_check(-1) return plent->likeness; } static struct rpld_playlist_entry * _ple_get_next (struct rpld_playlist_entry * plent) { __ple_check(NULL) return plent->list.next; } static int _ple_set_offset(struct rpld_playlist_entry * plent, int_least32_t start, int_least32_t end) { __ple_check(-1) plent->start = start; plent->end = end; return 0; } static int _ple_get_offset(struct rpld_playlist_entry * plent, int_least32_t * start, int_least32_t * end) { __ple_check(-1) if ( start != NULL ) *start = plent->start; if ( end != NULL ) *end = plent->end; return 0; } #define _begin(ret) \ struct rpld_playlist * playlist = rpld_pl_get_by_id(pl); \ int err; \ if ( playlist == NULL ) \ return (ret); #define _return \ err = roar_error; \ rpld_pl_unref(playlist); \ roar_err_set(err); \ return ret; static rpld_pli_t _playlist_new (const char * name, rpld_pli_t parent) { struct rpld_playlist * playlist; rpld_pli_t ret; if ( name == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return RPLD_PLI_INVALID; } playlist = rpld_pl_new(); if ( playlist == NULL ) return RPLD_PLI_INVALID; rpld_pl_set_name(playlist, name); if ( parent != RPLD_PLI_INVALID ) rpld_pl_set_parent(playlist, parent); rpld_pl_register(playlist); ret = rpld_pl_get_id(playlist); rpld_pl_unref(playlist); return ret; } static void _playlist_free (rpld_pli_t pl) { struct rpld_playlist * playlist = rpld_pl_get_by_id(pl); if ( playlist == NULL ) return; rpld_pl_set_name(playlist, NULL); rpld_pl_unref(playlist); } static int _playlist_flush(rpld_pli_t pl) { const int ret = 0; _begin(-1) rpld_pl_flush(playlist); _return } static int _playlist_merge(rpld_pli_t pl, rpld_pli_t tm) { struct rpld_playlist * playlist_tm; int ret; _begin(-1) playlist_tm = rpld_pl_get_by_id(tm); if ( playlist_tm == NULL ) { ret = -1; _return } ret = rpld_pl_merge(playlist, playlist_tm); err = roar_error; rpld_pl_unref(playlist_tm); roar_err_set(err); _return } static int _playlist_set_name(rpld_pli_t pl, const char * name) { int ret; _begin(-1) ret = rpld_pl_set_name(playlist, name); _return } static const char * _playlist_get_name(rpld_pli_t pl) { const char * ret; _begin(NULL) ret = rpld_pl_get_name(playlist); _return } static int _playlist_set_parent(rpld_pli_t pl, rpld_pli_t parent) { int ret; _begin(-1) ret = rpld_pl_set_parent(playlist, parent); _return } static rpld_pli_t _playlist_get_parent(rpld_pli_t pl) { rpld_pli_t ret; _begin(RPLD_PLI_INVALID) ret = rpld_pl_get_parent(playlist); _return } static rpld_pli_t _playlist_get_by_name(const char * name) { struct rpld_playlist * playlist = rpld_pl_get_by_name(name); int err; rpld_pli_t ret; if ( playlist == NULL ) return RPLD_PLI_INVALID; ret = rpld_pl_get_id(playlist); _return } static ssize_t _playlist_get_num(rpld_pli_t pl) { ssize_t ret; _begin(-1) ret = rpld_pl_num(playlist); _return } static int _playlist_push (rpld_pli_t pl, struct rpld_playlist_entry * plent) { const int ret = 0; _begin(-1) rpld_pl_push(playlist, plent); _return } static struct rpld_playlist_entry * _playlist_pop (rpld_pli_t pl) { struct rpld_playlist_entry * ret; _begin(NULL) ret = rpld_pl_pop(playlist); _return } static struct rpld_playlist_entry * _playlist_shift (rpld_pli_t pl) { struct rpld_playlist_entry * ret; _begin(NULL) ret = rpld_pl_shift(playlist); _return } static int _playlist_add (rpld_pli_t pl, struct rpld_playlist_entry * plent, ssize_t pos) { const int ret = 0; _begin(-1) rpld_pl_add(playlist, plent, pos); _return } static int _playlist_unshift (rpld_pli_t pl, struct rpld_playlist_entry * plent) { return _playlist_add(pl, plent, -1); } static struct rpld_playlist_entry * _playlist_get_first(rpld_pli_t pl) { struct rpld_playlist_entry * ret; _begin(NULL) ret = rpld_pl_get_first(playlist); _return } static int _history_set_size(rpld_pli_t history, ssize_t size) { struct rpld_playlist * pl = rpld_pl_get_by_id(history); int ret; int err; if ( pl == NULL ) return -1; ret = rpld_pl_set_histsize(pl, size); err = roar_error; rpld_pl_unref(pl); roar_err_set(err); return ret; } static ssize_t _history_get_size(rpld_pli_t history) { struct rpld_playlist * pl = rpld_pl_get_by_id(history); ssize_t ret; int err; if ( pl == NULL ) return -1; ret = rpld_pl_get_histsize(pl); err = roar_error; rpld_pl_unref(pl); roar_err_set(err); return ret; } static struct rpld_playlist_pointer * _plp_new (rpld_pli_t playlist, const char * type, const void * argp) { struct rpld_playlist_search pls; union { const void * vp; const size_t * num; const float * likeness; const char * uuid; } arg = {.vp = argp}; struct rpld_playlist * pl; struct rpld_playlist_pointer * ret; int err; if ( type == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return NULL; } memset(&pls, 0, sizeof(pls)); if ( !strcasecmp(type, "num") ) { pls.type = RPLD_PL_ST_NUM; } else if ( !strcasecmp(type, "uuid") ) { pls.type = RPLD_PL_ST_UUID; } else if ( !strcasecmp(type, "likeness") ) { pls.type = RPLD_PL_ST_LIKENESS; } else if ( !strcasecmp(type, "random") ) { pls.type = RPLD_PL_ST_RANDOM; } else if ( !strcasecmp(type, "randomlike") ) { pls.type = RPLD_PL_ST_RANDOM_LIKENESS; } else { roar_err_set(ROAR_ERROR_NOTSUP); return NULL; } switch (pls.type) { case RPLD_PL_ST_UUID: case RPLD_PL_ST_NUM: case RPLD_PL_ST_LIKENESS: if ( argp == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return NULL; } break; case RPLD_PL_ST_RANDOM: case RPLD_PL_ST_RANDOM_LIKENESS: if ( playlist == RPLD_PLI_INVALID ) { roar_err_set(ROAR_ERROR_INVAL); return NULL; } break; } switch (pls.type) { case RPLD_PL_ST_UUID: if ( roar_str2uuid(pls.subject.uuid, arg.uuid) != 0 ) { roar_err_set(ROAR_ERROR_ILLSEQ); return NULL; } break; case RPLD_PL_ST_NUM: pls.subject.num = *arg.num; break; case RPLD_PL_ST_LIKENESS: pls.subject.likeness = *arg.likeness; break; case RPLD_PL_ST_RANDOM: case RPLD_PL_ST_RANDOM_LIKENESS: pls.subject.pl = playlist; break; } pl = rpld_pl_get_by_id(playlist); // we can ignore errors here as rpld_plp_init() can handle NULL. ret = rpld_plp_init(pl, &pls); err = roar_error; if ( pl != NULL ) rpld_pl_unref(pl); roar_err_set(err); return ret; } static int _playback_stop(rpld_pli_t queue) { return playback_stop(queue, 0, 1); } static int _playback_pause(rpld_pli_t queue, rpldph_bool_t how) { switch (how) { case RPLDPH_FALSE: return playback_pause(queue, PLAYBACK_PAUSE_FALSE); break; case RPLDPH_TRUE: return playback_pause(queue, PLAYBACK_PAUSE_TRUE); break; case RPLDPH_TOGGLE: return playback_pause(queue, PLAYBACK_PAUSE_TOGGLE); break; case RPLDPH_ASK: case RPLDPH_ERROR: // don't do anything, run into the error case below. break; } roar_err_set(ROAR_ERROR_BADRQC); return -1; } static rpldph_bool_t _playback_is_playing(rpld_pli_t queue) { switch (playback_is_playing(queue)) { case 0: return RPLDPH_FALSE; break; case 1: return RPLDPH_TRUE; break; default: return RPLDPH_ERROR; break; } } static rpldph_bool_t _playback_is_paused (rpld_pli_t queue) { switch (playback_is_pause(queue)) { case PLAYBACK_PAUSE_FALSE: return RPLDPH_FALSE; break; case PLAYBACK_PAUSE_TRUE: return RPLDPH_TRUE; break; default: return RPLDPH_ERROR; break; } } static rpldph_bool_t _playback_is_queue (rpld_pli_t queue) { struct rpld_playlist * pl = rpld_pl_get_by_id(queue); rpldph_bool_t ret; if ( pl == NULL ) return RPLDPH_ERROR; if ( pl->queue == NULL ) { ret = RPLDPH_FALSE; } else { ret = RPLDPH_TRUE; } rpld_pl_unref(pl); return ret; } static float _playback_get_volume(rpld_pli_t queue) { float ret = playback_get_volume_mu16(queue); return ret / 65535.; } static int _playback_set_volume(rpld_pli_t queue, float volume) { if ( volume < 0. || volume > 65535. ) { roar_err_set(ROAR_ERROR_RANGE); return -1; } volume *= 65535.; return playback_set_volume_mu16(queue, (uint16_t)volume); } struct roar_connection * _backend_get_con(struct rpld_backend * backend) { if ( backend == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return NULL; } if ( !(backend->flags & BACKEND_FLAG_CONNECTED) ) { roar_err_set(ROAR_ERROR_NOTCONN); return NULL; } if ( roar_connectionref(&(backend->con)) == -1 ) return NULL; return &(backend->con); } static int _fformat_playlist_export(rpld_fformat_t handle, struct roar_vio_calls * vio, rpld_pli_t pl) { struct rpld_playlist * realpl; int ret; realpl = rpld_pl_get_by_id(pl); if ( realpl == NULL ) return -1; ret = fformat_playlist_export((struct fformat_handle *)handle, vio, realpl); rpld_pl_unref(realpl); return ret; } static int _fformat_playlist_import(rpld_fformat_t handle, struct roar_vio_calls * vio, rpld_pli_t pl) { struct rpld_playlist * realpl; int ret; realpl = rpld_pl_get_by_id(pl); if ( realpl == NULL ) return -1; ret = fformat_playlist_import((struct fformat_handle *)handle, vio, realpl); rpld_pl_unref(realpl); return ret; } static inline void _yield_ay(enum yield_auto cmd) { yield_auto(cmd, RPLD_YIELD_TASK_NONE, RPLD_YIELD_TASK_ALL, RPLD_YIELD_NONBLOCK); } static void _yield_ay_trigger(void) { _yield_ay(RPLD_YIELD_TRIGGER); } static void _yield_ay_pause(void) { _yield_ay(RPLD_YIELD_PAUSE); } static void _yield_ay_unpause(void) { _yield_ay(RPLD_YIELD_UNPAUSE); } static struct __rpldph_binargv __binargv = { .functions = { .config = { ._get_limit = _config_get_limit, ._get_value = _config_get_value, }, .memory = { ._calloc = _mm_calloc, ._malloc = _mm_malloc, ._free = roar_mm_free_retvoid, ._realloc = _mm_realloc, ._strdup = _mm_strdup }, .error = { ._get = _error_get, ._set = roar_err_set, ._error2str = roar_error2str, }, .control = { ._exit = rpld_exit, ._serverinfo = rpld_serverinfo_get }, .ple = { ._new = rpld_ple_new, ._free = rpld_ple_free, ._copy = rpld_ple_copy, ._set_res = _ple_set_res, ._set_meta = _ple_set_meta, ._get_meta = _ple_get_meta, ._set_meta_int = _ple_set_meta_int, ._get_meta_int = _ple_get_meta_int, ._get_codec = _ple_get_codec, ._get_length = _ple_get_length, ._set_uuid = _ple_set_uuid, ._get_uuid = _ple_get_uuid, ._set_likeness = _ple_set_likeness, ._inc_likeness = _ple_inc_likeness, ._get_likeness = _ple_get_likeness, ._get_next = _ple_get_next, ._set_offset = _ple_set_offset, ._get_offset = _ple_get_offset }, .playlist = { ._new = _playlist_new, ._free = _playlist_free, ._flush = _playlist_flush, ._merge = _playlist_merge, ._set_name = _playlist_set_name, ._get_name = _playlist_get_name, ._set_parent = _playlist_set_parent, ._get_parent = _playlist_get_parent, ._get_by_name = _playlist_get_by_name, ._get_num = _playlist_get_num, ._push = _playlist_push, ._unshift = _playlist_unshift, ._pop = _playlist_pop, ._shift = _playlist_shift, ._add = _playlist_add, ._get_first = _playlist_get_first }, .history = { ._set_size = _history_set_size, ._get_size = _history_get_size }, .plp = { ._new = _plp_new, ._ref = rpld_plp_ref, ._unref = rpld_plp_unref, ._copy = rpld_plp_copy, ._search = rpld_plp_search }, .playback = { ._play = playback_play, ._next = playback_next, ._prev = playback_prev, ._stop = _playback_stop, ._pause = _playback_pause, ._is_playing = _playback_is_playing, ._is_paused = _playback_is_paused, ._is_queue = _playback_is_queue, ._get_volume = _playback_get_volume, ._set_volume = _playback_set_volume, ._get_ple = playback_get_ple, ._get_mduc = playback_get_mduc, ._get_stream = playback_get_stream }, .store = { ._save = store, ._load = restore }, .backend = { ._get_connection = backend_get_connection, ._ref = backend_ref, ._unref = backend_unref, ._get_name = backend_get_name, ._get_con = _backend_get_con, ._blacklist_codec = backend_blacklist_codec, ._blacklist_codec_global = backend_blacklist_codec_global, ._blacklist_check_codec = backend_blacklist_check_codec }, .client = { ._set_name = client_set_name, ._get_name = client_get_name, ._set_playlist = client_set_playlist, ._get_playlist = client_get_playlist, ._set_queue = client_set_queue, ._get_queue = client_get_queue, ._str2proto = client_str2proto, ._proto2str = client_proto2str }, .fformat = { ._str2plf = fformat_str2plf, ._plf2str = fformat_plf2str, ._handle_new = (rpld_fformat_t (*)(int format))fformat_handle_new, ._handle_close = (void (*)(rpld_fformat_t handle))fformat_handle_close, ._playlist_export = _fformat_playlist_export, ._playlist_import = _fformat_playlist_import }, .pointer = { ._get_name = rpld_pointer_get_name, ._parse_name = rpld_pointer_parse_name, ._is_set = rpld_pointer_is_set, ._get = rpld_pointer_get, ._get_by_name = rpld_pointer_get_by_name, ._set = rpld_pointer_set, ._set_by_name = rpld_pointer_set_by_name, ._search = rpld_pointer_search, }, .yield = { ._ay_trigger = _yield_ay_trigger, ._ay_pause = _yield_ay_pause, ._ay_unpause = _yield_ay_unpause, ._watchdog_trigger = yield_watchdog_trigger } } }; int rpld_plugin_init(void) { struct roar_dl_librarypara * plugin_para; int err; if ( g_plugin_container != NULL ) { roar_err_set(ROAR_ERROR_ALREADY); return -1; } plugin_para = roar_dl_para_new(NULL, &__binargv, RPLDPH_APPNAME, RPLDPH_ABIVERSION); g_plugin_container = roar_plugincontainer_new(plugin_para); err = roar_error; roar_dl_para_unref(plugin_para); if ( g_plugin_container == NULL ) { roar_err_set(err); return -1; } else { return 0; } } int rpld_plugin_free(void) { if ( g_plugin_container == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } rpld_plugin_appsched(ROAR_DL_APPSCHED_FREE); roar_plugincontainer_unref(g_plugin_container); g_plugin_container = NULL; return 0; } int rpld_plugin_load(const char * plugin, const char * args) { struct roar_dl_librarypara * plugin_para = NULL; int ret; if ( args != NULL ) plugin_para = roar_dl_para_new(args, &__binargv, RPLDPH_APPNAME, RPLDPH_ABIVERSION); ret = roar_plugincontainer_load(g_plugin_container, plugin, plugin_para); if ( plugin_para != NULL ) roar_dl_para_unref(plugin_para); return ret; } int rpld_plugin_appsched(enum roar_dl_appsched_trigger trigger) { return roar_plugincontainer_appsched_trigger(g_plugin_container, trigger); } #endif //ll rpld-0.1.9/plugin.h0000644000175000017500000000227612266574305012274 0ustar phiphi//plugin.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_PLUGIN_H_ #define _RPLD_PLUGIN_H_ #ifdef ROAR_FT_SONAME_LIBROAR2 #define SUPPORT_PLUGIN int rpld_plugin_init(void); int rpld_plugin_free(void); int rpld_plugin_load(const char * plugin, const char * args); int rpld_plugin_appsched(enum roar_dl_appsched_trigger trigger); #endif #endif //ll rpld-0.1.9/pointer.c0000644000175000017500000001321212266574305012441 0ustar phiphi//pointer.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" enum rpld_pointertype { PT_GLOBAL = 0, PT_QUEUE, PT_CLIENT }; struct rpld_pointerarray { const char * name; enum rpld_pointertype type; struct rpld_playlist_pointer * pointer; }; struct rpld_pointerarray g_pointer[POINTER_NUM] = { {"DEFAULT", PT_QUEUE, NULL}, {"CURRENT", PT_QUEUE, NULL}, {"STARTUP", PT_QUEUE, NULL}, {"TEMP", PT_CLIENT, NULL}, {"FALLBACK", PT_QUEUE, NULL} }; #define _chargs(ret) if ( pointer < 0 || pointer >= POINTER_NUM ) { roar_err_set(ROAR_ERROR_INVAL); return (ret); } char * rpld_pointer_get_name(const int pointer, pli_t queue, const int client) { char * ret; const char * pointer_name; _chargs(NULL); pointer_name = g_pointer[pointer].name; #define _SIZE 32 ret = roar_mm_malloc(_SIZE); if ( queue == (pli_t)-1 && client == -1 ) { snprintf(ret, _SIZE, "%s", pointer_name); } else if ( queue == (pli_t)-1 ) { snprintf(ret, _SIZE, "%s[:%i]", pointer_name, client); } else if ( client == -1 ) { snprintf(ret, _SIZE, "%s[%i]", pointer_name, (int)queue); } else { snprintf(ret, _SIZE, "%s[%i:%i]", pointer_name, (int)queue, client); } return ret; } int rpld_pointer_parse_name(int * pointer, pli_t * queue, int * client, int client_hint, const char * name) { size_t i; size_t namelen; const char * client_info; if ( queue == NULL || pointer == NULL || client == NULL || name == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } *queue = (pli_t)-1; *pointer = -1; *client = client_hint; if ( client_hint != -1 ) { *queue = client_get_queue(client_hint); } for (i = 0; i < POINTER_NUM; i++) { namelen = roar_mm_strlen(g_pointer[i].name); if ( !strncasecmp(g_pointer[i].name, name, namelen) ) { if ( name[namelen] == 0 ) { *pointer = i; return 0; } else if ( name[namelen] == '[' ) { *pointer = i; client_info = strstr(name + namelen + 1, ":"); ROAR_DBG("rpld_pointer_parse_name(*): client_info=%p'%s'", client_info, client_info); if ( client_info != NULL ) *client = atoi(client_info + 1); if ( name[namelen+1] == ':' ) { *queue = client_get_queue(*client); } else { *queue = atoi(name + namelen + 1); } return 0; } else { roar_err_set(ROAR_ERROR_ILLSEQ); return -1; } } } roar_err_set(ROAR_ERROR_NOENT); return -1; } int rpld_pointer_is_set(const int pointer, pli_t queue, const int client) { struct rpld_playlist_pointer * plp; int ret; _chargs(-1); plp = rpld_pointer_get(pointer, queue, client); ret = plp == NULL ? 0 : 1; rpld_plp_unref(plp); return ret; } struct rpld_playlist_pointer * rpld_pointer_get(const int pointer, pli_t queue, const int client) { struct rpld_playlist_pointer * ret = NULL; _chargs(NULL); roar_err_set(ROAR_ERROR_NOTSUP); switch (g_pointer[pointer].type) { case PT_GLOBAL: ret = g_pointer[pointer].pointer; if ( ret == NULL ) { roar_err_set(ROAR_ERROR_NOENT); } else { rpld_plp_ref(g_pointer[pointer].pointer); } break; case PT_CLIENT: ret = client_get_pointer(client, pointer); break; case PT_QUEUE: ret = playback_get_pointer(queue, pointer); break; } return ret; } struct rpld_playlist_pointer * rpld_pointer_get_by_name(const char * name, int client_hint) { pli_t queue; int pointer, client; if ( rpld_pointer_parse_name(&pointer, &queue, &client, client_hint, name) == -1 ) return NULL; return rpld_pointer_get(pointer, queue, client); } int rpld_pointer_set(const int pointer, pli_t queue, const int client, struct rpld_playlist_pointer * plp) { _chargs(-1); roar_err_set(ROAR_ERROR_NOTSUP); switch (g_pointer[pointer].type) { case PT_GLOBAL: if ( g_pointer[pointer].pointer != NULL ) { rpld_plp_unref(g_pointer[pointer].pointer); g_pointer[pointer].pointer = NULL; } if ( plp != NULL ) rpld_plp_ref(plp); g_pointer[pointer].pointer = plp; return 0; break; case PT_CLIENT: return client_set_pointer(client, pointer, plp); break; case PT_QUEUE: return playback_set_pointer(queue, pointer, plp); break; } return -1; } int rpld_pointer_set_by_name(const char * name, int client_hint, struct rpld_playlist_pointer * plp) { pli_t queue; int pointer, client; if ( rpld_pointer_parse_name(&pointer, &queue, &client, client_hint, name) == -1 ) return -1; return rpld_pointer_set(pointer, queue, client, plp); } struct rpld_playlist_entry * rpld_pointer_search(const int pointer, pli_t queue, const int client) { struct rpld_playlist_pointer * plp = rpld_pointer_get(pointer, queue, client); struct rpld_playlist_entry * ret; if ( plp == NULL ) return NULL; ret = rpld_plp_search(plp); rpld_plp_unref(plp); return ret; } //ll rpld-0.1.9/pointer.h0000644000175000017500000000401112266574305012443 0ustar phiphi//pointer.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_POINTER_H_ #define _RPLD_POINTER_H_ #define POINTER_DEFAULT 0 #define POINTER_CURRENT 1 #define POINTER_STARTUP 2 #define POINTER_TEMP 3 #define POINTER_FALLBACK 4 #define POINTER_NUM 5 char * rpld_pointer_get_name(const int pointer, pli_t queue, const int client); int rpld_pointer_parse_name(int * pointer, pli_t * queue, int * client, int client_hint, const char * name); int rpld_pointer_is_set(const int pointer, pli_t queue, const int client); struct rpld_playlist_pointer * rpld_pointer_get(const int pointer, pli_t queue, const int client); struct rpld_playlist_pointer * rpld_pointer_get_by_name(const char * name, int client_hint); int rpld_pointer_set(const int pointer, pli_t queue, const int client, struct rpld_playlist_pointer * plp); int rpld_pointer_set_by_name(const char * name, int client_hint, struct rpld_playlist_pointer * plp); struct rpld_playlist_entry * rpld_pointer_search(const int pointer, pli_t queue, const int client); #endif //ll rpld-0.1.9/proto_mpd.c0000644000175000017500000003000612266574306012765 0ustar phiphi//proto_mpd.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" #define YES 1 #define NO 0 #define ND -1 static struct { int auth; char * cmd; } _commands[] = { {NO, "setvol"}, {NO, "stop"}, {NO, "play"}, {NO, "playid"}, {NO, "next"}, {NO, "previous"}, {NO, "status"}, {NO, "ping"}, {NO, "close"}, {NO, "commands"}, {NO, "notcommands"}, {NO, "outputs"}, {NO, "urlhandlers"}, {NO, "currentsong"}, {NO, "playlistid"}, {NO, "stats"}, /* not supported commands: */ {ND, "disableoutput"}, {ND, "enableoutput"}, {ND, "kill"}, {ND, "update"}, {ND, "tagtypes"}, {ND, "find"}, {ND, "list"}, {ND, "listall"}, {ND, "listallinfo"}, {ND, "lsinfo"}, {ND, "search"}, {ND, "count"}, {ND, "add"}, {ND, "addid"}, {ND, "clear"}, {ND, "delete"}, {ND, "deleteid"}, {ND, "load"}, {ND, "rename"}, {ND, "move"}, {ND, "moveid"}, {ND, "playlist"}, {ND, "playlistinfo"}, {ND, "plchanges"}, {ND, "plchangesposid"}, {ND, "rm"}, {ND, "save"}, {ND, "shuffle"}, {ND, "swap"}, {ND, "swapid"}, {ND, "listplaylist"}, {ND, "listplaylistinfo"}, {ND, "playlistadd"}, {ND, "playlistclear"}, {ND, "playlistdelete"}, {ND, "playlistmove"}, {ND, "playlistfind"}, {ND, "playlistsearch"}, {ND, "crossfade"}, {ND, "random"}, {ND, "repeat"}, {ND, "seek"}, {ND, "seekid"}, {ND, "setvol"}, {ND, "volume"}, {ND, "clearerror"}, {ND, "password"}, {NO, NULL} }; static char * _dequote (char * str) { ssize_t len; if ( str == NULL ) return NULL; if ( *str != '"' ) return str; str++; len = strlen(str); str[len-1] = 0; return str; } static void _print_handlers(struct roar_vio_calls * vio) { char * h[] = { "file", "fh", "socket", "http", "gopher", "icy", "tantalos", NULL }; int i; for (i = 0; h[i] != NULL; i++) roar_vio_printf(vio, "handler: %s://\n", h[i]); } struct rpld_playlist_entry * proto_mpd_parse_id(int client, char * args) { struct rpld_playlist_search pls; struct rpld_playlist_entry * ret; int i; int bit31; (void)client; memset(&pls, 0, sizeof(pls)); pls.type = RPLD_PL_ST_TRACKNUM_SHORT; pls.subject.short_tracknum = atol(args); for (bit31 = 0; bit31 == 0 || bit31 == 1; bit31++) { pls.subject.short_tracknum |= bit31 ? ((uint32_t)1<<31) : 0; for (i = 0; i < MAX_PLAYLISTS; i++) { if ( g_playlists[i] != NULL ) { if ( (ret = rpld_pl_search(g_playlists[i], &pls, NULL)) != NULL ) return ret; } } } return NULL; } #define _pk(k, kt, v) roar_vio_printf(vio, k ": " kt "\n", (v)) #define _pks(k, v) _pk(k, "%s", v) int proto_mpd_print_song (int id, struct roar_vio_calls * vio, struct rpld_proto_mpd_error * error, struct rpld_playlist_entry * ple, ssize_t pos) { uint32_t songid; /* Xfile: 2007-omc3-203_orange_sofa-the_one_you_need.ogg XTime: 209 XAlbum: open music contest #3: "by perseverance the snail reached art" (black disc) XArtist: orange sofa Date: 2007 Disc: 2 XGenre: Creative Commons XTitle: the one you need XTrack: 03 Pos: 0 Id: 0 */ (void)id; (void)error; if ( ple == NULL ) return -1; _pks("file", rpld_ple_get_filename(ple, -1, NULL)); if ( ple->length ) _pk("Time", "%lu", (long unsigned int)ple->length); if ( ple->meta.album[0] != 0 ) _pks("Album", ple->meta.album); if ( ple->meta.artist[0] != 0 ) _pks("Artist", ple->meta.artist); _pks("Genre", roar_meta_strgenre(ple->meta.genre)); if ( ple->meta.title[0] != 0 ) _pks("Title", ple->meta.title); if ( ple->meta.tracknum ) _pk("Track", "%i", ple->meta.tracknum); if ( pos != -1 ) _pk("Pos", "%lu", (long unsigned int)pos); songid = ple->global_short_tracknum & (uint32_t)0x7FFFFFFF; _pk("Id", "%lu", (long unsigned int)songid); return 0; } int proto_mpd_client_set_proto(int id, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen, struct roar_dl_librarypara * pluginpara) { #define NEW_CLIENT_STRING "OK MPD " RPLD_PROTO_MPD_VERSION "\n" (void)id, (void)obuffer, (void)userdata, (void)para, (void)paralen, (void)pluginpara; if ( roar_vio_puts(vio, NEW_CLIENT_STRING) != (sizeof(NEW_CLIENT_STRING)-1) ) return -1; return 0; } int proto_mpd_client_handle(int id, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen, struct roar_dl_librarypara * pluginpara) { struct rpld_proto_mpd_error error; ssize_t len; char * args; int ret; char buffer[1024]; (void)obuffer, (void)userdata, (void)para, (void)paralen, (void)pluginpara; if ( vio == NULL ) return -1; if ( (len = roar_vio_read(vio, buffer, 1023)) < 1 ) return -1; if ( buffer[len-1] != '\n' ) return -1; if ( len > 1 && buffer[len-2] == '\r' ) { len -= 2; } else { len--; } buffer[len] = 0; if ( (args = strstr(buffer, " ")) != NULL ) { *args = 0; args++; } error.error = RPLD_PROTO_MPD_ACK_ERROR_UNKNOWN; error.offset = 0; error.cmd = buffer; error.msg = "Unknown error"; ret = proto_mpd_pcmd(id, vio, &error, buffer, args); if ( error.error == RPLD_PROTO_MPD_ACK_ERROR_DISCONNECT ) return -1; if ( ret == -1 ) { //ACK [5@2] {} unknown command "pay" roar_vio_printf(vio, "ACK [%i@%i] {%s} %s\n", error.error, error.offset, error.cmd, error.msg); } else { if ( roar_vio_puts(vio, "OK\n") != 3 ) return -1; } return 0; } #define NULL_OK 0 #define NULL_NOT_OK 1 #define _CK_ARGS(ok) if ( (ok) && args == NULL ) { \ error->error = RPLD_PROTO_MPD_ACK_ERROR_UNKNOWN; \ error->msg = "Protocol error"; \ return -1; \ } int proto_mpd_pcmd(int id, struct roar_vio_calls * vio, struct rpld_proto_mpd_error * error, char * cmd, char * args) { pli_t queue = client_get_queue(id); struct rpld_playlist * pl; struct rpld_playlist_entry * plent; const struct roar_stream * s; ssize_t pos = 0; int i; ROAR_DBG("proto_mpd_pcmd(id=%i, vio=%p, error=%p, cmd='%s', args='%s') = ?", id, vio, error, cmd, args); // handle null-string-command: if ( *cmd == 0 ) return 0; /* basic commands */ if ( !strcasecmp(cmd, "close") ) { _CK_ARGS(NULL_OK); error->error = RPLD_PROTO_MPD_ACK_ERROR_DISCONNECT; return 0; } else if ( !strcasecmp(cmd, "ping") ) { _CK_ARGS(NULL_OK); return 0; /* status commands */ } else if ( !strcasecmp(cmd, "stats") ) { _CK_ARGS(NULL_OK); /* artists: 1 albums: 1 songs: 1 uptime: 6562 playtime: 82 db_playtime: 209 db_update: 1264178670 */ return 0; // send no info at the moment } else if ( !strcasecmp(cmd, "status") ) { _CK_ARGS(NULL_OK); roar_vio_printf(vio, "volume: %i\n", playback_get_volume_mpc(queue)); roar_vio_printf(vio, "repeat: 0\n"); roar_vio_printf(vio, "random: 0\n"); roar_vio_printf(vio, "playlist: 0\n"); roar_vio_printf(vio, "playlistlength: 0\n"); // count global number of PLEs roar_vio_printf(vio, "xfade: 0\n"); if ( playback_is_playing(queue) ) { if ( playback_is_pause(queue) == PLAYBACK_PAUSE_TRUE ) { roar_vio_printf(vio, "state: pause\n"); } else { roar_vio_printf(vio, "state: play\n"); } if ( (plent = playback_get_ple(queue)) != NULL && (s = playback_get_stream(queue)) != NULL ) { roar_vio_printf(vio, "song: 0\n"); roar_vio_printf(vio, "songid: %u\n", plent->global_short_tracknum & (uint32_t)0x7FFFFFFF); roar_vio_printf(vio, "time: %u:%u\n", (int)((float)s->pos/(s->info.rate*s->info.channels)), (unsigned)plent->length); roar_vio_printf(vio, "audio: %i:%i:%i\n", s->info.rate, s->info.bits, s->info.channels); } } else { roar_vio_printf(vio, "state: stop\n"); } return 0; } else if ( !strcasecmp(cmd, "outputs") ) { _CK_ARGS(NULL_OK); roar_vio_printf(vio, "outputid: 0\n"); roar_vio_printf(vio, "outputname: RoarAudio output\n"); roar_vio_printf(vio, "outputenabled: 1\n"); return 0; } else if ( !strcasecmp(cmd, "urlhandlers") ) { _CK_ARGS(NULL_OK); _print_handlers(vio); return 0; /* playback commands */ } else if ( !strcasecmp(cmd, "next") ) { _CK_ARGS(NULL_OK); if ( playback_next(queue) != -1 ) return 0; return -1; } else if ( !strcasecmp(cmd, "previous") ) { _CK_ARGS(NULL_OK); if ( playback_prev(queue) != -1 ) return 0; return -1; } else if ( !strcasecmp(cmd, "play") || !strcasecmp(cmd, "playid") ) { _CK_ARGS(NULL_OK); args = _dequote(args); if ( args != NULL && !strcmp(args, "-1") ) args = NULL; if ( args != NULL ) { plent = proto_mpd_parse_id(id, args); if ( plent == NULL ) { error->msg = "Song not found"; return -1; } plent = rpld_ple_copy(plent); if ( plent == NULL ) { error->msg = "Can not copy playlist entry into queue"; return -1; } pl = rpld_pl_get_by_id(queue); if ( pl != NULL ) { rpld_pl_add(pl, plent, 0); rpld_pl_unref(pl); } playback_next(queue); } if ( playback_play(queue) != -1 ) return 0; return -1; } else if ( !strcasecmp(cmd, "stop") ) { _CK_ARGS(NULL_OK); if ( playback_stop(queue, 0, 1) != -1 ) return 0; return -1; } else if ( !strcasecmp(cmd, "setvol") ) { _CK_ARGS(NULL_NOT_OK); args = _dequote(args); if ( playback_set_volume_mpc(queue, atoi(args)) == -1 ) return -1; return 0; } else if ( !strcasecmp(cmd, "pause") ) { _CK_ARGS(NULL_OK); args = _dequote(args); i = PLAYBACK_PAUSE_TOGGLE; if ( args != NULL ) { if ( atoi(args) ) { i = PLAYBACK_PAUSE_TRUE; } else { i = PLAYBACK_PAUSE_FALSE; } } if ( playback_pause(queue, i) != -1 ) return 0; return -1; /* plylist commands */ } else if ( !strcasecmp(cmd, "currentsong") ) { _CK_ARGS(NULL_OK); if ( playback_is_playing(queue) ) { plent = playback_get_ple(queue); } else { pl = rpld_pl_get_by_id(queue); if ( pl == NULL ) { plent = NULL; } else { plent = rpld_pl_get_first(pl); rpld_pl_unref(pl); } } if ( plent == NULL ) { error->error = RPLD_PROTO_MPD_ACK_ERROR_UNKNOWN; // FIXME error->msg = "Can not find current song"; return -1; } return proto_mpd_print_song(id, vio, error, plent, 0); } else if ( !strcasecmp(cmd, "playlistid") ) { _CK_ARGS(NULL_OK); ROAR_DBG("proto_mpd_pcmd(id=%i, ...): cmd='%s', args='%s'", id, cmd, args); args = _dequote(args); if ( args != NULL && !strcmp(args, "-1") ) args = NULL; if ( args != NULL ) { plent = proto_mpd_parse_id(id, args); if ( plent == NULL ) { error->msg = "Song not found"; return -1; } proto_mpd_print_song(id, vio, error, plent, pos++); return 0; } for (i = 0; i < MAX_PLAYLISTS; i++) { pl = rpld_pl_get_by_id(i); plent = rpld_pl_get_first(pl); while (plent != NULL) { proto_mpd_print_song(id, vio, error, plent, pos++); plent = plent->list.next; } rpld_pl_unref(pl); } return 0; /* control commands */ } else if ( !strcasecmp(cmd, "commands") ) { _CK_ARGS(NULL_OK); for (i = 0; _commands[i].cmd != NULL; i++) { if ( _commands[i].auth == NO ) roar_vio_printf(vio, "command: %s\n", _commands[i].cmd); } return 0; } else if ( !strcasecmp(cmd, "notcommands") ) { _CK_ARGS(NULL_OK); for (i = 0; _commands[i].cmd != NULL; i++) { if ( _commands[i].auth != NO ) roar_vio_printf(vio, "command: %s\n", _commands[i].cmd); } return 0; } error->error = RPLD_PROTO_MPD_ACK_ERROR_UNKNOWN; error->msg = "Unsupported command"; return -1; } //ll rpld-0.1.9/proto_mpd.h0000644000175000017500000000467512266574306013007 0ustar phiphi//proto_mpd.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2014 * Copyright (C) Warren Dukes 1 && buffer[len-2] == '\r' ) { len -= 2; } else { len--; } buffer[len] = 0; if ( len > 0 && buffer[0] != '#' ) { status = proto_simple_parse(id, buffer, len); } else { status = PROTO_SIMPLE_STATUS_OK; } switch (status) { case PROTO_SIMPLE_STATUS_OK: statustext = "OK"; break; case PROTO_SIMPLE_STATUS_ERROR: statustext = "Error"; break; case PROTO_SIMPLE_STATUS_INPROC: statustext = "In Process"; break; case PROTO_SIMPLE_STATUS_YES: statustext = "Yes"; break; case PROTO_SIMPLE_STATUS_NO: statustext = "No"; break; case PROTO_SIMPLE_STATUS_PROERR: statustext = "Protocol Error"; break; case PROTO_SIMPLE_STATUS_GOODBYE: statustext = "GoodBye"; break; case PROTO_SIMPLE_STATUS_NOTPERM: statustext = "Not Permitted"; break; case PROTO_SIMPLE_STATUS_NFPROERR: statustext = "Protocol or Syntax Error"; break; default: statustext = "(UNKNOWN)"; break; } if ( status == PROTO_SIMPLE_STATUS_ERROR ) { errortext = roar_error2str(roar_error); } if ( errortext != NULL ) { snprintf(buffer, sizeof(buffer), ".\n> %i %s (%s)\n", status, statustext, errortext); } else { snprintf(buffer, sizeof(buffer), ".\n> %i %s\n", status, statustext); } buffer[sizeof(buffer)-1] = 0; if ( proto_simple_client_puts(id, buffer) == -1 ) return -1; switch (status) { case PROTO_SIMPLE_STATUS_PROERR: case PROTO_SIMPLE_STATUS_GOODBYE: return -1; break; } return 0; } #define _CKPERM(p) if ( acclev < (p) ) return PROTO_SIMPLE_STATUS_NOTPERM #define NULL_OK 0 #define NULL_NOT_OK 1 #define _CKARGS(ok) if ( (ok) && args == NULL ) return PROTO_SIMPLE_STATUS_NFPROERR int proto_simple_parse(int client, char * line, size_t len) { enum rpld_client_acclev acclev = client_get_acclev(client); struct rpld_playlist_entry * plent; struct rpld_playlist * cpl, * pl; char * cmd = line; char * args; char * tmp; float tmpf; size_t i; int mode; ssize_t pos = -2; if ( (args = strstr(cmd, " ")) != NULL ) { *args = 0; args++; } ROAR_DBG("proto_simple_parse(client=%i, ...): cmd='%s'", client, cmd); if ( !strcasecmp(cmd, "noop") ) { _CKPERM(ACCLEV_CONCTL); _CKARGS(NULL_OK); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "help") ) { _CKPERM(ACCLEV_CONCTL); _CKARGS(NULL_OK); for (i = 0; proto_simple_help_text[i] != NULL; i++) { if ( proto_simple_client_puts(client, proto_simple_help_text[i]) == -1 ) return PROTO_SIMPLE_STATUS_PROERR; } return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "serverinfo") ) { _CKPERM(ACCLEV_CONCTL); _CKARGS(NULL_OK); return proto_simple_serverinfo(client); } else if ( !strcasecmp(cmd, "quit") ) { _CKPERM(ACCLEV_CONCTL); _CKARGS(NULL_OK); return PROTO_SIMPLE_STATUS_GOODBYE; } else if ( !strcasecmp(cmd, "auth") ) { _CKPERM(ACCLEV_CONCTL); _CKARGS(NULL_NOT_OK); /* " AUTH [TO AUTHLEV {n|\"name\"}] USING authtype...\n" */ return PROTO_SIMPLE_STATUS_PROERR; } else if ( !strcasecmp(cmd, "unauth") ) { _CKPERM(ACCLEV_CONCTL); _CKARGS(NULL_NOT_OK); /* " UNAUTH [ACCLEV] {BY n|TO {n|\"name\"}}\n" */ if ( !strncasecmp(args, "acclev ", 7) ) args += 7; if ( !strncmp(args, "to ", 3) ) { args += 3; if ( *args == '"' ) { args++; for (i = 0; args[i] != 0; i++) { if ( args[i] == '"' ) { args[i] = 0; break; } } if ( client_set_acclev(client, client_str2acclev(args), client) == -1 ) { return PROTO_SIMPLE_STATUS_NOTPERM; } else { return PROTO_SIMPLE_STATUS_OK; } } else { if ( client_set_acclev(client, atoi(args), client) == -1 ) { return PROTO_SIMPLE_STATUS_NOTPERM; } else { return PROTO_SIMPLE_STATUS_OK; } } } else if ( !strncmp(args, "by ", 3) ) { args += 3; if ( client_inc_acclev(client, -1*atoi(args), client) == -1 ) { return PROTO_SIMPLE_STATUS_NOTPERM; } else { return PROTO_SIMPLE_STATUS_OK; } } return PROTO_SIMPLE_STATUS_PROERR; } else if ( !strcasecmp(cmd, "play") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_OK); if ( playback_play(client_get_queue(client)) != -1 ) return PROTO_SIMPLE_STATUS_OK; return PROTO_SIMPLE_STATUS_ERROR; } else if ( !strcasecmp(cmd, "stop") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_OK); if ( playback_stop(client_get_queue(client), 0, 1) != -1 ) return PROTO_SIMPLE_STATUS_OK; return PROTO_SIMPLE_STATUS_ERROR; } else if ( !strcasecmp(cmd, "next") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_OK); if ( playback_next(client_get_queue(client)) != -1 ) return PROTO_SIMPLE_STATUS_OK; return PROTO_SIMPLE_STATUS_ERROR; } else if ( !strcasecmp(cmd, "prev") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_OK); if ( playback_prev(client_get_queue(client)) != -1 ) return PROTO_SIMPLE_STATUS_OK; return PROTO_SIMPLE_STATUS_ERROR; } else if ( !strcasecmp(cmd, "autoqueue") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_OK); if ( autoqueue(client_get_queue(client)) != -1 ) return PROTO_SIMPLE_STATUS_OK; return PROTO_SIMPLE_STATUS_ERROR; } else if ( !strcasecmp(cmd, "pause") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_NOT_OK); if ( args == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( !strcasecmp(args, "true") ) { mode = PLAYBACK_PAUSE_TRUE; } else if ( !strcasecmp(args, "false") ) { mode = PLAYBACK_PAUSE_FALSE; } else if ( !strcasecmp(args, "toggle") ) { mode = PLAYBACK_PAUSE_TOGGLE; } else { return PROTO_SIMPLE_STATUS_ERROR; } if ( playback_pause(client_get_queue(client), mode) != -1 ) return PROTO_SIMPLE_STATUS_OK; return PROTO_SIMPLE_STATUS_ERROR; } else if ( !strcasecmp(cmd, "isplaying") ) { _CKPERM(ACCLEV_GUEST); _CKARGS(NULL_OK); return playback_is_playing(client_get_queue(client)) ? PROTO_SIMPLE_STATUS_YES : PROTO_SIMPLE_STATUS_NO; } else if ( !strcasecmp(cmd, "showidentifier") ) { _CKPERM(ACCLEV_GUEST); _CKARGS(NULL_OK); if ( (args = playback_stream_identifier(client_get_queue(client))) == NULL ) return PROTO_SIMPLE_STATUS_ERROR; // TODO: do some cleanup here: if ( proto_simple_client_puts(client, args) == -1 ) return PROTO_SIMPLE_STATUS_PROERR; if ( proto_simple_client_puts(client, "\n") == 1 ) return PROTO_SIMPLE_STATUS_ERROR; return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "showplaying") ) { _CKPERM(ACCLEV_GUEST); _CKARGS(NULL_OK); return proto_simple_showplaying(client); } else if ( !strcasecmp(cmd, "listq") || !strcasecmp(cmd, "listple") ) { _CKPERM(ACCLEV_GUEST); _CKARGS(NULL_OK); if ( args == NULL ) { if ( !strcasecmp(cmd, "listq") ) { pl = rpld_pl_get_by_id(client_get_queue(client)); } else { pl = rpld_pl_get_by_id(client_get_playlist(client)); } } else { pl = proto_simple_parse_pli(args, NULL); } if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; plent = rpld_pl_get_first(pl); while (plent != NULL) { proto_simple_print_plent(client, plent); plent = plent->list.next; } rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "showcur") || !strcasecmp(cmd, "showple") ) { _CKPERM(ACCLEV_GUEST); _CKARGS(NULL_OK); if ( args == NULL ) { if ( !strcasecmp(cmd, "showcur") ) { pl = rpld_pl_get_by_id(client_get_queue(client)); if ( pl == NULL ) { plent = NULL; } else { plent = rpld_pl_get_first(pl); rpld_pl_unref(pl); } } else { return PROTO_SIMPLE_STATUS_ERROR; } } else { plent = proto_simple_parse_ple_bopts(client, args, 0); if ( plent == NULL ) return PROTO_SIMPLE_STATUS_ERROR; } if ( plent != NULL ) proto_simple_print_plent(client, plent); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "flushq") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_OK); if ( playback_stop(client_get_queue(client), 0, 1) == -1 ) return PROTO_SIMPLE_STATUS_ERROR; pl = rpld_pl_get_by_id(client_get_queue(client)); if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; rpld_pl_flush(pl); rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "setvolume") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_NOT_OK); if ( args == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( (len = strlen(args)) == 0 ) return PROTO_SIMPLE_STATUS_ERROR; switch (args[len-1]) { case '%': args[len-1] = 0; if ( playback_set_volume_mpc(client_get_queue(client), atoi(args)) == -1 ) return PROTO_SIMPLE_STATUS_ERROR; break; default: if ( playback_set_volume_mu16(client_get_queue(client), atoi(args)) == -1 ) return PROTO_SIMPLE_STATUS_ERROR; break; } return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "showvolume") ) { _CKPERM(ACCLEV_GUEST); _CKARGS(NULL_OK); return proto_simple_showvolume(client); } else if ( !strcasecmp(cmd, "listplaylists") ) { _CKPERM(ACCLEV_GUEST); _CKARGS(NULL_OK); for (i = 0; i < MAX_PLAYLISTS; i++) { pl = rpld_pl_get_by_id(i); if ( pl != NULL ) { proto_simple_print_playlist(client, pl); rpld_pl_unref(pl); } } return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "showlist") || !strcasecmp(cmd, "showqueue") ) { _CKPERM(ACCLEV_GUEST); _CKARGS(NULL_OK); if ( args == NULL ) { if ( !strcasecmp(cmd, "showqueue") ) { pl = rpld_pl_get_by_id(client_get_queue(client)); } else { pl = rpld_pl_get_by_id(client_get_playlist(client)); } } else { pl = proto_simple_parse_pli(args, NULL); } if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; proto_simple_print_playlist(client, pl); rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "delplaylist") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_OK); if ( args == NULL ) { pl = rpld_pl_get_by_id(client_get_playlist(client)); } else { pl = proto_simple_parse_pli(args, NULL); } if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; // TODO: fix this by unsetting name? rpld_pl_set_name(pl, NULL); rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "addplaylist") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_NOT_OK); if ( args == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( *args != '"' ) return PROTO_SIMPLE_STATUS_ERROR; args++; i = strlen(args); if ( args[i-1] != '"' ) return PROTO_SIMPLE_STATUS_ERROR; args[i-1] = 0; pl = rpld_pl_new(); if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; // TODO: check for errors: rpld_pl_set_name(pl, args); rpld_pl_register(pl); rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "flushplaylist") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_OK); if ( args == NULL ) { pl = rpld_pl_get_by_id(client_get_playlist(client)); } else { pl = proto_simple_parse_pli(args, NULL); } if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; rpld_pl_flush(pl); rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "setplaylist") || !strcasecmp(cmd, "setqueue") ) { _CKPERM(ACCLEV_GUEST); _CKARGS(NULL_OK); if ( args == NULL ) { pl = rpld_pl_get_by_id(client_get_playlist(client)); } else { pl = proto_simple_parse_pli(args, NULL); } if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( !strcasecmp(cmd, "setplaylist") ) { if ( client_set_playlist(client, rpld_pl_get_id(pl)) == -1 ) { rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } } else { if ( client_set_queue(client, rpld_pl_get_id(pl)) == -1 ) { rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } } rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "setparentlist") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_NOT_OK); if ( args == NULL ) return PROTO_SIMPLE_STATUS_ERROR; i = 0; if ( *args == 'O' || *args == 'o' ) { i = 1; args = strstr(args, " "); if ( args == NULL ) return PROTO_SIMPLE_STATUS_ERROR; } if ( i ) { cpl = proto_simple_parse_pli(args, NULL); args = strstr(args, " "); if ( args == NULL ) return PROTO_SIMPLE_STATUS_ERROR; } else { cpl = rpld_pl_get_by_id(client_get_playlist(client)); } if ( cpl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( *args == 'T' || *args == 't' ) { args = strstr(args, " "); if ( args == NULL ) { rpld_pl_unref(cpl); return PROTO_SIMPLE_STATUS_ERROR; } } pl = proto_simple_parse_pli(args, NULL); if ( pl == NULL ) { rpld_pl_unref(cpl); return PROTO_SIMPLE_STATUS_ERROR; } rpld_pl_set_parent(cpl, rpld_pl_get_id(pl)); rpld_pl_unref(pl); rpld_pl_unref(cpl); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "addhistory") ) { _CKPERM(ACCLEV_ALL); _CKARGS(NULL_OK); tmp = NULL; if ( args != NULL ) { if ( (args[0] == 't' || args[0] == 'T') && (args[1] == 'o' || args[1] == 'O') && args[2] == ' ' ) args += 3; tmp = strstr(args, " SIZE "); if ( tmp == NULL ) tmp = strstr(args, " size "); if ( tmp == NULL ) { tmp = strstr(args, "SIZE "); if ( tmp == NULL ) tmp = strstr(args, "size "); if ( tmp == args ) { args = ""; } else { tmp = NULL; } } if ( tmp != NULL && tmp[0] == ' ' ) { *tmp = 0; tmp += 6; } else if ( tmp != NULL ) { *tmp = 0; tmp += 5; } if ( *args == 0 ) args = NULL; } if ( args == NULL ) { pl = rpld_pl_get_by_id(client_get_playlist(client)); } else { pl = proto_simple_parse_pli(args, NULL); } if ( tmp == NULL ) tmp = "42"; // TODO: FIXME: use global const here. if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( rpld_pl_set_histsize(pl, atoi(tmp)) == -1 ) { rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "delhistory") ) { _CKPERM(ACCLEV_ALL); _CKARGS(NULL_OK); if ( args == NULL ) { pl = rpld_pl_get_by_id(client_get_playlist(client)); } else { pl = proto_simple_parse_pli(args, NULL); } if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( rpld_pl_set_histsize(pl, -1) == -1 ) { rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "addqueue") ) { _CKPERM(ACCLEV_ALL); _CKARGS(NULL_NOT_OK); return proto_simple_addqueue(client, args); } else if ( !strcasecmp(cmd, "delqueue") ) { _CKPERM(ACCLEV_ALL); _CKARGS(NULL_OK); if ( args == NULL ) { pl = rpld_pl_get_by_id(client_get_playlist(client)); } else { pl = proto_simple_parse_pli(args, NULL); } if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( playback_del_queue(pl) == -1 ) { rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "copyple") || !strcasecmp(cmd, "queueple") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_NOT_OK); if ( args == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( (plent = proto_simple_parse_ple_bopts(client, args, 0)) == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( !strcasecmp(cmd, "queueple") ) { pl = rpld_pl_get_by_id(client_get_queue(client)); } else { if ( (tmp = strstr(args, " TO ")) == NULL ) if ( (tmp = strstr(args, " to ")) == NULL ) return PROTO_SIMPLE_STATUS_ERROR; args = tmp + 4; pl = proto_simple_parse_pli(args, NULL); if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; } tmp = NULL; if ( (tmp = strstr(args, " AT ")) == NULL ) tmp = strstr(args, " at "); if ( tmp != NULL ) { args = tmp + 4; pos = atoi(args); } if ( (plent = rpld_ple_copy(plent)) == NULL ) { rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } if ( pos == -2 ) { rpld_pl_push(pl, plent); } else { if ( pos == -1 && pl->queue != NULL && playback_is_playing(rpld_pl_get_id(pl)) ) { playback_stop(rpld_pl_get_id(pl), 0, 1); rpld_pl_add(pl, plent, pos); playback_play(rpld_pl_get_id(pl)); } else { rpld_pl_add(pl, plent, pos); } } rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "moveple") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_NOT_OK); if ( args == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( (tmp = strstr(args, " TO ")) == NULL ) if ( (tmp = strstr(args, " to ")) == NULL ) return PROTO_SIMPLE_STATUS_ERROR; pl = proto_simple_parse_pli(tmp+4, NULL); if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( (plent = proto_simple_parse_ple_bopts(client, args, 1)) == NULL ) { rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } if ( (plent = rpld_ple_cut_out_next(plent)) == NULL ) { rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } tmp = NULL; if ( (tmp = strstr(args, " AT ")) == NULL ) tmp = strstr(args, " at "); if ( tmp != NULL ) { args = tmp + 4; pos = atoi(args); } if ( pos == -2 ) { rpld_pl_push(pl, plent); } else { if ( pos == -1 && pl->queue == NULL && playback_is_playing(rpld_pl_get_id(pl)) ) { playback_stop(rpld_pl_get_id(pl), 0, 1); rpld_pl_add(pl, plent, pos); playback_play(rpld_pl_get_id(pl)); } else { rpld_pl_add(pl, plent, pos); } } rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "delple") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_NOT_OK); if ( args == NULL ) return PROTO_SIMPLE_STATUS_ERROR; ROAR_DBG("proto_simple_parse(*) = ?"); if ( (plent = proto_simple_parse_ple_bopts(client, args, 1)) == NULL ) return PROTO_SIMPLE_STATUS_ERROR; ROAR_DBG("proto_simple_parse(*) = ?"); if ( (plent = rpld_ple_cut_out_next(plent)) == NULL ) return PROTO_SIMPLE_STATUS_ERROR; ROAR_DBG("proto_simple_parse(*) = ?"); rpld_ple_free(plent); return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "like") || !strcasecmp(cmd, "dislike") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_NOT_OK); if ( args == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( (plent = proto_simple_parse_ple_bopts(client, args, 0)) == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( (tmp = strrchr(args, ' ')) == NULL ) return PROTO_SIMPLE_STATUS_ERROR; tmpf = atof(tmp+1); if ( !strcasecmp(cmd, "dislike") ) tmpf *= -1; plent->likeness += tmpf; return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "import") || !strcasecmp(cmd, "export") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_NOT_OK); return proto_simple_import_export(client, args, !strcasecmp(cmd, "export")); } else if ( !strcasecmp(cmd, "searchple") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_NOT_OK); return proto_simple_searchple(client, args); } else if ( !strcasecmp(cmd, "store") ) { _CKPERM(ACCLEV_ALL); _CKARGS(NULL_OK); if ( store() == -1 ) return PROTO_SIMPLE_STATUS_ERROR; return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "restore") ) { _CKPERM(ACCLEV_ALL); _CKARGS(NULL_OK); if ( restore() == -1 ) return PROTO_SIMPLE_STATUS_ERROR; return PROTO_SIMPLE_STATUS_OK; } else if ( !strcasecmp(cmd, "setpointer") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_NOT_OK); return proto_simple_setpointer(client, args); } else if ( !strcasecmp(cmd, "unsetpointer") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_NOT_OK); return proto_simple_unsetpointer(client, args); } else if ( !strcasecmp(cmd, "showpointer") ) { _CKPERM(ACCLEV_GUEST); _CKARGS(NULL_OK); if ( args == NULL ) { return proto_simple_showpointer_all(client); } else { return proto_simple_showpointer(client, args, 0); } } else if ( !strcasecmp(cmd, "listclients") ) { _CKPERM(ACCLEV_USER); _CKARGS(NULL_OK); return proto_simple_listclients(client); } else if ( !strcasecmp(cmd, "identify") ) { _CKPERM(ACCLEV_CONCTL); _CKARGS(NULL_OK); return proto_simple_identify(client, args); } // unknown command return PROTO_SIMPLE_STATUS_PROERR; } int proto_simple_print_plent(int client, struct rpld_playlist_entry * plent) { char buffer[1024]; char uuid[37]; roar_uuid2str(uuid, plent->uuid, sizeof(uuid)); //TYPE=LENGTH=ALBUM=TITLE=ARTIST=VERSION=FILE snprintf(buffer, sizeof(buffer) - 1, "%s=%s=%s=%s=%s=%s=%s=%s=long:0x%.16" __ll "X/short:0x%.8X/uuid:%s=0x%.8x/%i=%s(0x%x)=%f\n", roar_codec2str(plent->codec), rpld_ple_time_hr(plent), plent->meta.album, plent->meta.title, plent->meta.artist, plent->meta.performer, plent->meta.version, rpld_ple_get_filename(plent, -1, NULL), (__longlong unsigned int)plent->global_tracknum, plent->global_short_tracknum, uuid, plent->meta.discid, plent->meta.tracknum, roar_meta_strgenre(plent->meta.genre), plent->meta.genre, (double)plent->likeness ); buffer[1023] = 0; return proto_simple_client_puts(client, buffer); } struct rpld_playlist * proto_simple_parse_pli(char * txt, char ** next) { struct rpld_playlist * ret = NULL; char * end = NULL; char saved; if ( txt == NULL ) return NULL; if ( next != NULL ) *next = NULL; ROAR_DBG("proto_simple_parse_pli(txt='%s') = ?", txt); if ( *txt == '"' ) { if ( (end = strstr(txt+1, "\"")) == NULL ) return NULL; saved = *end; *end = 0; ret = rpld_pl_get_by_name(txt+1); *end = saved; end++; } else { end = strstr(txt+1, " "); if ( end != NULL ) { saved = *end; *end = 0; } ret = rpld_pl_get_by_id(atoi(txt)); if ( end != NULL ) *end = saved; } if ( next != NULL ) { if ( end != NULL ) { *next = end; } else { *next = txt + roar_mm_strlen(txt); } } ROAR_DBG("proto_simple_parse_pli(txt='%s') = %p", txt, ret); return ret; } int proto_simple_print_playlist (int client, struct rpld_playlist * pl) { const char * name; int id, parent; ssize_t histsize; struct rpld_queue * plq; char buf[768]; char options[512] = ""; if ( pl == NULL ) return -1; id = rpld_pl_get_id(pl); parent = rpld_pl_get_parent(pl); name = rpld_pl_get_name(pl); histsize = rpld_pl_get_histsize(pl); plq = pl->queue; if ( histsize != -1 ) { snprintf(options, sizeof(options), "history size: %" __ll "u", (__longlong unsigned int)histsize); } else if ( plq != NULL ) { snprintf(options, sizeof(options), "volume: %u/65535, role: %s, history: %i, backend: \"%s\", mixer: %i", (unsigned int)plq->volume_mono, roar_role2str(plq->role), (int)rpld_pl_get_id(plq->history), backend_get_name(plq->backend), plq->mixer ); } snprintf(buf, sizeof(buf), "%3i: [parent: %i%s%s] \"%s\"\n", id, parent, *options ? ", " : "", options, name); buf[sizeof(buf)-1] = 0; proto_simple_client_puts(client, buf); return 0; } int proto_simple_parse_ple_bopts_noeval(int client, char * txt, int need_prev, int * try_any, struct rpld_playlist ** pl, struct rpld_playlist_search * pls) { struct rpld_playlist_pointer * pointer = NULL; char * ei = txt; char * from; char * pli = NULL; char from_save = 0; __longlong unsigned int tmp; if ( txt == NULL || client == -1 ) return -1; if ( (from = strstr(ei, " ")) != NULL ) { if ( !strncasecmp(from, " from ", 6) ) { pli = strstr(from+1, " "); } from_save = *from; *from = 0; } if ( pli == NULL ) { *pl = rpld_pl_get_by_id(client_get_playlist(client)); } else { pli++; ROAR_DBG("proto_simple_parse_ple_bopts(*): pli='%s'", pli); if ( !strcasecmp(pli, "any") || !strncasecmp(pli, "any ", 4) ) { *pl = NULL; *try_any = 1; } else { *pl = proto_simple_parse_pli(pli, NULL); } } if ( *pl == NULL && !*try_any ) { if ( from != NULL ) *from = from_save; return -1; } ROAR_DBG("proto_simple_parse_ple_bopts(*): ei='%s', from='%s', pli='%s'", ei, from, pli); memset(pls, 0, sizeof(*pls)); if ( need_prev ) pls->options |= RPLD_PL_SO_PREVIOUS; if ( !strncmp(ei, "short:", 6) ) { if ( sscanf(ei+6, "0x%8X", &(pls->subject.short_tracknum)) != 1 ) pls->subject.short_tracknum = 0; pls->type = RPLD_PL_ST_TRACKNUM_SHORT; ROAR_DBG("proto_simple_parse_ple_bopts(*): pls->subject.short_tracknum=0x%.8X", pls->subject.short_tracknum); } else if ( !strncmp(ei, "long:", 5) || *ei == '0' ) { if ( *ei == 'l' ) ei += 5; if ( sscanf(ei, "0x%16" __ll "X", &tmp) != 1 ) { pls->subject.long_tracknum = 0; } else { pls->subject.long_tracknum = tmp; } pls->type = RPLD_PL_ST_TRACKNUM_LONG; ROAR_DBG("proto_simple_parse_ple_bopts(*): pls->subject.long_tracknum=0x%.16" __ll "X", (__longlong unsigned int)pls->subject.long_tracknum); } else if ( !strncmp(ei, "pointer:", 8) ) { pointer = rpld_pointer_get_by_name(ei+8, client); if ( pointer == NULL ) { if ( from != NULL ) *from = from_save; return -1; } else { if ( pointer->pls.type == RPLD_PL_ST_RANDOM || pointer->pls.type == RPLD_PL_ST_RANDOM_LIKENESS ) { *pl = rpld_pl_get_by_id(pointer->pls.subject.pl); } else { *pl = pointer->hint.pl; if ( *pl != NULL ) rpld_pl_ref(*pl); } if ( *pl == NULL ) *try_any = 1; memcpy(pls, &(pointer->pls), sizeof(*pls)); rpld_plp_unref(pointer); } } else if ( !strncmp(ei, "uuid:", 5) ) { if ( roar_str2uuid(pls->subject.uuid, ei+5) != 0 ) roar_uuid_clear(pls->subject.uuid); pls->type = RPLD_PL_ST_UUID; } else if ( !strncmp(ei, "num:", 4) ) { pls->subject.num = (size_t)atoi(ei+4); pls->type = RPLD_PL_ST_NUM; } else if ( !strncmp(ei, "likeness:", 9) ) { pls->subject.likeness = (float)atof(ei+9); pls->type = RPLD_PL_ST_LIKENESS; } else if ( !strncmp(ei, "random:", 7) ) { pls->subject.pl = atoi(ei+7); if ( *pl != NULL && pls->subject.pl == 0 ) { pls->subject.pl = rpld_pl_get_id(*pl); } if ( *pl != NULL ) rpld_pl_unref(*pl); *pl = rpld_pl_get_by_id(pls->subject.pl); pls->type = RPLD_PL_ST_RANDOM; } else if ( !strncmp(ei, "randomlike:", 11) ) { pls->subject.pl = atoi(ei+11); if ( *pl != NULL && pls->subject.pl == 0 ) { pls->subject.pl = rpld_pl_get_id(*pl); } if ( *pl != NULL ) rpld_pl_unref(*pl); *pl = rpld_pl_get_by_id(pls->subject.pl); pls->type = RPLD_PL_ST_RANDOM_LIKENESS; } else { ROAR_WARN("proto_simple_parse_ple_bopts(*): Unknown PLE format: %s", ei); if ( from != NULL ) *from = from_save; return -1; } if ( from != NULL ) *from = from_save; return 0; } struct rpld_playlist_entry * proto_simple_parse_ple_bopts_eval(int try_any, struct rpld_playlist * pl, struct rpld_playlist_search * pls) { struct rpld_playlist_entry * ret = NULL; size_t i; if ( try_any ) { for (i = 0; i < MAX_PLAYLISTS; i++) { if ( g_playlists[i] != NULL ) { if ( (ret = rpld_pl_search(g_playlists[i], pls, NULL)) != NULL ) break; } } } else { ret = rpld_pl_search(pl, pls, NULL); } return ret; } struct rpld_playlist_entry * proto_simple_parse_ple_bopts(int client, char * txt, int need_prev) { struct rpld_playlist_entry * ret; struct rpld_playlist_search pls; struct rpld_playlist * pl = NULL; int try_any = 0; if ( proto_simple_parse_ple_bopts_noeval(client, txt, need_prev, &try_any, &pl, &pls) == -1 ) { return NULL; } ret = proto_simple_parse_ple_bopts_eval(try_any, pl, &pls); if ( pl != NULL ) rpld_pl_unref(pl); return ret; } int proto_simple_import_export (int client, char * args, int is_export) { struct roar_vio_defaults def; struct fformat_handle * handle; struct roar_vio_calls vio; struct rpld_playlist * pl = NULL; int format; char * ftpos; char * tpos; const char * delm; int ret; /* IMPORT [{"Name"|ID}] {TO|FROM} {STDIN|STDOUT|"Filename"} [AS {RPLD|PLS|M3U|VCLT|XSPF}] EXPORT [{"Name"|ID}] {TO|FROM} {STDIN|STDOUT|"Filename"} [AS {RPLD|PLS|M3U|VCLT|XSPF}] */ ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i) = ?", client, args, is_export); if ( client == -1 || args == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( is_export ) { if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_WRONLY|O_CREAT|O_TRUNC, 0644) == -1 ) return PROTO_SIMPLE_STATUS_ERROR; } else { if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 ) return PROTO_SIMPLE_STATUS_ERROR; } ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i) = ?", client, args, is_export); if ( *args == 'f' || *args == 'F' ) { pl = rpld_pl_get_by_id(client_get_playlist(client)); args += 5; } else if ( *args == 't' || *args == 'T' ) { pl = rpld_pl_get_by_id(client_get_playlist(client)); args += 3; } else { if ( (ftpos = strstr(args, " FROM ")) == NULL ) if ( (ftpos = strstr(args, " from ")) == NULL ) if ( (ftpos = strstr(args, " TO ")) == NULL ) if ( (ftpos = strstr(args, " to ")) == NULL ) return PROTO_SIMPLE_STATUS_ERROR; pl = proto_simple_parse_pli(args, NULL); args = ftpos + 1; if ( *ftpos == 'f' || *ftpos == 'F' ) { args += 5; } else { args += 3; } } if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i) = ?", client, args, is_export); ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i): *args='%c'", client, args, is_export, *args); switch (*args) { case '\"': delm = "\""; break; case '\'': delm = "\'"; break; default: delm = " "; break; } ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i): delm='%s'", client, args, is_export, delm); if ( (tpos = strstr(*args == *delm ? args+1 : args, delm)) == NULL ) { format = RPLD_FF_PLF_DEFAULT; } else { *tpos = 0; tpos++; ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i) = ?", client, args, is_export); ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i): *tpos='%c'", client, args, is_export, *tpos); if ( *tpos == 0 ) { ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i) = ?", client, args, is_export); format = RPLD_FF_PLF_DEFAULT; } else { ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i): tpos='%s'", client, args, is_export, tpos); remove_spaces(&tpos); ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i): tpos='%s'", client, args, is_export, tpos); if ( strncasecmp(tpos, "as ", 3) ) return PROTO_SIMPLE_STATUS_ERROR; tpos += 3; format = fformat_str2plf(tpos); } } if ( format == -1 ) { rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i) = ?", client, args, is_export); if ( (handle = fformat_handle_new(format)) == NULL ) { rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i) = ?", client, args, is_export); if ( !strcasecmp(args, "stdout") || !strcasecmp(args, "stdin") ) { if ( rpld_proto_simple_vio_open(&vio, client_get_vio(client)) == -1 ) { fformat_handle_close(handle); rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } } else if ( *args == '"' ) { args++; ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i) = ?", client, args, is_export); if ( roar_vio_open_dstr(&vio, args, &def, 1) == -1 ) { fformat_handle_close(handle); rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i) = ?", client, args, is_export); } else { fformat_handle_close(handle); rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i) = ?", client, args, is_export); if ( is_export ) { ret = fformat_playlist_export(handle, &vio, pl); } else { ret = fformat_playlist_import(handle, &vio, pl); } roar_vio_close(&vio); fformat_handle_close(handle); rpld_pl_unref(pl); ROAR_DBG("proto_simple_import_export(client=%i, args='%s', is_export=%i) = ?", client, args, is_export); if ( ret == -1 ) { // we return PROTO_SIMPLE_STATUS_PROERR in case of import as we do not read up all input // which would result as input read as commands in case we would not terminate te connection. return is_export ? PROTO_SIMPLE_STATUS_ERROR : PROTO_SIMPLE_STATUS_PROERR; } else { return PROTO_SIMPLE_STATUS_OK; } } int proto_simple_showvolume (int client) { pli_t queue = client_get_queue(client); char buf[80]; snprintf(buf, sizeof(buf), "VOLUME %i/65535 %i%%\n", playback_get_volume_mu16(queue), playback_get_volume_mpc(queue)); proto_simple_client_puts(client, buf); return PROTO_SIMPLE_STATUS_OK; } #define _BS 80 int proto_simple_showplaying (int client) { struct rpld_playlist_entry * plent; const struct roar_stream * s; char buf[_BS]; char uuid[37]; if ( !playback_is_playing(client_get_queue(client)) ) { proto_simple_client_puts(client, "STATE STOPPED\n"); return PROTO_SIMPLE_STATUS_OK; } if ( playback_is_pause(client_get_queue(client)) == PLAYBACK_PAUSE_TRUE ) { proto_simple_client_puts(client, "STATE PAUSE\n"); } else { proto_simple_client_puts(client, "STATE RUNNING\n"); } plent = playback_get_ple(client_get_queue(client)); if ( plent == NULL ) return PROTO_SIMPLE_STATUS_ERROR; /* * "%s=%s=%s=%s=%s=%s=%s=%s=long:0x%.16llX/short:0x%.8X/uuid:%s=0x%.8x/%i=%s(0x%x)\n", */ snprintf(buf, _BS, "LONGGTN long:0x%.16" __ll "X\n", (__longlong unsigned int)plent->global_tracknum); proto_simple_client_puts(client, buf); snprintf(buf, _BS, "SHORTGTN short:0x%.8X\n", plent->global_short_tracknum); proto_simple_client_puts(client, buf); roar_uuid2str(uuid, plent->uuid, sizeof(uuid)); snprintf(buf, _BS, "UUID uuid:%s\n", uuid); proto_simple_client_puts(client, buf); // send meta data: if ( *(plent->meta.album) != 0 ) { snprintf(buf, _BS, "META ALBUM \"%s\"\n", plent->meta.album); proto_simple_client_puts(client, buf); } if ( *(plent->meta.title) != 0 ) { snprintf(buf, _BS, "META TITLE \"%s\"\n", plent->meta.title); proto_simple_client_puts(client, buf); } if ( *(plent->meta.artist) != 0 ) { snprintf(buf, _BS, "META ARTIST \"%s\"\n", plent->meta.artist); proto_simple_client_puts(client, buf); } if ( *(plent->meta.performer) != 0 ) { snprintf(buf, _BS, "META PERFORMER \"%s\"\n", plent->meta.performer); proto_simple_client_puts(client, buf); } if ( *(plent->meta.version) != 0 ) { snprintf(buf, _BS, "META VERSION \"%s\"\n", plent->meta.version); proto_simple_client_puts(client, buf); } snprintf(buf, _BS, "MDUC %lu\n", (unsigned long int)playback_get_mduc(client_get_queue(client))); proto_simple_client_puts(client, buf); // TODO: FIXME: add support for genre, tracknum and discid if ( (s = playback_get_stream(client_get_queue(client))) == NULL ) return PROTO_SIMPLE_STATUS_ERROR; if ( s->info.rate ) { snprintf(buf, _BS, "RATE %i\n", s->info.rate); proto_simple_client_puts(client, buf); } if ( s->info.channels ) { snprintf(buf, _BS, "CHANNELS %i\n", s->info.channels); proto_simple_client_puts(client, buf); } if ( s->info.bits ) { snprintf(buf, _BS, "BITS %i\n", s->info.bits); proto_simple_client_puts(client, buf); } if ( (int32_t) s->pos != -1 ) { if ( s->info.rate && s->info.channels ) { snprintf(buf, _BS, "TIME %lu S (%.3fs)\n", (unsigned long int) s->pos, (float)s->pos/(s->info.rate*s->info.channels)); } else { snprintf(buf, _BS, "TIME %lu S\n", (unsigned long int) s->pos); } proto_simple_client_puts(client, buf); } return PROTO_SIMPLE_STATUS_OK; } int proto_simple_unsetpointer(int client, char * args) { if ( rpld_pointer_set_by_name(args, client, NULL) == -1 ) return PROTO_SIMPLE_STATUS_ERROR; return PROTO_SIMPLE_STATUS_OK; } int proto_simple_setpointer(int client, char * args) { struct rpld_playlist * pl = NULL; struct rpld_playlist_search pls; struct rpld_playlist_entry * ple; struct rpld_playlist_pointer * plp; char * pointer_name; char * bopts; int try_any = 0; // SETPOINTER {CURRENT|DEFAULT} {long:0xLongID|0xLongID|short:0xShortID|uuid:UUID} [FROM {"Name"|ID}] if ( args == NULL ) return PROTO_SIMPLE_STATUS_ERROR; pointer_name = args; if ( (bopts = strstr(args, " ")) == NULL ) return PROTO_SIMPLE_STATUS_ERROR; *bopts = 0; bopts++; if ( !strncasecmp(bopts, "to ", 3) ) { bopts += 3; } if ( proto_simple_parse_ple_bopts_noeval(client, bopts, 0, &try_any, &pl, &pls) == -1 ) return PROTO_SIMPLE_STATUS_ERROR; if ( !(pls.type == RPLD_PL_ST_RANDOM || pls.type == RPLD_PL_ST_RANDOM_LIKENESS) ) { ple = proto_simple_parse_ple_bopts_eval(try_any, pl, &pls); if ( ple == NULL ) return PROTO_SIMPLE_STATUS_ERROR; memset(&pls, 0, sizeof(pls)); pls.type = RPLD_PL_ST_UUID; memcpy(pls.subject.uuid, ple->uuid, sizeof(pls.subject.uuid)); } plp = rpld_plp_init(NULL, &pls); if ( rpld_pointer_set_by_name(pointer_name, client, plp) == -1 ) { rpld_plp_unref(plp); if ( pl != NULL ) rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } rpld_plp_unref(plp); if ( pl != NULL ) rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_OK; } int proto_simple_showpointer(int client, char * name, int no_rename) { pli_t queue; int pointer, pointer_client; struct rpld_playlist_pointer * plp; char * text = NULL; char uuid[37]; if ( client == -1 || name == NULL || *name == 0 ) return PROTO_SIMPLE_STATUS_ERROR; if ( rpld_pointer_parse_name(&pointer, &queue, &pointer_client, client, name) == -1 ) return PROTO_SIMPLE_STATUS_ERROR; if ( no_rename ) { name = roar_mm_strdup(name); } else { name = rpld_pointer_get_name(pointer, queue, queue == (pli_t)-1 ? pointer_client : -1); } if ( name == NULL ) return PROTO_SIMPLE_STATUS_ERROR; plp = rpld_pointer_get(pointer, queue, pointer_client); if ( plp == NULL ) { asprintf(&text, "POINTER %s NOT SET\n", name); } else { switch (plp->pls.type) { case RPLD_PL_ST_TRACKNUM_LONG: asprintf(&text, "POINTER %s IS AT long:0x0x%.16" __ll "X\n", name, (__longlong unsigned int)plp->pls.subject.long_tracknum); break; case RPLD_PL_ST_TRACKNUM_SHORT: asprintf(&text, "POINTER %s IS AT short:0x0x%.8X\n", name, plp->pls.subject.short_tracknum); break; case RPLD_PL_ST_UUID: roar_uuid2str(uuid, plp->pls.subject.uuid, sizeof(uuid)); asprintf(&text, "POINTER %s IS AT uuid:%s\n", name, uuid); break; case RPLD_PL_ST_RANDOM: asprintf(&text, "POINTER %s IS AT random:%i\n", name, plp->pls.subject.pl); break; case RPLD_PL_ST_RANDOM_LIKENESS: asprintf(&text, "POINTER %s IS AT randomlike:%i\n", name, plp->pls.subject.pl); break; default: return PROTO_SIMPLE_STATUS_ERROR; } } roar_mm_free(name); rpld_plp_unref(plp); if ( proto_simple_client_puts(client, text) == -1 ) { free(text); return PROTO_SIMPLE_STATUS_ERROR; } free(text); return PROTO_SIMPLE_STATUS_OK; } int proto_simple_showpointer_all(int client) { int pointer; pli_t queue; size_t i; char * name; for (i = 0; i < MAX_PLAYLISTS; i++) { if ( g_playlists[i] == NULL ) continue; if ( g_playlists[i]->queue == NULL ) continue; queue = g_playlists[i]->id; for (pointer = 0; pointer < POINTER_NUM; pointer++) { if ( pointer == POINTER_TEMP ) continue; name = rpld_pointer_get_name(pointer, queue, -1); proto_simple_showpointer(client, name, 1); roar_mm_free(name); } } for (i = 0; i < RPLD_CLIENTS_MAX; i++) { if ( client_get_proto(i) == RPLD_PROTO_UNUSED ) continue; name = rpld_pointer_get_name(POINTER_TEMP, -1, i); proto_simple_showpointer(client, name, 1); roar_mm_free(name); } return PROTO_SIMPLE_STATUS_OK; } static struct addqueue_para proto_simple_parse_addqueue(int client, char * txt) { // ADDQUEUE [[TO] {"Name"|ID}] [WITH BACKEND backend] [MIXER n] WITH HISTORY {"Name"|ID} [WITH ROLE role] struct addqueue_para ret = {.queue = -1, .history = -1, .backend = "+default", .mixer = -1, .role = -1}; struct rpld_playlist * pl; const char * tmp; ROAR_DBG("proto_simple_parse_addqueue(client=%i, txt='%s') = ?", client, txt); remove_spaces(&txt); ROAR_DBG("proto_simple_parse_addqueue(client=%i, txt='%s') = ?", client, txt); if ( (txt[0] == 't' || txt[0] == 'T') && (txt[1] == 'o' || txt[1] == 'O') && txt[2] == ' ' ) { txt += 3; remove_spaces(&txt); } ROAR_DBG("proto_simple_parse_addqueue(client=%i, txt='%s') = ?", client, txt); if ( *txt == '\'' || *txt == '\"' || (*txt >= '0' && *txt <= '9' ) ) { pl = proto_simple_parse_pli(txt, &txt); } else { pl = rpld_pl_get_by_id(client_get_playlist(client)); } if ( pl == NULL ) return ret; // queue is still set to -1, which means error. ROAR_DBG("proto_simple_parse_addqueue(client=%i, txt='%s') = ?", client, txt); ret.queue = rpld_pl_get_id(pl); rpld_pl_unref(pl); ROAR_DBG("proto_simple_parse_addqueue(client=%i, txt='%s') = ?", client, txt); while (txt != NULL && *txt) { remove_spaces(&txt); ROAR_DBG("proto_simple_parse_addqueue(client=%i, txt='%s') = ?", client, txt); if ( !strncasecmp(txt, "with backend ", 13) ) { txt += 13; ret.backend = __parse_string(&txt, "+default"); if ( ret.backend == NULL ) { ret.queue = -1; return ret; } } else if ( !strncasecmp(txt, "mixer ", 6) ) { txt += 6; ret.mixer = strtol(txt, &txt, 0); } else if ( !strncasecmp(txt, "with history ", 13) ) { txt += 13; pl = proto_simple_parse_pli(txt, &txt); if ( pl == NULL ) { ret.queue = -1; return ret; } ret.history = rpld_pl_get_id(pl); rpld_pl_unref(pl); } else if ( !strncasecmp(txt, "with role", 9) ) { txt += 9; tmp = __parse_string(&txt, "music"); if (tmp == NULL) { ret.history = ret.queue = -1; roar_err_set(ROAR_ERROR_ILLSEQ); return ret; } ret.role = roar_str2role(tmp); } else { ret.history = ret.queue = -1; roar_err_set(ROAR_ERROR_ILLSEQ); return ret; } } ROAR_DBG("proto_simple_parse_addqueue(client=%i, txt='%s') = ?", client, txt); if ( ret.history == (pli_t)-1 ) ret.queue = -1; ROAR_DBG("proto_simple_parse_addqueue(client=%i, txt='%s') = ?", client, txt); return ret; } static int proto_simple_addqueue(int client, char * txt) { struct addqueue_para para; struct rpld_playlist * pl, * history; ROAR_DBG("proto_simple_addqueue(client=%i, txt='%s') = ?", client, txt); if ( txt == NULL ) return PROTO_SIMPLE_STATUS_ERROR; ROAR_DBG("proto_simple_addqueue(client=%i, txt='%s') = ?", client, txt); para = proto_simple_parse_addqueue(client, txt); ROAR_DBG("proto_simple_addqueue(client=%i, txt='%s') = ?", client, txt); if ( para.queue == (pli_t)-1 ) return PROTO_SIMPLE_STATUS_ERROR; ROAR_DBG("proto_simple_addqueue(client=%i, txt='%s') = ?", client, txt); pl = rpld_pl_get_by_id(para.queue); if ( pl == NULL ) return PROTO_SIMPLE_STATUS_ERROR; ROAR_DBG("proto_simple_addqueue(client=%i, txt='%s') = ?", client, txt); history = rpld_pl_get_by_id(para.history); if ( history == NULL ) { rpld_pl_unref(pl); return PROTO_SIMPLE_STATUS_ERROR; } ROAR_DBG("proto_simple_addqueue(client=%i, txt='%s') = ?", client, txt); if ( playback_add_queue(pl, para.backend, para.mixer, history) == -1 ) { rpld_pl_unref(pl); rpld_pl_unref(history); ROAR_DBG("proto_simple_addqueue(client=%i, txt='%s') = PROTO_SIMPLE_STATUS_ERROR", client, txt); return PROTO_SIMPLE_STATUS_ERROR; } rpld_pl_unref(pl); rpld_pl_unref(history); playback_set_role(para.queue, para.role); ROAR_DBG("proto_simple_addqueue(client=%i, txt='%s') = PROTO_SIMPLE_STATUS_OK", client, txt); return PROTO_SIMPLE_STATUS_OK; } int proto_simple_listclients (int client) { char buf[256]; int i; int proto; const char * name; for (i = 0; i < RPLD_CLIENTS_MAX; i++) { proto = client_get_proto(i); if ( proto == RPLD_PROTO_UNUSED ) continue; name = client_get_name(i); buf[sizeof(buf)-2] = 0; snprintf(buf, sizeof(buf), "%3i: [protocol: \"%s\", acclev: %s, playlist: %i, queue: %i]%s%s%s\n", i, client_proto2str(proto), client_acclev2str(client_get_acclev(i)), client_get_playlist(i), client_get_queue(i), name == NULL ? "" : " \"", name == NULL ? "" : name, name == NULL ? "" : "\""); buf[sizeof(buf)-1] = 0; if ( buf[strlen(buf)-1] != '\n' ) { ROAR_WARN("proto_simple_listclients(client=%i): Buffer too small for client listing: client=%i, proto=%i", client, i, proto); snprintf(buf, sizeof(buf), "%3i: []\n", i); buf[sizeof(buf)-1] = 0; } proto_simple_client_puts(client, buf); } return PROTO_SIMPLE_STATUS_OK; } int proto_simple_identify(int client, char * txt) { const char * name = NULL; const char * nodename = NULL; pid_t pid = 0; long int hostid = 0; remove_spaces(&txt); while (txt != NULL && *txt) { remove_spaces(&txt); if ( !!strncasecmp(txt, "with ", 5) ) { roar_err_set(ROAR_ERROR_ILLSEQ); return PROTO_SIMPLE_STATUS_ERROR; } txt += 5; remove_spaces(&txt); /* X NAME * PID * NODENAME * HOSTID */ if ( !strncasecmp(txt, "name ", 5) ) { txt += 5; name = __parse_string(&txt, NULL); } else if ( !strncasecmp(txt, "pid ", 4) ) { txt += 4; pid = strtol(txt, &txt, 0); } else if ( !strncasecmp(txt, "nodename ", 9) ) { txt += 9; nodename = __parse_string(&txt, NULL); } else if ( !strncasecmp(txt, "hostid ", 7) ) { txt += 7; hostid = strtol(txt, &txt, 0); } else { roar_err_set(ROAR_ERROR_BADRQC); return PROTO_SIMPLE_STATUS_ERROR; } } // avoid compiler warnings. Those will likely be used later. _LIBROAR_IGNORE_RET(hostid); _LIBROAR_IGNORE_RET(pid); _LIBROAR_IGNORE_RET(nodename); if ( name != NULL ) client_set_name(client, name); return PROTO_SIMPLE_STATUS_OK; } static int proto_simple_serverinfo(int client) { const struct roar_server_info * info = rpld_serverinfo_get(); char buf[1024]; proto_simple_client_puts(client, "X-APPLICATION \"" APPLICATION_NAME "\"\n"); #define _display2(var,prefix) \ if ( info->var != NULL ) { \ snprintf(buf, sizeof(buf), prefix "\n", info->var); \ proto_simple_client_puts(client, buf); \ } #define _display(var,prefix) _display2(var,prefix " \"%s\"") _display(version, "VERSION") _display(location, "LOCATION") _display(description, "DESCRIPTION") _display(contact, "CONTACT") _display(serial, "SERIAL") _display(address, "ADDRESS") _display(uiurl, "UIURL") _display2(hostid, "HOSTID %s") _display(license, "LICENSE") _display(build, "BUILD") _display(un.sysname, "SYSTEM NAME") _display(un.release, "SYSTEM RELEASE") _display(un.nodename, "SYSTEM NODENAME") _display(un.machine, "SYSTEM MACHINE") #undef _display #undef _display2 return PROTO_SIMPLE_STATUS_OK; } static inline void __searchple_handle_playlist(int client, struct rpld_playlist * pl, const void * needle, const char * key, int options, int neg) { struct rpld_playlist_entry * plent = rpld_pl_get_first(pl); int ret; while (plent != NULL) { ret = rpld_ple_filter(plent, needle, key, options); // if ( (ret == 1 && !neg) || (ret == 0 && neg) ) if ( ret ^ neg ) proto_simple_print_plent(client, plent); plent = plent->list.next; } } static int proto_simple_searchple(int client, char * args) { struct rpld_playlist * pl = NULL; const void * needle; const char * key = NULL, * binkey = NULL; int options = RPLD_PLE_FILTER_NORMKEY; size_t i; char * next = NULL; int bneedle_si; discid_t bneedle_discid; roar_uuid_t bneedle_uuid; int neg = 0; int with_queues = 1, with_histories = 1; remove_spaces(&args); if ( *args == '"' || *args == '\'' ) { needle = __parse_string(&args, NULL); } else if ( !strncasecmp(args, "discid:", 7) ) { args += 7; binkey = "discid"; if ( sscanf(args, "0x%x", &bneedle_si) != 1 ) { roar_err_set(ROAR_ERROR_ILLSEQ); return PROTO_SIMPLE_STATUS_ERROR; } bneedle_discid = bneedle_si; needle = &bneedle_discid; } else if ( !strncasecmp(args, "uuid:", 5) ) { args += 5; binkey = "uuid"; if ( roar_str2uuid(bneedle_uuid, args) != 0 ) return PROTO_SIMPLE_STATUS_ERROR; needle = &bneedle_uuid; } else if ( !strncasecmp(args, "genre:", 6) ) { args += 6; binkey = "genre"; bneedle_si = roar_meta_intgenre(args); needle = &bneedle_si; } else if ( !strncasecmp(args, "tracknum:", 9) ) { args += 9; binkey = "tracknum"; bneedle_si = atoi(args); needle = &bneedle_si; } else if ( !strncasecmp(args, "tracknumber:", 12) ) { args += 12; binkey = "tracknumber"; bneedle_si = atoi(args); needle = &bneedle_si; } else { roar_err_set(ROAR_ERROR_PROTO); return PROTO_SIMPLE_STATUS_ERROR; } if ( binkey != NULL ) { args = strstr(args, " "); if ( args == NULL ) args = ""; } remove_spaces(&args); if ( !strncasecmp(args, "case", 4) ) { args += 4; options |= RPLD_PLE_FILTER_CASE; remove_spaces(&args); if ( !strncasecmp(args, "sensitive", 9) ) { args += 9; remove_spaces(&args); } } if ( !strncasecmp(args, "not ", 4) ) { neg ^= 1; args += 4; remove_spaces(&args); } if ( !strncasecmp(args, "in", 2) ) { args += 2; } else if ( !strncasecmp(args, "as", 2) || !strncasecmp(args, "is", 2) ) { args += 2; options |= RPLD_PLE_FILTER_ANCHORB|RPLD_PLE_FILTER_ANCHORE; } else if ( !strncasecmp(args, "at begin of", 11) ) { args += 11; options |= RPLD_PLE_FILTER_ANCHORB; } else if ( !strncasecmp(args, "at end of", 9) ) { args += 9; options |= RPLD_PLE_FILTER_ANCHORE; } remove_spaces(&args); if ( !strncasecmp(args, "not ", 4) ) { neg ^= 1; args += 4; remove_spaces(&args); } remove_spaces(&args); next = strstr(args, " "); if ( next != NULL ) { *next = 0; next++; remove_spaces(&next); } if ( !strcasecmp(args, "all") || !strcasecmp(args, "any") ) { key = NULL; options |= RPLD_PLE_FILTER_EXTKEY; } else if ( !strncasecmp(args, "tag:", 4) ) { args += 4; key = __parse_string(&args, NULL); options |= RPLD_PLE_FILTER_EXTKEY; } else if ( !!strcasecmp(args, "from") ){ if ( *args ) { key = args; } else { key = NULL; } } if ( binkey != NULL ) { if ( key == NULL ) { key = binkey; } else if ( !!strcasecmp(key, binkey) ) { roar_err_set(ROAR_ERROR_USER); return PROTO_SIMPLE_STATUS_ERROR; } options |= RPLD_PLE_FILTER_BNEEDLE; } if ( next == NULL ) { pl = rpld_pl_get_by_id(client_get_playlist(client)); if ( pl == NULL ) { roar_err_set(ROAR_ERROR_NOENT); return PROTO_SIMPLE_STATUS_OK; } } else { if ( !strncasecmp(next, "from", 4) ) next += 4; remove_spaces(&next); if ( !strcasecmp(next, "any") || !strncasecmp(next, "any ", 4) ) { pl = NULL; next += 3; remove_spaces(&next); while ( !strncasecmp(next, "but ", 4) ) { next += 4; remove_spaces(&next); if ( !strncasecmp(next, "queues", 6) ) { with_queues = 0; next += 6; } else if ( !strncasecmp(next, "histories", 9) ) { with_histories = 0; next += 9; } remove_spaces(&next); } } else { pl = proto_simple_parse_pli(next, NULL); if ( pl == NULL ) { roar_err_set(ROAR_ERROR_NOENT); return PROTO_SIMPLE_STATUS_OK; } } } if ( pl != NULL ) { __searchple_handle_playlist(client, pl, needle, key, options, neg); rpld_pl_unref(pl); } else { for (i = 0; i < MAX_PLAYLISTS; i++) { pl = rpld_pl_get_by_id(i); if ( pl != NULL ) { if ( (pl->queue == NULL || with_queues) && (pl->histsize == -1 || with_histories) ) __searchple_handle_playlist(client, pl, needle, key, options, neg); rpld_pl_unref(pl); } } } return PROTO_SIMPLE_STATUS_OK; } //ll rpld-0.1.9/proto_simple.h0000644000175000017500000000617112266574307013512 0ustar phiphi//proto_simple.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_PROTO_SIMPLE_H_ #define _RPLD_PROTO_SIMPLE_H_ #define PROTO_SIMPLE_STATUS_UNKNOWN -1 /* unknown error */ #define PROTO_SIMPLE_STATUS_OK 0 /* OK */ #define PROTO_SIMPLE_STATUS_ERROR 1 /* Error processing request */ #define PROTO_SIMPLE_STATUS_INPROC 2 /* Request is being processed in background */ #define PROTO_SIMPLE_STATUS_YES 3 /* Yes */ #define PROTO_SIMPLE_STATUS_NO 4 /* No */ #define PROTO_SIMPLE_STATUS_PROERR 5 /* protocol error */ #define PROTO_SIMPLE_STATUS_GOODBYE 6 /* on quit */ #define PROTO_SIMPLE_STATUS_NOTPERM 7 /* not permitted */ #define PROTO_SIMPLE_STATUS_NFPROERR 8 /* non fatal protocol error (syntax error?) */ int proto_simple_client_handle(int id, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen, struct roar_dl_librarypara * pluginpara); int proto_simple_parse(int client, char * line, size_t len); int proto_simple_print_plent(int client, struct rpld_playlist_entry * plent); struct rpld_playlist * proto_simple_parse_pli(char * txt, char ** next); int proto_simple_print_playlist (int client, struct rpld_playlist * pl); int proto_simple_parse_ple_bopts_noeval(int client, char * txt, int need_prev, int * try_any, struct rpld_playlist ** pl, struct rpld_playlist_search * pls); struct rpld_playlist_entry * proto_simple_parse_ple_bopts_eval(int try_any, struct rpld_playlist * pl, struct rpld_playlist_search * pls); struct rpld_playlist_entry * proto_simple_parse_ple_bopts(int client, char * txt, int need_prev); int proto_simple_import_export (int client, char * args, int is_export); int proto_simple_showvolume (int client); int proto_simple_showplaying (int client); int proto_simple_setpointer(int client, char * args); int proto_simple_unsetpointer(int client, char * args); int proto_simple_showpointer(int client, char * name, int no_rename); int proto_simple_showpointer_all(int client); int proto_simple_listclients (int client); int proto_simple_identify(int client, char * txt); #endif //ll rpld-0.1.9/proto_simple_vio.c0000644000175000017500000001341312266574307014357 0ustar phiphi//proto_simple_vio.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" int rpld_proto_simple_vio_open (struct roar_vio_calls * vio, struct roar_vio_calls * dst) { struct rpld_proto_simple_inst * self; ROAR_DBG("rpld_proto_simple_vio_open(vio=%p, dst=%p) = ?", vio, dst); if ( vio == NULL || dst == NULL ) return -1; self = roar_mm_malloc(sizeof(struct rpld_proto_simple_inst)); if ( self == NULL ) return -1; memset(self, 0, sizeof(struct rpld_proto_simple_inst)); memset(vio, 0, sizeof(struct roar_vio_calls)); self->vio = dst; self->input_dots = -1; self->output_dots = -1; self->eof = 0; vio->refc = 1; vio->flags = ROAR_VIO_FLAGS_NONE; vio->inst = self; vio->close = rpld_proto_simple_vio_close; vio->read = rpld_proto_simple_vio_read; vio->write = rpld_proto_simple_vio_write; vio->sync = rpld_proto_simple_vio_sync; // vio->ctl = rpld_proto_simple_vio_ctl; ROAR_DBG("rpld_proto_simple_vio_open(vio=%p, dst=%p) = 0", vio, dst); return 0; } int rpld_proto_simple_vio_close (struct roar_vio_calls * vio) { struct rpld_proto_simple_inst * self = vio->inst; ROAR_DBG("rpld_proto_simple_vio_close(vio=%p) = ?", vio); if ( self->iobuffer != NULL ) roar_buffer_free(self->iobuffer); roar_mm_free(self); ROAR_DBG("rpld_proto_simple_vio_close(vio=%p) = 0", vio); return 0; } ssize_t rpld_proto_simple_vio_read (struct roar_vio_calls * vio, void *buf, size_t count) { struct rpld_proto_simple_inst * self = vio->inst; size_t buflen; size_t done = 0; ssize_t ret; void * bufdata; ROAR_DBG("rpld_proto_simple_vio_read(vio=%p, buf=%p, count=%lu) = ?", vio, buf, (unsigned long)count); if ( count == 0 ) return 0; ROAR_DBG("rpld_proto_simple_vio_read(vio=%p, buf=%p, count=%lu) = ?", vio, buf, (unsigned long)count); if ( self->iobuffer == NULL ) { if ( roar_buffer_new(&(self->iobuffer), RPLD_PROTO_SIMPLE_VIO_BUFSIZE) == -1 ) return -1; if ( roar_buffer_set_len(self->iobuffer, 0) == -1 ) { roar_buffer_free(self->iobuffer); self->iobuffer = NULL; return -1; } } if ( roar_buffer_get_len(self->iobuffer, &buflen) == -1 ) return -1; // optimize a bit: if ( buflen >= count ) { if ( roar_buffer_get_data(self->iobuffer, &bufdata) == -1 ) return -1; memcpy(buf, bufdata, count); _LIBROAR_IGNORE_RET(roar_buffer_set_offset(self->iobuffer, count)); ROAR_DBG("rpld_proto_simple_vio_read(vio=%p, buf=%p, count=%lu) = %lu", vio, buf, (unsigned long)count, (unsigned long) count); return count; } ROAR_DBG("rpld_proto_simple_vio_read(*): entering main loop..."); while ( done < count ) { ROAR_DBG("rpld_proto_simple_vio_read(*): we still need %lu bytes", (unsigned long) (count - done)); if ( roar_buffer_get_len(self->iobuffer, &buflen) == -1 ) return -1; if ( buflen ) { ROAR_DBG("rpld_proto_simple_vio_read(*): we got %lu bytes from buffer", (unsigned long) buflen); if ( roar_buffer_get_data(self->iobuffer, &bufdata) == -1 ) break; if ( buflen > (count - done) ) buflen = count - done; memcpy(buf, bufdata, buflen); _LIBROAR_IGNORE_RET(roar_buffer_set_offset(self->iobuffer, buflen)); buf += buflen; done += buflen; } if ( done == count ) break; if ( self->eof ) break; ROAR_DBG("rpld_proto_simple_vio_read(*): we need a new buffer"); if ( roar_buffer_set_len(self->iobuffer, RPLD_PROTO_SIMPLE_VIO_BUFSIZE) == -1 ) break; if ( roar_buffer_get_data(self->iobuffer, &bufdata) == -1 ) break; ret = roar_vio_read(self->vio, bufdata, RPLD_PROTO_SIMPLE_VIO_BUFSIZE); ROAR_DBG("rpld_proto_simple_vio_read(*): got %li bytes from network", (long) ret); if ( ret == -1 || ret == 0 ) break; if ( self->input_dots == 0 ) { if ( ret >= 2 ) { if ( ((char*)bufdata)[0] == '.' && ((char*)bufdata)[1] == '\n' ) { self->eof = 1; ret = 0; } else { self->input_dots = -1; } } else { self->input_dots = -1; } } if ( ret >= 3 ) { if ( !strncmp(bufdata+ret-3, "\n.\n", 3) ) { self->eof = 1; ret -= 3; } } if ( ret >= 1 ) { if ( *((char*)bufdata+ret-1) == '\n' ) self->input_dots = 0; } // very bad if this goes wrong: if ( roar_buffer_set_len(self->iobuffer, ret) == -1 ) return -1; } ROAR_DBG("rpld_proto_simple_vio_read(vio=%p, buf=%p, count=%lu) = %lu", vio, buf, (unsigned long)count, (unsigned long) done); return done; } ssize_t rpld_proto_simple_vio_write (struct roar_vio_calls * vio, void *buf, size_t count) { struct rpld_proto_simple_inst * self = vio->inst; return roar_vio_write(self->vio, buf, count); } //off_t rpld_proto_simple_vio_lseek (struct roar_vio_calls * vio, off_t offset, int whence); //int rpld_proto_simple_vio_nonblock(struct roar_vio_calls * vio, int state); int rpld_proto_simple_vio_sync (struct roar_vio_calls * vio) { (void)vio; return 0; } /* int rpld_proto_simple_vio_ctl (struct roar_vio_calls * vio, int cmd, void * data) { return -1; } */ //ll rpld-0.1.9/proto_simple_vio.h0000644000175000017500000000353212266574307014365 0ustar phiphi//proto_simple_vio.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_PROTO_SIMPLE_VIO_H_ #define _RPLD_PROTO_SIMPLE_VIO_H_ #define RPLD_PROTO_SIMPLE_VIO_BUFSIZE 1024 struct rpld_proto_simple_inst { struct roar_buffer * iobuffer; int input_dots; int output_dots; struct roar_vio_calls * vio; int eof; }; int rpld_proto_simple_vio_open (struct roar_vio_calls * vio, struct roar_vio_calls * dst); int rpld_proto_simple_vio_close (struct roar_vio_calls * vio); ssize_t rpld_proto_simple_vio_read (struct roar_vio_calls * vio, void *buf, size_t count); ssize_t rpld_proto_simple_vio_write (struct roar_vio_calls * vio, void *buf, size_t count); //off_t rpld_proto_simple_vio_lseek (struct roar_vio_calls * vio, off_t offset, int whence); //int rpld_proto_simple_vio_nonblock(struct roar_vio_calls * vio, int state); int rpld_proto_simple_vio_sync (struct roar_vio_calls * vio); //int rpld_proto_simple_vio_ctl (struct roar_vio_calls * vio, int cmd, void * data); #endif //ll rpld-0.1.9/rpld.10000644000175000017500000001240312023626321011624 0ustar phiphi.\" rpld.1: .TH "rpld" "1" "July 2010" "RoarAudio PlayList Daemon" "System User's Manual: rpld" .SH NAME rpld \- RoarAudio PlayList Daemon .SH SYNOPSIS rpld [OPTIONS] .SH DESCRIPTION The RoarAudio PlayList Daemon is a daemon which manages playlists and can play files or streams from those lists using a RoarAudio Sound Server. .SH "MISC OPTIONS" .TP \fB-h \-\-help\fR Show a small help. .TP \fB\-\-daemon\fR Daemonize (go into background). .TP \fB\-\-watchdog\fR Start watchdog. This will automatically terminate the daemon if it stops responding. .TP \fB\-\-server SERVER\fR Set default server to the RoarAudio server (e.g. roard) at SERVER. .TP \fB\-\-server\-queue SERV\fR The server to use for the Main Queue. Normally \-\-server should be used. .TP \fB\-\-server\-info SERV\fR Copies the serverinfo data from the given server. Use +default as server to use the data from the default server. The following data is copied from the server: location, description, contact, serial and uiurl. .TP \fB\-\-pidfile PIDFILE\fR Write a pidfile at PIDFILE. .TP \fB\-\-histsize NUM\fR Set size of the default history playlist to NUM entrys. This may be overwritten by restoring a store. The special value of "default" can be used to not alter the value. This may be used by init scripts to keep the default. .TP \fB\-\-location LOC\fR Sets lion-readable location of server. Examples: livingroom, room 32 .TP \fB\-\-description DESC\fR Sets lion-readable description of server. Examples: Stereo, UKW Transmitter .TP \fB\-\-contact CONTACT\fR Sets contact information for the server. .TP \fB\-\-serial SERIAL\fR Sets the serial number for this device or server. This is normally only used by embedded systems. .TP \fB\-\-uiurl UIURL\fR Sets the URL of the user interface for this device or server. This is normally only used by embedded systems. It is common to set this to a URL of type HTTP but all protocols are considered valid. This includes ssh, telnet and others. .TP \fB\-\-plugin\-load PLUGIN\fR Load plugin PLUGIN. .TP \fB\-\-plugin\-args ARGS\fR Set the plugin arguments for the plugin loaded next to ARGS. This must always be used before \-\-plugin\-load. .SH "SECURITY OPTIONS" .TP \fB\-\-user USER\fR Sets UID to USER. .TP \fB\-\-group GROUP\fR Sets GID to GROUP. .TP \fB\-\-allow\-running\-as\-root\fR Allow to run as root. This is a bad thing to do. Do never set this option. This will open very bad security holes! .SH "STORE OPTIONS" .TP \fB\-\-restore\fR Restore state from store. .TP \fB\-\-no\-restore\fR Do not restore state from store. .TP \fB\-\-auto\-restore\fR will restore old state if possible. This is a non-fatal version of \fB\-\-restore\fR. .TP \fB\-\-store\fR Store state on exit. .TP \fB\-\-no\-store\fR Do not store state on exit. .TP \fB\-\-store\-path DIR\fR Location where to store/restore from/to. .SH "PLAYBACK OPTIONS" .TP \fB\-\-play\fR Start in playling state. .TP \fB\-\-stopped\fR Start in stopped state (default). .TP \fB\-\-no\-default\-queue\fR Do not create a default queue. If set and no store is loaded or the loaded store does not contain any queues itself rpld will not connect to any RoarAudio server at startup at all. This is mainly for debuggung and testing. .TP \fB\-\-role ROLE\fR Set role for streams (default: music). The special value of "default" can be used to use the default. .TP \fB\-\-codec\-helper\-rate RATE\fR Set the sample rate the codec helper uses as it's output format. .TP \fB\-\-codec\-helper\-bits BITS\fR Set the number of bits the codec helper uses as it's output format. .TP \fB\-\-codec\-helper\-channels CHANNELS\fR Set the number of channels the codec helper uses as it's output format. .TP \fB\-\-codec\-helper\-codec CODEC\fR Set the codec the codec helper uses as it's output format. .SH "PLAYLIST OPTIONS" .TP \fB\-\-playlist\-import PLAYLIST TYPE FILE\fR Load playlist PLAYLIST of type TYPE from file FILE. The playlist is created if it does not exist. .TP \fB\-\-playlist\-export PLAYLIST TYPE FILE\fR save playlist PLAYLIST to file FILE in format TYPE. .TP \fB--load-playlist PLAYLIST TYPE FILE\fR The old name of \-\-playlist\-import. Should not be used. .SH "NETWORK OPTIONS" .TP \fB\-\-tcp\fR Listen on TCP Socket. .TP \fB\-\-unix\fR Listen on UNIX Socket. .TP \fB\-\-decnet\fR Listen on DECnet Socket. .TP \fB\-\-port PORT\fR Listen on port PORT. This is only useful for TCP listen sockets. .TP \fB\-\-bind ADDR\fR Listen on address ADDR. .TP \fB\-\-proto PROTO\fR Set protocol of listen socket. .TP \fB\-\-acclev LEV\fR Sets the accesslevel for this socket to LEV. .TP \fB\-\-new\-sock\fR Opens an additional listen socket. .TP \fB\-\-slp\fR Enable OpenSLP support. .TP \fB\-\-no\-listen\fR Do not add a default listening socket. This option is in general not very useful for any user. It is only useful for specal tests and with \fB\-\-client\-fh\fR. .TP \fB\-\-client\-fh FH\fR Added a client at the given FH to rpld. This option is in general not very useful for any user. .TP \fB\-\-close\-fh FH\fR This closes a given FH at startup time. This option is in general not very useful for any user. .SH "CODEC OPTIONS" .TP \fB\-\-bl\-codec CODEC\fR Use helper for codec CODEC. .SH "SEE ALSO" \fBroartips\fR(7), \fBlibroar\fR(7), \fBRoarAudio\fR(7). .SH "HISTORY" For history information see \fBRoarAudio\fR(7). .\" ll rpld-0.1.9/rpld.c0000644000175000017500000005504012266574307011731 0ustar phiphi//rpld.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) #include #include #endif #define DEFAULT_ROLE ROAR_ROLE_MUSIC enum iodir { IODIR_IMPORT, IODIR_EXPORT }; struct import_playlist { const char * playlist; const char * type; const char * filename; enum iodir iodir; }; #if defined(ROAR_HAVE_IO_POSIX) && defined(ROAR_HAVE_FS_POSIX) #define SUPPORT_PIDFILE static const char * pidfile = NULL; #endif static volatile int g_alive = 1; #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) struct group * g_grp = NULL; #endif #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) struct passwd * g_pwd = NULL; #endif void usage (const char * progname) { printf("Usage: %s [OPTIONS]\n", progname); printf("\nMisc Options:\n\n"); printf( " -h --help - Show this help\n" " --daemon - Daemonize\n" " --watchdog - Enable watchdog\n" " --server SERVER - Connect to the RoarAudio server at SERVER\n" " --server-queue SERV - The server to use for the Main Queue.\n" " Normally --server should be used.\n" " --server-info SERV - Copy server infos from this server.\n" #ifdef SUPPORT_PIDFILE " --pidfile PIDFILE - Write a pidfile at PIDFILE\n" #endif " --histsize NUM - Set history size to NUM\n" " --location LOC - Set lion readable location of server\n" " --description DESC - Set lion readable description of server\n" " --contact CONTACT - Set contact for this server\n" " --serial SERIAL - Set serial for this device or server\n" " (for embedded devices only)\n" " --uiurl UIURL - Set URL for userinterface of this device or server\n" " (for embedded devices only)\n" #ifdef SUPPORT_PLUGIN " --plugin-load PLUGIN - Load plugin PLUGIN\n" " --plugin-args ARGS - Arguments for the plugin\n" " (must be given before the --plugin-load)\n" #endif ); printf("\nSecurity Options:\n\n"); printf( " --user USER - Sets UID to USER\n" " --group GROUP - Sets GID to GROUP\n" " --allow-running-as-root\n" " - Allows rpld to run as root. NEVER USE THIS.\n" ); printf("\nStore Options:\n\n"); printf( " --restore - restore laste state\n" " --no-restore - do not restore laste state\n" " --auto-restore - restore last state if possible\n" " (a non-fatal version of --restore)\n" " --store - store state on exit\n" " --no-store - do not store state on exit\n" " --store-path DIR - location to store/restore from/to\n" ); printf("\nPlayback Options:\n\n"); printf( " --play - Start in playling state\n" " --stopped - Start in stopped state (default)\n" " --no-default-queue - Do not create a default queue\n" " --role ROLE - Set role for streams (default: music)\n" " --codec-helper-rate RATE\n" " --codec-helper-bits BITS\n" " --codec-helper-channels CHANS\n" " --codec-helper-codec CODEC\n" " - Set output format of codec-helper.\n" ); printf("\nPlayList Options:\n\n"); printf( " --playlist-import PLAYLIST TYPE FILE\n" " - Load playlist PLAYLIST of type TYPE from file FILE\n" " --playlist-export PLAYLIST TYPE FILE\n" " - export playlist PLAYLIST to file FILE in format TYPE\n" ); printf("\nNetwork Options:\n\n"); printf( " --tcp - Listen on TCP Socket\n" " --unix - Listen on UNIX Socket\n" " --decnet - Listen on DECnet Socket\n" " --port PORT - Listen on port PORT\n" " --bind ADDR - Listen on address ADDR\n" " --proto PROTO - Set protocol of listen socket\n" " --acclev LEV - Set the accesslevel for this socket to ACCLEV\n" " --new-sock - Opens an additional listen socket\n" #ifdef HAVE_LIB_SLP " --slp - Enable OpenSLP support\n" #endif " --no-listen - Do not listen for new clients\n" " (only useful with --client-fh)\n" " --client-fh FH - Comunicate with a client over this handle\n" " (only useful for relaing)\n" " --close-fh FH - Closes the given fh\n" ); printf("\nCodec Options:\n\n"); printf( " --bl-codec CODEC - Use helper for codec CODEC\n" ); } #ifdef ROAR_HAVE_H_SIGNAL void on_sig_int (int signum) { (void)signum; rpld_exit(); } #ifdef SIGUSR1 void on_sig_usr1 (int signum) { (void)signum; store(); } #endif #endif void rpld_exit(void) { g_alive = 0; } #ifdef SUPPORT_PIDFILE int pidfile_save(void) { struct roar_vio_calls pidfile_vio; if ( pidfile != NULL ) { if ( roar_vio_open_dstr_simple(&pidfile_vio, pidfile, O_WRONLY|O_CREAT) == -1 ) { ROAR_ERR("Can not write pidfile: %s", pidfile); return -1; } else { roar_vio_printf(&pidfile_vio, "%i\n", getpid()); roar_vio_close(&pidfile_vio); #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) if ( g_pwd != NULL || g_grp != NULL ) { if ( chown(pidfile, g_pwd != NULL ? g_pwd->pw_uid : (uid_t)-1, g_grp != NULL ? g_grp->gr_gid : (gid_t)-1) == -1 ) { ROAR_WARN("Can not change ownership of pidfile: %s: %s", pidfile, strerror(errno)); } } if ( chmod(pidfile, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1 ) { ROAR_WARN("Can not change permissions of pidfile: %s: %s", pidfile, strerror(errno)); } #endif return 0; } } return 0; } int pidfile_unlink(void) { if ( pidfile != NULL ) return unlink(pidfile); return 0; } #endif static void addstartup_to_queue(pli_t queue) { struct rpld_playlist_entry * plent; struct rpld_playlist_entry * copy; if ( (plent = rpld_pointer_search(POINTER_STARTUP, queue, -1)) == NULL ) return; if ( (copy = rpld_ple_copy(plent)) == NULL ) return; rpld_pl_add(g_playlists[queue], copy, -1); } static void addstartup(void) { size_t i; pli_t queue; for (i = 0; i < MAX_PLAYLISTS; i++) { if ( g_playlists[i] == NULL ) continue; if ( g_playlists[i]->queue == NULL ) continue; queue = g_playlists[i]->id; if ( rpld_pointer_is_set(POINTER_STARTUP, queue, -1) ) { addstartup_to_queue(queue); } } } static int imexportplaylist(const struct import_playlist * playlist) { struct roar_vio_defaults def; struct fformat_handle * handle; struct roar_vio_calls vio; struct rpld_playlist * pl = NULL; int format; int ret; if ( playlist->playlist == NULL || playlist->playlist[0] == 0 || playlist->type == NULL || playlist->type[0] == 0 || playlist->filename == NULL || playlist->filename[0] == 0 ) { ROAR_ERR("imexportplaylist(playlist='%s', type='%s', file='%s'): Invalid argument", playlist->playlist, playlist->type, playlist->filename); return -1; } if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, playlist->iodir == IODIR_IMPORT ? O_RDONLY : O_WRONLY|O_CREAT|O_TRUNC, 0644) == -1 ) { ROAR_ERR("imexportplaylist(playlist='%s', type='%s', file='%s'): Can not create DSTR defaults", playlist->playlist, playlist->type, playlist->filename); return -1; } format = fformat_str2plf(playlist->type); if ( format == -1 ) { ROAR_ERR("imexportplaylist(playlist='%s', type='%s', file='%s'): Unknown playlist type", playlist->playlist, playlist->type, playlist->filename); return -1; } handle = fformat_handle_new(format); if ( handle == NULL ) { ROAR_ERR("imexportplaylist(playlist='%s', type='%s', file='%s'): Can not open file format handle for playlist type", playlist->playlist, playlist->type, playlist->filename); return -1; } if ( roar_vio_open_dstr(&vio, playlist->filename, &def, 1) == -1 ) { ROAR_ERR("imexportplaylist(playlist='%s', type='%s', file='%s'): Can not open file: %s", playlist->playlist, playlist->type, playlist->filename, roar_error2str(roar_error)); fformat_handle_close(handle); return -1; } pl = rpld_pl_get_by_name(playlist->playlist); if ( pl == NULL ) { pl = rpld_pl_new(); if ( pl != NULL ) { rpld_pl_set_name(pl, playlist->playlist); rpld_pl_register(pl); } } if ( pl == NULL ) { ROAR_ERR("imexportplaylist(playlist='%s', type='%s', file='%s'): Playlist not found and playlist creation failed", playlist->playlist, playlist->type, playlist->filename); roar_vio_close(&vio); fformat_handle_close(handle); return -1; } if ( playlist->iodir == IODIR_IMPORT ) { ret = fformat_playlist_import(handle, &vio, pl); } else { ret = fformat_playlist_export(handle, &vio, pl); } roar_vio_close(&vio); fformat_handle_close(handle); rpld_pl_unref(pl); if ( ret == -1 ) { ROAR_ERR("imexportplaylist(playlist='%s', type='%s', file='%s'): Can not import playlist", playlist->playlist, playlist->type, playlist->filename); } return ret; } int main (int argc, char * argv[]) { struct roar_server_info serverinfo; const char * info_server = NULL; struct roar_audio_info * codechelper_info = playback_get_codechelper_info(); struct roar_vio_calls * clientvio; struct rpld_playlist * queue, * history; int allow_root = 0; int do_restore = 0; int do_store = 0; int i; const char * k; const char * n_server = NULL; int n_listen = 1; int n_port = -1; int n_type = ROAR_SOCKET_TYPE_UNKNOWN; int n_proto = ROAR_PROTO_RPLD; enum rpld_client_acclev n_acclev = ACCLEV_ALL; int playing = 0; #ifdef HAVE_LIB_SLP int slp = 0; #endif int daemon = 0; int watchdog = 0; int is_playing = 1; const char * queue_server = NULL; int role = DEFAULT_ROLE; int create_default_queue = 1; #ifdef SUPPORT_PLUGIN const char * plugin_args = NULL; #endif struct import_playlist import_playlist[8]; int import_num = 0; ROAR_DBG("main(*) = ?"); memset(&serverinfo, 0, sizeof(serverinfo)); if ( roar_notify_core_new_global(-1) == -1 ) { ROAR_ERR("main(*): Can not create new global notify bus: %s", roar_error2str(roar_error)); return 1; } if ( roar_notify_core_register_proxy(NULL, roar_notify_proxy_std, NULL) == -1 ) { ROAR_ERR("main(*): Can not register global notify proxy: %s", roar_error2str(roar_error)); return 1; } if ( backend_init() == -1 ) { ROAR_ERR("main(*): Can not start backend module: %s", roar_error2str(roar_error)); return 1; } #ifdef SUPPORT_PLUGIN if ( rpld_plugin_init() == -1 ) { ROAR_ERR("main(*): Can not allocate plugin container: %s", roar_error2str(roar_error)); return 1; } #endif if ( (queue = rpld_pl_new()) == NULL ) return 1; ROAR_DBG("main(*) = ?"); if ( (history = rpld_pl_new()) == NULL ) return 1; memset(g_playlists, 0, sizeof(g_playlists)); rpld_pl_register_id(queue, 0); rpld_pl_register_id(history, 1); rpld_pl_set_name(queue, "Main Queue"); rpld_pl_set_name(history, "Main History"); rpld_pl_set_histsize(history, 42); ROAR_DBG("main(*) = ?"); if ( playback_preinit() == -1 ) return 1; ROAR_DBG("main(*) = ?"); if ( network_preinit() == -1 ) return 1; ROAR_DBG("main(*) = ?"); client_init(); for (i = 1; i < argc; i++) { k = argv[i]; if ( !strcmp(k, "-h") || !strcmp(k, "--help") ) { usage(argv[0]); return 0; } else if ( !strcmp(k, "--daemon") ) { daemon = 1; } else if ( !strcmp(k, "--watchdog") ) { watchdog = 1; } else if ( !strcmp(k, "--server") ) { roar_libroar_set_server(argv[++i]); } else if ( !strcmp(k, "--server-queue") ) { queue_server = argv[++i]; } else if ( !strcmp(k, "--server-info") ) { info_server = argv[++i]; } else if ( strcmp(k, "--pidfile") == 0 ) { #ifdef SUPPORT_PIDFILE pidfile = argv[++i]; #else ROAR_ERR("--pidfile not supported"); i++; #endif } else if ( strcmp(k, "--location") == 0 ) { serverinfo.location = argv[++i]; } else if ( strcmp(k, "--description") == 0 ) { serverinfo.description = argv[++i]; } else if ( strcmp(k, "--contact") == 0 ) { serverinfo.contact = argv[++i]; } else if ( strcmp(k, "--serial") == 0 ) { serverinfo.serial = argv[++i]; } else if ( strcmp(k, "--uiurl") == 0 ) { serverinfo.uiurl = argv[++i]; } else if ( strcmp(k, "--plugin-args") == 0 ) { #ifdef SUPPORT_PLUGIN plugin_args = argv[++i]; #else i++; #endif } else if ( strcmp(k, "--plugin-load") == 0 ) { #ifdef SUPPORT_PLUGIN rpld_plugin_load(argv[++i], plugin_args); plugin_args = NULL; #else ROAR_ERR("--plugin-load not supported"); i++; #endif } else if ( strcmp(k, "--no-listen") == 0 ) { n_listen = 0; } else if ( strcmp(k, "--client-fh") == 0 ) { if ( client_new(&clientvio) == -1 ) { ROAR_ERR("Can not add client from fh %i", atoi(argv[++i])); return 1; } if ( roar_vio_open_fh(clientvio, atoi(argv[++i])) == -1 ) { ROAR_ERR("Can not add client from fh %i", atoi(argv[i])); return 1; } } else if ( strcmp(k, "--close-fh") == 0 ) { #ifdef ROAR_HAVE_IO_POSIX close(atoi(argv[++i])); #else i++; ROAR_WARN("can not close file handle %s (closing not supported)", argv[i]); #endif } else if ( !strcmp(k, "--histsize") ) { i++; if ( !strcmp(argv[i], "default") ) { // noop. Used by rpld-storemgr to simplify the argument generator. } else { rpld_pl_set_histsize(history, atol(argv[i])); } } else if ( !strcmp(k, "--user") ) { #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) // early test for UID as we need this for the pidfile and the setuid() if ( (g_pwd = getpwnam(argv[++i])) == NULL ) { ROAR_ERR("Can not get UID for user %s: %s", argv[i], strerror(errno)); return 1; } #else ROAR_ERR("No support for setuid()"); return 1; #endif } else if ( !strcmp(k, "--group") ) { #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) if ( (g_grp = getgrnam(argv[++i])) == NULL ) { ROAR_ERR("Can not get GID for group %s: %s", argv[i], strerror(errno)); return 1; } if ( setgroups(0, (const gid_t *) NULL) == -1 ) { ROAR_ERR("Can not clear supplementary group IDs: %s", strerror(errno)); } if ( g_grp == NULL || setgid(g_grp->gr_gid) == -1 ) { ROAR_ERR("Can not set GroupID: %s", strerror(errno)); } #else ROAR_ERR("No support for setgid()"); return 1; #endif } else if ( !strcmp(k, "--allow-running-as-root") ) { allow_root = 1; } else if ( !strcmp(k, "--store-path") ) { do_restore = 1; if ( setstorepath(argv[++i]) == -1 ) { fprintf(stderr, "Error: can not set restore path\n"); return 1; } } else if ( !strcmp(k, "--restore") ) { do_restore = 1; } else if ( !strcmp(k, "--no-restore") ) { do_restore = 0; } else if ( !strcmp(k, "--auto-restore") ) { do_restore = 2; } else if ( !strcmp(k, "--store") ) { do_store = 1; } else if ( !strcmp(k, "--no-store") ) { do_store = 0; } else if ( !strcmp(k, "--play") ) { playing = 1; } else if ( !strcmp(k, "--stopped") ) { playing = 0; } else if ( !strcmp(k, "--no-default-queue") ) { create_default_queue = 0; } else if ( !strcmp(k, "--role") ) { i++; if ( !strcmp(argv[i], "default") ) { role = DEFAULT_ROLE; } else { if ( (role = roar_str2role(argv[i])) == -1 ) { fprintf(stderr, "Error: can not set role (unknown role name?) to: %s\n", argv[i]); return 1; } } } else if ( !strcmp(k, "--codec-helper-rate") ) { codechelper_info->rate = roar_str2rate(argv[++i]); } else if ( !strcmp(k, "--codec-helper-bits") ) { codechelper_info->bits = roar_str2bits(argv[++i]); } else if ( !strcmp(k, "--codec-helper-channels") ) { codechelper_info->channels = roar_str2channels(argv[++i]); } else if ( !strcmp(k, "--codec-helper-codec") ) { codechelper_info->codec = roar_str2codec(argv[++i]); // --load-playlist is old parameter name and should no longer be used. } else if ( !strcmp(k, "--load-playlist") || !strcmp(k, "--playlist-import") || !strcmp(k, "--playlist-export") ) { if ( !strcmp(k, "--load-playlist") ) { roar_debug_option_obsolete(argv[0], k, "--playlist-import", NULL); } if ( import_num == (sizeof(import_playlist)/sizeof(*import_playlist)) ) { ROAR_WARN("Can not import more playlists: maximum number of playlists to import reached."); i += 3; continue; } import_playlist[import_num].playlist = argv[i+1]; import_playlist[import_num].type = argv[i+2]; import_playlist[import_num].filename = argv[i+3]; import_playlist[import_num].iodir = !strcmp(k, "--playlist-export") ? IODIR_EXPORT : IODIR_IMPORT; import_num++; i += 3; } else if ( !strcmp(k, "--tcp") ) { n_type = ROAR_SOCKET_TYPE_TCP; } else if ( !strcmp(k, "--unix") ) { n_type = ROAR_SOCKET_TYPE_UNIX; } else if ( !strcmp(k, "--decnet") ) { n_type = ROAR_SOCKET_TYPE_DECNET; } else if ( !strcmp(k, "--bind") ) { n_server = argv[++i]; } else if ( !strcmp(k, "--port") ) { n_port = atoi(argv[++i]); } else if ( !strcmp(k, "--proto") ) { n_proto = client_str2proto(argv[++i]); } else if ( !strcmp(k, "--acclev") ) { n_acclev = client_str2acclev(argv[++i]); } else if ( !strcmp(k, "--new-sock") ) { if ( network_add_server(n_server, n_port, n_type, n_proto, n_acclev) == -1 ) return 1; } else if ( !strcmp(k, "--slp") ) { #ifdef HAVE_LIB_SLP slp = 1; #else fprintf(stderr, "Warning: No OpenSLP support compiled in.\n"); #endif } else if ( !strcmp(k, "--bl-codec") ) { backend_blacklist_codec_global(roar_str2codec(argv[++i])); } else { fprintf(stderr, "Error: Invalid option: %s\n", k); usage(argv[0]); return 1; } } #ifdef ROAR_HAVE_GETUID if ( getgid() == ROOT_UID ) { if ( !allow_root ) { fprintf(stderr, "Error: Running as superuser. THIS IS A VERY BAD THING TO DO.\n"); fprintf(stderr, "Error: Rejecting to run as superuser. Terminating.\n"); return 1; } } #else if ( !allow_root ) { fprintf(stderr, "Warning: Can not check if running as superuser\n"); } #endif // set up the main queue. if ( create_default_queue ) { playback_add_queue(queue, queue_server, -1 /* FIXME */, history); playback_set_role(rpld_pl_get_id(queue), role); } rpld_pl_unref(queue); rpld_pl_unref(history); // setting up server info: if ( info_server != NULL ) rpld_serverinfo_update(RPLD_SERVERINFO_SOURCE_SERVER, info_server); rpld_serverinfo_update(RPLD_SERVERINFO_SOURCE_OBJECT, &serverinfo); if ( playback_init() == -1 ) return 1; // init network if ( do_restore ) { if ( restore() == -1 ) { if ( do_restore == 2 ) { fprintf(stderr, "Warning: Restore failed.\n"); } else { fprintf(stderr, "Error: Restore failed.\n"); return 1; } } } for (i = 0; i < import_num; i++) { if ( imexportplaylist(&(import_playlist[i])) == -1 ) { ROAR_WARN("Failed to import/export playlist: %s: %s", import_playlist[i].filename, roar_error2str(roar_error)); } } // We need to fork before the init the playback backend // so the PID does not change after the init. // We will close the STD* handles later. if ( daemon ) { switch (roar_fork(NULL)) { case -1: ROAR_ERR("Fork failed: %s", roar_error2str(roar_error)); ROAR_U_EXIT(1); break; case 0: break; default: ROAR_U_EXIT(0); } #ifdef ROAR_HAVE_SETSID setsid(); #endif } yield_watchdog_active(watchdog); yield_watchdog_start(); ROAR_DBG("main(*) = ?"); if ( n_listen ) if ( network_add_server(n_server, n_port, n_type, n_proto, n_acclev) == -1 ) return 1; ROAR_DBG("main(*) = ?"); if ( network_init() == -1 ) return 1; ROAR_DBG("main(*) = ?"); #ifdef HAVE_LIB_SLP if ( slp ) { if ( n_type == ROAR_SOCKET_TYPE_UNIX ) { ROAR_WARN("SLP not supported on UNIX Sockets, ignoring --slp"); slp = 0; } else { if ( register_slp(0, n_server) == -1 ) { return 1; } } } #endif if ( pidfile != NULL ) { if ( pidfile_save() == -1 ) { ROAR_WARN("Can not save pidfile: %s", pidfile); } } ROAR_DBG("main(*) = ?"); #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) if ( g_pwd != NULL ) { if ( setuid(g_pwd->pw_uid) == -1 ) { ROAR_ERR("Can not set UserID: %s", strerror(errno)); return 1; } } #endif ROAR_DBG("main(*) = ?"); #ifdef ROAR_HAVE_H_SIGNAL #ifdef SIGINT signal(SIGINT, on_sig_int); #endif #ifdef SIGTERM signal(SIGTERM, on_sig_int); #endif #ifdef SIGPIPE signal(SIGPIPE, SIG_IGN); // ignore broken pipes #endif #ifdef SIGUSR1 signal(SIGUSR1, on_sig_usr1); #endif #endif addstartup(); // Now we should have everything up and running, we close the STD* handles. if ( daemon ) { roar_debug_set_stderr_mode(ROAR_DEBUG_MODE_SYSLOG); close(ROAR_STDIN ); close(ROAR_STDOUT); close(ROAR_STDERR); } ROAR_DBG("main(*) = ?"); #ifdef SUPPORT_PLUGIN rpld_plugin_appsched(ROAR_DL_APPSCHED_INIT); #endif if ( playing ) playback_play_all(); while (g_alive) { // main loop, check clients, play files yield_watchdog_trigger(); network_check(is_playing ? RPLD_YIELD_BLOCK : RPLD_YIELD_LONGBLOCK); playback_check(RPLD_YIELD_BLOCK); is_playing = playback_is_playing_any(); #ifdef SUPPORT_PLUGIN rpld_plugin_appsched(ROAR_DL_APPSCHED_UPDATE); #endif } ROAR_DBG("main(*) = ?"); playback_stop_all(0, 1); #ifdef HAVE_LIB_SLP if ( slp ) { if ( register_slp(1, n_server) == -1 ) { ROAR_WARN("Can not unregister SLP service"); } } #endif if ( do_store ) { store(); } #ifdef SUPPORT_PLUGIN rpld_plugin_free(); #endif // deinit network network_uninit(); playback_uninit(); backend_free(); if ( pidfile != NULL ) pidfile_unlink(); return 0; } //ll rpld-0.1.9/rpld.h0000644000175000017500000000366512266574307011744 0ustar phiphi//rpld.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_RPLD_H_ #define _RPLD_RPLD_H_ #if defined(HAVE_LIB_XML2) && defined(ROAR_TARGET_WIN32) // to work around the broken loader for DLLs disable use of libxml here. #undef HAVE_LIB_XML2 #endif #include #include #include "config.h" #include "rpldnotify.h" #include "playlist.h" #include "fformat.h" #include "backend.h" #include "playback.h" #include "proto_simple_vio.h" #include "proto_simple.h" #include "proto_mpd.h" #include "client.h" #include "network.h" #include "store.h" #include "autoqueue.h" #include "yield.h" #include "rpldslp.h" #include "pointer.h" #include "plugin.h" #include "serverinfo.h" #define APPLICATION_NAME "RoarAudio PlayList Daemon" #if defined(ROAR_HAVE_SETGID) && defined(ROAR_HAVE_IO_POSIX) extern struct group * g_grp; #endif #if defined(ROAR_HAVE_SETUID) && defined(ROAR_HAVE_IO_POSIX) extern struct passwd * g_pwd; #endif #ifdef ROAR_TARGET_WIN32 #define __longlong long #define __ll "l" #else #define __longlong long long #define __ll "ll" #endif void rpld_exit(void); #endif //ll rpld-0.1.9/rpldnotify.h0000644000175000017500000000441412266574310013160 0ustar phiphi//rpldnotify.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLDNOTIFY_H_ #define _RPLDNOTIFY_H_ #define RPLD_NOTIFY_BASE_QUEUE ((uint32_t)0x01000000) #define RPLD_NOTIFY_BASE_PLAYBACK ((uint32_t)0x02000000) #define RPLD_NOTIFY_QUEUE(x) ROAR_NOTIFY_USER2EVENT((x) | RPLD_NOTIFY_BASE_QUEUE) #define RPLD_NOTIFY_PLAYBACK(x) ROAR_NOTIFY_USER2EVENT((x) | RPLD_NOTIFY_BASE_PLAYBACK) /* target=$QUEUE_ID */ #define RPLD_NOTIFY_PLAYBACK_STOP RPLD_NOTIFY_PLAYBACK(0) /* arg0=$OFFSET, arg1=$KICK */ #define RPLD_NOTIFY_PLAYBACK_PLAY RPLD_NOTIFY_PLAYBACK(1) /* (none) */ #define RPLD_NOTIFY_PLAYBACK_NEXT RPLD_NOTIFY_PLAYBACK(2) /* (none) */ #define RPLD_NOTIFY_PLAYBACK_PREV RPLD_NOTIFY_PLAYBACK(3) /* (none) */ #define RPLD_NOTIFY_PLAYBACK_PAUSE RPLD_NOTIFY_PLAYBACK(4) /* arg0=$HOW */ #define RPLD_NOTIFY_PLAYBACK_VOLUME RPLD_NOTIFY_PLAYBACK(5) /* arg0=(unsigned int)$VOL */ #define RPLD_NOTIFY_PLAYBACK_ROLE RPLD_NOTIFY_PLAYBACK(6) /* arg0=$ROLE */ #ifdef _XXX_ int emitter; int target; int target_type; int arg0; int arg1; void * arg2; int playback_add_queue(struct rpld_playlist * pl, const char * backend, int mixer, struct rpld_playlist * history); int playback_del_queue(struct rpld_playlist * pl); int playback_set_pointer(pli_t queue, int pointer, struct rpld_playlist_pointer * plp); // start or stop all queues. void playback_play_all(void); void playback_stop_all(size_t offset, int kick); #endif #endif //ll rpld-0.1.9/rpldplugin.h0000644000175000017500000004620312266574310013150 0ustar phiphi//rpldplugin.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLDPLUGIN_H_ #define _RPLDPLUGIN_H_ #include #define RPLDPH_APPNAME "rpld " ROAR_VSTR_ROARAUDIO #define RPLDPH_ABIVERSION "0.1.5" #define RPLDPH_CHECK_VERSIONS() ROAR_DL_PLUGIN_CHECK_VERSIONS(RPLDPH_APPNAME, RPLDPH_ABIVERSION) // forward declerations: struct rpld_playlist_entry; struct rpld_backend; struct rpld_playlist_pointer; // normal declerations: typedef unsigned int rpld_pli_t; #define RPLD_PLI_INVALID ((rpld_pli_t)-1) struct rpld_fformat_handle; typedef struct rpld_fformat_handle * rpld_fformat_t; typedef int64_t rpld_maxint_t; typedef enum { RPLDPH_CONFIG_KEY_MAX_CLIENTS = 16, RPLDPH_CONFIG_KEY_MAX_PLAYLISTS, RPLDPH_CONFIG_KEY_MAX_LISTENS, RPLDPH_CONFIG_KEY_MAX_CODECBL, RPLDPH_CONFIG_KEY_MAX_POINTER, RPLDPH_CONFIG_KEY_DEFAULT_BACKEND, RPLDPH_CONFIG_KEY_DEFAULT_PLF, RPLDPH_CONFIG_KEY_APPNAME, RPLDPH_CONFIG_KEY_APPVENDOR, } rpldph_config_key_t; typedef enum { RPLDPH_FALSE = 0, RPLDPH_TRUE = 1, RPLDPH_TOGGLE = 2, RPLDPH_ASK = -2, RPLDPH_ERROR = -1 } rpldph_bool_t; // binargv tree: struct __rpldph_functions_config { ssize_t (*_get_limit)(rpldph_config_key_t key); const char * (*_get_value)(rpldph_config_key_t key); }; // This structure allows access to libroar's (common) memory functions without linking it. struct __rpldph_functions_memory { void * (*_calloc)(size_t nmemb, size_t size); void * (*_malloc)(size_t size); void (*_free)(void *ptr); void * (*_realloc)(void *ptr, size_t size); char * (*_strdup)(const char *s); }; // This structure allows access to libroar's (common) error functions without linking it. struct __rpldph_functions_error { int (*_get)(void); void (*_set)(const int error); const char * (*_error2str)(const int error); }; struct __rpldph_functions_control { void (*_exit)(void); const struct roar_server_info * (*_serverinfo)(void); }; struct __rpldph_functions_ple { struct rpld_playlist_entry * (*_new) (void); void (*_free) (struct rpld_playlist_entry * plent); struct rpld_playlist_entry * (*_copy) (struct rpld_playlist_entry * plent); int (*_set_res) (struct rpld_playlist_entry * plent, const char * file, int codec, time_t length); int (*_set_meta) (struct rpld_playlist_entry * plent, struct roar_keyval * kv, ssize_t len); const char * (*_get_meta) (struct rpld_playlist_entry * plent, const char * key); int (*_set_meta_int)(struct rpld_playlist_entry * plent, const char * key, rpld_maxint_t val); rpld_maxint_t (*_get_meta_int)(struct rpld_playlist_entry * plent, const char * key); int (*_get_codec) (struct rpld_playlist_entry * plent); time_t (*_get_length) (struct rpld_playlist_entry * plent); int (*_set_uuid) (struct rpld_playlist_entry * plent, const char * uuid); const char * (*_get_uuid) (struct rpld_playlist_entry * plent, char * buf); int (*_set_likeness)(struct rpld_playlist_entry * plent, float likeness); int (*_inc_likeness)(struct rpld_playlist_entry * plent, float likeness); float (*_get_likeness)(struct rpld_playlist_entry * plent); struct rpld_playlist_entry * (*_get_next) (struct rpld_playlist_entry * plent); int (*_set_offset) (struct rpld_playlist_entry * plent, int_least32_t start, int_least32_t end); int (*_get_offset) (struct rpld_playlist_entry * plent, int_least32_t * start, int_least32_t * end); }; struct __rpldph_functions_playlist { rpld_pli_t (*_new) (const char * name, rpld_pli_t parent); void (*_free) (rpld_pli_t pl); int (*_flush)(rpld_pli_t pl); int (*_merge)(rpld_pli_t pl, rpld_pli_t tm); int (*_set_name)(rpld_pli_t pl, const char * name); const char * (*_get_name)(rpld_pli_t pl); int (*_set_parent)(rpld_pli_t pl, rpld_pli_t parent); rpld_pli_t (*_get_parent)(rpld_pli_t pl); rpld_pli_t (*_get_by_name)(const char * name); ssize_t (*_get_num)(rpld_pli_t pl); int (*_push) (rpld_pli_t pl, struct rpld_playlist_entry * plent); int (*_unshift) (rpld_pli_t pl, struct rpld_playlist_entry * plent); struct rpld_playlist_entry * (*_pop) (rpld_pli_t pl); struct rpld_playlist_entry * (*_shift) (rpld_pli_t pl); int (*_add) (rpld_pli_t pl, struct rpld_playlist_entry * plent, ssize_t pos); struct rpld_playlist_entry * (*_get_first)(rpld_pli_t pl); }; struct __rpldph_functions_history { int (*_set_size)(rpld_pli_t history, ssize_t size); ssize_t (*_get_size)(rpld_pli_t history); }; struct __rpldph_functions_plp { struct rpld_playlist_pointer * (*_new) (rpld_pli_t playlist, const char * type, const void * argp); int (*_ref) (struct rpld_playlist_pointer * plp); int (*_unref) (struct rpld_playlist_pointer * plp); int (*_copy) (struct rpld_playlist_pointer ** dst, struct rpld_playlist_pointer * src); struct rpld_playlist_entry * (*_search) (struct rpld_playlist_pointer * plp); }; struct __rpldph_functions_playback { int (*_play)(rpld_pli_t queue); int (*_next)(rpld_pli_t queue); int (*_prev)(rpld_pli_t queue); int (*_stop)(rpld_pli_t queue); int (*_pause)(rpld_pli_t queue, rpldph_bool_t how); rpldph_bool_t (*_is_playing)(rpld_pli_t queue); rpldph_bool_t (*_is_paused) (rpld_pli_t queue); rpldph_bool_t (*_is_queue) (rpld_pli_t queue); float (*_get_volume)(rpld_pli_t queue); int (*_set_volume)(rpld_pli_t queue, float volume); void (*_set_role)(rpld_pli_t queue, const int role); struct rpld_playlist_entry * (*_get_ple)(rpld_pli_t queue); size_t (*_get_mduc)(rpld_pli_t queue); const struct roar_stream * (*_get_stream)(rpld_pli_t queue); }; struct __rpldph_functions_store { int (*_save)(void); int (*_load)(void); }; struct __rpldph_functions_backend { struct rpld_backend * (*_get_connection)(const char * name); int (*_ref)(struct rpld_backend * backend); int (*_unref)(struct rpld_backend * backend); const char * (*_get_name)(struct rpld_backend * backend); struct roar_connection * (*_get_con)(struct rpld_backend * backend); // need to roar_connectionunref() after use. int (*_blacklist_codec)(struct rpld_backend * backend, int codec); int (*_blacklist_codec_global)(int codec); int (*_blacklist_check_codec)(struct rpld_backend * backend, int codec); }; struct __rpldph_functions_client { // enum rpld_client_acclev client_get_acclev(int id); // int client_set_acclev(int id, enum rpld_client_acclev acclev, int setter); // int client_inc_acclev(int id, int inc, int setter); int (*_set_name)(int id, const char * name); const char * (*_get_name)(int id); int (*_set_playlist)(int id, rpld_pli_t pl); rpld_pli_t (*_get_playlist)(int id); int (*_set_queue)(int id, rpld_pli_t pl); rpld_pli_t (*_get_queue)(int id); int (*_str2proto)(const char * str); const char * (*_proto2str)(const int proto); // enum rpld_client_acclev (*_str2acclev)(const char * str); }; struct __rpldph_functions_fformat { int (*_str2plf)(const char * str); const char * (*_plf2str)(int plf); rpld_fformat_t (*_handle_new)(int format); void (*_handle_close)(rpld_fformat_t handle); int (*_playlist_export)(rpld_fformat_t handle, struct roar_vio_calls * vio, rpld_pli_t pl); int (*_playlist_import)(rpld_fformat_t handle, struct roar_vio_calls * vio, rpld_pli_t pl); }; struct __rpldph_functions_pointer { char * (*_get_name)(const int pointer, const rpld_pli_t queue, const int client); int (*_parse_name)(int * pointer, rpld_pli_t * queue, int * client, int client_hint, const char * name); int (*_is_set)(const int pointer, const rpld_pli_t queue, const int client); struct rpld_playlist_pointer * (*_get)(const int pointer, const rpld_pli_t queue, const int client); struct rpld_playlist_pointer * (*_get_by_name)(const char * name, int client_hint); int (*_set)(const int pointer, const rpld_pli_t queue, const int client, struct rpld_playlist_pointer * plp); int (*_set_by_name)(const char * name, const int client_hint, struct rpld_playlist_pointer * plp); struct rpld_playlist_entry * (*_search)(const int pointer, const rpld_pli_t queue, const int client); }; struct __rpldph_functions_yield { void (*_ay_trigger)(void); void (*_ay_pause)(void); void (*_ay_unpause)(void); void (*_watchdog_trigger)(void); }; struct __rpldph_functions { struct __rpldph_functions_config config; // libroar's (common) memory functions (libroar/memmgr.h) struct __rpldph_functions_memory memory; // libroar's (common) error functions (libroar/error.h) struct __rpldph_functions_error error; // rpld.h struct __rpldph_functions_control control; // playlist.h struct __rpldph_functions_ple ple; struct __rpldph_functions_playlist playlist; struct __rpldph_functions_history history; struct __rpldph_functions_plp plp; // playback.h struct __rpldph_functions_playback playback; // store.h struct __rpldph_functions_store store; // backend.h struct __rpldph_functions_backend backend; // client.h struct __rpldph_functions_client client; // fformat.h struct __rpldph_functions_fformat fformat; // pointer.h struct __rpldph_functions_pointer pointer; // yield.h struct __rpldph_functions_yield yield; }; struct __rpldph_binargv { const struct __rpldph_functions functions; }; #define __rpldph_export_func(prefix,func) (((struct __rpldph_binargv*)para->binargv)->functions.prefix.func) #define __rpldph_export0(prefix,func) __rpldph_export_func(prefix,func)() #define __rpldph_export1(prefix,func,arg) __rpldph_export_func(prefix,func)(arg) #define __rpldph_exportn(prefix,func,arg,...) __rpldph_export_func(prefix,func)(arg, __VA_ARGS__) #define rpldph_config_get_limit(arg) __rpldph_export1(config,_get_limit,arg) #define rpldph_config_get_value(arg) __rpldph_export1(config,_get_value,arg) #define rpldph_memory_calloc(arg,...) __rpldph_exportn(memory,_calloc,arg,__VA_ARGS__) #define rpldph_memory_malloc(arg) __rpldph_export1(memory,_malloc,arg) #define rpldph_memory_free(arg) __rpldph_export1(memory,_free,arg) #define rpldph_memory_realloc(arg,...) __rpldph_exportn(memory,_realloc,arg,__VA_ARGS__) #define rpldph_memory_strdup(arg) __rpldph_export1(memory,_strdup,arg) #define rpldph_error_get() __rpldph_export0(error,_get) #define rpldph_error_set(arg) __rpldph_export1(error,_set,arg) #define rpldph_error_error2str(arg) __rpldph_export1(error,_error2str,arg) #define rpldph_control_exit() __rpldph_export0(control,_exit) #define rpldph_control_serverinfo() __rpldph_export0(control,_serverinfo) #define rpldph_ple_new() __rpldph_export0(ple,_new) #define rpldph_ple_free(arg) __rpldph_export1(ple,_free,arg) #define rpldph_ple_copy(arg) __rpldph_export1(ple,_copy,arg) #define rpldph_ple_set_res(arg,...) __rpldph_exportn(ple,_set_res,arg,__VA_ARGS__) #define rpldph_ple_set_meta(arg,...) __rpldph_exportn(ple,_set_meta,arg,__VA_ARGS__) #define rpldph_ple_get_meta(arg,...) __rpldph_exportn(ple,_get_meta,arg,__VA_ARGS__) #define rpldph_ple_set_meta_int(arg,...) __rpldph_exportn(ple,_set_meta_int,arg,__VA_ARGS__) #define rpldph_ple_get_meta_int(arg,...) __rpldph_exportn(ple,_get_meta_int,arg,__VA_ARGS__) #define rpldph_ple_get_codec(arg) __rpldph_export1(ple,_get_codec,arg) #define rpldph_ple_get_time(arg) __rpldph_export1(ple,_get_time,arg) #define rpldph_ple_set_uuid(arg,...) __rpldph_exportn(ple,_set_uuid,arg,__VA_ARGS__) #define rpldph_ple_get_uuid(arg,...) __rpldph_exportn(ple,_get_uuid,arg,__VA_ARGS__) #define rpldph_ple_set_likeness(arg,...) __rpldph_exportn(ple,_set_likeness,arg,__VA_ARGS__) #define rpldph_ple_inc_likeness(arg,...) __rpldph_exportn(ple,_inc_likeness,arg,__VA_ARGS__) #define rpldph_ple_get_likeness(arg) __rpldph_export1(ple,_get_likeness,arg) #define rpldph_ple_get_next(arg) __rpldph_export1(ple,_get_next,arg) #define rpldph_ple_set_offset(arg,...) __rpldph_exportn(ple,_set_offset,arg,__VA_ARGS__) #define rpldph_ple_get_offset(arg,...) __rpldph_exportn(ple,_get_offset,arg,__VA_ARGS__) #define rpldph_playlist_new(arg,...) __rpldph_exportn(playlist,_new,arg,__VA_ARGS__) #define rpldph_playlist_free(arg) __rpldph_export1(playlist,_free,arg) #define rpldph_playlist_flush(arg) __rpldph_export1(playlist,_flush,arg) #define rpldph_playlist_merge(arg,...) __rpldph_exportn(playlist,_merge,arg,__VA_ARGS__) #define rpldph_playlist_set_name(arg,...) __rpldph_exportn(playlist,_set_name,arg,__VA_ARGS__) #define rpldph_playlist_get_name(arg) __rpldph_export1(playlist,_get_name,arg) #define rpldph_playlist_set_parent(arg,...) __rpldph_exportn(playlist,_set_parent,arg,__VA_ARGS__) #define rpldph_playlist_get_parent(arg) __rpldph_export1(playlist,_parent,arg) #define rpldph_playlist_get_by_name(arg) __rpldph_export1(playlist,_get_by_name,arg) #define rpldph_playlist_get_num(arg) __rpldph_export1(playlist,_get_num,arg) #define rpldph_playlist_push(arg,...) __rpldph_exportn(playlist,_push,arg,__VA_ARGS__) #define rpldph_playlist_unshift(arg,...) __rpldph_exportn(playlist,_unshift,arg,__VA_ARGS__) #define rpldph_playlist_pop(arg,...) __rpldph_exportn(playlist,_pop,arg,__VA_ARGS__) #define rpldph_playlist_shift(arg,...) __rpldph_exportn(playlist,_shift,arg,__VA_ARGS__) #define rpldph_playlist_add(arg,...) __rpldph_exportn(playlist,_add,arg,__VA_ARGS__) #define rpldph_playlist_get_first(arg) __rpldph_export1(playlist,_get_first,arg) #define rpldph_history_set_size(arg,...) __rpldph_exportn(history,_set_size,arg,__VA_ARGS__) #define rpldph_history_get_size(arg) __rpldph_export1(history,_get_size,arg) #define rpldph_plp_new(arg,...) __rpldph_exportn(plp,_new,arg,__VA_ARGS__) #define rpldph_plp_ref(arg) __rpldph_export1(plp,_ref,arg) #define rpldph_plp_unref(arg) __rpldph_export1(plp,_unref,arg) #define rpldph_plp_copy(arg,...) __rpldph_exportn(plp,_copy,arg,__VA_ARGS__) #define rpldph_plp_search(arg) __rpldph_export1(plp,_search,arg) #define rpldph_playback_play(arg) __rpldph_export1(playback,_play,arg) #define rpldph_playback_next(arg) __rpldph_export1(playback,_next,arg) #define rpldph_playback_prev(arg) __rpldph_export1(playback,_prev,arg) #define rpldph_playback_stop(arg) __rpldph_export1(playback,_stop,arg) #define rpldph_playback_pause(arg,...) __rpldph_exportn(playback,_pause,arg,__VA_ARGS__) #define rpldph_playback_is_playing(arg) __rpldph_export1(playback,_is_playing,arg) #define rpldph_playback_is_paused(arg) __rpldph_export1(playback,_is_paused,arg) #define rpldph_playback_is_queue(arg) __rpldph_export1(playback,_is_queue,arg) #define rpldph_playback_get_volume(arg) __rpldph_export1(playback,_get_volume,arg) #define rpldph_playback_set_volume(arg,...) __rpldph_exportn(playback,_set_volume,arg,__VA_ARGS__) #define rpldph_playback_set_role(arg,...) __rpldph_exportn(playback,_set_role,arg,__VA_ARGS__) #define rpldph_playback_get_ple(arg) __rpldph_export1(playback,_get_ple,arg) #define rpldph_playback_get_mduc(arg) __rpldph_export1(playback,_get_mduc,arg) #define rpldph_playback_get_stream(arg) __rpldph_export1(playback,_get_stream,arg) #define rpldph_store_save() __rpldph_export0(store,_save) #define rpldph_store_load() __rpldph_export0(store,_load) #define rpldph_backend_get_connection(arg) __rpldph_export1(backend,_get_connection,arg) #define rpldph_backend_ref(arg) __rpldph_export1(backend,_ref,arg) #define rpldph_backend_unref(arg) __rpldph_export1(backend,_unref,arg) #define rpldph_backend_get_name(arg) __rpldph_export1(backend,_get_name,arg) #define rpldph_backend_get_con(arg) __rpldph_export1(backend,_get_con,arg) #define rpldph_backend_blacklist_codec(arg,...) __rpldph_exportn(backend,_blacklist_codec,arg,__VA_ARGS__) #define rpldph_backend_blacklist_check_codec(arg,...) __rpldph_exportn(backend,_blacklist_codec,arg,__VA_ARGS__) #define rpldph_client_set_name(arg,...) __rpldph_exportn(client,_set_name,arg,__VA_ARGS__) #define rpldph_client_get_name(arg) __rpldph_export1(client,_get_name,arg) #define rpldph_client_set_playlist(arg,...) __rpldph_exportn(client,_set_playlist,arg,__VA_ARGS__) #define rpldph_client_get_playlist(arg) __rpldph_export1(client,_get_playlist,arg) #define rpldph_client_set_queue(arg,...) __rpldph_exportn(client,_set_queue,arg,__VA_ARGS__) #define rpldph_client_get_queue(arg) __rpldph_export1(client,_get_queue,arg) #define rpldph_client_str2proto(arg) __rpldph_export1(client,_str2proto,arg) #define rpldph_client_proto2str(arg) __rpldph_export1(client,_proto2str,arg) #define rpldph_fformat_str2plf(arg) __rpldph_export1(fformat,_str2plf,arg) #define rpldph_fformat_plf2str(arg) __rpldph_export1(fformat,_plf2str,arg) #define rpldph_fformat_handle_new(arg) __rpldph_export1(fformat,_handle_new,arg) #define rpldph_fformat_handle_close(arg) __rpldph_export1(fformat,_handle_close,arg) #define rpldph_fformat_playlist_export(arg,...) __rpldph_exportn(fformat,_playlist_export,arg,__VA_ARGS__) #define rpldph_fformat_playlist_import(arg,...) __rpldph_exportn(fformat,_playlist_import,arg,__VA_ARGS__) #define rpldph_pointer_get_name(arg,...) __rpldph_exportn(pointer,_get_name,arg,__VA_ARGS__) #define rpldph_pointer_parse_name(arg,...) __rpldph_exportn(pointer,_parse_name,arg,__VA_ARGS__) #define rpldph_pointer_is_set(arg,...) __rpldph_exportn(pointer,_is_set,arg,__VA_ARGS__) #define rpldph_pointer_get(arg,...) __rpldph_exportn(pointer,_get,arg,__VA_ARGS__) #define rpldph_pointer_get_by__name(arg,...) __rpldph_exportn(pointer,_get_by_name,arg,__VA_ARGS__) #define rpldph_pointer_set(arg,...) __rpldph_exportn(pointer,_set,arg,__VA_ARGS__) #define rpldph_pointer_set_by_name(arg,...) __rpldph_exportn(pointer,_set_by_name,arg,__VA_ARGS__) #define rpldph_pointer_search(arg,...) __rpldph_exportn(pointer,_search,arg,__VA_ARGS__) #define rpldph_yield_ay_trigger() __rpldph_export0(yield,_ay_trigger) #define rpldph_yield_ay_pause() __rpldph_export0(yield,_ay_pause) #define rpldph_yield_ay_unpause() __rpldph_export0(yield,_ay_unpause) #define rpldph_yield_watchdog_trigger() __rpldph_export0(yield,_watchdog_trigger) #endif //ll rpld-0.1.9/rpldslp.c0000644000175000017500000000475612266574311012453 0ustar phiphi//rpldslp.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" #ifdef HAVE_LIB_SLP void register_slp_callback(SLPHandle hslp, SLPError errcode, void * cookie) { (void)hslp; /* return the error code in the cookie */ *(SLPError*)cookie = errcode; } int register_slp (int unreg, const char * sockname) { static int regged = 0; static const char * sn = NULL; SLPError err; SLPError callbackerr; SLPHandle hslp; char addr[1024]; if ( sockname != NULL ) sn = sockname; snprintf(addr, sizeof(addr), RPLD_SLP_TYPE_RPLD "://%s", sn); err = SLPOpen("en", SLP_FALSE, &hslp); if (err != SLP_OK) { ROAR_ERR("Error opening slp handle: Error #%i", err); return -1; } if (!unreg) { err = SLPReg(hslp, addr, SLP_LIFETIME_MAXIMUM, NULL, "", /* attributes */ SLP_TRUE, register_slp_callback, &callbackerr); regged = 1; } else if ( unreg && regged ) { err = SLPDereg(hslp, addr, register_slp_callback, &callbackerr); regged = 0; } else { SLPClose(hslp); return -1; } /* err may contain an error code that occurred as the slp library */ /* _prepared_ to make the call. */ if ( err != SLP_OK ) { ROAR_ERR("Error (de)registering service with slp: Error #%i", err); return -1; } /* callbackerr may contain an error code (that was assigned through */ /* the callback cookie) that occurred as slp packets were sent on */ /* the wire */ if (callbackerr != SLP_OK) { ROAR_ERR("Error (de)registering service with slp: Error #%i", callbackerr); return -1; } SLPClose(hslp); return 0; } #endif //ll rpld-0.1.9/rpldslp.h0000644000175000017500000000230712266574311012446 0ustar phiphi//rpldslp.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_SLP_H_ #define _RPLD_SLP_H_ #define RPLD_SLP_TYPE_RPLD "service:playlist.fellig:rpld" #define RPLD_SLP_TYPE_RPLD_LEN 28 #ifdef ROAR_HAVE_LIBSLP void register_slp_callback(SLPHandle hslp, SLPError errcode, void * cookie); int register_slp (int unreg, const char * sockname); #endif #endif //ll rpld-0.1.9/serverinfo.c0000644000175000017500000001011112266574311013133 0ustar phiphi//serverinfo.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" static struct roar_server_info * __info_lib = NULL; static struct roar_server_info * __info_server = NULL; static struct roar_server_info * rpld_serverinfo_get_raw(int reinit) { static struct roar_server_info info; static int inited = 0; if ( reinit || !inited ) { memset(&info, 0, sizeof(info)); inited = 1; rpld_serverinfo_update(RPLD_SERVERINFO_SOURCE_BUILDIN, NULL); rpld_serverinfo_update(RPLD_SERVERINFO_SOURCE_LIBRARY, NULL); } return &info; } int rpld_serverinfo_free(void) { roar_server_info_free(__info_lib); roar_server_info_free(__info_server); __info_lib = NULL; __info_server = NULL; rpld_serverinfo_get_raw(1); return 0; } const struct roar_server_info * rpld_serverinfo_get(void) { return rpld_serverinfo_get_raw(0); } static int rpld_serverinfo_update_lib(struct roar_server_info * info) { if ( __info_lib != NULL ) return 0; // noop. __info_lib = roar_library_info(); if ( __info_lib == NULL ) return -1; #define _copy(var) if ( __info_lib->var != NULL ) info->var = __info_lib->var _copy(location); _copy(contact); _copy(serial); _copy(address); _copy(hostid); _copy(un.sysname); _copy(un.release); _copy(un.nodename); _copy(un.machine); #undef _copy return -1; } static int rpld_serverinfo_update_server(struct roar_server_info * info, const char * server) { struct rpld_backend * backend; if ( __info_server != NULL ) return 0; // noop. backend = backend_get_connection(server); if ( backend == NULL ) return -1; if ( !(backend->flags & BACKEND_FLAG_CONNECTED) ) { roar_err_set(ROAR_ERROR_NOTCONN); return -1; } __info_server = roar_server_info(&(backend->con)); backend_unref(backend); if ( __info_server == NULL ) return -1; #define _copy(var) if ( __info_server->var != NULL ) info->var = __info_server->var _copy(location); _copy(description); _copy(contact); _copy(serial); _copy(uiurl); #undef _copy return -1; } static int rpld_serverinfo_update_object(struct roar_server_info * info, const struct roar_server_info * obj) { if ( obj == NULL ) { roar_err_set(ROAR_ERROR_FAULT); return -1; } #define _copy(var) if ( obj->var != NULL ) info->var = obj->var _copy(location); _copy(description); _copy(contact); _copy(serial); _copy(address); _copy(uiurl); #undef _copy return 0; } int rpld_serverinfo_update(enum rpld_serverinfo_source source, const void * argp) { struct roar_server_info * info = rpld_serverinfo_get_raw(0); switch (source) { case RPLD_SERVERINFO_SOURCE_BUILDIN: // the following if is optimized out by compiler. if ( DISTRIBUTION_VERSION_STRING[0] == 0 ) { info->version = "rpld/" VERSION " " ROAR_VSTR_ROARAUDIO; } else { info->version = "rpld/" VERSION " " ROAR_VSTR_ROARAUDIO " (" DISTRIBUTION_VERSION_STRING ")"; } info->license = ROAR_LICENSE_GPLv3_0; info->build = BUILD_STAMP; return 0; break; case RPLD_SERVERINFO_SOURCE_LIBRARY: return rpld_serverinfo_update_lib(info); break; case RPLD_SERVERINFO_SOURCE_SERVER: return rpld_serverinfo_update_server(info, argp); break; case RPLD_SERVERINFO_SOURCE_OBJECT: return rpld_serverinfo_update_object(info, argp); break; } roar_err_set(ROAR_ERROR_NOTSUP); return -1; } //ll rpld-0.1.9/serverinfo.h0000644000175000017500000000244312266574311013151 0ustar phiphi//serverinfo.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_SERVERINFO_H_ #define _RPLD_SERVERINFO_H_ enum rpld_serverinfo_source { RPLD_SERVERINFO_SOURCE_BUILDIN, RPLD_SERVERINFO_SOURCE_LIBRARY, RPLD_SERVERINFO_SOURCE_SERVER, RPLD_SERVERINFO_SOURCE_OBJECT }; int rpld_serverinfo_free(void); const struct roar_server_info * rpld_serverinfo_get(void); int rpld_serverinfo_update(enum rpld_serverinfo_source source, const void * argp); #endif //ll rpld-0.1.9/store.c0000644000175000017500000003545512266574312012130 0ustar phiphi//store.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" struct index_lion { // PL: $id:$parent:X:$name:$histsize:$volume:$role:$history_pli:$backend_name:$mixer_id: pli_t id; pli_t parent; const char * name; ssize_t histsize; uint16_t volume_mono; int role; pli_t history; const char * backend_name; int mixer_id; }; static const char * _g_path = NULL; static char * _astr(size_t * s) { size_t len; if ( _g_path == NULL ) return NULL; len = strlen(_g_path); *s = len+1 /* slash */ + 32 /* pl-* */; return (char*) roar_mm_malloc(*s); } static void _mkfile(char * buf, size_t len, const char * path, const char * file) { snprintf(buf, len, "%s/%s", path, file); buf[len-1] = 0; } int store (void) { struct fformat_handle * format; struct rpld_playlist * pl; struct rpld_queue * plq; struct roar_vio_calls file; struct roar_vio_calls index, export; struct roar_vio_defaults def; struct rpld_playlist_pointer * plp; char * pointer_name; int pointer; size_t i; char * buf; size_t len; char uuid[37]; // TODO: free format... if ( _g_path == NULL ) return -1; if ( (format = fformat_handle_new(RPLD_FF_PLF_DEFAULT)) == NULL ) return -1; if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_WRONLY|O_CREAT|O_TRUNC, 0644) == -1 ) { fformat_handle_close(format); return -1; } if ( (buf = _astr(&len)) == NULL ) { fformat_handle_close(format); return -1; } _mkfile(buf, len, _g_path, "store-version"); if ( roar_vio_open_dstr(&file, buf, &def, 1) == -1 ) { fformat_handle_close(format); return -1; } roar_vio_printf(&file, "%i\n", STORE_VERSION_CURRENT); roar_vio_close(&file); _mkfile(buf, len, _g_path, "pointer"); if ( roar_vio_open_dstr(&file, buf, &def, 1) == -1 ) { fformat_handle_close(format); return -1; } for (i = 0; i < MAX_PLAYLISTS; i++) { if ( g_playlists[i] == NULL ) continue; if ( g_playlists[i]->queue == NULL ) continue; for (pointer = 0; pointer < POINTER_NUM; pointer++) { pointer_name = rpld_pointer_get_name(pointer, g_playlists[i]->id, -1); plp = rpld_pointer_get(pointer, g_playlists[i]->id, -1); if ( plp == NULL ) continue; switch (plp->pls.type) { case RPLD_PL_ST_TRACKNUM_LONG: roar_vio_printf(&file, "POINTER: \"%s\" -> long:0x0x%.16" __ll "X\n", pointer_name, (__longlong unsigned int)plp->pls.subject.long_tracknum); break; case RPLD_PL_ST_TRACKNUM_SHORT: roar_vio_printf(&file, "POINTER: \"%s\" -> short:0x0x%.8lX\n", pointer_name, (long unsigned int)plp->pls.subject.short_tracknum); break; case RPLD_PL_ST_UUID: roar_uuid2str(uuid, plp->pls.subject.uuid, sizeof(uuid)); roar_vio_printf(&file, "POINTER: \"%s\" -> uuid:%s\n", pointer_name, uuid); break; case RPLD_PL_ST_RANDOM: roar_vio_printf(&file, "POINTER: \"%s\" -> random:%i\n", pointer_name, plp->pls.subject.pl); break; case RPLD_PL_ST_RANDOM_LIKENESS: roar_vio_printf(&file, "POINTER: \"%s\" -> randomlike:%i\n", pointer_name, plp->pls.subject.pl); break; } rpld_plp_unref(plp); roar_mm_free(pointer_name); } } roar_vio_close(&file); _mkfile(buf, len, _g_path, "index"); if ( roar_vio_open_dstr(&index, buf, &def, 1) == -1 ) { fformat_handle_close(format); return -1; } for (i = 0; i < MAX_PLAYLISTS; i++) { pl = rpld_pl_get_by_id(i); if ( pl != NULL ) { plq = pl->queue; // format: // PL: $id:$parent:X:$name:$histsize:$volume:$role:$history_pli:$backend_name:$mixer_id: roar_vio_printf(&index, "PL: %i:%i:X:%s:%li:", rpld_pl_get_id(pl), rpld_pl_get_parent(pl), rpld_pl_get_name(pl), (long int)rpld_pl_get_histsize(pl) ); if ( plq == NULL ) { roar_vio_printf(&index, "-1:unknown:-1:+invalid:-1:\n"); } else { roar_vio_printf(&index, "%u:%s:%i:%s:%i:\n", (unsigned int)plq->volume_mono, roar_role2str(plq->role), rpld_pl_get_id(plq->history), backend_get_name(plq->backend), plq->mixer ); } /* int fformat_playlist_export(struct fformat_handle * handle, struct roar_vio_calls * vio, struct rpld_playlist * pl); */ snprintf(buf, len, "%s/pl-%i", _g_path, rpld_pl_get_id(pl)); buf[len-1] = 0; if ( roar_vio_open_dstr(&export, buf, &def, 1) == -1 ) { roar_vio_close(&index); fformat_handle_close(format); rpld_pl_unref(pl); return -1; } fformat_playlist_export(format, &export, pl); roar_vio_close(&export); rpld_pl_unref(pl); } } roar_vio_close(&index); roar_mm_free(buf); fformat_handle_close(format); return 0; } static inline int _parse_index_line(struct index_lion * index, char * lion) { char * div[11]; int i; // 0 1 2 3 4 5 6 7 8 9 // PL: $id:$parent:X:$name:$histsize:$volume:$role:$history_pli:$backend_name:$mixer_id: if ( !!strncmp(lion, "PL: ", 4) ) { roar_err_set(ROAR_ERROR_ILLSEQ); return -1; } div[0] = lion + 4; for (i = 1; i < 11; i++) { if ( div[i-1] == NULL ) { div[i] = NULL; } else { div[i] = strstr(div[i-1], ":"); } if ( div[i] != NULL ) { *div[i] = 0; div[i]++; if ( *div[i] == '\r' || *div[i] == '\n' ) div[i] = NULL; } } #define _def(idx,val) if ( div[(idx)] == NULL ) div[(idx)] = (val) _def(0, "-1"); _def(1, "0"); _def(2, "X"); // dummy. _def(3, "NO NAME"); _def(4, "-1"); // this is not an history _def(5, "65535"); // max volume. _def(6, "unknown"); // unknown role. _def(7, "-1"); // no history PLI for this stream. _def(8, "+invalid"); _def(9, "-1"); // default mixer. _def(10, ""); // END OF RECORD. index->id = atoi(div[0]); index->parent = atoi(div[1]); index->name = div[3]; index->histsize = atoi(div[4]); index->volume_mono = atoi(div[5]); index->role = roar_str2role(div[6]); index->history = atoi(div[7]); index->backend_name = div[8]; index->mixer_id = atoi(div[9]); ROAR_DBG("_parse_index_line(index=%p{.id=%i, .parent=%i, .name='%s', .histsize=%zi, .volume_mono=%u, .role=%i, .history=%i, .backend_name='%s', .index=%i}, lion='%s') = 0", index, (int)index->id, (int)index->parent, index->name, index->histsize, (unsigned int)index->volume_mono, index->role, (int)index->history, index->backend_name, index->mixer_id, lion); return 0; } static inline int __flush_state(void) { struct rpld_playlist * pl; size_t i; for (i = 0; i < MAX_PLAYLISTS; i++) { if ( (pl = g_playlists[i]) == NULL ) continue; rpld_pl_set_name(pl, NULL); rpld_pl_unregister(pl); } return 0; } int restore_pointers (const char * filename, struct roar_vio_defaults * def) { struct rpld_playlist_search pls; struct rpld_playlist_pointer * plp; struct roar_vio_calls file; char lion[1024]; char * div[3]; pli_t queue; int pointer; int client; int i; if ( roar_vio_open_dstr(&file, filename, def, 1) == -1 ) return -1; while (roar_vio_fgets(&file, lion, sizeof(lion)) != NULL) { if ( !strncmp(lion, "POINTER: \"", 10) ) { div[0] = lion+10; div[1] = strstr(div[0], "\" -> "); if ( div[1] == NULL ) continue; ROAR_DBG("restore() = ?"); *div[1] = 0; div[1] += 5; if ( rpld_pointer_parse_name(&pointer, &queue, &client, -1, div[0]) == -1 ) continue; ROAR_DBG("restore() = ?"); div[2] = strstr(div[1], ":"); if ( div[2] == NULL ) continue; ROAR_DBG("restore() = ?"); *div[2] = 0; div[2]++; memset(&pls, 0, sizeof(pls)); ROAR_DBG("restore() = ?"); i = strlen(div[2]) - 1; for (; i > -1; i--) { if ( div[2][i] == '\r' || div[2][i] == '\n' ) { div[2][i] = 0; } else { break; } } if ( !strcmp(div[1], "uuid") ) { ROAR_DBG("restore(): uuid='%s'", div[2]); pls.type = RPLD_PL_ST_UUID; if ( roar_str2uuid(pls.subject.uuid, div[2]) != 0 ) continue; ROAR_DBG("restore() = ?"); } else if ( !strcmp(div[1], "random") ) { pls.type = RPLD_PL_ST_RANDOM; pls.subject.pl = atoi(div[2]); } else if ( !strcmp(div[1], "randomlike") ) { pls.type = RPLD_PL_ST_RANDOM_LIKENESS; pls.subject.pl = atoi(div[2]); } else { ROAR_WARN("restore(): Unsupported search schema: %s", div[1]); continue; ROAR_DBG("restore() = ?"); } plp = rpld_plp_init(NULL, &pls); rpld_pointer_set(pointer, queue, client, plp); rpld_plp_unref(plp); } } roar_vio_close(&file); return 0; } int restore (void) { struct fformat_handle * format; struct rpld_playlist * pl, * history; struct rpld_backend * backend; struct roar_vio_calls file; struct roar_vio_calls index, import; struct roar_vio_defaults def; struct index_lion index_lion; char * buf; char lion[1024]; size_t len; int store_version = STORE_VERSION_DEFAULT; if ( __flush_state() == -1 ) return -1; // TODO: free format... if ( _g_path == NULL ) return -1; if ( (format = fformat_handle_new(RPLD_FF_PLF_DEFAULT)) == NULL ) return -1; if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_RDONLY, 0644) == -1 ) { fformat_handle_close(format); return -1; } if ( (buf = _astr(&len)) == NULL ) { fformat_handle_close(format); return -1; } _mkfile(buf, len, _g_path, "store-version"); if ( roar_vio_open_dstr(&file, buf, &def, 1) != -1 ) { if ( roar_vio_fgets(&file, lion, sizeof(lion)) != NULL ) { store_version = atoi(lion); } else { store_version = STORE_VERSION_DEFAULT; } roar_vio_close(&file); } else { store_version = STORE_VERSION_DEFAULT; } if ( store_version > STORE_VERSION_CURRENT ) { fformat_handle_close(format); ROAR_ERR("restore(): Can not restore: store version too new: %i (%i is current)", store_version, STORE_VERSION_CURRENT); roar_err_set(ROAR_ERROR_NSVERSION); return -1; } switch (store_version) { case STORE_VERSION_OLD: case STORE_VERSION_V0_1RC1: history = rpld_pl_get_by_id(1); if ( history == NULL ) { history = rpld_pl_new(); rpld_pl_set_name(history, "Main History"); rpld_pl_register_id(history, 1); } rpld_pl_unref(history); pl = rpld_pl_get_by_id(0); if ( pl == NULL ) { pl = rpld_pl_new(); rpld_pl_set_name(pl, "Main Queue"); rpld_pl_register_id(pl, 0); } rpld_pl_unref(pl); break; } _mkfile(buf, len, _g_path, "index"); if ( roar_vio_open_dstr(&index, buf, &def, 1) == -1 ) { fformat_handle_close(format); return -1; } while (roar_vio_fgets(&index, lion, sizeof(lion)) != NULL) { if ( _parse_index_line(&index_lion, lion) == 0 ) { if ( store_version < STORE_VERSION_V0_1RC7 ) { if ( (index_lion.id & 0xFF) == 1 && !!strcmp(index_lion.name, "Main History") ) { store_version = STORE_VERSION_OLD; // allow re-registering by unrefing. pl = rpld_pl_get_by_id(index_lion.id); if ( pl != NULL ) { rpld_pl_set_name(pl, NULL); rpld_pl_unref(pl); } } } pl = rpld_pl_get_by_id(index_lion.id); if ( pl == NULL ) { pl = rpld_pl_new(); rpld_pl_register_id(pl, index_lion.id); } rpld_pl_set_name(pl, index_lion.name); rpld_pl_set_parent(pl, index_lion.parent); rpld_pl_unref(pl); // pl keeps valid as it is stored in the global register. if ( !!strcmp(index_lion.backend_name, "+invalid") ) { history = rpld_pl_get_by_id(index_lion.history); if ( history == NULL ) { history = rpld_pl_new(); rpld_pl_register_id(history, index_lion.history); } // first pre-connect to the backend server. // this allows us to track connection errors a bit more easy. backend = backend_get_connection2(index_lion.backend_name, 1); if ( backend == NULL ) { ROAR_WARN("restore(void): Can not create backend object for server. BAD.: %s: %s", index_lion.backend_name, roar_errorstring); } else { if ( !(backend->flags & BACKEND_FLAG_CONNECTED) ) { ROAR_WARN("restore(void): Unabled to connect to server: %s: %s", index_lion.backend_name, roar_errorstring); } backend_unref(backend); } playback_add_queue(pl, index_lion.backend_name, index_lion.mixer_id, history); playback_set_volume_mu16(index_lion.id, index_lion.volume_mono); playback_set_role(index_lion.id, index_lion.role); rpld_pl_unref(history); } if ( pl != NULL ) { if ( index_lion.histsize != -1 ) rpld_pl_set_histsize(pl, index_lion.histsize); snprintf(buf, len, "%s/pl-%i", _g_path, index_lion.id); buf[len-1] = 0; if ( roar_vio_open_dstr(&import, buf, &def, 1) == -1 ) { roar_vio_close(&index); fformat_handle_close(format); return -1; } fformat_playlist_import(format, &import, pl); roar_vio_close(&import); } } } roar_vio_close(&index); fformat_handle_close(format); _mkfile(buf, len, _g_path, "pointer"); if ( restore_pointers(buf, &def) == -1 ) { ROAR_WARN("restore(): Loading pointers failed: %s", roar_error2str(roar_error)); } switch (store_version) { case STORE_VERSION_OLD: case STORE_VERSION_V0_1RC1: if ( store_version < STORE_VERSION_V0_1RC1 ) { history = rpld_pl_new(); rpld_pl_set_name(history, "Main History"); rpld_pl_register(history); } else { history = rpld_pl_get_by_id(1); } pl = rpld_pl_get_by_id(0); if ( rpld_pl_get_histsize(history) == -1 ) rpld_pl_set_histsize(history, 42); // TODO: FIXME: use global const here. playback_add_queue(pl, BACKEND_DEFAULT_NAME, -1, history); rpld_pl_unref(pl); rpld_pl_unref(history); break; } roar_mm_free(buf); return 0; } int setstorepath(const char * path) { if ( path == NULL ) return -1; if ( *path == 0 ) return -1; _g_path = path; return 0; } //ll rpld-0.1.9/store.h0000644000175000017500000000261612266574312012126 0ustar phiphi//store.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_STORE_H_ #define _RPLD_STORE_H_ #define STORE_VERSION_OLD 0 /* pre 0.1rc1 (no history) */ #define STORE_VERSION_V0_1RC1 1 /* pre 0.1rc7 (single queue) */ #define STORE_VERSION_V0_1RC7 2 /* version as of 0.1rc7 */ #define STORE_VERSION_CURRENT STORE_VERSION_V0_1RC7 /* the current version */ #define STORE_VERSION_DEFAULT STORE_VERSION_V0_1RC1 /* the version to assume in case there is no store-version file */ int store (void); int restore (void); int setstorepath(const char * path); #endif //ll rpld-0.1.9/yield.c0000644000175000017500000001302412266574312012066 0ustar phiphi//yield.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "rpld.h" #define INTERVAL 100000 /* in µs */ #define WATCHDOG_SCALER 20 /* in units of INTERVAL */ static int _ay_ptasks = RPLD_YIELD_TASK_NONE; static int _ay_ntasks = RPLD_YIELD_TASK_NONE; static int _ay_block = RPLD_YIELD_NONBLOCK; static size_t _ay_count = 0; static size_t _ay_pause = 0; #ifdef ROAR_FT_FEATURE_WATCHDOG static int _ay_watchdog_enabled = 0; static int _ay_watchdog = 0; #endif static void _task_plugin_update(int block) { (void)block; rpld_plugin_appsched(ROAR_DL_APPSCHED_UPDATE); } static void _task_plugin_tick(int block) { (void)block; rpld_plugin_appsched(ROAR_DL_APPSCHED_TICK); } #ifdef ROAR_FT_FEATURE_WATCHDOG static void _task_watchdog(int block) { static int tickc = 0; (void)block; tickc++; if ( tickc != WATCHDOG_SCALER ) return; tickc = 0; roar_watchdog_tick(); } #endif static const struct { int task; int block; void (*func)(int block); } _g_yield_tasks[] = { {RPLD_YIELD_TASK_NETWORK, RPLD_YIELD_NONBLOCK, network_check }, {RPLD_YIELD_TASK_PLAYBACK, RPLD_YIELD_NONBLOCK, playback_check }, {RPLD_YIELD_TASK_PLUGIN_UPDATE, RPLD_YIELD_NONBLOCK, _task_plugin_update}, {RPLD_YIELD_TASK_PLUGIN_TICK, RPLD_YIELD_NONBLOCK, _task_plugin_tick }, #ifdef ROAR_FT_FEATURE_WATCHDOG {RPLD_YIELD_TASK_WATCHDOG, RPLD_YIELD_NONBLOCK, _task_watchdog }, #endif {-1, 1, NULL} }; void yield(int ptasks, int ntasks, int block) { int i; ptasks |= ntasks; ptasks -= ntasks; // always do watchdog. ptasks |= RPLD_YIELD_TASK_WATCHDOG; if ( ptasks == 0 ) return; for (i = 0; _g_yield_tasks[i].task != -1; i++) { if ( !(_g_yield_tasks[i].task & ptasks) ) continue; if ( _g_yield_tasks[i].block > block ) continue; _g_yield_tasks[i].func(block); } } #ifdef HAVE_FUNC_UALARM static void on_sig_alarm (int signum) { (void)signum; ROAR_DBG("on_sig_alarm(signum=%i): _ay_ptasks=0x%x, _ay_ntasks=0x%x, _ay_block=0x%x", signum, _ay_ptasks, _ay_ntasks, _ay_block); #ifdef ROAR_FT_FEATURE_WATCHDOG if ( _ay_pause || !_ay_count ) { yield(RPLD_YIELD_TASK_WATCHDOG, RPLD_YIELD_TASK_NONE, RPLD_YIELD_NONBLOCK); } else { #endif yield(_ay_ptasks, _ay_ntasks, _ay_block); #ifdef ROAR_FT_FEATURE_WATCHDOG } #endif } #endif static void _timer_enable(void) { #ifdef HAVE_FUNC_UALARM signal(SIGALRM, on_sig_alarm); ualarm(INTERVAL, INTERVAL); #endif } static void _timer_disable(void) { #ifdef ROAR_FT_FEATURE_WATCHDOG if ( _ay_watchdog ) return; #endif #ifdef HAVE_FUNC_UALARM signal(SIGALRM, SIG_IGN); ualarm(0, 0); #endif } void yield_auto(enum yield_auto cmd, int ptasks, int ntasks, int block) { switch (cmd) { case RPLD_YIELD_START: if ( !_ay_count ) { _ay_ptasks = RPLD_YIELD_TASK_ALL; _ay_ntasks = RPLD_YIELD_TASK_NONE; _ay_block = RPLD_YIELD_LONGBLOCK; } _ay_count++; _ay_ptasks &= ptasks; _ay_ntasks |= ntasks; if ( _ay_block > block ) _ay_block = block; if ( _ay_count != 1 ) return; if ( _ay_pause ) return; // start timer. _timer_enable(); break; case RPLD_YIELD_STOP: if ( !_ay_count ) { ROAR_WARN("yield_auto(cmd=RPLD_YIELD_STOP, ptasks=0x%x, ntasks=0x%x, block=%i): auto yield stopped before started. This is a programming error.", ptasks, ntasks, block); return; } _ay_count--; if ( !_ay_count) { // stop timer. _timer_disable(); } break; case RPLD_YIELD_PAUSE: _ay_pause++; if ( _ay_pause == 1 && _ay_count ) _timer_disable(); break; case RPLD_YIELD_UNPAUSE: if ( !_ay_pause ) { ROAR_WARN("yield_auto(cmd=RPLD_YIELD_UNPAUSE, ptasks=0x%x, ntasks=0x%x, block=%i): auto yield unpaused before paused. This is a programming error.", ptasks, ntasks, block); return; } _ay_pause--; if ( _ay_pause == 0 && _ay_count ) _timer_enable(); break; case RPLD_YIELD_TRIGGER: if ( _ay_count && !_ay_pause ) yield(_ay_ptasks, _ay_ntasks, _ay_block); break; } } void yield_watchdog_active(int active) { #ifdef ROAR_FT_FEATURE_WATCHDOG _ay_watchdog_enabled = active; if ( !active && _ay_watchdog ) yield_watchdog_stop(); #else (void)active; #endif } void yield_watchdog_start(void) { #ifdef ROAR_FT_FEATURE_WATCHDOG if ( !_ay_watchdog_enabled ) return; roar_watchdog_start(ROAR_WATCHDOG_CONF_STOPPABLE|ROAR_WATCHDOG_CONF_CLOCK_EXTERNAL, 1000, NULL); _ay_watchdog = 1; _timer_enable(); #endif } void yield_watchdog_stop(void) { #ifdef ROAR_FT_FEATURE_WATCHDOG if ( !_ay_watchdog ) return; roar_watchdog_stop(); _ay_watchdog = 0; if ( !_ay_count ) _timer_disable(); #endif } void yield_watchdog_trigger(void) { #ifdef ROAR_FT_FEATURE_WATCHDOG roar_watchdog_trigger(); #endif } //ll rpld-0.1.9/yield.h0000644000175000017500000000404012266574312012071 0ustar phiphi//yield.h: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #ifndef _RPLD_YIELD_H_ #define _RPLD_YIELD_H_ #define RPLD_YIELD_TASK_NONE 0x0000 #define RPLD_YIELD_TASK_ALL 0xFFFF #define RPLD_YIELD_TASK_NETWORK 0x0001 #define RPLD_YIELD_TASK_PLAYBACK 0x0002 #define RPLD_YIELD_TASK_PLUGIN_UPDATE 0x0004 #define RPLD_YIELD_TASK_PLUGIN_TICK 0x0008 #define RPLD_YIELD_TASK_WATCHDOG 0x0010 #define RPLD_YIELD_NONBLOCK 0 #define RPLD_YIELD_BLOCK 1 #define RPLD_YIELD_LONGBLOCK 2 enum yield_auto { RPLD_YIELD_UNPAUSE = +64, #define RPLD_YIELD_UNPAUSE RPLD_YIELD_UNPAUSE RPLD_YIELD_START = +1, #define RPLD_YIELD_START RPLD_YIELD_START RPLD_YIELD_TRIGGER = 0, #define RPLD_YIELD_TRIGGER RPLD_YIELD_TRIGGER RPLD_YIELD_STOP = -1, #define RPLD_YIELD_STOP RPLD_YIELD_STOP RPLD_YIELD_PAUSE = -64 #define RPLD_YIELD_PAUSE RPLD_YIELD_PAUSE }; void yield(int ptasks, int ntasks, int block); void yield_auto(enum yield_auto cmd, int ptasks, int ntasks, int block); void yield_watchdog_active(int active); void yield_watchdog_start(void); void yield_watchdog_stop(void); void yield_watchdog_trigger(void); #endif //ll rpld-0.1.9/dist/0000755000175000017500000000000012266602740011554 5ustar phiphirpld-0.1.9/dist/debian-like/0000755000175000017500000000000012266602740013720 5ustar phiphirpld-0.1.9/dist/debian-like/defaults0000644000175000017500000000246312023607753015457 0ustar phiphi#RoarAudio PlayList Daemon (RPLD) Configuration # --- [ General Options ]--- # Start rpld? YES or NO: RPLD='NO' # Additionl Options to pass to rpld, should normally be empty RPLD_OPTS='' # Server address of roard: # Default: libroar buildin server list. # ROARAUDIO_SERVER='server.local' # --- [ Network ] --- # Listening socket's address family: # UNIX - Local connections only # TCP - Connections via TCP/IP # DECnet - Connections via DECnet RPLD_AF='UNIX' # Socket to listen on (UNIX): RPLD_SOCKET='/tmp/.rpld' # Port to listen on (TCP): # RPLD_PORT=24148 # Host/Nodename to listen on (TCP): # use a value of '0.0.0.0' to listen publicly for TCP. # RPLD_HOST='0.0.0.0' # --- [ Storing and Restoring ]--- # Where to store to?: RPLD_STORE_LOCATION='/var/lib/roarplaylistd/' # ReStore on startup: # RPLD_RESTORE='false' # Store on exit: # RPLD_STORE='false' # --- [ Playback ] --- # Should we start up in playing state? # RPLD_PLAY='false' # --- [ Permitions ] --- # User/Group to run rpld as: # YOU MUST NOT SET USER TO 'root'. # THIS WILL ALLOW EVERY USER ABLED TO ACCESS RPLD OVERWRITE SYSTEM FILES # LIKE PASSWORD DATABASE. # RPLD_USER='roard' # RPLD_GROUP='audio' # User and Group to set on socket: # Note: Users in the same group can access rpld # RPLD_SOCK_USER='roard' # RPLD_SOCK_GROUP='audio' #ll rpld-0.1.9/dist/debian-like/rpld0000755000175000017500000001123411757751450014617 0ustar phiphi#!/bin/sh # # RoarAudio PlayList Daemon initscript # # Copyright (c) 2008-2010 Philipp 'ph3-der-loewe' Schafft # Copyright (c) 2007 Javier Fernandez-Sanguino # # This is free software; you may redistribute it and/or modify # it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 3, # or (at your option) any later version. # # This 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 General Public License for more details. # # You should have received a copy of the GNU General Public License with # the Debian operating system, in /usr/share/common-licenses/GPL; if # not, write to the Free Software Foundation, Inc., 59 Temple Place, # Suite 330, Boston, MA 02111-1307 USA ### BEGIN INIT INFO # Provides: roarplaylistd # Required-Start: $network $local_fs $remote_fs # Required-Stop: $network $local_fs $remote_fs # Should-Start: roaraudio-server # Should-Stop: roaraudio-server # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: PlayList mangement daemon for RoarAudio # Description: RoarAudio PlayList Daemon is a daemon managing playlist # for the user and playback of those. # It uses a RoarAudio server as audio backend. ### END INIT INFO set -e PATH=/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/bin/rpld NAME=rpld DESC="RoarAudio PlayList Daemon" PIDFILEDIR=/var/run/$NAME PIDFILE=$PIDFILEDIR/`basename $DAEMON`.pid SCRIPTNAME=/etc/init.d/$NAME RPLD_RESTORE=true # Gracefully exit if the package has been removed. test -x $DAEMON || exit 0; # Read config file if it is present. if [ -r /etc/default/$NAME ] then . /etc/default/$NAME fi [ "$RPLD" = 'YES' ] || exit 0; RPLD_OPTS="--daemon $RPLD_OPTS" [ "$PIDFILE" = '' ] || RPLD_OPTS="--pidfile $PIDFILE $RPLD_OPTS" [ "$ROARAUDIO_SERVER" = '' ] || RPLD_OPTS="--server $ROARAUDIO_SERVER $RPLD_OPTS" [ "$RPLD_STORE_LOCATION" = '' ] || RPLD_OPTS="--store-path $RPLD_STORE_LOCATION $RPLD_OPTS" [ "$RPLD_PLAY" = '' ] || RPLD_OPTS="--play $RPLD_OPTS" [ "$RPLD_USER" = '' ] || RPLD_OPTS="--user $RPLD_USER $RPLD_OPTS" [ "$RPLD_GROUP" = '' ] || RPLD_OPTS="--group $RPLD_GROUP $RPLD_OPTS" if $RPLD_RESTORE then RPLD_OPTS="$RPLD_OPTS --auto-restore" else RPLD_OPTS="$RPLD_OPTS --no-restore" fi if $RPLD_STORE then RPLD_OPTS="$RPLD_OPTS --store" else RPLD_OPTS="$RPLD_OPTS --no-store" fi case "$RPLD_AF" in UNIX|unix) RPLD_OPTS="--unix $RPLD_OPTS" [ "$RPLD_SOCKET" = '' ] || RPLD_OPTS="--bind $RPLD_SOCKET $RPLD_OPTS" ;; TCP|tcp) RPLD_OPTS="--tcp $RPLD_OPTS" [ "$RPLD_PORT" = '' ] || RPLD_OPTS="--port $RPLD_PORT $RPLD_OPTS" [ "$RPLD_HOST" = '' ] || RPLD_OPTS="--bind $RPLD_HOST $RPLD_OPTS" ;; DECNET|DECnet|decnet) RPLD_OPTS="--decnet $RPLD_OPTS" [ "$RPLD_PORT" = '' ] || RPLD_OPTS="--port $RPLD_PORT $RPLD_OPTS" [ "$RPLD_HOST" = '' ] || RPLD_OPTS="--bind $RPLD_HOST $RPLD_OPTS" ;; esac case "$1" in start) echo -n "Starting $DESC: $NAME" # Set up dir to use for pidfile mkdir -p "$PIDFILEDIR" chown $RPLD_USER:$RPLD_GROUP "$PIDFILEDIR" # Set up dir for store mkdir -p "$RPLD_STORE_LOCATION" chown $RPLD_SOCK_USER:$RPLD_SOCK_GROUP "$RPLD_STORE_LOCATION" # Check if daemon is already running: set +e if [ "$PIDFILE" != '' ] then _pid=`cat $PIDFILE 2> /dev/null` if [ "$_pid" != '' ] then if kill -0 $_pid 2> /dev/null then echo "." exit 0; fi fi fi set -e # Start Daemon $DAEMON $RPLD_OPTS echo "." ;; stop) echo -n "Stopping $DESC: $NAME" set +e if [ "$PIDFILE" = '' ] then pkill $NAME else _pid=`cat $PIDFILE 2> /dev/null` [ "$_pid" != '' ] && kill -TERM $_pid fi set -e echo "." ;; status) echo -n "Status of $DESC: " set +e if [ "$PIDFILE" != '' ] then _pid=`cat $PIDFILE 2> /dev/null` if [ "$_pid" != '' ] then kill -0 $_pid 2> /dev/null if [ "$?" = '0' ] then echo "running." exit 0; else echo "dead (stale pid file)." exit 1; fi else echo "not running." exit 3; fi fi set -e echo "unknown (no pid file configured)." exit 4 ;; restart|force-reload) $0 stop sleep 1 $0 start ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2 exit 1 ;; esac exit 0 rpld-0.1.9/plugins/0000755000175000017500000000000012266602740012272 5ustar phiphirpld-0.1.9/plugins/playback-logging/0000755000175000017500000000000012266602740015504 5ustar phiphirpld-0.1.9/plugins/playback-logging/Makefile0000644000175000017500000000007112023600332017124 0ustar phiphiBASENAME = playback-logging include ../Makefile.inc rpld-0.1.9/plugins/playback-logging/playback-logging.c0000644000175000017500000002217112266574313021071 0ustar phiphi//playback-logging.c: /* * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2012-2014 * * This file is part of RoarAudio PlayList Daemon, * a playlist management daemon for RoarAudio. * See README for details. * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 * as published by the Free Software Foundation. * * RoarAudio 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; see the file COPYING. If not, write to * the Free Software Foundation, 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ /* API: * Plugin Args: * filename * Name of the log file for the queueu. This is processed thru strftime(). * queue * The queue to use. */ #include #include #include #define FILENAME_SIZE 1024 #define VCLT_PREFIX "X-" BASENAME "-" struct instance { char filename[FILENAME_SIZE]; const char * filename_tpl; const char * queue; time_t now; struct tm tm; int new_file; struct roar_vio_calls * vio; struct roar_vio_calls vio_store; struct roar_subscriber * subscription; struct roar_dl_librarypara * para; }; static struct instance * g_instance = NULL; static struct instance g_instance_init = { .filename = "", .filename_tpl = NULL, .queue = NULL, .now = (time_t)0, .new_file = 1, .vio = NULL, .subscription = NULL, .para = NULL }; #define __get_config(x) roar_keyval_lookup(para->argv, (x), para->argc, 0) static inline void __get_time(void) { char filename[FILENAME_SIZE]; ROAR_DBG("__get_time(void) = ?"); g_instance->now = time(NULL); localtime_r(&(g_instance->now), &(g_instance->tm)); strftime(filename, sizeof(filename), g_instance->filename_tpl, &(g_instance->tm)); if ( !!strncmp(filename, g_instance->filename, sizeof(filename)) ) { memcpy(g_instance->filename, filename, sizeof(filename)); g_instance->new_file = 1; ROAR_DBG("__get_time(void): g_instance->new_file=1"); } ROAR_DBG("__get_time(void) = (void)"); } static inline int __reopen_file(void) { ROAR_DBG("__reopen_file(void) = ?"); if ( g_instance->vio != NULL ) { roar_vio_close(g_instance->vio); g_instance->vio = NULL; } ROAR_DBG("__reopen_file(void) = ?"); if ( roar_vio_open_dstr_simple(&(g_instance->vio_store), g_instance->filename, ROAR_VIOF_WRITE|ROAR_VIOF_CREAT|ROAR_VIOF_TRUNC) == -1 ) { ROAR_WARN("__reopen_file(void): Can not open file: %s: %s", g_instance->filename, roar_errorstring); return -1; } ROAR_DBG("__reopen_file(void) = ?"); g_instance->vio = &(g_instance->vio_store); g_instance->new_file = 0; ROAR_DBG("__reopen_file(void) = 0"); return 0; } static inline void __log_kv(const char * key, const char * value) { if ( key == NULL || value == NULL || value[0] == 0 ) return; roar_vio_printf(g_instance->vio, "%s=%s\n", key, value); } static inline const char * __get_logtime(char * buffer, size_t len) { size_t i; if ( len < 26 ) return NULL; asctime_r(&(g_instance->tm), buffer); // strip \n. for (i = 0; i < len && buffer[i]; i++) if (buffer[i] == '\n') buffer[i] = 0; return buffer; } static inline void __log_stream_pos(const struct roar_stream * stream, const char * prefix) { if ( stream == NULL || prefix == NULL ) return; roar_vio_printf(g_instance->vio, "%s=%lu\n", prefix, (long unsigned int)stream->pos); if ( stream->info.rate && stream->info.channels ) { roar_vio_printf(g_instance->vio, "%s-Time=%.3fs\n", prefix, (float)stream->pos/(stream->info.rate*stream->info.channels)); } } static inline void __log_length(const char * key, rpld_maxint_t l) { rpld_maxint_t h, m; if ( key == NULL ) return; h = l / 3600; l -= h * 3600; m = l / 60; l -= m * 60; roar_vio_printf(g_instance->vio, "%s=%.2i:%.2i:%.2i\n", key, (int)h, (int)m, (int)l); } static inline int __log_ple(struct roar_dl_librarypara * para, struct rpld_playlist_entry * ple, const struct roar_stream * stream) { static const char * const keys[] = { // common keys: "TITLE", "ALBUM", "ARTIST", "PERFORMER", "VERSION", // URAS keys: "X-URAS-START", "X-URAS-MAPNUM" }; size_t i; char buffer[37]; // minimum size: uuid=37, asctime=26 int codec; rpld_maxint_t ret; __get_time(); if ( g_instance->vio == NULL ) __reopen_file(); if ( g_instance->vio == NULL ) { // error still set by __reopen_file(). return -1; } for (i = 0; i < (sizeof(keys)/sizeof(*keys)); i++) __log_kv(keys[i], rpldph_ple_get_meta(ple, keys[i])); __log_kv("UUID", rpldph_ple_get_uuid(ple, buffer)); ret = rpldph_ple_get_meta_int(ple, "tracknumber"); if ( ret != (rpld_maxint_t)-1 ) roar_vio_printf(g_instance->vio, "TRACKNUMBER=%li\n", (long int)ret); ret = rpldph_ple_get_meta_int(ple, "discid"); if ( ret != (rpld_maxint_t)-1 && ret != (rpld_maxint_t)0 ) roar_vio_printf(g_instance->vio, "DISCID=0x%.8lx\n", (long int)ret); ret = rpldph_ple_get_meta_int(ple, "genre"); if ( ret != (rpld_maxint_t)-1 ) __log_kv("GENRE", roar_meta_strgenre(ret)); ret = rpldph_ple_get_meta_int(ple, "length"); if ( ret != (rpld_maxint_t)-1 && ret != (rpld_maxint_t)0 ) __log_length("LENGTH", ret); if ( stream != NULL ) { codec = rpldph_ple_get_codec(ple); if ( codec == -1 ) { roar_vio_printf(g_instance->vio, "SIGNALINFO=rate:%i channels:%i\n", (int)stream->info.rate, (int)stream->info.channels); } else { roar_vio_printf(g_instance->vio, "SIGNALINFO=codec:%s rate:%i channels:%i\n", roar_codec2str(codec), (int)stream->info.rate, (int)stream->info.channels); } } __log_kv(VCLT_PREFIX "Start-Time", __get_logtime(buffer, sizeof(buffer))); __log_stream_pos(stream, VCLT_PREFIX "StartPos"); return 0; } static inline int __log_end(const struct roar_stream * stream) { char buffer[26]; __get_time(); if ( g_instance->vio == NULL ) __reopen_file(); if ( g_instance->vio != NULL ) { __log_kv(VCLT_PREFIX "End-Time", __get_logtime(buffer, sizeof(buffer))); __log_stream_pos(stream, VCLT_PREFIX "EndPos"); if ( roar_vio_write(g_instance->vio, "==\n", 3) != (ssize_t)3 ) { ROAR_WARN("__log_end(void): Can not write PLE end entry. Logfile may be corrupted: %s", roar_errorstring); } } if ( g_instance->new_file ) __reopen_file(); return 0; } static void __cb_subscription(struct roar_notify_core * core, struct roar_event * event, void * userdata) { struct instance * old_instance; rpld_pli_t queue = event->target; struct roar_dl_librarypara * para; (void)core; old_instance = g_instance; g_instance = userdata; para = g_instance->para; ROAR_DBG("__cb_subscription(core=%p, event=%p, userdata=%p) = ?", core, event, userdata); if ( queue != rpldph_playlist_get_by_name(g_instance->queue) ) return; switch (event->event_proxy) { case RPLD_NOTIFY_PLAYBACK_STOP: __log_end(rpldph_playback_get_stream(queue)); break; case RPLD_NOTIFY_PLAYBACK_PLAY: __log_ple(g_instance->para, rpldph_playback_get_ple(queue), rpldph_playback_get_stream(queue)); break; } g_instance = old_instance; } static inline int __subscribe(void) { struct roar_event event; memset(&event, 0, sizeof(event)); event.event = ROAR_EGRP_ANY_EVENT; event.emitter = -1; event.target = -1; event.target_type = -1; g_instance->subscription = roar_notify_core_subscribe(NULL, &event, __cb_subscription, g_instance); return 0; } static int _init (struct roar_dl_librarypara * para) { struct roar_keyval * kv; ROAR_DBG("_init(para=%p) = ?", para); roar_dl_para_ref(para); g_instance->para = para; kv = __get_config("filename"); if ( kv == NULL || kv->value == NULL || kv->value[0] == 0 ) { ROAR_ERR("_init(para=%p): No filename given.", para); } g_instance->filename_tpl = kv->value; kv = __get_config("queue"); if ( kv == NULL || kv->value == NULL || kv->value[0] == 0 ) { g_instance->queue = "Main Queue"; } else { g_instance->queue = kv->value; } __get_time(); __reopen_file(); __subscribe(); ROAR_DBG("_init(para=%p) = 0", para); return 0; } static int _free (struct roar_dl_librarypara * para) { (void)para; ROAR_DBG("_free(para=%p) = ?", para); roar_notify_core_unsubscribe(NULL, g_instance->subscription); if ( g_instance->vio != NULL ) { roar_vio_close(g_instance->vio); g_instance->vio = NULL; } roar_dl_para_unref(g_instance->para); g_instance->para = NULL; ROAR_DBG("_free(para=%p) = 0", para); return 0; } static struct roar_dl_appsched sched = { .init = _init, .free = _free, .update = NULL, .tick = NULL, .wait = NULL }; ROAR_DL_PLUGIN_START(playback_logging) { ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org"); ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0); ROAR_DL_PLUGIN_META_PRODUCT_NIV(BASENAME, ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); ROAR_DL_PLUGIN_META_DESC("This plugin is used to log the activity of played tracks"); RPLDPH_CHECK_VERSIONS(); ROAR_DL_PLUGIN_REG_GLOBAL_DATA(g_instance, g_instance_init); ROAR_DL_PLUGIN_REG_APPSCHED(&sched); } ROAR_DL_PLUGIN_END //ll rpld-0.1.9/plugins/Makefile.inc0000644000175000017500000000011412030031257014462 0ustar phiphiinclude ../../Makefile.conf include $(ROAR_BUILDSYSTEM_DIR)/Makefile.plugin rpld-0.1.9/tools/0000755000175000017500000000000012266602740011751 5ustar phiphirpld-0.1.9/tools/OLD/0000755000175000017500000000000012266602740012367 5ustar phiphirpld-0.1.9/tools/OLD/rpld-addplaylist0000755000175000017500000000220611756651046015574 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2012 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; my ($pl, $parent) = @ARGV; die unless $pl; print STDERR "Warning: Using this tool is deprecated. Use: rpld-ctl addplaylist $pl\n"; my $rpld = Audio::RPLD->new(); $rpld->connect_default(); $rpld->is_connected() or die; $rpld->addplaylist($pl); $rpld->disconnect(); #ll rpld-0.1.9/tools/OLD/rpld-delplaylist0000755000175000017500000000217511756651046015615 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2012 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; my ($pl) = @ARGV; die unless $pl; print STDERR "Warning: Using this tool is deprecated. Use: rpld-ctl delplaylist $pl\n"; my $rpld = Audio::RPLD->new(); $rpld->connect_default(); $rpld->is_connected() or die; $rpld->delplaylist($pl); $rpld->disconnect(); #ll rpld-0.1.9/tools/OLD/rpld-play0000755000175000017500000000210411756651047014225 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2012 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; print STDERR "Warning: Using this tool is deprecated. Use: rpld-ctl play\n"; my $rpld = Audio::RPLD->new(); $rpld->connect_default(); $rpld->is_connected() or die; $rpld->play(); $rpld->disconnect(); #ll rpld-0.1.9/tools/OLD/rpld-prev0000755000175000017500000000210511756651047014235 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2012 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; print STDERR "Warning: Using this tool is deprecated. Use: rpld-ctl prev\n"; my $rpld = Audio::RPLD->new(); $rpld->connect_default(); $rpld->is_connected() or die; $rpld->prev(); $rpld->disconnect(); #ll rpld-0.1.9/tools/OLD/rpld-stop0000755000175000017500000000210411756651047014245 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2012 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; print STDERR "Warning: Using this tool is deprecated. Use: rpld-ctl stop\n"; my $rpld = Audio::RPLD->new(); $rpld->connect_default(); $rpld->is_connected() or die; $rpld->stop(); $rpld->disconnect(); #ll rpld-0.1.9/tools/OLD/rpld-store0000755000175000017500000000210611756651047014416 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2012 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; print STDERR "Warning: Using this tool is deprecated. Use: rpld-ctl store\n"; my $rpld = Audio::RPLD->new(); $rpld->connect_default(); $rpld->is_connected() or die; $rpld->store(); $rpld->disconnect(); #ll rpld-0.1.9/tools/rpld-ctl0000755000175000017500000000635711756651046013441 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2012 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; my $server; my $queue; my ($cmd, $arg); my $ret; while ($_ = shift(@ARGV)) { if ( $_ =~ /^--/ ) { if ( $_ eq '--server' ) { $server = shift(@ARGV); } elsif ( $_ eq '--queue' ) { $queue = shift(@ARGV); } elsif ( $_ eq '--help' ) { usage(); exit(0); } else { print STDERR "Invalid option: $_\n"; usage(); exit(1); } } elsif ( !defined($cmd) ) { $cmd = lc($_); } elsif ( !defined($arg) ) { $arg = $_; } else { print STDERR "Invalid extra parameter: $_\n"; usage(); exit(1); } } if ( !defined($cmd) ) { print STDERR "Error: No command given.\n"; usage(); exit(1); } my $rpld = Audio::RPLD->new(); if ( defined($server) ) { $rpld->connect($server); } else { $rpld->connect_default(); } $rpld->is_connected() or die; if ( defined($queue) ) { $rpld->setqueue($queue) or die; } # initial commands: if ( $cmd eq 'pause' ) { $ret = $rpld->pause(); } elsif ( $cmd eq 'unpause' ) { $ret = $rpld->unpause(); } elsif ( $cmd eq 'togglepause' ) { $ret = $rpld->togglepause(); } elsif ( $cmd eq 'volume' ) { $ret = $rpld->setvolume($arg); # playback: } elsif ( $cmd eq 'play' ) { $ret = $rpld->play(); } elsif ( $cmd eq 'stop' ) { $ret = $rpld->stop(); } elsif ( $cmd eq 'next' ) { $ret = $rpld->next(); } elsif ( $cmd eq 'prev' ) { $ret = $rpld->prev(); # store: } elsif ( $cmd eq 'store' ) { $ret = $rpld->store(); # playlists: } elsif ( $cmd eq 'addplaylist' ) { $ret = $rpld->addplaylist($arg); } elsif ( $cmd eq 'delplaylist' ) { $ret = $rpld->delplaylist($arg); # other: } else { die 'Unknown command'; } $rpld->disconnect(); exit(0); sub usage { print "Usage: $0 [--server SERVER] COMMAND [arg]\n"; print "Or: $0 --help\n"; print "\n"; print <<'__EOF__'; Options: --help - Show this help. --server SERVER - Set server address. --queue QUEUE - Set default queue for this process. Commands: pause - Pause playback unpause - Unpause playback togglepause - If playback is paused unpause, if not pause. volume VOL - Set volume to VOL play - Start playback stop - Stop playback next - Play next track prev - Play previous track store - Save current state to store addplaylist PLAYLIST - Add a new playlist delplaylist PLAYLIST - Delete a playlist __EOF__ } #ll rpld-0.1.9/tools/rpld-deprecated.10000644000175000017500000000322611776015211015071 0ustar phiphi.\" rpld-*.1: .TH "rpld-*" "1" "July 2012" "rpld-deprecated" "System User's Manual: rpld-deprecated" .SH NAME rpld-deprecated \- Deprecated RoarAudio PlayList Daemon control programs .SH SYNOPSIS rpld-play rpld-stop rpld-next [\-\-ifcurple PLE] rpld-prev rpld-addplaylist PLI rpld-delplaylist PLI rpld-store .SH DESCRIPTION The RoarAudio PlayList Daemon is a daemon which manages playlists and can play files or streams from those lists using a RoarAudio Sound Server. This is a set of deprecated tools to do simple control of the server. All those tools has be replaced by \fBrpld-ctl\fR(1). Some of them may no longer be installed on your system. This manpage only exists to help you migrate your scripts. The following tools are deprecated: .TP \fBrpld-play\fR Start playback if not yet started. Replaced by: rpld-ctl play .TP \fBrpld-stop\fR Stop playback. Replaced by: rpld-ctl stop .TP \fBrpld-next [\-\-ifcurple PLE]\fR Skip current song. if \-\-ifcurple and a PLE is given the song is only skiped if the currently played song matches the given PLE. This tool has only been deprecated in case \-\-ifcurple is not used. Replaced by: rpld-ctl next .TP \fBrpld-prev\fR Go back to previous song. Replaced by: rpld-ctl prev .TP \fBrpld-addplaylist PLI\fR Add playlist with name PLI. Replaced by: rpld-ctl addplaylist PLI .TP \fBrpld-delplaylist PLI\fR Delete playlist PLI. Replaced by: rpld-ctl delplaylist PLI .TP \fBrpld-store\fR Store current state to disk. This tool should not be needed to be called by a user at all for normal use cases. Replaced by: rpld-ctl store .SH "SEE ALSO" \fBrpld-tools\fR(1), \fBrpld\fR(7), \fBRoarAudio\fR(7). .\" ll rpld-0.1.9/tools/rpld-import0000755000175000017500000000322011756651047014154 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; my $server; my $queue; while (@ARGV) { $_ = shift(@ARGV); if ( $_ eq '--help' ) { print STDERR "Usage: $0 [OPTIONS] PLI TYPE FILE\n"; exit(0); } elsif ( $_ eq '--server' ) { $server = shift(@ARGV); } elsif ( $_ eq '--queue' ) { $queue = shift(@ARGV); } else { unshift(@ARGV, $_); last; } } my ($pl, $type, $src) = @ARGV; die unless $pl; my $rpld = Audio::RPLD->new(); if ( defined($server) ) { $rpld->connect($server); } else { $rpld->connect_default(); } $rpld->is_connected() or die; if ( defined($queue) ) { $rpld->setqueue($queue) or die; } $rpld->setplaylist($pl); my @q = ('IMPORT', 'FROM'); if ( $src ) { push(@q, $rpld->q_str($src)); } else { push(@q, 'STDIN'); } if ( $type ) { push(@q, 'AS'); push(@q, $type); } $rpld->cmd(@q); $rpld->disconnect(); #ll rpld-0.1.9/tools/rpld-listplaylists0000755000175000017500000000544311756651047015573 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; my $server; my $queue; my $level = 0; while (($_ = shift(@ARGV))) { if ( $_ eq '--tree' ) { $level = 0; } elsif ( $_ eq '--flat' ) { $level = -1; } elsif ( $_ eq '--server' ) { $server = shift(@ARGV); } elsif ( $_ eq '--queue' ) { $queue = shift(@ARGV); } elsif ( $_ eq '--help' ) { print STDERR "Usage: $0 [OPTIONS] [--tree|--flat]\n"; exit(0); } else { die 'Unknown option: '.$_; } } my $rpld = Audio::RPLD->new(); if ( defined($server) ) { $rpld->connect($server); } else { $rpld->connect_default(); } $rpld->is_connected() or die; if ( defined($queue) ) { $rpld->setqueue($queue) or die; } my $res = $rpld->listplaylists() or die; $rpld->disconnect(); proc($res, $level, 1, $res); sub get_list { my ($lists, $id) = @_; local $_; foreach (@{$lists}) { return $_ if $_->{'id'} == $id; } return {}; } sub proc { my ($lists, $level, $nocircular, $alllists) = @_; my $c; my $prefix = ''; my $type; $level ||= 0; unless ( $level < 0 ) { $prefix = ' ' x ($level * 2); } foreach $c (@{$_[0]}) { if ( $c->{'processed'} ) { #printf("%s[%-8i]: %s ***circular parentship***\n", $prefix, $c->{'id'}, $c->{'name'}) unless $nocircular; printf("%s%i: %s ***circular parentship***\n", $prefix, $c->{'id'}, $c->{'name'}) unless $nocircular; next; } $type = 'playlist'; if ( defined($c->{'history_size'}) ) { $type = sprintf('history(size %i)', $c->{'history_size'}); } elsif ( defined($c->{'history'}) ) { $type = sprintf('queue(volume %i, history %s, %sbackend%s)', $c->{'volume'}, get_list($alllists, $c->{'history'})->{'name'} || $c->{'history'}, $c->{'backend'} eq '+default' ? ('default ', '') : ('', ' default')); } #printf("%s[%-8i]: %s\n", $prefix, $c->{'id'}, $c->{'name'}); printf("%s%i [%s]: %s\n", $prefix, $c->{'id'}, $type, $c->{'name'}); $c->{'processed'} = 1; proc($c->{'children'}, $level + 1, 0, $alllists) unless $level < 0; } } #ll rpld-0.1.9/tools/rpld-listq0000755000175000017500000000576311756651047014014 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; my $server; my $queue; while (@ARGV) { $_ = shift(@ARGV); if ( $_ eq '--help' ) { print STDERR "Usage: $0 [OPTIONS] [PLAYLIST]\n"; exit(0); } elsif ( $_ eq '--server' ) { $server = shift(@ARGV); } elsif ( $_ eq '--queue' ) { $queue = shift(@ARGV); } else { unshift(@ARGV, $_); last; } } my ($pl) = @ARGV; my $rpld = Audio::RPLD->new(); if ( defined($server) ) { $rpld->connect($server); } else { $rpld->connect_default(); } $rpld->is_connected() or die; if ( defined($queue) ) { $rpld->setqueue($queue) or die; } my $list = $rpld->listq($pl) or die; my $c; my $meta; my $num = 0; my $length = ''; my $discid = ''; my ($h, $m, $s); foreach $c (@{$list}) { $meta = $c->{'meta'}; if ( $c->{'length'} ) { $s = $c->{'length'}; $h = int($s / 3600); $s = $s % 3600; $m = int($s / 60); $s = $s % 60; $length = sprintf('%.2i:%.2i:%.2i', $h, $m, $s); } else { $length = 'unknown'; } if ( $meta->{'discid'} ) { $discid = sprintf('0x%.8X', $meta->{'discid'}); } else { $discid = 'unknown'; } $meta->{'artist'} = undef if lc($meta->{'artist'}) eq 'unknown'; $c->{'codec'} ||= 'unknown'; #printf("num:%-4i = %s, %s, %s\n", $num++, $c->{"longid"}, $c->{"shortid"}, $c->{"uuid"}); printf("num:%-4i = %s, %s\n", $num++, $c->{"longid"}, $c->{"shortid"}); printf("UUID: %s\n", $c->{'uuid'}) if $c->{'uuid'}; printf("File: %s\n", $c->{'file'}) if $c->{'file'}; printf("Codec: %-14s Length: %-8s\n", $c->{'codec'}, $length) if $c->{'codec'} ne 'unknown' || $length ne 'unknown'; printf("Disc: %-10s Track: %2i of %2i\n", $discid, $meta->{'tracknumber'}, $meta->{'totaltracks'}) if $discid ne 'unknown' || $meta->{'tracknumber'} || $meta->{'totaltracks'}; printf("Album: %-32s Title: %s\n", $meta->{'album'}, $meta->{'title'}); printf(" Version: %s\n", $meta->{'version'}) if $meta->{'version'}; printf("Artist: %-31s ", $meta->{'artist'}) if $meta->{'artist'}; printf("Performer: %s", $meta->{'performer'}) if $meta->{'performer'}; printf("\n") if $meta->{'artist'} || $meta->{'performer'}; printf("\n"); } $rpld->disconnect(); #ll rpld-0.1.9/tools/rpld-next0000755000175000017500000000320611756651047013624 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; print STDERR "Warning: Using this tool is deprecated. Use: rpld-ctl next\n" if scalar(@ARGV) == 0; my %map = ( 'uuid' => 'uuid', 'long' => 'longid', 'short' => 'shortid', ); my $rpld = Audio::RPLD->new(); my $k; $rpld->connect_default(); $rpld->is_connected() or die; while (@ARGV) { $_ = shift(@ARGV); if ( $_ eq '--ifcurple' ) { $_ = shift(@ARGV); my $cur = $rpld->showcur(); s/^0x/long:0x/; if ( /^([^:]+):/ ) { if ( ($k = $map{$1}) ) { exit(0) unless $cur->{$k} eq $_; } else { print STDERR "Unknown PLE type\n"; exit(1); } } else { print STDERR "Unknown PLE type\n"; exit(1); } } else { print STDERR "Unknown (Too may) arguments\n"; exit(1); } } $rpld->next(); $rpld->disconnect(); #ll rpld-0.1.9/tools/rpld-queueple0000755000175000017500000000355011756651047014475 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; my $server; my $queue; my $ple = undef; my $pli = undef; my $pos = undef; while (@ARGV) { $_ = shift(@ARGV); # print "ARG: '$_'\n"; if ( $_ eq '--help' ) { print STDERR "Usage: $0 [OPTIONS] PLE [PLI]\n"; exit(0); } elsif ( $_ eq '--server' ) { $server = shift(@ARGV); } elsif ( $_ eq '--queue' ) { $queue = shift(@ARGV); } elsif ( $_ eq '--pos' ) { $_ = shift(@ARGV); if ( lc($_) eq 'first' ) { $pos = -1; } elsif ( lc($_) eq 'last' ) { $pos = -2; } else { $pos = int($_); } } elsif ( !defined($ple) ) { $ple = $_; } elsif ( !defined($pli) ) { $pli = $_; } else { print STDERR "Error: To may arguemnts!\n"; exit(1); } } die unless $ple; my $rpld = Audio::RPLD->new(); if ( defined($server) ) { $rpld->connect($server); } else { $rpld->connect_default(); } $rpld->is_connected() or die; if ( defined($queue) ) { $rpld->setqueue($queue) or die; } $pli = $rpld->any() unless defined $pli; die unless $rpld->queueple($ple, $pli, $pos); $rpld->disconnect(); #ll rpld-0.1.9/tools/rpld-setpointer0000755000175000017500000000274511756651047015051 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; my $server; my $queue; while (@ARGV) { $_ = shift(@ARGV); if ( $_ eq '--help' ) { print STDERR "Usage: $0 [OPTIONS] POINTER PLE [PLI]\n"; exit(0); } elsif ( $_ eq '--server' ) { $server = shift(@ARGV); } elsif ( $_ eq '--queue' ) { $queue = shift(@ARGV); } else { unshift(@ARGV, $_); last; } } my ($pointer, $ple, $pl) = @ARGV; my $rpld = Audio::RPLD->new(); if ( defined($server) ) { $rpld->connect($server); } else { $rpld->connect_default(); } $rpld->is_connected() or die; if ( defined($queue) ) { $rpld->setqueue($queue) or die; } $rpld->setpointer($pointer, $ple, $pl); $rpld->disconnect(); #ll rpld-0.1.9/tools/rpld-showplaying0000755000175000017500000000440611503017024015172 0ustar phiphi#!/usr/bin/perl # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. use strict; use Audio::RPLD; my $rpld = Audio::RPLD->new(); my $cur; my $playing; $rpld->connect_default(); $rpld->is_connected() or die; $cur = $rpld->showcur(); $playing = $rpld->showplaying(); $rpld->disconnect(); $playing->{'state'} ||= 'STOPPED'; print 'Playback state: ', ucfirst(lc($playing->{'state'})), ".\n"; exit(0) if $playing->{'state'} eq 'STOPPED'; timedisplay($playing, $cur); exit(0); sub timedisplay { my ($p, $c) = @_; my $barlen = 50; my $f = -1; my $bar; my $ptime; my $ltime = 'unknown '; local $_; if ( $cur->{'length'} ) { $ltime = time2lr($cur->{'length'}); $f = $p->{'time'}->{'s'} / $cur->{'length'}; } if ( $f < 0 ) { $bar = ' '; $bar .= ' ' x ($barlen - length($bar)); } else { $bar = '=' x ($f * ($barlen - 1)); $bar .= '>'; $bar .= ' ' x ($barlen - length($bar)); } $ptime = time2lr($p->{'time'}->{'s'}); printf("%s of %s [%s]\n", $ptime, $ltime, $bar); printf("num:0 = %s, %s\n", $p->{'longgtn'}, $p->{'shortgtn'}); printf("UUID: %s\n", $p->{'uuid'}) if $p->{'uuid'}; printf("Signal: %i channels of %i bits at %i Hz\n", $p->{'channels'}, $p->{'bits'}, $p->{'rate'}); foreach (keys(%{$p->{'meta'}})) { printf("%-10s %s\n", ucfirst(lc($_)).':', $p->{'meta'}->{$_}); } } sub time2lr { my ($s) = @_; my $m; my $h; $h = int($s / 3600); $s = $s % 3600; $m = int($s / 60); $s = $s % 60; return sprintf('%.2i:%.2i:%.2i', $h, $m, $s); } #ll rpld-0.1.9/tools/rpld-storemgr0000755000175000017500000002064612023606451014502 0ustar phiphi#!/bin/sh # Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2012 # # This file is part of RoarAudio PlayList Daemon, # a playlist management daemon for RoarAudio. # See README for details. # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # RoarAudio 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this software; see the file COPYING. If not, write to # the Free Software Foundation, 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. RPLD_STORE_LOCATION='/var/lib/roarplaylistd/' RPLD='rpld' COMMAND='_error' FORCE=false HISTSIZE='default' ROLE='default' if [ -f /etc/rpld-storemgr.conf ]; then . /etc/rpld-storemgr.conf fi if [ -f ~/.rpld-storemgr.conf ]; then . ~/.rpld-storemgr.conf fi # lib: __test() { test -d "$RPLD_STORE_LOCATION"; } __mkdir() { mkdir -p "$RPLD_STORE_LOCATION"; } __rmdir() { rm -rf "$RPLD_STORE_LOCATION"; } __ask_bool() { read -p "$1 [y/N]: " ret; if [ "$ret" = 'y' -o "$ret" = 'Y' -o "$ret" = 'yes' ]; then true; else false; fi; } __run() { "$RPLD" --store-path "$RPLD_STORE_LOCATION" --histsize "$HISTSIZE" --role "$ROLE" "$@"; } # end of lib # commands: cmd_help() { echo "Usage: $0 [OPTIONS] command [ARGS]" cat <&2 return 3; ;; esac; if __test then echo "Warning: store directory already exists." return 0; else : fi __mkdir if [ "$mode" = 'savannahice' ] then [ "$server" != '' ] && server=" -O $server"; { echo '#!/bin/sh'; echo "exec savannahice \"\$@\"$server"; echo '#ll'; } > "$RPLD_STORE_LOCATION"/server chmod a+rx "$RPLD_STORE_LOCATION"/server server="+fork=!$RPLD_STORE_LOCATION/server --no-listen --client-fh 0" fi __run --no-listen --stopped --no-restore --store --server-queue "$server" } cmd_imexport() { command="$1" playlist="$2" type="$3" file="$4" [ "$type" = '' ] && type='VCLT'; if [ "$file" = '-' -o "$file" = '' ] then [ "$command" = 'import' ] && file='/dev/stdin'; [ "$command" = 'export' ] && file='/dev/stdout'; fi if __test then : else echo "Error: Store does not exist." return 1; fi __run --no-listen --stopped --restore --store --playlist-$command "$playlist" "$type" "$file" } cmd_run() { if __test then : else echo "Error: Store does not exist." return 1; fi __run --restore "$@" } cmd_info() { if __test then : else echo "Error: Store does not exist." return 1; fi _version=`cat "$RPLD_STORE_LOCATION"/store-version 2>/dev/null` case "$_version" in '') _version=0 _version_str='pre 0.1rc1 (assumed)' ;; '0') _version_str='pre 0.1rc1' ;; '1') _version_str='pre 0.1rc7' ;; '2') _version_str='0.1rc7' ;; esac; echo "Store format: $_version: $_version_str" echo "Playlists:" while IFS=':' read _PLTAG pl_id pl_parent _XTAG pl_name pl_histsize pl_volume pl_role pl_history pl_backend pl_mixer do if [ "$pl_parent" = '0' ] then pl_parent='no parent' else pl_parent="parent: $pl_parent" fi if [ "$pl_mixer" = '-1' ] then pl_mixer='default mixer' else pl_mixer="mixer: $pl_mixer" fi echo "$pl_id[$pl_parent]: $pl_name" [ "$_version" -ge 2 -a "$pl_histsize" != '-1' ] && echo " Is history with history size $pl_histsize" [ "$_version" -ge 2 -a "$pl_backend" != '+invalid' ] && echo " Is queue with backend $pl_backend[$pl_mixer], volume $pl_volume/65535, role $pl_role and history $pl_history" done < "$RPLD_STORE_LOCATION"/index echo "Pointers:" while IFS=' ' read _POINTERTAG pointer_name _ARROWTAG pointer_value do pointer_name=`echo "$pointer_name" | cut -d\" -f2` echo " $pointer_name set to $pointer_value" done < "$RPLD_STORE_LOCATION"/pointer } cmd_check() { error=false; if __test then : else echo "Error: Store does not exist." return 1; fi _version=`cat "$RPLD_STORE_LOCATION"/store-version 2>/dev/null` [ "$_version" = '' ] && _version=0 if [ "$_version" = '2' ] then echo "Store format: 2 - Good." elif [ "$_version" -gt '2' ] then echo "Store format: $_version - greater than current. BAD." error=true; else echo "Store format: $_version - Old. Try to upgrade." fi while IFS=':' read _PLTAG pl_id pl_parent _XTAG pl_name pl_histsize pl_volume pl_role pl_history pl_backend pl_mixer do pl_id=`echo "$pl_id" | tr -d ' '` if [ -f "$RPLD_STORE_LOCATION/pl-$pl_id" ] then echo "Playlist $pl_id: exists - Good." else echo "Playlist $pl_id: does not exist - BAD." error=true; fi if [ "$pl_parent" = '0' ] then echo "Playlist $pl_id's parent: Playlist has no parent - Good." else if [ -f "$RPLD_STORE_LOCATION/pl-$pl_parent" ] then echo "Playlist $pl_id's parant $pl_parent: exists - Good." else echo "Playlist $pl_id's parent $pl_parent: does not exist - BAD." error=true; fi _res=`grep -c "^PL: $pl_parent:" < "$RPLD_STORE_LOCATION"/index` if [ "$_res" = '1' ] then echo "Playlist $pl_id's parant $pl_parent: is in index - Good." elif [ "$_res" = '0' ] then echo "Playlist $pl_id's parant $pl_parent: is not in index - BAD." error=true else echo "Playlist $pl_id's parant $pl_parent: has bad index count: $_res - BAD." error=true fi fi done < "$RPLD_STORE_LOCATION"/index $error && return 2; return 0; } # end of commands while [ "$1" != '' ] do case "$1" in '-h'|'--help') cmd_help; exit 0; ;; '--config') . "$2" shift; ;; '--store-path') RPLD_STORE_LOCATION="$2" shift; ;; '--histsize') HISTSIZE="$2" shift; ;; '--role') ROLE="$2" shift; ;; '--force') FORCE=true ;; --*) echo "Unknown option: $1" >&2 exit 1; ;; *) COMMAND="$1" shift; break; ;; esac; shift; done case "$COMMAND" in help) cmd_help; ;; remove) cmd_remove; ;; create) cmd_create "$@"; ;; import|export) cmd_imexport "$COMMAND" "$@"; ;; run) cmd_run "$@"; ;; console) cmd_run --no-listen --client-fh 3 "$@" 3<>`tty`; ;; info) cmd_info; ;; check) cmd_check; ;; *) echo "Unknown command: $COMMAND" >&2 exit 2; ;; esac #ll rpld-0.1.9/tools/rpld-storemgr.10000644000175000017500000000602512023606451014631 0ustar phiphi.\" rpld-*.1: .TH "rpld-storemgr" "1" "August 2012" "rpld-storemgr" "System User's Manual: rpld-storemgr" .SH NAME rpld-storemgr \- Offline store manager for the RoarAudio PlayList Daemon .SH SYNOPSIS rpld-storemgr [OPTIONS] command [ARGS] .SH DESCRIPTION The RoarAudio PlayList Daemon is a daemon which manages playlists and can play files or streams from those lists using a RoarAudio Sound Server. This program is used to create, alter and remove stores (databases) for this daemon. .SH "OPTIONS" .TP \fB\-h \-\-help\fR Show a small help. .TP \fB\-\-config FILE\fR Read an additional config files. .TP \fB\-\-store-path PATH\fR Sets the store path to PATH. .TP \fB\-\-histsize SIZE\fR Set size of default history. .TP \fB\-\-role ROLE\fR Set the stream role for the default queue. .TP \fB\-\-force\fR Force operation. .SH "COMMANDS" .TP \fBhelp\fR Does the same as \fB\-\-help\fR. .TP \fBremove\fR Remove an existing store. .TP \fBcreate [TYPE [SERVER]]\fR Create a new store. TYPE may be "roar" or "SavannahIce". If TYPE is set to "roar" SERVER is the location of the RoarAudio server to use. If TYPE is set to "SavannahIce" SERVER is the URL of an Icecast mount point to stream to. The script will set up the store in a way that will automatically start SavannahIce and stream to the given mount. .TP \fBimport PLAYLIST [TYPE [FILE]]\fR Import the playlist file FILE into the playlist PLAYLIST. FILE is a playlist of type TYPE. If FILE is not given stdin is assumed. If TYPE is not given VCLT is assumed. .TP \fBexport PLAYLIST [TYPE [FILE]]\fR Export the playlist PLAYLIST into the file FILE. FILE is a playlist of type TYPE. If FILE is not given stdout is assumed. If TYPE is not given VCLT is assumed. .TP \fBrun [ARGS]\fR Start rpld with selected store. The given arguments ARGS are passed as they are to the daemon. .TP \fBconsole [ARGS]\fR Start rpld with only the current console connected. The given arguments ARGS are passed as they are to the daemon. .TP \fBinfo\fR Show information about the store. .TP \fBcheck\fR Check store for errors. .SH "FILES" By default the files /etc/rpld-storemgr.conf and ~/.rpld-storemgr.conf are included if they exist. The user can also add additional config files using the \fB\-\-config\fR option (see above). .SH "CONFIG FILE FORMAT" The config files are in normal POSIX shell syntax. They can set the following variables: .TP \fBRPLD_STORE_LOCATION\fR This is the location of the store to operate on. .TP \fBRPLD\fR This is the program name and path to the Daemon. .TP \fBCOMMAND\fR This is the command to be executed. It is very unlikely that this needs to be set by an config file. Note that this does not include the command's options. .TP \fBFORCE\fR This is the current value of the force option. It can be set to "true" and "false". .TP \fBHISTSIZE\fR This is the default history size. .TP \fBROLE\fR This is the default role. .SH "HISTORY" This tool got introduced in version 0.1.4 of the RoarAudio PlayList Daemon. .SH "SEE ALSO" \fBrpld\-deprecated\fR(1), \fBrpld\fR(7), \fBRoarAudio\fR(7). .\" ll rpld-0.1.9/tools/rpld-tools.10000644000175000017500000000537411776015211014137 0ustar phiphi.\" rpld-*.1: .TH "rpld-tools" "1" "May 2012" "rpld-tools" "System User's Manual: rpld-tools" .SH NAME rpld-tools \- RoarAudio PlayList Daemon control programs .SH SYNOPSIS rpld-next \-\-ifcurple PLE rpld-ctl [COMMON OPTIONS] COMMAND [arg] rpld-queueple [COMMON OPTIONS] [\-\-pos {first|last|POS]] PLE [PLI] rpld-listq [COMMON OPTIONS] [PLI] rpld-setpointer [COMMON OPTIONS] POINTER PLE [PLI] rpld-listplaylists [COMMON OPTIONS] [{\-\-tree|\-\-flat}] rpld-import [COMMON OPTIONS] PLI TYPE FILE .SH DESCRIPTION The RoarAudio PlayList Daemon is a daemon which manages playlists and can play files or streams from those lists using a RoarAudio Sound Server. This is a set of Perl based tools to do simple control of the server. The following tools are supported: .TP \fBrpld-next \-\-ifcurple PLE\fR Skip current song. if \-\-ifcurple and a PLE is given the song is only skiped if the currently played song matches the given PLE. .TP \fBrpld-ctl [COMMON OPTIONS] COMMAND [arg]\fR This command can alter diffrent parts of the current rpld state. This included playback state as well as some playlist manipulation. Possible commands are: .RS .TP \fBpause\fR Pause playback. .TP \fBunpause\fR Unpause playback. .TP \fBtogglepause\fR If playback is paused unpause, if not pause. .TP \fBvolume VOL\fR Set volume to VOL. VOL must be in range 0%..100% or 0..65535. .TP \fBplay\fR Start playback. .TP \fBstop\fR Stop playback. .TP \fBnext\fR Play next track. .TP \fBprev\fR Play previous track. .TP \fBstore\fR Save current state to store. .TP \fBaddplaylist PLAYLIST\fR Add a new playlist. .TP \fBdelplaylist PLAYLIST\fR Delete a playlist. .RE .TP \fBrpld-queueple [COMMON OPTIONS] [\-\-pos {first|last|POS]] PLE [PLI]\fR Queue the song PLE form playlist PLI. If no playlist is given all playlists are searched. A position where to queue to can optionaly be given. .TP \fBrpld-listq [COMMON OPTIONS] [PLI]\fR List content of queue or given playlist PLI. .TP \fBrpld-setpointer [COMMON OPTIONS] POINTER PLE [PLI]\fR Set pointer POINTER to a given target PLE. If no playlist (PLI) is given Main Queue is used. .TP \fBrpld-listplaylists [COMMON OPTIONS] [{\-\-tree|\-\-flat}]\fR List all known playlists. Listing is done in correct tree view (default) or as flat view. .TP \fBrpld-import [COMMON OPTIONS] PLI TYPE FILE\fR Import a playlist file FILE into a playlist PLI. The type of the file is given as TYPE. .SH "COMMON OPTIONS" The following common options are supported: .TP \fB--help\fR THis option shows a brief help. .TP \fB--server SERVER\fR This option sets the server to connect to. This overrides the defaults. .TP \fB--queue QUEUE\fR This sets the default queue for the current process. .SH "SEE ALSO" \fBrpld-deprecated\fR(1), \fBrpld\fR(7), \fBRoarAudio\fR(7). .\" ll